Patchwork contrib: add a helper script that help to build interesting repositories

login
register
mail settings
Submitter Boris Feld
Date Dec. 3, 2018, 8:51 a.m.
Message ID <3374ca3b09624245f50f.1543827101@pc62.home>
Download mbox | patch
Permalink /patch/36915/
State Accepted
Headers show

Comments

Boris Feld - Dec. 3, 2018, 8:51 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1543378018 -3600
#      Wed Nov 28 05:06:58 2018 +0100
# Node ID 3374ca3b09624245f50f8e7ca556451198ac9b26
# Parent  0800d9e6e216b2ca59f05788b288685b8d7b2d93
# EXP-Topic discovery-helper
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 3374ca3b0962
contrib: add a helper script that help to build interesting repositories

The script is dedicated to building a couple of repositories that should be
interesting to run discovery from one another. It seems a common enough need
to contribute it upstream.
Yuya Nishihara - Dec. 4, 2018, 11:24 a.m.
On Mon, 03 Dec 2018 09:51:41 +0100, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1543378018 -3600
> #      Wed Nov 28 05:06:58 2018 +0100
> # Node ID 3374ca3b09624245f50f8e7ca556451198ac9b26
> # Parent  0800d9e6e216b2ca59f05788b288685b8d7b2d93
> # EXP-Topic discovery-helper
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 3374ca3b0962
> contrib: add a helper script that help to build interesting repositories

Looks good. Queued, thanks.

Patch

diff --git a/contrib/discovery-helper.sh b/contrib/discovery-helper.sh
new file mode 100755
--- /dev/null
+++ b/contrib/discovery-helper.sh
@@ -0,0 +1,64 @@ 
+#!/bin/bash
+#
+# produces two repositories with different common and missing subsets
+#
+#   $ discovery-helper.sh REPO NBHEADS DEPT
+#
+# The Goal is to produce two repositories with some common part and some
+# exclusive part on each side. Provide a source repository REPO, it will
+# produce two repositories REPO-left and REPO-right.
+#
+# Each repository will be missing some revisions exclusive to NBHEADS of the
+# repo topological heads. These heads and revisions exclusive to them (up to
+# DEPTH depth) are stripped.
+#
+# The "left" repository will use the NBHEADS first heads (sorted by
+# description). The "right" use the last NBHEADS one.
+#
+# To find out how many topological heads a repo has, use:
+#
+#   $ hg heads -t -T '{rev}\n' | wc -l
+#
+# Example:
+#
+#  The `pypy-2018-09-01` repository has 192 heads. To produce two repositories
+#  with 92 common heads and ~50 exclusive heads on each side.
+#
+#    $ ./discovery-helper.sh pypy-2018-08-01 50 10
+
+set -euo pipefail
+
+if [ $# -lt 3 ]; then
+     echo "usage: `basename $0` REPO NBHEADS DEPTH"
+     exit 64
+fi
+
+repo="$1"
+shift
+
+nbheads="$1"
+shift
+
+depth="$1"
+shift
+
+leftrepo="${repo}-left"
+rightrepo="${repo}-right"
+
+left="first(sort(heads(all()), 'desc'), $nbheads)"
+right="last(sort(heads(all()), 'desc'), $nbheads)"
+
+leftsubset="ancestors($left, $depth) and only($left, heads(all() - $left))"
+rightsubset="ancestors($right, $depth) and only($right, heads(all() - $right))"
+
+echo '### building left repository:' $left-repo
+echo '# cloning'
+hg clone --noupdate "${repo}" "${leftrepo}"
+echo '# stripping' '"'${leftsubset}'"'
+hg -R "${leftrepo}" --config extensions.strip= strip --rev "$leftsubset" --no-backup
+
+echo '### building right repository:' $right-repo
+echo '# cloning'
+hg clone --noupdate "${repo}" "${rightrepo}"
+echo '# stripping:' '"'${rightsubset}'"'
+hg -R "${rightrepo}" --config extensions.strip= strip --rev "$rightsubset" --no-backup