mercurial/subrepoutil.py
author Arseniy Alekseyev <aalekseyev@janestreet.com>
Mon, 15 Apr 2024 16:33:37 +0100
branchstable
changeset 51482 74230abb2504
parent 51461 08913487ae80
child 51714 c6e4fec01775
permissions -rw-r--r--
match: strengthen visit_children_set invariant, Recursive means "all files" My previous interpretation of "Recursive" was too relaxed: I thought it instructed the caller to do something like this: > you can stop calling `visit_children_set` because you'll need to descend into > every directory recursively, but you should still check every file if it > matches or not Whereas the real instruction seems to be: > I guarantee that everything in this subtree matches, you can stop > querying the matcher for all files and dirs altogether. The evidence to support this: - the test actually passes with the stronger invariant, revealing no exceptions from this rule - the implementation of `visit_children_set` for `DifferenceMatcher` clearly relies on this requirement, so it must hold for that not to lead to bugs.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36047
55e8efa2451a subrepo: split non-core functions to new module
Yuya Nishihara <yuya@tcha.org>
parents: 35965
diff changeset
     1
# subrepoutil.py - sub-repository operations and substate handling
8812
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     2
#
46819
d4ba4d51f85f contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents: 46682
diff changeset
     3
# Copyright 2009-2010 Olivia Mackall <olivia@selenic.com>
8812
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     4
#
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 10251
diff changeset
     6
# GNU General Public License version 2 or any later version.
8812
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     7
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
     8
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
     9
import os
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    10
import posixpath
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    11
import re
51302
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    12
import typing
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    13
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    14
from typing import (
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    15
    Any,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    16
    Dict,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    17
    List,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    18
    Optional,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    19
    Set,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    20
    Tuple,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    21
)
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    22
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    23
from .i18n import _
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    24
from . import (
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    25
    config,
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    26
    error,
30060
a145161debed merge: use labels in subrepo merge
Simon Farnsworth <simonfar@fb.com>
parents: 29510
diff changeset
    27
    filemerge,
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    28
    pathutil,
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    29
    phases,
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    30
    util,
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    31
)
46907
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46819
diff changeset
    32
from .utils import (
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46819
diff changeset
    33
    stringutil,
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46819
diff changeset
    34
    urlutil,
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46819
diff changeset
    35
)
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    36
51302
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    37
# keeps pyflakes happy
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    38
assert [
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    39
    Any,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    40
    Dict,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    41
    List,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    42
    Optional,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    43
    Set,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    44
    Tuple,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    45
]
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    46
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    47
nullstate = (b'', b'', b'empty')
8812
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    48
51302
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    49
if typing.TYPE_CHECKING:
46682
eef13b940887 typing: add type annotations to the public methods of mercurial/subrepoutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 46491
diff changeset
    50
    from . import (
eef13b940887 typing: add type annotations to the public methods of mercurial/subrepoutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 46491
diff changeset
    51
        context,
eef13b940887 typing: add type annotations to the public methods of mercurial/subrepoutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 46491
diff changeset
    52
        localrepo,
eef13b940887 typing: add type annotations to the public methods of mercurial/subrepoutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 46491
diff changeset
    53
        match as matchmod,
eef13b940887 typing: add type annotations to the public methods of mercurial/subrepoutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 46491
diff changeset
    54
        scmutil,
eef13b940887 typing: add type annotations to the public methods of mercurial/subrepoutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 46491
diff changeset
    55
        subrepo,
eef13b940887 typing: add type annotations to the public methods of mercurial/subrepoutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 46491
diff changeset
    56
        ui as uimod,
eef13b940887 typing: add type annotations to the public methods of mercurial/subrepoutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 46491
diff changeset
    57
    )
eef13b940887 typing: add type annotations to the public methods of mercurial/subrepoutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 46491
diff changeset
    58
51302
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    59
    # keeps pyflakes happy
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    60
    assert [
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    61
        context,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    62
        localrepo,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    63
        matchmod,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    64
        scmutil,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    65
        subrepo,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    66
        uimod,
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    67
    ]
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    68
9d3721552b6c pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50952
diff changeset
    69
Substate = Dict[bytes, Tuple[bytes, bytes, bytes]]
46682
eef13b940887 typing: add type annotations to the public methods of mercurial/subrepoutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 46491
diff changeset
    70
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    71
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
    72
def state(ctx: "context.changectx", ui: "uimod.ui") -> Substate:
11571
636554d58665 subrepo: docstrings
Mads Kiilerich <mads@kiilerich.com>
parents: 11470
diff changeset
    73
    """return a state dict, mapping subrepo paths configured in .hgsub
636554d58665 subrepo: docstrings
Mads Kiilerich <mads@kiilerich.com>
parents: 11470
diff changeset
    74
    to tuple: (source from .hgsub, revision from .hgsubstate, kind
636554d58665 subrepo: docstrings
Mads Kiilerich <mads@kiilerich.com>
parents: 11470
diff changeset
    75
    (key in types dict))
636554d58665 subrepo: docstrings
Mads Kiilerich <mads@kiilerich.com>
parents: 11470
diff changeset
    76
    """
