##// END OF EJS Templates
test: stabilize bundle generation for test-sparse-revlog.t...
marmoute -
r41964:b5967607 stable
parent child Browse files
Show More
@@ -1,1 +1,1 b''
1 403f5c247ad7cf58d3fad247a6b5e731
1 cb1e67ae6b17ba66dd455f9782692f4a
@@ -1,139 +1,139 b''
1 1 #!/usr/bin/env python
2 2 #
3 3 # generate-branchy-bundle - generate a branch for a "large" branchy repository
4 4 #
5 5 # Copyright 2018 Octobus, contact@octobus.net
6 6 #
7 7 # This software may be used and distributed according to the terms of the
8 8 # GNU General Public License version 2 or any later version.
9 9 #
10 10 # This script generates a repository suitable for testing delta computation
11 11 # strategies.
12 12 #
13 13 # The repository update a single "large" file with many updates. One fixed part
14 14 # of the files always get updated while the rest of the lines get updated over
15 15 # time. This update happens over many topological branches, some getting merged
16 16 # back.
17 17 #
18 18 # Running with `chg` in your path and `CHGHG` set is recommended for speed.
19 19
20 20 from __future__ import absolute_import, print_function
21 21
22 22 import hashlib
23 23 import os
24 24 import shutil
25 25 import subprocess
26 26 import sys
27 27 import tempfile
28 28
29 29 BUNDLE_NAME = 'big-file-churn.hg'
30 30
31 31 # constants for generating the repository
32 32 NB_CHANGESET = 5000
33 33 PERIOD_MERGING = 8
34 34 PERIOD_BRANCHING = 7
35 35 MOVE_BACK_MIN = 3
36 36 MOVE_BACK_RANGE = 5
37 37
38 38 # constants for generating the large file we keep updating
39 39 #
40 40 # At each revision, the beginning on the file change,
41 41 # and set of other lines changes too.
42 42 FILENAME='SPARSE-REVLOG-TEST-FILE'
43 43 NB_LINES = 10500
44 44 ALWAYS_CHANGE_LINES = 500
45 45 FILENAME = 'SPARSE-REVLOG-TEST-FILE'
46 46 OTHER_CHANGES = 300
47 47
48 48 def nextcontent(previous_content):
49 49 """utility to produce a new file content from the previous one"""
50 50 return hashlib.md5(previous_content).hexdigest()
51 51
52 52 def filecontent(iteridx, oldcontent):
53 53 """generate a new file content
54 54
55 55 The content is generated according the iteration index and previous
56 56 content"""
57 57
58 58 # initial call
59 59 if iteridx is None:
60 60 current = ''
61 61 else:
62 62 current = str(iteridx)
63 63
64 64 for idx in xrange(NB_LINES):
65 65 do_change_line = True
66 66 if oldcontent is not None and ALWAYS_CHANGE_LINES < idx:
67 67 do_change_line = not ((idx - iteridx) % OTHER_CHANGES)
68 68
69 69 if do_change_line:
70 70 to_write = current + '\n'
71 71 current = nextcontent(current)
72 72 else:
73 73 to_write = oldcontent[idx]
74 74 yield to_write
75 75
76 76 def updatefile(filename, idx):
77 77 """update <filename> to be at appropriate content for iteration <idx>"""
78 78 existing = None
79 79 if idx is not None:
80 80 with open(filename, 'rb') as old:
81 81 existing = old.readlines()
82 82 with open(filename, 'wb') as target:
83 83 for line in filecontent(idx, existing):
84 84 target.write(line)
85 85
86 86 def hg(command, *args):
87 87 """call a mercurial command with appropriate config and argument"""
88 88 env = os.environ.copy()
89 89 if 'CHGHG' in env:
90 90 full_cmd = ['chg']
91 91 else:
92 92 full_cmd = ['hg']
93 93 full_cmd.append('--quiet')
94 94 full_cmd.append(command)
95 95 if command == 'commit':
96 96 # reproducible commit metadata
97 97 full_cmd.extend(['--date', '0 0', '--user', 'test'])
98 98 elif command == 'merge':
99 99 # avoid conflicts by picking the local variant
100 100 full_cmd.extend(['--tool', ':merge-local'])
101 101 full_cmd.extend(args)
102 102 env['HGRCPATH'] = ''
103 103 return subprocess.check_call(full_cmd, env=env)
104 104
105 105 def run(target):
106 106 tmpdir = tempfile.mkdtemp(prefix='tmp-hg-test-big-file-bundle-')
107 107 try:
108 108 os.chdir(tmpdir)
109 109 hg('init')
110 110 updatefile(FILENAME, None)
111 111 hg('commit', '--addremove', '--message', 'initial commit')
112 112 for idx in xrange(1, NB_CHANGESET + 1):
113 113 if sys.stdout.isatty():
114 114 print("generating commit #%d/%d" % (idx, NB_CHANGESET))
115 115 if (idx % PERIOD_BRANCHING) == 0:
116 116 move_back = MOVE_BACK_MIN + (idx % MOVE_BACK_RANGE)
117 117 hg('update', ".~%d" % move_back)
118 118 if (idx % PERIOD_MERGING) == 0:
119 119 hg('merge', 'min(head())')
120 120 updatefile(FILENAME, idx)
121 121 hg('commit', '--message', 'commit #%d' % idx)
122 hg('bundle', '--all', target)
122 hg('bundle', '--all', target, '--config', 'devel.bundle.delta=p1')
123 123 with open(target, 'rb') as bundle:
124 124 data = bundle.read()
125 125 digest = hashlib.md5(data).hexdigest()
126 126 with open(target + '.md5', 'wb') as md5file:
127 127 md5file.write(digest + '\n')
128 128 if sys.stdout.isatty():
129 129 print('bundle generated at "%s" md5: %s' % (target, digest))
130 130
131 131 finally:
132 132 shutil.rmtree(tmpdir)
133 133 return 0
134 134
135 135 if __name__ == '__main__':
136 136 orig = os.path.realpath(os.path.dirname(sys.argv[0]))
137 137 target = os.path.join(orig, os.pardir, 'cache', BUNDLE_NAME)
138 138 sys.exit(run(target))
139 139
General Comments 0
You need to be logged in to leave comments. Login now