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

Moved latest_unique_successor in a common obsutil module

It will also be useful elsewhere
parent 4aabd418
No related branches found
No related tags found
No related merge requests found
...@@ -18,10 +18,9 @@ ...@@ -18,10 +18,9 @@
from mercurial import ( from mercurial import (
error, error,
hg, hg,
obsutil,
phases, phases,
pycompat, pycompat,
) )
import re import re
import traceback import traceback
...@@ -22,9 +21,11 @@ ...@@ -22,9 +21,11 @@
phases, phases,
pycompat, pycompat,
) )
import re import re
import traceback import traceback
from . import obsutil
class MultipleDescendants(LookupError): class MultipleDescendants(LookupError):
pass pass
...@@ -295,7 +296,7 @@ ...@@ -295,7 +296,7 @@
return self.published_topic_latest_hg_sha(topic, before_ctx) return self.published_topic_latest_hg_sha(topic, before_ctx)
try: try:
succctx = self.latest_unique_successor(before_ctx) succctx = obsutil.latest_unique_successor(before_ctx)
except error.Abort as exc: except error.Abort as exc:
if initial_import: if initial_import:
# we don't want to break an initial import because # we don't want to break an initial import because
...@@ -596,25 +597,3 @@ ...@@ -596,25 +597,3 @@
"Can't find public descendants of %r in topic %r" % ( "Can't find public descendants of %r in topic %r" % (
ctx.hex(), topic)) ctx.hex(), topic))
return self.repo[rev] return self.repo[rev]
def latest_unique_successor(self, ctx):
"""Return the latest of unique set of successors of a changeset.
The changeset is given by its context, and a context is also returned,
or `None` if there is no successor.
`Abort` gets raised if there are several sets of successors.
"""
successorssets = obsutil.successorssets(self.repo,
ctx.node())
if not successorssets:
return None
if len(successorssets) > 1:
# There is more than one set of successors, so we have
# a divergence, and we cannot handle it automatically
raise error.Abort(("Changeset %r evolved into a "
"divergent state") % ctx.hex())
# Single successor set: it can be one or many (split)
# In all cases, we can take the last one.
return self.repo[successorssets[0][-1]]
from mercurial import (
error,
obsutil as hgobsutil,
)
def latest_unique_successor(ctx):
"""Return the latest of unique set of successors of a changeset.
The changeset is given by its context, and a context is also returned,
or `None` if there is no successor.
`Abort` gets raised if there are several sets of successors.
"""
repo = ctx.repo()
successorssets = hgobsutil.successorssets(repo, ctx.node())
if not successorssets:
return None
if len(successorssets) > 1:
# There is more than one set of successors, so we have
# a divergence, and we cannot handle it automatically
raise error.Abort(("Changeset %r evolved into a "
"divergent state") % ctx.hex())
# Single successor set: it can be one or many (split)
# In all cases, we can take the last one.
return repo[successorssets[0][-1]]
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