##// END OF EJS Templates
localrepo: iteratively derive local repository type...
localrepo: iteratively derive local repository type This commit implements the dynamic local repository type derivation that was explained in the recent commit bfeab472e3c0 "localrepo: create new function for instantiating a local repo object." Instead of a static localrepository class/type which must be customized after construction, we now dynamically construct a type by building up base classes/types to represent specific repository interfaces. Conceptually, the end state is similar to what was happening when various extensions would monkeypatch the __class__ of newly-constructed repo instances. However, the approach is inverted. Instead of making the instance then customizing it, we do the customization up front by influencing the behavior of the type then we instantiate that custom type. This approach gives us much more flexibility. For example, we can use completely separate classes for implementing different aspects of the repository. For example, we could have one class representing revlog-based file storage and another representing non-revlog based file storage. When then choose which implementation to use based on the presence of repo requirements. A concern with this approach is that it creates a lot more types and complexity and that complexity adds overhead. Yes, it is true that this approach will result in more types being created. Yes, this is more complicated than traditional "instantiate a static type." However, I believe the alternatives to supporting alternate storage backends are just as complicated. (Before I arrived at this solution, I had patches storing factory functions on local repo instances for e.g. constructing a file storage instance. We ended up having a handful of these. And this was logically identical to assigning custom methods. Since we were logically changing the type of the instance, I figured it would be better to just use specialized types instead of introducing levels of abstraction at run-time.) On the performance front, I don't believe that having N base classes has any significant performance overhead compared to just a single base class. Intuition says that Python will need to iterate the base classes to find an attribute. However, CPython caches method lookups: as long as the __class__ or MRO isn't changing, method attribute lookup should be constant time after first access. And non-method attributes are stored in __dict__, of which there is only 1 per object, so the number of base classes for __dict__ is irrelevant. Anyway, this commit splits up the monolithic completelocalrepository interface into sub-interfaces: 1 for file storage and 1 representing everything else. We've taught ``makelocalrepository()`` to call a series of factory functions which will produce types implementing specific interfaces. It then calls type() to create a new type from the built-up list of base types. This commit should be considered a start and not the end state. I suspect we'll hit a number of problems as we start to implement alternate storage backends: * Passing custom arguments to __init__ and setting custom attributes on __dict__. * Customizing the set of interfaces that are needed. e.g. the "readonly" intent could translate to not requesting an interface providing methods related to writing. * More ergonomic way for extensions to insert themselves so their callbacks aren't unconditionally called. * Wanting to modify vfs instances, other arguments passed to __init__. That being said, this code is usable in its current state and I'm convinced future commits will demonstrate the value in this approach. Differential Revision: https://phab.mercurial-scm.org/D4642

File last commit:

r37805:92213f67 default
r39800:e4e88157 default
Show More
destutil.py
446 lines | 16.4 KiB | text/x-python | PythonLexer
Pierre-Yves David
update: move default destination computation to a function...
r26569 # destutil.py - Mercurial utility function for command destination
#
# Copyright Matt Mackall <mpm@selenic.com> and other
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
Gregory Szorc
destutil: use absolute_import
r27333 from __future__ import absolute_import
Pierre-Yves David
update: move default destination computation to a function...
r26569 from .i18n import _
from . import (
Pierre-Yves David
destupdate: also include bookmark related logic...
r26641 bookmarks,
Pierre-Yves David
update: move default destination computation to a function...
r26569 error,
obsutil: move 'successorssets' to the new modules...
r33143 obsutil,
Yuya Nishihara
scmutil: proxy revrange() through repo to break import cycles...
r31025 scmutil,
Boris Feld
show: use the new stack definition for show stack...
r37020 stack
Pierre-Yves David
update: move default destination computation to a function...
r26569 )
Augie Fackler
rebase: introduce support for automatically rebasing orphan changes...
r37805 def orphanpossibledestination(repo, rev):
"""Return all changesets that may be a new parent for orphan `rev`.
This function works fine on non-orphan revisions, it's just silly
because there's no destination implied by obsolete markers, so
it'll return nothing.
"""
tonode = repo.changelog.node
parents = repo.changelog.parentrevs
torev = repo.changelog.rev
dest = set()
tovisit = list(parents(rev))
while tovisit:
r = tovisit.pop()
succsets = obsutil.successorssets(repo, tonode(r))
if not succsets:
# if there are no successors for r, r was probably pruned
# and we should walk up to r's parents to try and find
# some successors.
tovisit.extend(parents(r))
else:
# We should probably pick only one destination from split
# (case where '1 < len(ss)'), This could be the currently
# tipmost, but the correct result is less clear when
# results of the split have been moved such that they
# reside on multiple branches.
for ss in succsets:
for n in ss:
dr = torev(n)
if dr != -1:
dest.add(dr)
return dest
Martin von Zweigbergk
destutil: drop now-unused "check" parameter from destupdate()
r30962 def _destupdateobs(repo, clean):
Pierre-Yves David
destupdate: extract logic based on obsolescence marker in its own function...
r26723 """decide of an update destination from obsolescence markers"""
Pierre-Yves David
update: move default destination computation to a function...
r26569 node = None
wc = repo[None]
p1 = wc.p1()
Pierre-Yves David
destupdate: extract logic based on obsolescence marker in its own function...
r26723 movemark = None
Pierre-Yves David
update: move default destination computation to a function...
r26569
if p1.obsolete() and not p1.children():
# allow updating to successors
obsutil: move 'successorssets' to the new modules...
r33143 successors = obsutil.successorssets(repo, p1.node())
Pierre-Yves David
update: move default destination computation to a function...
r26569
# behavior of certain cases is as follows,
#
# divergent changesets: update to highest rev, similar to what
# is currently done when there are more than one head
# (i.e. 'tip')
#
# replaced changesets: same as divergent except we know there
# is no conflict
#
# pruned changeset: no update is done; though, we could
# consider updating to the first non-obsolete parent,
# similar to what is current done for 'hg prune'
if successors:
# flatten the list here handles both divergent (len > 1)
# and the usual case (len = 1)
successors = [n for sub in successors for n in sub]
# get the max revision for the given successors set,
# i.e. the 'tip' of a set
node = repo.revs('max(%ln)', successors).first()
Pierre-Yves David
destupdate: move obsolete handling first...
r26722 if bookmarks.isactivewdirparent(repo):
movemark = repo['.'].node()
Pierre-Yves David
destupdate: extract logic based on obsolescence marker in its own function...
r26723 return node, movemark, None
Martin von Zweigbergk
destutil: drop now-unused "check" parameter from destupdate()
r30962 def _destupdatebook(repo, clean):
Pierre-Yves David
destupdate: extract logic based on bookmarks in its own function...
r26724 """decide on an update destination from active bookmark"""
# we also move the active bookmark, if any
Martin von Zweigbergk
bookmarks: calculateupdate() returns a bookmark, not a rev...
r37377 node = None
Martin von Zweigbergk
bookmarks: drop always-None argument from calculateupdate()...
r37393 activemark, movemark = bookmarks.calculateupdate(repo.ui, repo)
Martin von Zweigbergk
bookmarks: calculateupdate() returns a bookmark, not a rev...
r37377 if activemark is not None:
Martin von Zweigbergk
destutil: look up bookmarks only among bookmarks...
r37470 node = repo._bookmarks[activemark]
Pierre-Yves David
destupdate: extract logic based on bookmarks in its own function...
r26724 return node, movemark, activemark
Martin von Zweigbergk
destutil: drop now-unused "check" parameter from destupdate()
r30962 def _destupdatebranch(repo, clean):
FUJIWARA Katsunori
destutil: choose non-closed branch head at first (BC)...
r28385 """decide on an update destination from current branch
This ignores closed branch heads.
"""
Pierre-Yves David
destupdate: extract logic based on branch in its own function...
r26725 wc = repo[None]
movemark = node = None
FUJIWARA Katsunori
destutil: replace wc.branch() invocations by cached value for efficiency
r28235 currentbranch = wc.branch()
liscju
update: fix bare --clean to work on new branch (issue5003) (BC)...
r29284
if clean:
currentbranch = repo['.'].branch()
FUJIWARA Katsunori
destutil: use cached branch information instead of query for efficiency...
r28236 if currentbranch in repo.branchmap():
FUJIWARA Katsunori
destutil: choose non-closed branch head at first (BC)...
r28385 heads = repo.branchheads(currentbranch)
FUJIWARA Katsunori
destutil: use cached branch information instead of query for efficiency...
r28236 if heads:
node = repo.revs('max(.::(%ln))', heads).first()
Pierre-Yves David
destupdate: extract logic based on branch in its own function...
r26725 if bookmarks.isactivewdirparent(repo):
movemark = repo['.'].node()
Yuya Nishihara
update: resurrect bare update from null parent to tip-most branch head...
r28924 elif currentbranch == 'default' and not wc.p1():
# "null" parent belongs to "default" branch, but it doesn't exist, so
# update to the tipmost non-closed branch head
node = repo.revs('max(head() and not closed())').first()
FUJIWARA Katsunori
destutil: use cached branch information instead of query for efficiency...
r28236 else:
liscju
update: fix bare update to work on new branch...
r28903 node = repo['.'].node()
Pierre-Yves David
destupdate: extract logic based on branch in its own function...
r26725 return node, movemark, None
Martin von Zweigbergk
destutil: drop now-unused "check" parameter from destupdate()
r30962 def _destupdatebranchfallback(repo, clean):
FUJIWARA Katsunori
destutil: choose non-closed branch head at first (BC)...
r28385 """decide on an update destination from closed heads in current branch"""
wc = repo[None]
currentbranch = wc.branch()
movemark = None
if currentbranch in repo.branchmap():
# here, all descendant branch heads are closed
heads = repo.branchheads(currentbranch, closed=True)
assert heads, "any branch has at least one head"
node = repo.revs('max(.::(%ln))', heads).first()
assert node is not None, ("any revision has at least "
"one descendant branch head")
if bookmarks.isactivewdirparent(repo):
movemark = repo['.'].node()
else:
# here, no "default" branch, and all branches are closed
node = repo.lookup('tip')
assert node is not None, "'tip' exists even in empty repository"
return node, movemark, None
Mads Kiilerich
spelling: fixes of non-dictionary words
r30332 # order in which each step should be evaluated
Pierre-Yves David
destupdate: have a generic and extensible way to run each step...
r26726 # steps are run until one finds a destination
FUJIWARA Katsunori
destutil: choose non-closed branch head at first (BC)...
r28385 destupdatesteps = ['evolution', 'bookmark', 'branch', 'branchfallback']
Pierre-Yves David
destupdate: have a generic and extensible way to run each step...
r26726 # mapping to ease extension overriding steps.
destupdatestepmap = {'evolution': _destupdateobs,
'bookmark': _destupdatebook,
'branch': _destupdatebranch,
FUJIWARA Katsunori
destutil: choose non-closed branch head at first (BC)...
r28385 'branchfallback': _destupdatebranchfallback,
Pierre-Yves David
destupdate: have a generic and extensible way to run each step...
r26726 }
Martin von Zweigbergk
destutil: drop now-unused "check" parameter from destupdate()
r30962 def destupdate(repo, clean=False):
Pierre-Yves David
destupdate: extract logic based on obsolescence marker in its own function...
r26723 """destination for bare update operation
return (rev, movemark, activemark)
- rev: the revision to update to,
- movemark: node to move the active bookmark from
(cf bookmark.calculate update),
- activemark: a bookmark to activate at the end of the update.
"""
Pierre-Yves David
destupdate: have a generic and extensible way to run each step...
r26726 node = movemark = activemark = None
Pierre-Yves David
destupdate: extract logic based on obsolescence marker in its own function...
r26723
Pierre-Yves David
destupdate: have a generic and extensible way to run each step...
r26726 for step in destupdatesteps:
Martin von Zweigbergk
destutil: drop now-unused "check" parameter from destupdate()
r30962 node, movemark, activemark = destupdatestepmap[step](repo, clean)
Pierre-Yves David
destupdate: have a generic and extensible way to run each step...
r26726 if node is not None:
break
Pierre-Yves David
destupdate: move the check related to the "clean" logic in the function...
r26628 rev = repo[node].rev()
Pierre-Yves David
destupdate: also include bookmark related logic...
r26641 return rev, movemark, activemark
Pierre-Yves David
destutil: move default merge destination into a function...
r26714
Pierre-Yves David
destutil: extract all 'mergedest' abort messages into a dictionary...
r28102 msgdestmerge = {
# too many matching divergent bookmark
'toomanybookmarks':
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 {'merge':
(_("multiple matching bookmarks to merge -"
" please merge with an explicit rev or bookmark"),
_("run 'hg heads' to see all heads")),
Pierre-Yves David
rebase: choose default destination the same way as 'hg merge' (BC)...
r28189 'rebase':
(_("multiple matching bookmarks to rebase -"
" please rebase to an explicit rev or bookmark"),
_("run 'hg heads' to see all heads")),
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 },
Pierre-Yves David
destutil: extract all 'mergedest' abort messages into a dictionary...
r28102 # no other matching divergent bookmark
'nootherbookmarks':
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 {'merge':
(_("no matching bookmark to merge - "
"please merge with an explicit rev or bookmark"),
_("run 'hg heads' to see all heads")),
Pierre-Yves David
rebase: choose default destination the same way as 'hg merge' (BC)...
r28189 'rebase':
(_("no matching bookmark to rebase - "
"please rebase to an explicit rev or bookmark"),
_("run 'hg heads' to see all heads")),
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 },
Pierre-Yves David
destutil: extract all 'mergedest' abort messages into a dictionary...
r28102 # branch have too many unbookmarked heads, no obvious destination
'toomanyheads':
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 {'merge':
(_("branch '%s' has %d heads - please merge with an explicit rev"),
_("run 'hg heads .' to see heads")),
Pierre-Yves David
rebase: choose default destination the same way as 'hg merge' (BC)...
r28189 'rebase':
(_("branch '%s' has %d heads - please rebase to an explicit rev"),
_("run 'hg heads .' to see heads")),
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 },
Pierre-Yves David
destutil: extract all 'mergedest' abort messages into a dictionary...
r28102 # branch have no other unbookmarked heads
'bookmarkedheads':
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 {'merge':
(_("heads are bookmarked - please merge with an explicit rev"),
_("run 'hg heads' to see all heads")),
Pierre-Yves David
rebase: choose default destination the same way as 'hg merge' (BC)...
r28189 'rebase':
(_("heads are bookmarked - please rebase to an explicit rev"),
_("run 'hg heads' to see all heads")),
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 },
Pierre-Yves David
destutil: extract all 'mergedest' abort messages into a dictionary...
r28102 # branch have just a single heads, but there is other branches
'nootherbranchheads':
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 {'merge':
(_("branch '%s' has one head - please merge with an explicit rev"),
_("run 'hg heads' to see all heads")),
Pierre-Yves David
rebase: choose default destination the same way as 'hg merge' (BC)...
r28189 'rebase':
(_("branch '%s' has one head - please rebase to an explicit rev"),
_("run 'hg heads' to see all heads")),
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 },
Pierre-Yves David
destutil: extract all 'mergedest' abort messages into a dictionary...
r28102 # repository have a single head
'nootherheads':
Pierre-Yves David
rebase: choose default destination the same way as 'hg merge' (BC)...
r28189 {'merge':
(_('nothing to merge'),
None),
'rebase':
(_('nothing to rebase'),
None),
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 },
Pierre-Yves David
destutil: extract all 'mergedest' abort messages into a dictionary...
r28102 # repository have a single head and we are not on it
'nootherheadsbehind':
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 {'merge':
(_('nothing to merge'),
_("use 'hg update' instead")),
Pierre-Yves David
rebase: choose default destination the same way as 'hg merge' (BC)...
r28189 'rebase':
(_('nothing to rebase'),
_("use 'hg update' instead")),
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 },
Pierre-Yves David
destutil: extract all 'mergedest' abort messages into a dictionary...
r28102 # We are not on a head
'notatheads':
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 {'merge':
(_('working directory not at a head revision'),
Pierre-Yves David
rebase: choose default destination the same way as 'hg merge' (BC)...
r28189 _("use 'hg update' or merge with an explicit revision")),
'rebase':
(_('working directory not at a head revision'),
_("use 'hg update' or rebase to an explicit revision"))
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 },
Pierre-Yves David
destutil: allow to specify an explicit source for the merge...
r28139 'emptysourceset':
{'merge':
(_('source set is empty'),
Pierre-Yves David
rebase: choose default destination the same way as 'hg merge' (BC)...
r28189 None),
'rebase':
(_('source set is empty'),
None),
Pierre-Yves David
destutil: allow to specify an explicit source for the merge...
r28139 },
'multiplebranchessourceset':
{'merge':
(_('source set is rooted in multiple branches'),
Pierre-Yves David
rebase: choose default destination the same way as 'hg merge' (BC)...
r28189 None),
'rebase':
(_('rebaseset is rooted in multiple named branches'),
_('specify an explicit destination with --dest')),
Pierre-Yves David
destutil: allow to specify an explicit source for the merge...
r28139 },
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 }
Pierre-Yves David
destutil: extract all 'mergedest' abort messages into a dictionary...
r28102
Pierre-Yves David
destutil: add the ability to specify a search space for rebase destination...
r29043 def _destmergebook(repo, action='merge', sourceset=None, destspace=None):
Pierre-Yves David
destmerge: extract logic based on bookmark into its own function...
r26727 """find merge destination in the active bookmark case"""
node = None
Augie Fackler
localrepo: extract bookmarkheads method to bookmarks.py...
r32381 bmheads = bookmarks.headsforactive(repo)
Martin von Zweigbergk
destutil: look up bookmarks only among bookmarks...
r37470 curhead = repo._bookmarks[repo._activebookmark]
Pierre-Yves David
destmerge: extract logic based on bookmark into its own function...
r26727 if len(bmheads) == 2:
if curhead == bmheads[0]:
node = bmheads[1]
else:
node = bmheads[0]
elif len(bmheads) > 2:
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 msg, hint = msgdestmerge['toomanybookmarks'][action]
Pierre-Yves David
destutil: add more precise error classes for destmerge...
r28141 raise error.ManyMergeDestAbort(msg, hint=hint)
Pierre-Yves David
destmerge: extract logic based on bookmark into its own function...
r26727 elif len(bmheads) <= 1:
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 msg, hint = msgdestmerge['nootherbookmarks'][action]
Pierre-Yves David
destutil: add more precise error classes for destmerge...
r28141 raise error.NoMergeDestAbort(msg, hint=hint)
Pierre-Yves David
destmerge: extract logic based on bookmark into its own function...
r26727 assert node is not None
return node
Pierre-Yves David
destutil: add the ability to specify a search space for rebase destination...
r29043 def _destmergebranch(repo, action='merge', sourceset=None, onheadcheck=True,
destspace=None):
Pierre-Yves David
destmerge: extract logic based on branch heads in its own function...
r26728 """find merge destination based on branch heads"""
node = None
Pierre-Yves David
destutil: allow to specify an explicit source for the merge...
r28139
if sourceset is None:
sourceset = [repo[repo.dirstate.p1()].rev()]
branch = repo.dirstate.branch()
elif not sourceset:
msg, hint = msgdestmerge['emptysourceset'][action]
Pierre-Yves David
destutil: add more precise error classes for destmerge...
r28141 raise error.NoMergeDestAbort(msg, hint=hint)
Pierre-Yves David
destutil: allow to specify an explicit source for the merge...
r28139 else:
branch = None
for ctx in repo.set('roots(%ld::%ld)', sourceset, sourceset):
if branch is not None and ctx.branch() != branch:
msg, hint = msgdestmerge['multiplebranchessourceset'][action]
Pierre-Yves David
destutil: add more precise error classes for destmerge...
r28141 raise error.ManyMergeDestAbort(msg, hint=hint)
Pierre-Yves David
destutil: allow to specify an explicit source for the merge...
r28139 branch = ctx.branch()
Pierre-Yves David
destmerge: extract logic based on branch heads in its own function...
r26728 bheads = repo.branchheads(branch)
Pierre-Yves David
destutil: ensure we offer 'hg update' hint when not at head in all cases...
r28161 onhead = repo.revs('%ld and %ln', sourceset, bheads)
if onheadcheck and not onhead:
Pierre-Yves David
destutil: allow to specify an explicit source for the merge...
r28139 # Case A: working copy if not on a head. (merge only)
Pierre-Yves David
destutil: document various failure cases...
r28105 #
# This is probably a user mistake We bailout pointing at 'hg update'
Pierre-Yves David
merge: give priority to "not at head" failures for bare 'hg merge'...
r28103 if len(repo.heads()) <= 1:
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 msg, hint = msgdestmerge['nootherheadsbehind'][action]
Pierre-Yves David
merge: give priority to "not at head" failures for bare 'hg merge'...
r28103 else:
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 msg, hint = msgdestmerge['notatheads'][action]
Pierre-Yves David
merge: give priority to "not at head" failures for bare 'hg merge'...
r28103 raise error.Abort(msg, hint=hint)
Pierre-Yves David
destutil: allow to specify an explicit source for the merge...
r28139 # remove heads descendants of source from the set
bheads = list(repo.revs('%ln - (%ld::)', bheads, sourceset))
Pierre-Yves David
destutil: remove current head from list of candidates early...
r28138 # filters out bookmarked heads
Pierre-Yves David
destutil: allow to specify an explicit source for the merge...
r28139 nbhs = list(repo.revs('%ld - bookmark()', bheads))
Pierre-Yves David
destutil: add the ability to specify a search space for rebase destination...
r29043
if destspace is not None:
# restrict search space
# used in the 'hg pull --rebase' case, see issue 5214.
nbhs = list(repo.revs('%ld and %ld', destspace, nbhs))
Pierre-Yves David
destutil: remove current head from list of candidates early...
r28138 if len(nbhs) > 1:
# Case B: There is more than 1 other anonymous heads
Pierre-Yves David
destutil: document various failure cases...
r28105 #
# This means that there will be more than 1 candidate. This is
# ambiguous. We abort asking the user to pick as explicit destination
# instead.
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 msg, hint = msgdestmerge['toomanyheads'][action]
Pierre-Yves David
destutil: remove current head from list of candidates early...
r28138 msg %= (branch, len(bheads) + 1)
Pierre-Yves David
destutil: add more precise error classes for destmerge...
r28141 raise error.ManyMergeDestAbort(msg, hint=hint)
Pierre-Yves David
destutil: remove current head from list of candidates early...
r28138 elif not nbhs:
# Case B: There is no other anonymous heads
Pierre-Yves David
destutil: document various failure cases...
r28105 #
# This means that there is no natural candidate to merge with.
# We abort, with various messages for various cases.
Pierre-Yves David
destutil: remove current head from list of candidates early...
r28138 if bheads:
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 msg, hint = msgdestmerge['bookmarkedheads'][action]
Pierre-Yves David
destutil: extract all 'mergedest' abort messages into a dictionary...
r28102 elif len(repo.heads()) > 1:
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 msg, hint = msgdestmerge['nootherbranchheads'][action]
Pierre-Yves David
destutil: extract all 'mergedest' abort messages into a dictionary...
r28102 msg %= branch
Pierre-Yves David
destutil: ensure we offer 'hg update' hint when not at head in all cases...
r28161 elif not onhead:
# if 'onheadcheck == False' (rebase case),
# this was not caught in Case A.
msg, hint = msgdestmerge['nootherheadsbehind'][action]
Pierre-Yves David
destutil: extract all 'mergedest' abort messages into a dictionary...
r28102 else:
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 msg, hint = msgdestmerge['nootherheads'][action]
Pierre-Yves David
destutil: add more precise error classes for destmerge...
r28141 raise error.NoMergeDestAbort(msg, hint=hint)
Pierre-Yves David
destmerge: extract logic based on branch heads in its own function...
r26728 else:
node = nbhs[0]
assert node is not None
return node
Pierre-Yves David
destutil: add the ability to specify a search space for rebase destination...
r29043 def destmerge(repo, action='merge', sourceset=None, onheadcheck=True,
destspace=None):
Pierre-Yves David
destutil: add an 'action' layer to the destmerge message dictionary...
r28137 """return the default destination for a merge
(or raise exception about why it can't pick one)
:action: the action being performed, controls emitted error message
"""
Pierre-Yves David
destutil: add the ability to specify a search space for rebase destination...
r29043 # destspace is here to work around issues with `hg pull --rebase` see
# issue5214 for details
Pierre-Yves David
destutil: move default merge destination into a function...
r26714 if repo._activebookmark:
Pierre-Yves David
destutil: add the ability to specify a search space for rebase destination...
r29043 node = _destmergebook(repo, action=action, sourceset=sourceset,
destspace=destspace)
Pierre-Yves David
destutil: move default merge destination into a function...
r26714 else:
Pierre-Yves David
destutil: allow to disable the "on head check" in destmerge...
r28140 node = _destmergebranch(repo, action=action, sourceset=sourceset,
Pierre-Yves David
destutil: add the ability to specify a search space for rebase destination...
r29043 onheadcheck=onheadcheck, destspace=destspace)
Pierre-Yves David
destutil: move default merge destination into a function...
r26714 return repo[node].rev()
Gregory Szorc
histedit: pick an appropriate base changeset by default (BC)...
r27262
def desthistedit(ui, repo):
"""Default base revision to edit for `hg histedit`."""
Boris Feld
histedit: use the new stack definition for histedit...
r37021 default = ui.config('histedit', 'defaultrev')
if default is None:
revs = stack.getstack(repo)
elif default:
Gregory Szorc
destutil: use scmutil.revrange for desthistedit (issue5001)...
r27559 revs = scmutil.revrange(repo, [default])
Boris Feld
histedit: use the new stack definition for histedit...
r37021
if revs:
Boris Feld
histedit: simplify desthistedit...
r37408 # Take the first revision of the revset as the root
return revs.min()
Gregory Szorc
histedit: pick an appropriate base changeset by default (BC)...
r27262
return None
Pierre-Yves David
update: warn about other topological heads on bare update...
r28029
Gregory Szorc
show: implement "stack" view...
r33194 def stackbase(ui, repo):
Boris Feld
show: use the new stack definition for show stack...
r37020 revs = stack.getstack(repo)
Boris Feld
stack: return a sorted smartrev by default...
r37022 return revs.first() if revs else None
Gregory Szorc
show: implement "stack" view...
r33194
Pierre-Yves David
update: warn about other topological heads on bare update...
r28029 def _statusotherbook(ui, repo):
Augie Fackler
localrepo: extract bookmarkheads method to bookmarks.py...
r32381 bmheads = bookmarks.headsforactive(repo)
Martin von Zweigbergk
destutil: look up bookmarks only among bookmarks...
r37470 curhead = repo._bookmarks[repo._activebookmark]
Pierre-Yves David
update: warn about other topological heads on bare update...
r28029 if repo.revs('%n and parents()', curhead):
# we are on the active bookmark
bmheads = [b for b in bmheads if curhead != b]
if bmheads:
msg = _('%i other divergent bookmarks for "%s"\n')
ui.status(msg % (len(bmheads), repo._activebookmark))
def _statusotherbranchheads(ui, repo):
currentbranch = repo.dirstate.branch()
FUJIWARA Katsunori
destutil: show message about other branch heads, even if on a closed head...
r28266 allheads = repo.branchheads(currentbranch, closed=True)
Pierre-Yves David
update: warn about other topological heads on bare update...
r28029 heads = repo.branchheads(currentbranch)
FUJIWARA Katsunori
destutil: show message about other branch heads, even if on a closed head...
r28266 if repo.revs('%ln and parents()', allheads):
# we are on a head, even though it might be closed
FUJIWARA Katsunori
destutil: choose non-closed branch head at first (BC)...
r28385 #
# on closed otherheads
# ========= ==========
# o 0 all heads for current branch are closed
# N only descendant branch heads are closed
# x 0 there is only one non-closed branch head
# N there are some non-closed branch heads
# ========= ==========
FUJIWARA Katsunori
destutil: add new local variable to increase readability...
r28233 otherheads = repo.revs('%ln - parents()', heads)
FUJIWARA Katsunori
destutil: choose non-closed branch head at first (BC)...
r28385 if repo['.'].closesbranch():
FUJIWARA Katsunori
destutil: show message and hint at updating to the closed head as warning
r28684 ui.warn(_('no open descendant heads on branch "%s", '
FUJIWARA Katsunori
destutil: make messages at updating to the closed head usual form...
r28683 'updating to a closed head\n') %
(currentbranch))
FUJIWARA Katsunori
destutil: choose non-closed branch head at first (BC)...
r28385 if otherheads:
timeless
update: use single quotes in use warning
r29964 ui.warn(_("(committing will reopen the head, "
"use 'hg heads .' to see %i other heads)\n") %
FUJIWARA Katsunori
destutil: make messages at updating to the closed head usual form...
r28683 (len(otherheads)))
FUJIWARA Katsunori
destutil: choose non-closed branch head at first (BC)...
r28385 else:
FUJIWARA Katsunori
destutil: show message and hint at updating to the closed head as warning
r28684 ui.warn(_('(committing will reopen branch "%s")\n') %
FUJIWARA Katsunori
destutil: make messages at updating to the closed head usual form...
r28683 (currentbranch))
FUJIWARA Katsunori
destutil: choose non-closed branch head at first (BC)...
r28385 elif otherheads:
Pulkit Goyal
update: show the commit to which we updated in case of multiple heads (BC)...
r32698 curhead = repo['.']
ui.status(_('updated to "%s: %s"\n') % (curhead,
curhead.description().split('\n')[0]))
Pierre-Yves David
update: warn about other topological heads on bare update...
r28029 ui.status(_('%i other heads for branch "%s"\n') %
FUJIWARA Katsunori
destutil: add new local variable to increase readability...
r28233 (len(otherheads), currentbranch))
Pierre-Yves David
update: warn about other topological heads on bare update...
r28029
def statusotherdests(ui, repo):
"""Print message about other head"""
# XXX we should probably include a hint:
# - about what to do
# - how to see such heads
if repo._activebookmark:
_statusotherbook(ui, repo)
else:
_statusotherbranchheads(ui, repo)