hgext/evolve.py
author Laurent Charignon <lcharignon@fb.com>
Mon, 20 Apr 2015 13:39:18 -0700
changeset 1303 508f9911b042
parent 1302 ebcf23fe3032
child 1313 31e96036acd3
permissions -rw-r--r--
inhibit: updating to a obsolete commit prints warning message We move the inhibition marker in the same wlock than the update operation, this clears the warning message. To make it work we display the warning message on lock release in evolve.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     1
# Copyright 2011 Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     2
#                Logilab SA        <contact@logilab.fr>
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     3
#                Pierre-Yves David <pierre-yves.david@ens-lyon.org>
519
9825c7da5b54 ensure all file have a copyright notice
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 517
diff changeset
     4
#                Patrick Mezard <patrick@mezard.eu>
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     5
#
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     6
# This software may be used and distributed according to the terms of the
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     7
# GNU General Public License version 2 or any later version.
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     8
893
12ed6dfa8eea evolve: downcase first word in module doc
Olle Lundberg <geek@nerd.sh>
parents: 892
diff changeset
     9
'''extends Mercurial feature related to Changeset Evolution
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    10
540
8c5da9e75ae0 evolve: fixing syntax/grammar
Patrick Mezard <patrick@mezard.eu>
parents: 539
diff changeset
    11
This extension provides several commands to mutate history and deal with
8c5da9e75ae0 evolve: fixing syntax/grammar
Patrick Mezard <patrick@mezard.eu>
parents: 539
diff changeset
    12
issues it may raise.
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    13
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    14
It also:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    15
540
8c5da9e75ae0 evolve: fixing syntax/grammar
Patrick Mezard <patrick@mezard.eu>
parents: 539
diff changeset
    16
    - enables the "Changeset Obsolescence" feature of mercurial,
8c5da9e75ae0 evolve: fixing syntax/grammar
Patrick Mezard <patrick@mezard.eu>
parents: 539
diff changeset
    17
    - alters core commands and extensions that rewrite history to use
8c5da9e75ae0 evolve: fixing syntax/grammar
Patrick Mezard <patrick@mezard.eu>
parents: 539
diff changeset
    18
      this feature,
1011
0b44ae30cf3b evolve: drop reference to 2.3 in the extension help text
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 973
diff changeset
    19
    - improves some aspect of the early implementation in Mercurial core
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    20
'''
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    21
1281
891c3ce894fa prepare release 5.1.4
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1280
diff changeset
    22
__version__ = '5.1.4'
1257
c52c15100fb2 prepare version 5.1.3
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1256
diff changeset
    23
testedwith = '3.3.3 3.4-rc'
1012
205d549a972f evolve: point to the core mercurial tracker for bugfix
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1011
diff changeset
    24
buglink = 'http://bz.selenic.com/'
584
af3b0d696e7f evolve: add tested with info
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 577
diff changeset
    25
1104
cb36a4eb0157 evolve: fix the 'grab' alias to work on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 1101
diff changeset
    26
import sys, os
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
    27
import random
854
86b826399dfd exchange: add progress bar when pushing using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 853
diff changeset
    28
from StringIO import StringIO
820
a9a66143e2ec exchange: actually use _pushkeyescape fallback
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 819
diff changeset
    29
import struct
1106
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
    30
import re
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
    31
sha1re = re.compile(r'\b[0-9a-f]{6,40}\b')
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
    32
670
97ce1f801309 evolve: drop unused import
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 663
diff changeset
    33
import mercurial
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    34
from mercurial import util
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    35
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    36
try:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    37
    from mercurial import obsolete
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    38
    if not obsolete._enabled:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    39
        obsolete._enabled = True
952
f83f46411b09 evolve: bump requirement to 3.0.1
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 950
diff changeset
    40
    from mercurial import wireproto
f83f46411b09 evolve: bump requirement to 3.0.1
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 950
diff changeset
    41
    gboptslist = getattr(wireproto, 'gboptslist', None)
955
72670e282460 evolve: compatibility with memfilectx change
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 954
diff changeset
    42
    gboptsmap = getattr(wireproto, 'gboptsmap', None)
591
012e48e80840 evolve: require Mercurial 2.4 to work
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 590
diff changeset
    43
except (ImportError, AttributeError):
955
72670e282460 evolve: compatibility with memfilectx change
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 954
diff changeset
    44
    gboptslist = gboptsmap = None
585
f013ca072bd9 evolve: detect and abort if 2.4 is detected
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 584
diff changeset
    45
1226
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
    46
# Flags for enabling optional parts of evolve
1227
3d9c5f5df6d8 evolve: change config option name
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1226
diff changeset
    47
commandopt = 'allnewcommands'
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    48
820
a9a66143e2ec exchange: actually use _pushkeyescape fallback
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 819
diff changeset
    49
from mercurial import base85
490
8096833e9226 sort import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 485
diff changeset
    50
from mercurial import bookmarks
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    51
from mercurial import cmdutil
490
8096833e9226 sort import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 485
diff changeset
    52
from mercurial import commands
8096833e9226 sort import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 485
diff changeset
    53
from mercurial import context
8096833e9226 sort import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 485
diff changeset
    54
from mercurial import copies
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    55
from mercurial import error
817
c2bf0eb727f1 exchange: only push the set of marker relevant to want we push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 816
diff changeset
    56
from mercurial import exchange
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    57
from mercurial import extensions
880
7fe06f32d1ad exchange: fix push markers over wire protocol for http peer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 879
diff changeset
    58
from mercurial import httppeer
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    59
from mercurial import hg
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
    60
from mercurial import lock as lockmod
490
8096833e9226 sort import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 485
diff changeset
    61
from mercurial import merge
8096833e9226 sort import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 485
diff changeset
    62
from mercurial import node
113
3bdabdbb4140 adapt evolution to phase in core.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 108
diff changeset
    63
from mercurial import phases
930
cac35bef8aee import: --obsolete flag for automatic obsolescence marker creation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 927
diff changeset
    64
from mercurial import patch
1007
1d8ba8244001 push: put phase in the same bundle2 than changegroup and obsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1006
diff changeset
    65
from mercurial import pushkey
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    66
from mercurial import revset
490
8096833e9226 sort import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 485
diff changeset
    67
from mercurial import scmutil
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    68
from mercurial import templatekw
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    69
from mercurial.i18n import _
986
c1f8ece4182d evolve: add --tool option so we don't have to use HGMERGE
Greg Ward <greg@gerg.ca>
parents: 985
diff changeset
    70
from mercurial.commands import walkopts, commitopts, commitopts2, mergetoolopts
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    71
from mercurial.node import nullid
820
a9a66143e2ec exchange: actually use _pushkeyescape fallback
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 819
diff changeset
    72
from mercurial import wireproto
823
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
    73
from mercurial import localrepo
869
e9eeef0d07ec exchange: enforce permission on new wireprotocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 868
diff changeset
    74
from mercurial.hgweb import hgweb_mod
957
2cde59f3cb5d evolve: add a push pass using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 956
diff changeset
    75
from mercurial import bundle2
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    76
1067
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1063
diff changeset
    77
cmdtable = {}
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1063
diff changeset
    78
command = cmdutil.command(cmdtable)
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1063
diff changeset
    79
820
a9a66143e2ec exchange: actually use _pushkeyescape fallback
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 819
diff changeset
    80
_pack = struct.pack
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    81
955
72670e282460 evolve: compatibility with memfilectx change
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 954
diff changeset
    82
if gboptsmap is not None:
72670e282460 evolve: compatibility with memfilectx change
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 954
diff changeset
    83
    memfilectx = context.memfilectx
72670e282460 evolve: compatibility with memfilectx change
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 954
diff changeset
    84
elif gboptslist is not None:
72670e282460 evolve: compatibility with memfilectx change
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 954
diff changeset
    85
    oldmemfilectx = context.memfilectx
72670e282460 evolve: compatibility with memfilectx change
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 954
diff changeset
    86
    def memfilectx(repo, *args, **kwargs):
72670e282460 evolve: compatibility with memfilectx change
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 954
diff changeset
    87
        return oldmemfilectx(*args, **kwargs)
72670e282460 evolve: compatibility with memfilectx change
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 954
diff changeset
    88
else:
1191
583f7f03434b init: don't abort Mercurial on version mismatch
Matt Mackall <mpm@selenic.com>
parents: 1189
diff changeset
    89
    raise ImportError('evolve needs version %s or above' % min(testedwith.split()))
955
72670e282460 evolve: compatibility with memfilectx change
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 954
diff changeset
    90
1296
23819e1d61fd evolve: add -i flag to amend command
Laurent Charignon <lcharignon@fb.com>
parents: 1281
diff changeset
    91
aliases, entry = cmdutil.findcmd('commit', commands.table)
23819e1d61fd evolve: add -i flag to amend command
Laurent Charignon <lcharignon@fb.com>
parents: 1281
diff changeset
    92
hasinteractivemode = util.any(['interactive' in e for e in entry[1]])
23819e1d61fd evolve: add -i flag to amend command
Laurent Charignon <lcharignon@fb.com>
parents: 1281
diff changeset
    93
if hasinteractivemode:
23819e1d61fd evolve: add -i flag to amend command
Laurent Charignon <lcharignon@fb.com>
parents: 1281
diff changeset
    94
    interactiveopt = [['i', 'interactive', None, _('use interactive mode')]]
23819e1d61fd evolve: add -i flag to amend command
Laurent Charignon <lcharignon@fb.com>
parents: 1281
diff changeset
    95
else:
23819e1d61fd evolve: add -i flag to amend command
Laurent Charignon <lcharignon@fb.com>
parents: 1281
diff changeset
    96
    interactiveopt = []
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    97
# This extension contains the following code
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    98
#
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    99
# - Extension Helper code
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   100
# - Obsolescence cache
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   101
# - ...
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   102
# - Older format compat
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   103
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   104
1014
93507c20739e evolve: add a custom layer around retractboundary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1013
diff changeset
   105
#####################################################################
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   106
### Extension helper                                              ###
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   107
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   108
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   109
class exthelper(object):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   110
    """Helper for modular extension setup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   111
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   112
    A single helper should be instanciated for each extension. Helper
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   113
    methods are then used as decorator for various purpose.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   114
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   115
    All decorators return the original function and may be chained.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   116
    """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   117
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   118
    def __init__(self):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   119
        self._uicallables = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   120
        self._extcallables = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   121
        self._repocallables = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   122
        self._revsetsymbols = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   123
        self._templatekws = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   124
        self._commandwrappers = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   125
        self._extcommandwrappers = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   126
        self._functionwrappers = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   127
        self._duckpunchers = []
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   128
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   129
    def final_uisetup(self, ui):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   130
        """Method to be used as the extension uisetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   131
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   132
        The following operations belong here:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   133
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   134
        - Changes to ui.__class__ . The ui object that will be used to run the
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   135
          command has not yet been created. Changes made here will affect ui
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   136
          objects created after this, and in particular the ui that will be
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   137
          passed to runcommand
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   138
        - Command wraps (extensions.wrapcommand)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   139
        - Changes that need to be visible to other extensions: because
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   140
          initialization occurs in phases (all extensions run uisetup, then all
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   141
          run extsetup), a change made here will be visible to other extensions
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   142
          during extsetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   143
        - Monkeypatch or wrap function (extensions.wrapfunction) of dispatch
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   144
          module members
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   145
        - Setup of pre-* and post-* hooks
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   146
        - pushkey setup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   147
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   148
        for cont, funcname, func in self._duckpunchers:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   149
            setattr(cont, funcname, func)
1218
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   150
        for command, wrapper, opts in self._commandwrappers:
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   151
            entry = extensions.wrapcommand(commands.table, command, wrapper)
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   152
            if opts:
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   153
                for short, long, val, msg in opts:
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   154
                    entry[1].append((short, long, val, msg))
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   155
        for cont, funcname, wrapper in self._functionwrappers:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   156
            extensions.wrapfunction(cont, funcname, wrapper)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   157
        for c in self._uicallables:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   158
            c(ui)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   159
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   160
    def final_extsetup(self, ui):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   161
        """Method to be used as a the extension extsetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   162
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   163
        The following operations belong here:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   164
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   165
        - Changes depending on the status of other extensions. (if
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   166
          extensions.find('mq'))
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   167
        - Add a global option to all commands
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   168
        - Register revset functions
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   169
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   170
        knownexts = {}
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   171
        for name, symbol in self._revsetsymbols:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   172
            revset.symbols[name] = symbol
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   173
        for name, kw in self._templatekws:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   174
            templatekw.keywords[name] = kw
1218
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   175
        for ext, command, wrapper, opts in self._extcommandwrappers:
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   176
            if ext not in knownexts:
1219
658b0d032699 wrapcommand: fix wrapping extensions that aren't enabled
Durham Goode <durham@fb.com>
parents: 1218
diff changeset
   177
                try:
658b0d032699 wrapcommand: fix wrapping extensions that aren't enabled
Durham Goode <durham@fb.com>
parents: 1218
diff changeset
   178
                    e = extensions.find(ext)
658b0d032699 wrapcommand: fix wrapping extensions that aren't enabled
Durham Goode <durham@fb.com>
parents: 1218
diff changeset
   179
                except KeyError:
658b0d032699 wrapcommand: fix wrapping extensions that aren't enabled
Durham Goode <durham@fb.com>
parents: 1218
diff changeset
   180
                    # Extension isn't enabled, so don't bother trying to wrap
658b0d032699 wrapcommand: fix wrapping extensions that aren't enabled
Durham Goode <durham@fb.com>
parents: 1218
diff changeset
   181
                    # it.
658b0d032699 wrapcommand: fix wrapping extensions that aren't enabled
Durham Goode <durham@fb.com>
parents: 1218
diff changeset
   182
                    continue
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   183
                knownexts[ext] = e.cmdtable
1218
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   184
            entry = extensions.wrapcommand(knownexts[ext], command, wrapper)
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   185
            if opts:
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   186
                for short, long, val, msg in opts:
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   187
                    entry[1].append((short, long, val, msg))
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   188
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   189
        for c in self._extcallables:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   190
            c(ui)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   191
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   192
    def final_reposetup(self, ui, repo):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   193
        """Method to be used as a the extension reposetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   194
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   195
        The following operations belong here:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   196
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   197
        - All hooks but pre-* and post-*
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   198
        - Modify configuration variables
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   199
        - Changes to repo.__class__, repo.dirstate.__class__
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   200
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   201
        for c in self._repocallables:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   202
            c(ui, repo)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   203
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   204
    def uisetup(self, call):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   205
        """Decorated function will be executed during uisetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   206
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   207
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   208
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   209
            @eh.uisetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   210
            def setupbabar(ui):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   211
                print 'this is uisetup!'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   212
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   213
        self._uicallables.append(call)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   214
        return call
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   215
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   216
    def extsetup(self, call):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   217
        """Decorated function will be executed during extsetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   218
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   219
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   220
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   221
            @eh.extsetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   222
            def setupcelestine(ui):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   223
                print 'this is extsetup!'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   224
        """
672
f7834b360f8f evolve: fix extsetup extension helper
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 671
diff changeset
   225
        self._extcallables.append(call)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   226
        return call
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   227
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   228
    def reposetup(self, call):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   229
        """Decorated function will be executed during reposetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   230
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   231
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   232
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   233
            @eh.reposetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   234
            def setupzephir(ui, repo):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   235
                print 'this is reposetup!'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   236
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   237
        self._repocallables.append(call)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   238
        return call
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   239
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   240
    def revset(self, symbolname):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   241
        """Decorated function is a revset symbol
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   242
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   243
        The name of the symbol must be given as the decorator argument.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   244
        The symbol is added during `extsetup`.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   245
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   246
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   247
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   248
            @eh.revset('hidden')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   249
            def revsetbabar(repo, subset, x):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   250
                args = revset.getargs(x, 0, 0, 'babar accept no argument')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   251
                return [r for r in subset if 'babar' in repo[r].description()]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   252
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   253
        def dec(symbol):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   254
            self._revsetsymbols.append((symbolname, symbol))
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   255
            return symbol
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   256
        return dec
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   257
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   258
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   259
    def templatekw(self, keywordname):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   260
        """Decorated function is a revset keyword
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   261
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   262
        The name of the keyword must be given as the decorator argument.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   263
        The symbol is added during `extsetup`.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   264
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   265
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   266
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   267
            @eh.templatekw('babar')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   268
            def kwbabar(ctx):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   269
                return 'babar'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   270
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   271
        def dec(keyword):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   272
            self._templatekws.append((keywordname, keyword))
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   273
            return keyword
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   274
        return dec
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   275
1218
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   276
    def wrapcommand(self, command, extension=None, opts=[]):
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   277
        """Decorated function is a command wrapper
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   278
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   279
        The name of the command must be given as the decorator argument.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   280
        The wrapping is installed during `uisetup`.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   281
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   282
        If the second option `extension` argument is provided, the wrapping
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   283
        will be applied in the extension commandtable. This argument must be a
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   284
        string that will be searched using `extension.find` if not found and
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   285
        Abort error is raised. If the wrapping applies to an extension, it is
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   286
        installed during `extsetup`
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   287
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   288
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   289
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   290
            @eh.wrapcommand('summary')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   291
            def wrapsummary(orig, ui, repo, *args, **kwargs):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   292
                ui.note('Barry!')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   293
                return orig(ui, repo, *args, **kwargs)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   294
1218
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   295
        The `opts` argument allows specifying additional arguments for the
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   296
        command.
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   297
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   298
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   299
        def dec(wrapper):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   300
            if extension is None:
1218
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   301
                self._commandwrappers.append((command, wrapper, opts))
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   302
            else:
1218
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   303
                self._extcommandwrappers.append((extension, command, wrapper,
dd5e62979100 wrapcommand: allow adding additional arguments to commands
Durham Goode <durham@fb.com>
parents: 1214
diff changeset
   304
                    opts))
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   305
            return wrapper
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   306
        return dec
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   307
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   308
    def wrapfunction(self, container, funcname):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   309
        """Decorated function is a function wrapper
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   310
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   311
        This function takes two arguments, the container and the name of the
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   312
        function to wrap. The wrapping is performed during `uisetup`.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   313
        (there is no extension support)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   314
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   315
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   316
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   317
            @eh.function(discovery, 'checkheads')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   318
            def wrapfunction(orig, *args, **kwargs):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   319
                ui.note('His head smashed in and his heart cut out')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   320
                return orig(*args, **kwargs)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   321
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   322
        def dec(wrapper):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   323
            self._functionwrappers.append((container, funcname, wrapper))
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   324
            return wrapper
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   325
        return dec
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   326
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   327
    def addattr(self, container, funcname):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   328
        """Decorated function is to be added to the container
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   329
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   330
        This function takes two arguments, the container and the name of the
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   331
        function to wrap. The wrapping is performed during `uisetup`.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   332
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   333
        example::
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   334
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   335
            @eh.function(context.changectx, 'babar')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   336
            def babar(ctx):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   337
                return 'babar' in ctx.description
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   338
        """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   339
        def dec(func):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   340
            self._duckpunchers.append((container, funcname, func))
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   341
            return func
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   342
        return dec
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   343
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   344
eh = exthelper()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   345
uisetup = eh.final_uisetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   346
extsetup = eh.final_extsetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   347
reposetup = eh.final_reposetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   348
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   349
#####################################################################
1213
7118996bdf43 config: enable all obsolete options
Durham Goode <durham@fb.com>
parents: 1212
diff changeset
   350
### Option configuration                                          ###
7118996bdf43 config: enable all obsolete options
Durham Goode <durham@fb.com>
parents: 1212
diff changeset
   351
#####################################################################
7118996bdf43 config: enable all obsolete options
Durham Goode <durham@fb.com>
parents: 1212
diff changeset
   352
7118996bdf43 config: enable all obsolete options
Durham Goode <durham@fb.com>
parents: 1212
diff changeset
   353
@eh.reposetup # must be the first of its kin.
7118996bdf43 config: enable all obsolete options
Durham Goode <durham@fb.com>
parents: 1212
diff changeset
   354
def _configureoptions(ui, repo):
7118996bdf43 config: enable all obsolete options
Durham Goode <durham@fb.com>
parents: 1212
diff changeset
   355
    # If no capabilities are specified, enable everything.
7118996bdf43 config: enable all obsolete options
Durham Goode <durham@fb.com>
parents: 1212
diff changeset
   356
    # This is so existing evolve users don't need to change their config.
7118996bdf43 config: enable all obsolete options
Durham Goode <durham@fb.com>
parents: 1212
diff changeset
   357
    evolveopts = ui.configlist('experimental', 'evolution')
7118996bdf43 config: enable all obsolete options
Durham Goode <durham@fb.com>
parents: 1212
diff changeset
   358
    if not evolveopts:
7118996bdf43 config: enable all obsolete options
Durham Goode <durham@fb.com>
parents: 1212
diff changeset
   359
        evolveopts = ['all']
7118996bdf43 config: enable all obsolete options
Durham Goode <durham@fb.com>
parents: 1212
diff changeset
   360
        ui.setconfig('experimental', 'evolution', evolveopts)
7118996bdf43 config: enable all obsolete options
Durham Goode <durham@fb.com>
parents: 1212
diff changeset
   361
1226
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   362
@eh.uisetup
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   363
def _configurecmdoptions(ui):
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   364
    # Unregister evolve commands if the command capability is not specified.
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   365
    #
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   366
    # This must be in the same function as the option configuration above to
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   367
    # guarantee it happens after the above configuration, but before the
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   368
    # extsetup functions.
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   369
    evolveopts = ui.configlist('experimental', 'evolution')
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   370
    if evolveopts and (commandopt not in evolveopts and
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   371
                       'all' not in evolveopts):
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   372
        cmdtable.clear()
1213
7118996bdf43 config: enable all obsolete options
Durham Goode <durham@fb.com>
parents: 1212
diff changeset
   373
7118996bdf43 config: enable all obsolete options
Durham Goode <durham@fb.com>
parents: 1212
diff changeset
   374
#####################################################################
805
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   375
### experimental behavior                                         ###
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   376
#####################################################################
66c02a2e8e2f prune: wrap mercurial internal to add parent information in prune marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 804
diff changeset
   377
976
bed842762447 amend: add -D/--current-date option, just like mq's qrefresh has
Greg Ward <greg@gerg.ca>
parents: 962
diff changeset
   378
commitopts3 = [
bed842762447 amend: add -D/--current-date option, just like mq's qrefresh has
Greg Ward <greg@gerg.ca>
parents: 962
diff changeset
   379
    ('D', 'current-date', None,
bed842762447 amend: add -D/--current-date option, just like mq's qrefresh has
Greg Ward <greg@gerg.ca>
parents: 962
diff changeset
   380
     _('record the current date as commit date')),
985
6a37044ec0b3 amend: add -U/--current-user option (inspired by mq)
Greg Ward <greg@gerg.ca>
parents: 983
diff changeset
   381
    ('U', 'current-user', None,
6a37044ec0b3 amend: add -U/--current-user option (inspired by mq)
Greg Ward <greg@gerg.ca>
parents: 983
diff changeset
   382
     _('record the current user as committer')),
976
bed842762447 amend: add -D/--current-date option, just like mq's qrefresh has
Greg Ward <greg@gerg.ca>
parents: 962
diff changeset
   383
]
bed842762447 amend: add -D/--current-date option, just like mq's qrefresh has
Greg Ward <greg@gerg.ca>
parents: 962
diff changeset
   384
985
6a37044ec0b3 amend: add -U/--current-user option (inspired by mq)
Greg Ward <greg@gerg.ca>
parents: 983
diff changeset
   385
def _resolveoptions(ui, opts):
976
bed842762447 amend: add -D/--current-date option, just like mq's qrefresh has
Greg Ward <greg@gerg.ca>
parents: 962
diff changeset
   386
    """modify commit options dict to handle related options
bed842762447 amend: add -D/--current-date option, just like mq's qrefresh has
Greg Ward <greg@gerg.ca>
parents: 962
diff changeset
   387
bed842762447 amend: add -D/--current-date option, just like mq's qrefresh has
Greg Ward <greg@gerg.ca>
parents: 962
diff changeset
   388
    For now, all it does is figure out the commit date: respect -D unless
bed842762447 amend: add -D/--current-date option, just like mq's qrefresh has
Greg Ward <greg@gerg.ca>
parents: 962
diff changeset
   389
    -d was supplied.
