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

branch: don't let bookmarks shadow the default GitLab branch

We introduce a flag in the inner function that sorts out what
to do of the branchmap entries, and use it for the default GitLab
branch only.

As the test demonstrates, the default GitLab branch will still
point to the latest bookmarked head, which is consistent with
what happens with "wild" multiple heads.

This is a minor change of behaviour compared to the Heptapod
standard, in which the default GitLab branch would not move in
that case. The reason is that we don't have a natural support to
store the previous position of the default GitLab branch.
Of course hg-git based repositories have/had this extra state, in
the form of the actual Git branch. The new behaviour is not worse
and as much arbitrary as the previous one, and will of course
be matched by py-heptapod's mirrorring to Git.
parent 9abda71b
No related branches found
No related tags found
1 merge request!14Adjustments to pass Heptapod functional tests
......@@ -15,5 +15,6 @@
parse_wild_gitlab_branch,
gitlab_branch_ref,
)
from hgext3rd.heptapod.branch import get_default_gitlab_branch
......@@ -18,9 +19,10 @@
def _extract_branchmap_heads(repo, entry):
def _extract_branchmap_heads(repo, entry,
avoid_bookmark_shadowing=False):
"""From the given branchmap entry, extract default head and list of heads.
The default head is what needs to be returned for a simple branchmap
branch lookup. It can be ``None`` if all heads are invisible to GitLab
(closed or bookmarked).
......@@ -21,12 +23,14 @@
"""From the given branchmap entry, extract default head and list of heads.
The default head is what needs to be returned for a simple branchmap
branch lookup. It can be ``None`` if all heads are invisible to GitLab
(closed or bookmarked).
:param avoid_bookmark_shadowing: if ``True`` the bookmarked revision with
the highest revno can be returned if there's nothing else
:return: (default head, all heads visible to GitLab), all given as
:class:`changectx` instances.
"""
# branchmap entries results are already sorted by increasing rev number
contexts = (repo[node] for node in entry)
visible = [c for c in contexts if not (c.closesbranch() or c.bookmarks())]
......@@ -27,9 +31,16 @@
:return: (default head, all heads visible to GitLab), all given as
:class:`changectx` instances.
"""
# branchmap entries results are already sorted by increasing rev number
contexts = (repo[node] for node in entry)
visible = [c for c in contexts if not (c.closesbranch() or c.bookmarks())]
if not visible and avoid_bookmark_shadowing:
# rare case, performance is irrelevant, we can re-lookup
for ctx in (repo[node] for node in reversed(entry)):
if not ctx.obsolete() and not ctx.closesbranch():
return ctx, [ctx]
if not visible:
return None, visible
......@@ -76,7 +87,11 @@
entry = repo.branchmap()[branchmap_key]
except KeyError:
return None
return _extract_branchmap_heads(repo, entry)[0]
return _extract_branchmap_heads(
repo, entry,
avoid_bookmark_shadowing=(
gl_branch == get_default_gitlab_branch(repo)),
)[0]
# last chance: bookmarks
bookmark_node = repo._bookmarks.get(gl_branch)
......@@ -93,7 +108,11 @@
instance.
"""
for key, entry in pycompat.iteritems(repo.branchmap()):
default, visible = _extract_branchmap_heads(repo, entry)
gl_branch = gitlab_branch_from_branchmap_branch(key)
default, visible = _extract_branchmap_heads(
repo, entry,
avoid_bookmark_shadowing=(
gl_branch == get_default_gitlab_branch(repo)))
if not visible:
continue
......@@ -97,7 +116,7 @@
if not visible:
continue
yield gitlab_branch_from_branchmap_branch(key), default
yield gl_branch, default
if len(visible) > 1:
for head in visible:
yield b'wild/' + head.hex(), head
......
......@@ -14,6 +14,10 @@
iter_gitlab_branches,
)
from hgext3rd.heptapod.branch import (
set_default_gitlab_branch,
)
def make_repo(path):
return LocalRepoWrapper.init(path,
......@@ -71,3 +75,26 @@
# finally, a formally correct wild branch, with no corresponding changeset
assert gitlab_branch_head(repo, b'wild/' + (b'cafe' * 10)) is None
def test_bookmarks_not_shadowing_default_branch(tmpdir):
wrapper = make_repo(tmpdir)
repo = wrapper.repo
base = wrapper.write_commit('foo') # not strictly necessary
head1 = wrapper.write_commit('foo')
default_branch = b'branch/default'
set_default_gitlab_branch(repo, default_branch)
wrapper.command('bookmark', b'book1', rev=head1.hex())
assert gitlab_branch_head(repo, default_branch) == head1
head2 = wrapper.write_commit('foo', parent=base)
wrapper.command('bookmark', b'book2', rev=head2.hex())
assert gitlab_branch_head(repo, default_branch) == head2
assert set(iter_gitlab_branches(repo)) == {
(b'book1', head1),
(b'book2', head2),
(default_branch, head2)
}
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