Skip to content
Snippets Groups Projects
Commit 16fd9dcb authored by Georges Racinet's avatar Georges Racinet
Browse files

gitlab_ref: iterating functions for special refs and keep-arounds

We're keeping a uniform API with other refs (branches and tags),
although we'll probably use `deref=False` almost exclusively.
parent 57f13ccf
No related branches found
No related tags found
1 merge request!101RefService.ListRefs: initial implementation
......@@ -46,6 +46,19 @@
return repo.unfiltered()[sha]
def iter_gitlab_special_refs_as_refs(repo, deref=True):
"""Iterate on special refs, yielding full ref paths and target hashes.
"""
all_special_refs = special_refs(repo)
if all_special_refs is GITLAB_TYPED_REFS_MISSING:
# transitional while we still have an inner Git repo
# would still be the best we can do near the end of HGitaly2 milestone
all_special_refs = ensure_special_refs(repo)
for sref, sha in all_special_refs.items():
yield b'refs/' + sref, (repo[sha] if deref else sha.decode('ascii'))
def ensure_special_refs(repo):
return ensure_gitlab_special_refs(repo.ui, repo)
......@@ -64,6 +77,21 @@
return False
def keep_around_ref_path(sha):
# TODO should move to py-heptapod
return b'refs/keep-arounds/' + sha
def iter_keep_arounds_as_refs(repo, deref=True):
for sha in iter_keep_arounds(repo):
if sha is GITLAB_TYPED_REFS_MISSING:
ensure_gitlab_keep_arounds(repo.ui, repo)
yield from iter_keep_arounds_as_refs(repo)
return
yield (keep_around_ref_path(sha),
(repo[sha] if deref else sha.decode('ascii')))
def sort_key_ref_changeset_date_asc(ref_chgset):
"""Sorting key function meant for ref items.
......
......@@ -15,8 +15,11 @@
from hgext3rd.heptapod.special_ref import (
write_gitlab_special_ref,
)
from hgext3rd.heptapod.keep_around import (
create_keep_around,
)
from .common import (
MINIMAL_HG_CONFIG,
)
from ..gitlab_ref import (
gitlab_special_ref_target,
......@@ -18,8 +21,10 @@
from .common import (
MINIMAL_HG_CONFIG,
)
from ..gitlab_ref import (
gitlab_special_ref_target,
iter_gitlab_special_refs_as_refs,
iter_keep_arounds_as_refs,
)
......@@ -105,3 +110,36 @@
assert read_gitlab_typed_refs(repo, 'special-refs') == {
ref_name: ctx1.hex()}
assert gitlab_special_ref_target(repo, ref_path) == ctx1
def test_iterate_special_ref(repo_wrapper):
repo, wrapper = repo_wrapper
ref_name = b'pipelines/123'
ref_path = b'refs/pipelines/123'
base = wrapper.commit_file('foo')
base_hex = base.hex().decode()
assert list(iter_gitlab_special_refs_as_refs(repo)) == []
write_gitlab_special_ref(repo, ref_name, base)
assert list(iter_gitlab_special_refs_as_refs(repo)) == [
(ref_path, base)]
assert list(iter_gitlab_special_refs_as_refs(repo, deref=False)) == [
(ref_path, base_hex)]
def test_iterate_keep_arounds(repo_wrapper):
repo, wrapper = repo_wrapper
ctx = wrapper.commit_file('foo')
sha_bytes = ctx.hex()
sha_str = sha_bytes.decode()
assert list(iter_keep_arounds_as_refs(repo)) == []
create_keep_around(repo, sha_bytes)
assert list(iter_keep_arounds_as_refs(repo)) == [
(b'refs/keep-arounds/' + sha_bytes, ctx)]
assert list(iter_keep_arounds_as_refs(repo, deref=False)) == [
(b'refs/keep-arounds/' + sha_bytes, sha_str)]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment