# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1742513830 -3600
#      Fri Mar 21 00:37:10 2025 +0100
# Node ID 8a83a1249a5c3424aff8715459377d429cadaa29
# Parent  ebc14cd7edc5464ceef9bfda6e7ce76a3908ad10
ruff: reformat the code base

diff --git a/python-libs/poulpe/scheduling.py b/python-libs/poulpe/scheduling.py
--- a/python-libs/poulpe/scheduling.py
+++ b/python-libs/poulpe/scheduling.py
@@ -468,13 +468,13 @@
         # TODO make a "poulpe resolve-bin-env-spec"?
         cmd = [setup_script.resolve(), "--get-unique-id"] + cli_args_list
 
-
         # Get the actual unique bin-env ID that only the suite can resolve
         # (because of its dependencies, etc.)
         res = subprocess.run(
             cmd,
             cwd=tmp_target,
-            env=env, capture_output=True,
+            env=env,
+            capture_output=True,
         )
         try:
             res.check_returncode()
# HG changeset patch
# User Raphaël Gomès <rgomes@octobus.net>
# Date 1740579698 18000
#      Wed Feb 26 09:21:38 2025 -0500
# Node ID 9dd5c37d318bc8c80bc7c08ef5457802ea582af6
# Parent  8a83a1249a5c3424aff8715459377d429cadaa29
hg: use `-r` instead of `--rev` in certain benchmarks

Unfortunately, there is a bug in `rhg files` that went unnoticed until now,
where it expects the long flag `--revision` instead of `--rev`. Since Poulpe
cares about maximizing compatibility, we use the short flag.

diff --git a/suites/hg/benchmarks/cat.pbd b/suites/hg/benchmarks/cat.pbd
--- a/suites/hg/benchmarks/cat.pbd
+++ b/suites/hg/benchmarks/cat.pbd
@@ -23,13 +23,13 @@
 cwd = "DATA-VARS:mercurial.main-repo-path"
 
 [simple-command.variants.dimensions.rev.working-copy.environment]
-REV = "--rev wdir()"
+REV = "-r wdir()"
 
 [simple-command.variants.dimensions.rev.tip]
 default = true
 
 [simple-command.variants.dimensions.rev.tip.environment]
-REV = "--rev tip"
+REV = "-r tip"
 
 [simple-command.variants.dimensions.rev.default.environment]
 REV = ""
diff --git a/suites/hg/benchmarks/files.pbd b/suites/hg/benchmarks/files.pbd
--- a/suites/hg/benchmarks/files.pbd
+++ b/suites/hg/benchmarks/files.pbd
@@ -26,7 +26,7 @@
 REV = ""
 
 [simple-command.variants.dimensions.rev.tip.environment]
-REV = "--rev tip"
+REV = "-r tip"
 
 [simple-command.variants.dimensions.rev.default]
 default = true
diff --git a/suites/hg/benchmarks/lib/variants.pkl b/suites/hg/benchmarks/lib/variants.pkl
--- a/suites/hg/benchmarks/lib/variants.pkl
+++ b/suites/hg/benchmarks/lib/variants.pkl
@@ -139,12 +139,12 @@
         cases {
             ["working-copy"]{
                 environment {
-                    ["REV"] = "--rev wdir()"
+                    ["REV"] = "-r wdir()"
                 }
             }
             ["tip"]{
                 environment {
-                    ["REV"] = "--rev tip"
+                    ["REV"] = "-r tip"
                 }
             }
             ["default"]{
# HG changeset patch
# User Raphaël Gomès <rgomes@octobus.net>
# Date 1736953851 -3600
#      Wed Jan 15 16:10:51 2025 +0100
# Node ID 5afc8620e1cd3ec61e378a09f0c150a939aac8ff
# Parent  9dd5c37d318bc8c80bc7c08ef5457802ea582af6
hg-benchmarks: add FILE variants for listing files with large history

This will be useful for annotate, grep, etc.

diff --git a/suites/hg/benchmarks/lib/variants.pkl b/suites/hg/benchmarks/lib/variants.pkl
--- a/suites/hg/benchmarks/lib/variants.pkl
+++ b/suites/hg/benchmarks/lib/variants.pkl
@@ -169,6 +169,10 @@
             }
         }
     }