51306
7bd7fcc711f2 pytype: drop the last inline type comment
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51304
diff changeset
    77
    p: config.config = config.config()
25768
7a9ef8608a1d subrepo: prefetch ctx.repo() for efficiency and centralization
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25660
diff changeset
    78
    repo = ctx.repo()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    79
45281
668af67bfd18 config: remove now-unused `abs` argument from `include` callback
Martin von Zweigbergk <martinvonz@google.com>
parents: 45279
diff changeset
    80
    def read(f, sections=None, remap=None):
8812
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    81
        if f in ctx:
13017
d0e21c5fde41 subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents: 13015
diff changeset
    82
            try:
d0e21c5fde41 subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents: 13015
diff changeset
    83
                data = ctx[f].data()
49314
2e726c934fcd py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents: 49004
diff changeset
    84
            except FileNotFoundError:
13017
d0e21c5fde41 subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents: 13015
diff changeset
    85
                # handle missing subrepo spec files as removed
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    86
                ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    87
                    _(b"warning: subrepo spec file \'%s\' not found\n")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    88
                    % repo.pathto(f)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    89
                )
13017
d0e21c5fde41 subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents: 13015
diff changeset
    90
                return
d0e21c5fde41 subrepo: handle missing subrepo spec file as removed
Patrick Mezard <pmezard@gmail.com>
parents: 13015
diff changeset
    91
            p.parse(f, data, sections, remap, read)
10174
65b6dc44cdbf subrepo: fix includes support in .hgsub
Matt Mackall <mpm@selenic.com>
parents: 10069
diff changeset
    92
        else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    93
            raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    94
                _(b"subrepo spec file \'%s\' not found") % repo.pathto(f)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    95
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    96
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    97
    if b'.hgsub' in ctx:
45281
668af67bfd18 config: remove now-unused `abs` argument from `include` callback
Martin von Zweigbergk <martinvonz@google.com>
parents: 45279
diff changeset
    98
        read(b'.hgsub')
8812
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    99
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   100
    for path, src in ui.configitems(b'subpaths'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   101
        p.set(b'subpaths', path, src, ui.configsource(b'subpaths', path))
11775
a8614c5a5e9a subrepos: support remapping of .hgsub source paths
Martin Geisler <mg@lazybytes.net>
parents: 11572
diff changeset
   102
8812
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   103
    rev = {}
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   104
    if b'.hgsubstate' in ctx:
8812
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   105
        try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   106
            for i, l in enumerate(ctx[b'.hgsubstate'].data().splitlines()):
16595
2de6ac4ac17c subrepo: ignore blank lines in .hgsubstate (issue3424)
Patrick Mezard <patrick@mezard.eu>
parents: 16555
diff changeset
   107
                l = l.lstrip()
2de6ac4ac17c subrepo: ignore blank lines in .hgsubstate (issue3424)
Patrick Mezard <patrick@mezard.eu>
parents: 16555
diff changeset
   108
                if not l:
2de6ac4ac17c subrepo: ignore blank lines in .hgsubstate (issue3424)
Patrick Mezard <patrick@mezard.eu>
parents: 16555
diff changeset
   109
                    continue
16596
95ca6c8b38da subrepo: do not traceback on .hgsubstate parsing errors
Patrick Mezard <patrick@mezard.eu>
parents: 16595
diff changeset
   110
                try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   111
                    revision, path = l.split(b" ", 1)
16596
95ca6c8b38da subrepo: do not traceback on .hgsubstate parsing errors
Patrick Mezard <patrick@mezard.eu>
parents: 16595
diff changeset
   112
                except ValueError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   113
                    raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   114
                        _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   115
                            b"invalid subrepository revision "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   116
                            b"specifier in \'%s\' line %d"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   117
                        )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   118
                        % (repo.pathto(b'.hgsubstate'), (i + 1))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   119
                    )
8812
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   120
                rev[path] = revision
49314
2e726c934fcd py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents: 49004
diff changeset
   121
        except FileNotFoundError:
2e726c934fcd py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents: 49004
diff changeset
   122
            pass
8812
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   123
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   124
    def remap(src: bytes) -> bytes:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   125
        for pattern, repl in p.items(b'subpaths'):
11961
f3075ffa6b30 subrepos: handle backslashes in subpaths
Martin Geisler <mg@lazybytes.net>
parents: 11775
diff changeset
   126
            # Turn r'C:\foo\bar' into r'C:\\foo\\bar' since re.sub
f3075ffa6b30 subrepos: handle backslashes in subpaths
Martin Geisler <mg@lazybytes.net>
parents: 11775
diff changeset
   127
            # does a string decode.
37087
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36715
diff changeset
   128
            repl = stringutil.escapestr(repl)
11961
f3075ffa6b30 subrepos: handle backslashes in subpaths
Martin Geisler <mg@lazybytes.net>
parents: 11775
diff changeset
   129
            # However, we still want to allow back references to go
f3075ffa6b30 subrepos: handle backslashes in subpaths
Martin Geisler <mg@lazybytes.net>
parents: 11775
diff changeset
   130
            # through unharmed, so we turn r'\\1' into r'\1'. Again,
