Skip to content

Commit

Permalink
generate tags
Browse files Browse the repository at this point in the history
  • Loading branch information
cirosantilli committed Sep 5, 2018
1 parent 42c0d43 commit 8770bcb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
35 changes: 35 additions & 0 deletions other-test-repos/tag-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3

import datetime
import subprocess
import time
import sys

import util

email = b'[email protected]'
name = b''

util.init()
tree = util.create_tree_with_one_file()
commit, _, _ = util.save_commit_object(
tree,
(None,),
author_date_s=0,
author_email=email,
author_name=name,
committer_date_s=0,
committer_email=email,
committer_name=name,
message=b'',
)
tag_sha, _, _ = util.save_tag_object(
commit,
b'mytag',
object_type=b'commit',
user_name=name,
user_email=email,
date_s=0,
message=b'abc'
)
util.create_master(commit)
21 changes: 21 additions & 0 deletions other-test-repos/util.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

"""
TODO packfile operations instead of just object. Could be more efficient.
But also harder to implement that format.
Expand All @@ -12,6 +14,8 @@
repo_dir = 'repo.tmp'
git_dir = b'.git'
objects_dir = os.path.join(git_dir, b'objects')
refs_dir = os.path.join(git_dir, b'refs')
tags_dir = os.path.join(refs_dir, b'tags')

# Tree parameters.
default_blob_basename = b'a'
Expand Down Expand Up @@ -87,6 +91,23 @@ def save_commit_object(
message)
return save_object(b'commit', commit_content) + (commit_content,)

def save_tag_object(
object_sha_ascii,
tag_name,
object_type='commit',
user_name=default_author_name,
user_email=default_author_email,
date_s=default_author_date_s,
date_tz=default_author_date_tz,
message=default_message):
content = b'object %s\ntype %s\ntag %s\ntagger %s <%s> %s %s\n\n%s' % \
(object_sha_ascii, object_type, tag_name, user_name, user_email, str(date_s).encode('ascii'), date_tz, message)
tag_sha_ascii, tag_sha = save_object(b'tag', content)
os.makedirs(tags_dir, exist_ok=True)
with open(os.path.join(tags_dir, tag_name), 'w') as tag_file:
tag_file.write(tag_sha_ascii.decode('ascii') + '\n')
return tag_sha_ascii, tag_sha, content

def get_git_hash_object(obj_type, input):
cmd = [b'git', b'hash-object', b'--stdin', b'-t', obj_type]
return subprocess.check_output(cmd, input=input).rstrip()
Expand Down

0 comments on commit 8770bcb

Please sign in to comment.