Browse Source

Keep a record of what HEAD points at

tags/v1.0
JustAnotherArchivist 1 year ago
parent
commit
0da610744c
1 changed files with 7 additions and 0 deletions
  1. +7
    -0
      codearchiver/modules/git.py

+ 7
- 0
codearchiver/modules/git.py View File

@@ -18,6 +18,7 @@ class GitMetadata(codearchiver.core.Metadata):
codearchiver.core.MetadataField(key = 'Git version', required = True, repeatable = False),
codearchiver.core.MetadataField(key = 'Based on bundle', required = False, repeatable = True),
codearchiver.core.MetadataField(key = 'Ref', required = True, repeatable = True),
codearchiver.core.MetadataField(key = 'Head', required = True, repeatable = False),
codearchiver.core.MetadataField(key = 'Root commit', required = True, repeatable = True),
codearchiver.core.MetadataField(key = 'Object', required = False, repeatable = True),
)
@@ -75,6 +76,11 @@ class Git(codearchiver.core.Module):
rootCommits = list(filter(None, rootCommits.splitlines()))
_, objects, _ = codearchiver.subprocess.run_with_log(['git', 'cat-file', '--batch-check', '--batch-all-objects', '--unordered', '--buffer'], cwd = directory)
objects = {oid: otype for oid, otype, osize in map(functools.partial(str.split, sep = ' '), objects.splitlines())}
with open(os.path.join(directory, 'HEAD'), 'r') as fp:
head = fp.read()
if not head.startswith('ref: refs/heads/') or not head.endswith('\n'):
raise RuntimeError(f'Unexpected HEAD content: {head!r}')
head = head[:-1] # Remove trailing \n

# Check whether there are relevant prior bundles to create an incremental one
commitsAndTags = {oid for oid, otype in objects.items() if otype in ('commit', 'tag')}
@@ -168,6 +174,7 @@ class Git(codearchiver.core.Module):
metadata.append('Based on bundle', oldBundle)
for line in refs:
metadata.append('Ref', line)
metadata.append('Head', head)
for commitId in rootCommits:
metadata.append('Root commit', commitId)
for oid, otype in indexObjects.items():


Loading…
Cancel
Save