f3075ffa6b30 subrepos: handle backslashes in subpaths
Martin Geisler <mg@lazybytes.net>
parents: 11775
diff changeset
   131
            # extra escapes are needed because re.sub string decodes.
34085
6d21737c35bf py3: fix type of regex literals in subrepo.py
Yuya Nishihara <yuya@tcha.org>
parents: 34040
diff changeset
   132
            repl = re.sub(br'\\\\([0-9]+)', br'\\\1', repl)
11775
a8614c5a5e9a subrepos: support remapping of .hgsub source paths
Martin Geisler <mg@lazybytes.net>
parents: 11572
diff changeset
   133
            try:
a8614c5a5e9a subrepos: support remapping of .hgsub source paths
Martin Geisler <mg@lazybytes.net>
parents: 11572
diff changeset
   134
                src = re.sub(pattern, repl, src, 1)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25658
diff changeset
   135
            except re.error as e:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   136
                raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   137
                    _(b"bad subrepository pattern in %s: %s")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   138
                    % (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   139
                        p.source(b'subpaths', pattern),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   140
                        stringutil.forcebytestr(e),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   141
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   142
                )
15149
eaec9cf91aea subrepo: refactor state function
Martin Geisler <mg@aragost.com>
parents: 15061
diff changeset
   143
        return src
11775
a8614c5a5e9a subrepos: support remapping of .hgsub source paths
Martin Geisler <mg@lazybytes.net>
parents: 11572
diff changeset
   144
15149
eaec9cf91aea subrepo: refactor state function
Martin Geisler <mg@aragost.com>
parents: 15061
diff changeset
   145
    state = {}
51306
7bd7fcc711f2 pytype: drop the last inline type comment
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51304
diff changeset
   146
    for path, src in p.items(b''):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   147
        kind = b'hg'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   148
        if src.startswith(b'['):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   149
            if b']' not in src:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   150
                raise error.Abort(_(b'missing ] in subrepository source'))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   151
            kind, src = src.split(b']', 1)
15149
eaec9cf91aea subrepo: refactor state function
Martin Geisler <mg@aragost.com>
parents: 15061
diff changeset
   152
            kind = kind[1:]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   153
            src = src.lstrip()  # strip any extra whitespace after ']'
15150
91dc8878f888 subrepo: try remapping subpaths using the "final" path
Martin Geisler <mg@aragost.com>
parents: 15149
diff changeset
   154
46907
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46819
diff changeset
   155
        if not urlutil.url(src).isabs():
25768
7a9ef8608a1d subrepo: prefetch ctx.repo() for efficiency and centralization
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25660
diff changeset
   156
            parent = _abssource(repo, abort=False)
15150
91dc8878f888 subrepo: try remapping subpaths using the "final" path
Martin Geisler <mg@aragost.com>
parents: 15149
diff changeset
   157
            if parent:
46907
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46819
diff changeset
   158
                parent = urlutil.url(parent)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   159
                parent.path = posixpath.join(parent.path or b'', src)
15150
91dc8878f888 subrepo: try remapping subpaths using the "final" path
Martin Geisler <mg@aragost.com>
parents: 15149
diff changeset
   160
                parent.path = posixpath.normpath(parent.path)
37586
b94fecf4cd8c py3: use bytes() instead of str() on util.url()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37585
diff changeset
   161
                joined = bytes(parent)
15150
91dc8878f888 subrepo: try remapping subpaths using the "final" path
Martin Geisler <mg@aragost.com>
parents: 15149
diff changeset
   162
                # Remap the full joined path and use it if it changes,
91dc8878f888 subrepo: try remapping subpaths using the "final" path
Martin Geisler <mg@aragost.com>
parents: 15149
diff changeset
   163
                # else remap the original source.
91dc8878f888 subrepo: try remapping subpaths using the "final" path
Martin Geisler <mg@aragost.com>
parents: 15149
diff changeset
   164
                remapped = remap(joined)
91dc8878f888 subrepo: try remapping subpaths using the "final" path
Martin Geisler <mg@aragost.com>
parents: 15149
diff changeset
   165
                if remapped == joined:
91dc8878f888 subrepo: try remapping subpaths using the "final" path
Martin Geisler <mg@aragost.com>
parents: 15149
diff changeset
   166
                    src = remap(src)
91dc8878f888 subrepo: try remapping subpaths using the "final" path
Martin Geisler <mg@aragost.com>
parents: 15149
diff changeset
   167
                else:
91dc8878f888 subrepo: try remapping subpaths using the "final" path
Martin Geisler <mg@aragost.com>
parents: 15149
diff changeset
   168
                    src = remapped
91dc8878f888 subrepo: try remapping subpaths using the "final" path
Martin Geisler <mg@aragost.com>
parents: 15149
diff changeset
   169
15149
eaec9cf91aea subrepo: refactor state function
Martin Geisler <mg@aragost.com>
parents: 15061
diff changeset
   170
        src = remap(src)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   171
        state[util.pconvert(path)] = (src.strip(), rev.get(path, b''), kind)
