Skip to content

Commit

Permalink
Base whether the result of the capabilities call is a bundle on the c…
Browse files Browse the repository at this point in the history
…ontent-type

This avoids starting to read off the connection, and avoids the use of
chain.
  • Loading branch information
glandium committed Jun 21, 2024
1 parent 589b3a5 commit 5b21a50
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/hg_connect_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::borrow::ToOwned;
use std::ffi::{c_void, CStr, CString, OsStr};
use std::fs::File;
use std::io::{self, copy, stderr, Cursor, Read, Write};
use std::io::{self, stderr, Cursor, Read, Write};
use std::os::raw::{c_char, c_int, c_long};
use std::path::{Path, PathBuf};
use std::str::FromStr;
Expand Down Expand Up @@ -863,22 +863,18 @@ pub fn get_http_connection(url: &Url) -> Option<Box<dyn HgRepo>> {
}
let mut http_resp = http_req.execute().unwrap();
conn.handle_redirect(&http_resp);
let header = (&mut http_resp).take(4).read_all().unwrap();
match &*header {
b"HG10" | b"HG20" => Some(Box::new(BundleConnection::new(
HttpConnectionHoldingReader {
reader: Cursor::new(header).chain(http_resp),
conn,
},
))),

_ => {
let mut caps = Vec::<u8>::new();
caps.extend_from_slice(&header);
copy(&mut http_resp, &mut caps).unwrap();
match http_resp.content_type() {
Some("application/mercurial-0.1") | Some("application/mercurial-0.2") => {

Check failure on line 867 in src/hg_connect_http.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest, 1.79.0)

unnested or-patterns

error: unnested or-patterns --> src/hg_connect_http.rs:867:9 | 867 | Some("application/mercurial-0.1") | Some("application/mercurial-0.2") => { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns note: the lint level is defined here --> src/main.rs:38:9 | 38 | #![deny(clippy::unnested_or_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: nest the patterns | 867 | Some("application/mercurial-0.1" | "application/mercurial-0.2") => { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check failure on line 867 in src/hg_connect_http.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest, 1.79.0)

unnested or-patterns

error: unnested or-patterns --> src/hg_connect_http.rs:867:9 | 867 | Some("application/mercurial-0.1") | Some("application/mercurial-0.2") => { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns note: the lint level is defined here --> src/main.rs:38:9 | 38 | #![deny(clippy::unnested_or_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: nest the patterns | 867 | Some("application/mercurial-0.1" | "application/mercurial-0.2") => { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let caps = http_resp.read_all().unwrap();
drop(http_resp);
mem::swap(&mut conn.capabilities, &mut HgCapabilities::new_from(&caps));
Some(Box::new(HgWired::new(conn)))
}
_ => Some(Box::new(BundleConnection::new(
HttpConnectionHoldingReader {
reader: http_resp,
conn,
},
))),
}
}

0 comments on commit 5b21a50

Please sign in to comment.