cargo update: Don't fetch from the remote repo if the revision is already present locally#10288
cargo update: Don't fetch from the remote repo if the revision is already present locally#10288jyn514 wants to merge 1 commit into
cargo update: Don't fetch from the remote repo if the revision is already present locally#10288Conversation
|
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
Oh interesting, there's already a check for this at https://github.com/rust-lang/cargo/blob/ba9f2f80dd439bf38e81dcf907c1c06cfe9bf371/src/cargo/sources/git/source.rs#L114-L123 - I think I can move that into |
|
Ah wait no, |
ba9f2f8 to
79860aa
Compare
|
I am not following this super closely and it seems like this is rapidly changing. I wanted to say though that as a heads up the premise of this PR I think is flawed. A reference to something like a branch cannot check to see if there's a local copy since we need to check the remote to see if there's a more up-to-date version. The only case we can skip the remote update is if we have a locked git sha and that's already local. Just because we have |
cargo update: Don't fetch from the remote repo if the revision is already present locally
Ok, I can ensure this only happens when the revision is a locked sha and not a branch. The reason I opened this in the first place though is because cargo was updating the remote even when it's locked to a sha. |
79860aa to
9242fc5
Compare
|
I'm done changing this for now (except for addressing review comments) :) |
…ocally
This makes `cargo update` *much* faster when there are many git deps in a repo and they're already
cached locally.
There was an existing check for this, but it didn't quite hit all cases.
The code looked like this:
```rust
let (db, actual_rev) = match (self.locked_rev, db) {
(Some(rev), Some(db)) if db.contains(rev) => (db, rev),
(None, Some(db)) if self.config.offline() => {
let rev = db.resolve(&self.manifest_reference)?;
(db, rev)
}
(locked_rev, db) => self.remote.checkout(),
};
```
The problem was that when `locked_rev.is_none() && db.is_some()` and `--offline` wasn't passed,
cargo would skip the `db.resolve()` check, and issue a fetch from the remote even if it wasn't
necessary.
This changes the `db.resolve()` check to happen even in online mode.
This brings `cargo update` down from 53 to 6 seconds for me on a codebase with 10+ git dependencies.
9242fc5 to
acb6ce1
Compare
|
A git revision can be a tag or sha or anything. I don't think we can simply search it in the local db. Especially when it cannot be parsed as a commit object. For instance, the rev is a tag and chances are that the remote tag has been updated to point to another commit but our local database is still stale. |
|
Maybe something like this to check if the rev is a commit sha |
|
I found this doesn't actually fix my problem. Sorry for the noise. |
This makes
cargo updatemuch faster when there are many git deps in a repo and they're alreadycached locally.
There was an existing check for this, but it didn't quite hit all cases.
The code looked like this:
The problem was that when
locked_rev.is_none() && db.is_some()and--offlinewasn't passed,cargo would skip the
db.resolve()check, and issue a fetch from the remote even if it wasn'tnecessary.
This changes the
db.resolve()check to happen even in online mode.This brings
cargo updatedown from 53 to 6 seconds for me on a codebase with 10+ git dependencies.