8812
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   172
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   173
    return state
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   174
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   175
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   176
def writestate(repo: "localrepo.localrepository", state: Substate) -> None:
11571
636554d58665 subrepo: docstrings
Mads Kiilerich <mads@kiilerich.com>
parents: 11470
diff changeset
   177
    """rewrite .hgsubstate in (outer) repo with these subrepo states"""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   178
    lines = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   179
        b'%s %s\n' % (state[s][1], s)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   180
        for s in sorted(state)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   181
        if state[s][1] != nullstate[1]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   182
    ]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   183
    repo.wwrite(b'.hgsubstate', b''.join(lines), b'')
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   184
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   185
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   186
def submerge(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   187
    repo: "localrepo.localrepository",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   188
    wctx: "context.workingctx",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   189
    mctx: "context.changectx",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   190
    actx: "context.changectx",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   191
    overwrite: bool,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   192
    labels: Optional[Any] = None,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   193
) -> Substate:
46682
eef13b940887 typing: add type annotations to the public methods of mercurial/subrepoutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 46491
diff changeset
   194
    # TODO: type the `labels` arg
11571
636554d58665 subrepo: docstrings
Mads Kiilerich <mads@kiilerich.com>
parents: 11470
diff changeset
   195
    """delegated from merge.applyupdates: merging of .hgsubstate file
636554d58665 subrepo: docstrings
Mads Kiilerich <mads@kiilerich.com>
parents: 11470
diff changeset
   196
    in working context, merging context and ancestor context"""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   197
    if mctx == actx:  # backwards?
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   198
        actx = wctx.p1()
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   199
    s1 = wctx.substate
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   200
    s2 = mctx.substate
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   201
    sa = actx.substate
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   202
    sm = {}
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   203
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   204
    repo.ui.debug(b"subrepo merge %s %s %s\n" % (wctx, mctx, actx))
9782
c1c40511c276 subrepo: add more debugging output, lose _ markers
Matt Mackall <mpm@selenic.com>
parents: 9781
diff changeset
   205
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   206
    def debug(s, msg, r=b""):
9779
58a6f3f4d553 subrepo: add some debug output to submerge
Matt Mackall <mpm@selenic.com>
parents: 9752
diff changeset
   207
        if r:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   208
            r = b"%s:%s:%s" % r
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   209
        repo.ui.debug(b"  subrepo %s: %s %s\n" % (s, msg, r))
9779
58a6f3f4d553 subrepo: add some debug output to submerge
Matt Mackall <mpm@selenic.com>
parents: 9752
diff changeset
   210
30891
2915cc1d3429 subrepo: move prompts out of the if (issue5505)
Simon Farnsworth <simonfar@fb.com>
parents: 30755
diff changeset
   211
    promptssrc = filemerge.partextras(labels)
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
   212
    for s, l in sorted(s1.items()):
11470
34e33d50c26b subrepo: correctly handle update -C with modified subrepos (issue2022)
Matt Mackall <mpm@selenic.com>
parents: 11463
diff changeset
   213
        a = sa.get(s, nullstate)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   214
        ld = l  # local state with possible dirty flag for compares
11470
34e33d50c26b subrepo: correctly handle update -C with modified subrepos (issue2022)
Matt Mackall <mpm@selenic.com>
parents: 11463
diff changeset
   215
        if wctx.sub(s).dirty():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   216
            ld = (l[0], l[1] + b"+")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   217
        if wctx == actx:  # overwrite
11470
34e33d50c26b subrepo: correctly handle update -C with modified subrepos (issue2022)
Matt Mackall <mpm@selenic.com>
parents: 11463
diff changeset
   218
            a = ld
11463
f0ea93557133 subrepo: fix recording of + in .hgsubstate (issue2217)
Matt Mackall <mpm@selenic.com>
parents: 11455
diff changeset
   219
30891
2915cc1d3429 subrepo: move prompts out of the if (issue5505)
Simon Farnsworth <simonfar@fb.com>
parents: 30755
diff changeset
   220
        prompts = promptssrc.copy()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   221
        prompts[b's'] = s
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   222
        if s in s2:
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   223
            r = s2[s]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   224
            if ld == r or r == a:  # no change or local is newer
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   225
                sm[s] = l
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   226
                continue
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   227
            elif ld == a:  # other side changed
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   228
                debug(s, b"other changed, get", r)
13322
c19b9282d3a7 subrepo: make update -C clean the working directory for svn subrepos
Erik Zielke <ez@aragost.com>
parents: 13287
diff changeset
   229
                wctx.sub(s).get(r, overwrite)
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   230
                sm[s] = r
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   231
            elif ld[0] != r[0]:  # sources differ
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   232
                prompts[b'lo'] = l[0]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   233
                prompts[b'ro'] = r[0]
9048
86b4a9b0ddda ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents: 8997
diff changeset
   234
                if repo.ui.promptchoice(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   235
                    _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   236
                        b' subrepository sources for %(s)s differ\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   237
                        b'you can use (l)ocal%(l)s source (%(lo)s)'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   238
                        b' or (r)emote%(o)s source (%(ro)s).\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   239
                        b'what do you want to do?'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   240
                        b'$$ &Local $$ &Remote'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   241
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   242
                    % prompts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   243
                    0,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   244
                ):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   245
                    debug(s, b"prompt changed, get", r)