+
+    // variante providing files patterns to access in a single revision
+    //
+    // used for example for `hg cat`, or `hg files`
     ["rev-reading-files"] {
         default_key = "all-root"
         cases {
@@ -217,6 +221,21 @@
             }
         }
     }
+    // single file that has an interresting file history
+    //
+    // to be used by thing like `hg annotate` or `hg log`
+    ["file-reading-revs"] {
+        default_key = "all-root"
+        cases {
+            for (suffix in List("a", "b", "c", "d", "e")) {
+                ["file-with-long-history.\(suffix)"] {
+                    environment {
+                        ["FILES"] = "DATA-VARS:mercurial.file-with-long-history.\(suffix)"
+                    }
+                }
+            }
+        }
+    }
     // repo state should probably be split into multiple dimensions.
     //
     // However, that would be harder to do with the currently limited variant
# HG changeset patch
# User Raphaël Gomès <rgomes@octobus.net>
# Date 1736953906 -3600
#      Wed Jan 15 16:11:46 2025 +0100
# Node ID d8a701edf022c09a3a7cf8a0de5c583b44a37d22
# Parent  5afc8620e1cd3ec61e378a09f0c150a939aac8ff
hg-benchmarks: add an annotate benchmark

diff --git a/suites/hg/benchmarks/annotate.pbd b/suites/hg/benchmarks/annotate.pbd
new file mode 100644
--- /dev/null
+++ b/suites/hg/benchmarks/annotate.pbd
@@ -0,0 +1,47 @@
+[meta]
+format = "0"
+name = "hg.command.annotate"
+method = "simple-command"
+
+[run]
+copy-data-env = false
+
+[simple-command]
+command = "hg annotate $FILES > /dev/null"
+cwd = "DATA-VARS:mercurial.main-repo-path"
+
+[simple-command.variants.dimensions.files."file-with-long-history.a"]
+default = true
+
+[simple-command.variants.dimensions.files."file-with-long-history.a".environment]
+FILES = "DATA-VARS:mercurial.file-with-long-history.a"
+
+[simple-command.variants.dimensions.files."file-with-long-history.b".environment]
+FILES = "DATA-VARS:mercurial.file-with-long-history.b"
+
+[simple-command.variants.dimensions.files."file-with-long-history.c".environment]
+FILES = "DATA-VARS:mercurial.file-with-long-history.c"
+
+[simple-command.variants.dimensions.files."file-with-long-history.d".environment]
+FILES = "DATA-VARS:mercurial.file-with-long-history.d"
+
+[simple-command.variants.dimensions.files."file-with-long-history.e".environment]
+FILES = "DATA-VARS:mercurial.file-with-long-history.e"
+
+[simple-command.variants.dimensions.follow-copies.yes]
+default = true
+
+[simple-command.variants.dimensions.follow-copies.no]
+extend-command = " --no-follow"
+
+[simple-command.variants.dimensions.files-as-text.yes]
+extend-command = " --text"
+
+[simple-command.variants.dimensions.files-as-text.no]
+default = true
+
+[simple-command.variants.dimensions.listed.default]
+default = true
+
+[simple-command.variants.dimensions.listed.all]
+extend-command = " --user --file --date --changeset --line-number"
diff --git a/suites/hg/benchmarks/annotate.pkl b/suites/hg/benchmarks/annotate.pkl
new file mode 100644
--- /dev/null
+++ b/suites/hg/benchmarks/annotate.pkl
@@ -0,0 +1,36 @@
+amends "lib/simple-command.pkl"
+import "lib/variants.pkl" as v
+
+name = "hg.command.annotate"
+copy_data_env = false
+
+command = "hg annotate $FILES > /dev/null"
+cwd = "DATA-VARS:mercurial.main-repo-path"
+
+variants {
+    ["files"] = (v.simple_command["file-reading-revs"]) {
+        default_key = "file-with-long-history.a"
+    }
+    ["follow-copies"] {
+        default_key = "yes"
+        cases {
+            ["yes"]{}
+            ["no"]{extend_command = " --no-follow"}
+        }
+    }
+    ["files-as-text"] {
+        default_key = "no"
+        cases {
+            ["yes"]{extend_command = " --text"}
+            ["no"]{}
+        }
+    }
+    ["listed"] {
+        default_key = "default"
+        cases {
+            ["default"] {}
+            ["all"] {extend_command = " --user --file --date --changeset --line-number"}
+
+        }
+    }
+}
diff --git a/tests/test-setup-poulpe-den.t b/tests/test-setup-poulpe-den.t
--- a/tests/test-setup-poulpe-den.t
+++ b/tests/test-setup-poulpe-den.t
@@ -120,7 +120,7 @@
   data environments:     [OKAY]
     available: 0
   benchmarks:            [OKAY]
