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