13322
c19b9282d3a7 subrepo: make update -C clean the working directory for svn subrepos
Erik Zielke <ez@aragost.com>
parents: 13287
diff changeset
   246
                    wctx.sub(s).get(r, overwrite)
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   247
                    sm[s] = r
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   248
            elif ld[1] == a[1]:  # local side is unchanged
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   249
                debug(s, b"other side changed, get", r)
13322
c19b9282d3a7 subrepo: make update -C clean the working directory for svn subrepos
Erik Zielke <ez@aragost.com>
parents: 13287
diff changeset
   250
                wctx.sub(s).get(r, overwrite)
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   251
                sm[s] = r
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   252
            else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   253
                debug(s, b"both sides changed")
21401
2c364f7801c8 subrepo: use subrepo shortid method to generate subrepo diverged promptchoice
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21400
diff changeset
   254
                srepo = wctx.sub(s)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   255
                prompts[b'sl'] = srepo.shortid(l[1])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   256
                prompts[b'sr'] = srepo.shortid(r[1])
19811
5e10d41e7b9c merge: let the user choose to merge, keep local or keep remote subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 19788
diff changeset
   257
                option = repo.ui.promptchoice(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   258
                    _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   259
                        b' subrepository %(s)s diverged (local revision: %(sl)s, '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   260
                        b'remote revision: %(sr)s)\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   261
                        b'you can (m)erge, keep (l)ocal%(l)s or keep '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   262
                        b'(r)emote%(o)s.\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   263
                        b'what do you want to do?'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   264
                        b'$$ &Merge $$ &Local $$ &Remote'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   265
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   266
                    % prompts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   267
                    0,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   268
                )
19811
5e10d41e7b9c merge: let the user choose to merge, keep local or keep remote subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 19788
diff changeset
   269
                if option == 0:
5e10d41e7b9c merge: let the user choose to merge, keep local or keep remote subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 19788
diff changeset
   270
                    wctx.sub(s).merge(r)
5e10d41e7b9c merge: let the user choose to merge, keep local or keep remote subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 19788
diff changeset
   271
                    sm[s] = l
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   272
                    debug(s, b"merge with", r)
19811
5e10d41e7b9c merge: let the user choose to merge, keep local or keep remote subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 19788
diff changeset
   273
                elif option == 1:
5e10d41e7b9c merge: let the user choose to merge, keep local or keep remote subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 19788
diff changeset
   274
                    sm[s] = l
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   275
                    debug(s, b"keep local subrepo revision", l)
19811
5e10d41e7b9c merge: let the user choose to merge, keep local or keep remote subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 19788
diff changeset
   276
                else:
5e10d41e7b9c merge: let the user choose to merge, keep local or keep remote subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 19788
diff changeset
   277
                    wctx.sub(s).get(r, overwrite)
5e10d41e7b9c merge: let the user choose to merge, keep local or keep remote subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 19788
diff changeset
   278
                    sm[s] = r
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   279
                    debug(s, b"get remote subrepo revision", r)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   280
        elif ld == a:  # remote removed, local unchanged
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   281
            debug(s, b"remote removed, remove")
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   282
            wctx.sub(s).remove()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   283
        elif a == nullstate:  # not present in remote or ancestor
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   284
            debug(s, b"local added, keep")
14417
25137d99a5ed subrepo: handle local added subrepo case correctly
Matt Mackall <mpm@selenic.com>
parents: 14316
diff changeset
   285
            sm[s] = l
25137d99a5ed subrepo: handle local added subrepo case correctly
Matt Mackall <mpm@selenic.com>
parents: 14316
diff changeset
   286
            continue
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   287
        else:
9048
86b4a9b0ddda ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents: 8997
diff changeset
   288
            if repo.ui.promptchoice(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   289
                _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   290
                    b' local%(l)s changed subrepository %(s)s'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   291
                    b' which remote%(o)s removed\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   292
                    b'use (c)hanged version or (d)elete?'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   293
                    b'$$ &Changed $$ &Delete'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   294
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   295
                % prompts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   296
                0,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   297
            ):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   298
                debug(s, b"prompt remove")
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   299
                wctx.sub(s).remove()
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   300
13857
ba1f98f877ec subrepo: process merge substate in sorted order in submerge()
Adrian Buehlmann <adrian@cadifra.com>
parents: 13771
diff changeset
   301
    for s, r in sorted(s2.items()):
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   302
        if s in s1:
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   303
            continue
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   304
        elif s not in sa:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   305
            debug(s, b"remote added, get", r)
10175
fc32b2fc468e subrepo: load from a context where the subrepo exists
Augie Fackler <durin42@gmail.com>
parents: 10174
diff changeset
   306
            mctx.sub(s).get(r)
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   307
            sm[s] = r
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   308
        elif r != sa[s]:
30891
2915cc1d3429 subrepo: move prompts out of the if (issue5505)
Simon Farnsworth <simonfar@fb.com>
parents: 30755
diff changeset
   309
            prompts = promptssrc.copy()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   310
            prompts[b's'] = s
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   311
            if (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   312
                repo.ui.promptchoice(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   313
                    _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   314
                        b' remote%(o)s changed subrepository %(s)s'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   315
                        b' which local%(l)s removed\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   316
                        b'use (c)hanged version or (d)elete?'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   317
                        b'$$ &Changed $$ &Delete'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   318
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   319
                    % prompts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   320
                    0,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   321
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   322
                == 0
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   323
            ):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   324
                debug(s, b"prompt recreate", r)
24110
756c5c8331b0 subrepo: add tests for change/remove conflicts
Martin von Zweigbergk <martinvonz@google.com>
parents: 23963
diff changeset
   325
                mctx.sub(s).get(r)
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   326
                sm[s] = r
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   327
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   328
    # record merged .hgsubstate
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   329
    writestate(repo, sm)
19637
cc338115d3b2 subrepo: make submerge() return the merged substate
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 19226
diff changeset
   330
    return sm
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   331
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   332
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   333
def precommit(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   334
    ui: "uimod.ui",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   335
    wctx: "context.workingcommitctx",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   336
    status: "scmutil.status",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   337
    match: "matchmod.basematcher",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   338
    force: bool = False,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   339
) -> Tuple[List[bytes], Set[bytes], Substate]:
34977
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   340
    """Calculate .hgsubstate changes that should be applied before committing
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   341
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   342
    Returns (subs, commitsubs, newstate) where
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   343
    - subs: changed subrepos (including dirty ones)
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   344
    - commitsubs: dirty subrepos which the caller needs to commit recursively
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   345
    - newstate: new state dict which the caller must write to .hgsubstate
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   346
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   347
    This also updates the given status argument.
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   348
    """
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   349
    subs = []
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   350
    commitsubs = set()
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   351
    newstate = wctx.substate.copy()
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   352
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   353
    # only manage subrepos and .hgsubstate if .hgsub is present
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   354
    if b'.hgsub' in wctx:
34977
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   355
        # we'll decide whether to track this ourselves, thanks
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   356
        for c in status.modified, status.added, status.removed:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   357
            if b'.hgsubstate' in c:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   358
                c.remove(b'.hgsubstate')
34977
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   359
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   360
        # compare current state to last committed state
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   361
        # build new substate based on last committed state
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   362
        oldstate = wctx.p1().substate
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   363
        for s in sorted(newstate.keys()):
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   364
            if not match(s):
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   365
                # ignore working copy, use old state if present
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   366
                if s in oldstate:
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   367
                    newstate[s] = oldstate[s]
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   368
                    continue
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   369
                if not force:
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   370
                    raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   371
                        _(b"commit with new subrepo %s excluded") % s
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   372
                    )
34977
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   373
            dirtyreason = wctx.sub(s).dirtyreason(True)
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   374
            if dirtyreason:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   375
                if not ui.configbool(b'ui', b'commitsubrepos'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   376
                    raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   377
                        dirtyreason,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   378
                        hint=_(b"use --subrepos for recursive commit"),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   379
                    )
34977
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   380
                subs.append(s)
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   381
                commitsubs.add(s)
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   382
            else:
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   383
                bs = wctx.sub(s).basestate()
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   384
                newstate[s] = (newstate[s][0], bs, newstate[s][2])
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   385
                if oldstate.get(s, (None, None, None))[1] != bs:
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   386
                    subs.append(s)
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   387
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   388
        # check for removed subrepos
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   389
        for p in wctx.parents():
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   390
            r = [s for s in p.substate if s not in newstate]
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   391
            subs += [s for s in r if match(s)]
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   392
        if subs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   393
            if not match(b'.hgsub') and b'.hgsub' in (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   394
                wctx.modified() + wctx.added()
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   395
            ):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   396
                raise error.Abort(_(b"can't commit subrepos without .hgsub"))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   397
            status.modified.insert(0, b'.hgsubstate')
34977
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   398
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   399
    elif b'.hgsub' in status.removed:
34977
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   400
        # clean up .hgsubstate when .hgsub is removed
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   401
        if b'.hgsubstate' in wctx and b'.hgsubstate' not in (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   402
            status.modified + status.added + status.removed
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   403
        ):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   404
            status.removed.insert(0, b'.hgsubstate')
34977
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   405
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   406
    return subs, commitsubs, newstate
5c6b96b832c2 subrepo: extract preprocess of repo.commit() to free function
Yuya Nishihara <yuya@tcha.org>
parents: 34967
diff changeset
   407
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   408
46929
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   409
def repo_rel_or_abs_source(repo):
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   410
    """return the source of this repo
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   411
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   412
    Either absolute or relative the outermost repo"""
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   413
    parent = repo
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   414
    chunks = []
50951
d718eddf01d9 safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50638
diff changeset
   415
    while hasattr(parent, '_subparent'):
46929
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   416
        source = urlutil.url(parent._subsource)
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   417
        chunks.append(bytes(source))
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   418
        if source.isabs():
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   419
            break
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   420
        parent = parent._subparent
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   421
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   422
    chunks.reverse()
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   423
    path = posixpath.join(*chunks)
