annotate tests/testlib/check-compat-strings.py @ 6655:81fe0a498447 stable

topic: internal config option to fix hg pick behavior (issue6406) After some consideration, hg pick was made to always use current topic (and topic namespace), even if it's not set, in which case the resulting changeset will not have any topic. Previously the intended behavior was to only update topic if there was an active topic, and not touch commit extras at all otherwise. That wasn't ideal, since pick doesn't change active topic, and amending the just-picked commit would unset its topic without clear user's intent to do so and to their surprise.
author Anton Shestakov <av6@dwimlabs.net>
date Sat, 27 Jan 2024 17:36:39 -0300
parents 73cd416a1653
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5350
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
1 #!/usr/bin/env python
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
2 """
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
3 This script finds compatibility-related comments with a node hash specified
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
4 in all files in a given directory (. by default) and looks up the hash in a
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
5 repo (~/hg by default) to determine if each of the comments is correct and,
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
6 if not, it suggests the correct release. This can prevent accidentally
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
7 removing a piece of code that was misattributed to a different (earlier)
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
8 release of core hg.
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
9
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
10 Usage: $0 WDIR HGREPO where WDIR is usually evolve/hgext3rd/ and HGREPO is
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
11 the place with core Mercurial repo (not just checkout). Said repo has to be
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
12 sufficiently up-to-date, otherwise this script may not work correctly.
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
13 """
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
14
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
15 from __future__ import print_function
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
16
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
17 import argparse
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
18 import os
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
19 import re
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
20 from subprocess import check_output
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
21
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
22 def grepall(workdir, linere):
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
23 for root, dirs, files in os.walk(workdir):
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
24 for fname in files:
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
25 if not fname.endswith('.py'):
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
26 continue
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
27 path = os.path.join(root, fname)
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
28 with open(path, 'r') as src:
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
29 for lineno, line in enumerate(src, 1):
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
30 for groups in linere.findall(line):
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
31 yield path, lineno, line, groups
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
32
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
33 def main():
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
34 ap = argparse.ArgumentParser()
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
35 ap.add_argument('workdir', nargs='?', default='.')
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
36 ap.add_argument('hgdir', nargs='?', default=os.path.expanduser('~/hg'))
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
37
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
38 opts = ap.parse_args()
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
39
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
40 linere = re.compile(r'hg <= ([0-9.]+) \(([0-9a-f+]+)\)')
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
41 basecmd = ['hg', '--cwd', opts.hgdir, 'log', '-T', '{tags}']
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
42 hgenv = {'HGPLAIN': '1', 'HGENCODING': 'UTF-8'}
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
43 relcache = {}
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
44
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
45 for path, lineno, line, match in grepall(opts.workdir, linere):
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
46 expected, revset = match
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
47
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
48 if revset not in relcache:
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
49 tagrevset = 'max(tag("re:^[0-9]\\.[0-9]$") - (%s)::)' % revset
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
50 cmd = basecmd + ['-r', tagrevset]
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
51 relcache[revset] = check_output(cmd, env=hgenv).decode('UTF-8')
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
52
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
53 lastrel = relcache[revset]
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
54
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
55 if lastrel != expected:
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
56 print('%s:%d:%s' % (path, lineno, line.rstrip('\r\n')))
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
57 print('\\ actual last major release without %s is %s'
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
58 % (revset, lastrel))
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
59 print()
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
60
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
61 if __name__ == '__main__':
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
62 main()