Skip to content

Commit 44be1fc

Browse files
committed
Git fetcher: Don't compute revCount if it's already specified
We don't care if the user (or more likely the lock file) specifies an incorrect value for revCount, since it doesn't matter for security (unlikely content hashes like narHash).
1 parent 34fcfa5 commit 44be1fc

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/libfetchers/fetchers.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,6 @@ void Input::checkLocks(Input specified, Input & result)
289289
if (result.getRev() != prevRev)
290290
throw Error("'rev' attribute mismatch in input '%s', expected %s", result.to_string(), prevRev->gitRev());
291291
}
292-
293-
if (auto prevRevCount = specified.getRevCount()) {
294-
if (result.getRevCount() != prevRevCount)
295-
throw Error("'revCount' attribute mismatch in input '%s', expected %d", result.to_string(), *prevRevCount);
296-
}
297292
}
298293

299294
std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settings, ref<Store> store) const

src/libfetchers/git.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,13 @@ struct GitInputScheme : InputScheme
740740

741741
input.attrs.insert_or_assign("lastModified", getLastModified(settings, repoInfo, repoDir, rev));
742742

743-
if (!getShallowAttr(input))
744-
input.attrs.insert_or_assign("revCount", getRevCount(settings, repoInfo, repoDir, rev));
743+
if (!getShallowAttr(input)) {
744+
/* Skip revCount computation if it's already supplied by the caller.
745+
We don't care if they specify an incorrect value; it doesn't
746+
matter for security, unlike narHash. */
747+
if (!input.attrs.contains("revCount"))
748+
input.attrs.insert_or_assign("revCount", getRevCount(settings, repoInfo, repoDir, rev));
749+
}
745750

746751
printTalkative("using revision %s of repo '%s'", rev.gitRev(), repoInfo.locationToArg());
747752

0 commit comments

Comments
 (0)