libfetchers/mercurial: count revisions properly

The Mercurial fetcher previously used the revision number supplied by Mercurial
as its revision count. This is inappropriate, as the revision number is
incremented each time a change is added to the local repository, so also
changes only reachable from other heads will be counted. For the same reason,
it will also depend on whether such changes have been fetched before from the
same repository, introducing an impurity. Instead the revisions have to be
counted explicitly, similar to the Git fetcher.

Change-Id: Idb1e66ae2fb8b05101116c815f453efd6e95b09e
This commit is contained in:
Alois Wohlschlager
2024-12-29 10:28:43 +01:00
parent 92ed9fee7d
commit 54fac65fca
3 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -288,7 +288,7 @@ struct MercurialInputScheme : InputScheme
}
auto tokens = tokenizeString<std::vector<std::string>>(
runHg({ "log", "-R", cacheDir, "-r", revOrRef, "--template", "{node} {rev} {branch}" }));
runHg({ "log", "-R", cacheDir, "-r", revOrRef, "--template", "{node} {count(revset('::{rev}'))} {branch}" }));
assert(tokens.size() == 3);
input.attrs.insert_or_assign("rev", Hash::parseAny(tokens[0], HashType::SHA1).gitRev());
+1 -1
View File
@@ -54,7 +54,7 @@ path2=$(nix eval --impure --raw --expr "(builtins.fetchMercurial \"file://$repo\
[[ $path = $path2 ]]
[[ $(nix eval --impure --raw --expr "(builtins.fetchMercurial \"file://$repo\").branch") = default ]]
[[ $(nix eval --impure --expr "(builtins.fetchMercurial \"file://$repo\").revCount") = 1 ]]
[[ $(nix eval --impure --expr "(builtins.fetchMercurial \"file://$repo\").revCount") = 2 ]]
[[ $(nix eval --impure --raw --expr "(builtins.fetchMercurial \"file://$repo\").rev") = $rev2 ]]
# But with TTL 0, it should fail.
+1 -1
View File
@@ -37,7 +37,7 @@ hg commit --config ui.username=foobar@example.org $flake2Dir -m 'Add lock file'
nix flake metadata --json hg+file://$flake2Dir --refresh | jq -e -r .revision
nix flake metadata --json hg+file://$flake2Dir
[[ $(nix flake metadata --json hg+file://$flake2Dir | jq -e -r .revCount) = 1 ]]
[[ $(nix flake metadata --json hg+file://$flake2Dir | jq -e -r .revCount) = 2 ]]
nix build -o $TEST_ROOT/result hg+file://$flake2Dir --no-registries --no-allow-dirty
nix build -o $TEST_ROOT/result hg+file://$flake2Dir --no-use-registries --no-allow-dirty