Show More
@@ -1,49 +1,54 b'' | |||
|
1 | 1 | # generate proper file state to test working copy behavior |
|
2 | 2 | import sys |
|
3 | 3 | import os |
|
4 | 4 | |
|
5 | # build the combination of possible states | |
|
6 | combination = [] | |
|
7 | for base in [None, 'content1']: | |
|
8 | for parent in set([None, 'content2']) | set([base]): | |
|
9 | for wcc in set([None, 'content3']) | set([base, parent]): | |
|
10 | for tracked in ('untracked', 'tracked'): | |
|
11 | def statestring(content): | |
|
12 | return content is None and 'missing' or content | |
|
13 | filename = "%s_%s_%s-%s" % (statestring(base), | |
|
14 | statestring(parent), | |
|
15 | statestring(wcc), | |
|
16 | tracked) | |
|
17 | combination.append((filename, base, parent, wcc)) | |
|
5 | # Generates pairs of (filename, contents), where 'contents' is a list | |
|
6 | # describing the file's content at each revision (or in the working copy). | |
|
7 | # At each revision, it is either None or the file's actual content. When not | |
|
8 | # None, it may be either new content or the same content as an earlier | |
|
9 | # revisions, so all of (modified,clean,added,removed) can be tested. | |
|
10 | def generatestates(maxchangesets, parentcontents): | |
|
11 | depth = len(parentcontents) | |
|
12 | if depth == maxchangesets + 1: | |
|
13 | for tracked in ('untracked', 'tracked'): | |
|
14 | filename = "_".join([(content is None and 'missing' or content) for | |
|
15 | content in parentcontents]) + "-" + tracked | |
|
16 | yield (filename, parentcontents) | |
|
17 | else: | |
|
18 | for content in (set([None, 'content' + str(depth + 1)]) | | |
|
19 | set(parentcontents)): | |
|
20 | for combination in generatestates(maxchangesets, | |
|
21 | parentcontents + [content]): | |
|
22 | yield combination | |
|
18 | 23 | |
|
19 | # make sure we have stable output | |
|
20 | combination.sort() | |
|
24 | # sort to make sure we have stable output | |
|
25 | combinations = sorted(generatestates(2, [])) | |
|
21 | 26 | |
|
22 | 27 | # retrieve the state we must generate |
|
23 | 28 | target = sys.argv[1] |
|
24 | 29 | |
|
25 | 30 | # compute file content |
|
26 | 31 | content = [] |
|
27 | for filename, base, parent, wcc in combination: | |
|
32 | for filename, [base, parent, wcc] in combinations: | |
|
28 | 33 | if target == 'filelist': |
|
29 | 34 | print filename |
|
30 | 35 | elif target == 'base': |
|
31 | 36 | content.append((filename, base)) |
|
32 | 37 | elif target == 'parent': |
|
33 | 38 | content.append((filename, parent)) |
|
34 | 39 | elif target == 'wc': |
|
35 | 40 | # Make sure there is content so the file gets written and can be |
|
36 | 41 | # tracked. It will be deleted outside of this script. |
|
37 | 42 | content.append((filename, wcc or 'TOBEDELETED')) |
|
38 | 43 | else: |
|
39 | 44 | print >> sys.stderr, "unknown target:", target |
|
40 | 45 | sys.exit(1) |
|
41 | 46 | |
|
42 | 47 | # write actual content |
|
43 | 48 | for filename, data in content: |
|
44 | 49 | if data is not None: |
|
45 | 50 | f = open(filename, 'w') |
|
46 | 51 | f.write(data + '\n') |
|
47 | 52 | f.close() |
|
48 | 53 | elif os.path.exists(filename): |
|
49 | 54 | os.remove(filename) |
General Comments 0
You need to be logged in to leave comments.
Login now