Show More
@@ -1,88 +1,88 | |||||
1 | # Helper script used for generating history and working copy files and content. |
|
1 | # Helper script used for generating history and working copy files and content. | |
2 | # The file's name corresponds to its history. The number of changesets can |
|
2 | # The file's name corresponds to its history. The number of changesets can | |
3 | # be specified on the command line. With 2 changesets, files with names like |
|
3 | # be specified on the command line. With 2 changesets, files with names like | |
4 | # content1_content2_content1-untracked are generated. The first two filename |
|
4 | # content1_content2_content1-untracked are generated. The first two filename | |
5 | # segments describe the contents in the two changesets. The third segment |
|
5 | # segments describe the contents in the two changesets. The third segment | |
6 | # ("content1-untracked") describes the state in the working copy, i.e. |
|
6 | # ("content1-untracked") describes the state in the working copy, i.e. | |
7 | # the file has content "content1" and is untracked (since it was previously |
|
7 | # the file has content "content1" and is untracked (since it was previously | |
8 | # tracked, it has been forgotten). |
|
8 | # tracked, it has been forgotten). | |
9 | # |
|
9 | # | |
10 | # This script generates the filenames and their content, but it's up to the |
|
10 | # This script generates the filenames and their content, but it's up to the | |
11 | # caller to tell hg about the state. |
|
11 | # caller to tell hg about the state. | |
12 | # |
|
12 | # | |
13 | # There are two subcommands: |
|
13 | # There are two subcommands: | |
14 | # filelist <numchangesets> |
|
14 | # filelist <numchangesets> | |
15 | # state <numchangesets> (<changeset>|wc) |
|
15 | # state <numchangesets> (<changeset>|wc) | |
16 | # |
|
16 | # | |
17 | # Typical usage: |
|
17 | # Typical usage: | |
18 | # |
|
18 | # | |
19 | # $ python $TESTDIR/generate-working-copy-states.py state 2 1 |
|
19 | # $ python $TESTDIR/generate-working-copy-states.py state 2 1 | |
20 | # $ hg addremove --similarity 0 |
|
20 | # $ hg addremove --similarity 0 | |
21 | # $ hg commit -m 'first' |
|
21 | # $ hg commit -m 'first' | |
22 | # |
|
22 | # | |
23 | # $ python $TESTDIR/generate-working-copy-states.py state 2 1 |
|
23 | # $ python $TESTDIR/generate-working-copy-states.py state 2 1 | |
24 | # $ hg addremove --similarity 0 |
|
24 | # $ hg addremove --similarity 0 | |
25 | # $ hg commit -m 'second' |
|
25 | # $ hg commit -m 'second' | |
26 | # |
|
26 | # | |
27 | # $ python $TESTDIR/generate-working-copy-states.py state 2 wc |
|
27 | # $ python $TESTDIR/generate-working-copy-states.py state 2 wc | |
28 | # $ hg addremove --similarity 0 |
|
28 | # $ hg addremove --similarity 0 | |
29 | # $ hg forget *_*_*-untracked |
|
29 | # $ hg forget *_*_*-untracked | |
30 | # $ rm *_*_missing-* |
|
30 | # $ rm *_*_missing-* | |
31 |
|
31 | |||
32 | from __future__ import absolute_import, print_function |
|
32 | from __future__ import absolute_import, print_function | |
33 |
|
33 | |||
34 | import os |
|
34 | import os | |
35 | import sys |
|
35 | import sys | |
36 |
|
36 | |||
37 | # Generates pairs of (filename, contents), where 'contents' is a list |
|
37 | # Generates pairs of (filename, contents), where 'contents' is a list | |
38 | # describing the file's content at each revision (or in the working copy). |
|
38 | # describing the file's content at each revision (or in the working copy). | |
39 | # At each revision, it is either None or the file's actual content. When not |
|
39 | # At each revision, it is either None or the file's actual content. When not | |
40 | # None, it may be either new content or the same content as an earlier |
|
40 | # None, it may be either new content or the same content as an earlier | |
41 | # revisions, so all of (modified,clean,added,removed) can be tested. |
|
41 | # revisions, so all of (modified,clean,added,removed) can be tested. | |
42 | def generatestates(maxchangesets, parentcontents): |
|
42 | def generatestates(maxchangesets, parentcontents): | |
43 | depth = len(parentcontents) |
|
43 | depth = len(parentcontents) | |
44 | if depth == maxchangesets + 1: |
|
44 | if depth == maxchangesets + 1: | |
45 | for tracked in ('untracked', 'tracked'): |
|
45 | for tracked in (b'untracked', b'tracked'): | |
46 |
filename = "_".join([(content is None and 'missing' or content) |
|
46 | filename = b"_".join([(content is None and b'missing' or content) | |
47 | content in parentcontents]) + "-" + tracked |
|
47 | for content in parentcontents]) + b"-" + tracked | |
48 | yield (filename, parentcontents) |
|
48 | yield (filename, parentcontents) | |
49 | else: |
|
49 | else: | |
50 |
for content in ({None, 'content' + |
|
50 | for content in ({None, b'content' + (b"%d" % (depth + 1))} | | |
51 | set(parentcontents)): |
|
51 | set(parentcontents)): | |
52 | for combination in generatestates(maxchangesets, |
|
52 | for combination in generatestates(maxchangesets, | |
53 | parentcontents + [content]): |
|
53 | parentcontents + [content]): | |
54 | yield combination |
|
54 | yield combination | |
55 |
|
55 | |||
56 | # retrieve the command line arguments |
|
56 | # retrieve the command line arguments | |
57 | target = sys.argv[1] |
|
57 | target = sys.argv[1] | |
58 | maxchangesets = int(sys.argv[2]) |
|
58 | maxchangesets = int(sys.argv[2]) | |
59 | if target == 'state': |
|
59 | if target == 'state': | |
60 | depth = sys.argv[3] |
|
60 | depth = sys.argv[3] | |
61 |
|
61 | |||
62 | # sort to make sure we have stable output |
|
62 | # sort to make sure we have stable output | |
63 | combinations = sorted(generatestates(maxchangesets, [])) |
|
63 | combinations = sorted(generatestates(maxchangesets, [])) | |
64 |
|
64 | |||
65 | # compute file content |
|
65 | # compute file content | |
66 | content = [] |
|
66 | content = [] | |
67 | for filename, states in combinations: |
|
67 | for filename, states in combinations: | |
68 | if target == 'filelist': |
|
68 | if target == 'filelist': | |
69 | print(filename) |
|
69 | print(filename) | |
70 | elif target == 'state': |
|
70 | elif target == 'state': | |
71 | if depth == 'wc': |
|
71 | if depth == 'wc': | |
72 | # Make sure there is content so the file gets written and can be |
|
72 | # Make sure there is content so the file gets written and can be | |
73 | # tracked. It will be deleted outside of this script. |
|
73 | # tracked. It will be deleted outside of this script. | |
74 | content.append((filename, states[maxchangesets] or 'TOBEDELETED')) |
|
74 | content.append((filename, states[maxchangesets] or b'TOBEDELETED')) | |
75 | else: |
|
75 | else: | |
76 | content.append((filename, states[int(depth) - 1])) |
|
76 | content.append((filename, states[int(depth) - 1])) | |
77 | else: |
|
77 | else: | |
78 | print("unknown target:", target, file=sys.stderr) |
|
78 | print("unknown target:", target, file=sys.stderr) | |
79 | sys.exit(1) |
|
79 | sys.exit(1) | |
80 |
|
80 | |||
81 | # write actual content |
|
81 | # write actual content | |
82 | for filename, data in content: |
|
82 | for filename, data in content: | |
83 | if data is not None: |
|
83 | if data is not None: | |
84 | f = open(filename, 'wb') |
|
84 | f = open(filename, 'wb') | |
85 | f.write(data + '\n') |
|
85 | f.write(data + b'\n') | |
86 | f.close() |
|
86 | f.close() | |
87 | elif os.path.exists(filename): |
|
87 | elif os.path.exists(filename): | |
88 | os.remove(filename) |
|
88 | os.remove(filename) |
General Comments 0
You need to be logged in to leave comments.
Login now