mercurial/commit.py
author Augie Fackler <augie@google.com>
Fri, 25 Mar 2022 11:33:12 -0400
changeset 49062 533820f5b997
parent 48966 6000f5b25c9b
child 49320 fce591256085
permissions -rw-r--r--
merge: with stable
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45239
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     1
# commit.py - fonction to perform commit
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     2
#
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     3
# This software may be used and distributed according to the terms of the
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     4
# GNU General Public License version 2 or any later version.
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     5
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     6
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     7
import errno
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     8
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     9
from .i18n import _
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    10
from .node import (
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    11
    hex,
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    12
    nullrev,
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    13
)
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    14
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    15
from . import (
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
    16
    context,
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
    17
    mergestate,
45239
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    18
    metadata,
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    19
    phases,
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    20
    scmutil,
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    21
    subrepoutil,
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    22
)
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    23
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    24
45260
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    25
def _write_copy_meta(repo):
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    26
    """return a (changelog, filelog) boolean tuple
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    27
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    28
    changelog: copy related information should be stored in the changeset
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    29
    filelof:   copy related information should be written in the file revision
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    30
    """
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    31
    if repo.filecopiesmode == b'changeset-sidedata':
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    32
        writechangesetcopy = True
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    33
        writefilecopymeta = True
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    34
    else:
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    35
        writecopiesto = repo.ui.config(b'experimental', b'copies.write-to')
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    36
        writefilecopymeta = writecopiesto != b'changeset-only'
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    37
        writechangesetcopy = writecopiesto in (
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    38
            b'changeset-only',
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    39
            b'compatibility',
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    40
        )
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    41
    return writechangesetcopy, writefilecopymeta
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    42
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45259
diff changeset
    43
45239
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    44
def commitctx(repo, ctx, error=False, origctx=None):
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    45
    """Add a new revision to the target repository.
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    46
    Revision information is passed via the context argument.
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    47
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    48
    ctx.files() should list all files involved in this commit, i.e.
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    49
    modified/added/removed files. On merge, it may be wider than the
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    50
    ctx.files() to be committed, since any file nodes derived directly
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    51
    from p1 or p2 are excluded from the committed ctx.files().
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    52
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    53
    origctx is for convert to work around the problem that bug
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    54
    fixes to the files list in changesets change hashes. For
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    55
    convert to be the identity, it can pass an origctx and this
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    56
    function will use the same files list when it makes sense to
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    57
    do so.
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    58
    """
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    59
    repo = repo.unfiltered()
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    60
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    61
    p1, p2 = ctx.p1(), ctx.p2()
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    62
    user = ctx.user()
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    63
45265
bd7515273fd6 commitctx: gather more preparation code within the lock context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45264
diff changeset
    64
    with repo.lock(), repo.transaction(b"commit") as tr:
45344
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45277
diff changeset
    65
        mn, files = _prepare_files(tr, ctx, error=error, origctx=origctx)
45239
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    66
45274
4cde23ba076e commitctx: create the new extra dict on its own line
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45273
diff changeset
    67
        extra = ctx.extra().copy()
4cde23ba076e commitctx: create the new extra dict on its own line
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45273
diff changeset
    68
45275
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
    69
        if extra is not None:
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
    70
            for name in (
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
    71
                b'p1copies',
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
    72
                b'p2copies',
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
    73
                b'filesadded',
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
    74
                b'filesremoved',
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
    75
            ):
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
    76
                extra.pop(name, None)
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
    77
        if repo.changelog._copiesstorage == b'extra':
45344
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45277
diff changeset
    78
            extra = _extra_with_copies(repo, extra, files)
45275
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
    79
45756
067707e026b4 commit: don't change phases for preexisting commits
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 45715
diff changeset
    80
        # save the tip to check whether we actually committed anything
067707e026b4 commit: don't change phases for preexisting commits
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 45715
diff changeset
    81
        oldtip = repo.changelog.tiprev()
067707e026b4 commit: don't change phases for preexisting commits
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 45715
diff changeset
    82
