Skip to content

Commit

Permalink
Use a connection that doesn't first try a capabilities command for cl…
Browse files Browse the repository at this point in the history
…onebundles
  • Loading branch information
glandium committed Jun 21, 2024
1 parent d68de86 commit b01ca2e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
18 changes: 14 additions & 4 deletions src/hg_connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ use url::Url;
use crate::cinnabar::GitChangesetId;
use crate::git::{CommitId, GitObjectId};
use crate::hg::HgChangesetId;
use crate::hg_bundle::{BundleReader, BundleSpec};
use crate::hg_connect_http::get_http_connection;
use crate::hg_bundle::{BundleConnection, BundleReader, BundleSpec};
use crate::hg_connect_http::{get_http_connection, HttpRequest};
use crate::hg_connect_stdio::get_stdio_connection;
use crate::libgit::{die, remote, resolve_ref, rev_list, rev_list_with_parents};
use crate::libgit::{
die, http_follow_config, remote, resolve_ref, rev_list, rev_list_with_parents,
};
use crate::oid::ObjectId;
use crate::store::{has_metadata, merge_metadata, store_changegroup, Dag, Store};
use crate::util::{
Expand Down Expand Up @@ -1169,7 +1171,7 @@ fn get_initial_bundle(
.flatten()
{
eprintln!("Getting clone bundle from {}", url);
let mut bundle_conn = get_connection(&url).unwrap();
let mut bundle_conn = get_bundle_connection(&url).unwrap();
match get_store_bundle(store, &mut *bundle_conn, &[], &[]) {
Ok(()) => {
return Ok(true);
Expand Down Expand Up @@ -1390,6 +1392,14 @@ pub fn get_cinnabarclone_url(
None
}

pub fn get_bundle_connection(url: &Url) -> Option<Box<dyn HgRepo>> {
let mut req = HttpRequest::new(url.clone());
if unsafe { http_follow_config } == http_follow_config::HTTP_FOLLOW_INITIAL {
req.follow_redirects(true);
}
Some(Box::new(BundleConnection::new(req.execute().ok()?)))
}

pub fn get_connection(url: &Url) -> Option<Box<dyn HgRepo>> {
let conn = if ["http", "https"].contains(&url.scheme()) {
get_http_connection(url)?
Expand Down
12 changes: 7 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ use graft::{graft_finish, grafted, init_graft};
use hg::{HgChangesetId, HgFileId, HgManifestId, ManifestEntry};
use hg_bundle::{create_bundle, create_chunk_data, read_rev_chunk, BundleSpec, RevChunkIter};
use hg_connect::{
get_bundle, get_clonebundle_url, get_connection, get_store_bundle, HgConnection,
HgConnectionBase, HgRepo,
get_bundle, get_bundle_connection, get_clonebundle_url, get_connection, get_store_bundle,
HgConnection, HgConnectionBase, HgRepo,
};
use itertools::EitherOrBoth::{Both, Left, Right};
use itertools::{EitherOrBoth, Itertools};
Expand Down Expand Up @@ -1902,15 +1902,17 @@ fn do_unbundle(store: &mut Store, clonebundle: bool, mut url: OsString) -> Resul
if graft_config_enabled(None)?.unwrap_or(false) {
init_graft(store);
}
if clonebundle {
let mut conn = if clonebundle {
let mut conn = get_connection(&url).unwrap();
if conn.get_capability(b"clonebundles").is_none() {
Err("Repository does not support clonebundles")?;
}
url = get_clonebundle_url(&mut *conn).ok_or("Repository didn't provide a clonebundle")?;
eprintln!("Getting clone bundle from {}", url);
}
let mut conn = get_connection(&url).unwrap();
get_bundle_connection(&url).unwrap()
} else {
get_connection(&url).unwrap()
};

get_store_bundle(store, &mut *conn, &[], &[])
.map_err(|e| String::from_utf8_lossy(&e).into_owned())?;
Expand Down

0 comments on commit b01ca2e

Please sign in to comment.