-    available: 28
+    available: 29
   results:               [OKAY]
   poulpe suites:         [OKAY]
     available bin setup: 2
@@ -137,7 +137,7 @@
   data environments:     [OKAY]
     available: 0
   benchmarks:            [OKAY]
-    available: 28
+    available: 29
   results:               [OKAY]
   poulpe suites:         [OKAY]
     available bin setup: 2
# HG changeset patch
# User Raphaël Gomès <rgomes@octobus.net>
# Date 1738586996 -3600
#      Mon Feb 03 13:49:56 2025 +0100
# Node ID 9875caa93f61b5172542e6b379e2d877cadc9abb
# Parent  d8a701edf022c09a3a7cf8a0de5c583b44a37d22
hg-data-env-setup: record information about files worth testing `annotate` on

This is quite slow because it needs to get the size for all filelogs ever,
and it does so in sequence. We could optimize it, but we don't for now.

diff --git a/suites/hg/data-env-setup/setup-70-annotate.sh b/suites/hg/data-env-setup/setup-70-annotate.sh
new file mode 100755
--- /dev/null
+++ b/suites/hg/data-env-setup/setup-70-annotate.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+# Simple script to record the most interesting files for benchmarking annotate
+#
+# You still have to build the env by hand.
+set -Eeuo pipefail
+
+if [ $# -ne 1 ]; then
+    echo >&2 "USAGE: setup-70-annotate.sh DATA-ENV-PATH"
+    echo >&2 "  DATA-ENV-PATH: the path to that data-env"
+    exit 32
+fi
+
+data_env_directory=$1
+desc="${data_env_directory}/data-env.poulpe"
+
+repository_path="$(poulpe env-desc get "$desc" bench-input-vars.mercurial.main-repo-path)"
+
+repo="$data_env_directory/$repository_path"
+
+INDEX=0
+
+suffixes=("a" "b" "c" "d" "e")
+
+for filename in $(
+    hg -R "$repo" debug-revlog-stats -f | \
+        tail -n +2 | \
+        awk '{print $1, $5}' | \
+        sort -n | \
+        tail -n 5 | \
+        cut -f2 -d' ' | \
+        tac
+    ); do
+    poulpe env-desc set "$desc" \
+        "bench-input-vars.mercurial.file-with-long-history.${suffixes[INDEX]}" \
+        "$filename"
+    ((INDEX=INDEX+1))
+done
diff --git a/suites/hg/data-env-setup/setup-full.py b/suites/hg/data-env-setup/setup-full.py
--- a/suites/hg/data-env-setup/setup-full.py
+++ b/suites/hg/data-env-setup/setup-full.py
@@ -141,6 +141,12 @@
             check=True,
         )
 
