author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Wed, 09 Jun 2021 19:47:29 +0200 | |
changeset 47455 | f93a867a6486 |
parent 46772 | 63a3941d9847 |
child 49013 | 186223795e4a |
permissions | -rw-r--r-- |
46766
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 |
"""revset to select sample of repository |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 |
|
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
3 |
Hopefully this is useful to create interesting discovery cases. |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 |
""" |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 |
|
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 |
import collections |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
7 |
import random |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 |
|
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
9 |
from mercurial.i18n import _ |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 |
|
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 |
from mercurial import ( |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 |
registrar, |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 |
revset, |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 |
revsetlang, |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 |
smartset, |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 |
) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 |
|
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 |
revsetpredicate = registrar.revsetpredicate() |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 |
|
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 |
|
46772
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
21 |
@revsetpredicate(b'subsetspec("<spec>")') |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
22 |
def subsetmarkerspec(repo, subset, x): |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
23 |
"""use a shorthand spec as used by search-discovery-case |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
24 |
|
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
25 |
Supported format are: |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
26 |
|
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
27 |
- "scratch-count-seed": not scratch(all(), count, "seed") |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
28 |
- "randomantichain-seed": ::randomantichain(all(), "seed") |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
29 |
- "rev-REV": "::REV" |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
30 |
""" |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
31 |
args = revsetlang.getargs( |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
32 |
x, 0, 1, _(b'subsetspec("spec") required an argument') |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
33 |
) |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
34 |
|
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
35 |
spec = revsetlang.getstring(args[0], _(b"spec should be a string")) |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
36 |
case = spec.split(b'-') |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
37 |
t = case[0] |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
38 |
if t == b'scratch': |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
39 |
spec_revset = b'not scratch(all(), %s, "%s")' % (case[1], case[2]) |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
40 |
elif t == b'randomantichain': |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
41 |
spec_revset = b'::randomantichain(all(), "%s")' % case[1] |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
42 |
elif t == b'rev': |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
43 |
spec_revset = b'::%d' % case[1] |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
44 |
else: |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
45 |
assert False, spec |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
46 |
|
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
47 |
selected = repo.revs(spec_revset) |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
48 |
|
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
49 |
return selected & subset |
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
50 |
|
63a3941d9847
perf-util: add an helper revset to use the same spec as the case search script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46767
diff
changeset
|
51 |
|
46766
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
52 |
@revsetpredicate(b'scratch(REVS, <count>, [seed])') |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
53 |
def scratch(repo, subset, x): |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
54 |
"""randomly remove <count> revision from the repository top |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
55 |
|
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
56 |
This subset is created by recursively picking changeset starting from the |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
57 |
heads. It can be summarized using the following algorithm:: |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
58 |
|
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
59 |
selected = set() |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
60 |
for i in range(<count>): |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
61 |
unselected = repo.revs("not <selected>") |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
62 |
candidates = repo.revs("heads(<unselected>)") |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
63 |
pick = random.choice(candidates) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
64 |
selected.add(pick) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
65 |
""" |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
66 |
m = _(b"scratch expects revisions, count argument and an optional seed") |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
67 |
args = revsetlang.getargs(x, 2, 3, m) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
68 |
if len(args) == 2: |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
69 |
x, n = args |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
70 |
rand = random |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
71 |
elif len(args) == 3: |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
72 |
x, n, seed = args |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
73 |
seed = revsetlang.getinteger(seed, _(b"seed should be a number")) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
74 |
rand = random.Random(seed) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
75 |
else: |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
76 |
assert False |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
77 |
|
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
78 |
n = revsetlang.getinteger(n, _(b"scratch expects a number")) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
79 |
|
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
80 |
selected = set() |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
81 |
heads = set() |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
82 |
children_count = collections.defaultdict(lambda: 0) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
83 |
parents = repo.changelog._uncheckedparentrevs |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
84 |
|
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
85 |
baseset = revset.getset(repo, smartset.fullreposet(repo), x) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
86 |
baseset.sort() |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
87 |
for r in baseset: |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
88 |
heads.add(r) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
89 |
|
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
90 |
p1, p2 = parents(r) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
91 |
if p1 >= 0: |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
92 |
heads.discard(p1) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
93 |
children_count[p1] += 1 |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
94 |
if p2 >= 0: |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
95 |
heads.discard(p2) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
96 |
children_count[p2] += 1 |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
97 |
|
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
98 |
for h in heads: |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
99 |
assert children_count[h] == 0 |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
100 |
|
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
101 |
selected = set() |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
102 |
for x in range(n): |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
103 |
if not heads: |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
104 |
break |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
105 |
pick = rand.choice(list(heads)) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
106 |
heads.remove(pick) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
107 |
assert pick not in selected |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
108 |
selected.add(pick) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
109 |
p1, p2 = parents(pick) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
110 |
if p1 in children_count: |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
111 |
assert p1 in children_count |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
112 |
children_count[p1] -= 1 |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
113 |
assert children_count[p1] >= 0 |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
114 |
if children_count[p1] == 0: |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
115 |
assert p1 not in selected, (r, p1) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
116 |
heads.add(p1) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
117 |
if p2 in children_count: |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
118 |
assert p2 in children_count |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
119 |
children_count[p2] -= 1 |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
120 |
assert children_count[p2] >= 0 |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
121 |
if children_count[p2] == 0: |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
122 |
assert p2 not in selected, (r, p2) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
123 |
heads.add(p2) |
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
124 |
|
cb70dabe5718
perf-helper: add a small extension with revsets to select repository subset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
125 |
return smartset.baseset(selected) & subset |
46767
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
126 |
|
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
127 |
|
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
128 |
@revsetpredicate(b'randomantichain(REVS, [seed])') |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
129 |
def antichain(repo, subset, x): |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
130 |
"""Pick a random anti-chain in the repository |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
131 |
|
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
132 |
A antichain is a set of changeset where there isn't any element that is |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
133 |
either a descendant or ancestors of any other element in the set. In other |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
134 |
word, all the elements are independant. It can be summarized with the |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
135 |
following algorithm:: |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
136 |
|
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
137 |
selected = set() |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
138 |
unselected = repo.revs('all()') |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
139 |
while unselected: |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
140 |
pick = random.choice(unselected) |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
141 |
selected.add(pick) |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
142 |
unselected -= repo.revs('::<pick> + <pick>::') |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
143 |
""" |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
144 |
|
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
145 |
args = revsetlang.getargs( |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
146 |
x, 1, 2, _(b"randomantichain expects revisions and an optional seed") |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
147 |
) |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
148 |
if len(args) == 1: |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
149 |
(x,) = args |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
150 |
rand = random |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
151 |
elif len(args) == 2: |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
152 |
x, seed = args |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
153 |
seed = revsetlang.getinteger(seed, _(b"seed should be a number")) |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
154 |
rand = random.Random(seed) |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
155 |
else: |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
156 |
assert False |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
157 |
|
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
158 |
selected = set() |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
159 |
|
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
160 |
baseset = revset.getset(repo, smartset.fullreposet(repo), x) |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
161 |
undecided = baseset |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
162 |
|
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
163 |
while undecided: |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
164 |
pick = rand.choice(list(undecided)) |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
165 |
selected.add(pick) |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
166 |
undecided = repo.revs( |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
167 |
'%ld and not (::%ld or %ld::head())', baseset, selected, selected |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
168 |
) |
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
169 |
|
36b4640ccb6a
perf-helper: add a new sampling revset based on anti-chain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46766
diff
changeset
|
170 |
return smartset.baseset(selected) & subset |