mercurial/commit.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Sat, 25 Jul 2020 16:13:32 +0200
changeset 45328 e52031f5e046
parent 45327 6de4c5647db3
child 45329 dcbad0f17d76
permissions -rw-r--r--
commitctx: create the ChangingFiles object directly in the various case No need to compute all data then create the object, we can create it early and directly store data in it. We start simple by moving create higher in the function, but the end goal is to eventually move the creation inside the `_process_files` function to take advantage of the object there.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45203
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
from __future__ import absolute_import
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     7
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     8
import errno
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     9
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    10
from .i18n import _
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    11
from .node import (
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    12
    hex,
45204
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
    13
    nullid,
45203
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    14
    nullrev,
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    15
)
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    16
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    17
from . import (
45204
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
    18
    context,
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
    19
    mergestate,
45203
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    20
    metadata,
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    21
    phases,
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    22
    scmutil,
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    23
    subrepoutil,
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    24
)
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    25
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    26
45233
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45232
diff changeset
    27
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: 45232
diff changeset
    28
    """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: 45232
diff changeset
    29
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45232
diff changeset
    30
    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: 45232
diff changeset
    31
    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: 45232
diff changeset
    32
    """
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45232
diff changeset
    33
    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: 45232
diff changeset
    34
        writechangesetcopy = True
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45232
diff changeset
    35
        writefilecopymeta = True
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45232
diff changeset
    36
    else:
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45232
diff changeset
    37
        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: 45232
diff changeset
    38
        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: 45232
diff changeset
    39
        writechangesetcopy = writecopiesto in (
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45232
diff changeset
    40
            b'changeset-only',
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45232
diff changeset
    41
            b'compatibility',
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45232
diff changeset
    42
        )
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45232
diff changeset
    43
    return writechangesetcopy, writefilecopymeta
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45232
diff changeset
    44
ada51c1b6916 commitctx: move copy meta config reading in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45232
diff changeset
    45
