Skip to content

Commit

Permalink
refactor: deduce parent_remote_url from database.remote.url()
Browse files Browse the repository at this point in the history
This should be less controversial as the current logic share the
same `GitRemote`. You can see the callsite of `GitDatabase::copy_to`
use `self.url()`, which then calls into `self.remote.url(). When a
`GitDatabase` is created, Cargo also uses `self.remote` as the
remote of that `GitDatabase`.
  • Loading branch information
weihanglo committed May 31, 2023
1 parent 078da5a commit 88845b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/cargo/sources/git/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ impl<'cfg> Source for GitSource<'cfg> {
.join("checkouts")
.join(&self.ident)
.join(short_id.as_str());
let parent_remote_url = self.url();
db.copy_to(actual_rev, &checkout_path, self.config, parent_remote_url)?;
db.copy_to(actual_rev, &checkout_path, self.config)?;

let source_id = self.source_id.with_precise(Some(actual_rev.to_string()));
let path_source = PathSource::new_recursive(&checkout_path, source_id, self.config);
Expand Down
12 changes: 8 additions & 4 deletions src/cargo/sources/git/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ impl GitDatabase {
rev: git2::Oid,
dest: &Path,
cargo_config: &Config,
parent_remote_url: &Url,
) -> CargoResult<GitCheckout<'_>> {
// If the existing checkout exists, and it is fresh, use it.
// A non-fresh checkout can happen if the checkout operation was
Expand All @@ -193,7 +192,7 @@ impl GitDatabase {
Some(co) => co,
None => GitCheckout::clone_into(dest, self, rev, cargo_config)?,
};
checkout.update_submodules(cargo_config, parent_remote_url)?;
checkout.update_submodules(cargo_config)?;
Ok(checkout)
}

Expand Down Expand Up @@ -280,6 +279,11 @@ impl<'a> GitCheckout<'a> {
}
}

/// Gets the remote repository URL.
fn remote_url(&self) -> &Url {
&self.database.remote.url()
}

/// Clone a repo for a `revision` into a local path from a `datatabase`.
/// This is a filesystem-to-filesystem clone.
fn clone_into(
Expand Down Expand Up @@ -387,8 +391,8 @@ impl<'a> GitCheckout<'a> {
/// Submodules set to `none` won't be fetched.
///
/// [^1]: <https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-none>
fn update_submodules(&self, cargo_config: &Config, parent_remote_url: &Url) -> CargoResult<()> {
return update_submodules(&self.repo, cargo_config, parent_remote_url);
fn update_submodules(&self, cargo_config: &Config) -> CargoResult<()> {
return update_submodules(&self.repo, cargo_config, self.remote_url());

/// Recusive helper for [`GitCheckout::update_submodules`].
fn update_submodules(
Expand Down

0 comments on commit 88845b9

Please sign in to comment.