mercurial/rewriteutil.py
author Martin von Zweigbergk <martinvonz@google.com>
Tue, 27 Apr 2021 14:59:45 -0700
changeset 47017 da4e6d7a8fdd
parent 47016 8ad2f43fe37b
child 47018 7a90fddb13b0
permissions -rw-r--r--
help: add topic about evolution, based on text from evolve extension I've taken the text produced by `hg help evolution` when the evolve extension is enabled and made that available by the same command with just hg core. Changes I've made: * Added "(EXPERIMENTAL)" to the title. (That doesn't hide the topic from `hg help`, though.) * Replaced old-style `experimental.evolution=<names>` config by new-style `experimental.evolution.<name>=true`. * Replaces a "obsolete markers" by "obsolescence markers". * Removed most content from "Current feature status". When the evolve extension is enabled, its help text takes precedence. Differential Revision: https://phab.mercurial-scm.org/D10516
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35242
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     1
# rewriteutil.py - utility functions for rewriting changesets
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     2
#
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     3
# Copyright 2017 Octobus <contact@octobus.net>
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     4
#
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     7
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     8
from __future__ import absolute_import
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     9
45424
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
    10
import re
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
    11
35243
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    12
from .i18n import _
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45853
diff changeset
    13
from .node import (
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45853
diff changeset
    14
    hex,
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45853
diff changeset
    15
    nullrev,
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45853
diff changeset
    16
)
35243
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    17
35242
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    18
from . import (
35243
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    19
    error,
35242
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    20
    obsolete,
45424
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
    21
    obsutil,
35242
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    22
    revset,
45424
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
    23
    scmutil,
47016
8ad2f43fe37b rewriteutil: add devel warning if precheck is called with contexts
Martin von Zweigbergk <martinvonz@google.com>
parents: 47015
diff changeset
    24
    util,
35242
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    25
)
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    26
43075
57875cf423c9 style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents: 40636
diff changeset
    27
45427
78861610ded8 rewriteutil: relax the sha1 hash references to handle future hash types
Matt Harbison <matt_harbison@yahoo.com>
parents: 45425
diff changeset
    28
NODE_RE = re.compile(br'\b[0-9a-f]{6,64}\b')
45424
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
    29
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
    30
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43075
diff changeset
    31
def precheck(repo, revs, action=b'rewrite'):
35243
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    32
    """check if revs can be rewritten
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    33
    action is used to control the error message.
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    34
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    35
    Make sure this function is called after taking the lock.
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    36
    """
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45853
diff changeset
    37
    if nullrev in revs:
47015
7001f92e0ee9 rewriteutil: replace "null changeset" by "the null revision" in error message
Martin von Zweigbergk <martinvonz@google.com>
parents: 46113
diff changeset
    38
        msg = _(b"cannot %s the null revision") % action
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43075
diff changeset
    39
        hint = _(b"no changeset checked out")
45853
b4694ef45db5 errors: raise more specific errors from rewriteutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 45711
diff changeset
    40
        raise error.InputError(msg, hint=hint)
35243
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    41
47016
8ad2f43fe37b rewriteutil: add devel warning if precheck is called with contexts
Martin von Zweigbergk <martinvonz@google.com>
parents: 47015
diff changeset
    42
    if any(util.safehasattr(r, 'rev') for r in revs):
8ad2f43fe37b rewriteutil: add devel warning if precheck is called with contexts
Martin von Zweigbergk <martinvonz@google.com>
parents: 47015
diff changeset
    43
        repo.ui.develwarn(b"rewriteutil.precheck called with ctx not revs")
8ad2f43fe37b rewriteutil: add devel warning if precheck is called with contexts
Martin von Zweigbergk <martinvonz@google.com>
parents: 47015
diff changeset
    44
        revs = (r.rev() for r in revs)
8ad2f43fe37b rewriteutil: add devel warning if precheck is called with contexts
Martin von Zweigbergk <martinvonz@google.com>
parents: 47015
diff changeset
    45
35243
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    46
    if len(repo[None].parents()) > 1:
45853
b4694ef45db5 errors: raise more specific errors from rewriteutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 45711
diff changeset
    47
        raise error.StateError(_(b"cannot %s while merging") % action)
35243
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    48
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43075
diff changeset
    49
    publicrevs = repo.revs(b'%ld and public()', revs)
35243
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    50
    if publicrevs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43075
diff changeset
    51
        msg = _(b"cannot %s public changesets") % action
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43075
diff changeset
    52
        hint = _(b"see 'hg help phases' for details")
45853
b4694ef45db5 errors: raise more specific errors from rewriteutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 45711
diff changeset
    53
        raise error.InputError(msg, hint=hint)
35243
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    54
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    55
    newunstable = disallowednewunstable(repo, revs)
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    56
    if newunstable:
45853
b4694ef45db5 errors: raise more specific errors from rewriteutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 45711
diff changeset
    57
        raise error.InputError(_(b"cannot %s changeset with children") % action)
35243
490df753894d rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35242
diff changeset
    58
43075
57875cf423c9 style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents: 40636
diff changeset
    59
35242
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    60
def disallowednewunstable(repo, revs):
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    61
    """Checks whether editing the revs will create new unstable changesets and
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    62
    are we allowed to create them.
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    63
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    64
    To allow new unstable changesets, set the config:
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    65
        `experimental.evolution.allowunstable=True`
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    66
    """
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    67
    allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt)
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    68
    if allowunstable:
