From 54fac65fcadb2ce19b14676ca096f9b9781fbfc6 Mon Sep 17 00:00:00 2001 From: Alois Wohlschlager Date: Sat, 28 Dec 2024 18:55:26 +0100 Subject: [PATCH] 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 --- lix/libfetchers/mercurial.cc | 2 +- tests/functional/fetchMercurial.sh | 2 +- tests/functional/flakes/mercurial.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lix/libfetchers/mercurial.cc b/lix/libfetchers/mercurial.cc index 3454d58ba..eda49f93c 100644 --- a/lix/libfetchers/mercurial.cc +++ b/lix/libfetchers/mercurial.cc @@ -288,7 +288,7 @@ struct MercurialInputScheme : InputScheme } auto tokens = tokenizeString>( - 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()); diff --git a/tests/functional/fetchMercurial.sh b/tests/functional/fetchMercurial.sh index d82347829..624705e9b 100644 --- a/tests/functional/fetchMercurial.sh +++ b/tests/functional/fetchMercurial.sh @@ -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. diff --git a/tests/functional/flakes/mercurial.sh b/tests/functional/flakes/mercurial.sh index 7074af6f7..b5756a3ea 100644 --- a/tests/functional/flakes/mercurial.sh +++ b/tests/functional/flakes/mercurial.sh @@ -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