45239
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    83
        # update changelog
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    84
        repo.ui.note(_(b"committing changelog\n"))
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    85
        repo.changelog.delayupdate(tr)
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    86
        n = repo.changelog.add(
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    87
            mn,
45345
6c56277317c2 commitctx: directly pass a ChangingFiles object to changelog.add
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45344
diff changeset
    88
            files,
45239
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    89
            ctx.description(),
45257
5d0998ccedbb commitctx: stop using weakref proxy for transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45256
diff changeset
    90
            tr,
45239
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    91
            p1.node(),
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    92
            p2.node(),
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    93
            user,
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    94
            ctx.date(),
45274
4cde23ba076e commitctx: create the new extra dict on its own line
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45273
diff changeset
    95
            extra,
45239
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    96
        )
46431
72f5280e33b6 commit: look-up new revision once
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
    97
        rev = repo[n].rev()
46443
0903d6b9b1df repository: introduce register_changeset callback
Joerg Sonnenberger <joerg@bec.de>
parents: 46431
diff changeset
    98
        if oldtip != repo.changelog.tiprev():
0903d6b9b1df repository: introduce register_changeset callback
Joerg Sonnenberger <joerg@bec.de>
parents: 46431
diff changeset
    99
            repo.register_changeset(rev, repo.changelog.changelogrevision(rev))
0903d6b9b1df repository: introduce register_changeset callback
Joerg Sonnenberger <joerg@bec.de>
parents: 46431
diff changeset
   100
45239
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   101
        xp1, xp2 = p1.hex(), p2 and p2.hex() or b''
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   102
        repo.hook(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45817
diff changeset
   103
            b'pretxncommit',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45817
diff changeset
   104
            throw=True,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45817
diff changeset
   105
            node=hex(n),
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45817
diff changeset
   106
            parent1=xp1,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45817
diff changeset
   107
            parent2=xp2,
45239
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   108
        )
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   109
        # set the new commit is proper phase
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   110
        targetphase = subrepoutil.newcommitphase(repo.ui, ctx)
45756
067707e026b4 commit: don't change phases for preexisting commits
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 45715
diff changeset
   111
067707e026b4 commit: don't change phases for preexisting commits
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 45715
diff changeset
   112
        # prevent unmarking changesets as public on recommit
46431
72f5280e33b6 commit: look-up new revision once
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   113
        waspublic = oldtip == repo.changelog.tiprev() and not repo[rev].phase()
45756
067707e026b4 commit: don't change phases for preexisting commits
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 45715
diff changeset
   114
067707e026b4 commit: don't change phases for preexisting commits
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 45715
diff changeset
   115
        if targetphase and not waspublic:
45239
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   116
            # retract boundary do not alter parent changeset.
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   117
            # if a parent have higher the resulting phase will
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   118
            # be compliant anyway
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   119
            #
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   120
            # if minimal phase was 0 we don't need to retract anything
46431
72f5280e33b6 commit: look-up new revision once
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   121
            phases.registernew(repo, tr, targetphase, [rev])
45239
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   122
        return n
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   123
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   124
45266
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   125
def _prepare_files(tr, ctx, error=False, origctx=None):
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   126
    repo = ctx.repo()
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   127
    p1 = ctx.p1()
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   128
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   129
    writechangesetcopy, writefilecopymeta = _write_copy_meta(repo)
45708
60c46cc28bf4 commit: pass ChangingFiles object as argument to _process_files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45707
diff changeset
   130
    files = metadata.ChangingFiles()
45706
b92887ce8db4 commit: move salvaged calculation a bit earlier in the function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45705
diff changeset
   131
    ms = mergestate.mergestate.read(repo)
b92887ce8db4 commit: move salvaged calculation a bit earlier in the function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45705
diff changeset
   132
    salvaged = _get_salvaged(repo, ms, ctx)
45708
60c46cc28bf4 commit: pass ChangingFiles object as argument to _process_files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45707
diff changeset
   133
    for s in salvaged:
60c46cc28bf4 commit: pass ChangingFiles object as argument to _process_files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45707
diff changeset
   134
        files.mark_salvaged(s)
45266
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   135
48730
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   136
    narrow_files = {}
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   137
    if not ctx.repo().narrowmatch().always():
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   138
        for f, e in ms.allextras().items():
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   139
            action = e.get(b'outside-narrow-merge-action')
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   140
            if action is not None:
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   141
                narrow_files[f] = action
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   142
    if ctx.manifestnode() and not narrow_files:
45266
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   143
        # reuse an existing manifest revision
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   144
        repo.ui.debug(b'reusing known manifest\n')
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   145
        mn = ctx.manifestnode()
45349
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45348
diff changeset
   146
        files.update_touched(ctx.files())
45266
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   147
        if writechangesetcopy:
45349
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45348
diff changeset
   148
            files.update_added(ctx.filesadded())
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45348
diff changeset
   149
            files.update_removed(ctx.filesremoved())
48730
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   150
    elif not ctx.files() and not narrow_files:
45266
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   151
        repo.ui.debug(b'reusing manifest from p1 (no file change)\n')
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   152
        mn = p1.manifestnode()
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   153
    else:
48730
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   154
        mn = _process_files(tr, ctx, ms, files, narrow_files, error=error)
45266
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   155
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   156
    if origctx and origctx.manifestnode() == mn:
45349
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45348
diff changeset
   157
        origfiles = origctx.files()
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45348
diff changeset
   158
        assert files.touched.issubset(origfiles)
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45348
diff changeset
   159
        files.update_touched(origfiles)
45266
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   160
45347
99614011892b commitctx: directly gather p1 and p2 copies in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45345
diff changeset
   161
    if writechangesetcopy:
99614011892b commitctx: directly gather p1 and p2 copies in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45345
diff changeset
   162
        files.update_copies_from_p1(ctx.p1copies())
99614011892b commitctx: directly gather p1 and p2 copies in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45345
diff changeset
   163
        files.update_copies_from_p2(ctx.p2copies())
45344
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45277
diff changeset
   164
45705
61454026fa04 commit: refactor salvage calculation to a different function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45662
diff changeset
   165
    return mn, files
61454026fa04 commit: refactor salvage calculation to a different function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45662
diff changeset
   166
61454026fa04 commit: refactor salvage calculation to a different function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45662
diff changeset
   167
61454026fa04 commit: refactor salvage calculation to a different function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45662
diff changeset
   168
def _get_salvaged(repo, ms, ctx):
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45817
diff changeset
   169
    """returns a list of salvaged files
45705
61454026fa04 commit: refactor salvage calculation to a different function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45662
diff changeset
   170
61454026fa04 commit: refactor salvage calculation to a different function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45662
diff changeset
   171
    returns empty list if config option which process salvaged files are
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45817
diff changeset
   172
    not enabled"""
45705
61454026fa04 commit: refactor salvage calculation to a different function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45662
diff changeset
   173
    salvaged = []
61454026fa04 commit: refactor salvage calculation to a different function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45662
diff changeset
   174
    copy_sd = repo.filecopiesmode == b'changeset-sidedata'
45662
64a4b85c4a00 salvaged: record salvaged in ChangingFiles at commit time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45615
diff changeset
   175
    if copy_sd and len(ctx.parents()) > 1:
64a4b85c4a00 salvaged: record salvaged in ChangingFiles at commit time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45615
diff changeset
   176
        if ms.active():
45715
0428978bca22 mergestate: add `allextras()` to get all extras
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45708
diff changeset
   177
            for fname in sorted(ms.allextras().keys()):
45662
64a4b85c4a00 salvaged: record salvaged in ChangingFiles at commit time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45615
diff changeset
   178
                might_removed = ms.extras(fname).get(b'merge-removal-candidate')
64a4b85c4a00 salvaged: record salvaged in ChangingFiles at commit time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45615
diff changeset
   179
                if might_removed == b'yes':
64a4b85c4a00 salvaged: record salvaged in ChangingFiles at commit time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45615
diff changeset
   180
                    if fname in ctx:
45705
61454026fa04 commit: refactor salvage calculation to a different function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45662
diff changeset
   181
                        salvaged.append(fname)
61454026fa04 commit: refactor salvage calculation to a different function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45662
diff changeset
   182
    return salvaged
45266
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   183
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45265
diff changeset
   184