bed842762447 amend: add -D/--current-date option, just like mq's qrefresh has
Greg Ward <greg@gerg.ca>
parents: 962
diff changeset
   390
    """
bed842762447 amend: add -D/--current-date option, just like mq's qrefresh has
Greg Ward <greg@gerg.ca>
parents: 962
diff changeset
   391
    # N.B. this is extremely similar to setupheaderopts() in mq.py
bed842762447 amend: add -D/--current-date option, just like mq's qrefresh has
Greg Ward <greg@gerg.ca>
parents: 962
diff changeset
   392
    if not opts.get('date') and opts.get('current_date'):
bed842762447 amend: add -D/--current-date option, just like mq's qrefresh has
Greg Ward <greg@gerg.ca>
parents: 962
diff changeset
   393
        opts['date'] = '%d %d' % util.makedate()
985
6a37044ec0b3 amend: add -U/--current-user option (inspired by mq)
Greg Ward <greg@gerg.ca>
parents: 983
diff changeset
   394
    if not opts.get('user') and opts.get('current_user'):
6a37044ec0b3 amend: add -U/--current-user option (inspired by mq)
Greg Ward <greg@gerg.ca>
parents: 983
diff changeset
   395
        opts['user'] = ui.username()
976
bed842762447 amend: add -D/--current-date option, just like mq's qrefresh has
Greg Ward <greg@gerg.ca>
parents: 962
diff changeset
   396
590
02cadd3dc9f4 evolve: adapt to 2.4 code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 589
diff changeset
   397
getrevs = obsolete.getrevs
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   398
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   399
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   400
### Additional Utilities                                          ###
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   401
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   402
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   403
# This section contains a lot of small utility function and method
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   404
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   405
# - Function to create markers
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   406
# - useful alias pstatus and pdiff (should probably go in evolve)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   407
# - "troubles" method on changectx
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   408
# - function to travel throught the obsolescence graph
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   409
# - function to find useful changeset to stabilize
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   410
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   411
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   412
### Useful alias
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   413
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   414
@eh.uisetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   415
def _installalias(ui):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   416
    if ui.config('alias', 'pstatus', None) is None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   417
        ui.setconfig('alias', 'pstatus', 'status --rev .^')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   418
    if ui.config('alias', 'pdiff', None) is None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   419
        ui.setconfig('alias', 'pdiff', 'diff --rev .^')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   420
    if ui.config('alias', 'olog', None) is None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   421
        ui.setconfig('alias', 'olog', "log -r 'precursors(.)' --hidden")
497
43e1b2cab789 evolve: add the odiff alias
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 492
diff changeset
   422
    if ui.config('alias', 'odiff', None) is None:
949
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
   423
        ui.setconfig('alias', 'odiff',
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
   424
            "diff --hidden --rev 'limit(precursors(.),1)' --rev .")
696
121e2d265e85 alias: add a grab alias
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 695
diff changeset
   425
    if ui.config('alias', 'grab', None) is None:
1104
cb36a4eb0157 evolve: fix the 'grab' alias to work on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 1101
diff changeset
   426
        if os.name == 'nt':
cb36a4eb0157 evolve: fix the 'grab' alias to work on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 1101
diff changeset
   427
            ui.setconfig('alias', 'grab',
1109
212f24013455 evolve: really fix the 'grab' alias on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 1106
diff changeset
   428
                "! " + util.hgexecutable() + " rebase --dest . --rev $@ && "
1104
cb36a4eb0157 evolve: fix the 'grab' alias to work on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 1101
diff changeset
   429
                 + util.hgexecutable() + " up tip")
cb36a4eb0157 evolve: fix the 'grab' alias to work on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 1101
diff changeset
   430
        else:
cb36a4eb0157 evolve: fix the 'grab' alias to work on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 1101
diff changeset
   431
            ui.setconfig('alias', 'grab',
cb36a4eb0157 evolve: fix the 'grab' alias to work on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 1101
diff changeset
   432
                "! $HG rebase --dest . --rev $@ && $HG up tip")
696
121e2d265e85 alias: add a grab alias
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 695
diff changeset
   433
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   434
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   435
### Troubled revset symbol
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   436
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   437
@eh.revset('troubled')
594
7f89b31fcb26 merge bumped rename
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 592 593
diff changeset
   438
def revsettroubled(repo, subset, x):
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   439
    """``troubled()``
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   440
    Changesets with troubles.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   441
    """
993
8a4a8fe50c26 evolve: do not use _ as an unused variable
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 988
diff changeset
   442
    revset.getargs(x, 0, 0, 'troubled takes no arguments')
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
   443
    return repo.revs('%ld and (unstable() + bumped() + divergent())',
511
ddeb71df916d evolve: localrepo.revs() already returns a list
Patrick Mezard <patrick@mezard.eu>
parents: 510
diff changeset
   444
                     subset)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   445
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   446
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   447
### Obsolescence graph
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   448
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   449
# XXX SOME MAJOR CLEAN UP TO DO HERE XXX
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   450
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   451
def _precursors(repo, s):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   452
    """Precursor of a changeset"""
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   453
    cs = set()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   454
    nm = repo.changelog.nodemap
590
02cadd3dc9f4 evolve: adapt to 2.4 code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 589
diff changeset
   455
    markerbysubj = repo.obsstore.precursors
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   456
    for r in s:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   457
        for p in markerbysubj.get(repo[r].node(), ()):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   458
            pr = nm.get(p[0])
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   459
            if pr is not None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   460
                cs.add(pr)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   461
    return cs
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   462
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   463
def _allprecursors(repo, s):  # XXX we need a better naming
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   464
    """transitive precursors of a subset"""
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   465
    toproceed = [repo[r].node() for r in s]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   466
    seen = set()
590
02cadd3dc9f4 evolve: adapt to 2.4 code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 589
diff changeset
   467
    allsubjects = repo.obsstore.precursors
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   468
    while toproceed:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   469
        nc = toproceed.pop()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   470
        for mark in allsubjects.get(nc, ()):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   471
            np = mark[0]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   472
            if np not in seen:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   473
                seen.add(np)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   474
                toproceed.append(np)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   475
    nm = repo.changelog.nodemap
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   476
    cs = set()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   477
    for p in seen:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   478
        pr = nm.get(p)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   479
        if pr is not None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   480
            cs.add(pr)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   481
    return cs
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   482
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   483
def _successors(repo, s):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   484
    """Successors of a changeset"""
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   485
    cs = set()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   486
    nm = repo.changelog.nodemap
590
02cadd3dc9f4 evolve: adapt to 2.4 code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 589
diff changeset
   487
    markerbyobj = repo.obsstore.successors
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   488
    for r in s:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   489
        for p in markerbyobj.get(repo[r].node(), ()):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   490
            for sub in p[1]:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   491
                sr = nm.get(sub)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   492
                if sr is not None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   493
                    cs.add(sr)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   494
    return cs
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   495
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   496
def _allsuccessors(repo, s, haltonflags=0):  # XXX we need a better naming
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   497
    """transitive successors of a subset
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   498
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   499
    haltonflags allows to provide flags which prevent the evaluation of a
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   500
    marker.  """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   501
    toproceed = [repo[r].node() for r in s]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   502
    seen = set()
590
02cadd3dc9f4 evolve: adapt to 2.4 code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 589
diff changeset
   503
    allobjects = repo.obsstore.successors
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   504
    while toproceed:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   505
        nc = toproceed.pop()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   506
        for mark in allobjects.get(nc, ()):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   507
            if mark[2] & haltonflags:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   508
                continue
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   509
            for sub in mark[1]:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   510
                if sub == nullid:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   511
                    continue # should not be here!
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   512
                if sub not in seen:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   513
                    seen.add(sub)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   514
                    toproceed.append(sub)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   515
    nm = repo.changelog.nodemap
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   516
    cs = set()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   517
    for s in seen:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   518
        sr = nm.get(s)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   519
        if sr is not None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   520
            cs.add(sr)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   521
    return cs
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   522
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   523
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   524
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   525
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   526
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   527
### Extending revset and template                                 ###
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   528
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   529
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   530
# this section add several useful revset symbol not yet in core.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   531
# they are subject to changes
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   532
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   533
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   534
### XXX I'm not sure this revset is useful
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   535
@eh.revset('suspended')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   536
def revsetsuspended(repo, subset, x):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   537
    """``suspended()``
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   538
    Obsolete changesets with non-obsolete descendants.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   539
    """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   540
    args = revset.getargs(x, 0, 0, 'suspended takes no arguments')
590
02cadd3dc9f4 evolve: adapt to 2.4 code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 589
diff changeset
   541
    suspended = getrevs(repo, 'suspended')
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   542
    return [r for r in subset if r in suspended]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   543
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   544
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   545
@eh.revset('precursors')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   546
def revsetprecursors(repo, subset, x):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   547
    """``precursors(set)``
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   548
    Immediate precursors of changesets in set.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   549
    """
1204
161b8f6e7402 evolve: use 3.2+ fullreposet to evaluate argument set (issue4515)
Yuya Nishihara <yuya@tcha.org>
parents: 1203
diff changeset
   550
    s = revset.getset(repo, revset.fullreposet(repo), x)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   551
    cs = _precursors(repo, s)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   552
    return [r for r in subset if r in cs]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   553
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   554
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   555
@eh.revset('allprecursors')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   556
def revsetallprecursors(repo, subset, x):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   557
    """``allprecursors(set)``
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   558
    Transitive precursors of changesets in set.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   559
    """
1204
161b8f6e7402 evolve: use 3.2+ fullreposet to evaluate argument set (issue4515)
Yuya Nishihara <yuya@tcha.org>
parents: 1203
diff changeset
   560
    s = revset.getset(repo, revset.fullreposet(repo), x)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   561
    cs = _allprecursors(repo, s)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   562
    return [r for r in subset if r in cs]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   563
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   564
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   565
@eh.revset('successors')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   566
def revsetsuccessors(repo, subset, x):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   567
    """``successors(set)``
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   568
    Immediate successors of changesets in set.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   569
    """
1204
161b8f6e7402 evolve: use 3.2+ fullreposet to evaluate argument set (issue4515)
Yuya Nishihara <yuya@tcha.org>
parents: 1203
diff changeset
   570
    s = revset.getset(repo, revset.fullreposet(repo), x)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   571
    cs = _successors(repo, s)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   572
    return [r for r in subset if r in cs]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   573
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   574
@eh.revset('allsuccessors')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   575
def revsetallsuccessors(repo, subset, x):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   576
    """``allsuccessors(set)``
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   577
    Transitive successors of changesets in set.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   578
    """
1204
161b8f6e7402 evolve: use 3.2+ fullreposet to evaluate argument set (issue4515)
Yuya Nishihara <yuya@tcha.org>
parents: 1203
diff changeset
   579
    s = revset.getset(repo, revset.fullreposet(repo), x)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   580
    cs = _allsuccessors(repo, s)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   581
    return [r for r in subset if r in cs]
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   582
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   583
### template keywords
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   584
# XXX it does not handle troubles well :-/
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   585
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   586
@eh.templatekw('obsolete')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   587
def obsoletekw(repo, ctx, templ, **args):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   588
    """:obsolete: String. The obsolescence level of the node, could be
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   589
    ``stable``, ``unstable``, ``suspended`` or ``extinct``.
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   590
    """
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   591
    rev = ctx.rev()
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   592
    if ctx.obsolete():
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   593
        if ctx.extinct():
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   594
            return 'extinct'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   595
        else:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   596
            return 'suspended'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   597
    elif ctx.unstable():
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   598
        return 'unstable'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   599
    return 'stable'
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   600
982
1c7b73739a0d template: add a troubles keyword
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 976
diff changeset
   601
@eh.templatekw('troubles')
1c7b73739a0d template: add a troubles keyword
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 976
diff changeset
   602
def showtroubles(repo, ctx, **args):
1c7b73739a0d template: add a troubles keyword
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 976
diff changeset
   603
    """:troubles: List of strings. Evolution troubles affecting the changeset
1c7b73739a0d template: add a troubles keyword
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 976
diff changeset
   604
    (zero or more of "unstable", "divergent" or "bumped")."""
1c7b73739a0d template: add a troubles keyword
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 976
diff changeset
   605
    return templatekw.showlist('trouble', ctx.troubles(), plural='troubles',
1c7b73739a0d template: add a troubles keyword
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 976
diff changeset
   606
                               **args)
1c7b73739a0d template: add a troubles keyword
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 976
diff changeset
   607
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   608
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   609
### Various trouble warning                                       ###
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   610
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   611
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   612
# This section take care of issue warning to the user when troubles appear
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   613
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   614
@eh.wrapcommand("update")
745
99e51aff724b add obsolete parents wrapper to the 'parents' command
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 743
diff changeset
   615
@eh.wrapcommand("parents")
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   616
@eh.wrapcommand("pull")
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   617
def wrapmayobsoletewc(origfn, ui, repo, *args, **opts):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   618
    """Warn that the working directory parent is an obsolete changeset"""
1303
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1302
diff changeset
   619
    def warnobsolete():
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1302
diff changeset
   620
        if repo['.'].obsolete():
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1302
diff changeset
   621
            ui.warn(_('working directory parent is obsolete!\n'))
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1302
diff changeset
   622
    wlock = None
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1302
diff changeset
   623
    try:
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1302
diff changeset
   624
        wlock = repo.wlock()
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1302
diff changeset
   625
        repo._afterlock(warnobsolete)
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1302
diff changeset
   626
        res = origfn(ui, repo, *args, **opts)
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1302
diff changeset
   627
    finally:
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1302
diff changeset
   628
        lockmod.release(wlock)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   629
    return res
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   630
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   631
# XXX this could wrap transaction code
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   632
# XXX (but this is a bit a layer violation)
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   633
@eh.wrapcommand("commit")
763
966e2659e989 import: warn about new unstable changesets
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 762
diff changeset
   634
@eh.wrapcommand("import")
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   635
@eh.wrapcommand("push")
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   636
@eh.wrapcommand("pull")
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   637
@eh.wrapcommand("graft")
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   638
@eh.wrapcommand("phase")
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   639
@eh.wrapcommand("unbundle")
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   640
def warnobserrors(orig, ui, repo, *args, **kwargs):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   641
    """display warning is the command resulted in more instable changeset"""
658
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   642
    # part of the troubled stuff may be filtered (stash ?)
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   643
    # This needs a better implementation but will probably wait for core.
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   644
    filtered = repo.changelog.filteredrevs
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   645
    priorunstables = len(set(getrevs(repo, 'unstable')) - filtered)
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   646
    priorbumpeds = len(set(getrevs(repo, 'bumped')) - filtered)
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   647
    priordivergents = len(set(getrevs(repo, 'divergent')) - filtered)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   648
    ret = orig(ui, repo, *args, **kwargs)
552
f7e54d4a3b90 warning: work around phase limitation when computing warnings
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 551
diff changeset
   649
    # workaround phase stupidity
649
d318fbb1cd67 evolve: stop working around phase limitation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 647
diff changeset
   650
    #phases._filterunknown(ui, repo.changelog, repo._phasecache.phaseroots)
658
2a2b8c95bb43 evolve: remove revset calls in warnobserror
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 657
diff changeset
   651
    filtered = repo.changelog.filteredrevs
949
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
   652
    newunstables = \
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
   653
        len(set(getrevs(repo, 'unstable')) - filtered) - priorunstables
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
   654
    newbumpeds = \
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
   655
        len(set(getrevs(repo, 'bumped')) - filtered) - priorbumpeds
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
   656
    newdivergents = \
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
   657
        len(set(getrevs(repo, 'divergent')) - filtered) - priordivergents
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   658
    if newunstables > 0:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   659
        ui.warn(_('%i new unstable changesets\n') % newunstables)
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
   660
    if newbumpeds > 0:
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
   661
        ui.warn(_('%i new bumped changesets\n') % newbumpeds)
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
   662
    if newdivergents > 0:
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
   663
        ui.warn(_('%i new divergent changesets\n') % newdivergents)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   664
    return ret
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   665
1122
c8750f4388c8 evolve: wrap exchange.push() for compatability with core mercurial 4d52e6eb98ea
Matt Harbison <matt_harbison@yahoo.com>
parents: 1120
diff changeset
   666
@eh.wrapfunction(mercurial.exchange, 'push')
c8750f4388c8 evolve: wrap exchange.push() for compatability with core mercurial 4d52e6eb98ea
Matt Harbison <matt_harbison@yahoo.com>
parents: 1120
diff changeset
   667
def push(orig, repo, *args, **opts):
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
   668
    """Add a hint for "hg evolve" when troubles make push fails
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   669
    """
1122
c8750f4388c8 evolve: wrap exchange.push() for compatability with core mercurial 4d52e6eb98ea
Matt Harbison <matt_harbison@yahoo.com>
parents: 1120
diff changeset
   670
    try:
c8750f4388c8 evolve: wrap exchange.push() for compatability with core mercurial 4d52e6eb98ea
Matt Harbison <matt_harbison@yahoo.com>
parents: 1120
diff changeset
   671
        return orig(repo, *args, **opts)
c8750f4388c8 evolve: wrap exchange.push() for compatability with core mercurial 4d52e6eb98ea
Matt Harbison <matt_harbison@yahoo.com>
parents: 1120
diff changeset
   672
    except util.Abort, ex:
c8750f4388c8 evolve: wrap exchange.push() for compatability with core mercurial 4d52e6eb98ea
Matt Harbison <matt_harbison@yahoo.com>
parents: 1120
diff changeset
   673
        hint = _("use 'hg evolve' to get a stable history "
c8750f4388c8 evolve: wrap exchange.push() for compatability with core mercurial 4d52e6eb98ea
Matt Harbison <matt_harbison@yahoo.com>
parents: 1120
diff changeset
   674
                 "or --force to ignore warnings")
c8750f4388c8 evolve: wrap exchange.push() for compatability with core mercurial 4d52e6eb98ea
Matt Harbison <matt_harbison@yahoo.com>
parents: 1120
diff changeset
   675
        if (len(ex.args) >= 1
c8750f4388c8 evolve: wrap exchange.push() for compatability with core mercurial 4d52e6eb98ea
Matt Harbison <matt_harbison@yahoo.com>
parents: 1120
diff changeset
   676
            and ex.args[0].startswith('push includes ')
c8750f4388c8 evolve: wrap exchange.push() for compatability with core mercurial 4d52e6eb98ea
Matt Harbison <matt_harbison@yahoo.com>
parents: 1120
diff changeset
   677
            and ex.hint is None):
c8750f4388c8 evolve: wrap exchange.push() for compatability with core mercurial 4d52e6eb98ea
Matt Harbison <matt_harbison@yahoo.com>
parents: 1120
diff changeset
   678
            ex.hint = hint
c8750f4388c8 evolve: wrap exchange.push() for compatability with core mercurial 4d52e6eb98ea
Matt Harbison <matt_harbison@yahoo.com>
parents: 1120
diff changeset
   679
        raise
c8750f4388c8 evolve: wrap exchange.push() for compatability with core mercurial 4d52e6eb98ea
Matt Harbison <matt_harbison@yahoo.com>
parents: 1120
diff changeset
   680
    return result
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   681
788
e973dd5bf583 evolve: register a summary hook instead of wrapping the summary command
Simon Heimberg <simohe@besonet.ch>
parents: 776
diff changeset
   682
def summaryhook(ui, repo):
513
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   683
    def write(fmt, count):
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   684
        s = fmt % count
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   685
        if count:
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   686
            ui.write(s)
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   687
        else:
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   688
            ui.note(s)
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   689
590
02cadd3dc9f4 evolve: adapt to 2.4 code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 589
diff changeset
   690
    nbunstable = len(getrevs(repo, 'unstable'))
594
7f89b31fcb26 merge bumped rename
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 592 593
diff changeset
   691
    nbbumped = len(getrevs(repo, 'bumped'))
626
896463193675 merge with fix in 2.3
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 621 623
diff changeset
   692
    nbdivergent = len(getrevs(repo, 'divergent'))
513
4602104b190d evolve: factor out copy/paste in obssummary()
Patrick Mezard <patrick@mezard.eu>
parents: 512
diff changeset
   693
    write('unstable: %i changesets\n', nbunstable)
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
   694
    write('bumped: %i changesets\n', nbbumped)
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
   695
    write('divergent: %i changesets\n', nbdivergent)
788
e973dd5bf583 evolve: register a summary hook instead of wrapping the summary command
Simon Heimberg <simohe@besonet.ch>
parents: 776
diff changeset
   696
e973dd5bf583 evolve: register a summary hook instead of wrapping the summary command
Simon Heimberg <simohe@besonet.ch>
parents: 776
diff changeset
   697
@eh.extsetup
e973dd5bf583 evolve: register a summary hook instead of wrapping the summary command
Simon Heimberg <simohe@besonet.ch>
parents: 776
diff changeset
   698
def obssummarysetup(ui):
e973dd5bf583 evolve: register a summary hook instead of wrapping the summary command
Simon Heimberg <simohe@besonet.ch>
parents: 776
diff changeset
   699
    cmdutil.summaryhooks.add('evolve', summaryhook)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   700
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   701
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   702
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   703
### Core Other extension compat                                   ###
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   704
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   705
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   706
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   707
@eh.extsetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   708
def _rebasewrapping(ui):
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   709
    # warning about more obsolete
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   710
    try:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   711
        rebase = extensions.find('rebase')
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   712
        if rebase:
572
dc107acd0bd2 adapt to core rebase support
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 571
diff changeset
   713
            extensions.wrapcommand(rebase.cmdtable, 'rebase', warnobserrors)
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   714
    except KeyError:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   715
        pass  # rebase not found
678
718262019c6f evolve: warn for troubles created by histedit too.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 677
diff changeset
   716
    try:
718262019c6f evolve: warn for troubles created by histedit too.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 677
diff changeset
   717
        histedit = extensions.find('histedit')
718262019c6f evolve: warn for troubles created by histedit too.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 677
diff changeset
   718
        if histedit:
718262019c6f evolve: warn for troubles created by histedit too.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 677
diff changeset
   719
            extensions.wrapcommand(histedit.cmdtable, 'histedit', warnobserrors)
718262019c6f evolve: warn for troubles created by histedit too.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 677
diff changeset
   720
    except KeyError:
718262019c6f evolve: warn for troubles created by histedit too.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 677
diff changeset
   721
        pass  # rebase not found
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   722
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   723
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   724
### Old Evolve extension content                                  ###
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   725
#####################################################################
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   726
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
   727
# XXX need clean up and proper sorting in other section
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   728
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   729
### util function
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   730
#############################
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
   731
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   732
### changeset rewriting logic
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   733
#############################
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   734
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   735
def rewrite(repo, old, updates, head, newbases, commitopts):
265
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   736
    """Return (nodeid, created) where nodeid is the identifier of the
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   737
    changeset generated by the rewrite process, and created is True if
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   738
    nodeid was actually created. If created is False, nodeid
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   739
    references a changeset existing before the rewrite call.
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   740
    """
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   741
    if len(old.parents()) > 1: #XXX remove this unecessary limitation.
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   742
        raise error.Abort(_('cannot amend merge changesets'))
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   743
    base = old.p1()
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   744
    updatebookmarks = _bookmarksupdater(repo, old.node())
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   745
1017
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   746
    # commit a new version of the old changeset, including the update
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   747
    # collect all files which might be affected
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   748
    files = set(old.files())
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   749
    for u in updates:
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   750
        files.update(u.files())
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   751
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   752
    # Recompute copies (avoid recording a -> b -> a)
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   753
    copied = copies.pathcopies(base, head)
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   754
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   755
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   756
    # prune files which were reverted by the updates
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   757
    def samefile(f):
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   758
        if f in head.manifest():
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   759
            a = head.filectx(f)
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   760
            if f in base.manifest():
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   761
                b = base.filectx(f)
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   762
                return (a.data() == b.data()
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   763
                        and a.flags() == b.flags())
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   764
            else:
1017
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   765
                return False
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   766
        else:
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   767
            return f not in base.manifest()
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   768
    files = [f for f in files if not samefile(f)]
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   769
    # commit version of these files as defined by head
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   770
    headmf = head.manifest()
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   771
    def filectxfn(repo, ctx, path):
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   772
        if path in headmf:
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   773
            fctx = head[path]
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   774
            flags = fctx.flags()
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   775
            mctx = memfilectx(repo, fctx.path(), fctx.data(),
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   776
                              islink='l' in flags,
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   777
                              isexec='x' in flags,
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   778
                              copied=copied.get(path))
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   779
            return mctx
1086
96b9e0c31cc1 compat: adapt to change to memctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1085
diff changeset
   780
        return None
1017
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   781
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   782
    message = cmdutil.logmessage(repo.ui, commitopts)
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   783
    if not message:
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   784
        message = old.description()
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   785
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   786
    user = commitopts.get('user') or old.user()
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   787
    date = commitopts.get('date') or None # old.date()
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   788
    extra = dict(commitopts.get('extra', {}))
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   789
    extra['branch'] = head.branch()
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   790
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   791
    new = context.memctx(repo,
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   792
                         parents=newbases,
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   793
                         text=message,
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   794
                         files=files,
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   795
                         filectxfn=filectxfn,
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   796
                         user=user,
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   797
                         date=date,
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   798
                         extra=extra)
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   799
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   800
    if commitopts.get('edit'):
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   801
        new._text = cmdutil.commitforceeditor(repo, new, [])
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   802
    revcount = len(repo)
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   803
    newid = repo.commitctx(new)
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   804
    new = repo[newid]
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   805
    created = len(repo) != revcount
186b72e41294 evolve: drop useless wlock in rewrite
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1016
diff changeset
   806
    updatebookmarks(newid)
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   807
265
24943df310d4 amend: do not traceback on no-ops
Patrick Mezard <patrick@mezard.eu>
parents: 264
diff changeset
   808
    return newid, created
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
   809
463
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   810
class MergeFailure(util.Abort):
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   811
    pass
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   812
1141
ca17770d2ee9 evolve: preserve branch change
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1140
diff changeset
   813
def relocate(repo, orig, dest, keepbranch=False):
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   814
    """rewrite <rev> on dest"""
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
   815
    if orig.rev() == dest.rev():
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
   816
        raise util.Abort(_('tried to relocate a node on top of itself'),
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
   817
                         hint=_("This shouldn't happen. If you still "
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
   818
                                "need to move changesets, please do so "
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
   819
                                "manually with nothing to rebase - working "
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
   820
                                "directory parent is also destination"))
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
   821
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
   822
    if not orig.p2().rev() == node.nullrev:
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
   823
        raise util.Abort(
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
   824
            'no support for evolving merge changesets yet',
1116
d4977b04ef98 evolve: update evolve merge message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1112
diff changeset
   825
            hint="Redo the merge and use `hg prune <old> --succ <new>` to obsolete the old one")
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
   826
    destbookmarks = repo.nodebookmarks(dest.node())
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
   827
    nodesrc = orig.node()
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
   828
    destphase = repo[nodesrc].phase()
1106
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   829
    commitmsg = orig.description()
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   830
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   831
    cache = {}
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   832
    sha1s = re.findall(sha1re, commitmsg)
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   833
    unfi = repo.unfiltered()
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   834
    for sha1 in sha1s:
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   835
        ctx = None
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   836
        try:
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   837
            ctx = unfi[sha1]
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   838
        except error.RepoLookupError:
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   839
            continue
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   840
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   841
        if not ctx.obsolete():
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   842
            continue
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   843
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   844
        successors = obsolete.successorssets(repo, ctx.node(), cache)
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   845
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   846
        # We can't make any assumptions about how to update the hash if the
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   847
        # cset in question was split or diverged.
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   848
        if len(successors) == 1 and len(successors[0]) == 1:
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   849
            newsha1 = node.hex(successors[0][0])
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   850
            commitmsg = commitmsg.replace(sha1, newsha1[:len(sha1)])
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   851
        else:
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   852
            repo.ui.note(_('The stale commit message reference to %s could '
1145
fb51113a1c08 evolve: add the missing newline to output messages where needed
Matt Harbison <matt_harbison@yahoo.com>
parents: 1144
diff changeset
   853
                           'not be updated\n') % sha1)
1106
6b0cf1b73693 evolve: replace each obsolete sha1 in the description with its latest successor
Matt Harbison <matt_harbison@yahoo.com>
parents: 1104
diff changeset
   854
1023
7c8e3941241f relocate: add transaction around phase movement
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1022
diff changeset
   855
    tr = repo.transaction('relocate')
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   856
    try:
326
52c53e2d413b stabilize: clear error message than conflict during rebase offer no hope
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 319
diff changeset
   857
        try:
1183
58370c718183 evolve: use `merge.graft` instead of `rebasenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1177
diff changeset
   858
            if repo['.'].rev() != dest.rev():
58370c718183 evolve: use `merge.graft` instead of `rebasenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1177
diff changeset
   859
                merge.update(repo, dest, False, True, False)
1194
aa7cdd9d7310 evolve: explicitly disable bookmark on evolve (issue4432)
Tyrone Nicholas <tnicholas@fb.com>
parents: 1191
diff changeset
   860
            if repo._bookmarkcurrent:
aa7cdd9d7310 evolve: explicitly disable bookmark on evolve (issue4432)
Tyrone Nicholas <tnicholas@fb.com>
parents: 1191
diff changeset
   861
                repo.ui.status(_("(leaving bookmark %s)\n") %
aa7cdd9d7310 evolve: explicitly disable bookmark on evolve (issue4432)
Tyrone Nicholas <tnicholas@fb.com>
parents: 1191
diff changeset
   862
                               repo._bookmarkcurrent)
aa7cdd9d7310 evolve: explicitly disable bookmark on evolve (issue4432)
Tyrone Nicholas <tnicholas@fb.com>
parents: 1191
diff changeset
   863
            bookmarks.unsetcurrent(repo)
1184
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   864
            if keepbranch:
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   865
                repo.dirstate.setbranch(orig.branch())
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   866
            r = merge.graft(repo, orig, orig.p1(), ['local', 'graft'])
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   867
            if r[-1]:  #some conflict
550
362e65fc6146 evolve-cmd: fix merge error detection for external tools.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 549
diff changeset
   868
                raise util.Abort(
362e65fc6146 evolve-cmd: fix merge error detection for external tools.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 549
diff changeset
   869
                        'unresolved merge conflicts (see hg help resolve)')
1184
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   870
            if commitmsg is None:
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   871
                commitmsg = orig.description()
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   872
            extra = {'rebase_source': orig.hex()}
1141
ca17770d2ee9 evolve: preserve branch change
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1140
diff changeset
   873
1184
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   874
            backup = repo.ui.backupconfig('phases', 'new-commit')
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   875
            try:
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   876
                targetphase = max(orig.phase(), phases.draft)
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   877
                repo.ui.setconfig('phases', 'new-commit', targetphase, 'rebase')
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   878
                # Commit might fail if unresolved files exist
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   879
                nodenew = repo.commit(text=commitmsg, user=orig.user(),
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   880
                                      date=orig.date(), extra=extra)
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   881
            finally:
bc601c010185 evolve: remove the use of `rebase.concludenode`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1183
diff changeset
   882
                repo.ui.restoreconfig(backup)
463
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   883
        except util.Abort, exc:
1131
a44a26f8cc48 evolve: adapt to change in core rebase
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1129
diff changeset
   884
            repo.dirstate.beginparentchange()
a44a26f8cc48 evolve: adapt to change in core rebase
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1129
diff changeset
   885
            repo.setparents(repo['.'].node(), nullid)
a44a26f8cc48 evolve: adapt to change in core rebase
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1129
diff changeset
   886
            repo.dirstate.write()
a44a26f8cc48 evolve: adapt to change in core rebase
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1129
diff changeset
   887
            # fix up dirstate for copies and renames
a44a26f8cc48 evolve: adapt to change in core rebase
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1129
diff changeset
   888
            copies.duplicatecopies(repo, dest.rev(), orig.p1().rev())
a44a26f8cc48 evolve: adapt to change in core rebase
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1129
diff changeset
   889
            repo.dirstate.endparentchange()
463
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   890
            class LocalMergeFailure(MergeFailure, exc.__class__):
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   891
                pass
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
   892
            exc.__class__ = LocalMergeFailure
326
52c53e2d413b stabilize: clear error message than conflict during rebase offer no hope
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 319
diff changeset
   893
            raise
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   894
        oldbookmarks = repo.nodebookmarks(nodesrc)
284
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   895
        if nodenew is not None:
1069
356552e55489 evolve: always use the transaction version of phase movement
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1068
diff changeset
   896
            phases.retractboundary(repo, tr, destphase, [nodenew])
1070
527b12a59628 drop relevant marker compat
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1069
diff changeset
   897
            obsolete.createmarkers(repo, [(repo[nodesrc], (repo[nodenew],))])
284
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   898
            for book in oldbookmarks:
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   899
                repo._bookmarks[book] = nodenew
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   900
        else:
1070
527b12a59628 drop relevant marker compat
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1069
diff changeset
   901
            obsolete.createmarkers(repo, [(repo[nodesrc], ())])
284
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   902
            # Behave like rebase, move bookmarks to dest
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   903
            for book in oldbookmarks:
88a851a54f26 evolve: fix relocate() with removed revision
Patrick Mezard <patrick@mezard.eu>
parents: 272
diff changeset
   904
                repo._bookmarks[book] = dest.node()
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   905
        for book in destbookmarks: # restore bookmark that rebase move
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   906
            repo._bookmarks[book] = dest.node()
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
   907
        if oldbookmarks or destbookmarks:
612
15299bfd0813 adapt to 7f5dab94e48c in crew
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 604
diff changeset
   908
            repo._bookmarks.write()
1023
7c8e3941241f relocate: add transaction around phase movement
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1022
diff changeset
   909
        tr.close()
7c8e3941241f relocate: add transaction around phase movement
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1022
diff changeset
   910
    finally:
7c8e3941241f relocate: add transaction around phase movement
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1022
diff changeset
   911
        tr.release()
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
   912
    return nodenew
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
   913
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   914
def _bookmarksupdater(repo, oldid):
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   915
    """Return a callable update(newid) updating the current bookmark
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   916
    and bookmarks bound to oldid to newid.
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   917
    """
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   918
    bm = bookmarks.readcurrent(repo)
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   919
    def updatebookmarks(newid):
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   920
        dirty = False
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   921
        if bm:
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   922
            repo._bookmarks[bm] = newid
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   923
            dirty = True
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   924
        oldbookmarks = repo.nodebookmarks(oldid)
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   925
        if oldbookmarks:
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   926
            for b in oldbookmarks:
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   927
                repo._bookmarks[b] = newid
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   928
            dirty = True
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   929
        if dirty:
612
15299bfd0813 adapt to 7f5dab94e48c in crew
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 604
diff changeset
   930
            repo._bookmarks.write()
313
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   931
    return updatebookmarks
47d10459fa24 uncommit: handle bookmarks
Patrick Mezard <patrick@mezard.eu>
parents: 312
diff changeset
   932
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   933
### new command
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   934
#############################
716
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
   935
metadataopts = [
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
   936
    ('d', 'date', '',
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
   937
     _('record the specified date in metadata'), _('DATE')),
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
   938
    ('u', 'user', '',
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
   939
     _('record the specified user in metadata'), _('USER')),
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
   940
]
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
   941
953
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   942
@eh.uisetup
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   943
def _installimportobsolete(ui):
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   944
    entry = cmdutil.findcmd('import', commands.table)[1]
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   945
    entry[1].append(('', 'obsolete', False,
1162
5c07f464981e help: fix typo in help for 'obsolete' option added to import command
Mike Edgar <adgar@google.com>
parents: 1160
diff changeset
   946
                    _('mark the old node as obsoleted by '
953
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   947
                      'the created commit')))
930
cac35bef8aee import: --obsolete flag for automatic obsolescence marker creation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 927
diff changeset
   948
953
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   949
@eh.wrapfunction(mercurial.cmdutil, 'tryimportone')
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   950
def tryimportone(orig, ui, repo, hunk, parents, opts, *args, **kwargs):
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   951
    extracted = patch.extract(ui, hunk)
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   952
    expected = extracted[5]
1115
cc19b6400dae import: fix the "is None" check for the Node
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1109
diff changeset
   953
    if expected is not None:
1055
cfe1b9d3e5d9 import: handle patch with no node information
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1054
diff changeset
   954
        expected = node.bin(expected)
953
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   955
    oldextract = patch.extract
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   956
    try:
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   957
        patch.extract = lambda ui, hunk: extracted
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   958
        ret = orig(ui, repo, hunk, parents, opts, *args, **kwargs)
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   959
    finally:
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   960
        patch.extract = oldextract
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   961
    created = ret[1]
1055
cfe1b9d3e5d9 import: handle patch with no node information
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1054
diff changeset
   962
    if (opts['obsolete'] and None not in (created, expected)
cfe1b9d3e5d9 import: handle patch with no node information
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1054
diff changeset
   963
        and created != expected):
953
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   964
            tr = repo.transaction('import-obs')
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   965
            try:
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   966
                metadata = {'user': ui.username()}
1054
93e920feff5e import: compare binary node with binary node when using --obsolete
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1052
diff changeset
   967
                repo.obsstore.create(tr, expected, (created,),
953
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   968
                                     metadata=metadata)
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   969
                tr.close()
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   970
            finally:
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   971
                tr.release()
a02e5916a7e3 import: drop version check for ``import --obsolete``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 952
diff changeset
   972
    return ret
930
cac35bef8aee import: --obsolete flag for automatic obsolescence marker creation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 927
diff changeset
   973
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
   974
894
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   975
def _deprecatealias(oldalias, newalias):
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   976
    '''Deprecates an alias for a command in favour of another
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   977
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   978
    Creates a new entry in the command table for the old alias. It creates a
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   979
    wrapper that has its synopsis set to show that is has been deprecated.
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   980
    The documentation will be replace with a pointer to the new alias.
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   981
    If a user invokes the command a deprecation warning will be printed and
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   982
    the command of the *new* alias will be invoked.
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   983
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   984
    This function is loosely based on the extensions.wrapcommand function.
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   985
    '''
1226
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   986
    try:
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   987
        aliases, entry = cmdutil.findcmd(newalias, cmdtable)
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   988
    except error.UnknownCommand:
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   989
        # Commands may be disabled
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
   990
        return
894
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   991
    for alias, e in cmdtable.iteritems():
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   992
        if e is entry:
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   993
            break
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   994
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   995
    synopsis = '(DEPRECATED)'
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   996
    if len(entry) > 2:
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   997
        fn, opts, _syn = entry
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   998
    else:
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
   999
        fn, opts, = entry
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
  1000
    deprecationwarning = _('%s have been deprecated in favor of %s\n' % (
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
  1001
        oldalias, newalias))
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
  1002
    def newfn(*args, **kwargs):
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
  1003
        ui = args[0]
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
  1004
        ui.warn(deprecationwarning)
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
  1005
        util.checksignature(fn)(*args, **kwargs)
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
  1006
    newfn.__doc__  = deprecationwarning
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
  1007
    cmdwrapper = command(oldalias, opts, synopsis)
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
  1008
    cmdwrapper(newfn)
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
  1009
895
17ac69db9329 evolve: deprecate gup and gdown aliases
Olle Lundberg <geek@nerd.sh>
parents: 894
diff changeset
  1010
@eh.extsetup
17ac69db9329 evolve: deprecate gup and gdown aliases
Olle Lundberg <geek@nerd.sh>
parents: 894
diff changeset
  1011
def deprecatealiases(ui):
17ac69db9329 evolve: deprecate gup and gdown aliases
Olle Lundberg <geek@nerd.sh>
parents: 894
diff changeset
  1012
    _deprecatealias('gup', 'next')
17ac69db9329 evolve: deprecate gup and gdown aliases
Olle Lundberg <geek@nerd.sh>
parents: 894
diff changeset
  1013
    _deprecatealias('gdown', 'previous')
894
4f21a3279a60 evolve: add function to deprecate an alias
Olle Lundberg <geek@nerd.sh>
parents: 890
diff changeset
  1014
811
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1015
@command('debugrecordpruneparents', [], '')
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1016
def cmddebugrecordpruneparents(ui, repo):
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1017
    """add parents data to prune markers when possible
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1018
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1019
    This commands search the repo for prune markers without parent information.
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1020
    If the pruned node is locally known, a new markers with parent data is
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1021
    created."""
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1022
    pgop = 'reading markers'
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1023
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1024
    # lock from the beginning to prevent race
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1025
    wlock = lock = tr = None
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1026
    try:
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1027
        wlock = repo.wlock()
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1028
        lock = repo.lock()
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1029
        tr = repo.transaction('recordpruneparents')
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1030
        unfi = repo.unfiltered()
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1031
        nm = unfi.changelog.nodemap
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1032
        store = repo.obsstore
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1033
        pgtotal = len(store._all)
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1034
        for idx, mark in enumerate(list(store._all)):
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1035
            if not mark[1]:
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1036
                rev = nm.get(mark[0])
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1037
                if rev is not None:
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1038
                    ctx = unfi[rev]
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1039
                    meta = obsolete.decodemeta(mark[3])
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1040
                    for i, p in enumerate(ctx.parents(), 1):
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1041
                        meta['p%i' % i] = p.hex()
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1042
                    before = len(store._all)
1061
f3867e60d072 compat: always call metadata as a keyword argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1043
                    store.create(tr, mark[0], mark[1], mark[2], metadata=meta)
811
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1044
                    if len(store._all) - before:
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1045
                        ui.write('created new markers for %i\n' % rev)
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1046
            ui.progress(pgop, idx, total=pgtotal)
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1047
        tr.close()
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1048
        ui.progress(pgop, None)
acfa2b67cff6 evolve: add a cmddebugrecordpruneparents command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 809
diff changeset
  1049
    finally:
1018
30262465b932 debugrecordpruneparents: release tr the same way than the lock
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1017
diff changeset
  1050
        lockmod.release(tr, lock, wlock)
809
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1051
807
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1052
@command('debugobsstorestat', [], '')
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1053
def cmddebugobsstorestat(ui, repo):
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1054
    """print statistic about obsolescence markers in the repo"""
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1055
    store = repo.obsstore
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1056
    unfi = repo.unfiltered()
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1057
    nm = unfi.changelog.nodemap
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1058
    ui.write('markers total:              %9i\n' % len(store._all))
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1059
    sucscount = [0, 0 , 0, 0]
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1060
    known = 0
809
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1061
    parentsdata = 0
807
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1062
    metakeys = {}
809
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1063
    # node -> cluster mapping
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1064
    #   a cluster is a (set(nodes), set(markers)) tuple
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1065
    clustersmap = {}
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1066
    # same data using parent information
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1067
    pclustersmap= {}
807
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1068
    for mark in store:
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1069
        if mark[0] in nm:
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1070
            known += 1
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1071
        nbsucs = len(mark[1])
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1072
        sucscount[min(nbsucs, 3)] += 1
1129
da565c825429 evolve: adapt to the new metadata storage
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1128
diff changeset
  1073
        meta = mark[3]
da565c825429 evolve: adapt to the new metadata storage
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1128
diff changeset
  1074
        for key, value in meta:
807
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1075
            metakeys.setdefault(key, 0)
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1076
            metakeys[key] += 1
1129
da565c825429 evolve: adapt to the new metadata storage
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1128
diff changeset
  1077
        meta = dict(meta)
809
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1078
        parents = [meta.get('p1'), meta.get('p2')]
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1079
        parents = [node.bin(p) for p in parents if p is not None]
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1080
        if parents:
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1081
            parentsdata += 1
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1082
        # cluster handling
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1083
        nodes = set()
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1084
        nodes.add(mark[0])
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1085
        nodes.update(mark[1])
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1086
        c = (set(nodes), set([mark]))
807
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1087
809
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1088
        toproceed = set(nodes)
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1089
        while toproceed:
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1090
            n = toproceed.pop()
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1091
            other = clustersmap.get(n)
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1092
            if (other is not None
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1093
                and other is not c):
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1094
                other[0].update(c[0])
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1095
                other[1].update(c[1])
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1096
                for on in c[0]:
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1097
                    if on in toproceed:
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1098
                        continue
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1099
                    clustersmap[on] = other
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1100
                c = other
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1101
            clustersmap[n] = c
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1102
        # same with parent data
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1103
        nodes.update(parents)
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1104
        c = (set(nodes), set([mark]))
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1105
        toproceed = set(nodes)
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1106
        while toproceed:
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1107
            n = toproceed.pop()
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1108
            other = pclustersmap.get(n)
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1109
            if (other is not None
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1110
                and other is not c):
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1111
                other[0].update(c[0])
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1112
                other[1].update(c[1])
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1113
                for on in c[0]:
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1114
                    if on in toproceed:
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1115
                        continue
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1116
                    pclustersmap[on] = other
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1117
                c = other
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1118
            pclustersmap[n] = c
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1119
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1120
    # freezing the result
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1121
    for c in clustersmap.values():
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1122
        fc = (frozenset(c[0]), frozenset(c[1]))
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1123
        for n in fc[0]:
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1124
            clustersmap[n] = fc
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1125
    # same with parent data
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1126
    for c in pclustersmap.values():
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1127
        fc = (frozenset(c[0]), frozenset(c[1]))
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1128
        for n in fc[0]:
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1129
            pclustersmap[n] = fc
807
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1130
    ui.write('    for known precursors:   %9i\n' % known)
809
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1131
    ui.write('    with parents data:      %9i\n' % parentsdata)
807
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1132
    # successors data
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1133
    ui.write('markers with no successors: %9i\n' % sucscount[0])
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1134
    ui.write('              1 successors: %9i\n' % sucscount[1])
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1135
    ui.write('              2 successors: %9i\n' % sucscount[2])
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1136
    ui.write('    more than 2 successors: %9i\n' % sucscount[3])
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1137
    # meta data info
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1138
    ui.write('    available  keys:\n')
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1139
    for key in sorted(metakeys):
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1140
        ui.write('    %15s:        %9i\n' % (key, metakeys[key]))
4dd1cda16fd0 evolve: add a debugobsstorestat command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 806
diff changeset
  1141
809
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1142
    allclusters = list(set(clustersmap.values()))
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1143
    allclusters.sort(key=lambda x: len(x[1]))
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1144
    ui.write('disconnected clusters:      %9i\n' % len(allclusters))
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1145
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1146
    ui.write('        any known node:     %9i\n'
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1147
             % len([c for c in allclusters
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1148
                    if [n for n in c[0] if nm.get(n) is not None]]))
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1149
    if allclusters:
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1150
        nbcluster = len(allclusters)
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1151
        ui.write('        smallest length:    %9i\n' % len(allclusters[0][1]))
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1152
        ui.write('        longer length:      %9i\n' % len(allclusters[-1][1]))
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1153
        median = len(allclusters[nbcluster//2][1])
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1154
        ui.write('        median length:      %9i\n' % median)
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1155
        mean = sum(len(x[1]) for x in allclusters) // nbcluster
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1156
        ui.write('        mean length:        %9i\n' % mean)
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1157
    allpclusters = list(set(pclustersmap.values()))
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1158
    allpclusters.sort(key=lambda x: len(x[1]))
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1159
    ui.write('    using parents data:     %9i\n' % len(allpclusters))
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1160
    ui.write('        any known node:     %9i\n'
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1161
             % len([c for c in allclusters
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1162
                    if [n for n in c[0] if nm.get(n) is not None]]))
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1163
    if allpclusters:
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1164
        nbcluster = len(allpclusters)
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1165
        ui.write('        smallest length:    %9i\n' % len(allpclusters[0][1]))
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1166
        ui.write('        longer length:      %9i\n' % len(allpclusters[-1][1]))
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1167
        median = len(allpclusters[nbcluster//2][1])
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1168
        ui.write('        median length:      %9i\n' % median)
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1169
        mean = sum(len(x[1]) for x in allpclusters) // nbcluster
5d3ddede6ccf debugobsstorestat: add information about cluster
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 808
diff changeset
  1170
        ui.write('        mean length:        %9i\n' % mean)
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1171
714
3867f7b1fe6e evolve: remove duplicate alias.
Levi Bard <levi@unity3d.com>
parents: 710
diff changeset
  1172
@command('^evolve|stabilize|solve',
949
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1173
    [('n', 'dry-run', False,
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1174
        'do not perform actions, just print what would be done'),
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1175
     ('', 'confirm', False,
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1176
        'ask for confirmation before performing the action'),
1044
c878deb2fd73 evolve: attempt to clarify the documentation around --all and --any
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1043
diff changeset
  1177
    ('A', 'any', False, 'also consider troubled changesets unrelated to current working directory'),
1045
b346d7a3d89e doc: forgotten amend
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1044
diff changeset
  1178
    ('a', 'all', False, 'evolve all troubled changesets in the repo '
b346d7a3d89e doc: forgotten amend
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1044
diff changeset
  1179
                        '(implies any)'),
986
c1f8ece4182d evolve: add --tool option so we don't have to use HGMERGE
Greg Ward <greg@gerg.ca>
parents: 985
diff changeset
  1180
    ('c', 'continue', False, 'continue an interrupted evolution'),
c1f8ece4182d evolve: add --tool option so we don't have to use HGMERGE
Greg Ward <greg@gerg.ca>
parents: 985
diff changeset
  1181
    ] + mergetoolopts,
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  1182
    _('[OPTIONS]...'))
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
  1183
def evolve(ui, repo, **opts):
1168
2187f7c88ff6 evolve: fix capitalization in docstring for commands
André Sintzoff <andre.sintzoff@gmail.com>
parents: 1163
diff changeset
  1184
    """solve trouble in your repository
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
  1185
