Replace dict comprehension for Python 2.6 support
[stgit.git] / perf / create_synthetic_repo.py
blob6470bf5911d2072d010616722a98dcf7f3853c88
1 # -*- coding: utf-8 -*-
2 from __future__ import (absolute_import, division, print_function,
3 unicode_literals)
6 next_mark = 1
7 def get_mark():
8 global next_mark
9 next_mark += 1
10 return (next_mark - 1)
12 def write_data(s):
13 print('data %d' % len(s))
14 print(s)
16 def write_blob(s):
17 print('blob')
18 m = get_mark()
19 print('mark :%d' % m)
20 write_data(s)
21 return m
23 def write_commit(branch, files, msg, parent = None):
24 print('commit %s' % branch)
25 m = get_mark()
26 print('mark :%d' % m)
27 auth = 'X Ample <xa@example.com> %d +0000' % (1000000000 + m)
28 print('author %s' % auth)
29 print('committer %s' % auth)
30 write_data(msg)
31 if parent is not None:
32 print('from :%d' % parent)
33 for fn, fm in sorted(files.items()):
34 print('M 100644 :%d %s' % (fm, fn))
35 return m
37 def set_ref(ref, mark):
38 print('reset %s' % ref)
39 print('from :%d' % mark)
41 def stdblob(fn):
42 return ''.join('%d %s\n' % (x, fn) for x in range(10))
44 def iter_paths():
45 for i in range(32):
46 for j in range(32):
47 for k in range(32):
48 yield '%02d/%02d/%02d' % (i, j, k)
50 def setup():
51 def t(name): return 'refs/tags/%s' % name
52 files = dict((fn, write_blob(stdblob(fn))) for fn in iter_paths())
53 initial = write_commit(t('bomb-base'), files, 'Initial commit')
54 set_ref(t('bomb-top'), initial)
55 for fn in iter_paths():
56 write_commit(t('bomb-top'),
57 { fn: write_blob(stdblob(fn) + 'Last line\n') },
58 'Add last line to %s' % fn)
59 write_commit(t('add-file'), { 'woo-hoo.txt': write_blob('woo-hoo\n') },
60 'Add a new file', parent = initial)
61 files = dict((fn, write_blob('First line\n' + stdblob(fn)))
62 for fn in iter_paths())
63 write_commit(t('modify-all'), files, 'Add first line to all files',
64 parent = initial)
66 setup()