mirror of
https://github.com/facebook/sapling.git
synced 2024-10-12 17:58:27 +03:00
9dc21f8d0b
Summary: D13853115 adds `edenscm/` to `sys.path` and code still uses `import mercurial`. That has nasty problems if both `import mercurial` and `import edenscm.mercurial` are used, because Python would think `mercurial.foo` and `edenscm.mercurial.foo` are different modules so code like `try: ... except mercurial.error.Foo: ...`, or `isinstance(x, mercurial.foo.Bar)` would fail to handle the `edenscm.mercurial` version. There are also some module-level states (ex. `extensions._extensions`) that would cause trouble if they have multiple versions in a single process. Change imports to use the `edenscm` so ideally the `mercurial` is no longer imported at all. Add checks in extensions.py to catch unexpected extensions importing modules from the old (wrong) locations when running tests. Reviewed By: phillco Differential Revision: D13868981 fbshipit-source-id: f4e2513766957fd81d85407994f7521a08e4de48
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 edenscm.mercurial import obsutil, phases, registrar, revset, smartset
|
|
from edenscm.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)])
|