891
36c1c80e99a3 commands: small language fixes in help
Brendan Cully <brendan@kublai.com>
parents: 867
diff changeset
  1186
    - rebase unstable changesets to make them stable again,
36c1c80e99a3 commands: small language fixes in help
Brendan Cully <brendan@kublai.com>
parents: 867
diff changeset
  1187
    - create proper diffs from bumped changesets,
36c1c80e99a3 commands: small language fixes in help
Brendan Cully <brendan@kublai.com>
parents: 867
diff changeset
  1188
    - merge divergent changesets,
750
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1189
    - update to a successor if the working directory parent is
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1190
      obsolete
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
  1191
1044
c878deb2fd73 evolve: attempt to clarify the documentation around --all and --any
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1043
diff changeset
  1192
    By default a single changeset is evolved for each invocation and only
1045
b346d7a3d89e doc: forgotten amend
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1044
diff changeset
  1193
    troubled changesets that would evolve as a descendant of the current
1044
c878deb2fd73 evolve: attempt to clarify the documentation around --all and --any
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1043
diff changeset
  1194
    working directory will be considered. See --all and --any options to change
c878deb2fd73 evolve: attempt to clarify the documentation around --all and --any
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1043
diff changeset
  1195
    this behavior.
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
  1196
708
0ff2251adfe0 evolve: clean up help message
Levi Bard <levi@unity3d.com>
parents: 707
diff changeset
  1197
    - For unstable, this means taking the first which could be rebased as a
0ff2251adfe0 evolve: clean up help message
Levi Bard <levi@unity3d.com>
parents: 707
diff changeset
  1198
      child of the working directory parent revision or one of its descendants
0ff2251adfe0 evolve: clean up help message
Levi Bard <levi@unity3d.com>
parents: 707
diff changeset
  1199
      and rebasing it.
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
  1200
708
0ff2251adfe0 evolve: clean up help message
Levi Bard <levi@unity3d.com>
parents: 707
diff changeset
  1201
    - For divergent, this means taking "." if applicable.
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
  1202
