File: create_synthetic_repo.py

package info (click to toggle)
stgit 0.19-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,748 kB
  • sloc: python: 10,558; sh: 5,739; lisp: 2,678; makefile: 142; perl: 42
file content (66 lines) | stat: -rw-r--r-- 1,930 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)


next_mark = 1
def get_mark():
    global next_mark
    next_mark += 1
    return (next_mark - 1)

def write_data(s):
    print('data %d' % len(s))
    print(s)

def write_blob(s):
    print('blob')
    m = get_mark()
    print('mark :%d' % m)
    write_data(s)
    return m

def write_commit(branch, files, msg, parent = None):
    print('commit %s' % branch)
    m = get_mark()
    print('mark :%d' % m)
    auth = 'X Ample <xa@example.com> %d +0000' % (1000000000 + m)
    print('author %s' % auth)
    print('committer %s' % auth)
    write_data(msg)
    if parent is not None:
        print('from :%d' % parent)
    for fn, fm in sorted(files.items()):
        print('M 100644 :%d %s' % (fm, fn))
    return m

def set_ref(ref, mark):
    print('reset %s' % ref)
    print('from :%d' % mark)

def stdblob(fn):
    return ''.join('%d %s\n' % (x, fn) for x in range(10))

def iter_paths():
    for i in range(32):
        for j in range(32):
            for k in range(32):
                yield '%02d/%02d/%02d' % (i, j, k)

def setup():
    def t(name): return 'refs/tags/%s' % name
    files = dict((fn, write_blob(stdblob(fn))) for fn in iter_paths())
    initial = write_commit(t('bomb-base'), files, 'Initial commit')
    set_ref(t('bomb-top'), initial)
    for fn in iter_paths():
        write_commit(t('bomb-top'),
                     { fn: write_blob(stdblob(fn) + 'Last line\n') },
                     'Add last line to %s' % fn)
    write_commit(t('add-file'), { 'woo-hoo.txt': write_blob('woo-hoo\n') },
                 'Add a new file', parent = initial)
    files = dict((fn, write_blob('First line\n' + stdblob(fn)))
                 for fn in iter_paths())
    write_commit(t('modify-all'), files, 'Add first line to all files',
                 parent = initial)

setup()