|
@@ -25,6 +25,7 @@
|
|
|
from contextlib import suppress
|
|
|
import os
|
|
|
from typing import Dict, Optional
|
|
|
+import warnings
|
|
|
|
|
|
from dulwich.errors import (
|
|
|
PackedRefsException,
|
|
@@ -50,7 +51,10 @@ SYMREF = b"ref: "
|
|
|
LOCAL_BRANCH_PREFIX = b"refs/heads/"
|
|
|
LOCAL_TAG_PREFIX = b"refs/tags/"
|
|
|
BAD_REF_CHARS = set(b"\177 ~^:?*[")
|
|
|
-ANNOTATED_TAG_SUFFIX = b"^{}"
|
|
|
+PEELED_TAG_SUFFIX = b"^{}"
|
|
|
+
|
|
|
+# For backwards compatibility
|
|
|
+ANNOTATED_TAG_SUFFIX = PEELED_TAG_SUFFIX
|
|
|
|
|
|
|
|
|
class SymrefLoop(Exception):
|
|
@@ -593,7 +597,7 @@ class InfoRefsContainer(RefsContainer):
|
|
|
self._peeled = {}
|
|
|
for line in f.readlines():
|
|
|
sha, name = line.rstrip(b"\n").split(b"\t")
|
|
|
- if name.endswith(ANNOTATED_TAG_SUFFIX):
|
|
|
+ if name.endswith(PEELED_TAG_SUFFIX):
|
|
|
name = name[:-3]
|
|
|
if not check_ref_format(name):
|
|
|
raise ValueError("invalid ref name %r" % name)
|
|
@@ -1153,7 +1157,7 @@ def read_info_refs(f):
|
|
|
|
|
|
def write_info_refs(refs, store: ObjectContainer):
|
|
|
"""Generate info refs."""
|
|
|
- # Avoid recursive import :(
|
|
|
+ # TODO: Avoid recursive import :(
|
|
|
from dulwich.object_store import peel_sha
|
|
|
for name, sha in sorted(refs.items()):
|
|
|
# get_refs() includes HEAD as a special case, but we don't want to
|
|
@@ -1164,10 +1168,10 @@ def write_info_refs(refs, store: ObjectContainer):
|
|
|
o = store[sha]
|
|
|
except KeyError:
|
|
|
continue
|
|
|
- peeled = peel_sha(store, sha)
|
|
|
+ unpeeled, peeled = peel_sha(store, sha)
|
|
|
yield o.id + b"\t" + name + b"\n"
|
|
|
if o.id != peeled.id:
|
|
|
- yield peeled.id + b"\t" + name + ANNOTATED_TAG_SUFFIX + b"\n"
|
|
|
+ yield peeled.id + b"\t" + name + PEELED_TAG_SUFFIX + b"\n"
|
|
|
|
|
|
|
|
|
def is_local_branch(x):
|
|
@@ -1179,7 +1183,7 @@ def strip_peeled_refs(refs):
|
|
|
return {
|
|
|
ref: sha
|
|
|
for (ref, sha) in refs.items()
|
|
|
- if not ref.endswith(ANNOTATED_TAG_SUFFIX)
|
|
|
+ if not ref.endswith(PEELED_TAG_SUFFIX)
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1275,6 +1279,27 @@ def _import_remote_refs(
|
|
|
tags = {
|
|
|
n[len(LOCAL_TAG_PREFIX) :]: v
|
|
|
for (n, v) in stripped_refs.items()
|
|
|
- if n.startswith(LOCAL_TAG_PREFIX) and not n.endswith(ANNOTATED_TAG_SUFFIX)
|
|
|
+ if n.startswith(LOCAL_TAG_PREFIX) and not n.endswith(PEELED_TAG_SUFFIX)
|
|
|
}
|
|
|
refs_container.import_refs(LOCAL_TAG_PREFIX, tags, message=message, prune=prune_tags)
|
|
|
+
|
|
|
+
|
|
|
+def serialize_refs(store, refs):
|
|
|
+ # TODO: Avoid recursive import :(
|
|
|
+ from dulwich.object_store import peel_sha
|
|
|
+ ret = {}
|
|
|
+ for ref, sha in refs.items():
|
|
|
+ try:
|
|
|
+ unpeeled, peeled = peel_sha(store, sha)
|
|
|
+ except KeyError:
|
|
|
+ warnings.warn(
|
|
|
+ "ref %s points at non-present sha %s"
|
|
|
+ % (ref.decode("utf-8", "replace"), sha.decode("ascii")),
|
|
|
+ UserWarning,
|
|
|
+ )
|
|
|
+ continue
|
|
|
+ else:
|
|
|
+ if isinstance(unpeeled, Tag):
|
|
|
+ ret[ref + PEELED_TAG_SUFFIX] = peeled.id
|
|
|
+ ret[ref] = unpeeled.id
|
|
|
+ return ret
|