48730
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   185
def _process_files(tr, ctx, ms, files, narrow_files=None, error=False):
45263
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   186
    repo = ctx.repo()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   187
    p1 = ctx.p1()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   188
    p2 = ctx.p2()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   189
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   190
    writechangesetcopy, writefilecopymeta = _write_copy_meta(repo)
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   191
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   192
    m1ctx = p1.manifestctx()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   193
    m2ctx = p2.manifestctx()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   194
    mctx = m1ctx.copy()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   195
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   196
    m = mctx.read()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   197
    m1 = m1ctx.read()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   198
    m2 = m2ctx.read()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   199
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   200
    # check in files
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   201
    added = []
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   202
    removed = list(ctx.removed())
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   203
    linkrev = len(repo)
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   204
    repo.ui.note(_(b"committing files:\n"))
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   205
    uipathfn = scmutil.getuipathfn(repo)
48730
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   206
    all_files = ctx.modified() + ctx.added()
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   207
    all_files.extend(narrow_files.keys())
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   208
    all_files.sort()
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   209
    for f in all_files:
45263
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   210
        repo.ui.note(uipathfn(f) + b"\n")
48730
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   211
        if f in narrow_files:
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   212
            narrow_action = narrow_files.get(f)
48751
18e69f224e4b narrow: add support for merging add and remove outside of the tracked set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48730
diff changeset
   213
            if narrow_action == mergestate.CHANGE_REMOVED:
18e69f224e4b narrow: add support for merging add and remove outside of the tracked set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48730
diff changeset
   214
                files.mark_removed(f)
18e69f224e4b narrow: add support for merging add and remove outside of the tracked set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48730
diff changeset
   215
                removed.append(f)
18e69f224e4b narrow: add support for merging add and remove outside of the tracked set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48730
diff changeset
   216
            elif narrow_action == mergestate.CHANGE_ADDED:
18e69f224e4b narrow: add support for merging add and remove outside of the tracked set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48730
diff changeset
   217
                files.mark_added(f)
18e69f224e4b narrow: add support for merging add and remove outside of the tracked set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48730
diff changeset
   218
                added.append(f)
18e69f224e4b narrow: add support for merging add and remove outside of the tracked set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48730
diff changeset
   219
                m[f] = m2[f]
18e69f224e4b narrow: add support for merging add and remove outside of the tracked set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48730
diff changeset
   220
                flags = m2ctx.find(f)[1] or b''
18e69f224e4b narrow: add support for merging add and remove outside of the tracked set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48730
diff changeset
   221
                m.setflag(f, flags)
18e69f224e4b narrow: add support for merging add and remove outside of the tracked set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48730
diff changeset
   222
            elif narrow_action == mergestate.CHANGE_MODIFIED:
48730
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   223
                files.mark_touched(f)
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   224
                added.append(f)
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   225
                m[f] = m2[f]
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   226
                flags = m2ctx.find(f)[1] or b''
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   227
                m.setflag(f, flags)
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   228
            else:
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   229
                msg = _(b"corrupted mergestate, unknown narrow action: %b")
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   230
                hint = _(b"restart the merge")
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   231
                raise error.Abort(msg, hint=hint)
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   232
            continue
45263
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   233
        try:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   234
            fctx = ctx[f]
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   235
            if fctx is None:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   236
                removed.append(f)
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   237
            else:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   238
                added.append(f)
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   239
                m[f], is_touched = _filecommit(
45454
037e88d453fa commit: pass mergestate into _filecommit() instead of re-reading it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45443
diff changeset
   240
                    repo, fctx, m1, m2, linkrev, tr, writefilecopymeta, ms
45263
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   241
                )
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   242
                if is_touched:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   243
                    if is_touched == 'added':
45353
54eeb1a0e325 commitctx: directly update the touched and added set of files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45352
diff changeset
   244
                        files.mark_added(f)
45615
094a91a183f1 changing-files: record merged files at commit time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45588
diff changeset
   245
                    elif is_touched == 'merged':
094a91a183f1 changing-files: record merged files at commit time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45588
diff changeset
   246
                        files.mark_merged(f)
45353
54eeb1a0e325 commitctx: directly update the touched and added set of files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45352
diff changeset
   247
                    else:
54eeb1a0e325 commitctx: directly update the touched and added set of files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45352
diff changeset
   248
                        files.mark_touched(f)