45203
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    46
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
    47
    """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
    48
    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
    49
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    50
    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
    51
    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
    52
    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
    53
    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
    54
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    55
    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
    56
    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
    57
    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
    58
    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
    59
    do so.
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
    repo = repo.unfiltered()
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    62
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    63
    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
    64
    user = ctx.user()
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    65
45238
bd7515273fd6 commitctx: gather more preparation code within the lock context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45237
diff changeset
    66
    with repo.lock(), repo.transaction(b"commit") as tr:
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45251
diff changeset
    67
        mn, files = _prepare_files(tr, ctx, error=error, origctx=origctx)
45203
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    68
45248
4cde23ba076e commitctx: create the new extra dict on its own line
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45247
diff changeset
    69
        extra = ctx.extra().copy()
4cde23ba076e commitctx: create the new extra dict on its own line
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45247
diff changeset
    70
45249
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
    71
        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: 45248
diff changeset
    72
            for name in (
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
    73
                b'p1copies',
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
    74
                b'p2copies',
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
    75
                b'filesadded',
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
    76
                b'filesremoved',
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
    77
            ):
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
    78
                extra.pop(name, None)
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
    79
        if repo.changelog._copiesstorage == b'extra':
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45251
diff changeset
    80
            extra = _extra_with_copies(repo, extra, files)
45249
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
    81
45203
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    82
        # update changelog
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    83
        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
    84
        repo.changelog.delayupdate(tr)
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    85
        n = repo.changelog.add(
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    86
            mn,
45324
6c56277317c2 commitctx: directly pass a ChangingFiles object to changelog.add
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
    87
            files,
45203
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    88
            ctx.description(),
45230
5d0998ccedbb commitctx: stop using weakref proxy for transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45223
diff changeset
    89
            tr,
45203
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    90
            p1.node(),
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    91
            p2.node(),
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    92
            user,
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    93
            ctx.date(),
45248
4cde23ba076e commitctx: create the new extra dict on its own line
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45247
diff changeset
    94
            extra,
45203
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    95
        )
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    96
        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
    97
        repo.hook(
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    98
            b'pretxncommit', throw=True, node=hex(n), parent1=xp1, parent2=xp2,
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    99
        )
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   100
        # 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
   101
        targetphase = subrepoutil.newcommitphase(repo.ui, ctx)
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   102
        if targetphase:
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   103
            # 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
   104
            # 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
   105
            # be compliant anyway
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   106
            #
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   107
            # if minimal phase was 0 we don't need to retract anything
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   108
            phases.registernew(repo, tr, targetphase, [n])
ae5c1a3bc339 commitctx: extract the function in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   109
        return n
45204
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   110
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   111
45239
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   112
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: 45238
diff changeset
   113
    repo = ctx.repo()
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   114
    p1 = ctx.p1()
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   115
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   116
    writechangesetcopy, writefilecopymeta = _write_copy_meta(repo)
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   117
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   118
    if ctx.manifestnode():
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   119
        # 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: 45238
diff changeset
   120
        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: 45238
diff changeset
   121
        mn = ctx.manifestnode()
45328
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45327
diff changeset
   122
        files = metadata.ChangingFiles()
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45327
diff changeset
   123
        files.update_touched(ctx.files())
45239
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   124
        if writechangesetcopy:
45328
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45327
diff changeset
   125
            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: 45327
diff changeset
   126
            files.update_removed(ctx.filesremoved())
45239
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   127
    elif not ctx.files():
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   128
        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: 45238
diff changeset
   129
        mn = p1.manifestnode()
45328
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45327
diff changeset
   130
        files = metadata.ChangingFiles()
45239
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   131
    else:
45328
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45327
diff changeset
   132
        mn, touched, added, removed = _process_files(tr, ctx, error=error)
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45327
diff changeset
   133
        files = metadata.ChangingFiles()
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45327
diff changeset
   134
        files.update_touched(touched)
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45327
diff changeset
   135
        if added:
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45327
diff changeset
   136
            files.update_added(added)
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45327
diff changeset
   137
        if removed:
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45327
diff changeset
   138
            files.update_removed(removed)
45239
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   139
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   140
    if origctx and origctx.manifestnode() == mn:
45328
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45327
diff changeset
   141
        origfiles = origctx.files()
e52031f5e046 commitctx: create the ChangingFiles object directly in the various case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45327
diff changeset
   142
        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: 45327
diff changeset
   143
        files.update_touched(origfiles)
45239
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   144
45326
99614011892b commitctx: directly gather p1 and p2 copies in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45324
diff changeset
   145
    if writechangesetcopy:
99614011892b commitctx: directly gather p1 and p2 copies in `files`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45324
diff changeset
   146
        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: 45324
diff changeset
   147
        files.update_copies_from_p2(ctx.p2copies())
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45251
diff changeset
   148
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45251
diff changeset
   149
    return mn, files
45239
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   150
13814622b3b1 commitctx: extract all the file preparation logic in a new function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45238
diff changeset
   151
45236
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   152
def _process_files(tr, ctx, error=False):
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   153
    repo = ctx.repo()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   154
    p1 = ctx.p1()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   155
    p2 = ctx.p2()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   156
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   157
    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: 45235
diff changeset
   158
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   159
    m1ctx = p1.manifestctx()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   160
    m2ctx = p2.manifestctx()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   161
    mctx = m1ctx.copy()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   162
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   163
    m = mctx.read()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   164
    m1 = m1ctx.read()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   165
    m2 = m2ctx.read()
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   166
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   167
    # check in files
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   168
    added = []
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   169
    filesadded = []
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   170
    removed = list(ctx.removed())
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   171
    touched = []
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   172
    linkrev = len(repo)
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   173
    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: 45235
diff changeset
   174
    uipathfn = scmutil.getuipathfn(repo)
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   175
    for f in sorted(ctx.modified() + ctx.added()):
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   176
        repo.ui.note(uipathfn(f) + b"\n")
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   177
        try:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   178
            fctx = ctx[f]
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   179
            if fctx is None:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   180
                removed.append(f)
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   181
            else:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   182
                added.append(f)
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   183
                m[f], is_touched = _filecommit(
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   184
                    repo, fctx, m1, m2, linkrev, tr, writefilecopymeta,
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   185
                )
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   186
                if is_touched:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   187
                    touched.append(f)
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   188
                    if is_touched == 'added':
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   189
                        filesadded.append(f)
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   190
                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: 45235
diff changeset
   191
        except OSError:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   192
            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: 45235
diff changeset
   193
            raise
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   194
        except IOError as inst:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   195
            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: 45235
diff changeset
   196
            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: 45235
diff changeset
   197
                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: 45235
diff changeset
   198
            raise
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   199
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   200
    # update manifest
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   201
    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: 45235
diff changeset
   202
    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: 45235
diff changeset
   203
    for f in drop:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   204
        del m[f]
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   205
    if p2.rev() != nullrev:
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   206
        rf = metadata.get_removal_filter(ctx, (p1, p2, m1, m2))
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   207
        removed = [f for f in removed if not rf(f)]
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   208
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   209
    touched.extend(removed)
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   210
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   211
    files = touched
45247
e15416c95b25 commitctx: explicitly pass `manifest` to _commit_manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   212
    mn = _commit_manifest(tr, linkrev, ctx, mctx, m, files, added, drop)
45236
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   213
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   214
    return mn, files, filesadded, removed
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   215
0c468fef09b3 commitctx: extract all the manual logic to process the files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45235
diff changeset
   216
45204
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   217
def _filecommit(
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   218
    repo, fctx, manifest1, manifest2, linkrev, tr, includecopymeta,
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   219
):
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   220
    """
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   221
    commit an individual file as part of a larger transaction
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   222
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   223
    input:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   224
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   225
        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: 45203
