Skip to content

Commit ff1b4ea

Browse files
committed
Git fetcher: Don't compute lastModified if it's already specified
Same as revCount.
1 parent 44be1fc commit ff1b4ea

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

src/libfetchers/fetchers.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,6 @@ void Input::checkLocks(Input specified, Input & result)
276276
}
277277
}
278278

279-
if (auto prevLastModified = specified.getLastModified()) {
280-
if (result.getLastModified() != prevLastModified)
281-
throw Error(
282-
"'lastModified' attribute mismatch in input '%s', expected %d, got %d",
283-
result.to_string(),
284-
*prevLastModified,
285-
result.getLastModified().value_or(-1));
286-
}
287-
288279
if (auto prevRev = specified.getRev()) {
289280
if (result.getRev() != prevRev)
290281
throw Error("'rev' attribute mismatch in input '%s', expected %s", result.to_string(), prevRev->gitRev());

src/libfetchers/git.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -738,12 +738,14 @@ struct GitInputScheme : InputScheme
738738

739739
auto rev = *input.getRev();
740740

741-
input.attrs.insert_or_assign("lastModified", getLastModified(settings, repoInfo, repoDir, rev));
741+
/* Skip lastModified computation if it's already supplied by the caller.
742+
We don't care if they specify an incorrect value; it doesn't
743+
matter for security, unlike narHash. */
744+
if (!input.attrs.contains("lastModified"))
745+
input.attrs.insert_or_assign("lastModified", getLastModified(settings, repoInfo, repoDir, rev));
742746

743747
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. */
748+
/* Like lastModified, skip revCount if supplied by the caller. */
747749
if (!input.attrs.contains("revCount"))
748750
input.attrs.insert_or_assign("revCount", getRevCount(settings, repoInfo, repoDir, rev));
749751
}

0 commit comments

Comments
 (0)