27d5c2d2db2b rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    69
        return revset.baseset()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43075
diff changeset
    70
    return repo.revs(b"(%ld::) - %ld", revs, revs)
45122
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    71
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    72
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    73
def skip_empty_successor(ui, command):
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    74
    empty_successor = ui.config(b'rewrite', b'empty-successor')
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    75
    if empty_successor == b'skip':
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    76
        return True
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    77
    elif empty_successor == b'keep':
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    78
        return False
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    79
    else:
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    80
        raise error.ConfigError(
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    81
            _(
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    82
                b"%s doesn't know how to handle config "
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    83
                b"rewrite.empty-successor=%s (only 'skip' and 'keep' are "
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    84
                b"supported)"
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    85
            )
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    86
            % (command, empty_successor)
a391d0710f22 rewriteutil: add utility to check whether empty successors should be skipped
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    87
        )
45424
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
    88
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
    89
45425
f7e293e0475f rewriteutil: also consider pending obsoletes when updating hashes in messages
Matt Harbison <matt_harbison@yahoo.com>
parents: 45424
diff changeset
    90
def update_hash_refs(repo, commitmsg, pending=None):
45424
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
    91
    """Replace all obsolete commit hashes in the message with the current hash.
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
    92
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
    93
    If the obsolete commit was split or is divergent, the hash is not replaced
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
    94
    as there's no way to know which successor to choose.
45425
f7e293e0475f rewriteutil: also consider pending obsoletes when updating hashes in messages
Matt Harbison <matt_harbison@yahoo.com>
parents: 45424
diff changeset
    95
f7e293e0475f rewriteutil: also consider pending obsoletes when updating hashes in messages
Matt Harbison <matt_harbison@yahoo.com>
parents: 45424
diff changeset
    96
    For commands that update a series of commits in the current transaction, the
f7e293e0475f rewriteutil: also consider pending obsoletes when updating hashes in messages
Matt Harbison <matt_harbison@yahoo.com>
parents: 45424
diff changeset
    97
    new obsolete markers can be considered by setting ``pending`` to a mapping
f7e293e0475f rewriteutil: also consider pending obsoletes when updating hashes in messages
Matt Harbison <matt_harbison@yahoo.com>
parents: 45424
diff changeset
    98
    of ``pending[oldnode] = [successor_node1, successor_node2,..]``.
45424
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
    99
    """
45425
f7e293e0475f rewriteutil: also consider pending obsoletes when updating hashes in messages
Matt Harbison <matt_harbison@yahoo.com>
parents: 45424
diff changeset
   100
    if not pending:
f7e293e0475f rewriteutil: also consider pending obsoletes when updating hashes in messages
Matt Harbison <matt_harbison@yahoo.com>
parents: 45424
diff changeset
   101
        pending = {}
45424
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   102
    cache = {}
45427
78861610ded8 rewriteutil: relax the sha1 hash references to handle future hash types
Matt Harbison <matt_harbison@yahoo.com>
parents: 45425
diff changeset
   103
    hashes = re.findall(NODE_RE, commitmsg)
45424
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   104
    unfi = repo.unfiltered()
45427
78861610ded8 rewriteutil: relax the sha1 hash references to handle future hash types
Matt Harbison <matt_harbison@yahoo.com>
parents: 45425
diff changeset
   105
    for h in hashes:
78861610ded8 rewriteutil: relax the sha1 hash references to handle future hash types
Matt Harbison <matt_harbison@yahoo.com>
parents: 45425
diff changeset
   106
        fullnode = scmutil.resolvehexnodeidprefix(unfi, h)
45424
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   107
        if fullnode is None:
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   108
            continue
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   109
        ctx = unfi[fullnode]
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   110
        if not ctx.obsolete():