51461
08913487ae80 subrepo: fix normalizing paths with scheme
Felipe Resende <felipe@fcresende.dev.br>
parents: 51306
diff changeset
   424
    matchscheme = re.compile(b'^[a-zA-Z0-9+.\\-]+:').match
08913487ae80 subrepo: fix normalizing paths with scheme
Felipe Resende <felipe@fcresende.dev.br>
parents: 51306
diff changeset
   425
    if matchscheme(path):
08913487ae80 subrepo: fix normalizing paths with scheme
Felipe Resende <felipe@fcresende.dev.br>
parents: 51306
diff changeset
   426
        scheme, path = path.split(b':', 1)
08913487ae80 subrepo: fix normalizing paths with scheme
Felipe Resende <felipe@fcresende.dev.br>
parents: 51306
diff changeset
   427
        if path.startswith(b'//'):
08913487ae80 subrepo: fix normalizing paths with scheme
Felipe Resende <felipe@fcresende.dev.br>
parents: 51306
diff changeset
   428
            path = path[2:]
08913487ae80 subrepo: fix normalizing paths with scheme
Felipe Resende <felipe@fcresende.dev.br>
parents: 51306
diff changeset
   429
            sep = b'//'
08913487ae80 subrepo: fix normalizing paths with scheme
Felipe Resende <felipe@fcresende.dev.br>
parents: 51306
diff changeset
   430
        else:
08913487ae80 subrepo: fix normalizing paths with scheme
Felipe Resende <felipe@fcresende.dev.br>
parents: 51306
diff changeset
   431
            sep = b''
08913487ae80 subrepo: fix normalizing paths with scheme
Felipe Resende <felipe@fcresende.dev.br>
parents: 51306
diff changeset
   432
        normalized_path = scheme + b':' + sep + posixpath.normpath(path)
08913487ae80 subrepo: fix normalizing paths with scheme
Felipe Resende <felipe@fcresende.dev.br>
parents: 51306
diff changeset
   433
    else:
08913487ae80 subrepo: fix normalizing paths with scheme
Felipe Resende <felipe@fcresende.dev.br>
parents: 51306
diff changeset
   434
        normalized_path = posixpath.normpath(path)
08913487ae80 subrepo: fix normalizing paths with scheme
Felipe Resende <felipe@fcresende.dev.br>
parents: 51306
diff changeset
   435
    return normalized_path
46929
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   436
5a59a0ed0a37 subrepo: introduce a `repo_rel_or_abs_source` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   437
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   438
def reporelpath(repo: "localrepo.localrepository") -> bytes:
24785
39f519be5e65 subrepo: backout 93b0e0db7929 to restore reporelpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24778
diff changeset
   439
    """return path to this (sub)repo as seen from outermost repo"""
39f519be5e65 subrepo: backout 93b0e0db7929 to restore reporelpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24778
diff changeset
   440
    parent = repo
50951
d718eddf01d9 safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50638
diff changeset
   441
    while hasattr(parent, '_subparent'):
24785
39f519be5e65 subrepo: backout 93b0e0db7929 to restore reporelpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24778
diff changeset
   442
        parent = parent._subparent
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   443
    return repo.root[len(pathutil.normasprefix(parent.root)) :]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   444
24785
39f519be5e65 subrepo: backout 93b0e0db7929 to restore reporelpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24778
diff changeset
   445
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   446
def subrelpath(sub: "subrepo.abstractsubrepo") -> bytes:
11571
636554d58665 subrepo: docstrings
Mads Kiilerich <mads@kiilerich.com>
parents: 11470
diff changeset
   447
    """return path to this subrepo as seen from outermost repo"""
24673
105758d1b37b subrepo: add _relpath field to centralize subrelpath logic
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24672
diff changeset
   448
    return sub._relpath
11112
4a9bee613737 subrepo: print paths relative to upper repo root for push/pull/commit
Edouard Gomez <ed.gomez@free.fr>
parents: 11111
diff changeset
   449
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   450
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   451
def _abssource(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   452
    repo: "localrepo.localrepository",
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   453
    push: bool = False,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   454
    abort: bool = True,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   455
) -> Optional[bytes]:
12753
ef5eaf53f4f7 subrepo: abort instead of pushing/pulling to the repo itself
Mads Kiilerich <mads@kiilerich.com>
parents: 12752
diff changeset
   456
    """return pull/push path of repo - either based on parent repo .hgsub info
ef5eaf53f4f7 subrepo: abort instead of pushing/pulling to the repo itself
Mads Kiilerich <mads@kiilerich.com>
parents: 12752
diff changeset
   457
    or on the top repo config. Abort or return None if no source found."""
50951
d718eddf01d9 safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50638
diff changeset
   458
    if hasattr(repo, '_subparent'):
46907
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46819
diff changeset
   459
        source = urlutil.url(repo._subsource)
14766
4f56b7530eab subrepos: be smarter about what's an absolute path (issue2808)
Matt Mackall <mpm@selenic.com>
parents: 14664
diff changeset
   460
        if source.isabs():
