hgext/drophack.py
author Pierre-Yves David <pierre-yves.david@fb.com>
Sat, 07 Mar 2015 02:32:43 -0800
changeset 1225 577f5340be6f
parent 1210 1f8428096078
child 1553 ed63bf62ff02
permissions -rw-r--r--
inhibit: Add some inhibition clearing mechanism We do not want to keep inhibition marker around for ever. So we are removing the one applying on public changeset.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
790
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     1
# This software may be used and distributed according to the terms of the
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     2
# GNU General Public License version 2 or any later version.
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     3
'''This extension add a hacky command to drop changeset during review
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     4
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     5
This extension is intended as a temporary hack to allow Matt Mackall to use
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     6
evolve in the Mercurial review it self. You should probably not use it if your
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     7
name is not Matt Mackall.
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     8
'''
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     9
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    10
import os
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    11
import time
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    12
import contextlib
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    13
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    14
from mercurial.i18n import _
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    15
from mercurial import cmdutil
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    16
from mercurial import repair
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    17
from mercurial import scmutil
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    18
from mercurial import lock as lockmod
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    19
from mercurial import util
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    20
from mercurial import commands
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    21
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    22
cmdtable = {}
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    23
command = cmdutil.command(cmdtable)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    24
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    25
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    26
@contextlib.contextmanager
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    27
def timed(ui, caption):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    28
    ostart = os.times()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    29
    cstart = time.time()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    30
    yield
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    31
    cstop = time.time()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    32
    ostop = os.times()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    33
    wall = cstop - cstart
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    34
    user = ostop[0] - ostart[0]
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    35
    sys  = ostop[1] - ostart[1]
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    36
    comb = user + sys
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    37
    ui.write("%s: wall %f comb %f user %f sys %f\n"
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    38
             % (caption, wall, comb, user, sys))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    39
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    40
def obsmarkerchainfrom(obsstore, nodes):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    41
    """return all marker chain starting from node
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    42
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    43
    Starting from mean "use as successors"."""
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    44
    # XXX need something smarter for descendant of bumped changeset
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    45
    seennodes = set(nodes)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    46
    seenmarkers = set()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    47
    pendingnodes = set(nodes)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    48
    precursorsmarkers = obsstore.precursors
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    49
    while pendingnodes:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    50
        current = pendingnodes.pop()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    51
        new = set()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    52
        for precmark in precursorsmarkers.get(current, ()):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    53
            if precmark in seenmarkers:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    54
                continue
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    55
            seenmarkers.add(precmark)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    56
            new.add(precmark[0])
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    57
            yield precmark
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    58
        new -= seennodes
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    59
        pendingnodes |= new
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    60
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    61
def stripmarker(ui, repo, markers):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    62
    """remove <markers> from the repo obsstore
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    63
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    64
    The old obsstore content is saved in a `obsstore.prestrip` file
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    65
    """
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    66
    repo = repo.unfiltered()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    67
    repo.destroying()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    68
    oldmarkers = list(repo.obsstore._all)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    69
    util.rename(repo.sjoin('obsstore'),
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    70
                repo.join('obsstore.prestrip'))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    71
    del repo.obsstore # drop the cache
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    72
    newstore = repo.obsstore
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    73
    assert not newstore # should be empty after rename
812
60dd0c401034 drophack: major speedup to marker stripping
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 790
diff changeset
    74
    newmarkers = [m for m in oldmarkers if m not in markers]
790
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    75
    tr = repo.transaction('drophack')
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    76
    try:
812
60dd0c401034 drophack: major speedup to marker stripping
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 790
diff changeset
    77
        newstore.add(tr, newmarkers)
790
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    78
        tr.close()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    79
    finally:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    80
        tr.release()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    81
    repo.destroyed()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    82
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    83
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    84
@command('drop', [('r', 'rev', [], 'revision to update')], _('[-r] revs'))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    85
def cmddrop(ui, repo, *revs, **opts):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    86
    """I'm hacky do not use me!
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    87
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    88
    This command strip a changeset, its precursors and all obsolescence marker
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    89
    associated to its chain.
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    90
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    91
    There is no way to limit the extend of the purge yet. You may have to
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    92
    repull from other source to get some changeset and obsolescence marker
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    93
    back.
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    94
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    95
    This intended for Matt Mackall usage only. do not use me.
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    96
    """
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    97
    revs = list(revs)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    98
    revs.extend(opts['rev'])
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    99
    if not revs:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   100
        revs = ['.']
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   101
    # get the changeset
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   102
    revs = scmutil.revrange(repo, revs)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   103
    if not revs:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   104
        ui.write_err('no revision to drop\n')
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   105
        return 1
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   106
    # lock from the beginning to prevent race
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   107
    wlock = lock = None
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   108
    try:
1001
f7f4a1fac6c0 test: use `hg log` in the `getid` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 812
diff changeset
   109
        wlock = repo.wlock()
790
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   110
        lock = repo.lock()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   111
        # check they have no children
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   112
        if repo.revs('%ld and public()', revs):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   113
            ui.write_err('cannot drop public revision')
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   114
            return 1
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   115
        if repo.revs('children(%ld) - %ld', revs, revs):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   116
            ui.write_err('cannot drop revision with children')
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   117
            return 1
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   118
        if repo.revs('. and %ld', revs):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   119
            newrevs = repo.revs('max(::. - %ld)', revs)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   120
            if newrevs:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   121
                assert len(newrevs) == 1
1121
1a39b1b8e092 drophack: use `first` and `last` on smartset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1001
diff changeset
   122
                newrev = newrevs.first()
790
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   123
            else:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   124
                newrev = -1
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   125
            commands.update(ui, repo, newrev)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   126
            ui.status(_('working directory now at %s\n') % repo[newrev])
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   127
        # get all markers and successors up to root
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   128
        nodes = [repo[r].node() for r in revs]
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   129
        with timed(ui, 'search obsmarker'):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   130
            markers = set(obsmarkerchainfrom(repo.obsstore, nodes))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   131
        ui.write('%i obsmarkers found\n' % len(markers))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   132
        cl = repo.unfiltered().changelog
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   133
        with timed(ui, 'search nodes'):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   134
            allnodes = set(nodes)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   135
            allnodes.update(m[0] for m in markers if cl.hasnode(m[0]))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   136
        ui.write('%i nodes found\n' % len(allnodes))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   137
        cl = repo.changelog
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   138
        visiblenodes = set(n for n in allnodes if cl.hasnode(n))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   139
        # check constraint again
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   140
        if repo.revs('%ln and public()', visiblenodes):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   141
            ui.write_err('cannot drop public revision')
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   142
            return 1
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   143
        if repo.revs('children(%ln) - %ln', visiblenodes, visiblenodes):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   144
            ui.write_err('cannot drop revision with children')
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   145
            return 1
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   146
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   147
        if markers:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   148
            # strip them
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   149
            with timed(ui, 'strip obsmarker'):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   150
                stripmarker(ui, repo, markers)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   151
        # strip the changeset
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   152
        with timed(ui, 'strip nodes'):
1210
1f8428096078 drophack: fix to match upstream repair.strip
Durham Goode <durham@fb.com>
parents: 1121
diff changeset
   153
            repair.strip(ui, repo, list(allnodes), backup="all", topic='drophack')
790
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   154
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   155
    finally:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   156
        lockmod.release(lock, wlock)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   157
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   158
    # rewrite the whole file.
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   159
    # print data.
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   160
    # - time to compute the chain
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   161
    # - time to strip the changeset
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   162
    # - time to strip the obs marker.