Skip to content

Commit e2c61e9

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 8ab4b68 commit e2c61e9

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

@@ -285,6 +284,11 @@ impl<'a> GitCheckout<'a> {
285284
}
286285
}
287286

287+
/// Gets the remote repository URL.
288+
fn remote_url(&self) -> &Url {
289+
&self.database.remote.url()
290+
}
291+
288292
/// Clone a repo for a `revision` into a local path from a `datatabase`.
289293
/// This is a filesystem-to-filesystem clone.
290294
fn clone_into(
@@ -392,8 +396,8 @@ impl<'a> GitCheckout<'a> {
392396
/// Submodules set to `none` won't be fetched.
393397
///
394398
/// [^1]: <https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-none>
395-
fn update_submodules(&self, cargo_config: &Config, parent_remote_url: &Url) -> CargoResult<()> {
396-
return update_submodules(&self.repo, cargo_config, parent_remote_url);
399+
fn update_submodules(&self, cargo_config: &Config) -> CargoResult<()> {
400+
return update_submodules(&self.repo, cargo_config, self.remote_url());
397401

398402
/// Recusive helper for [`GitCheckout::update_submodules`].
399403
fn update_submodules(

0 commit comments

Comments
 (0)