35613
991f0be9dc39 py3: use bytes instead of pycompat.bytestr
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35587
diff changeset
   461
            return bytes(source)
13771
ce6227306c9a subrepos: use url.url when normalizing repo paths
Brodie Rao <brodie@bitheap.org>
parents: 13753
diff changeset
   462
        source.path = posixpath.normpath(source.path)
12753
ef5eaf53f4f7 subrepo: abort instead of pushing/pulling to the repo itself
Mads Kiilerich <mads@kiilerich.com>
parents: 12752
diff changeset
   463
        parent = _abssource(repo._subparent, push, abort=False)
ef5eaf53f4f7 subrepo: abort instead of pushing/pulling to the repo itself
Mads Kiilerich <mads@kiilerich.com>
parents: 12752
diff changeset
   464
        if parent:
46907
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46819
diff changeset
   465
            parent = urlutil.url(util.pconvert(parent))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   466
            parent.path = posixpath.join(parent.path or b'', source.path)
13771
ce6227306c9a subrepos: use url.url when normalizing repo paths
Brodie Rao <brodie@bitheap.org>
parents: 13753
diff changeset
   467
            parent.path = posixpath.normpath(parent.path)
35613
991f0be9dc39 py3: use bytes instead of pycompat.bytestr
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35587
diff changeset
   468
            return bytes(parent)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   469
    else:  # recursion reached top repo
35777
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   470
        path = None
50951
d718eddf01d9 safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50638
diff changeset
   471
        if hasattr(repo, '_subtoppath'):
35777
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   472
            path = repo._subtoppath
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   473
        elif push and repo.ui.config(b'paths', b'default-push'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   474
            path = repo.ui.config(b'paths', b'default-push')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   475
        elif repo.ui.config(b'paths', b'default'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   476
            path = repo.ui.config(b'paths', b'default')
35777
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   477
        elif repo.shared():
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   478
            # chop off the .hg component to get the default path form.  This has
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   479
            # already run through vfsmod.vfs(..., realpath=True), so it doesn't
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   480
            # have problems with 'C:'
18510
f254ab6207ae subrepo: use sharepath if available when locating the source repo
Matt Harbison <matt_harbison@yahoo.com>
parents: 18364
diff changeset
   481
            return os.path.dirname(repo.sharedpath)
35777
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   482
        if path:
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   483
            # issue5770: 'C:\' and 'C:' are not equivalent paths.  The former is
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   484
            # as expected: an absolute path to the root of the C: drive.  The
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   485
            # latter is a relative path, and works like so:
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   486
            #
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   487
            #   C:\>cd C:\some\path
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   488
            #   C:\>D:
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   489
            #   D:\>python -c "import os; print os.path.abspath('C:')"
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   490
            #   C:\some\path
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   491
            #
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   492
            #   D:\>python -c "import os; print os.path.abspath('C:relative')"
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   493
            #   C:\some\path\relative
46907
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46819
diff changeset
   494
            if urlutil.hasdriveletter(path):
35777
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   495
                if len(path) == 2 or path[2:3] not in br'\/':
47629
5cf2059d2647 windows: use abspath in subrepoutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46929
diff changeset
   496
                    path = util.abspath(path)
35777
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   497
            return path
0c0689a7565e subrepo: handle 'C:' style paths on the command line (issue5770)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35676
diff changeset
   498
12753
ef5eaf53f4f7 subrepo: abort instead of pushing/pulling to the repo itself
Mads Kiilerich <mads@kiilerich.com>
parents: 12752
diff changeset
   499
    if abort:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   500
        raise error.Abort(_(b"default path for subrepository not found"))
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   501
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   502
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
   503
def newcommitphase(ui: "uimod.ui", ctx: "context.changectx") -> int:
20176
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   504
    commitphase = phases.newcommitphase(ui)
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   505
    substate = getattr(ctx, "substate", None)
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   506
    if not substate:
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   507
        return commitphase
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   508
    check = ui.config(b'phases', b'checksubrepos')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   509
    if check not in (b'ignore', b'follow', b'abort'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   510
        raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   511
            _(b'invalid phases.checksubrepos configuration: %s') % check
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   512
        )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   513
    if check == b'ignore':
20176
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   514
        return commitphase
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   515
    maxphase = phases.public
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   516
    maxsub = None
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   517
    for s in sorted(substate):
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   518
        sub = ctx.sub(s)
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   519
        subphase = sub.phase(substate[s][1])
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   520
        if maxphase < subphase:
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   521
            maxphase = subphase
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   522
            maxsub = s
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   523
    if commitphase < maxphase:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   524
        if check == b'abort':
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   525
            raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   526
                _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   527
                    b"can't commit in %s phase"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   528
                    b" conflicting %s from subrepository %s"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   529
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   530
                % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   531
                    phases.phasenames[commitphase],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   532
                    phases.phasenames[maxphase],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   533
                    maxsub,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   534
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   535
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   536
        ui.warn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   537
            _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   538
                b"warning: changes are committed in"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   539
                b" %s phase from subrepository %s\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   540
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   541
            % (phases.phasenames[maxphase], maxsub)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   542
        )
20176
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   543
        return maxphase
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   544
    return commitphase