891
36c1c80e99a3 commands: small language fixes in help
Brendan Cully <brendan@kublai.com>
parents: 867
diff changeset
  1203
    With --any, evolve picks any troubled changeset to repair.
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
  1204
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
  1205
    The working directory is updated to the newly created revision.
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
  1206
    """
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
  1207
465
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
  1208
    contopt = opts['continue']
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
  1209
    anyopt = opts['any']
704
2ec7c3673679 evolve: add --all argument.
Levi Bard <levi@unity3d.com>
parents: 703
diff changeset
  1210
    allopt = opts['all']
703
a246b02499d9 evolve: extract evolve --any implementation into a function.
Levi Bard <levi@unity3d.com>
parents: 663
diff changeset
  1211
    dryrunopt = opts['dry_run']
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1212
    confirmopt = opts['confirm']
986
c1f8ece4182d evolve: add --tool option so we don't have to use HGMERGE
Greg Ward <greg@gerg.ca>
parents: 985
diff changeset
  1213
    ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'evolve')
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
  1214
1099
bac4e0bc9f6a evolve: write a status message when the working directory changes
David Soria Parra <davidsp@fb.com>
parents: 1067
diff changeset
  1215
    startnode = repo['.']
bac4e0bc9f6a evolve: write a status message when the working directory changes
David Soria Parra <davidsp@fb.com>
parents: 1067
diff changeset
  1216
465
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
  1217
    if contopt:
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
  1218
        if anyopt:
947
9a6cc7e6f0dd evolve: improve wording of a few of messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 946
diff changeset
  1219
            raise util.Abort('cannot specify both "--any" and "--continue"')
704
2ec7c3673679 evolve: add --all argument.
Levi Bard <levi@unity3d.com>
parents: 703
diff changeset
  1220
        if allopt:
947
9a6cc7e6f0dd evolve: improve wording of a few of messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 946
diff changeset
  1221
            raise util.Abort('cannot specify both "--all" and "--continue"')
465
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
  1222
        graftcmd = commands.table['graft'][0]
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
  1223
        return graftcmd(ui, repo, old_obsolete=True, **{'continue': True})
703
a246b02499d9 evolve: extract evolve --any implementation into a function.
Levi Bard <levi@unity3d.com>
parents: 663
diff changeset
  1224
1015
68d9c7e4a03d evolve: rename `tr` variable (for troubled) to `tro`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1014
diff changeset
  1225
    tro = _picknexttroubled(ui, repo, anyopt or allopt)
68d9c7e4a03d evolve: rename `tr` variable (for troubled) to `tro`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1014
diff changeset
  1226
    if tro is None:
750
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1227
        if repo['.'].obsolete():
949
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1228
            displayer = cmdutil.show_changeset(
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1229
                ui, repo, {'template': shorttemplate})
750
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1230
            successors = set()
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1231
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1232
            for successorsset in obsolete.successorssets(repo, repo['.'].node()):
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1233
                for nodeid in successorsset:
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1234
                    successors.add(repo[nodeid])
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1235
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1236
            if not successors:
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1237
                ui.warn(_('parent is obsolete without successors; ' +
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1238
                          'likely killed\n'))
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1239
                return 2
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1240
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1241
            elif len(successors) > 1:
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1242
                ui.warn(_('parent is obsolete with multiple successors:\n'))
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1243
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1244
                for ctx in sorted(successors, key=lambda ctx: ctx.rev()):
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1245
                    displayer.show(ctx)
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1246
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1247
                return 2
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1248
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1249
            else:
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1250
                ctx = successors.pop()
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1251
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1252
                ui.status(_('update:'))
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1253
                if not ui.quiet:
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1254
                    displayer.show(ctx)
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1255
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1256
                if dryrunopt:
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1257
                    return 0
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1258
                else:
1099
bac4e0bc9f6a evolve: write a status message when the working directory changes
David Soria Parra <davidsp@fb.com>
parents: 1067
diff changeset
  1259
                    res = hg.update(repo, ctx.rev())
bac4e0bc9f6a evolve: write a status message when the working directory changes
David Soria Parra <davidsp@fb.com>
parents: 1067
diff changeset
  1260
                    if ctx != startnode:
bac4e0bc9f6a evolve: write a status message when the working directory changes
David Soria Parra <davidsp@fb.com>
parents: 1067
diff changeset
  1261
                        ui.status(_('working directory is now at %s\n') % ctx)
bac4e0bc9f6a evolve: write a status message when the working directory changes
David Soria Parra <davidsp@fb.com>
parents: 1067
diff changeset
  1262
                    return res
750
ddbea2fdee5e evolve: allow updating to the successor if the parent is obsolete
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 749
diff changeset
  1263
511
ddeb71df916d evolve: localrepo.revs() already returns a list
Patrick Mezard <patrick@mezard.eu>
parents: 510
diff changeset
  1264
        troubled = repo.revs('troubled()')
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1265
        if troubled:
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
  1266
            ui.write_err(_('nothing to evolve here\n'))
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1267
            ui.status(_('(%i troubled changesets, do you want --any ?)\n')
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1268
                      % len(troubled))
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
  1269
            return 2
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1270
        else:
722
4e7e7a7d8500 evolve: remove trailing spaces
AndréSintzoff <andre.sintzoff@gmail.com>
parents: 716
diff changeset
  1271
            ui.write_err(_('no troubled changesets\n'))
145
928f217c1701 stabilize: stabilize my topological branch only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 142
diff changeset
  1272
            return 1
706
90f0a1ede70a evolve: clean up evolve implementation.
Levi Bard <levi@unity3d.com>
parents: 704
diff changeset
  1273
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1274
    def progresscb():
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1275
        if allopt:
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1276
            ui.progress('evolve', seen, unit='changesets', total=count)
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1277
    seen = 1
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1278
    count = allopt and _counttroubled(ui, repo) or 1
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1279
1015
68d9c7e4a03d evolve: rename `tr` variable (for troubled) to `tro`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1014
diff changeset
  1280
    while tro is not None:
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1281
        progresscb()
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1282
        wlock = lock = tr = None
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1283
        try:
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1284
            wlock = repo.wlock()
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1285
            lock = repo.lock()
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1286
            tr = repo.transaction("evolve")
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1287
            result = _evolveany(ui, repo, tro, dryrunopt, confirmopt,
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1288
                                progresscb=progresscb)
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1289
            tr.close()
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1290
        finally:
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1291
            lockmod.release(tr, lock, wlock)
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1292
        progresscb()
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1293
        seen += 1
707
f914e315b717 evolve: remove magic return values from utility functions
Levi Bard <levi@unity3d.com>
parents: 706
diff changeset
  1294
        if not allopt:
1099
bac4e0bc9f6a evolve: write a status message when the working directory changes
David Soria Parra <davidsp@fb.com>
parents: 1067
diff changeset
  1295
            if repo['.'] != startnode:
bac4e0bc9f6a evolve: write a status message when the working directory changes
David Soria Parra <davidsp@fb.com>
parents: 1067
diff changeset
  1296
                ui.status(_('working directory is now at %s\n') % repo['.'])
706
90f0a1ede70a evolve: clean up evolve implementation.
Levi Bard <levi@unity3d.com>
parents: 704
diff changeset
  1297
            return result
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1298
        progresscb()
1015
68d9c7e4a03d evolve: rename `tr` variable (for troubled) to `tro`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1014
diff changeset
  1299
        tro = _picknexttroubled(ui, repo, anyopt or allopt)
722
4e7e7a7d8500 evolve: remove trailing spaces
AndréSintzoff <andre.sintzoff@gmail.com>
parents: 716
diff changeset
  1300
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1301
    if allopt:
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1302
        ui.progress('evolve', None)
706
90f0a1ede70a evolve: clean up evolve implementation.
Levi Bard <levi@unity3d.com>
parents: 704
diff changeset
  1303
1099
bac4e0bc9f6a evolve: write a status message when the working directory changes
David Soria Parra <davidsp@fb.com>
parents: 1067
diff changeset
  1304
    if repo['.'] != startnode:
bac4e0bc9f6a evolve: write a status message when the working directory changes
David Soria Parra <davidsp@fb.com>
parents: 1067
diff changeset
  1305
        ui.status(_('working directory is now at %s\n') % repo['.'])
bac4e0bc9f6a evolve: write a status message when the working directory changes
David Soria Parra <davidsp@fb.com>
parents: 1067
diff changeset
  1306
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1307
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1308
def _evolveany(ui, repo, tro, dryrunopt, confirmopt, progresscb):
651
609faf10d307 evolve: ensure evolve command run unfiltered
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 649
diff changeset
  1309
    repo = repo.unfiltered()
1015
68d9c7e4a03d evolve: rename `tr` variable (for troubled) to `tro`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1014
diff changeset
  1310
    tro = repo[tro.rev()]
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1311
    cmdutil.bailifchanged(repo)
1015
68d9c7e4a03d evolve: rename `tr` variable (for troubled) to `tro`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1014
diff changeset
  1312
    troubles = tro.troubles()
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1313
    if 'unstable' in troubles:
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1314
        return _solveunstable(ui, repo, tro, dryrunopt, confirmopt, progresscb)
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1315
    elif 'bumped' in troubles:
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1316
        return _solvebumped(ui, repo, tro, dryrunopt, confirmopt, progresscb)
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1317
    elif 'divergent' in troubles:
625
e291e5271694 prepare for Full scale filtering !!!
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 622
diff changeset
  1318
        repo = repo.unfiltered()
1015
68d9c7e4a03d evolve: rename `tr` variable (for troubled) to `tro`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1014
diff changeset
  1319
        tro = repo[tro.rev()]
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1320
        return _solvedivergent(ui, repo, tro, dryrunopt, confirmopt,
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1321
                               progresscb)
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1322
    else:
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1323
        assert False  # WHAT? unknown troubles
269
6c6bb7a23bb5 stabilize: improve unstable selection heuristic
Patrick Mezard <patrick@mezard.eu>
parents: 268
diff changeset
  1324
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1325
def _counttroubled(ui, repo):
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1326
    """Count the amount of troubled changesets"""
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1327
    troubled = set()
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1328
    troubled.update(getrevs(repo, 'unstable'))
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1329
    troubled.update(getrevs(repo, 'bumped'))
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1330
    troubled.update(getrevs(repo, 'divergent'))
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1331
    return len(troubled)
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1332
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1333
def _picknexttroubled(ui, repo, pickany=False, progresscb=None):
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1334
    """Pick a the next trouble changeset to solve"""
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1335
    if progresscb: progresscb()
1015
68d9c7e4a03d evolve: rename `tr` variable (for troubled) to `tro`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1014
diff changeset
  1336
    tro = _stabilizableunstable(repo, repo['.'])
68d9c7e4a03d evolve: rename `tr` variable (for troubled) to `tro`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1014
diff changeset
  1337
    if tro is None:
484
20e2f2dd71f1 stabilize: conflicting changeset are considered if "."
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 482
diff changeset
  1338
        wdp = repo['.']
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1339
        if 'divergent' in wdp.troubles():
1015
68d9c7e4a03d evolve: rename `tr` variable (for troubled) to `tro`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1014
diff changeset
  1340
            tro = wdp
68d9c7e4a03d evolve: rename `tr` variable (for troubled) to `tro`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1014
diff changeset
  1341
    if tro is None and pickany:
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1342
        troubled = list(repo.set('unstable()'))
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1343
        if not troubled:
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1344
            troubled = list(repo.set('bumped()'))
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1345
        if not troubled:
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1346
            troubled = list(repo.set('divergent()'))
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1347
        if troubled:
1015
68d9c7e4a03d evolve: rename `tr` variable (for troubled) to `tro`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1014
diff changeset
  1348
            tro = troubled[0]
68d9c7e4a03d evolve: rename `tr` variable (for troubled) to `tro`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1014
diff changeset
  1349
68d9c7e4a03d evolve: rename `tr` variable (for troubled) to `tro`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1014
diff changeset
  1350
    return tro
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1351
509
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1352
def _stabilizableunstable(repo, pctx):
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1353
    """Return a changectx for an unstable changeset which can be
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1354
    stabilized on top of pctx or one of its descendants. None if none
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1355
    can be found.
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1356
    """
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1357
    def selfanddescendants(repo, pctx):
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1358
        yield pctx
636
27c890b4f864 evolve: make evolve smarter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 626
diff changeset
  1359
        for prec in repo.set('allprecursors(%d)', pctx):
27c890b4f864 evolve: make evolve smarter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 626
diff changeset
  1360
            yield prec
509
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1361
        for ctx in pctx.descendants():
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1362
            yield ctx
636
27c890b4f864 evolve: make evolve smarter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 626
diff changeset
  1363
            for prec in repo.set('allprecursors(%d)', ctx):
27c890b4f864 evolve: make evolve smarter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 626
diff changeset
  1364
                yield prec
509
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1365
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1366
    # Look for an unstable which can be stabilized as a child of
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1367
    # node. The unstable must be a child of one of node predecessors.
1157
5951969400ce evolve: fix selection of changeset to evolve from the middle of a stack (issue4434)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1153
diff changeset
  1368
    directdesc = set([pctx.rev()])
509
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1369
    for ctx in selfanddescendants(repo, pctx):
636
27c890b4f864 evolve: make evolve smarter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 626
diff changeset
  1370
        for child in ctx.children():
1157
5951969400ce evolve: fix selection of changeset to evolve from the middle of a stack (issue4434)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1153
diff changeset
  1371
            if ctx.rev() in directdesc and not child.obsolete():
5951969400ce evolve: fix selection of changeset to evolve from the middle of a stack (issue4434)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1153
diff changeset
  1372
                directdesc.add(child.rev())
5951969400ce evolve: fix selection of changeset to evolve from the middle of a stack (issue4434)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1153
diff changeset
  1373
            elif child.unstable():
636
27c890b4f864 evolve: make evolve smarter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 626
diff changeset
  1374
                return child
509
c072e559746d evolve: move _stabilizableunstable() with related functions
Patrick Mezard <patrick@mezard.eu>
parents: 507
diff changeset
  1375
    return None
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1376
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1377
def _solveunstable(ui, repo, orig, dryrun=False, confirm=False,
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1378
                   progresscb=None):
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1379
    """Stabilize a unstable changeset"""
464
d88c761f97c4 stabilize: rename "node" variable to "orig"
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 463
diff changeset
  1380
    obs = orig.parents()[0]
87
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
  1381
    if not obs.obsolete():
1157
5951969400ce evolve: fix selection of changeset to evolve from the middle of a stack (issue4434)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1153
diff changeset
  1382
        obs = orig.parents()[1] # second parent is obsolete ?
87
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
  1383
    assert obs.obsolete()
630
722b52c75f02 compat: adapt to upstreaming of divergent logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 622
diff changeset
  1384
    newer = obsolete.successorssets(repo, obs.node())
466
b98490b689a5 stabilize: handle killed changeset in stabilize.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 465
diff changeset
  1385
    # search of a parent which is not killed
588
89c8550019d0 mercurial: replace all `newerversion` call by `successorsset` call
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 587
diff changeset
  1386
    while not newer or newer == [()]:
466
b98490b689a5 stabilize: handle killed changeset in stabilize.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 465
diff changeset
  1387
        ui.debug("stabilize target %s is plain dead,"
1145
fb51113a1c08 evolve: add the missing newline to output messages where needed
Matt Harbison <matt_harbison@yahoo.com>
parents: 1144
diff changeset
  1388
                 " trying to stabilize on its parent\n" %
1144
b2a78b950a51 evolve: add the missing argument to a debug statement
Matt Harbison <matt_harbison@yahoo.com>
parents: 1143
diff changeset
  1389
                 obs)
466
b98490b689a5 stabilize: handle killed changeset in stabilize.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 465
diff changeset
  1390
        obs = obs.parents()[0]
630
722b52c75f02 compat: adapt to upstreaming of divergent logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 622
diff changeset
  1391
        newer = obsolete.successorssets(repo, obs.node())
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1392
    if len(newer) > 1:
707
f914e315b717 evolve: remove magic return values from utility functions
Levi Bard <levi@unity3d.com>
parents: 706
diff changeset
  1393
        raise util.Abort(_("conflict rewriting. can't choose destination\n"))
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1394
    targets = newer[0]
466
b98490b689a5 stabilize: handle killed changeset in stabilize.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 465
diff changeset
  1395
    assert targets
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1396
    if len(targets) > 1:
707
f914e315b717 evolve: remove magic return values from utility functions
Levi Bard <levi@unity3d.com>
parents: 706
diff changeset
  1397
        raise util.Abort(_("does not handle split parents yet\n"))
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1398
        return 2
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  1399
    target = targets[0]
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
  1400
    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
  1401
    target = repo[target]
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1402
    if not ui.quiet or confirm:
1046
296d48e1f55a evolve: gather evolve output together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1045
diff changeset
  1403
        repo.ui.write(_('move:'))
464
d88c761f97c4 stabilize: rename "node" variable to "orig"
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 463
diff changeset
  1404
        displayer.show(orig)
1046
296d48e1f55a evolve: gather evolve output together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1045
diff changeset
  1405
        repo.ui.write(_('atop:'))
146
e80a6c8ad452 stabilize: proper --quiet behavior
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 145
diff changeset
  1406
        displayer.show(target)
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1407
    if confirm and ui.prompt('perform evolve? [Ny]') != 'y':
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1408
            raise util.Abort(_('evolve aborted by user'))
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1409
    if progresscb: progresscb()
546
415540dee2bd fix missing --dest evolve output in dryrun
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 540
diff changeset
  1410
    todo = 'hg rebase -r %s -d %s\n' % (orig, target)
468
6b1b6d338478 stabilize: rework stabilize code to allow selection of latecomer and conflicting
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 466
diff changeset
  1411
    if dryrun:
146
e80a6c8ad452 stabilize: proper --quiet behavior
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 145
diff changeset
  1412
        repo.ui.write(todo)
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
  1413
    else:
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
  1414
        repo.ui.note(todo)
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1415
        if progresscb: progresscb()
1141
ca17770d2ee9 evolve: preserve branch change
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1140
diff changeset
  1416
        keepbranch = orig.p1().branch() != orig.branch()
139
9b9500175ae5 evolve that does something \o/
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 137
diff changeset
  1417
        try:
1141
ca17770d2ee9 evolve: preserve branch change
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1140
diff changeset
  1418
            relocate(repo, orig, target, keepbranch)
463
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
  1419
        except MergeFailure:
465
4a039a8c1cf3 stabilize: --continue support !!!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 464
diff changeset
  1420
            repo.opener.write('graftstate', orig.hex() + '\n')
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
  1421
            repo.ui.write_err(_('evolve failed!\n'))
949
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1422
            repo.ui.write_err(
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1423
                _('fix conflict and run "hg evolve --continue"\n'))
463
3f91654713dd obsolete Move merge failure handling into stabilize code
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 455
diff changeset
  1424
            raise
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
  1425
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1426
def _solvebumped(ui, repo, bumped, dryrun=False, confirm=False,
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1427
                 progresscb=None):
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1428
    """Stabilize a bumped changeset"""
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1429
    # For now we deny bumped merge
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1430
    if len(bumped.parents()) > 1:
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1431
        raise util.Abort('late comer stabilization is confused by bumped'
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1432
                         ' %s being a merge' % bumped)
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1433
    prec = repo.set('last(allprecursors(%d) and public())', bumped).next()
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1434
    # For now we deny target merge
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1435
    if len(prec.parents()) > 1:
492
7ecd41520dae rename `stabilize` to `evolve`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 491
diff changeset
  1436
        raise util.Abort('late comer evolution is confused by precursors'
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1437
                         ' %s being a merge' % prec)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1438
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1439
    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1440
    if not ui.quiet or confirm:
1046
296d48e1f55a evolve: gather evolve output together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1045
diff changeset
  1441
        repo.ui.write(_('recreate:'))
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1442
        displayer.show(bumped)
1046
296d48e1f55a evolve: gather evolve output together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1045
diff changeset
  1443
        repo.ui.write(_('atop:'))
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1444
        displayer.show(prec)
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1445
    if confirm and ui.prompt('perform evolve? [Ny]') != 'y':
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1446
        raise util.Abort(_('evolve aborted by user'))
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1447
    if dryrun:
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1448
        todo = 'hg rebase --rev %s --dest %s;\n' % (bumped, prec.p1())
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1449
        repo.ui.write(todo)
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1450
        repo.ui.write('hg update %s;\n' % prec)
593
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1451
        repo.ui.write('hg revert --all --rev %s;\n' % bumped)
26f76b38f879 evolve: Rename latecomer into bumped
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 588
diff changeset
  1452
        repo.ui.write('hg commit --msg "bumped update to %s"')
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1453
        return 0
762
942aabaa8a8e evolve: show progress
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 760
diff changeset
  1454
    if progresscb: progresscb()
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1455
    newid = tmpctx = None
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1456
    tmpctx = bumped
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1457
    bmupdate = _bookmarksupdater(repo, bumped.node())
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1458
    # Basic check for common parent. Far too complicated and fragile
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1459
    tr = repo.transaction('bumped-stabilize')
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1460
    try:
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1461
        if not list(repo.set('parents(%d) and parents(%d)', bumped, prec)):
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1462
            # Need to rebase the changeset at the right place
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1463
            repo.ui.status(
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1464
                _('rebasing to destination parent: %s\n') % prec.p1())
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1465
            try:
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1466
                tmpid = relocate(repo, bumped, prec.p1())
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1467
                if tmpid is not None:
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1468
                    tmpctx = repo[tmpid]
1070
527b12a59628 drop relevant marker compat
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1069
diff changeset
  1469
                    obsolete.createmarkers(repo, [(bumped, (tmpctx,))])
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1470
            except MergeFailure:
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1471
                repo.opener.write('graftstate', bumped.hex() + '\n')
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1472
                repo.ui.write_err(_('evolution failed!\n'))
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1473
                repo.ui.write_err(
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1474
                    _('fix conflict and run "hg evolve --continue"\n'))
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1475
                raise
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1476
        # Create the new commit context
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1477
        repo.ui.status(_('computing new diff\n'))
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1478
        files = set()
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1479
        copied = copies.pathcopies(prec, bumped)
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1480
        precmanifest = prec.manifest()
1212
2c1b6e2ec59a merge with stable
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1211
diff changeset
  1481
        # 3.3.2 needs a list.
2c1b6e2ec59a merge with stable
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1211
diff changeset
  1482
        # future 3.4 don't detect the size change during iteration
2c1b6e2ec59a merge with stable
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1211
diff changeset
  1483
        # this is fishy
1228
72a3f8d307b2 evolve: have a stable manifest content when solving bumped
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1211
diff changeset
  1484
        for key, val in list(bumped.manifest().iteritems()):
1211
9523c027a240 evolve: fix manifest usage to match upstream
Durham Goode <durham@fb.com>
parents: 1209
diff changeset
  1485
            precvalue = precmanifest.get(key, None)
9523c027a240 evolve: fix manifest usage to match upstream
Durham Goode <durham@fb.com>
parents: 1209
diff changeset
  1486
            if precvalue is not None:
9523c027a240 evolve: fix manifest usage to match upstream
Durham Goode <durham@fb.com>
parents: 1209
diff changeset
  1487
                del precmanifest[key]
9523c027a240 evolve: fix manifest usage to match upstream
Durham Goode <durham@fb.com>
parents: 1209
diff changeset
  1488
            if precvalue != val:
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1489
                files.add(key)
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1490
        files.update(precmanifest)  # add missing files
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1491
        # commit it
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1492
        if files: # something to commit!
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1493
            def filectxfn(repo, ctx, path):
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1494
                if path in bumped:
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1495
                    fctx = bumped[path]
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1496
                    flags = fctx.flags()
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1497
                    mctx = memfilectx(repo, fctx.path(), fctx.data(),
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1498
                                      islink='l' in flags,
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1499
                                      isexec='x' in flags,
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1500
                                      copied=copied.get(path))
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1501
                    return mctx
1086
96b9e0c31cc1 compat: adapt to change to memctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1085
diff changeset
  1502
                return None
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1503
            text = 'bumped update to %s:\n\n' % prec
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1504
            text += bumped.description()
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1505
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1506
            new = context.memctx(repo,
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1507
                                 parents=[prec.node(), node.nullid],
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1508
                                 text=text,
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1509
                                 files=files,
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1510
                                 filectxfn=filectxfn,
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1511
                                 user=bumped.user(),
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1512
                                 date=bumped.date(),
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1513
                                 extra=bumped.extra())
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1514
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1515
            newid = repo.commitctx(new)
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1516
        if newid is None:
1070
527b12a59628 drop relevant marker compat
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1069
diff changeset
  1517
            obsolete.createmarkers(repo, [(tmpctx, ())])
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1518
            newid = prec.node()
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1519
        else:
1069
356552e55489 evolve: always use the transaction version of phase movement
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1068
diff changeset
  1520
            phases.retractboundary(repo, tr, bumped.phase(), [newid])
1070
527b12a59628 drop relevant marker compat
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1069
diff changeset
  1521
            obsolete.createmarkers(repo, [(tmpctx, (repo[newid],))],
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1522
                                   flag=obsolete.bumpedfix)
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1523
        bmupdate(newid)
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1524
        tr.close()
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1525
        repo.ui.status(_('committed as %s\n') % node.short(newid))
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1526
    finally:
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1527
        tr.release()
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1528
    # reroute the working copy parent to the new changeset
1112
c3e23fbf7bd7 evolve: wrap setparents calls in begin/endparentchange
Siddharth Agarwal <sid0@fb.com>
parents: 1111
diff changeset
  1529
    repo.dirstate.beginparentchange()
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1530
    repo.dirstate.setparents(newid, node.nullid)
1112
c3e23fbf7bd7 evolve: wrap setparents calls in begin/endparentchange
Siddharth Agarwal <sid0@fb.com>
parents: 1111
diff changeset
  1531
    repo.dirstate.endparentchange()
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1532
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1533
def _solvedivergent(ui, repo, divergent, dryrun=False, confirm=False,
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1534
                    progresscb=None):
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1535
    base, others = divergentdata(divergent)
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1536
    if len(others) > 1:
760
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1537
        othersstr = "[%s]" % (','.join([str(i) for i in others]))
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1538
        hint = ("changeset %d is divergent with a changeset that got splitted "
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1539
                "| into multiple ones:\n[%s]\n"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1540
                "| This is not handled by automatic evolution yet\n"
947
9a6cc7e6f0dd evolve: improve wording of a few of messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 946
diff changeset
  1541
                "| You have to fallback to manual handling with commands "
9a6cc7e6f0dd evolve: improve wording of a few of messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 946
diff changeset
  1542
                "such as:\n"
760
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1543
                "| - hg touch -D\n"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1544
                "| - hg prune\n"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1545
                "| \n"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1546
                "| You should contact your local evolution Guru for help.\n"
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1547
                % (divergent, othersstr))
948
b2b3d5aa16bc evolve: start all util.Abort messages with lower case
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 947
diff changeset
  1548
        raise util.Abort("we do not handle divergence with split yet",
1016
facb5efa8ea4 divergence: actually use the hint that have been around for age
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1015
diff changeset
  1549
                         hint=hint)
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1550
    other = others[0]
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1551
    if divergent.phase() <= phases.public:
948
b2b3d5aa16bc evolve: start all util.Abort messages with lower case
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 947
diff changeset
  1552
        raise util.Abort("we can't resolve this conflict from the public side",
949
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1553
                    hint="%s is public, try from %s" % (divergent, other))
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1554
    if len(other.parents()) > 1:
760
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1555
        raise util.Abort("divergent changeset can't be a merge (yet)",
949
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1556
                    hint="You have to fallback to solving this by hand...\n"
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1557
                         "| This probably means redoing the merge and using "
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1558
                         "| `hg prune` to kill older version.")
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1559
    if other.p1() not in divergent.parents():
760
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1560
        raise util.Abort("parents are not common (not handled yet)",
1152
be6eff57d5bb evolve: add missing newlines in "parents are not common" hint
Martin von Zweigbergk <martinvonz@google.com>
parents: 1150
diff changeset
  1561
                    hint="| %(d)s, %(o)s are not based on the same changeset.\n"
be6eff57d5bb evolve: add missing newlines in "parents are not common" hint
Martin von Zweigbergk <martinvonz@google.com>
parents: 1150
diff changeset
  1562
                         "| With the current state of its implementation, \n"
949
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1563
                         "| evolve does not work in that case.\n"
1152
be6eff57d5bb evolve: add missing newlines in "parents are not common" hint
Martin von Zweigbergk <martinvonz@google.com>
parents: 1150
diff changeset
  1564
                         "| rebase one of them next to the other and run \n"
949
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1565
                         "| this command again.\n"
1153
4241a5162de7 evolve: fix suggested commands in "parents are not common" hint
Martin von Zweigbergk <martinvonz@google.com>
parents: 1152
diff changeset
  1566
                         "| - either: hg rebase --dest 'p1(%(d)s)' -r %(o)s\n"
4241a5162de7 evolve: fix suggested commands in "parents are not common" hint
Martin von Zweigbergk <martinvonz@google.com>
parents: 1152
diff changeset
  1567
                         "| - or:     hg rebase --dest 'p1(%(o)s)' -r %(d)s"
760
bbb3a0e1dfea evolve: add more details when we abort for case not handled yet
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1568
                              % {'d': divergent, 'o': other})
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1569
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1570
    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1571
    if not ui.quiet or confirm:
1046
296d48e1f55a evolve: gather evolve output together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1045
diff changeset
  1572
        ui.write(_('merge:'))
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1573
        displayer.show(divergent)
1046
296d48e1f55a evolve: gather evolve output together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1045
diff changeset
  1574
        ui.write(_('with: '))
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1575
        displayer.show(other)
1046
296d48e1f55a evolve: gather evolve output together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1045
diff changeset
  1576
        ui.write(_('base: '))
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1577
        displayer.show(base)
1047
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1578
    if confirm and ui.prompt('perform evolve? [Ny]') != 'y':
d830377bf186 evolve: adds a --confirm option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1046
diff changeset
  1579
        raise util.Abort(_('evolve aborted by user'))
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1580
    if dryrun:
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1581
        ui.write('hg update -c %s &&\n' % divergent)
533
87c41ef95ebf test conflicting conflicting (sic) resolution
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 523
diff changeset
  1582
        ui.write('hg merge %s &&\n' % other)
517
0bc0c9edcb15 evolve: usual syntax/grammar errors/long lines cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 516
diff changeset
  1583
        ui.write('hg commit -m "auto merge resolving conflict between '
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1584
                 '%s and %s"&&\n' % (divergent, other))
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1585
        ui.write('hg up -C %s &&\n' % base)
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1586
        ui.write('hg revert --all --rev tip &&\n')
517
0bc0c9edcb15 evolve: usual syntax/grammar errors/long lines cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 516
diff changeset
  1587
        ui.write('hg commit -m "`hg log -r %s --template={desc}`";\n'
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1588
                 % divergent)
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1589
        return
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1590
    if divergent not in repo[None].parents():
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1591
        repo.ui.status(_('updating to "local" conflict\n'))
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1592
        hg.update(repo, divergent.rev())
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1593
    repo.ui.note(_('merging divergent changeset\n'))
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1594
    if progresscb: progresscb()
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1595
    stats = merge.update(repo,
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1596
                         other.node(),
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1597
                         branchmerge=True,
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1598
                         force=False,
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1599
                         partial=None,
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1600
                         ancestor=base.node(),
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1601
                         mergeancestor=True)
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1602
    hg._showstats(repo, stats)
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1603
    if stats[3]:
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1604
        repo.ui.status(_("use 'hg resolve' to retry unresolved file merges "
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1605
                         "or 'hg update -C .' to abandon\n"))
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1606
    if stats[3] > 0:
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1607
        raise util.Abort('merge conflict between several amendments '
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1608
            '(this is not automated yet)',
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1609
            hint="""/!\ You can try:
534
45ccaba212f9 a better msg for this tricky situation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 533
diff changeset
  1610
/!\ * manual merge + resolve => new cset X
45ccaba212f9 a better msg for this tricky situation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 533
diff changeset
  1611
/!\ * hg up to the parent of the amended changeset (which are named W and Z)
45ccaba212f9 a better msg for this tricky situation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 533
diff changeset
  1612
/!\ * hg revert --all -r X
45ccaba212f9 a better msg for this tricky situation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 533
diff changeset
  1613
/!\ * hg ci -m "same message as the amended changeset" => new cset Y
45ccaba212f9 a better msg for this tricky situation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 533
diff changeset
  1614
/!\ * hg kill -n Y W Z
45ccaba212f9 a better msg for this tricky situation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 533
diff changeset
  1615
