-
Notifications
You must be signed in to change notification settings - Fork 1
/
hilevel_util.py
59 lines (44 loc) · 1.35 KB
/
hilevel_util.py
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
import os
import lolevel_util
import tempfile
def to_bytes(s):
return bytes(s, encoding='utf-8')
def make_repo(repo_dir, readme_contents):
lolevel_util.init(repo_dir)
tree = lolevel_util.create_tree_with_one_file(
repo_dir,
blob_basename=to_bytes('README.md'),
blob_content=readme_contents,
)
return tree
def set_head(repo_dir, commit_sha):
lolevel_util.create_master(repo_dir, commit_sha)
def make_commit(repo_dir, tree, parent_sha, email, name, date):
if parent_sha:
parents = [parent_sha]
else:
parents = []
timestamp = int(date.timestamp())
commit_sha, _, _ = lolevel_util.save_commit_object(
repo_dir,
tree,
parents,
author_date_s=timestamp,
author_email=email,
author_name=name,
committer_date_s=timestamp,
committer_email=email,
committer_name=name,
message=to_bytes('Psych!'),
)
return commit_sha
def draw_git_history(repo_dir, email, name, dates, readme_contents):
repo_dir = to_bytes(repo_dir)
email = to_bytes(email)
name = to_bytes(name)
tree = make_repo(repo_dir, readme_contents)
commit_sha = None
for date in dates:
for _ in range(100):
commit_sha = make_commit(repo_dir, tree, commit_sha, email, name, date)
set_head(repo_dir, commit_sha)