Mercurial > public > mercurial-scm > hg
comparison tests/artifacts/scripts/generate-churning-bundle.py @ 52437:e26b738430a1
test-sparse-revlog: pre-generate the graph structure in memory
This is the first step toward a more "in memory" generation of that content that
should be faster.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 04 Dec 2024 00:14:56 +0100 |
parents | 599c696bb514 |
children | 9feb175c028d |
comparison
equal
deleted
inserted
replaced
52436:599c696bb514 | 52437:e26b738430a1 |
---|---|
42 NB_LINES = 10500 | 42 NB_LINES = 10500 |
43 ALWAYS_CHANGE_LINES = 500 | 43 ALWAYS_CHANGE_LINES = 500 |
44 OTHER_CHANGES = 300 | 44 OTHER_CHANGES = 300 |
45 | 45 |
46 | 46 |
47 def build_graph(): | |
48 heads = {0} | |
49 graph = {0: (None, None)} | |
50 for idx in range(1, NB_CHANGESET + 1): | |
51 p, _ = parents = [idx - 1, None] | |
52 if (idx % PERIOD_BRANCHING) == 0: | |
53 back = MOVE_BACK_MIN + (idx % MOVE_BACK_RANGE) | |
54 for _ in range(back): | |
55 p = graph.get(p, (p,))[0] | |
56 parents[0] = p | |
57 if (idx % PERIOD_MERGING) == 0: | |
58 parents[1] = min(heads) | |
59 for p in parents: | |
60 heads.discard(p) | |
61 heads.add(idx) | |
62 graph[idx] = tuple(parents) | |
63 return graph | |
64 | |
65 | |
66 GRAPH = build_graph() | |
67 | |
68 | |
47 def nextcontent(previous_content): | 69 def nextcontent(previous_content): |
48 """utility to produce a new file content from the previous one""" | 70 """utility to produce a new file content from the previous one""" |
49 return hashlib.md5(previous_content).hexdigest().encode('ascii') | 71 return hashlib.md5(previous_content).hexdigest().encode('ascii') |
50 | 72 |
51 | 73 |
54 | 76 |
55 The content is generated according the iteration index and previous | 77 The content is generated according the iteration index and previous |
56 content""" | 78 content""" |
57 | 79 |
58 # initial call | 80 # initial call |
59 if iteridx is None: | 81 if iteridx == 0: |
60 current = b'' | 82 current = b'' |
61 else: | 83 else: |
62 current = b"%d" % iteridx | 84 current = b"%d" % iteridx |
63 | 85 |
64 for idx in range(NB_LINES): | 86 for idx in range(NB_LINES): |
75 | 97 |
76 | 98 |
77 def updatefile(filename, idx): | 99 def updatefile(filename, idx): |
78 """update <filename> to be at appropriate content for iteration <idx>""" | 100 """update <filename> to be at appropriate content for iteration <idx>""" |
79 existing = None | 101 existing = None |
80 if idx is not None: | 102 if idx > 0: |
81 with open(filename, 'rb') as old: | 103 with open(filename, 'rb') as old: |
82 existing = old.readlines() | 104 existing = old.readlines() |
83 with open(filename, 'wb') as target: | 105 with open(filename, 'wb') as target: |
84 for line in filecontent(idx, existing): | 106 for line in filecontent(idx, existing): |
85 target.write(line) | 107 target.write(line) |
108 def run(target): | 130 def run(target): |
109 tmpdir = tempfile.mkdtemp(prefix='tmp-hg-test-big-file-bundle-') | 131 tmpdir = tempfile.mkdtemp(prefix='tmp-hg-test-big-file-bundle-') |
110 try: | 132 try: |
111 os.chdir(tmpdir) | 133 os.chdir(tmpdir) |
112 hg('init') | 134 hg('init') |
113 updatefile(FILENAME, None) | 135 for idx, (p1, p2) in GRAPH.items(): |
114 hg('commit', '--addremove', '--message', 'initial commit') | |
115 for idx in range(1, NB_CHANGESET + 1): | |
116 if sys.stdout.isatty(): | 136 if sys.stdout.isatty(): |
117 print("generating commit #%d/%d" % (idx, NB_CHANGESET)) | 137 print("generating commit #%d/%d" % (idx, NB_CHANGESET)) |
118 if (idx % PERIOD_BRANCHING) == 0: | 138 if p1 is not None and p1 != idx - 1: |
119 move_back = MOVE_BACK_MIN + (idx % MOVE_BACK_RANGE) | 139 hg('update', "%d" % p1) |
120 hg('update', "max(0+.~%d)" % move_back) | 140 if p2 is not None: |
121 if (idx % PERIOD_MERGING) == 0: | 141 hg('merge', "%d" % p2) |
122 hg('merge', 'min(head())') | |
123 updatefile(FILENAME, idx) | 142 updatefile(FILENAME, idx) |
124 hg('commit', '--message', 'commit #%d' % idx) | 143 if idx == 0: |
144 hg('add', FILENAME) | |
145 hg('commit', '--addremove', '--message', 'initial commit') | |
146 else: | |
147 hg('commit', '--message', 'commit #%d' % idx) | |
125 hg('bundle', '--all', target, '--config', 'devel.bundle.delta=p1') | 148 hg('bundle', '--all', target, '--config', 'devel.bundle.delta=p1') |
126 with open(target, 'rb') as bundle: | 149 with open(target, 'rb') as bundle: |
127 data = bundle.read() | 150 data = bundle.read() |
128 digest = hashlib.md5(data).hexdigest() | 151 digest = hashlib.md5(data).hexdigest() |
129 with open(target + '.md5', 'wb') as md5file: | 152 with open(target + '.md5', 'wb') as md5file: |