diff changeset
   226
        manifest1:  manifest of changeset first parent
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   227
        manifest2:  manifest of changeset second parent
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   228
        linkrev:    revision number of the changeset being created
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   229
        tr:         current transation
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   230
        individual: boolean, set to False to skip storing the copy data
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   231
                    (only used by the Google specific feature of using
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   232
                    changeset extra as copy source of truth).
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   233
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   234
    output: (filenode, touched)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   235
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   236
        filenode: the filenode that should be used by this changeset
45223
d056a131c93f commitctx: document the None return for "touched" value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45204
diff changeset
   237
        touched:  one of: None (mean untouched), 'added' or 'modified'
45204
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   238
    """
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   239
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   240
    fname = fctx.path()
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   241
    fparent1 = manifest1.get(fname, nullid)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   242
    fparent2 = manifest2.get(fname, nullid)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   243
    touched = None
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   244
    if fparent1 == fparent2 == nullid:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   245
        touched = 'added'
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   246
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   247
    if isinstance(fctx, context.filectx):
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   248
        # 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: 45203
diff changeset
   249
        # 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: 45203
diff changeset
   250
        # need to create a new file revision in this case.
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   251
        node = fctx.filenode()
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   252
        if node in [fparent1, fparent2]:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   253
            repo.ui.debug(b'reusing %s filelog entry\n' % fname)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   254
            if (
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   255
                fparent1 != nullid and manifest1.flags(fname) != fctx.flags()
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   256
            ) or (
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   257
                fparent2 != nullid and manifest2.flags(fname) != fctx.flags()
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   258
            ):
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   259
                touched = 'modified'
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   260
            return node, touched
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   261
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   262
    flog = repo.file(fname)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   263
    meta = {}
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   264
    cfname = fctx.copysource()
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   265
    fnode = None
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   266
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   267
    if cfname and cfname != fname:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   268
        # 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: 45203
diff changeset
   269
        # file.  This copy data will effectively act as a parent
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   270
        # 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: 45203
diff changeset
   271
        # 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: 45203
diff changeset
   272
        # 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: 45203
diff changeset
   273
        #
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   274
        # 0 --- 1 --- 3   rev1 changes file foo
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   275
        #   \       /     rev2 renames foo to bar and changes it
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   276
        #    \- 2 -/      rev3 should have bar with all changes and
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   277
        #                      should record that bar descends from
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   278
        #                      bar in rev2 and foo in rev1
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   279
        #
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   280
        # this allows this merge to succeed:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   281
        #
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   282
        # 0 --- 1 --- 3   rev4 reverts the content change from rev2
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   283
        #   \       /     merging rev3 and rev4 should use bar@rev2
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   284
        #    \- 2 --- 4        as the merge base
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   285
        #
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   286
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   287
        cnode = manifest1.get(cfname)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   288
        newfparent = fparent2
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   289
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   290
        if manifest2:  # branch merge
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   291
            if fparent2 == nullid or cnode is None:  # copied on remote side
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   292
                if cfname in manifest2:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   293
                    cnode = manifest2[cfname]
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   294
                    newfparent = fparent1
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   295
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   296
        # 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: 45203
diff changeset
   297
        # 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: 45203
diff changeset
   298
        # 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: 45203
diff changeset
   299
        # 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: 45203
diff changeset
   300
        # 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: 45203
diff changeset
   301
        # 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: 45203
diff changeset
   302
        # 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: 45203
diff changeset
   303
        # behavior in this circumstance.
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   304
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   305
        if cnode:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   306
            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: 45203
diff changeset
   307
            if includecopymeta:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   308
                meta[b"copy"] = cfname
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   309
                meta[b"copyrev"] = hex(cnode)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   310
            fparent1, fparent2 = nullid, newfparent
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   311
        else:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   312
            repo.ui.warn(
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   313
                _(
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   314
                    b"warning: can't find ancestor for '%s' "
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   315
                    b"copied from '%s'!\n"
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   316
                )
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   317
                % (fname, cfname)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   318
            )
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   319
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   320
    elif fparent1 == nullid:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   321
        fparent1, fparent2 = fparent2, nullid
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   322
    elif fparent2 != nullid:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   323
        # is one parent an ancestor of the other?
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   324
        fparentancestors = flog.commonancestorsheads(fparent1, fparent2)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   325
        if fparent1 in fparentancestors:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   326
            fparent1, fparent2 = fparent2, nullid
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   327
        elif fparent2 in fparentancestors:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   328
            fparent2 = nullid
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   329
        elif not fparentancestors:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   330
            # TODO: this whole if-else might be simplified much more
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   331
            ms = mergestate.mergestate.read(repo)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   332
            if (
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   333
                fname in ms
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   334
                and ms[fname] == mergestate.MERGE_RECORD_MERGED_OTHER
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   335
            ):
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   336
                fparent1, fparent2 = fparent2, nullid
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   337
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   338
    # is the file changed?
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   339
    text = fctx.data()
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   340
    if fparent2 != nullid or meta or flog.cmp(fparent1, text):
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   341
        if touched is None:  # do not overwrite added
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   342
            touched = 'modified'
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   343
        fnode = flog.add(text, meta, tr, linkrev, fparent1, fparent2)
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   344
    # are just the flags changed during merge?
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   345
    elif fname in manifest1 and manifest1.flags(fname) != fctx.flags():
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   346
        touched = 'modified'
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   347
        fnode = fparent1
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   348
    else:
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   349
        fnode = fparent1
ce9ee81df9ff commitctx: extract _filecommit too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45203
diff changeset
   350
    return fnode, touched
45231
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   351
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   352
45247
e15416c95b25 commitctx: explicitly pass `manifest` to _commit_manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45239
diff changeset
   353
def _commit_manifest(tr, linkrev, ctx, mctx, manifest, files, added, drop):
45231
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   354
    """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: 45230
