Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cookers/git_bare.py
Show First 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | def write_refs(self, snapshot=None): | ||||
self.write_revision_node(revision.to_dict()) | self.write_revision_node(revision.to_dict()) | ||||
refs = {b"refs/heads/master": hash_to_bytehex(revision.id)} | refs = {b"refs/heads/master": hash_to_bytehex(revision.id)} | ||||
elif obj_type == "revision": | elif obj_type == "revision": | ||||
refs = {b"refs/heads/master": hash_to_bytehex(self.obj_id)} | refs = {b"refs/heads/master": hash_to_bytehex(self.obj_id)} | ||||
elif obj_type == "snapshot": | elif obj_type == "snapshot": | ||||
if snapshot is None: | if snapshot is None: | ||||
# refs were already written in a previous step | # refs were already written in a previous step | ||||
return | return | ||||
branches = [] | |||||
for (branch_name, branch) in snapshot.branches.items(): | |||||
if branch is None: | |||||
logging.error( | |||||
"%s has dangling branch: %r", snapshot.swhid(), branch_name | |||||
) | |||||
else: | |||||
branches.append((branch_name, branch)) | |||||
refs = { | refs = { | ||||
branch_name: ( | branch_name: ( | ||||
b"ref: " + branch.target | b"ref: " + branch.target | ||||
if branch.target_type == TargetType.ALIAS | if branch.target_type == TargetType.ALIAS | ||||
else hash_to_bytehex(branch.target) | else hash_to_bytehex(branch.target) | ||||
) | ) | ||||
for (branch_name, branch) in snapshot.branches.items() | for (branch_name, branch) in branches | ||||
} | } | ||||
else: | else: | ||||
assert False, obj_type | assert False, obj_type | ||||
for (ref_name, ref_target) in refs.items(): | for (ref_name, ref_target) in refs.items(): | ||||
path = os.path.join(self.gitdir.encode(), ref_name) | path = os.path.join(self.gitdir.encode(), ref_name) | ||||
os.makedirs(os.path.dirname(path), exist_ok=True) | os.makedirs(os.path.dirname(path), exist_ok=True) | ||||
with open(path, "wb") as fd: | with open(path, "wb") as fd: | ||||
▲ Show 20 Lines • Show All 299 Lines • Show Last 20 Lines |