""")
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1616
    if progresscb: progresscb()
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1617
    tr = repo.transaction('stabilize-divergent')
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1618
    try:
1112
c3e23fbf7bd7 evolve: wrap setparents calls in begin/endparentchange
Siddharth Agarwal <sid0@fb.com>
parents: 1111
diff changeset
  1619
        repo.dirstate.beginparentchange()
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1620
        repo.dirstate.setparents(divergent.node(), node.nullid)
1112
c3e23fbf7bd7 evolve: wrap setparents calls in begin/endparentchange
Siddharth Agarwal <sid0@fb.com>
parents: 1111
diff changeset
  1621
        repo.dirstate.endparentchange()
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1622
        oldlen = len(repo)
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1623
        amend(ui, repo, message='', logfile='')
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1624
        if oldlen == len(repo):
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1625
            new = divergent
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1626
            # no changes
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1627
        else:
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1628
            new = repo['.']
1070
527b12a59628 drop relevant marker compat
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1069
diff changeset
  1629
        obsolete.createmarkers(repo, [(other, (new,))])
1069
356552e55489 evolve: always use the transaction version of phase movement
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1068
diff changeset
  1630
        phases.retractboundary(repo, tr, other.phase(), [new.node()])
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1631
        tr.close()
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1632
    finally:
1021
200f2d9b9f39 evolve: saner locking an transaction in `hg evolve`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1020
diff changeset
  1633
        tr.release()
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1634
586
f01721161532 evolve: rename conflicting into divergent
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 585
diff changeset
  1635
def divergentdata(ctx):
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1636
    """return base, other part of a conflict
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1637
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1638
    This only return the first one.
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1639
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1640
    XXX this woobly function won't survive XXX
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1641
    """
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1642
    for base in ctx._repo.set('reverse(precursors(%d))', ctx):
630
722b52c75f02 compat: adapt to upstreaming of divergent logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 622
diff changeset
  1643
        newer = obsolete.successorssets(ctx._repo, base.node())
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1644
        # drop filter and solution including the original ctx
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1645
        newer = [n for n in newer if n and ctx.node() not in n]
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1646
        if newer:
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1647
            return base, tuple(ctx._repo[o] for o in newer[0])
1173
fc95401f952f evolve: tell user which "base of divergent changeset" is not found
Martin von Zweigbergk <martinvonz@google.com>
parents: 1168
diff changeset
  1648
    raise util.Abort("base of divergent changeset %s not found" % ctx,
749
f728edc7fcd1 evolve: abort on unknown divergent changeset base
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 745
diff changeset
  1649
                     hint='this case is not yet handled')
485
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1650
41bf6c27a122 evolve: stabilize now handle conflicting changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 484
diff changeset
  1651
469
abeb17a9e313 stabilize: handle latecomer
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 468
diff changeset
  1652
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1653
shorttemplate = '[{rev}] {desc|firstline}\n'
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1654
895
17ac69db9329 evolve: deprecate gup and gdown aliases
Olle Lundberg <geek@nerd.sh>
parents: 894
diff changeset
  1655
@command('^previous',
1160
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1656
         [('B', 'move-bookmark', False,
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1657
             _('Move current active bookmark after update'))],
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1658
         '[-B]')
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1659
def cmdprevious(ui, repo, **opts):
724
fa049c1d9445 evolve: fix typo
André Sintzoff <andre.sintzoff@gmail.com>
parents: 723
diff changeset
  1660
    """update to parent and display summary lines"""
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1661
    wkctx = repo[None]
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1662
    wparents = wkctx.parents()
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1663
    if len(wparents) != 1:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1664
        raise util.Abort('merge in progress')
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1665
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1666
    parents = wparents[0].parents()
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1667
    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1668
    if len(parents) == 1:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1669
        p = parents[0]
892
947fb5b1915b evolve: active bookmark should move when using prev/next (#37)
Olle Lundberg <geek@nerd.sh>
parents: 891
diff changeset
  1670
        bm = bookmarks.readcurrent(repo)
1160
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1671
        shouldmove = opts.get('move_bookmark') and bm is not None
892
947fb5b1915b evolve: active bookmark should move when using prev/next (#37)
Olle Lundberg <geek@nerd.sh>
parents: 891
diff changeset
  1672
        ret = hg.update(repo, p.rev())
1160
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1673
        if not ret:
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1674
            if shouldmove:
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1675
                repo._bookmarks[bm] = p.node()
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1676
                repo._bookmarks.write()
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1677
            else:
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1678
                bookmarks.unsetcurrent(repo)
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1679
        displayer.show(p)
88
64fe5a4f877e [evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 87
diff changeset
  1680
        return 0
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1681
    else:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1682
        for p in parents:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1683
            displayer.show(p)
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1684
        ui.warn(_('multiple parents, explicitly update to one\n'))
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1685
        return 1
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1686
895
17ac69db9329 evolve: deprecate gup and gdown aliases
Olle Lundberg <geek@nerd.sh>
parents: 894
diff changeset
  1687
@command('^next',
1160
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1688
         [('B', 'move-bookmark', False,
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1689
             _('Move current active bookmark after update'))],
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1690
         '[-B]')
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1691
def cmdnext(ui, repo, **opts):
724
fa049c1d9445 evolve: fix typo
André Sintzoff <andre.sintzoff@gmail.com>
parents: 723
diff changeset
  1692
    """update to child and display summary lines"""
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1693
    wkctx = repo[None]
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1694
    wparents = wkctx.parents()
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1695
    if len(wparents) != 1:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1696
        raise util.Abort('merge in progress')
87
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
  1697
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1698
    children = [ctx for ctx in wparents[0].children() if not ctx.obsolete()]
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1699
    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1700
    if not children:
743
af74a5cdf96b conform to the Mercurial custom of lowercase messages
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 742
diff changeset
  1701
        ui.warn(_('no non-obsolete children\n'))
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1702
        return 1
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1703
    if len(children) == 1:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1704
        c = children[0]
892
947fb5b1915b evolve: active bookmark should move when using prev/next (#37)
Olle Lundberg <geek@nerd.sh>
parents: 891
diff changeset
  1705
        bm = bookmarks.readcurrent(repo)
1160
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1706
        shouldmove = opts.get('move_bookmark') and bm is not None
892
947fb5b1915b evolve: active bookmark should move when using prev/next (#37)
Olle Lundberg <geek@nerd.sh>
parents: 891
diff changeset
  1707
        ret = hg.update(repo, c.rev())
1160
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1708
        if not ret:
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1709
            if shouldmove:
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1710
                repo._bookmarks[bm] = c.node()
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1711
                repo._bookmarks.write()
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1712
            else:
e29a813f6af5 Make next/prev only move bookmarks optionally
Ryan McElroy <rmcelroy@fb.com>
parents: 1157
diff changeset
  1713
                bookmarks.unsetcurrent(repo)
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1714
        displayer.show(c)
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1715
        return 0
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1716
    else:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1717
        for c in children:
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1718
            displayer.show(c)
949
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1719
        ui.warn(_('multiple non-obsolete children, '
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1720
            'explicitly update to one of them\n'))
127
7e113963f2c8 Add gup and gdown command to mimic qpop and qpush command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 119
diff changeset
  1721
        return 1
87
246b8fefd0a5 [evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 82
diff changeset
  1722
715
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1723
def _reachablefrombookmark(repo, revs, mark):
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1724
    """filter revisions and bookmarks reachable from the given bookmark
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1725
    yoinked from mq.py
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1726
    """
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1727
    marks = repo._bookmarks
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1728
    if mark not in marks:
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1729
        raise util.Abort(_("bookmark '%s' not found") % mark)
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1730
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1731
    # If the requested bookmark is not the only one pointing to a
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1732
    # a revision we have to only delete the bookmark and not strip
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1733
    # anything. revsets cannot detect that case.
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1734
    uniquebm = True
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1735
    for m, n in marks.iteritems():
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1736
        if m != mark and n == repo[mark].node():
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1737
            uniquebm = False
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1738
            break
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1739
    if uniquebm:
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1740
        rsrevs = repo.revs("ancestors(bookmark(%s)) - "
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1741
                           "ancestors(head() and not bookmark(%s)) - "
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1742
                           "ancestors(bookmark() and not bookmark(%s)) - "
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1743
                           "obsolete()",
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1744
                           mark, mark, mark)
1135
db16c4ad15d0 fixup previous changesets (after forgot to amend).
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1134
diff changeset
  1745
        revs = set(revs)
715
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1746
        revs.update(set(rsrevs))
1135
db16c4ad15d0 fixup previous changesets (after forgot to amend).
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1134
diff changeset
  1747
        revs = sorted(revs)
db16c4ad15d0 fixup previous changesets (after forgot to amend).
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1134
diff changeset
  1748
    return marks, revs
715
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1749
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1750
def _deletebookmark(ui, marks, mark):
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1751
    del marks[mark]
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1752
    marks.write()
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1753
    ui.write(_("bookmark '%s' deleted\n") % mark)
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1754
716
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1755
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1756
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1757
def _getmetadata(**opts):
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1758
    metadata = {}
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1759
    date = opts.get('date')
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1760
    user = opts.get('user')
818
fcdd9b8c970b prune: accept '0 0' as a valide --date value
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 757
diff changeset
  1761
    if date:
716
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1762
        metadata['date'] = '%i %i' % util.parsedate(date)
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1763
    if user:
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1764
        metadata['user'] = user
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1765
    return metadata
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1766
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1767
365
9f6a77ec66cb evolve: switch the official name for "kill" to prune
Pierre-Yves.David@ens-lyon.org
parents: 362
diff changeset
  1768
@command('^prune|obsolete|kill',
682
6cbb52a8401b prune: rename --new to --succ
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 681
diff changeset
  1769
    [('n', 'new', [], _("successor changeset (DEPRECATED)")),
6cbb52a8401b prune: rename --new to --succ
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 681
diff changeset
  1770
     ('s', 'succ', [], _("successor changeset")),
715
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1771
     ('r', 'rev', [], _("revisions to prune")),
1221
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1772
     ('k', 'keep', None, _("does not modify working copy during prune")),
789
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1773
     ('', 'biject', False, _("do a 1-1 map between rev and successor ranges")),
715
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1774
     ('B', 'bookmark', '', _("remove revs only reachable from given"
716
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1775
                             " bookmark"))] + metadataopts,
644
8e41d5b78dff support -r option in prune, add a test for this
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 636
diff changeset
  1776
    _('[OPTION] [-r] REV...'))
690
929d7617a13d prune: more command switch idea
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 689
diff changeset
  1777
    # -U  --noupdate option to prevent wc update and or bookmarks update ?
681
eff18fcaaddc prune: improve command function name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 680
diff changeset
  1778
def cmdprune(ui, repo, *revs, **opts):
891
36c1c80e99a3 commands: small language fixes in help
Brendan Cully <brendan@kublai.com>
parents: 867
diff changeset
  1779
    """hide changesets by marking them obsolete
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1780
689
d48aae167b9d prune: documentation update
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 688
diff changeset
  1781
    Obsolete changesets becomes invisible to all commands.
d48aae167b9d prune: documentation update
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 688
diff changeset
  1782
891
36c1c80e99a3 commands: small language fixes in help
Brendan Cully <brendan@kublai.com>
parents: 867
diff changeset
  1783
    Unpruned descendants of pruned changesets becomes "unstable". Use the
689
d48aae167b9d prune: documentation update
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 688
diff changeset
  1784
    :hg:`evolve` to handle such situation.
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1785
891
36c1c80e99a3 commands: small language fixes in help
Brendan Cully <brendan@kublai.com>
parents: 867
diff changeset
  1786
    When the working directory parent is pruned, the repository is updated to a
36c1c80e99a3 commands: small language fixes in help
Brendan Cully <brendan@kublai.com>
parents: 867
diff changeset
  1787
    non-obsolete parent.
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1788
891
36c1c80e99a3 commands: small language fixes in help
Brendan Cully <brendan@kublai.com>
parents: 867
diff changeset
  1789
    You can use the ``--succ`` option to inform mercurial that a newer version
689
d48aae167b9d prune: documentation update
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 688
diff changeset
  1790
    of the pruned changeset exists.
789
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1791
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1792
    You can use the ``--biject`` option to specify a 1-1 (bijection) between
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1793
    revisions to prune and successor changesets. This option may be removed in
891
36c1c80e99a3 commands: small language fixes in help
Brendan Cully <brendan@kublai.com>
parents: 867
diff changeset
  1794
    a future release (with the functionality absorbed automatically).
789
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1795
715
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1796
    """
1134
7173c70ab2c3 prune: stop reinjecting all selected revisions back into the revrange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1132
diff changeset
  1797
    revs = scmutil.revrange(repo, list(revs) + opts.get('rev'))
715
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1798
    succs = opts['new'] + opts['succ']
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1799
    bookmark = opts.get('bookmark')
716
4c0f6d555032 prune: add --user and --date options
Levi Bard <levi@unity3d.com>
parents: 715
diff changeset
  1800
    metadata = _getmetadata(**opts)
789
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1801
    biject = opts.get('biject')
689
d48aae167b9d prune: documentation update
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 688
diff changeset
  1802
715
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1803
    if bookmark:
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1804
        marks,revs = _reachablefrombookmark(repo, revs, bookmark)
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1805
        if not revs:
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1806
            # no revisions to prune - delete bookmark immediately
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1807
            _deletebookmark(ui, marks, bookmark)
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1808
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1809
    if not revs:
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1810
        raise util.Abort(_('nothing to prune'))
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1811
1295
1ac05eef72ca prune: prune fix transaction pattern
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1294
diff changeset
  1812
    wlock = lock = tr = None
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1813
    try:
1019
0c733dab0036 prune: lock inside the try
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1018
diff changeset
  1814
        wlock = repo.wlock()
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
  1815
        lock = repo.lock()
1294
d1c29db2e055 prune: fix pruning w/ bookmarks and inhibit
Durham Goode <durham@fb.com>
parents: 1283
diff changeset
  1816
        tr = repo.transaction('prune')
691
6e63b4185a5c prune: update inline documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 690
diff changeset
  1817
        # defines pruned changesets
684
19a1a8f93c07 prune: detect bad input
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 683
diff changeset
  1818
        precs = []
1134
7173c70ab2c3 prune: stop reinjecting all selected revisions back into the revrange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1132
diff changeset
  1819
        revs.sort()
7173c70ab2c3 prune: stop reinjecting all selected revisions back into the revrange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1132
diff changeset
  1820
        for p in revs:
684
19a1a8f93c07 prune: detect bad input
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 683
diff changeset
  1821
            cp = repo[p]
687
6c1fbef2952e prune: test and improve message of immutable aborting.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 685
diff changeset
  1822
            if not cp.mutable():
927
154510dc4318 evolve: fix grammar in a comment
Greg Ward <greg@gerg.ca>
parents: 925
diff changeset
  1823
                # note: createmarkers() would have raised something anyway
687
6c1fbef2952e prune: test and improve message of immutable aborting.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 685
diff changeset
  1824
                raise util.Abort('cannot prune immutable changeset: %s' % cp,
6c1fbef2952e prune: test and improve message of immutable aborting.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 685
diff changeset
  1825
                                 hint='see "hg help phases" for details')
684
19a1a8f93c07 prune: detect bad input
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 683
diff changeset
  1826
            precs.append(cp)
19a1a8f93c07 prune: detect bad input
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 683
diff changeset
  1827
        if not precs:
683
6d24bd455f79 simplify locking in prune
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 682
diff changeset
  1828
            raise util.Abort('nothing to prune')
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1829
691
6e63b4185a5c prune: update inline documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 690
diff changeset
  1830
        # defines successors changesets
1135
db16c4ad15d0 fixup previous changesets (after forgot to amend).
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1134
diff changeset
  1831
        sucs = scmutil.revrange(repo, succs)
db16c4ad15d0 fixup previous changesets (after forgot to amend).
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1134
diff changeset
  1832
        sucs.sort()
db16c4ad15d0 fixup previous changesets (after forgot to amend).
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1134
diff changeset
  1833
        sucs = tuple(repo[n] for n in sucs)
789
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1834
        if not biject and len(sucs) > 1 and len(precs) > 1:
684
19a1a8f93c07 prune: detect bad input
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 683
diff changeset
  1835
            msg = "Can't use multiple successors for multiple precursors"
19a1a8f93c07 prune: detect bad input
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 683
diff changeset
  1836
            raise util.Abort(msg)
789
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1837
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1838
        if biject and len(sucs) != len(precs):
949
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1839
            msg = "Can't use %d successors for %d precursors" \
2b2a4ab0eb68 evolve: make most line lenghts 80 characters or less
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 948
diff changeset
  1840
                % (len(sucs), len(precs))
789
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1841
            raise util.Abort(msg)
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1842
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1843
        relations = [(p, sucs) for p in precs]
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1844
        if biject:
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1845
            relations = [(p, (s,)) for p, s in zip(precs, sucs)]
0d2bb0282e78 prune: add biject option
Sean Farley <sean.michael.farley@gmail.com>
parents: 788
diff changeset
  1846
683
6d24bd455f79 simplify locking in prune
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 682
diff changeset
  1847
        wdp = repo['.']
931
32915143d448 prune: update to successor rather than parent when prune '.'
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 930
diff changeset
  1848
32915143d448 prune: update to successor rather than parent when prune '.'
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 930
diff changeset
  1849
        if len(sucs) == 1 and len(precs) == 1 and wdp in precs:
32915143d448 prune: update to successor rather than parent when prune '.'
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 930
diff changeset
  1850
            # '.' killed, so update to the successor
32915143d448 prune: update to successor rather than parent when prune '.'
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 930
diff changeset
  1851
            newnode = sucs[0]
32915143d448 prune: update to successor rather than parent when prune '.'
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 930
diff changeset
  1852
        else:
32915143d448 prune: update to successor rather than parent when prune '.'
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 930
diff changeset
  1853
            # update to an unkilled parent
32915143d448 prune: update to successor rather than parent when prune '.'
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 930
diff changeset
  1854
            newnode = wdp
32915143d448 prune: update to successor rather than parent when prune '.'
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 930
diff changeset
  1855
1239
8a06b32061ce evolve: apply prune update before creating obsolescence markers
Laurent Charignon <lcharignon@fb.com>
parents: 1235
diff changeset
  1856
            while newnode in precs or newnode.obsolete():
931
32915143d448 prune: update to successor rather than parent when prune '.'
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 930
diff changeset
  1857
                newnode = newnode.parents()[0]
32915143d448 prune: update to successor rather than parent when prune '.'
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 930
diff changeset
  1858
1239
8a06b32061ce evolve: apply prune update before creating obsolescence markers
Laurent Charignon <lcharignon@fb.com>
parents: 1235
diff changeset
  1859
683
6d24bd455f79 simplify locking in prune
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 682
diff changeset
  1860
        if newnode.node() != wdp.node():
1221
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1861
            if opts.get('keep', False):
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1862
                # This is largely the same as the implementation in
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1863
                # strip.stripcmd(). We might want to refactor this somewhere
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1864
                # common at some point.
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1865
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1866
                # only reset the dirstate for files that would actually change
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1867
                # between the working context and uctx
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1868
                descendantrevs = repo.revs("%d::." % newnode.rev())
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1869
                changedfiles = []
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1870
                for rev in descendantrevs:
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1871
                    # blindly reset the files, regardless of what actually changed
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1872
                    changedfiles.extend(repo[rev].files())
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1873
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1874
                # reset files that only changed in the dirstate too
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1875
                dirstate = repo.dirstate
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1876
                dirchanges = [f for f in dirstate if dirstate[f] != 'n']
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1877
                changedfiles.extend(dirchanges)
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1878
                repo.dirstate.rebuild(newnode.node(), newnode.manifest(), changedfiles)
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1879
                repo.dirstate.write()
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1880
            else:
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1881
                commands.update(ui, repo, newnode.rev())
524dbc8ffeac prune: add --keep to not touch the working copy
Durham Goode <durham@fb.com>
parents: 1220
diff changeset
  1882
                ui.status(_('working directory now at %s\n') % newnode)
715
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1883
        # update bookmarks
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1884
        if bookmark:
070bbbb0e6f2 prune: add strip-like bookmark
Levi Bard <levi@unity3d.com>
parents: 714
diff changeset
  1885
            _deletebookmark(ui, marks, bookmark)
1239
8a06b32061ce evolve: apply prune update before creating obsolescence markers
Laurent Charignon <lcharignon@fb.com>
parents: 1235
diff changeset
  1886
8a06b32061ce evolve: apply prune update before creating obsolescence markers
Laurent Charignon <lcharignon@fb.com>
parents: 1235
diff changeset
  1887
        # create markers
8a06b32061ce evolve: apply prune update before creating obsolescence markers
Laurent Charignon <lcharignon@fb.com>
parents: 1235
diff changeset
  1888
        obsolete.createmarkers(repo, relations, metadata=metadata)
8a06b32061ce evolve: apply prune update before creating obsolescence markers
Laurent Charignon <lcharignon@fb.com>
parents: 1235
diff changeset
  1889
        
8a06b32061ce evolve: apply prune update before creating obsolescence markers
Laurent Charignon <lcharignon@fb.com>
parents: 1235
diff changeset
  1890
        # informs that changeset have been pruned
8a06b32061ce evolve: apply prune update before creating obsolescence markers
Laurent Charignon <lcharignon@fb.com>
parents: 1235
diff changeset
  1891
        ui.status(_('%i changesets pruned\n') % len(precs))
8a06b32061ce evolve: apply prune update before creating obsolescence markers
Laurent Charignon <lcharignon@fb.com>
parents: 1235
diff changeset
  1892
693
d3c1fe0035d1 prune: handle bookmark
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 691
diff changeset
  1893
        for ctx in repo.unfiltered().set('bookmark() and %ld', precs):
1101
8cac667a0d7d prune: work around lazy revset slowdown
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1099
diff changeset
  1894
            # used to be:
8cac667a0d7d prune: work around lazy revset slowdown
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1099
diff changeset
  1895
            #
8cac667a0d7d prune: work around lazy revset slowdown
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1099
diff changeset
  1896
            #   ldest = list(repo.set('max((::%d) - obsolete())', ctx))
8cac667a0d7d prune: work around lazy revset slowdown
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1099
diff changeset
  1897
            #   if ldest:
8cac667a0d7d prune: work around lazy revset slowdown
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1099
diff changeset
  1898
            #      c = ldest[0]
8cac667a0d7d prune: work around lazy revset slowdown
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1099
diff changeset
  1899
            #
8cac667a0d7d prune: work around lazy revset slowdown
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1099
diff changeset
  1900
            # but then revset took a lazy arrow in the knee and became much
8cac667a0d7d prune: work around lazy revset slowdown
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1099
diff changeset
  1901
            # slower. The new forms makes as much sense and a much faster.
8cac667a0d7d prune: work around lazy revset slowdown
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1099
diff changeset
  1902
            for dest in ctx.ancestors():
8cac667a0d7d prune: work around lazy revset slowdown
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1099
diff changeset
  1903
                if not dest.obsolete():
8cac667a0d7d prune: work around lazy revset slowdown
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1099
diff changeset
  1904
                    updatebookmarks = _bookmarksupdater(repo, ctx.node())
8cac667a0d7d prune: work around lazy revset slowdown
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1099
diff changeset
  1905
                    updatebookmarks(dest.node())
8cac667a0d7d prune: work around lazy revset slowdown
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1099
diff changeset
  1906
                    break
1294
d1c29db2e055 prune: fix pruning w/ bookmarks and inhibit
Durham Goode <durham@fb.com>
parents: 1283
diff changeset
  1907
d1c29db2e055 prune: fix pruning w/ bookmarks and inhibit
Durham Goode <durham@fb.com>
parents: 1283
diff changeset
  1908
        tr.close()
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1909
    finally:
1295
1ac05eef72ca prune: prune fix transaction pattern
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1294
diff changeset
  1910
        lockmod.release(tr, lock, wlock)
81
5cec25ce019c Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
  1911
673
761b5b266985 evolve: removes amend from the list of advertised function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 672
diff changeset
  1912
@command('amend|refresh',
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1913
    [('A', 'addremove', None,
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1914
     _('mark new/missing files as added/removed before committing')),
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  1915
    ('e', 'edit', False, _('invoke editor on commit messages')),
742
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1916
    ('', 'close-branch', None,
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1917
     _('mark a branch as closed, hiding it from the branch list')),
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1918
    ('s', 'secret', None, _('use the secret phase for committing')),
1296
23819e1d61fd evolve: add -i flag to amend command
Laurent Charignon <lcharignon@fb.com>
parents: 1281
diff changeset
  1919
    ] + walkopts + commitopts + commitopts2 + commitopts3 + interactiveopt,
82
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1920
    _('[OPTION]... [FILE]...'))
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1921
def amend(ui, repo, *pats, **opts):
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1922
    """combine a changeset with updates and replace it with a new one
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1923
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1924
    Commits a new changeset incorporating both the changes to the given files
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1925
    and all the changes from the current parent changeset into the repository.
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1926
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1927
    See :hg:`commit` for details about committing changes.
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1928
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1929
    If you don't specify -m, the parent's message will be reused.
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1930
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1931
    Behind the scenes, Mercurial first commits the update as a regular child
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1932
    of the current parent. Then it creates a new commit on the parent's parents
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1933
    with the updated contents. Then it changes the working copy parent to this
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1934
    new combined changeset. Finally, the old changeset and its update are hidden
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1935
    from :hg:`log` (unless you use --hidden with log).
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1936
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1937
    Returns 0 on success, 1 if nothing changed.
