Skip to content

Commit 88845b9

Browse files
committed
refactor: deduce parent_remote_url from database.remote.url()
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`.
1 parent 078da5a commit 88845b9

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/cargo/sources/git/source.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,7 @@ impl<'cfg> Source for GitSource<'cfg> {
279279
.join("checkouts")
280280
.join(&self.ident)
281281
.join(short_id.as_str());
282-
let parent_remote_url = self.url();
283-
db.copy_to(actual_rev, &checkout_path, self.config, parent_remote_url)?;
282+
db.copy_to(actual_rev, &checkout_path, self.config)?;
284283

285284
let source_id = self.source_id.with_precise(Some(actual_rev.to_string()));
286285
let path_source = PathSource::new_recursive(&checkout_path, source_id, self.config);

src/cargo/sources/git/utils.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ impl GitDatabase {
179179
rev: git2::Oid,
180180
dest: &Path,
181181
cargo_config: &Config,
182-
parent_remote_url: &Url,
183182
) -> CargoResult<GitCheckout<'_>> {
184183
// If the existing checkout exists, and it is fresh, use it.
185184
// A non-fresh checkout can happen if the checkout operation was
@@ -193,7 +192,7 @@ impl GitDatabase {
193192
Some(co) => co,
194193
None => GitCheckout::clone_into(dest, self, rev, cargo_config)?,
195194
};
196-
checkout.update_submodules(cargo_config, parent_remote_url)?;
195+
checkout.update_submodules(cargo_config)?;
197196
Ok(checkout)
198197
}
199198

@@ -280,6 +279,11 @@ impl<'a> GitCheckout<'a> {
280279
}
281280
}
282281

282+
/// Gets the remote repository URL.
283+
fn remote_url(&self) -> &Url {
284+
&self.database.remote.url()
285+
}
286+
283287
/// Clone a repo for a `revision` into a local path from a `datatabase`.
284288
/// This is a filesystem-to-filesystem clone.
285289
fn clone_into(
@@ -387,8 +391,8 @@ impl<'a> GitCheckout<'a> {
387391
/// Submodules set to `none` won't be fetched.
388392
///
389393
/// [^1]: <https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-none>
390-
fn update_submodules(&self, cargo_config: &Config, parent_remote_url: &Url) -> CargoResult<()> {
391-
return update_submodules(&self.repo, cargo_config, parent_remote_url);
394+
fn update_submodules(&self, cargo_config: &Config) -> CargoResult<()> {
395+
return update_submodules(&self.repo, cargo_config, self.remote_url());
392396

393397
/// Recusive helper for [`GitCheckout::update_submodules`].
394398
fn update_submodules(

0 commit comments

Comments
 (0)