diff changeset
   355
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   356
    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: 45230
diff changeset
   357
    - 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: 45230
diff changeset
   358
    - 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: 45230
diff changeset
   359
    - 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: 45230
diff changeset
   360
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   361
    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: 45230
diff changeset
   362
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   363
    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: 45230
diff changeset
   364
    """
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   365
    repo = ctx.repo()
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   366
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   367
    md = None
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   368
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   369
    # 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: 45230
diff changeset
   370
    p1 = ctx.p1()
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   371
    p2 = ctx.p2()
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   372
    m1ctx = p1.manifestctx()
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   373
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   374
    m1 = m1ctx.read()
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   375
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   376
    if not files:
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   377
        # 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: 45230
diff changeset
   378
        # 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: 45230
diff changeset
   379
        # 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: 45230
diff changeset
   380
        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: 45230
diff changeset
   381
    if not files and md:
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   382
        repo.ui.debug(
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   383
            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: 45230
diff changeset
   384
            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: 45230
diff changeset
   385
        )
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   386
    if files or md:
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   387
        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: 45230
diff changeset
   388
        # 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: 45230
diff changeset
   389
        # 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: 45230
diff changeset
   390
        # 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: 45230
diff changeset
   391
        # 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: 45230
diff changeset
   392
        # 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: 45230
diff changeset
   393
        # 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: 45230
diff changeset
   394
        # so this is safe.
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   395
        mn = mctx.write(
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   396
            tr,
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   397
            linkrev,
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   398
            p1.manifestnode(),
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   399
            p2.manifestnode(),
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   400
            added,
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   401
            drop,
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   402
            match=repo.narrowmatch(),
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   403
        )
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   404
    else:
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   405
        repo.ui.debug(
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   406
            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: 45230
diff changeset
   407
        )
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   408
        mn = p1.manifestnode()
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   409
f0d4d1343cb4 commitctx: extract the function that commit a new manifest
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45230
diff changeset
   410
    return mn
45249
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
   411
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
   412
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45251
diff changeset
   413
def _extra_with_copies(repo, extra, files):
45249
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
   414
    """encode copy information into a `extra` dictionnary"""
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45251
diff changeset
   415
    p1copies = files.copied_from_p1
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45251
diff changeset
   416
    p2copies = files.copied_from_p2
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45251
diff changeset
   417
    filesadded = files.added
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45251
diff changeset
   418
    filesremoved = files.removed
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45251
diff changeset
   419
    files = sorted(files.touched)
45251
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45250
diff changeset
   420
    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: 45250
diff changeset
   421
        # 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: 45250
diff changeset
   422
        # 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: 45250
diff changeset
   423
        # 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: 45250
diff changeset
   424
        # filelogs.
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45250
diff changeset
   425
        p1copies = p1copies or None
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45250
diff changeset
   426
        p2copies = p2copies or None
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45250
diff changeset
   427
        filesadded = filesadded or None
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45250
diff changeset
   428
        filesremoved = filesremoved or None
0041a42c6f28 commitctx: gather more code dealing with copy-in-extra
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45250
diff changeset
   429
45249
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
   430
    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: 45248
diff changeset
   431
    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: 45248
diff changeset
   432
        extra = {}
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
   433
    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: 45248
diff changeset
   434
        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: 45248
diff changeset
   435
        extra[b'p1copies'] = p1copies
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
   436
    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: 45248
diff changeset
   437
        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: 45248
diff changeset
   438
        extra[b'p2copies'] = p2copies
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
   439
    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: 45248
diff changeset
   440
        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: 45248
diff changeset
   441
        extra[b'filesadded'] = filesadded
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
   442
    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: 45248
diff changeset
   443
        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: 45248
diff changeset
   444
        extra[b'filesremoved'] = filesremoved
b3040b6739ce commitctx: extract copy information encoding into extra into commit.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45248
diff changeset
   445
    return extra