8108d566a8b5 [evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 81
diff changeset
  1938
    """
742
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1939
    opts = opts.copy()
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1940
    edit = opts.pop('edit', False)
1140
b7d85cd8ec7b amend: allow the --logfile argument to work properly
Matt Harbison <matt_harbison@yahoo.com>
parents: 1137
diff changeset
  1941
    log = opts.get('logfile')
742
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1942
    opts['amend'] = True
1140
b7d85cd8ec7b amend: allow the --logfile argument to work properly
Matt Harbison <matt_harbison@yahoo.com>
parents: 1137
diff changeset
  1943
    if not (edit or opts['message'] or log):
742
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1944
        opts['message'] = repo['.'].description()
985
6a37044ec0b3 amend: add -U/--current-user option (inspired by mq)
Greg Ward <greg@gerg.ca>
parents: 983
diff changeset
  1945
    _resolveoptions(ui, opts)
742
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1946
    _alias, commitcmd = cmdutil.findcmd('commit', commands.table)
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  1947
    return commitcmd[0](ui, repo, *pats, **opts)
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
  1948
1058
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1949
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1950
def _touchedbetween(repo, source, dest, match=None):
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1951
    touched = set()
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1952
    for files in repo.status(source, dest, match=match)[:3]:
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1953
        touched.update(files)
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1954
    return touched
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1955
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1956
def _commitfiltered(repo, ctx, match, target=None):
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1957
    """Recommit ctx with changed files not in match. Return the new
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1958
    node identifier, or None if nothing changed.
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1959
    """
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1960
    base = ctx.p1()
1058
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1961
    if target is None:
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1962
        target = base
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1963
    # ctx
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1964
    initialfiles = _touchedbetween(repo, base, ctx)
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1965
    if base == target:
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1966
        affected = set(f for f in initialfiles if match(f))
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1967
        newcontent = set()
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1968
    else:
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1969
        affected = _touchedbetween(repo, target, ctx, match=match)
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1970
        newcontent = _touchedbetween(repo, target, base, match=match)
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1971
    # The commit touchs all existing files
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1972
    # + all file that needs a new content
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1973
    # - the file affected bny uncommit with the same content than base.
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1974
    files = (initialfiles - affected) | newcontent
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1975
    if not newcontent and files == initialfiles:
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1976
        return None
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1977
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1978
    # Filter copies
1058
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1979
    copied = copies.pathcopies(target, ctx)
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1980
    copied = dict((src, dst) for src, dst in copied.iteritems()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1981
                  if dst in files)
1058
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1982
    def filectxfn(repo, memctx, path, contentctx=ctx, redirect=newcontent):
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1983
        if path in redirect:
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1984
            return filectxfn(repo, memctx, path, contentctx=target, redirect=())
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1985
        if path not in contentctx:
1086
96b9e0c31cc1 compat: adapt to change to memctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1085
diff changeset
  1986
            return None
1058
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  1987
        fctx = contentctx[path]
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1988
        flags = fctx.flags()
955
72670e282460 evolve: compatibility with memfilectx change
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 954
diff changeset
  1989
        mctx = memfilectx(repo, fctx.path(), fctx.data(),
954
ef155e3ead8f evolve: abstract access to context.memfilectx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 953
diff changeset
  1990
                          islink='l' in flags,
ef155e3ead8f evolve: abstract access to context.memfilectx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 953
diff changeset
  1991
                          isexec='x' in flags,
ef155e3ead8f evolve: abstract access to context.memfilectx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 953
diff changeset
  1992
                          copied=copied.get(path))
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1993
        return mctx
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1994
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1995
    new = context.memctx(repo,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1996
                         parents=[base.node(), node.nullid],
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1997
                         text=ctx.description(),
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1998
                         files=files,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  1999
                         filectxfn=filectxfn,
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2000
                         user=ctx.user(),
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2001
                         date=ctx.date(),
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2002
                         extra=ctx.extra())
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2003
    # commitctx always create a new revision, no need to check
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2004
    newid = repo.commitctx(new)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2005
    return newid
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2006
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2007
def _uncommitdirstate(repo, oldctx, match):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2008
    """Fix the dirstate after switching the working directory from
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2009
    oldctx to a copy of oldctx not containing changed files matched by
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2010
    match.
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2011
    """
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2012
    ctx = repo['.']
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2013
    ds = repo.dirstate
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2014
    copies = dict(ds.copies())
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2015
    m, a, r = repo.status(oldctx.p1(), oldctx, match=match)[:3]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2016
    for f in m:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2017
        if ds[f] == 'r':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2018
            # modified + removed -> removed
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2019
            continue
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2020
        ds.normallookup(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2021
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2022
    for f in a:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2023
        if ds[f] == 'r':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2024
            # added + removed -> unknown
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2025
            ds.drop(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2026
        elif ds[f] != 'a':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2027
            ds.add(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2028
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2029
    for f in r:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2030
        if ds[f] == 'a':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2031
            # removed + added -> normal
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2032
            ds.normallookup(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2033
        elif ds[f] != 'r':
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2034
            ds.remove(f)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2035
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2036
    # Merge old parent and old working dir copies
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2037
    oldcopies = {}
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2038
    for f in (m + a):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2039
        src = oldctx[f].renamed()
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2040
        if src:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2041
            oldcopies[f] = src[0]
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2042
    oldcopies.update(copies)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2043
    copies = dict((dst, oldcopies.get(src, src))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2044
                  for dst, src in oldcopies.iteritems())
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2045
    # Adjust the dirstate copies
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2046
    for dst, src in copies.iteritems():
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2047
        if (src not in ctx or dst in ctx or ds[dst] != 'a'):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2048
            src = None
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2049
        ds.copy(src, dst)
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2050
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2051
@command('^uncommit',
314
ebd286f06879 uncommit: add --all option
Patrick Mezard <patrick@mezard.eu>
parents: 313
diff changeset
  2052
    [('a', 'all', None, _('uncommit all changes when no arguments given')),
1058
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  2053
     ('r', 'rev', '', _('revert commit content to REV instead')),
314
ebd286f06879 uncommit: add --all option
Patrick Mezard <patrick@mezard.eu>
parents: 313
diff changeset
  2054
     ] + commands.walkopts,
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2055
    _('[OPTION]... [NAME]'))
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2056
def uncommit(ui, repo, *pats, **opts):
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2057
    """move changes from parent revision to working directory
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2058
891
36c1c80e99a3 commands: small language fixes in help
Brendan Cully <brendan@kublai.com>
parents: 867
diff changeset
  2059
    Changes to selected files in the checked out revision appear again as
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2060
    uncommitted changed in the working directory. A new revision
891
36c1c80e99a3 commands: small language fixes in help
Brendan Cully <brendan@kublai.com>
parents: 867
diff changeset
  2061
    without the selected changes is created, becomes the checked out
36c1c80e99a3 commands: small language fixes in help
Brendan Cully <brendan@kublai.com>
parents: 867
diff changeset
  2062
    revision, and obsoletes the previous one.
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2063
867
6a67606e1c34 evolve: fix typos in uncommit docstring
André Sintzoff <andre.sintzoff@gmail.com>
parents: 858
diff changeset
  2064
    The --include option specifies patterns to uncommit.
6a67606e1c34 evolve: fix typos in uncommit docstring
André Sintzoff <andre.sintzoff@gmail.com>
parents: 858
diff changeset
  2065
    The --exclude option specifies patterns to keep in the commit.
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2066
1058
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  2067
    The --rev argument let you change the commit file to a content of another
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  2068
    revision. It still does not change the content of your file in the working
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  2069
    directory.
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  2070
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2071
    Return 0 if changed files are uncommitted.
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2072
    """
1020
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2073
1022
6f4fd3e49d1c uncommit tr
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1021
diff changeset
  2074
    wlock = lock = tr = None
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2075
    try:
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2076
        wlock = repo.wlock()
1020
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2077
        lock = repo.lock()
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2078
        wctx = repo[None]
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2079
        if len(wctx.parents()) <= 0:
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2080
            raise util.Abort(_("cannot uncommit null changeset"))
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2081
        if len(wctx.parents()) > 1:
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2082
            raise util.Abort(_("cannot uncommit while merging"))
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2083
        old = repo['.']
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2084
        if old.phase() == phases.public:
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2085
            raise util.Abort(_("cannot rewrite immutable changeset"))
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2086
        if len(old.parents()) > 1:
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2087
            raise util.Abort(_("cannot uncommit merge changeset"))
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2088
        oldphase = old.phase()
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2089
        updatebookmarks = _bookmarksupdater(repo, old.node())
1022
6f4fd3e49d1c uncommit tr
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1021
diff changeset
  2090
1058
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  2091
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  2092
        rev = None
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  2093
        if opts.get('rev'):
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  2094
            rev = scmutil.revsingle(repo, opts.get('rev'))
1143
160fd06312fc uncommit: abort when rev specifies the current changeset
Nathan Goldbaum <ngoldbau@ucsc.edu>
parents: 1141
diff changeset
  2095
            ctx = repo[None]
160fd06312fc uncommit: abort when rev specifies the current changeset
Nathan Goldbaum <ngoldbau@ucsc.edu>
parents: 1141
diff changeset
  2096
            if ctx.p1() == rev or ctx.p2() == rev:
160fd06312fc uncommit: abort when rev specifies the current changeset
Nathan Goldbaum <ngoldbau@ucsc.edu>
parents: 1141
diff changeset
  2097
                raise util.Abort(_("cannot uncommit to parent changeset"))
1058
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  2098
1020
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2099
        # Recommit the filtered changeset
1022
6f4fd3e49d1c uncommit tr
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1021
diff changeset
  2100
        tr = repo.transaction('uncommit')
1020
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2101
        newid = None
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2102
        if (pats or opts.get('include') or opts.get('exclude')
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2103
            or opts.get('all')):
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2104
            match = scmutil.match(old, pats, opts)
1058
00bc31523074 uncommit: add a --rev argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1055
diff changeset
  2105
            newid = _commitfiltered(repo, old, match, target=rev)
1020
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2106
        if newid is None:
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2107
            raise util.Abort(_('nothing to uncommit'),
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2108
                             hint=_("use --all to uncommit all files"))
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2109
        # Move local changes on filtered changeset
1070
527b12a59628 drop relevant marker compat
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1069
diff changeset
  2110
        obsolete.createmarkers(repo, [(old, (repo[newid],))])
1069
356552e55489 evolve: always use the transaction version of phase movement
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1068
diff changeset
  2111
        phases.retractboundary(repo, tr, oldphase, [newid])
1112
c3e23fbf7bd7 evolve: wrap setparents calls in begin/endparentchange
Siddharth Agarwal <sid0@fb.com>
parents: 1111
diff changeset
  2112
        repo.dirstate.beginparentchange()
1020
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2113
        repo.dirstate.setparents(newid, node.nullid)
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2114
        _uncommitdirstate(repo, old, match)
1112
c3e23fbf7bd7 evolve: wrap setparents calls in begin/endparentchange
Siddharth Agarwal <sid0@fb.com>
parents: 1111
diff changeset
  2115
        repo.dirstate.endparentchange()
1020
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2116
        updatebookmarks(newid)
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2117
        if not repo[newid].files():
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2118
            ui.warn(_("new changeset is empty\n"))
155949287628 uncommit: saner locking scheme
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1019
diff changeset
  2119
            ui.status(_('(use "hg prune ." to remove it)\n'))
1022
6f4fd3e49d1c uncommit tr
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1021
diff changeset
  2120
        tr.close()
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2121
    finally:
1022
6f4fd3e49d1c uncommit tr
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1021
diff changeset
  2122
        lockmod.release(tr, lock, wlock)
312
a7b5989d1d92 evolve: add uncommit command
Patrick Mezard <patrick@mezard.eu>
parents: 309
diff changeset
  2123
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  2124
@eh.wrapcommand('commit')
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
  2125
def commitwrapper(orig, ui, repo, *arg, **kwargs):
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  2126
    if kwargs.get('amend', False):
1255
a2d4901e211e commit: avoid potential deadlock
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1253
diff changeset
  2127
        wlock = lock = None
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  2128
    else:
1255
a2d4901e211e commit: avoid potential deadlock
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1253
diff changeset
  2129
        wlock = repo.wlock()
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  2130
        lock = repo.lock()
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  2131
    try:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  2132
        obsoleted = kwargs.get('obsolete', [])
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  2133
        if obsoleted:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  2134
            obsoleted = repo.set('%lr', obsoleted)
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  2135
        result = orig(ui, repo, *arg, **kwargs)
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  2136
        if not result: # commit successed
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  2137
            new = repo['-1']
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  2138
            oldbookmarks = []
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
  2139
            markers = []
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  2140
            for old in obsoleted:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  2141
                oldbookmarks.extend(repo.nodebookmarks(old.node()))
444
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
  2142
                markers.append((old, (new,)))
aedb6b8ace86 drop repo.addobsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 443
diff changeset
  2143
            if markers:
1070
527b12a59628 drop relevant marker compat
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1069
diff changeset
  2144
                obsolete.createmarkers(repo, markers)
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  2145
            for book in oldbookmarks:
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  2146
                repo._bookmarks[book] = new.node()
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  2147
            if oldbookmarks:
612
15299bfd0813 adapt to 7f5dab94e48c in crew
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 604
diff changeset
  2148
                repo._bookmarks.write()
137
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  2149
        return result
bbc653876876 fix evolve test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 133
diff changeset
  2150
    finally:
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  2151
        if lock is not None:
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  2152
            lock.release()
1255
a2d4901e211e commit: avoid potential deadlock
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1253
diff changeset
  2153
        if wlock is not None:
a2d4901e211e commit: avoid potential deadlock
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1253
diff changeset
  2154
            wlock.release()
116
64ca29eef349 Add a -o option to commit
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 113
diff changeset
  2155
1220
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2156
@eh.wrapcommand('strip', extension='strip', opts=[
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2157
    ('', 'bundle', None, _("delete the commit entirely and move it to a "
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2158
        "backup bundle")),
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2159
    ])
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2160
def stripwrapper(orig, ui, repo, *revs, **kwargs):
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2161
    if (not ui.configbool('experimental', 'prunestrip') or
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2162
        kwargs.get('bundle', False)):
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2163
        return orig(ui, repo, *revs, **kwargs)
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2164
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2165
    if kwargs.get('force'):
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2166
        ui.warn(_("warning: --force has no effect during strip with evolve "
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2167
                  "enabled\n"))
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2168
    if kwargs.get('no_backup', False):
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2169
        ui.warn(_("warning: --no-backup has no effect during strips with "
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2170
                  "evolve enabled\n"))
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2171
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2172
    revs = list(revs) + kwargs.pop('rev', [])
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2173
    revs = set(scmutil.revrange(repo, revs))
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2174
    revs = repo.revs("(%ld)::", revs)
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2175
    kwargs['rev'] = []
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2176
    kwargs['new'] = []
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2177
    kwargs['succ'] = []
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2178
    kwargs['biject'] = False
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2179
    return cmdprune(ui, repo, *revs, **kwargs)
71240f696f26 strip: add the option for wrapping the strip command
Durham Goode <durham@fb.com>
parents: 1219
diff changeset
  2180
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2181
@command('^touch',
701
f752089479ce add a duplicate option in touch
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 699
diff changeset
  2182
    [('r', 'rev', [], 'revision to update'),
f752089479ce add a duplicate option in touch
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 699
diff changeset
  2183
     ('D', 'duplicate', False,
f752089479ce add a duplicate option in touch
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 699
diff changeset
  2184
      'do not mark the new revision as successor of the old one')],
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2185
    # allow to choose the seed ?
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2186
    _('[-r] revs'))
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2187
def touch(ui, repo, *revs, **opts):
1168
2187f7c88ff6 evolve: fix capitalization in docstring for commands
André Sintzoff <andre.sintzoff@gmail.com>
parents: 1163
diff changeset
  2188
    """create successors that are identical to their predecessors except for the changeset ID
517
0bc0c9edcb15 evolve: usual syntax/grammar errors/long lines cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 516
diff changeset
  2189
0bc0c9edcb15 evolve: usual syntax/grammar errors/long lines cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 516
diff changeset
  2190
    This is used to "resurrect" changesets
0bc0c9edcb15 evolve: usual syntax/grammar errors/long lines cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 516
diff changeset
  2191
    """
701
f752089479ce add a duplicate option in touch
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 699
diff changeset
  2192
    duplicate = opts['duplicate']
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2193
    revs = list(revs)
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2194
    revs.extend(opts['rev'])
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2195
    if not revs:
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2196
        revs = ['.']
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2197
    revs = scmutil.revrange(repo, revs)
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2198
    if not revs:
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2199
        ui.write_err('no revision to touch\n')
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2200
        return 1
701
f752089479ce add a duplicate option in touch
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 699
diff changeset
  2201
    if not duplicate and repo.revs('public() and %ld', revs):
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2202
        raise util.Abort("can't touch public revision")
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  2203
    wlock = lock = None
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2204
    try:
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  2205
        wlock = repo.wlock()
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2206
        lock = repo.lock()
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  2207
        tr = repo.transaction('touch')
702
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  2208
        revs.sort() # ensure parent are run first
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  2209
        newmapping = {}
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2210
        try:
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  2211
            for r in revs:
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  2212
                ctx = repo[r]
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  2213
                extra = ctx.extra().copy()
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  2214
                extra['__touch-noise__'] = random.randint(0, 0xffffffff)
702
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  2215
                # search for touched parent
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  2216
                p1 = ctx.p1().node()
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  2217
                p2 = ctx.p2().node()
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  2218
                p1 = newmapping.get(p1, p1)
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  2219
                p2 = newmapping.get(p2, p2)
993
8a4a8fe50c26 evolve: do not use _ as an unused variable
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 988
diff changeset
  2220
                new, unusedvariable = rewrite(repo, ctx, [], ctx,
8a4a8fe50c26 evolve: do not use _ as an unused variable
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 988
diff changeset
  2221
                                              [p1, p2],
8a4a8fe50c26 evolve: do not use _ as an unused variable
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 988
diff changeset
  2222
                                              commitopts={'extra': extra})
702
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  2223
                # store touched version to help potential children
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  2224
                newmapping[ctx.node()] = new
701
f752089479ce add a duplicate option in touch
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 699
diff changeset
  2225
                if not duplicate:
1070
527b12a59628 drop relevant marker compat
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1069
diff changeset
  2226
                    obsolete.createmarkers(repo, [(ctx, (repo[new],))])
1069
356552e55489 evolve: always use the transaction version of phase movement
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1068
diff changeset
  2227
                phases.retractboundary(repo, tr, ctx.phase(), [new])
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  2228
                if ctx in repo[None].parents():
1112
c3e23fbf7bd7 evolve: wrap setparents calls in begin/endparentchange
Siddharth Agarwal <sid0@fb.com>
parents: 1111
diff changeset
  2229
                    repo.dirstate.beginparentchange()
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  2230
                    repo.dirstate.setparents(new, node.nullid)
1112
c3e23fbf7bd7 evolve: wrap setparents calls in begin/endparentchange
Siddharth Agarwal <sid0@fb.com>
parents: 1111
diff changeset
  2231
                    repo.dirstate.endparentchange()
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  2232
            tr.close()
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2233
        finally:
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  2234
            tr.release()
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2235
    finally:
514
ea667749ccd1 touch: simplify locking pattern
Patrick Mezard <patrick@mezard.eu>
parents: 513
diff changeset
  2236
        lockmod.release(lock, wlock)
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2237
934
f13facb01ac5 fold: add squash as a possible alias
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 933
diff changeset
  2238
@command('^fold|squash',
996
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2239
    [('r', 'rev', [], _("revision to fold")),
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2240
     ('', 'exact', None, _("only fold specified revisions"))
933
e5baeb8fefec fold: add --message and --logfile options
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 931
diff changeset
  2241
    ] + commitopts + commitopts2,
996
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2242
    _('hg fold [OPTION]... [-r] REV'))
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2243
def fold(ui, repo, *revs, **opts):
996
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2244
    """fold multiple revisions into a single one
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2245
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2246
    Folds a set of revisions with the parent of the working directory.
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2247
    All revisions linearly between the given revisions and the parent
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2248
    of the working directory will also be folded.
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2249
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2250
    Use --exact for folding only the specified revisions while ignoring the
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2251
    parent of the working directory. In this case, the given revisions must
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2252
    form a linear unbroken chain.
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2253
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2254
    .. container:: verbose
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2255
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2256
     Some examples:
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2257
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2258
     - Fold the current revision with its parent::
702
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  2259
996
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2260
         hg fold .^
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2261
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2262
     - Fold all draft revisions with working directory parent::
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2263
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2264
         hg fold 'draft()'
702
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  2265
996
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2266
       See :hg:`help phases` for more about draft revisions and
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2267
       :hg:`help revsets` for more about the `draft()` keyword
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2268
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2269
     - Fold revisions 3, 4, 5, and 6 with the working directory parent::
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2270
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2271
         hg fold 3:6
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2272
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2273
     - Only fold revisions linearly between foo and @::
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2274
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2275
         hg fold foo::@ --exact
702
b5a85a8909d3 touch: properly handle touching multiple changeset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 701
diff changeset
  2276
    """
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2277
    revs = list(revs)
996
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2278
    revs.extend(opts['rev'])
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2279
    if not revs:
994
debf44fa91a2 fold: clarify message for empty revision set and abort instead (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 993
diff changeset
  2280
        raise util.Abort(_('no revisions specified'))
995
0f3a7efd6ee9 fold: emit error message when folding a single revision
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 994
diff changeset
  2281
996
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2282
    revs = scmutil.revrange(repo, revs)
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2283
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2284
    if not opts['exact']:
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2285
        # Try to extend given revision starting from the working directory
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2286
        extrevs = repo.revs('(%ld::.) or (.::%ld)', revs, revs)
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2287
        discardedrevs = [r for r in revs if r not in extrevs]
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2288
        if discardedrevs:
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2289
            raise util.Abort(_("cannot fold non-linear revisions"),
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2290
                               hint=_("given revisions are unrelated to parent "
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2291
                                      "of working directory"))
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2292
        revs = extrevs
b98dd5d3065c fold: overhaul handling of revisions with --rev (BC)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 995
diff changeset
  2293
995
0f3a7efd6ee9 fold: emit error message when folding a single revision
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 994
diff changeset
  2294
    if len(revs) == 1:
0f3a7efd6ee9 fold: emit error message when folding a single revision
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 994
diff changeset
  2295
        ui.write_err(_('single revision specified, nothing to fold\n'))
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2296
        return 1
995
0f3a7efd6ee9 fold: emit error message when folding a single revision
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 994
diff changeset
  2297
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2298
    roots = repo.revs('roots(%ld)', revs)
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2299
    if len(roots) > 1:
998
85ec2a55fe7c fold: improve error messages for multiple heads and roots
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 997
diff changeset
  2300
        raise util.Abort(_("cannot fold non-linear revisions "
85ec2a55fe7c fold: improve error messages for multiple heads and roots
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 997
diff changeset
  2301
                           "(multiple roots given)"))
1120
9bc4857f573b evolve: use `first` and `last` on revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1118
diff changeset
  2302
    root = repo[roots.first()]
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2303
    if root.phase() <= phases.public:
997
f48cd2f48d14 fold: reword error message for public commits
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 996
diff changeset
  2304
        raise util.Abort(_("cannot fold public revisions"))
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2305
    heads = repo.revs('heads(%ld)', revs)
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2306
    if len(heads) > 1:
998
85ec2a55fe7c fold: improve error messages for multiple heads and roots
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 997
diff changeset
  2307
        raise util.Abort(_("cannot fold non-linear revisions "
85ec2a55fe7c fold: improve error messages for multiple heads and roots
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 997
diff changeset
  2308
                           "(multiple heads given)"))
1120
9bc4857f573b evolve: use `first` and `last` on revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1118
diff changeset
  2309
    head = repo[heads.first()]
515
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  2310
    wlock = lock = None
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2311
    try:
515
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  2312
        wlock = repo.wlock()
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2313
        lock = repo.lock()
515
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  2314
        tr = repo.transaction('touch')
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2315
        try:
915
1ebe5c51919b fold: enable --date and --user options
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 912
diff changeset
  2316
            commitopts = opts.copy()
515
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  2317
            allctx = [repo[r] for r in revs]
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  2318
            targetphase = max(c.phase() for c in allctx)
933
e5baeb8fefec fold: add --message and --logfile options
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 931
diff changeset
  2319
e5baeb8fefec fold: add --message and --logfile options
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 931
diff changeset
  2320
            if commitopts.get('message') or commitopts.get('logfile'):
e5baeb8fefec fold: add --message and --logfile options
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 931
diff changeset
  2321
                commitopts['edit'] = False
e5baeb8fefec fold: add --message and --logfile options
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 931
diff changeset
  2322
            else:
e5baeb8fefec fold: add --message and --logfile options
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 931
diff changeset
  2323
                msgs = ["HG: This is a fold of %d changesets." % len(allctx)]
e5baeb8fefec fold: add --message and --logfile options
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 931
diff changeset
  2324
                msgs += ["HG: Commit message of changeset %s.\n\n%s\n" %
e5baeb8fefec fold: add --message and --logfile options
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 931
diff changeset
  2325
                         (c.rev(), c.description()) for c in allctx]
e5baeb8fefec fold: add --message and --logfile options
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 931
diff changeset
  2326
                commitopts['message'] =  "\n".join(msgs)
e5baeb8fefec fold: add --message and --logfile options
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 931
diff changeset
  2327
                commitopts['edit'] = True
e5baeb8fefec fold: add --message and --logfile options
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 931
diff changeset
  2328
993
8a4a8fe50c26 evolve: do not use _ as an unused variable
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 988
diff changeset
  2329
            newid, unusedvariable = rewrite(repo, root, allctx, head,
8a4a8fe50c26 evolve: do not use _ as an unused variable
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 988
diff changeset
  2330
                                            [root.p1().node(), root.p2().node()],
8a4a8fe50c26 evolve: do not use _ as an unused variable
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 988
diff changeset
  2331
                                            commitopts=commitopts)
1069
356552e55489 evolve: always use the transaction version of phase movement
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1068
diff changeset
  2332
            phases.retractboundary(repo, tr, targetphase, [newid])
1070
527b12a59628 drop relevant marker compat
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1069
diff changeset
  2333
            obsolete.createmarkers(repo, [(ctx, (repo[newid],))
515
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  2334
                                 for ctx in allctx])
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  2335
            tr.close()
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2336
        finally:
515
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  2337
            tr.release()
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2338
        ui.status('%i changesets folded\n' % len(revs))
632
cb0807646f5a fold: work around potential bug with filtering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 631
diff changeset
  2339
        if repo['.'].rev() in revs:
549
b047e9417d96 Properly update after fold
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 548
diff changeset
  2340
            hg.update(repo, newid)
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2341
    finally:
515
0b60c28d9c43 fold: simplify locking
Patrick Mezard <patrick@mezard.eu>
parents: 514
diff changeset
  2342
        lockmod.release(lock, wlock)
482
d2531a747ff5 evolve: fold command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 481
diff changeset
  2343
587
8152fedbac65 evolve: smarter code for divergent changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 586
diff changeset
  2344
481
4e0f1aae8d24 evolve: touch command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 477
diff changeset
  2345
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  2346
@eh.wrapcommand('graft')
117
438fe133b068 Add a -o and -O option to graft.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 116
diff changeset
  2347
def graftwrapper(orig, ui, repo, *revs, **kwargs):
419
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
  2348
    kwargs = dict(kwargs)
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
  2349
    revs = list(revs) + kwargs.get('rev', [])
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
  2350
    kwargs['rev'] = []
417
a1fb18ad29a1 evolve: avoid duplication in graft wrapper
Patrick Mezard <patrick@mezard.eu>
parents: 416
diff changeset
  2351
    obsoleted = kwargs.setdefault('obsolete', [])
419
03672e955bc8 evolve: make graft wrapper handle --rev
Patrick Mezard <patrick@mezard.eu>
parents: 410
diff changeset
  2352
1256
f8cb01637e75 graft: avoid potential deadlock
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1255
diff changeset
  2353
    wlock = lock = None
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  2354
    try:
1256
f8cb01637e75 graft: avoid potential deadlock
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1255
diff changeset
  2355
        wlock = repo.wlock()
f8cb01637e75 graft: avoid potential deadlock
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1255
diff changeset
  2356
        lock = repo.lock()
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  2357
        if kwargs.get('old_obsolete'):
418
18a0d96ed559 evolve: graft --continue is optional, test
Patrick Mezard <patrick@mezard.eu>
parents: 417
diff changeset
  2358
            if kwargs.get('continue'):
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  2359
                obsoleted.extend(repo.opener.read('graftstate').splitlines())
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  2360
            else:
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  2361
                obsoleted.extend(revs)
151
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
  2362
        # convert obsolete target into revs to avoid alias joke
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
  2363
        obsoleted[:] = [str(i) for i in repo.revs('%lr', obsoleted)]
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
  2364
        if obsoleted and len(revs) > 1:
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
  2365
743
af74a5cdf96b conform to the Mercurial custom of lowercase messages
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 742
diff changeset
  2366
            raise error.Abort(_('cannot graft multiple revisions while '
151
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
  2367
                                'obsoleting (for now).'))
e73944b6be8f evolve: improve graft handling of -O
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 147
diff changeset
  2368
119
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  2369
        return commitwrapper(orig, ui, repo,*revs, **kwargs)
22f2b700bd59 evolution: proper locking scheme
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 118
diff changeset
  2370
    finally:
1256
f8cb01637e75 graft: avoid potential deadlock
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1255
diff changeset
  2371
        lockmod.release(lock, wlock)
117
438fe133b068 Add a -o and -O option to graft.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 116
diff changeset
  2372
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  2373
@eh.extsetup
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  2374
def oldevolveextsetup(ui):
742
760d01a549a6 amend: use core mechanism for amend
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 741
diff changeset
  2375
    for cmd in ['kill', 'uncommit', 'touch', 'fold']:
1226
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
  2376
        try:
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
  2377
            entry = extensions.wrapcommand(cmdtable, cmd,
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
  2378
                                           warnobserrors)
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
  2379
        except error.UnknownCommand:
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
  2380
            # Commands may be disabled
901d2f4b21a9 config: allow disabling commands
Durham Goode <durham@fb.com>
parents: 1221
diff changeset
  2381
            continue
356
56d4c6207ef9 Move obserror warning into the obsolete extension.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 355
diff changeset
  2382
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  2383
    entry = cmdutil.findcmd('commit', commands.table)[1]
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  2384
    entry[1].append(('o', 'obsolete', [],
1008
a010ba5a0ffb evolve: deprecated --obsolete and --old-obsolete option on commit and graft
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1007
diff changeset
  2385
                     _("make commit obsolete this revision (DEPRECATED)")))
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
  2386
    entry = cmdutil.findcmd('graft', commands.table)[1]
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  2387
    entry[1].append(('o', 'obsolete', [],
1008
a010ba5a0ffb evolve: deprecated --obsolete and --old-obsolete option on commit and graft
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1007
diff changeset
  2388
                     _("make graft obsoletes this revision (DEPRECATED)")))
303
8529b4b95f5d evolve: tidy up a bit
Patrick Mezard <patrick@mezard.eu>
parents: 298
diff changeset
  2389
    entry[1].append(('O', 'old-obsolete', False,
1008
a010ba5a0ffb evolve: deprecated --obsolete and --old-obsolete option on commit and graft
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1007
diff changeset
  2390
                     _("make graft obsoletes its source (DEPRECATED)")))
211
69a37d56c7fb evolve: issue the "%i new unstable changeset" in more place
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 196
diff changeset
  2391
816
03587920dfd9 evolve: add relevant marker exchange machinery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 811
diff changeset
  2392
#####################################################################
03587920dfd9 evolve: add relevant marker exchange machinery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 811
diff changeset
  2393
### Obsolescence marker exchange experimenation                   ###
03587920dfd9 evolve: add relevant marker exchange machinery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 811
diff changeset
  2394
#####################################################################
03587920dfd9 evolve: add relevant marker exchange machinery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 811
diff changeset
  2395
1036
70de12b7721a evolve: re-introduce the "pushing 42 markers…" message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1035
diff changeset
  2396
def obsexcmsg(ui, message, important=False):
70de12b7721a evolve: re-introduce the "pushing 42 markers…" message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1035
diff changeset
  2397
    verbose = ui.configbool('experimental', 'verbose-obsolescence-exchange',
70de12b7721a evolve: re-introduce the "pushing 42 markers…" message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1035
diff changeset
  2398
                             False)
70de12b7721a evolve: re-introduce the "pushing 42 markers…" message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1035
diff changeset
  2399
    if verbose:
1035
59bc29c84ce0 evolve: hide the OBSEXC message behind a config option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1034
diff changeset
  2400
        message = 'OBSEXC: ' + message
1036
70de12b7721a evolve: re-introduce the "pushing 42 markers…" message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1035
diff changeset
  2401
    if important or verbose:
1035
59bc29c84ce0 evolve: hide the OBSEXC message behind a config option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1034
diff changeset
  2402
        ui.status(message)
1033
908273755215 evolve: move OBSEXC message in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1032
diff changeset
  2403
1034
5fd28e46e8f5 evolve: move OBSEXC progress in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1033
diff changeset
  2404
def obsexcprg(ui, *args, **kwargs):
1043
6a7d34010f8f evolve: re enable progress for all
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1042
diff changeset
  2405
    topic = 'obsmarkers exchange'
1035
59bc29c84ce0 evolve: hide the OBSEXC message behind a config option
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1034
diff changeset
  2406
    if ui.configbool('experimental', 'verbose-obsolescence-exchange', False):
1043
6a7d34010f8f evolve: re enable progress for all
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1042
diff changeset
  2407
        topic = 'OBSEXC'
6a7d34010f8f evolve: re enable progress for all
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1042
diff changeset
  2408
    ui.progress(topic, *args, **kwargs)
1034
5fd28e46e8f5 evolve: move OBSEXC progress in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1033
diff changeset
  2409
1300
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2410
@eh.wrapfunction(exchange, '_pushdiscoveryobsmarkers')
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2411
def _pushdiscoveryobsmarkers(orig, pushop):
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2412
    if (obsolete.isenabled(pushop.repo, obsolete.exchangeopt)
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2413
        and pushop.repo.obsstore
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2414
        and 'obsolete' in pushop.remote.listkeys('namespaces')):
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2415
        repo = pushop.repo
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2416
        obsexcmsg(repo.ui, "computing relevant nodes\n")
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2417
        revs = list(repo.revs('::%ln', pushop.futureheads))
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2418
        unfi = repo.unfiltered()
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2419
        cl = unfi.changelog
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2420
        if not pushop.remote.capable('_evoext_obshash_0'):
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2421
            # do not trust core yet
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2422
            # return orig(pushop)
1076
2039385d6460 discovery: hook on the official discovery for obsmarker
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1075
diff changeset
  2423
            nodes = [cl.node(r) for r in revs]
1078
5717d023da63 obsexc: use the common discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1077
diff changeset
  2424
            if nodes:
5717d023da63 obsexc: use the common discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1077
diff changeset
  2425
                obsexcmsg(repo.ui, "computing markers relevant to %i nodes\n"
5717d023da63 obsexc: use the common discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1077
diff changeset
  2426
                                   % len(nodes))
5717d023da63 obsexc: use the common discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1077
diff changeset
  2427
                pushop.outobsmarkers = repo.obsstore.relevantmarkers(nodes)
5717d023da63 obsexc: use the common discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1077
diff changeset
  2428
            else:
5717d023da63 obsexc: use the common discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1077
diff changeset
  2429
                obsexcmsg(repo.ui, "markers already in sync\n")
5717d023da63 obsexc: use the common discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1077
diff changeset
  2430
                pushop.outobsmarkers = []
1300
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2431
                pushop.outobsmarkers = repo.obsstore.relevantmarkers(nodes)
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2432
            return
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2433
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2434
        common = []
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2435
        obsexcmsg(repo.ui, "looking for common markers in %i nodes\n"
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2436
                           % len(revs))
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2437
        commonrevs = list(unfi.revs('::%ln', pushop.outgoing.commonheads))
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2438
        common = findcommonobsmarkers(pushop.ui, unfi, pushop.remote, commonrevs)
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2439
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2440
        revs = list(unfi.revs('%ld - (::%ln)', revs, common))
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2441
        nodes = [cl.node(r) for r in revs]
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2442
        if nodes:
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2443
            obsexcmsg(repo.ui, "computing markers relevant to %i nodes\n"
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2444
                               % len(nodes))
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2445
            pushop.outobsmarkers = repo.obsstore.relevantmarkers(nodes)
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2446
        else:
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2447
            obsexcmsg(repo.ui, "markers already in sync\n")
4a27123e0696 evolve: stop conditional wrapping of _pushdiscoveryobsmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1299
diff changeset
  2448
            pushop.outobsmarkers = []
1033
908273755215 evolve: move OBSEXC message in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1032
diff changeset
  2449
1075
1205f42ae54c discovery: use a different setup step for discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1074
diff changeset
  2450
@eh.wrapfunction(wireproto, 'capabilities')
1205f42ae54c discovery: use a different setup step for discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1074
diff changeset
  2451
def discocapabilities(orig, repo, proto):
1205f42ae54c discovery: use a different setup step for discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1074
diff changeset
  2452
    """wrapper to advertise new capability"""
1205f42ae54c discovery: use a different setup step for discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1074
diff changeset
  2453
    caps = orig(repo, proto)
1214
4b10e2c6f7e3 config: remove uses of obsolete._enabled
Durham Goode <durham@fb.com>
parents: 1213
diff changeset
  2454
    if obsolete.isenabled(repo, obsolete.exchangeopt):
1075
1205f42ae54c discovery: use a different setup step for discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1074
diff changeset
  2455
        caps += ' _evoext_obshash_0'
1205f42ae54c discovery: use a different setup step for discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1074
diff changeset
  2456
    return caps
816
03587920dfd9 evolve: add relevant marker exchange machinery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 811
diff changeset
  2457
1075
1205f42ae54c discovery: use a different setup step for discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1074
diff changeset
  2458
@eh.extsetup
1205f42ae54c discovery: use a different setup step for discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1074
diff changeset
  2459
def _installobsmarkersdiscovery(ui):
1205f42ae54c discovery: use a different setup step for discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1074
diff changeset
  2460
    hgweb_mod.perms['evoext_obshash'] = 'pull'
1244
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2461
    hgweb_mod.perms['evoext_obshash1'] = 'pull'
1075
1205f42ae54c discovery: use a different setup step for discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1074
diff changeset
  2462
    # wrap command content
1205f42ae54c discovery: use a different setup step for discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1074
diff changeset
  2463
    oldcap, args = wireproto.commands['capabilities']
1205f42ae54c discovery: use a different setup step for discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1074
diff changeset
  2464
    def newcap(repo, proto):
1205f42ae54c discovery: use a different setup step for discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1074
diff changeset
  2465
        return discocapabilities(oldcap, repo, proto)
1205f42ae54c discovery: use a different setup step for discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1074
diff changeset
  2466
    wireproto.commands['capabilities'] = (newcap, args)
1205f42ae54c discovery: use a different setup step for discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1074
diff changeset
  2467
    wireproto.commands['evoext_obshash'] = (srv_obshash, 'nodes')
1244
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2468
    wireproto.commands['evoext_obshash1'] = (srv_obshash1, 'nodes')
1108
87d60434b434 evolve: keep vague compatibility with 3.1
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1107
diff changeset
  2469
    if getattr(exchange, '_pushdiscoveryobsmarkers', None) is None:
87d60434b434 evolve: keep vague compatibility with 3.1
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1107
diff changeset
  2470
        ui.warn('evolve: your mercurial version is too old\n'
87d60434b434 evolve: keep vague compatibility with 3.1
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1107
diff changeset
  2471
                'evolve: (running in degraded mode, push will includes all markers)\n')
87d60434b434 evolve: keep vague compatibility with 3.1
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1107
diff changeset
  2472
    else:
87d60434b434 evolve: keep vague compatibility with 3.1
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1107
diff changeset
  2473
        olddisco = exchange.pushdiscoverymapping['obsmarker']
87d60434b434 evolve: keep vague compatibility with 3.1
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1107
diff changeset
  2474
        def newdisco(pushop):
87d60434b434 evolve: keep vague compatibility with 3.1
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1107
diff changeset
  2475
            _pushdiscoveryobsmarkers(olddisco, pushop)
87d60434b434 evolve: keep vague compatibility with 3.1
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1107
diff changeset
  2476
        exchange.pushdiscoverymapping['obsmarker'] = newdisco
816
03587920dfd9 evolve: add relevant marker exchange machinery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 811
diff changeset
  2477
1072
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2478
### Set discovery START
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2479
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2480
from mercurial import dagutil
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2481
from mercurial import setdiscovery
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2482
1244
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2483
def _obshash(repo, nodes, version=0):
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2484
    if version == 0:
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2485
        hashs = _obsrelsethashtreefm0(repo)
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2486
    elif version ==1:
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2487
        hashs = _obsrelsethashtreefm1(repo)
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2488
    else:
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2489
        assert False
1072
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2490
    nm = repo.changelog.nodemap
1073
f15f02007a0b obshash: resist to unknown revision during discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1072
diff changeset
  2491
    revs = [nm.get(n) for n in nodes]
f15f02007a0b obshash: resist to unknown revision during discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1072
diff changeset
  2492
    return [r is None and nullid or hashs[r][1] for r in revs]
1072
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2493
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2494
def srv_obshash(repo, proto, nodes):
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2495
    return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes)))
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2496
1244
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2497
def srv_obshash1(repo, proto, nodes):
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2498
    return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes), version=1))
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2499
1072
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2500
@eh.addattr(localrepo.localpeer, 'evoext_obshash')
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2501
def local_obshash(peer, nodes):
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2502
    return _obshash(peer._repo, nodes)
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2503
1244
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2504
@eh.addattr(localrepo.localpeer, 'evoext_obshash1')
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2505
def local_obshash1(peer, nodes):
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2506
    return _obshash(peer._repo, nodes, version=1)
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2507
1072
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2508
@eh.addattr(wireproto.wirepeer, 'evoext_obshash')
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2509
def peer_obshash(self, nodes):
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2510
    d = self._call("evoext_obshash", nodes=wireproto.encodelist(nodes))
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2511
    try:
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2512
        return wireproto.decodelist(d)
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2513
    except ValueError:
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2514
        self._abort(error.ResponseError(_("unexpected response:"), d))
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2515
1244
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2516
@eh.addattr(wireproto.wirepeer, 'evoext_obshash1')
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2517
def peer_obshash1(self, nodes):
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2518
    d = self._call("evoext_obshash1", nodes=wireproto.encodelist(nodes))
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2519
    try:
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2520
        return wireproto.decodelist(d)
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2521
    except ValueError:
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2522
        self._abort(error.ResponseError(_("unexpected response:"), d))
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2523
1072
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2524
def findcommonobsmarkers(ui, local, remote, probeset,
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2525
                         initialsamplesize=100,
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2526
                         fullsamplesize=200):
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2527
    # from discovery
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2528
    roundtrips = 0
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2529
    cl = local.changelog
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2530
    dag = dagutil.revlogdag(cl)
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2531
    missing = set()
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2532
    common = set()
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2533
    undecided = set(probeset)
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2534
    _takefullsample = setdiscovery._takefullsample
1244
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2535
    if remote.capable('_evoext_obshash_1'):
1249
1556d8fed538 discovery: stop being stupid about variable name
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1244
diff changeset
  2536
        getremotehash = remote.evoext_obshash1
1244
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2537
        localhash = _obsrelsethashtreefm1(local)
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2538
    else:
1249
1556d8fed538 discovery: stop being stupid about variable name
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1244
diff changeset
  2539
        getremotehash = remote.evoext_obshash
1244
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2540
        localhash = _obsrelsethashtreefm0(local)
1072
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2541
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2542
    while undecided:
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2543
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2544
        ui.note(_("sampling from both directions\n"))
1193
de73285cf504 discovery: do not build sample if undecided is smaller than sample size
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1192
diff changeset
  2545
        if len(undecided) < fullsamplesize:
de73285cf504 discovery: do not build sample if undecided is smaller than sample size
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1192
diff changeset
  2546
            sample = set(undecided)
de73285cf504 discovery: do not build sample if undecided is smaller than sample size
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1192
diff changeset
  2547
        else:
de73285cf504 discovery: do not build sample if undecided is smaller than sample size
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1192
diff changeset
  2548
            sample = _takefullsample(dag, undecided, size=fullsamplesize)
1072
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2549
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2550
        roundtrips += 1
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2551
        ui.debug("query %i; still undecided: %i, sample size is: %i\n"
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2552
                 % (roundtrips, len(undecided), len(sample)))
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2553
        # indices between sample and externalized version must match
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2554
        sample = list(sample)
1249
1556d8fed538 discovery: stop being stupid about variable name
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1244
diff changeset
  2555
        remotehash = getremotehash(dag.externalizeall(sample))
1072
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2556
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2557
        yesno = [localhash[ix][1] == remotehash[si]
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2558
                 for si, ix in enumerate(sample)]
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2559
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2560
        commoninsample = set(n for i, n in enumerate(sample) if yesno[i])
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2561
        common.update(dag.ancestorset(commoninsample, common))
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2562
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2563
        missinginsample = [n for i, n in enumerate(sample) if not yesno[i]]
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2564
        missing.update(dag.descendantset(missinginsample, missing))
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2565
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2566
        undecided.difference_update(missing)
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2567
        undecided.difference_update(common)
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2568
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2569
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2570
    result = dag.headsetofconnecteds(common)
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2571
    ui.debug("%d total queries\n" % roundtrips)
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2572
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2573
    if not result:
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2574
        return set([nullid])
1639810c11c2 code movement: gather discovery code together
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1071
diff changeset
  2575
    return dag.externalizeall(result)
816
03587920dfd9 evolve: add relevant marker exchange machinery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 811
diff changeset
  2576
03587920dfd9 evolve: add relevant marker exchange machinery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 811
diff changeset
  2577
817
c2bf0eb727f1 exchange: only push the set of marker relevant to want we push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 816
diff changeset
  2578
_pushkeyescape = getattr(obsolete, '_pushkeyescape', None)
c2bf0eb727f1 exchange: only push the set of marker relevant to want we push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 816
diff changeset
  2579
854
86b826399dfd exchange: add progress bar when pushing using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 853
diff changeset
  2580
class pushobsmarkerStringIO(StringIO):
86b826399dfd exchange: add progress bar when pushing using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 853
diff changeset
  2581
    """hacky string io for progress"""
86b826399dfd exchange: add progress bar when pushing using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 853
diff changeset
  2582
86b826399dfd exchange: add progress bar when pushing using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 853
diff changeset
  2583
    @util.propertycache
879
85b3d54516a7 exchange: expose length of pushed markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 877
diff changeset
  2584
    def length(self):
854
86b826399dfd exchange: add progress bar when pushing using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 853
diff changeset
  2585
        return len(self.getvalue())
86b826399dfd exchange: add progress bar when pushing using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 853
diff changeset
  2586
1080
41d2555141ea evolve: allow read() from the magic StringIO
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1079
diff changeset
  2587
    def read(self, size=None):
1034
5fd28e46e8f5 evolve: move OBSEXC progress in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1033
diff changeset
  2588
        obsexcprg(self.ui, self.tell(), unit="bytes", total=self.length)
854
86b826399dfd exchange: add progress bar when pushing using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 853
diff changeset
  2589
        return StringIO.read(self, size)
86b826399dfd exchange: add progress bar when pushing using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 853
diff changeset
  2590
961
8de88b323fb6 evolve: install progress support for the bundle2 push path
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 960
diff changeset
  2591
    def __iter__(self):
8de88b323fb6 evolve: install progress support for the bundle2 push path
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 960
diff changeset
  2592
        d = self.read(4096)
8de88b323fb6 evolve: install progress support for the bundle2 push path
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 960
diff changeset
  2593
        while d:
8de88b323fb6 evolve: install progress support for the bundle2 push path
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 960
diff changeset
  2594
            yield d
8de88b323fb6 evolve: install progress support for the bundle2 push path
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 960
diff changeset
  2595
            d = self.read(4096)
8de88b323fb6 evolve: install progress support for the bundle2 push path
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 960
diff changeset
  2596
1005
4fe159fdfc4c push: extract obsmarkers discovery in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1004
diff changeset
  2597
@eh.wrapfunction(exchange, '_pushobsolete')
4fe159fdfc4c push: extract obsmarkers discovery in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1004
diff changeset
  2598
def _pushobsolete(orig, pushop):
4fe159fdfc4c push: extract obsmarkers discovery in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1004
diff changeset
  2599
    """utility function to push obsolete markers to a remote"""
4fe159fdfc4c push: extract obsmarkers discovery in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1004
diff changeset
  2600
    stepsdone = getattr(pushop, 'stepsdone', None)
4fe159fdfc4c push: extract obsmarkers discovery in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1004
diff changeset
  2601
    if stepsdone is not None:
4fe159fdfc4c push: extract obsmarkers discovery in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1004
diff changeset
  2602
        if 'obsmarkers' in stepsdone:
4fe159fdfc4c push: extract obsmarkers discovery in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1004
diff changeset
  2603
            return
4fe159fdfc4c push: extract obsmarkers discovery in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1004
diff changeset
  2604
        stepsdone.add('obsmarkers')
1118
fbc400c1b022 evolve: adapt to core changeset 4f14303e8954
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1117
diff changeset
  2605
    if util.safehasattr(pushop, 'cgresult'):
fbc400c1b022 evolve: adapt to core changeset 4f14303e8954
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1117
diff changeset
  2606
        cgresult = pushop.cgresult
fbc400c1b022 evolve: adapt to core changeset 4f14303e8954
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1117
diff changeset
  2607
    else:
fbc400c1b022 evolve: adapt to core changeset 4f14303e8954
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1117
diff changeset
  2608
        cgresult = pushop.ret
fbc400c1b022 evolve: adapt to core changeset 4f14303e8954
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1117
diff changeset
  2609
    if cgresult == 0:
1077
cdfc19f25478 obsexc: push nothing if push fail
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1076
diff changeset
  2610
        return
1005
4fe159fdfc4c push: extract obsmarkers discovery in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1004
diff changeset
  2611
    pushop.ui.debug('try to push obsolete markers to remote\n')
4fe159fdfc4c push: extract obsmarkers discovery in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1004
diff changeset
  2612
    repo = pushop.repo
4fe159fdfc4c push: extract obsmarkers discovery in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1004
diff changeset
  2613
    remote = pushop.remote
4fe159fdfc4c push: extract obsmarkers discovery in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1004
diff changeset
  2614
    unfi = repo.unfiltered()
4fe159fdfc4c push: extract obsmarkers discovery in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1004
diff changeset
  2615
    cl = unfi.changelog
1214
4b10e2c6f7e3 config: remove uses of obsolete._enabled
Durham Goode <durham@fb.com>
parents: 1213
diff changeset
  2616
    if (obsolete.isenabled(repo, obsolete.exchangeopt) and repo.obsstore and
1005
4fe159fdfc4c push: extract obsmarkers discovery in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1004
diff changeset
  2617
        'obsolete' in remote.listkeys('namespaces')):
1078
5717d023da63 obsexc: use the common discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1077
diff changeset
  2618
        markers = pushop.outobsmarkers
864
401da1b38cca discovery: implement a discovery process and use it for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 863
diff changeset
  2619
        if not markers:
1033
908273755215 evolve: move OBSEXC message in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1032
diff changeset
  2620
            obsexcmsg(repo.ui, "no marker to push\n")
864
401da1b38cca discovery: implement a discovery process and use it for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 863
diff changeset
  2621
        elif remote.capable('_evoext_pushobsmarkers_0'):
854
86b826399dfd exchange: add progress bar when pushing using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 853
diff changeset
  2622
            obsdata = pushobsmarkerStringIO()
1091
236a8e81551e compat: use in-core encodemarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1090
diff changeset
  2623
            for chunk in obsolete.encodemarkers(markers, True):
236a8e81551e compat: use in-core encodemarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1090
diff changeset
  2624
                obsdata.write(chunk)
821
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2625
            obsdata.seek(0)
854
86b826399dfd exchange: add progress bar when pushing using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 853
diff changeset
  2626
            obsdata.ui = repo.ui
1037
bddee73b361e evolve: add "absolescence" in front of markers in the message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1036
diff changeset
  2627
            obsexcmsg(repo.ui, "pushing %i obsolescence markers (%i bytes)\n"
1036
70de12b7721a evolve: re-introduce the "pushing 42 markers…" message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1035
diff changeset
  2628
                               % (len(markers), len(obsdata.getvalue())),
70de12b7721a evolve: re-introduce the "pushing 42 markers…" message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1035
diff changeset
  2629
                      True)
821
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2630
            remote.evoext_pushobsmarkers_0(obsdata)
1034
5fd28e46e8f5 evolve: move OBSEXC progress in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1033
diff changeset
  2631
            obsexcprg(repo.ui, None)
821
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2632
        else:
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2633
            rslts = []
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2634
            remotedata = _pushkeyescape(markers).items()
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2635
            totalbytes = sum(len(d) for k,d in remotedata)
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2636
            sentbytes = 0
1037
bddee73b361e evolve: add "absolescence" in front of markers in the message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1036
diff changeset
  2637
            obsexcmsg(repo.ui, "pushing %i obsolescence markers in %i pushkey payload (%i bytes)\n"
1036
70de12b7721a evolve: re-introduce the "pushing 42 markers…" message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1035
diff changeset
  2638
                                % (len(markers), len(remotedata), totalbytes),
70de12b7721a evolve: re-introduce the "pushing 42 markers…" message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1035
diff changeset
  2639
                      True)
821
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2640
            for key, data in remotedata:
1034
5fd28e46e8f5 evolve: move OBSEXC progress in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1033
diff changeset
  2641
                obsexcprg(repo.ui, sentbytes, item=key, unit="bytes",
5fd28e46e8f5 evolve: move OBSEXC progress in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1033
diff changeset
  2642
                          total=totalbytes)
821
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2643
                rslts.append(remote.pushkey('obsolete', key, '', data))
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2644
                sentbytes += len(data)
1034
5fd28e46e8f5 evolve: move OBSEXC progress in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1033
diff changeset
  2645
                obsexcprg(repo.ui, sentbytes, item=key, unit="bytes",
5fd28e46e8f5 evolve: move OBSEXC progress in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1033
diff changeset
  2646
                          total=totalbytes)
5fd28e46e8f5 evolve: move OBSEXC progress in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1033
diff changeset
  2647
            obsexcprg(repo.ui, None)
821
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2648
            if [r for r in rslts if not r]:
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2649
                msg = _('failed to push some obsolete markers!\n')
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2650
                repo.ui.warn(msg)
1033
908273755215 evolve: move OBSEXC message in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1032
diff changeset
  2651
        obsexcmsg(repo.ui, "DONE\n")
821
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2652
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2653
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2654
@eh.addattr(wireproto.wirepeer, 'evoext_pushobsmarkers_0')
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2655
def client_pushobsmarkers(self, obsfile):
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2656
    """wireprotocol peer method"""
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2657
    self.requirecap('_evoext_pushobsmarkers_0',
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2658
                    _('push obsolete markers faster'))
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2659
    ret, output = self._callpush('evoext_pushobsmarkers_0', obsfile)
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2660
    for l in output.splitlines(True):
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2661
        self.ui.status(_('remote: '), l)
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2662
    return ret
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2663
880
7fe06f32d1ad exchange: fix push markers over wire protocol for http peer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 879
diff changeset
  2664
@eh.addattr(httppeer.httppeer, 'evoext_pushobsmarkers_0')
7fe06f32d1ad exchange: fix push markers over wire protocol for http peer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 879
diff changeset
  2665
def httpclient_pushobsmarkers(self, obsfile):
7fe06f32d1ad exchange: fix push markers over wire protocol for http peer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 879
diff changeset
  2666
    """httpprotocol peer method
7fe06f32d1ad exchange: fix push markers over wire protocol for http peer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 879
diff changeset
  2667
    (Cannot simply use _callpush as http is doing some special handling)"""
7fe06f32d1ad exchange: fix push markers over wire protocol for http peer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 879
diff changeset
  2668
    self.requirecap('_evoext_pushobsmarkers_0',
7fe06f32d1ad exchange: fix push markers over wire protocol for http peer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 879
diff changeset
  2669
                    _('push obsolete markers faster'))
1209
fa35aeb64d32 evolve: prevent a crash in httpclient_pushobsmarkers() when pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 1206
diff changeset
  2670
    try:
fa35aeb64d32 evolve: prevent a crash in httpclient_pushobsmarkers() when pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 1206
diff changeset
  2671
        r = self._call('evoext_pushobsmarkers_0', data=obsfile)
fa35aeb64d32 evolve: prevent a crash in httpclient_pushobsmarkers() when pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 1206
diff changeset
  2672
        vals = r.split('\n', 1)
fa35aeb64d32 evolve: prevent a crash in httpclient_pushobsmarkers() when pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 1206
diff changeset
  2673
        if len(vals) < 2:
fa35aeb64d32 evolve: prevent a crash in httpclient_pushobsmarkers() when pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 1206
diff changeset
  2674
            raise error.ResponseError(_("unexpected response:"), r)
fa35aeb64d32 evolve: prevent a crash in httpclient_pushobsmarkers() when pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 1206
diff changeset
  2675
fa35aeb64d32 evolve: prevent a crash in httpclient_pushobsmarkers() when pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 1206
diff changeset
  2676
        for l in vals[1].splitlines(True):
fa35aeb64d32 evolve: prevent a crash in httpclient_pushobsmarkers() when pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 1206
diff changeset
  2677
            if l.strip():
fa35aeb64d32 evolve: prevent a crash in httpclient_pushobsmarkers() when pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 1206
diff changeset
  2678
                self.ui.status(_('remote: '), l)
fa35aeb64d32 evolve: prevent a crash in httpclient_pushobsmarkers() when pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 1206
diff changeset
  2679
        return vals[0]
fa35aeb64d32 evolve: prevent a crash in httpclient_pushobsmarkers() when pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 1206
diff changeset
  2680
    except socket.error, err:
fa35aeb64d32 evolve: prevent a crash in httpclient_pushobsmarkers() when pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 1206
diff changeset
  2681
        if err.args[0] in (errno.ECONNRESET, errno.EPIPE):
fa35aeb64d32 evolve: prevent a crash in httpclient_pushobsmarkers() when pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 1206
diff changeset
  2682
            raise util.Abort(_('push failed: %s') % err.args[1])
fa35aeb64d32 evolve: prevent a crash in httpclient_pushobsmarkers() when pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 1206
diff changeset
  2683
        raise util.Abort(err.args[1])
880
7fe06f32d1ad exchange: fix push markers over wire protocol for http peer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 879
diff changeset
  2684
1081
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2685
@eh.wrapfunction(localrepo.localrepository, '_restrictcapabilities')
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2686
def local_pushobsmarker_capabilities(orig, repo, caps):
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2687
    caps = orig(repo, caps)
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2688
    caps.add('_evoext_pushobsmarkers_0')
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2689
    return caps
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2690
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2691
@eh.addattr(localrepo.localpeer, 'evoext_pushobsmarkers_0')
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2692
def local_pushobsmarkers(peer, obsfile):
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2693
    data = obsfile.read()
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2694
    lock = peer._repo.lock()
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2695
    try:
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2696
        tr = peer._repo.transaction('pushkey: obsolete markers')
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2697
        try:
1084
5459d9f48fea evolve: display more message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1083
diff changeset
  2698
            new = peer._repo.obsstore.mergemarkers(tr, data)
5459d9f48fea evolve: display more message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1083
diff changeset
  2699
            if new is not None:
5459d9f48fea evolve: display more message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1083
diff changeset
  2700
                obsexcmsg(peer._repo.ui, "%i obsolescence markers added\n" % new, True)
1081
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2701
            tr.close()
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2702
        finally:
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2703
            tr.release()
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2704
    finally:
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2705
        lock.release()
dddb8a70437c obsexc: add support for evoext_pushobsmarkers_0 on localpeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1080
diff changeset
  2706
    peer._repo.hook('evolve_pushobsmarkers')
821
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2707
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2708
def srv_pushobsmarkers(repo, proto):
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2709
    """wireprotocol command"""
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2710
    fp = StringIO()
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2711
    proto.redirect()
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2712
    proto.getfile(fp)
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2713
    data = fp.getvalue()
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2714
    fp.close()
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2715
    lock = repo.lock()
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2716
    try:
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2717
        tr = repo.transaction('pushkey: obsolete markers')
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2718
        try:
1084
5459d9f48fea evolve: display more message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1083
diff changeset
  2719
            new = repo.obsstore.mergemarkers(tr, data)
5459d9f48fea evolve: display more message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1083
diff changeset
  2720
            if new is not None:
5459d9f48fea evolve: display more message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1083
diff changeset
  2721
                obsexcmsg(repo.ui, "%i obsolescence markers added\n" % new, True)
821
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2722
            tr.close()
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2723
        finally:
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2724
            tr.release()
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2725
    finally:
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2726
        lock.release()
888
097ddcb0da25 evolve: add a hook related to the new pushobsmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 887
diff changeset
  2727
    repo.hook('evolve_pushobsmarkers')
821
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2728
    return wireproto.pushres(0)
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  2729
1095
26334cfd4e95 evolve: fix a typo in a long function name
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1094
diff changeset
  2730
def _buildpullobsmarkersboundaries(pullop):
825
7671717afef8 exchange: extract computation of pulled markers boundary in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 824
diff changeset
  2731
    """small funtion returning the argument for pull markers call
7671717afef8 exchange: extract computation of pulled markers boundary in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 824
diff changeset
  2732
    may to contains 'heads' and 'common'. skip the key for None.
7671717afef8 exchange: extract computation of pulled markers boundary in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 824
diff changeset
  2733
7671717afef8 exchange: extract computation of pulled markers boundary in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 824
diff changeset
  2734
    Its a separed functio to play around with strategy for that."""
865
5c40b2a4b52f discovery: use the discovery process for pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 864
diff changeset
  2735
    repo = pullop.repo
5c40b2a4b52f discovery: use the discovery process for pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 864
diff changeset
  2736
    cl = pullop.repo.changelog
5c40b2a4b52f discovery: use the discovery process for pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 864
diff changeset
  2737
    remote = pullop.remote
5c40b2a4b52f discovery: use the discovery process for pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 864
diff changeset
  2738
    unfi = repo.unfiltered()
1196
9e3f332f7630 discovery: filter null from the discovery revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1193
diff changeset
  2739
    revs = unfi.revs('::(%ln - null)', pullop.common)
865
5c40b2a4b52f discovery: use the discovery process for pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 864
diff changeset
  2740
    common = [nullid]
5c40b2a4b52f discovery: use the discovery process for pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 864
diff changeset
  2741
    if remote.capable('_evoext_obshash_0'):
1033
908273755215 evolve: move OBSEXC message in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1032
diff changeset
  2742
        obsexcmsg(repo.ui, "looking for common markers in %i nodes\n"
908273755215 evolve: move OBSEXC message in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1032
diff changeset
  2743
                           % len(revs))
865
5c40b2a4b52f discovery: use the discovery process for pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 864
diff changeset
  2744
        common = findcommonobsmarkers(repo.ui, repo, remote, revs)
5c40b2a4b52f discovery: use the discovery process for pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 864
diff changeset
  2745
    return {'heads': pullop.pulledsubset, 'common': common}
825
7671717afef8 exchange: extract computation of pulled markers boundary in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 824
diff changeset
  2746
960
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2747
@eh.uisetup
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2748
def addgetbundleargs(self):
1097
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1096
diff changeset
  2749
    gboptsmap['evo_obscommon'] = 'nodes'
960
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2750
1097
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1096
diff changeset
  2751
@eh.wrapfunction(exchange, '_pullbundle2extraprepare')
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1096
diff changeset
  2752
def _addobscommontob2pull(orig, pullop, kwargs):
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1096
diff changeset
  2753
    ret = orig(pullop, kwargs)
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1096
diff changeset
  2754
    if 'obsmarkers' in kwargs and pullop.remote.capable('_evoext_getbundle_obscommon'):
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1096
diff changeset
  2755
        boundaries = _buildpullobsmarkersboundaries(pullop)
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1096
diff changeset
  2756
        common = boundaries['common']
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1096
diff changeset
  2757
        if common != [nullid]:
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1096
diff changeset
  2758
            kwargs['evo_obscommon'] = common
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1096
diff changeset
  2759
    return ret
960
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2760
1301
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2761
@eh.wrapfunction(exchange, '_getbundleobsmarkerpart')
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2762
def _getbundleobsmarkerpart(orig, bundler, repo, source, **kwargs):
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2763
    if 'evo_obscommon' not in kwargs:
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2764
        return orig(bundler, repo, source, **kwargs)
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2765
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2766
    heads = kwargs.get('heads')
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2767
    if kwargs.get('obsmarkers', False):
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2768
        if heads is None:
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2769
            heads = repo.heads()
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2770
        obscommon = kwargs.get('evo_obscommon', ())
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2771
        assert obscommon
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2772
        obsset = repo.unfiltered().set('::%ln - ::%ln', heads, obscommon)
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2773
        subset = [c.node() for c in obsset]
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2774
        markers = repo.obsstore.relevantmarkers(subset)
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2775
        exchange.buildobsmarkerspart(bundler, markers)
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2776
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2777
@eh.uisetup
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2778
def installgetbundlepartgen(ui):
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2779
    origfunc = exchange.getbundle2partsmapping['obsmarkers']
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2780
    def newfunc(*args, **kwargs):
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2781
        return _getbundleobsmarkerpart(origfunc, *args, **kwargs)
896d66841f7f evolve: stop conditional wrapping of _getbundleobsmarkerpart
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1300
diff changeset
  2782
    exchange.getbundle2partsmapping['obsmarkers'] = newfunc
825
7671717afef8 exchange: extract computation of pulled markers boundary in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 824
diff changeset
  2783
823
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2784
@eh.wrapfunction(exchange, '_pullobsolete')
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2785
def _pullobsolete(orig, pullop):
1214
4b10e2c6f7e3 config: remove uses of obsolete._enabled
Durham Goode <durham@fb.com>
parents: 1213
diff changeset
  2786
    if not obsolete.isenabled(pullop.repo, obsolete.exchangeopt):
823
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2787
        return None
1132
7a1784a1c642 pullobsolete: handle migration from todosteps to donesteps
Augie Fackler <raf@durin42.com>
parents: 1131
diff changeset
  2788
    if 'obsmarkers' not in getattr(pullop, 'todosteps', ['obsmarkers']):
7a1784a1c642 pullobsolete: handle migration from todosteps to donesteps
Augie Fackler <raf@durin42.com>
parents: 1131
diff changeset
  2789
        return None
7a1784a1c642 pullobsolete: handle migration from todosteps to donesteps
Augie Fackler <raf@durin42.com>
parents: 1131
diff changeset
  2790
    if 'obsmarkers' in getattr(pullop, 'stepsdone', []):
1093
a49f2e7a2755 obsexch: respect todosteps when using the old push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1091
diff changeset
  2791
        return None
960
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2792
    wirepull = pullop.remote.capable('_evoext_pullobsmarkers_0')
1082
74bc8a0c2c02 pull: drop the custom bundle2 part
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1081
diff changeset
  2793
    if not wirepull:
823
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2794
        return orig(pullop)
883
d2fa1061df16 evolve: do not exchange obsolescence markers when server refuse it
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 880
diff changeset
  2795
    if 'obsolete' not in pullop.remote.listkeys('namespaces'):
d2fa1061df16 evolve: do not exchange obsolescence markers when server refuse it
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 880
diff changeset
  2796
        return None # remote opted out of obsolescence marker exchange
823
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2797
    tr = None
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2798
    ui = pullop.repo.ui
1095
26334cfd4e95 evolve: fix a typo in a long function name
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1094
diff changeset
  2799
    boundaries = _buildpullobsmarkersboundaries(pullop)
1041
7632f1f79946 evolve: do not even try to pull if all remote markers are known
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1040
diff changeset
  2800
    if not set(boundaries['heads']) - set(boundaries['common']):
7632f1f79946 evolve: do not even try to pull if all remote markers are known
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1040
diff changeset
  2801
        obsexcmsg(ui, "nothing to pull\n")
7632f1f79946 evolve: do not even try to pull if all remote markers are known
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1040
diff changeset
  2802
        return None
7632f1f79946 evolve: do not even try to pull if all remote markers are known
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1040
diff changeset
  2803
1042
86bd794f6037 evolve: stop pretending we are pulling markers when we don't
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1041
diff changeset
  2804
    obsexcmsg(ui, "pull obsolescence markers\n", True)
960
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2805
    new = 0
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2806
1082
74bc8a0c2c02 pull: drop the custom bundle2 part
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1081
diff changeset
  2807
    if wirepull:
960
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2808
        obsdata = pullop.remote.evoext_pullobsmarkers_0(**boundaries)
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2809
        obsdata = obsdata.read()
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2810
        if len(obsdata) > 5:
1033
908273755215 evolve: move OBSEXC message in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1032
diff changeset
  2811
            obsexcmsg(ui, "merging obsolescence markers (%i bytes)\n"
960
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2812
                           % len(obsdata))
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2813
            tr = pullop.gettransaction()
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2814
            old = len(pullop.repo.obsstore._all)
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2815
            pullop.repo.obsstore.mergemarkers(tr, obsdata)
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2816
            new = len(pullop.repo.obsstore._all) - old
1040
640f3280559e evolve: add "obsolescence" in front of marked in the previous message
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1039
diff changeset
  2817
            obsexcmsg(ui, "%i obsolescence markers added\n" % new, True)
960
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2818
        else:
1033
908273755215 evolve: move OBSEXC message in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1032
diff changeset
  2819
            obsexcmsg(ui, "no unknown remote markers\n")
908273755215 evolve: move OBSEXC message in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1032
diff changeset
  2820
        obsexcmsg(ui, "DONE\n")
960
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2821
    if new:
0c1142059a82 evolve: add a pull path using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 959
diff changeset
  2822
        pullop.repo.invalidatevolatilesets()
823
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2823
    return tr
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2824
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2825
def _getobsmarkersstream(repo, heads=None, common=None):
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2826
    revset = ''
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2827
    args = []
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2828
    repo = repo.unfiltered()
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2829
    if heads is None:
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2830
        revset = 'all()'
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2831
    elif heads:
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2832
        revset += "(::%ln)"
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2833
        args.append(heads)
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2834
    else:
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2835
        assert False, 'pulling no heads?'
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2836
    if common:
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2837
        revset += ' - (::%ln)'
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2838
        args.append(common)
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2839
    nodes = [c.node() for c in repo.set(revset, *args)]
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2840
    markers = repo.obsstore.relevantmarkers(nodes)
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2841
    obsdata = StringIO()
1091
236a8e81551e compat: use in-core encodemarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1090
diff changeset
  2842
    for chunk in obsolete.encodemarkers(markers, True):
236a8e81551e compat: use in-core encodemarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1090
diff changeset
  2843
        obsdata.write(chunk)
823
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2844
    obsdata.seek(0)
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2845
    return obsdata
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2846
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2847
@eh.addattr(wireproto.wirepeer, 'evoext_pullobsmarkers_0')
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2848
def client_pullobsmarkers(self, heads=None, common=None):
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2849
    self.requirecap('_evoext_pullobsmarkers_0', _('look up remote obsmarkers'))
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2850
    opts = {}
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2851
    if heads is not None:
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2852
        opts['heads'] = wireproto.encodelist(heads)
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2853
    if common is not None:
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2854
        opts['common'] = wireproto.encodelist(common)
897
b5227608d9dd evolve: use new api _callcompressable
Olle Lundberg <geek@nerd.sh>
parents: 896
diff changeset
  2855
    if util.safehasattr(self, '_callcompressable'):
b5227608d9dd evolve: use new api _callcompressable
Olle Lundberg <geek@nerd.sh>
parents: 896
diff changeset
  2856
        f = self._callcompressable("evoext_pullobsmarkers_0", **opts)
b5227608d9dd evolve: use new api _callcompressable
Olle Lundberg <geek@nerd.sh>
parents: 896
diff changeset
  2857
    else:
b5227608d9dd evolve: use new api _callcompressable
Olle Lundberg <geek@nerd.sh>
parents: 896
diff changeset
  2858
        f = self._callstream("evoext_pullobsmarkers_0", **opts)
b5227608d9dd evolve: use new api _callcompressable
Olle Lundberg <geek@nerd.sh>
parents: 896
diff changeset
  2859
        f = self._decompress(f)
898
934b6f0feffd evolve: small white space change
Olle Lundberg <geek@nerd.sh>
parents: 897
diff changeset
  2860
    length = int(f.read(20))
853
b82b49189328 exchange: add progress bar when pulling using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 825
diff changeset
  2861
    chunk = 4096
b82b49189328 exchange: add progress bar when pulling using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 825
diff changeset
  2862
    current = 0
b82b49189328 exchange: add progress bar when pulling using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 825
diff changeset
  2863
    data = StringIO()
b82b49189328 exchange: add progress bar when pulling using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 825
diff changeset
  2864
    ui = self.ui
1034
5fd28e46e8f5 evolve: move OBSEXC progress in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1033
diff changeset
  2865
    obsexcprg(ui, current, unit="bytes", total=length)
853
b82b49189328 exchange: add progress bar when pulling using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 825
diff changeset
  2866
    while current < length:
b82b49189328 exchange: add progress bar when pulling using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 825
diff changeset
  2867
        readsize = min(length-current, chunk)
b82b49189328 exchange: add progress bar when pulling using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 825
diff changeset
  2868
        data.write(f.read(readsize))
b82b49189328 exchange: add progress bar when pulling using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 825
diff changeset
  2869
        current += readsize
1034
5fd28e46e8f5 evolve: move OBSEXC progress in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1033
diff changeset
  2870
        obsexcprg(ui, current, unit="bytes", total=length)
5fd28e46e8f5 evolve: move OBSEXC progress in a dedicated function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1033
diff changeset
  2871
    obsexcprg(ui, None)
870
1a23c7c52a43 exchange: fix pull over wire protocol
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 869
diff changeset
  2872
    data.seek(0)
853
b82b49189328 exchange: add progress bar when pulling using wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 825
diff changeset
  2873
    return data
823
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2874
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2875
@eh.addattr(localrepo.localpeer, 'evoext_pullobsmarkers_0')
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2876
def local_pullobsmarkers(self, heads=None, common=None):
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2877
    return _getobsmarkersstream(self._repo, heads=heads, common=common)
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2878
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2879
def srv_pullobsmarkers(repo, proto, others):
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2880
    opts = wireproto.options('', ['heads', 'common'], others)
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2881
    for k, v in opts.iteritems():
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2882
        if k in ('heads', 'common'):
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2883
            opts[k] = wireproto.decodelist(v)
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2884
    obsdata = _getobsmarkersstream(repo, **opts)
877
cf35f38d6a10 exchange: fix changeset pulling over http
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 875
diff changeset
  2885
    finaldata = StringIO()
cf35f38d6a10 exchange: fix changeset pulling over http
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 875
diff changeset
  2886
    obsdata = obsdata.getvalue()
cf35f38d6a10 exchange: fix changeset pulling over http
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 875
diff changeset
  2887
    finaldata.write('%20i' % len(obsdata))
cf35f38d6a10 exchange: fix changeset pulling over http
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 875
diff changeset
  2888
    finaldata.write(obsdata)
cf35f38d6a10 exchange: fix changeset pulling over http
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 875
diff changeset
  2889
    finaldata.seek(0)
cf35f38d6a10 exchange: fix changeset pulling over http
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 875
diff changeset
  2890
    return wireproto.streamres(proto.groupchunks(finaldata))
823
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  2891
1244
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2892
def _obsrelsethashtreefm0(repo):
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2893
    return _obsrelsethashtree(repo, obsolete._fm0encodeonemarker)
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2894
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2895
def _obsrelsethashtreefm1(repo):
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2896
    return _obsrelsethashtree(repo, obsolete._fm1encodeonemarker)
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2897
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2898
def _obsrelsethashtree(repo, encodeonemarker):
863
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2899
    cache = []
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2900
    unfi = repo.unfiltered()
1203
936aa82884ab evolve: cache marker encoding to avoid performance degradation
Mathias De Maré <mathias.demare@gmail.com>
parents: 1202
diff changeset
  2901
    markercache = {}
863
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2902
    for i in unfi:
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2903
        ctx = unfi[i]
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2904
        entry = 0
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2905
        sha = util.sha1()
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2906
        # add data from p1
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2907
        for p in ctx.parents():
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2908
            p = p.rev()
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2909
            if p < 0:
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2910
                p = nullid
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2911
            else:
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2912
                p = cache[p][1]
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2913
            if p != nullid:
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2914
                entry += 1
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2915
                sha.update(p)
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2916
        tmarkers = repo.obsstore.relevantmarkers([ctx.node()])
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2917
        if tmarkers:
1203
936aa82884ab evolve: cache marker encoding to avoid performance degradation
Mathias De Maré <mathias.demare@gmail.com>
parents: 1202
diff changeset
  2918
            bmarkers = []
936aa82884ab evolve: cache marker encoding to avoid performance degradation
Mathias De Maré <mathias.demare@gmail.com>
parents: 1202
diff changeset
  2919
            for m in tmarkers:
936aa82884ab evolve: cache marker encoding to avoid performance degradation
Mathias De Maré <mathias.demare@gmail.com>
parents: 1202
diff changeset
  2920
                if not m in markercache:
1244
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2921
                    markercache[m] = encodeonemarker(m)
1203
936aa82884ab evolve: cache marker encoding to avoid performance degradation
Mathias De Maré <mathias.demare@gmail.com>
parents: 1202
diff changeset
  2922
                bmarkers.append(markercache[m])
863
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2923
            bmarkers.sort()
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2924
            for m in bmarkers:
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2925
                entry += 1
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2926
                sha.update(m)
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2927
        if entry:
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2928
            cache.append((ctx.node(), sha.digest()))
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2929
        else:
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2930
            cache.append((ctx.node(), nullid))
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2931
    return cache
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2932
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2933
@command('debugobsrelsethashtree',
1244
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2934
        [('', 'v0', None, 'hash on marker format "0"'),
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2935
         ('', 'v1', None, 'hash on marker format "1" (default)')
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2936
         ,] , _(''))
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2937
def debugobsrelsethashtree(ui, repo, v0=False, v1=False):
863
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2938
    """display Obsolete markers, Relevant Set, Hash Tree
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2939
    changeset-node obsrelsethashtree-node
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2940
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2941
    It computed form the "orsht" of its parent and markers
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2942
    relevant to the changeset itself."""
1244
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2943
    if v0 and v1:
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2944
        raise util.Abort('cannot only specify one format')
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2945
    elif v0:
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2946
        treefunc = _obsrelsethashtreefm0
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2947
    else:
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2948
        treefunc = _obsrelsethashtreefm1
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2949
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  2950
    for chg, obs in treefunc(repo):
863
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2951
        ui.status('%s %s\n' % (node.hex(chg), node.hex(obs)))
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2952
1159
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2953
_bestformat = max(obsolete.formats.keys())
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2954
1202
4099b087f672 evolve: handle invalid obsmarkers in the `debugobsconvert`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1198
diff changeset
  2955
1302
ebcf23fe3032 evolve: stop conditional wrapping of _checkinvalidmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1301
diff changeset
  2956
@eh.wrapfunction(obsolete, '_checkinvalidmarkers')
ebcf23fe3032 evolve: stop conditional wrapping of _checkinvalidmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1301
diff changeset
  2957
def _checkinvalidmarkers(orig, markers):
ebcf23fe3032 evolve: stop conditional wrapping of _checkinvalidmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1301
diff changeset
  2958
    """search for marker with invalid data and raise error if needed
ebcf23fe3032 evolve: stop conditional wrapping of _checkinvalidmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1301
diff changeset
  2959
ebcf23fe3032 evolve: stop conditional wrapping of _checkinvalidmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1301
diff changeset
  2960
    Exist as a separated function to allow the evolve extension for a more
ebcf23fe3032 evolve: stop conditional wrapping of _checkinvalidmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1301
diff changeset
  2961
    subtle handling.
ebcf23fe3032 evolve: stop conditional wrapping of _checkinvalidmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1301
diff changeset
  2962
    """
ebcf23fe3032 evolve: stop conditional wrapping of _checkinvalidmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1301
diff changeset
  2963
    if 'debugobsconvert' in sys.argv:
ebcf23fe3032 evolve: stop conditional wrapping of _checkinvalidmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1301
diff changeset
  2964
        return
ebcf23fe3032 evolve: stop conditional wrapping of _checkinvalidmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1301
diff changeset
  2965
    for mark in markers:
ebcf23fe3032 evolve: stop conditional wrapping of _checkinvalidmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1301
diff changeset
  2966
        if node.nullid in mark[1]:
ebcf23fe3032 evolve: stop conditional wrapping of _checkinvalidmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1301
diff changeset
  2967
            raise util.Abort(_('bad obsolescence marker detected: '
ebcf23fe3032 evolve: stop conditional wrapping of _checkinvalidmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1301
diff changeset
  2968
                               'invalid successors nullid'),
ebcf23fe3032 evolve: stop conditional wrapping of _checkinvalidmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1301
diff changeset
  2969
                             hint=_('You should run `hg debugobsconvert`'))
1202
4099b087f672 evolve: handle invalid obsmarkers in the `debugobsconvert`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1198
diff changeset
  2970
1159
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2971
@command(
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2972
    'debugobsconvert',
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2973
    [('', 'new-format', _bestformat, _('Destination format for markers.'))],
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2974
    '')
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2975
def debugobsconvert(ui, repo, new_format):
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2976
    if new_format == repo.obsstore._version:
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2977
        msg = _('New format is the same as the old format, not upgrading!')
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2978
        raise util.Abort(msg)
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2979
    f = repo.sopener('obsstore', 'wb', atomictemp=True)
1169
6f08a8f6bb1d debugobsconvert: also deduplicate markers in the process
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1159
diff changeset
  2980
    origmarkers = repo.obsstore._all
6f08a8f6bb1d debugobsconvert: also deduplicate markers in the process
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1159
diff changeset
  2981
    known = set()
6f08a8f6bb1d debugobsconvert: also deduplicate markers in the process
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1159
diff changeset
  2982
    markers = []
1172
8d28bb4fc127 debugobsconvert: fix 6f08a8f6bb1d and add proper test
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1171
diff changeset
  2983
    for m in origmarkers:
1202
4099b087f672 evolve: handle invalid obsmarkers in the `debugobsconvert`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1198
diff changeset
  2984
        # filter out invalid markers
4099b087f672 evolve: handle invalid obsmarkers in the `debugobsconvert`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1198
diff changeset
  2985
        if nullid in m[1]:
4099b087f672 evolve: handle invalid obsmarkers in the `debugobsconvert`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1198
diff changeset
  2986
            m = list(m)
4099b087f672 evolve: handle invalid obsmarkers in the `debugobsconvert`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1198
diff changeset
  2987
            m[1] = tuple(s for s in m[1] if s != nullid)
4099b087f672 evolve: handle invalid obsmarkers in the `debugobsconvert`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1198
diff changeset
  2988
            m = tuple(m)
1169
6f08a8f6bb1d debugobsconvert: also deduplicate markers in the process
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1159
diff changeset
  2989
        if m in known:
6f08a8f6bb1d debugobsconvert: also deduplicate markers in the process
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1159
diff changeset
  2990
            continue
1172
8d28bb4fc127 debugobsconvert: fix 6f08a8f6bb1d and add proper test
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1171
diff changeset
  2991
        known.add(m)
1169
6f08a8f6bb1d debugobsconvert: also deduplicate markers in the process
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1159
diff changeset
  2992
        markers.append(m)
1170
4697f23e0ede debugobsconvert: fix a typo on "version"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1169
diff changeset
  2993
    ui.write(_('Old store is version %d, will rewrite in version %d\n') % (
1159
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2994
        repo.obsstore._version, new_format))
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2995
    map(f.write, obsolete.encodemarkers(markers, True, new_format))
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2996
    f.close()
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2997
    ui.write(_('Done!\n'))
04bd66779a1f obsup: hack extension to make in-place upgrading of obsolete markers easy
Augie Fackler <raf@durin42.com>
parents: 1157
diff changeset
  2998
863
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  2999
864
401da1b38cca discovery: implement a discovery process and use it for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 863
diff changeset
  3000
@eh.wrapfunction(wireproto, 'capabilities')
401da1b38cca discovery: implement a discovery process and use it for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 863
diff changeset
  3001
def capabilities(orig, repo, proto):
401da1b38cca discovery: implement a discovery process and use it for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 863
diff changeset
  3002
    """wrapper to advertise new capability"""
401da1b38cca discovery: implement a discovery process and use it for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 863
diff changeset
  3003
    caps = orig(repo, proto)
1214
4b10e2c6f7e3 config: remove uses of obsolete._enabled
Durham Goode <durham@fb.com>
parents: 1213
diff changeset
  3004
    if obsolete.isenabled(repo, obsolete.exchangeopt):
864
401da1b38cca discovery: implement a discovery process and use it for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 863
diff changeset
  3005
        caps += ' _evoext_pushobsmarkers_0'
401da1b38cca discovery: implement a discovery process and use it for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 863
diff changeset
  3006
        caps += ' _evoext_pullobsmarkers_0'
401da1b38cca discovery: implement a discovery process and use it for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 863
diff changeset
  3007
        caps += ' _evoext_obshash_0'
1244
3249814dabd1 discovery: introduce a obshash1 function using fm1 during hashing (issue4587)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1230
diff changeset
  3008
        caps += ' _evoext_obshash_1'
1096
661f3a112f7a pull: run obsmarker discovery only on the common set
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1095
diff changeset
  3009
        caps += ' _evoext_getbundle_obscommon'
864
401da1b38cca discovery: implement a discovery process and use it for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 863
diff changeset
  3010
    return caps
863
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  3011
e9693738f234 discovery: first version of the "hash tree" idea
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 861
diff changeset
  3012
821
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  3013
@eh.extsetup
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  3014
def _installwireprotocol(ui):
941
576d3a198269 evolve: drop some pre-3.0 compatibility code
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 940
diff changeset
  3015
    localrepo.moderncaps.add('_evoext_pullobsmarkers_0')
869
e9eeef0d07ec exchange: enforce permission on new wireprotocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 868
diff changeset
  3016
    hgweb_mod.perms['evoext_pushobsmarkers_0'] = 'push'
e9eeef0d07ec exchange: enforce permission on new wireprotocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 868
diff changeset
  3017
    hgweb_mod.perms['evoext_pullobsmarkers_0'] = 'pull'
821
202376586cf6 exchange: introduce a wireprotocol command to push markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 820
diff changeset
  3018
    wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '')
823
9aa20585e158 exchange: add a new method to pull markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 821
diff changeset
  3019
    wireproto.commands['evoext_pullobsmarkers_0'] = (srv_pullobsmarkers, '*')
875
10867a8e27c6 exchange: properly wrap wireprotocol capabilities
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 871
diff changeset
  3020
    # wrap command content
10867a8e27c6 exchange: properly wrap wireprotocol capabilities
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 871
diff changeset
  3021
    oldcap, args = wireproto.commands['capabilities']
10867a8e27c6 exchange: properly wrap wireprotocol capabilities
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 871
diff changeset
  3022
    def newcap(repo, proto):
10867a8e27c6 exchange: properly wrap wireprotocol capabilities
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 871
diff changeset
  3023
        return capabilities(oldcap, repo, proto)
10867a8e27c6 exchange: properly wrap wireprotocol capabilities
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 871
diff changeset
  3024
    wireproto.commands['capabilities'] = (newcap, args)