mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 17:27:53 +03:00
6317ba0ca2
Summary: The functionality we care about is provided by the `fbamend` extension. Therefore, lets replace the `amend` extension with the `fbamend` extension. Reviewed By: farnz Differential Revision: D10320739 fbshipit-source-id: 5700d39f488777fcc4033f60ce0a51cda15ef2ad
72 lines
2.7 KiB
Python
72 lines
2.7 KiB
Python
# revsets.py - revset definitions
|
|
#
|
|
# Copyright 2017 Facebook, Inc.
|
|
#
|
|
# This software may be used and distributed according to the terms of the
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from mercurial import obsutil, phases, registrar, revset, smartset
|
|
from mercurial.node import nullrev
|
|
|
|
|
|
revsetpredicate = registrar.revsetpredicate()
|
|
|
|
|
|
@revsetpredicate("_destrestack(SRC)")
|
|
def _destrestack(repo, subset, x):
|
|
"""restack destination for given single source revision"""
|
|
unfi = repo.unfiltered()
|
|
obsoleted = unfi.revs("obsolete()")
|
|
getparents = unfi.changelog.parentrevs
|
|
getphase = unfi._phasecache.phase
|
|
nodemap = unfi.changelog.nodemap
|
|
|
|
src = revset.getset(repo, subset, x).first()
|
|
|
|
# Empty src or already obsoleted - Do not return a destination
|
|
if not src or src in obsoleted:
|
|
return smartset.baseset()
|
|
|
|
# Find the obsoleted "base" by checking source's parent recursively
|
|
base = src
|
|
while base not in obsoleted:
|
|
base = getparents(base)[0]
|
|
# When encountering a public revision which cannot be obsoleted, stop
|
|
# the search early and return no destination. Do the same for nullrev.
|
|
if getphase(repo, base) == phases.public or base == nullrev:
|
|
return smartset.baseset()
|
|
|
|
# Find successors for given base
|
|
# NOTE: Ideally we can use obsutil.successorssets to detect divergence
|
|
# case. However it does not support cycles (unamend) well. So we use
|
|
# allsuccessors and pick non-obsoleted successors manually as a workaround.
|
|
basenode = repo[base].node()
|
|
succnodes = [
|
|
n
|
|
for n in obsutil.allsuccessors(repo.obsstore, [basenode])
|
|
if (n != basenode and n in nodemap and nodemap[n] not in obsoleted)
|
|
]
|
|
|
|
# In case of a split, only keep its heads
|
|
succrevs = list(unfi.revs("heads(%ln)", succnodes))
|
|
|
|
if len(succrevs) == 0:
|
|
# Prune - Find the first non-obsoleted ancestor
|
|
while base in obsoleted:
|
|
base = getparents(base)[0]
|
|
if base == nullrev:
|
|
# Root node is pruned. The new base (destination) is the
|
|
# virtual nullrev.
|
|
return smartset.baseset([nullrev])
|
|
return smartset.baseset([base])
|
|
elif len(succrevs) == 1:
|
|
# Unique visible successor case - A valid destination
|
|
return smartset.baseset([succrevs[0]])
|
|
else:
|
|
# Multiple visible successors - Choose the one with a greater revision
|
|
# number. This is to be compatible with restack old behavior. We might
|
|
# want to revisit it when we introduce the divergence concept to users.
|
|
return smartset.baseset([max(succrevs)])
|