+    click.echo("Setting up `annotate` benchmark (can take up to a few minutes)")
+    subprocess.run(
+        [SCRIPT_DIR / "setup-70-annotate.sh", data_env],
+        check=True,
+    )
+
 
 if __name__ == "__main__":
     setup_full()
diff --git a/tests/test-data-env-listing.t b/tests/test-data-env-listing.t
--- a/tests/test-data-env-listing.t
+++ b/tests/test-data-env-listing.t
@@ -34,6 +34,7 @@
   Warning: running setup-working-copy without a data brick
   (non-default working-copy variants will be unavailable)
   Setting up `delta-find` benchmark (can take a very long time)
+  Setting up `annotate` benchmark (can take up to a few minutes)
   Creating the base data-env
   creating new file: "$TESTTMP/listing-test-den/data-env-2/data-env.poulpe"
   Registering graph details
@@ -42,6 +43,7 @@
   Warning: running setup-working-copy without a data brick
   (non-default working-copy variants will be unavailable)
   Setting up `delta-find` benchmark (can take a very long time)
+  Setting up `annotate` benchmark (can take up to a few minutes)
 
 Test listing itself
 ===================
diff --git a/tests/test-data-setup.t b/tests/test-data-setup.t
--- a/tests/test-data-setup.t
+++ b/tests/test-data-setup.t
@@ -111,6 +111,7 @@
   Applying hg::working-copy.copy-files with params {'files_pairs_list': 'copied.list'}
   Applying poulpe::modify-files with params {'files_list': 'modified.list'}
   Setting up `delta-find` benchmark (can take a very long time)
+  Setting up `annotate` benchmark (can take up to a few minutes)
 
   $ cd my-data-env
   $ poulpe env-desc show data-env.poulpe
@@ -124,6 +125,12 @@
     - mercurial.working-copy.modified-and-copied
   bench-input-vars:
     mercurial:
+      file-with-long-history:
+        a = removed-9
+        b = removed-8
+        c = removed-7
+        d = removed-6
+        e = removed-5
       main-repo-path = base-repo
       revlog:
         delta-find:
diff --git a/tests/test-tasks-consumption.t b/tests/test-tasks-consumption.t
--- a/tests/test-tasks-consumption.t
+++ b/tests/test-tasks-consumption.t
@@ -34,6 +34,7 @@
   Warning: running setup-working-copy without a data brick
   (non-default working-copy variants will be unavailable)
   Setting up `delta-find` benchmark (can take a very long time)
+  Setting up `annotate` benchmark (can take up to a few minutes)
   Creating the base data-env
   creating new file: "$TESTTMP/running-test-den/data-env-2/data-env.poulpe"
   Registering graph details
@@ -42,6 +43,7 @@
   Warning: running setup-working-copy without a data brick
   (non-default working-copy variants will be unavailable)
   Setting up `delta-find` benchmark (can take a very long time)
+  Setting up `annotate` benchmark (can take up to a few minutes)
 
 Test execution of tasks
 =======================
diff --git a/tests/test-tasks-generation.t b/tests/test-tasks-generation.t
--- a/tests/test-tasks-generation.t
+++ b/tests/test-tasks-generation.t
@@ -46,6 +46,7 @@
   Warning: running setup-working-copy without a data brick
   (non-default working-copy variants will be unavailable)
   Setting up `delta-find` benchmark (can take a very long time)
+  Setting up `annotate` benchmark (can take up to a few minutes)
   Creating the base data-env
   creating new file: "$TESTTMP/listing-test-den/data-env-2/data-env.poulpe"
   Registering graph details
@@ -54,6 +55,7 @@
   Warning: running setup-working-copy without a data brick
   (non-default working-copy variants will be unavailable)
   Setting up `delta-find` benchmark (can take a very long time)
+  Setting up `annotate` benchmark (can take up to a few minutes)
 
 Test generation of Tasks
 ========================