Skip to content

Commit 6bf5230

Browse files
authored
Merge pull request #269 from DeterminateSystems/skip-revCount
Git fetcher: Don't compute revCount/lastModified if they're already specified
2 parents f5e7146 + 5c9b85e commit 6bf5230

File tree

4 files changed

+12
-25
lines changed

4 files changed

+12
-25
lines changed

src/libfetchers/fetchers.cc

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,24 +276,10 @@ 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());
291282
}
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-
}
297283
}
298284

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

src/libfetchers/git.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -738,13 +738,17 @@ struct GitInputScheme : InputScheme
738738

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

741-
Attrs infoAttrs({
742-
{"rev", rev.gitRev()},
743-
{"lastModified", getLastModified(settings, repoInfo, repoDir, rev)},
744-
});
745-
746-
if (!getShallowAttr(input))
747-
infoAttrs.insert_or_assign("revCount", getRevCount(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));
746+
747+
if (!getShallowAttr(input)) {
748+
/* Like lastModified, skip revCount if supplied by the caller. */
749+
if (!input.attrs.contains("revCount"))
750+
input.attrs.insert_or_assign("revCount", getRevCount(settings, repoInfo, repoDir, rev));
751+
}
748752

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

@@ -800,9 +804,6 @@ struct GitInputScheme : InputScheme
800804
}
801805

802806
assert(!origRev || origRev == rev);
803-
if (!getShallowAttr(input))
804-
input.attrs.insert_or_assign("revCount", getIntAttr(infoAttrs, "revCount"));
805-
input.attrs.insert_or_assign("lastModified", getIntAttr(infoAttrs, "lastModified"));
806807

807808
return {accessor, std::move(input)};
808809
}

tests/nixos/content-encoding.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ in
131131
start_all()
132132
133133
machine.wait_for_unit("nginx.service")
134+
machine.wait_for_open_port(80)
134135
135136
# Original test: zstd archive with gzip content-encoding
136137
# Make sure that the file is properly compressed as the test would be meaningless otherwise

tests/nixos/tarball-flakes.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ in
9898
9999
# Check that fetching fails if we provide incorrect attributes.
100100
machine.fail("nix flake metadata --json http://localhost/tags/latest.tar.gz?rev=493300eb13ae6fb387fbd47bf54a85915acc31c0")
101-
machine.fail("nix flake metadata --json http://localhost/tags/latest.tar.gz?revCount=789")
102101
machine.fail("nix flake metadata --json http://localhost/tags/latest.tar.gz?narHash=sha256-tbudgBSg+bHWHiHnlteNzN8TUvI80ygS9IULh4rklEw=")
103102
'';
104103

0 commit comments

Comments
 (0)