45263
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   249
                m.setflag(f, fctx.flags())
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   250
        except OSError:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   251
            repo.ui.warn(_(b"trouble committing %s!\n") % uipathfn(f))
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   252
            raise
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   253
        except IOError as inst:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   254
            errcode = getattr(inst, 'errno', errno.ENOENT)
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   255
            if error or errcode and errcode != errno.ENOENT:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   256
                repo.ui.warn(_(b"trouble committing %s!\n") % uipathfn(f))
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   257
            raise
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   258
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   259
    # update manifest
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   260
    removed = [f for f in removed if f in m1 or f in m2]
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   261
    drop = sorted([f for f in removed if f in m])
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   262
    for f in drop:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   263
        del m[f]
45352
027f3dd76302 commitctx: directly updated the set of removed files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45351
diff changeset
   264
    if p2.rev() == nullrev:
027f3dd76302 commitctx: directly updated the set of removed files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45351
diff changeset
   265
        files.update_removed(removed)
027f3dd76302 commitctx: directly updated the set of removed files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45351
diff changeset
   266
    else:
45263
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   267
        rf = metadata.get_removal_filter(ctx, (p1, p2, m1, m2))
45352
027f3dd76302 commitctx: directly updated the set of removed files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45351
diff changeset
   268
        for f in removed:
027f3dd76302 commitctx: directly updated the set of removed files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45351
diff changeset
   269
            if not rf(f):
027f3dd76302 commitctx: directly updated the set of removed files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45351
diff changeset
   270
                files.mark_removed(f)
45263
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   271
48730
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   272
    mn = _commit_manifest(
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   273
        tr,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   274
        linkrev,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   275
        ctx,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   276
        mctx,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   277
        m,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   278
        files.touched,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   279
        added,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   280
        drop,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   281
        bool(narrow_files),
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   282
    )
