diff --git a/other-test-repos/tag-test.py b/other-test-repos/tag-test.py new file mode 100755 index 00000000..f66e393 --- /dev/null +++ b/other-test-repos/tag-test.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +import datetime +import subprocess +import time +import sys + +import util + +email = b'a@a.com' +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) diff --git a/other-test-repos/util.py b/other-test-repos/util.py index 82ae60a..8b9593e 100644 --- a/other-test-repos/util.py +++ b/other-test-repos/util.py @@ -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. @@ -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' @@ -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()