45425
f7e293e0475f rewriteutil: also consider pending obsoletes when updating hashes in messages
Matt Harbison <matt_harbison@yahoo.com>
parents: 45424
diff changeset
   111
            successors = pending.get(fullnode)
f7e293e0475f rewriteutil: also consider pending obsoletes when updating hashes in messages
Matt Harbison <matt_harbison@yahoo.com>
parents: 45424
diff changeset
   112
            if successors is None:
f7e293e0475f rewriteutil: also consider pending obsoletes when updating hashes in messages
Matt Harbison <matt_harbison@yahoo.com>
parents: 45424
diff changeset
   113
                continue
f7e293e0475f rewriteutil: also consider pending obsoletes when updating hashes in messages
Matt Harbison <matt_harbison@yahoo.com>
parents: 45424
diff changeset
   114
            # obsutil.successorssets() returns a list of list of nodes
f7e293e0475f rewriteutil: also consider pending obsoletes when updating hashes in messages
Matt Harbison <matt_harbison@yahoo.com>
parents: 45424
diff changeset
   115
            successors = [successors]
f7e293e0475f rewriteutil: also consider pending obsoletes when updating hashes in messages
Matt Harbison <matt_harbison@yahoo.com>
parents: 45424
diff changeset
   116
        else:
f7e293e0475f rewriteutil: also consider pending obsoletes when updating hashes in messages
Matt Harbison <matt_harbison@yahoo.com>
parents: 45424
diff changeset
   117
            successors = obsutil.successorssets(repo, ctx.node(), cache=cache)
45424
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   118
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   119
        # We can't make any assumptions about how to update the hash if the
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   120
        # cset in question was split or diverged.
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   121
        if len(successors) == 1 and len(successors[0]) == 1:
45711
3d68b47e461b rewriteutil: handle dropped commits when updating description hashes
Matt Harbison <matt_harbison@yahoo.com>
parents: 45427
diff changeset
   122
            successor = successors[0][0]
3d68b47e461b rewriteutil: handle dropped commits when updating description hashes
Matt Harbison <matt_harbison@yahoo.com>
parents: 45427
diff changeset
   123
            if successor is not None:
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45853
diff changeset
   124
                newhash = hex(successor)
45711
3d68b47e461b rewriteutil: handle dropped commits when updating description hashes
Matt Harbison <matt_harbison@yahoo.com>
parents: 45427
diff changeset
   125
                commitmsg = commitmsg.replace(h, newhash[: len(h)])
3d68b47e461b rewriteutil: handle dropped commits when updating description hashes
Matt Harbison <matt_harbison@yahoo.com>
parents: 45427
diff changeset
   126
            else:
3d68b47e461b rewriteutil: handle dropped commits when updating description hashes
Matt Harbison <matt_harbison@yahoo.com>
parents: 45427
diff changeset
   127
                repo.ui.note(
3d68b47e461b rewriteutil: handle dropped commits when updating description hashes
Matt Harbison <matt_harbison@yahoo.com>
parents: 45427
diff changeset
   128
                    _(
3d68b47e461b rewriteutil: handle dropped commits when updating description hashes
Matt Harbison <matt_harbison@yahoo.com>
parents: 45427
diff changeset
   129
                        b'The stale commit message reference to %s could '
3d68b47e461b rewriteutil: handle dropped commits when updating description hashes
Matt Harbison <matt_harbison@yahoo.com>
parents: 45427
diff changeset
   130
                        b'not be updated\n(The referenced commit was dropped)\n'
3d68b47e461b rewriteutil: handle dropped commits when updating description hashes
Matt Harbison <matt_harbison@yahoo.com>
parents: 45427
diff changeset
   131
                    )
3d68b47e461b rewriteutil: handle dropped commits when updating description hashes
Matt Harbison <matt_harbison@yahoo.com>
parents: 45427
diff changeset
   132
                    % h
3d68b47e461b rewriteutil: handle dropped commits when updating description hashes
Matt Harbison <matt_harbison@yahoo.com>
parents: 45427
diff changeset
   133
                )
45424
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   134
        else:
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   135
            repo.ui.note(
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   136
                _(
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   137
                    b'The stale commit message reference to %s could '
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   138
                    b'not be updated\n'
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   139
                )
45427
78861610ded8 rewriteutil: relax the sha1 hash references to handle future hash types
Matt Harbison <matt_harbison@yahoo.com>
parents: 45425
diff changeset
   140
                % h
45424
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   141
            )
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   142
0a57ef4b3bdb rewriteutil: extract evolve code used to replace obsolete hashes in commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 45122
diff changeset
   143
    return commitmsg