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