Mercurial > hg
annotate tests/test-fix-metadata.t @ 48393:1a8a70b4b0ad
dirstate: cleanup remaining of "now" during write
Since the whole `need_delay` have been removed, we no longer need this.
Differential Revision: https://phab.mercurial-scm.org/D11797
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 19 Nov 2021 03:03:01 +0100 |
parents | 2d70b1118af2 |
children |
rev | line source |
---|---|
42194
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
1 A python hook for "hg fix" that prints out the number of files and revisions |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
2 that were affected, along with which fixer tools were applied. Also checks how |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
3 many times it sees a specific key generated by one of the fixer tools defined |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
4 below. |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
5 |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
6 $ cat >> $TESTTMP/postfixhook.py <<EOF |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
7 > import collections |
42429
6ed04139ed37
py3: fix test-fix-metadata.t
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42194
diff
changeset
|
8 > def file(ui, repo, rev=None, path=b'', metadata=None, **kwargs): |
6ed04139ed37
py3: fix test-fix-metadata.t
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42194
diff
changeset
|
9 > ui.status(b'fixed %s in revision %d using %s\n' % |
6ed04139ed37
py3: fix test-fix-metadata.t
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42194
diff
changeset
|
10 > (path, rev, b', '.join(metadata.keys()))) |
42194
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
11 > def summarize(ui, repo, replacements=None, wdirwritten=False, |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
12 > metadata=None, **kwargs): |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
13 > counts = collections.defaultdict(int) |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
14 > keys = 0 |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
15 > for fixername, metadatalist in metadata.items(): |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
16 > for metadata in metadatalist: |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
17 > if metadata is None: |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
18 > continue |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
19 > counts[fixername] += 1 |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
20 > if 'key' in metadata: |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
21 > keys += 1 |
42429
6ed04139ed37
py3: fix test-fix-metadata.t
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42194
diff
changeset
|
22 > ui.status(b'saw "key" %d times\n' % (keys,)) |
42194
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
23 > for name, count in sorted(counts.items()): |
42429
6ed04139ed37
py3: fix test-fix-metadata.t
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42194
diff
changeset
|
24 > ui.status(b'fixed %d files with %s\n' % (count, name)) |
42194
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
25 > if replacements: |
42429
6ed04139ed37
py3: fix test-fix-metadata.t
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42194
diff
changeset
|
26 > ui.status(b'fixed %d revisions\n' % (len(replacements),)) |
42194
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
27 > if wdirwritten: |
42429
6ed04139ed37
py3: fix test-fix-metadata.t
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42194
diff
changeset
|
28 > ui.status(b'fixed the working copy\n') |
42194
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
29 > EOF |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
30 |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
31 Some mock output for fixer tools that demonstrate what could go wrong with |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
32 expecting the metadata output format. |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
33 |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
34 $ printf 'new content\n' > $TESTTMP/missing |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
35 $ printf 'not valid json\0new content\n' > $TESTTMP/invalid |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
36 $ printf '{"key": "value"}\0new content\n' > $TESTTMP/valid |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
37 |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
38 Configure some fixer tools based on the output defined above, and enable the |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
39 hooks defined above. Disable parallelism to make output of the parallel file |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
40 processing phase stable. |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
41 |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
42 $ cat >> $HGRCPATH <<EOF |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
43 > [extensions] |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
44 > fix = |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
45 > [fix] |
42757
2d70b1118af2
fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents:
42429
diff
changeset
|
46 > metadatafalse:command=cat $TESTTMP/missing |
2d70b1118af2
fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents:
42429
diff
changeset
|
47 > metadatafalse:pattern=metadatafalse |
2d70b1118af2
fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents:
42429
diff
changeset
|
48 > metadatafalse:metadata=false |
42194
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
49 > missing:command=cat $TESTTMP/missing |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
50 > missing:pattern=missing |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
51 > missing:metadata=true |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
52 > invalid:command=cat $TESTTMP/invalid |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
53 > invalid:pattern=invalid |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
54 > invalid:metadata=true |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
55 > valid:command=cat $TESTTMP/valid |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
56 > valid:pattern=valid |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
57 > valid:metadata=true |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
58 > [hooks] |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
59 > postfixfile = python:$TESTTMP/postfixhook.py:file |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
60 > postfix = python:$TESTTMP/postfixhook.py:summarize |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
61 > [worker] |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
62 > enabled=false |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
63 > EOF |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
64 |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
65 See what happens when we execute each of the fixer tools. Some print warnings, |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
66 some write back to the file. |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
67 |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
68 $ hg init repo |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
69 $ cd repo |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
70 |
42757
2d70b1118af2
fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents:
42429
diff
changeset
|
71 $ printf "old content\n" > metadatafalse |
42194
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
72 $ printf "old content\n" > invalid |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
73 $ printf "old content\n" > missing |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
74 $ printf "old content\n" > valid |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
75 $ hg add -q |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
76 |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
77 $ hg fix -w |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
78 ignored invalid output from fixer tool: invalid |
42757
2d70b1118af2
fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents:
42429
diff
changeset
|
79 fixed metadatafalse in revision 2147483647 using metadatafalse |
42194
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
80 ignored invalid output from fixer tool: missing |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
81 fixed valid in revision 2147483647 using valid |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
82 saw "key" 1 times |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
83 fixed 1 files with valid |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
84 fixed the working copy |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
85 |
42757
2d70b1118af2
fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents:
42429
diff
changeset
|
86 $ cat metadatafalse |
2d70b1118af2
fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents:
42429
diff
changeset
|
87 new content |
2d70b1118af2
fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents:
42429
diff
changeset
|
88 $ cat missing |
42194
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
89 old content |
42757
2d70b1118af2
fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents:
42429
diff
changeset
|
90 $ cat invalid |
42194
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
91 old content |
42757
2d70b1118af2
fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents:
42429
diff
changeset
|
92 $ cat valid |
42194
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
93 new content |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
94 |
0da689a60163
fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff
changeset
|
95 $ cd .. |