45350
dcbad0f17d76 commitctx: move ChangingFiles creation directly inside `_process_files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45349
diff changeset
   283
45708
60c46cc28bf4 commit: pass ChangingFiles object as argument to _process_files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45707
diff changeset
   284
    return mn
45263
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   285
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45262
diff changeset
   286
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   287
def _filecommit(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45817
diff changeset
   288
    repo,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45817
diff changeset
   289
    fctx,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45817
diff changeset
   290
    manifest1,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45817
diff changeset
   291
    manifest2,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45817
diff changeset
   292
    linkrev,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45817
diff changeset
   293
    tr,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45817
diff changeset
   294
    includecopymeta,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45817
diff changeset
   295
    ms,
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   296
):
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   297
    """
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   298
    commit an individual file as part of a larger transaction
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   299
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   300
    input:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   301
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   302
        fctx:       a file context with the content we are trying to commit
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   303
        manifest1:  manifest of changeset first parent
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   304
        manifest2:  manifest of changeset second parent
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   305
        linkrev:    revision number of the changeset being created
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   306
        tr:         current transation
45443
f52b0297acc8 commit: fix a wrong argument name in documentation
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45402
diff changeset
   307
        includecopymeta: boolean, set to False to skip storing the copy data
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   308
                    (only used by the Google specific feature of using
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   309
                    changeset extra as copy source of truth).
45454
037e88d453fa commit: pass mergestate into _filecommit() instead of re-reading it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45443
diff changeset
   310
        ms:         mergestate object
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   311
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   312
    output: (filenode, touched)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   313
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   314
        filenode: the filenode that should be used by this changeset
45256
d056a131c93f commitctx: document the None return for "touched" value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45240
diff changeset
   315
        touched:  one of: None (mean untouched), 'added' or 'modified'
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   316
    """
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   317
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   318
    fname = fctx.path()
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   319
    fparent1 = manifest1.get(fname, repo.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   320
    fparent2 = manifest2.get(fname, repo.nullid)
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   321
    touched = None
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   322
    if fparent1 == fparent2 == repo.nullid:
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   323
        touched = 'added'
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   324
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   325
    if isinstance(fctx, context.filectx):
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   326
        # This block fast path most comparisons which are usually done. It
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   327
        # assumes that bare filectx is used and no merge happened, hence no
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   328
        # need to create a new file revision in this case.
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   329
        node = fctx.filenode()
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   330
        if node in [fparent1, fparent2]:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   331
            repo.ui.debug(b'reusing %s filelog entry\n' % fname)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   332
            if (
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   333
                fparent1 != repo.nullid
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   334
                and manifest1.flags(fname) != fctx.flags()
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   335
            ) or (
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   336
                fparent2 != repo.nullid
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   337
                and manifest2.flags(fname) != fctx.flags()
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   338
            ):
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   339
                touched = 'modified'
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   340
            return node, touched
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   341
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   342
    flog = repo.file(fname)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   343
    meta = {}
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   344
    cfname = fctx.copysource()
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   345
    fnode = None
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   346
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   347
    if cfname and cfname != fname:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   348
        # Mark the new revision of this file as a copy of another
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   349
        # file.  This copy data will effectively act as a parent
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   350
        # of this new revision.  If this is a merge, the first
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   351
        # parent will be the nullid (meaning "look up the copy data")
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   352
        # and the second one will be the other parent.  For example:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   353
        #
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   354
        # 0 --- 1 --- 3   rev1 changes file foo
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   355
        #   \       /     rev2 renames foo to bar and changes it
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   356
        #    \- 2 -/      rev3 should have bar with all changes and
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   357
        #                      should record that bar descends from
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   358
        #                      bar in rev2 and foo in rev1
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   359
        #
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   360
        # this allows this merge to succeed:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   361
        #
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   362
        # 0 --- 1 --- 3   rev4 reverts the content change from rev2
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   363
        #   \       /     merging rev3 and rev4 should use bar@rev2
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   364
        #    \- 2 --- 4        as the merge base
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   365
        #
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   366
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   367
        cnode = manifest1.get(cfname)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   368
        newfparent = fparent2
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   369
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   370
        if manifest2:  # branch merge
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   371
            if (
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   372
                fparent2 == repo.nullid or cnode is None
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   373
            ):  # copied on remote side
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   374
                if cfname in manifest2:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   375
                    cnode = manifest2[cfname]
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   376
                    newfparent = fparent1
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   377
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   378
        # Here, we used to search backwards through history to try to find
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   379
        # where the file copy came from if the source of a copy was not in
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   380
        # the parent directory. However, this doesn't actually make sense to
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   381
        # do (what does a copy from something not in your working copy even
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   382
        # mean?) and it causes bugs (eg, issue4476). Instead, we will warn
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   383
        # the user that copy information was dropped, so if they didn't
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   384
        # expect this outcome it can be fixed, but this is the correct
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   385
        # behavior in this circumstance.
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   386
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   387
        if cnode:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   388
            repo.ui.debug(b" %s: copy %s:%s\n" % (fname, cfname, hex(cnode)))
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   389
            if includecopymeta:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   390
                meta[b"copy"] = cfname
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   391
                meta[b"copyrev"] = hex(cnode)
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   392
            fparent1, fparent2 = repo.nullid, newfparent
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   393
        else:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   394
            repo.ui.warn(
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   395
                _(
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   396
                    b"warning: can't find ancestor for '%s' "
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   397
                    b"copied from '%s'!\n"
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   398
                )
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   399
                % (fname, cfname)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   400
            )
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   401
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   402
    elif fparent1 == repo.nullid:
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   403
        fparent1, fparent2 = fparent2, repo.nullid
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   404
    elif fparent2 != repo.nullid:
46386
d6fa9fbd375d commit: reorder if-else conditional to give mergestate info priority
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45957
diff changeset
   405
        if ms.active() and ms.extras(fname).get(b'filenode-source') == b'other':
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   406
            fparent1, fparent2 = fparent2, repo.nullid
46811
5a0b930cfb3e commit: get info from mergestate whether a file was merged or not
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46796
diff changeset
   407
        elif ms.active() and ms.extras(fname).get(b'merged') != b'yes':
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   408
            fparent1, fparent2 = fparent1, repo.nullid
46386
d6fa9fbd375d commit: reorder if-else conditional to give mergestate info priority
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45957
diff changeset
   409
        # is one parent an ancestor of the other?
d6fa9fbd375d commit: reorder if-else conditional to give mergestate info priority
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45957
diff changeset
   410
        else:
d6fa9fbd375d commit: reorder if-else conditional to give mergestate info priority
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45957
diff changeset
   411
            fparentancestors = flog.commonancestorsheads(fparent1, fparent2)
d6fa9fbd375d commit: reorder if-else conditional to give mergestate info priority
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45957
diff changeset
   412
            if fparent1 in fparentancestors:
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   413
                fparent1, fparent2 = fparent2, repo.nullid
46386
d6fa9fbd375d commit: reorder if-else conditional to give mergestate info priority
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45957
diff changeset
   414
            elif fparent2 in fparentancestors:
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   415
                fparent2 = repo.nullid
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   416
45588
479cce8c9882 commit: force create a new filenode if it was set in mergestate by merge
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45454
diff changeset
   417
    force_new_node = False
479cce8c9882 commit: force create a new filenode if it was set in mergestate by merge
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45454
diff changeset
   418
    # The file might have been deleted by merge code and user explicitly choose
479cce8c9882 commit: force create a new filenode if it was set in mergestate by merge
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45454
diff changeset
   419
    # to revert the file and keep it. The other case can be where there is
479cce8c9882 commit: force create a new filenode if it was set in mergestate by merge
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45454
diff changeset
   420
    # change-delete or delete-change conflict and user explicitly choose to keep
479cce8c9882 commit: force create a new filenode if it was set in mergestate by merge
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45454
diff changeset
   421
    # the file. The goal is to create a new filenode for users explicit choices
479cce8c9882 commit: force create a new filenode if it was set in mergestate by merge
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45454
diff changeset
   422
    if (
479cce8c9882 commit: force create a new filenode if it was set in mergestate by merge
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45454
diff changeset
   423
        repo.ui.configbool(b'experimental', b'merge-track-salvaged')
479cce8c9882 commit: force create a new filenode if it was set in mergestate by merge
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45454
diff changeset
   424
        and ms.active()
479cce8c9882 commit: force create a new filenode if it was set in mergestate by merge
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45454
diff changeset
   425
        and ms.extras(fname).get(b'merge-removal-candidate') == b'yes'
479cce8c9882 commit: force create a new filenode if it was set in mergestate by merge
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45454
diff changeset
   426
    ):
479cce8c9882 commit: force create a new filenode if it was set in mergestate by merge
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45454
diff changeset
   427
        force_new_node = True
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   428
    # is the file changed?
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   429
    text = fctx.data()
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   430
    if (
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   431
        fparent2 != repo.nullid
47876
5b9de38a0356 narrow: fix commits of empty files
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 47055
diff changeset
   432
        or fparent1 == repo.nullid
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   433
        or meta
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   434
        or flog.cmp(fparent1, text)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   435
        or force_new_node
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   436
    ):
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   437
        if touched is None:  # do not overwrite added
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46811
diff changeset
   438
            if fparent2 == repo.nullid:
45615
094a91a183f1 changing-files: record merged files at commit time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45588
diff changeset
   439
                touched = 'modified'
094a91a183f1 changing-files: record merged files at commit time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45588
diff changeset
   440
            else:
094a91a183f1 changing-files: record merged files at commit time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45588
diff changeset
   441
                touched = 'merged'
45240
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   442
        fnode = flog.add(text, meta, tr, linkrev, fparent1, fparent2)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   443
    # are just the flags changed during merge?
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   444
    elif fname in manifest1 and manifest1.flags(fname) != fctx.flags():
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   445
        touched = 'modified'
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   446
        fnode = fparent1
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   447
    else:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   448
        fnode = fparent1
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   449
    return fnode, touched
45258
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   450
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   451
48730
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   452
def _commit_manifest(
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   453
    tr,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   454
    linkrev,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   455
    ctx,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   456
    mctx,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   457
    manifest,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   458
    files,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   459
    added,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   460
    drop,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   461
    has_some_narrow_action=False,
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   462
):
45258
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   463
    """make a new manifest entry (or reuse a new one)
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   464
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   465
    given an initialised manifest context and precomputed list of
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   466
    - files: files affected by the commit
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   467
    - added: new entries in the manifest
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   468
    - drop:  entries present in parents but absent of this one
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   469
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   470
    Create a new manifest revision, reuse existing ones if possible.
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   471
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   472
    Return the nodeid of the manifest revision.
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   473
    """
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   474
    repo = ctx.repo()
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   475
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   476
    md = None
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   477
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   478
    # all this is cached, so it is find to get them all from the ctx.
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   479
    p1 = ctx.p1()
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   480
    p2 = ctx.p2()
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   481
    m1ctx = p1.manifestctx()
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   482
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   483
    m1 = m1ctx.read()
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   484
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   485
    if not files:
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   486
        # if no "files" actually changed in terms of the changelog,
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   487
        # try hard to detect unmodified manifest entry so that the
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   488
        # exact same commit can be reproduced later on convert.
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   489
        md = m1.diff(manifest, scmutil.matchfiles(repo, ctx.files()))
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   490
    if not files and md:
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   491
        repo.ui.debug(
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   492
            b'not reusing manifest (no file change in '
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   493
            b'changelog, but manifest differs)\n'
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   494
        )
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   495
    if files or md:
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   496
        repo.ui.note(_(b"committing manifest\n"))
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   497
        # we're using narrowmatch here since it's already applied at
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   498
        # other stages (such as dirstate.walk), so we're already
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   499
        # ignoring things outside of narrowspec in most cases. The
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   500
        # one case where we might have files outside the narrowspec
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   501
        # at this point is merges, and we already error out in the
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   502
        # case where the merge has files outside of the narrowspec,
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   503
        # so this is safe.
48730
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   504
        if has_some_narrow_action:
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   505
            match = None
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   506
        else:
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   507
            match = repo.narrowmatch()
45258
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   508
        mn = mctx.write(
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   509
            tr,
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   510
            linkrev,
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   511
            p1.manifestnode(),
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   512
            p2.manifestnode(),
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   513
            added,
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   514
            drop,
48730
f1eb77dceb36 narrow: allow merging non-conflicting change outside of the narrow spec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47876
diff changeset
   515
            match=match,
45258
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   516
        )
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   517
    else:
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   518
        repo.ui.debug(
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   519
            b'reusing manifest from p1 (listed files ' b'actually unchanged)\n'
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   520
        )
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   521
        mn = p1.manifestnode()
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   522
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45257
diff changeset
   523
    return mn
45275
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   524
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   525
45344
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45277
diff changeset
   526
def _extra_with_copies(repo, extra, files):
45275
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   527
    """encode copy information into a `extra` dictionnary"""
45344
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45277
diff changeset
   528
    p1copies = files.copied_from_p1
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45277
diff changeset
   529
    p2copies = files.copied_from_p2
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45277
diff changeset
   530
    filesadded = files.added
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45277
diff changeset
   531
    filesremoved = files.removed
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45277
diff changeset
   532
    files = sorted(files.touched)
45277
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45276
diff changeset
   533
    if not _write_copy_meta(repo)[1]:
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45276
diff changeset
   534
        # If writing only to changeset extras, use None to indicate that
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45276
diff changeset
   535
        # no entry should be written. If writing to both, write an empty
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45276
diff changeset
   536
        # entry to prevent the reader from falling back to reading
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45276
diff changeset
   537
        # filelogs.
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45276
diff changeset
   538
        p1copies = p1copies or None
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45276
diff changeset
   539
        p2copies = p2copies or None
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45276
diff changeset
   540
        filesadded = filesadded or None
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45276
diff changeset
   541
        filesremoved = filesremoved or None
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45276
diff changeset
   542
45275
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   543
    extrasentries = p1copies, p2copies, filesadded, filesremoved
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   544
    if extra is None and any(x is not None for x in extrasentries):
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   545
        extra = {}
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   546
    if p1copies is not None:
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   547
        p1copies = metadata.encodecopies(files, p1copies)
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   548
        extra[b'p1copies'] = p1copies
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   549
    if p2copies is not None:
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   550
        p2copies = metadata.encodecopies(files, p2copies)
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   551
        extra[b'p2copies'] = p2copies
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   552
    if filesadded is not None:
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   553
        filesadded = metadata.encodefileindices(files, filesadded)
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   554
        extra[b'filesadded'] = filesadded
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   555
    if filesremoved is not None:
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   556
        filesremoved = metadata.encodefileindices(files, filesremoved)
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   557
        extra[b'filesremoved'] = filesremoved
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45274
diff changeset
   558
    return extra