mercurial/subrepo.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Sat, 04 Feb 2023 12:14:19 +0100
changeset 50045 bbe3a65bbd96
parent 49392 b9fcf54030d7
child 50046 2264e775512b
permissions -rw-r--r--
subrepo: let black expand some call on multiple lines early newer version of black are righfully doing this, so I apply it before more semantic change to reduce noise in the next changeset.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36009
55e8efa2451a subrepo: split non-core functions to new module
Yuya Nishihara <yuya@tcha.org>
parents: 35925
diff changeset
     1
# subrepo.py - sub-repository classes and factory
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: 46794
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
23540
f274d27f1994 addremove: automatically process a subrepository's subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 23537
diff changeset
     9
import copy
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    10
import errno
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    11
import os
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    12
import re
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    13
import stat
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    14
import subprocess
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    15
import sys
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    16
import tarfile
19788
c26690fe5f08 subrepo: move import of xml.minidom.dom to its own line for check-code
Augie Fackler <raf@durin42.com>
parents: 19637
diff changeset
    17
import xml.dom.minidom
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    18
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    19
from .i18n import _
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
    20
from .node import (
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
    21
    bin,
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
    22
    hex,
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
    23
    short,
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
    24
)
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    25
from . import (
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    26
    cmdutil,
30635
a150173da1c1 py3: replace os.environ with encoding.environ (part 2 of 5)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30615
diff changeset
    27
    encoding,
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    28
    error,
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    29
    exchange,
35888
c8e2d6ed1f9e cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35777
diff changeset
    30
    logcmdutil,
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    31
    match as matchmod,
45556
03726f5b6092 merge: use merge.clean_update() when applicable
Martin von Zweigbergk <martinvonz@google.com>
parents: 45375
diff changeset
    32
    merge as merge,
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    33
    pathutil,
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    34
    phases,
30615
bb77654dc7ae py3: replace os.sep with pycompat.ossep (part 3 of 4)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30060
diff changeset
    35
    pycompat,
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    36
    scmutil,
36009
55e8efa2451a subrepo: split non-core functions to new module
Yuya Nishihara <yuya@tcha.org>
parents: 35925
diff changeset
    37
    subrepoutil,
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    38
    util,
31236
8a0687a2be75 vfs: use 'vfs' module directly in 'mercurial.subrepo'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31102
diff changeset
    39
    vfs as vfsmod,
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    40
)
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36939
diff changeset
    41
from .utils import (
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36939
diff changeset
    42
    dateutil,
44060
a61287a95dc3 core: migrate uses of hashlib.sha1 to hashutil.sha1
Augie Fackler <augie@google.com>
parents: 44009
diff changeset
    43
    hashutil,
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37084
diff changeset
    44
    procutil,
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
    45
    urlutil,
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36939
diff changeset
    46
)
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
    47
9092
9aebeea7ac00 subrepo: use hg.repository instead of creating localrepo directly
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 9049
diff changeset
    48
hg = None
36009
55e8efa2451a subrepo: split non-core functions to new module
Yuya Nishihara <yuya@tcha.org>
parents: 35925
diff changeset
    49
reporelpath = subrepoutil.reporelpath
55e8efa2451a subrepo: split non-core functions to new module
Yuya Nishihara <yuya@tcha.org>
parents: 35925
diff changeset
    50
subrelpath = subrepoutil.subrelpath
55e8efa2451a subrepo: split non-core functions to new module
Yuya Nishihara <yuya@tcha.org>
parents: 35925
diff changeset
    51
_abssource = subrepoutil._abssource
14050
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 14025
diff changeset
    52
propertycache = util.propertycache
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
    53
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    54
18940
798bdb7f1517 subrepo: do not push mercurial subrepos whose store is clean
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18939
diff changeset
    55
def _expandedabspath(path):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
    56
    """
18940
798bdb7f1517 subrepo: do not push mercurial subrepos whose store is clean
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18939
diff changeset
    57
    get a path or url and if it is a path expand it and return an absolute path
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
    58
    """
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
    59
    expandedpath = urlutil.urllocalpath(util.expandpath(path))
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46819
diff changeset
    60
    u = urlutil.url(expandedpath)
18940
798bdb7f1517 subrepo: do not push mercurial subrepos whose store is clean
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18939
diff changeset
    61
    if not u.scheme:
47628
a125cbbc5782 windows: use abspath in subrepo
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
    62
        path = util.normpath(util.abspath(u.path))
18940
798bdb7f1517 subrepo: do not push mercurial subrepos whose store is clean
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18939
diff changeset
    63
    return path
18936
1fa4edb8456e subrepo: introduce storeclean helper functions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18851
diff changeset
    64
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    65
18936
1fa4edb8456e subrepo: introduce storeclean helper functions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18851
diff changeset
    66
def _getstorehashcachename(remotepath):
1fa4edb8456e subrepo: introduce storeclean helper functions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18851
diff changeset
    67
    '''get a unique filename for the store hash cache of a remote repository'''
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
    68
    return hex(hashutil.sha1(_expandedabspath(remotepath)).digest())[0:12]
18936
1fa4edb8456e subrepo: introduce storeclean helper functions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18851
diff changeset
    69
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    70
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
    71
class SubrepoAbort(error.Abort):
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
    72
    """Exception class used to avoid handling a subrepo error more than once"""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    73
18263
9aa6bee6e9f9 subrepo: add subrepo property to SubrepoAbort exceptions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18109
diff changeset
    74
    def __init__(self, *args, **kw):
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
    75
        self.subrepo = kw.pop('subrepo', None)
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
    76
        self.cause = kw.pop('cause', None)
18296
a74101cd6965 subrepo: fix python2.4 compatibility after 9aa6bee6e9f9
Brendan Cully <brendan@kublai.com>
parents: 18263
diff changeset
    77
        error.Abort.__init__(self, *args, **kw)
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
    78
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    79
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
    80
def annotatesubrepoerror(func):
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
    81
    def decoratedmethod(self, *args, **kargs):
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
    82
        try:
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
    83
            res = func(self, *args, **kargs)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25658
diff changeset
    84
        except SubrepoAbort as ex:
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
    85
            # This exception has already been handled
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
    86
            raise ex
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25658
diff changeset
    87
        except error.Abort as ex:
18263
9aa6bee6e9f9 subrepo: add subrepo property to SubrepoAbort exceptions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18109
diff changeset
    88
            subrepo = subrelpath(self)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    89
            errormsg = (
45682
d2e1dcd4490d errors: name arguments to Abort constructor
Martin von Zweigbergk <martinvonz@google.com>
parents: 45577
diff changeset
    90
                ex.message + b' ' + _(b'(in subrepository "%s")') % subrepo
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    91
            )
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
    92
            # avoid handling this exception by raising a SubrepoAbort exception
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    93
            raise SubrepoAbort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    94
                errormsg, hint=ex.hint, subrepo=subrepo, cause=sys.exc_info()
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    95
            )
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
    96
        return res
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
    97
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
    98
    return decoratedmethod
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
    99
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   100
13417
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   101
def _updateprompt(ui, sub, dirty, local, remote):
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   102
    if dirty:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   103
        msg = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   104
            b' subrepository sources for %s differ\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   105
            b'you can use (l)ocal source (%s) or (r)emote source (%s).\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   106
            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
   107
            b'$$ &Local $$ &Remote'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   108
        ) % (subrelpath(sub), local, remote)
13417
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   109
    else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   110
        msg = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   111
            b' subrepository sources for %s differ (in checked out '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   112
            b'version)\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   113
            b'you can use (l)ocal source (%s) or (r)emote source (%s).\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   114
            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
   115
            b'$$ &Local $$ &Remote'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   116
        ) % (subrelpath(sub), local, remote)
19226
c58b6ab4c26f ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents: 19156
diff changeset
   117
    return ui.promptchoice(msg, 0)
13417
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   118
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   119
24724
95eb067b2b5e subrepo: pass wvfs to _sanitize instead of absolute path to a subrepository
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24695
diff changeset
   120
def _sanitize(ui, vfs, ignore):
24726
747748766421 subrepo: use vfs.walk instead of os.walk
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24724
diff changeset
   121
    for dirname, dirs, names in vfs.walk():
21567
5900bc09e684 subrepo: avoid sanitizing ".hg/hgrc" in meta data area for non-hg subrepos
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21566
diff changeset
   122
        for i, d in enumerate(dirs):
5900bc09e684 subrepo: avoid sanitizing ".hg/hgrc" in meta data area for non-hg subrepos
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21566
diff changeset
   123
            if d.lower() == ignore:
5900bc09e684 subrepo: avoid sanitizing ".hg/hgrc" in meta data area for non-hg subrepos
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21566
diff changeset
   124
                del dirs[i]
5900bc09e684 subrepo: avoid sanitizing ".hg/hgrc" in meta data area for non-hg subrepos
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21566
diff changeset
   125
                break
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   126
        if vfs.basename(dirname).lower() != b'.hg':
21564
2e91d4964ecd subrepo: make "_sanitize()" work
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
   127
            continue
20104
224e96078708 subrepo: sanitize non-hg subrepos
Matt Mackall <mpm@selenic.com>
parents: 19811
diff changeset
   128
        for f in names:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   129
            if f.lower() == b'hgrc':
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   130
                ui.warn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   131
                    _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   132
                        b"warning: removing potentially hostile 'hgrc' "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   133
                        b"in '%s'\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   134
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   135
                    % vfs.join(dirname)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   136
                )
24726
747748766421 subrepo: use vfs.walk instead of os.walk
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24724
diff changeset
   137
                vfs.unlink(vfs.reljoin(dirname, f))
20104
224e96078708 subrepo: sanitize non-hg subrepos
Matt Mackall <mpm@selenic.com>
parents: 19811
diff changeset
   138
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   139
34984
071cbeba4212 subrepo: disallow symlink traversal across subrepo mount point (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 34879
diff changeset
   140
def _auditsubrepopath(repo, path):
41458
83377b4b4ae0 subrepo: reject potentially unsafe subrepo paths (BC) (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 41457
diff changeset
   141
    # sanity check for potentially unsafe paths such as '~' and '$FOO'
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   142
    if path.startswith(b'~') or b'$' in path or util.expandpath(path) != path:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   143
        raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   144
            _(b'subrepo path contains illegal component: %s') % path
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   145
        )
34984
071cbeba4212 subrepo: disallow symlink traversal across subrepo mount point (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 34879
diff changeset
   146
    # auditor doesn't check if the path itself is a symlink
071cbeba4212 subrepo: disallow symlink traversal across subrepo mount point (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 34879
diff changeset
   147
    pathutil.pathauditor(repo.root)(path)
071cbeba4212 subrepo: disallow symlink traversal across subrepo mount point (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 34879
diff changeset
   148
    if repo.wvfs.islink(path):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   149
        raise error.Abort(_(b"subrepo '%s' traverses symbolic link") % path)
34984
071cbeba4212 subrepo: disallow symlink traversal across subrepo mount point (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 34879
diff changeset
   150
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   151
34989
1a314176da9c subrepo: use per-type config options to enable subrepos
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34987
diff changeset
   152
SUBREPO_ALLOWED_DEFAULTS = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   153
    b'hg': True,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   154
    b'git': False,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   155
    b'svn': False,
34989
1a314176da9c subrepo: use per-type config options to enable subrepos
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34987
diff changeset
   156
}
1a314176da9c subrepo: use per-type config options to enable subrepos
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34987
diff changeset
   157
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   158
34985
5e27afeddaee subrepo: add config option to reject any subrepo operations (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 34984
diff changeset
   159
def _checktype(ui, kind):
34989
1a314176da9c subrepo: use per-type config options to enable subrepos
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34987
diff changeset
   160
    # subrepos.allowed is a master kill switch. If disabled, subrepos are
1a314176da9c subrepo: use per-type config options to enable subrepos
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34987
diff changeset
   161
    # disabled period.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   162
    if not ui.configbool(b'subrepos', b'allowed', True):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   163
        raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   164
            _(b'subrepos not enabled'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   165
            hint=_(b"see 'hg help config.subrepos' for details"),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   166
        )
34989
1a314176da9c subrepo: use per-type config options to enable subrepos
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34987
diff changeset
   167
1a314176da9c subrepo: use per-type config options to enable subrepos
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34987
diff changeset
   168
    default = SUBREPO_ALLOWED_DEFAULTS.get(kind, False)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   169
    if not ui.configbool(b'subrepos', b'%s:allowed' % kind, default):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   170
        raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   171
            _(b'%s subrepos not allowed') % kind,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   172
            hint=_(b"see 'hg help config.subrepos' for details"),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   173
        )
34989
1a314176da9c subrepo: use per-type config options to enable subrepos
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34987
diff changeset
   174
34985
5e27afeddaee subrepo: add config option to reject any subrepo operations (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 34984
diff changeset
   175
    if kind not in types:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   176
        raise error.Abort(_(b'unknown subrepo type %s') % kind)
34985
5e27afeddaee subrepo: add config option to reject any subrepo operations (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 34984
diff changeset
   177
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   178
29021
92d37fb3f1aa verify: don't init subrepo when missing one is referenced (issue5128) (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 28949
diff changeset
   179
def subrepo(ctx, path, allowwdir=False, allowcreate=True):
11571
636554d58665 subrepo: docstrings
Mads Kiilerich <mads@kiilerich.com>
parents: 11470
diff changeset
   180
    """return instance of the right subrepo class for subrepo in path"""
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   181
    # subrepo inherently violates our import layering rules
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   182
    # because it wants to make repo objects from deep inside the stack
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   183
    # so we manually delay the circular imports to not break
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   184
    # scripts that don't use our demand-loading
9092
9aebeea7ac00 subrepo: use hg.repository instead of creating localrepo directly
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 9049
diff changeset
   185
    global hg
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
   186
    from . import hg as h
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   187
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   188
    hg = h
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   189
34985
5e27afeddaee subrepo: add config option to reject any subrepo operations (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 34984
diff changeset
   190
    repo = ctx.repo()
5e27afeddaee subrepo: add config option to reject any subrepo operations (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 34984
diff changeset
   191
    _auditsubrepopath(repo, path)
16756
2e3513e7348a subrepo: make subrepo.subrepo(<not a subrepo path>) fail
Dov Feldstern <dfeldstern@gmail.com>
parents: 16683
diff changeset
   192
    state = ctx.substate[path]
34985
5e27afeddaee subrepo: add config option to reject any subrepo operations (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 34984
diff changeset
   193
    _checktype(repo.ui, state[2])
25600
70ac1868b707 subrepo: allow a representation of the working directory subrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 25591
diff changeset
   194
    if allowwdir:
70ac1868b707 subrepo: allow a representation of the working directory subrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 25591
diff changeset
   195
        state = (state[0], ctx.subrev(path), state[2])
29021
92d37fb3f1aa verify: don't init subrepo when missing one is referenced (issue5128) (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 28949
diff changeset
   196
    return types[state[2]](ctx, path, state[:2], allowcreate)
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   197
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   198
25416
c4a92867c048 subrepo: introduce the nullsubrepo() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 25228
diff changeset
   199
def nullsubrepo(ctx, path, pctx):
c4a92867c048 subrepo: introduce the nullsubrepo() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 25228
diff changeset
   200
    """return an empty subrepo in pctx for the extant subrepo in ctx"""
c4a92867c048 subrepo: introduce the nullsubrepo() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 25228
diff changeset
   201
    # subrepo inherently violates our import layering rules
c4a92867c048 subrepo: introduce the nullsubrepo() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 25228
diff changeset
   202
    # because it wants to make repo objects from deep inside the stack
c4a92867c048 subrepo: introduce the nullsubrepo() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 25228
diff changeset
   203
    # so we manually delay the circular imports to not break
c4a92867c048 subrepo: introduce the nullsubrepo() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 25228
diff changeset
   204
    # scripts that don't use our demand-loading
c4a92867c048 subrepo: introduce the nullsubrepo() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 25228
diff changeset
   205
    global hg
25980
38c585c2f8cc subrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25848
diff changeset
   206
    from . import hg as h
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   207
25416
c4a92867c048 subrepo: introduce the nullsubrepo() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 25228
diff changeset
   208
    hg = h
c4a92867c048 subrepo: introduce the nullsubrepo() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 25228
diff changeset
   209
34985
5e27afeddaee subrepo: add config option to reject any subrepo operations (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 34984
diff changeset
   210
    repo = ctx.repo()
5e27afeddaee subrepo: add config option to reject any subrepo operations (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 34984
diff changeset
   211
    _auditsubrepopath(repo, path)
25416
c4a92867c048 subrepo: introduce the nullsubrepo() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 25228
diff changeset
   212
    state = ctx.substate[path]
34985
5e27afeddaee subrepo: add config option to reject any subrepo operations (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 34984
diff changeset
   213
    _checktype(repo.ui, state[2])
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   214
    subrev = b''
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   215
    if state[2] == b'hg':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   216
        subrev = b"0" * 40
29021
92d37fb3f1aa verify: don't init subrepo when missing one is referenced (issue5128) (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 28949
diff changeset
   217
    return types[state[2]](pctx, path, (state[0], subrev), True)
25416
c4a92867c048 subrepo: introduce the nullsubrepo() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 25228
diff changeset
   218
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   219
11559
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   220
# subrepo classes need to implement the following abstract class:
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   221
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   222
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48913
diff changeset
   223
class abstractsubrepo:
24671
98ab035e9332 subrepo: change arguments of abstractsubrepo.__init__ (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24645
diff changeset
   224
    def __init__(self, ctx, path):
98ab035e9332 subrepo: change arguments of abstractsubrepo.__init__ (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24645
diff changeset
   225
        """Initialize abstractsubrepo part
98ab035e9332 subrepo: change arguments of abstractsubrepo.__init__ (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24645
diff changeset
   226
98ab035e9332 subrepo: change arguments of abstractsubrepo.__init__ (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24645
diff changeset
   227
        ``ctx`` is the context referring this subrepository in the
98ab035e9332 subrepo: change arguments of abstractsubrepo.__init__ (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24645
diff changeset
   228
        parent repository.
98ab035e9332 subrepo: change arguments of abstractsubrepo.__init__ (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24645
diff changeset
   229
26781
1aee2ab0f902 spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents: 26587
diff changeset
   230
        ``path`` is the path to this subrepository as seen from
24671
98ab035e9332 subrepo: change arguments of abstractsubrepo.__init__ (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24645
diff changeset
   231
        innermost repository.
98ab035e9332 subrepo: change arguments of abstractsubrepo.__init__ (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24645
diff changeset
   232
        """
98ab035e9332 subrepo: change arguments of abstractsubrepo.__init__ (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24645
diff changeset
   233
        self.ui = ctx.repo().ui
98ab035e9332 subrepo: change arguments of abstractsubrepo.__init__ (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24645
diff changeset
   234
        self._ctx = ctx
98ab035e9332 subrepo: change arguments of abstractsubrepo.__init__ (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24645
diff changeset
   235
        self._path = path
23536
fcbc66b5da6a subrepo: store the ui object in the base class
Matt Harbison <matt_harbison@yahoo.com>
parents: 23523
diff changeset
   236
32005
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31551
diff changeset
   237
    def addwebdirpath(self, serverpath, webconf):
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31551
diff changeset
   238
        """Add the hgwebdir entries for this subrepo, and any of its subrepos.
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31551
diff changeset
   239
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31551
diff changeset
   240
        ``serverpath`` is the path component of the URL for this repo.
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31551
diff changeset
   241
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31551
diff changeset
   242
        ``webconf`` is the dictionary of hgwebdir entries.
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31551
diff changeset
   243
        """
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31551
diff changeset
   244
        pass
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31551
diff changeset
   245
18937
9a171baa9202 subrepo: introduce storeclean method
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18936
diff changeset
   246
    def storeclean(self, path):
9a171baa9202 subrepo: introduce storeclean method
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18936
diff changeset
   247
        """
9a171baa9202 subrepo: introduce storeclean method
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18936
diff changeset
   248
        returns true if the repository has not changed since it was last
9a171baa9202 subrepo: introduce storeclean method
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18936
diff changeset
   249
        cloned from or pushed to a given repository.
9a171baa9202 subrepo: introduce storeclean method
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18936
diff changeset
   250
        """
9a171baa9202 subrepo: introduce storeclean method
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18936
diff changeset
   251
        return False
9a171baa9202 subrepo: introduce storeclean method
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18936
diff changeset
   252
33364
bf2daeddd42b subrepo: consider the parent repo dirty when a file is missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 32584
diff changeset
   253
    def dirty(self, ignoreupdate=False, missing=False):
13174
be7e8e9bc5e5 mq: update .hgsubstate if subrepos are clean (issue2499)
Kevin Bullock <kbullock@ringworld.org>
parents: 13172
diff changeset
   254
        """returns true if the dirstate of the subrepo is dirty or does not
be7e8e9bc5e5 mq: update .hgsubstate if subrepos are clean (issue2499)
Kevin Bullock <kbullock@ringworld.org>
parents: 13172
diff changeset
   255
        match current stored state. If ignoreupdate is true, only check
33364
bf2daeddd42b subrepo: consider the parent repo dirty when a file is missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 32584
diff changeset
   256
        whether the subrepo has uncommitted changes in its dirstate.  If missing
bf2daeddd42b subrepo: consider the parent repo dirty when a file is missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 32584
diff changeset
   257
        is true, check for deleted files.
11559
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   258
        """
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   259
        raise NotImplementedError
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   260
33364
bf2daeddd42b subrepo: consider the parent repo dirty when a file is missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 32584
diff changeset
   261
    def dirtyreason(self, ignoreupdate=False, missing=False):
24470
76b0b0fed2e3 subrepo: add dirtyreason to centralize composing dirty reason message
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24413
diff changeset
   262
        """return reason string if it is ``dirty()``
76b0b0fed2e3 subrepo: add dirtyreason to centralize composing dirty reason message
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24413
diff changeset
   263
76b0b0fed2e3 subrepo: add dirtyreason to centralize composing dirty reason message
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24413
diff changeset
   264
        Returned string should have enough information for the message
76b0b0fed2e3 subrepo: add dirtyreason to centralize composing dirty reason message
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24413
diff changeset
   265
        of exception.
76b0b0fed2e3 subrepo: add dirtyreason to centralize composing dirty reason message
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24413
diff changeset
   266
76b0b0fed2e3 subrepo: add dirtyreason to centralize composing dirty reason message
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24413
diff changeset
   267
        This returns None, otherwise.
76b0b0fed2e3 subrepo: add dirtyreason to centralize composing dirty reason message
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24413
diff changeset
   268
        """
33364
bf2daeddd42b subrepo: consider the parent repo dirty when a file is missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 32584
diff changeset
   269
        if self.dirty(ignoreupdate=ignoreupdate, missing=missing):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   270
            return _(b'uncommitted changes in subrepository "%s"') % subrelpath(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   271
                self
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   272
            )
24470
76b0b0fed2e3 subrepo: add dirtyreason to centralize composing dirty reason message
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24413
diff changeset
   273
30755
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30639
diff changeset
   274
    def bailifchanged(self, ignoreupdate=False, hint=None):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   275
        """raise Abort if subrepository is ``dirty()``"""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   276
        dirtyreason = self.dirtyreason(ignoreupdate=ignoreupdate, missing=True)
24471
1ff35d76421c subrepo: add bailifchanged to centralize raising Abort if subrepo is dirty
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24470
diff changeset
   277
        if dirtyreason:
30755
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30639
diff changeset
   278
            raise error.Abort(dirtyreason, hint=hint)
24471
1ff35d76421c subrepo: add bailifchanged to centralize raising Abort if subrepo is dirty
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24470
diff changeset
   279
16072
bcb973abcc0b subrepo: add basestate method
Matt Mackall <mpm@selenic.com>
parents: 16022
diff changeset
   280
    def basestate(self):
bcb973abcc0b subrepo: add basestate method
Matt Mackall <mpm@selenic.com>
parents: 16022
diff changeset
   281
        """current working directory base state, disregarding .hgsubstate
bcb973abcc0b subrepo: add basestate method
Matt Mackall <mpm@selenic.com>
parents: 16022
diff changeset
   282
        state and working directory modifications"""
bcb973abcc0b subrepo: add basestate method
Matt Mackall <mpm@selenic.com>
parents: 16022
diff changeset
   283
        raise NotImplementedError
bcb973abcc0b subrepo: add basestate method
Matt Mackall <mpm@selenic.com>
parents: 16022
diff changeset
   284
12506
e7d45e41338c subrepos: add missing self argument to abstractsubrepo.checknested
Brodie Rao <brodie@bitheap.org>
parents: 12503
diff changeset
   285
    def checknested(self, path):
12162
af8c4929931c localrepo: add auditor attribute which knows about subrepos
Martin Geisler <mg@lazybytes.net>
parents: 12060
diff changeset
   286
        """check if path is a subrepository within this repository"""
af8c4929931c localrepo: add auditor attribute which knows about subrepos
Martin Geisler <mg@lazybytes.net>
parents: 12060
diff changeset
   287
        return False
af8c4929931c localrepo: add auditor attribute which knows about subrepos
Martin Geisler <mg@lazybytes.net>
parents: 12060
diff changeset
   288
11559
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   289
    def commit(self, text, user, date):
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   290
        """commit the current changes to the subrepo with the given
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   291
        log message. Use given user and date if possible. Return the
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   292
        new state of the subrepo.
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   293
        """
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   294
        raise NotImplementedError
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   295
20176
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   296
    def phase(self, state):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   297
        """returns phase of specified state in the subrepository."""
20176
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   298
        return phases.public
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   299
11559
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   300
    def remove(self):
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   301
        """remove the subrepo
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   302
11559
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   303
        (should verify the dirstate is not dirty first)
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   304
        """
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   305
        raise NotImplementedError
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   306
13322
c19b9282d3a7 subrepo: make update -C clean the working directory for svn subrepos
Erik Zielke <ez@aragost.com>
parents: 13287
diff changeset
   307
    def get(self, state, overwrite=False):
11559
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   308
        """run whatever commands are needed to put the subrepo into
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   309
        this state
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   310
        """
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   311
        raise NotImplementedError
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   312
13413
fa921dcd9993 subrepo: remove argument introduced by mistake in c19b9282d3a7
Erik Zielke <ez@aragost.com>
parents: 13333
diff changeset
   313
    def merge(self, state):
11559
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   314
        """merge currently-saved state with the new state."""
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   315
        raise NotImplementedError
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   316
15708
309e49491253 push: propagate --new-branch and --ssh options when pushing subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15614
diff changeset
   317
    def push(self, opts):
11572
324bad1dc230 Merge with stable
Martin Geisler <mg@lazybytes.net>
parents: 11560 11571
diff changeset
   318
        """perform whatever action is analogous to 'hg push'
11559
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   319
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   320
        This may be a no-op on some systems.
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   321
        """
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   322
        raise NotImplementedError
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   323
41650
f8b18583049f add: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41648
diff changeset
   324
    def add(self, ui, match, prefix, uipathfn, explicitonly, **opts):
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12210
diff changeset
   325
        return []
11559
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   326
41652
6a447a3d1bd0 addremove: pass around uipathfn and use instead of m.uipath() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41651
diff changeset
   327
    def addremove(self, matcher, prefix, uipathfn, opts):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   328
        self.ui.warn(b"%s: %s" % (prefix, _(b"addremove is not supported")))
23537
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23536
diff changeset
   329
        return 1
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23536
diff changeset
   330
32584
746e12a767b3 cat: add formatter support
Yuya Nishihara <yuya@tcha.org>
parents: 32540
diff changeset
   331
    def cat(self, match, fm, fntemplate, prefix, **opts):
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 20970
diff changeset
   332
        return 1
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 20970
diff changeset
   333
12166
441a74b8def1 status: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12162
diff changeset
   334
    def status(self, rev2, **opts):
22914
c95db3208a33 status: update various other methods to return new class
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22695
diff changeset
   335
        return scmutil.status([], [], [], [], [], [], [])
12166
441a74b8def1 status: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12162
diff changeset
   336
18006
0c10cf819146 subrepo: add argument to "diff()" to pass "ui" of caller side (issue3712) (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17895
diff changeset
   337
    def diff(self, ui, diffopts, node2, match, prefix, **opts):
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12166
diff changeset
   338
        pass
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12166
diff changeset
   339
12272
42ecd56399d7 outgoing: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12270
diff changeset
   340
    def outgoing(self, ui, dest, opts):
42ecd56399d7 outgoing: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12270
diff changeset
   341
        return 1
42ecd56399d7 outgoing: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12270
diff changeset
   342
12274
c02e1ed3d407 incoming: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12272
diff changeset
   343
    def incoming(self, ui, source, opts):
c02e1ed3d407 incoming: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12272
diff changeset
   344
        return 1
c02e1ed3d407 incoming: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12272
diff changeset
   345
12322
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   346
    def files(self):
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   347
        """return filename iterator"""
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   348
        raise NotImplementedError
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   349
31099
b44ab288358e subrepo: run the repo decoders when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 30755
diff changeset
   350
    def filedata(self, name, decode):
b44ab288358e subrepo: run the repo decoders when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 30755
diff changeset
   351
        """return file data, optionally passed through repo decoders"""
12322
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   352
        raise NotImplementedError
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   353
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   354
    def fileflags(self, name):
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   355
        """return file flags"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   356
        return b''
12322
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   357
44009
e685fac56693 match: resolve filesets against the passed `cwd`, not the current one
Matt Harbison <matt_harbison@yahoo.com>
parents: 43913
diff changeset
   358
    def matchfileset(self, cwd, expr, badfn=None):
25121
df63d4843581 subrepo: introduce getfileset()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24943
diff changeset
   359
        """Resolve the fileset expression for this repo"""
41676
0531dff73d0b match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41675
diff changeset
   360
        return matchmod.never(badfn=badfn)
25121
df63d4843581 subrepo: introduce getfileset()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24943
diff changeset
   361
41748
980e05204ed8 subrepo: use root-repo-relative path from `hg files` with ui.relative-paths=no
Martin von Zweigbergk <martinvonz@google.com>
parents: 41679
diff changeset
   362
    def printfiles(self, ui, m, uipathfn, fm, fmt, subrepos):
24413
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24409
diff changeset
   363
        """handle the files command for this subrepo"""
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24409
diff changeset
   364
        return 1
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24409
diff changeset
   365
31099
b44ab288358e subrepo: run the repo decoders when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 30755
diff changeset
   366
    def archive(self, archiver, prefix, match=None, decode=True):
17108
1894dac619de subrepo: propagate matcher to subrepos when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 17036
diff changeset
   367
        if match is not None:
1894dac619de subrepo: propagate matcher to subrepos when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 17036
diff changeset
   368
            files = [f for f in self.files() if match(f)]
1894dac619de subrepo: propagate matcher to subrepos when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 17036
diff changeset
   369
        else:
1894dac619de subrepo: propagate matcher to subrepos when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 17036
diff changeset
   370
            files = self.files()
13144
aae2d5cbde64 subrepo: add progress bar support to archive
Martin Geisler <mg@aragost.com>
parents: 13137
diff changeset
   371
        total = len(files)
aae2d5cbde64 subrepo: add progress bar support to archive
Martin Geisler <mg@aragost.com>
parents: 13137
diff changeset
   372
        relpath = subrelpath(self)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   373
        progress = self.ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   374
            _(b'archiving (%s)') % relpath, unit=_(b'files'), total=total
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   375
        )
38379
3a7c33a2cc5e subrepo: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38370
diff changeset
   376
        progress.update(0)
3a7c33a2cc5e subrepo: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38370
diff changeset
   377
        for name in files:
12323
f00953d9533c subrepo: add support for 'hg archive'
Martin Geisler <mg@aragost.com>
parents: 12322
diff changeset
   378
            flags = self.fileflags(name)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   379
            mode = b'x' in flags and 0o755 or 0o644
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   380
            symlink = b'l' in flags
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   381
            archiver.addfile(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   382
                prefix + name, mode, symlink, self.filedata(name, decode)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   383
            )
38379
3a7c33a2cc5e subrepo: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38370
diff changeset
   384
            progress.increment()
3a7c33a2cc5e subrepo: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38370
diff changeset
   385
        progress.complete()
18967
88d1b59f6906 archive: raise error.Abort if the file pattern matches no files
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18964
diff changeset
   386
        return total
12323
f00953d9533c subrepo: add support for 'hg archive'
Martin Geisler <mg@aragost.com>
parents: 12322
diff changeset
   387
15410
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15287
diff changeset
   388
    def walk(self, match):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   389
        """
15410
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15287
diff changeset
   390
        walk recursively through the directory tree, finding all files
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15287
diff changeset
   391
        matched by the match function
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   392
        """
12323
f00953d9533c subrepo: add support for 'hg archive'
Martin Geisler <mg@aragost.com>
parents: 12322
diff changeset
   393
41653
16a49c778bde forget: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41652
diff changeset
   394
    def forget(self, match, prefix, uipathfn, dryrun, interactive):
16527
17a1f7690b49 subrepo: fix default implementation of forget() (issue3404)
Patrick Mezard <patrick@mezard.eu>
parents: 16468
diff changeset
   395
        return ([], [])
12323
f00953d9533c subrepo: add support for 'hg archive'
Martin Geisler <mg@aragost.com>
parents: 12322
diff changeset
   396
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   397
    def removefiles(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   398
        self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   399
        matcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   400
        prefix,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   401
        uipathfn,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   402
        after,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   403
        force,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   404
        subrepos,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   405
        dryrun,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   406
        warnings,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   407
    ):
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 22927
diff changeset
   408
        """remove the matched files from the subrepository and the filesystem,
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 22927
diff changeset
   409
        possibly by force and/or after the file has been removed from the
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 22927
diff changeset
   410
        filesystem.  Return 0 on success, 1 on any warning.
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 22927
diff changeset
   411
        """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   412
        warnings.append(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   413
            _(b"warning: removefiles not implemented (%s)") % self._path
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   414
        )
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 22927
diff changeset
   415
        return 1
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 22927
diff changeset
   416
23579
e1c39f207719 subrepo: drop the 'ui' parameter to revert()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23578
diff changeset
   417
    def revert(self, substate, *pats, **opts):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   418
        self.ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   419
            _(b'%s: reverting %s subrepos is unsupported\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   420
            % (substate[0], substate[2])
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   421
        )
16429
71dcce391a44 revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16197
diff changeset
   422
        return []
71dcce391a44 revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16197
diff changeset
   423
21400
78a60daacea8 subrepo: add shortid() method to subrepo classes
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21041
diff changeset
   424
    def shortid(self, revid):
78a60daacea8 subrepo: add shortid() method to subrepo classes
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21041
diff changeset
   425
        return revid
78a60daacea8 subrepo: add shortid() method to subrepo classes
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21041
diff changeset
   426
34879
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   427
    def unshare(self):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   428
        """
34879
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   429
        convert this repository from shared to normal storage.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   430
        """
34879
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   431
43913
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
   432
    def verify(self, onpush=False):
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
   433
        """verify the revision of this repository that is held in `_state` is
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
   434
        present and not hidden.  Return 0 on success or warning, 1 on any
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
   435
        error.  In the case of ``onpush``, warnings or errors will raise an
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
   436
        exception if the result of pushing would be a broken remote repository.
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
   437
        """
25591
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25572
diff changeset
   438
        return 0
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25572
diff changeset
   439
24672
dd0b86f740ef subrepo: add wvfs field to access the working directory via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24671
diff changeset
   440
    @propertycache
dd0b86f740ef subrepo: add wvfs field to access the working directory via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24671
diff changeset
   441
    def wvfs(self):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   442
        """return vfs to access the working directory of this subrepository"""
31236
8a0687a2be75 vfs: use 'vfs' module directly in 'mercurial.subrepo'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31102
diff changeset
   443
        return vfsmod.vfs(self._ctx.repo().wvfs.join(self._path))
24672
dd0b86f740ef subrepo: add wvfs field to access the working directory via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24671
diff changeset
   444
24673
105758d1b37b subrepo: add _relpath field to centralize subrelpath logic
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24672
diff changeset
   445
    @propertycache
105758d1b37b subrepo: add _relpath field to centralize subrelpath logic
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24672
diff changeset
   446
    def _relpath(self):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   447
        """return path to this subrepository as seen from outermost repository"""
24785
39f519be5e65 subrepo: backout 93b0e0db7929 to restore reporelpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24778
diff changeset
   448
        return self.wvfs.reljoin(reporelpath(self._ctx.repo()), self._path)
24673
105758d1b37b subrepo: add _relpath field to centralize subrelpath logic
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24672
diff changeset
   449
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   450
11559
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
   451
class hgsubrepo(abstractsubrepo):
29021
92d37fb3f1aa verify: don't init subrepo when missing one is referenced (issue5128) (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 28949
diff changeset
   452
    def __init__(self, ctx, path, state, allowcreate):
24671
98ab035e9332 subrepo: change arguments of abstractsubrepo.__init__ (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24645
diff changeset
   453
        super(hgsubrepo, self).__init__(ctx, path)
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   454
        self._state = state
24302
6e092ea2eff1 subrepo: replace 'ctx._repo' with 'ctx.repo()'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24256
diff changeset
   455
        r = ctx.repo()
41583
87a6e3c953e0 subrepo: avoid false unsafe path detection on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 41458
diff changeset
   456
        root = r.wjoin(util.localpath(path))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   457
        create = allowcreate and not r.wvfs.exists(b'%s/.hg' % path)
41457
6c10eba6b9cd subrepo: prohibit variable expansion on creation of hg subrepo (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40753
diff changeset
   458
        # repository constructor does expand variables in path, which is
6c10eba6b9cd subrepo: prohibit variable expansion on creation of hg subrepo (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40753
diff changeset
   459
        # unsafe since subrepo path might come from untrusted source.
47808
23921bc857b5 subrepo: compare normalised vfs path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47628
diff changeset
   460
        norm_root = os.path.normcase(root)
23921bc857b5 subrepo: compare normalised vfs path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47628
diff changeset
   461
        real_root = os.path.normcase(os.path.realpath(util.expandpath(root)))
23921bc857b5 subrepo: compare normalised vfs path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47628
diff changeset
   462
        if real_root != norm_root:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   463
            raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   464
                _(b'subrepo path contains illegal component: %s') % path
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   465
            )
17873
573bec4ab7ba subrepo: isolate configuration between each repositories in subrepo tree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17707
diff changeset
   466
        self._repo = hg.repository(r.baseui, root, create=create)
47808
23921bc857b5 subrepo: compare normalised vfs path
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47628
diff changeset
   467
        if os.path.normcase(self._repo.root) != os.path.normcase(root):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   468
            raise error.ProgrammingError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   469
                b'failed to reject unsafe subrepo '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   470
                b'path: %s (expanded to %s)' % (root, self._repo.root)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   471
            )
24877
cc497780eaf9 subrepo: propagate the --hidden option to hg subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 24876
diff changeset
   472
cc497780eaf9 subrepo: propagate the --hidden option to hg subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 24876
diff changeset
   473
        # Propagate the parent's --hidden option
cc497780eaf9 subrepo: propagate the --hidden option to hg subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 24876
diff changeset
   474
        if r is r.unfiltered():
cc497780eaf9 subrepo: propagate the --hidden option to hg subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 24876
diff changeset
   475
            self._repo = self._repo.unfiltered()
cc497780eaf9 subrepo: propagate the --hidden option to hg subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 24876
diff changeset
   476
23573
3fec2a3c768b subrepo: reset 'self.ui' to the subrepo copy of 'ui' in the hgsubrepo class
Matt Harbison <matt_harbison@yahoo.com>
parents: 23572
diff changeset
   477
        self.ui = self._repo.ui
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   478
        for s, k in [(b'ui', b'commitsubrepos')]:
17873
573bec4ab7ba subrepo: isolate configuration between each repositories in subrepo tree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17707
diff changeset
   479
            v = r.ui.config(s, k)
573bec4ab7ba subrepo: isolate configuration between each repositories in subrepo tree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17707
diff changeset
   480
            if v:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   481
                self.ui.setconfig(s, k, v, b'subrepo')
25848
0ae07173881d subrepo: mark internal-only option
Matt Mackall <mpm@selenic.com>
parents: 25773
diff changeset
   482
        # internal config: ui._usedassubrepo
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   483
        self.ui.setconfig(b'ui', b'_usedassubrepo', b'True', b'subrepo')
14281
ccb7240acf32 subrepo: create subrepos using clone instead of pull
Martin Geisler <mg@aragost.com>
parents: 14221
diff changeset
   484
        self._initrepo(r, state[0], create)
ccb7240acf32 subrepo: create subrepos using clone instead of pull
Martin Geisler <mg@aragost.com>
parents: 14221
diff changeset
   485
32005
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31551
diff changeset
   486
    @annotatesubrepoerror
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31551
diff changeset
   487
    def addwebdirpath(self, serverpath, webconf):
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31551
diff changeset
   488
        cmdutil.addwebdirpath(self._repo, subrelpath(self), webconf)
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31551
diff changeset
   489
18939
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   490
    def storeclean(self, path):
27844
469b86c49503 with: use context manager in subrepo storeclean
Bryan O'Sullivan <bryano@fb.com>
parents: 27843
diff changeset
   491
        with self._repo.lock():
21885
fe9db58b0b2d subrepo: ensure "lock.release()" execution at the end of "storeclean()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21585
diff changeset
   492
            return self._storeclean(path)
fe9db58b0b2d subrepo: ensure "lock.release()" execution at the end of "storeclean()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21585
diff changeset
   493
fe9db58b0b2d subrepo: ensure "lock.release()" execution at the end of "storeclean()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21585
diff changeset
   494
    def _storeclean(self, path):
18939
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   495
        clean = True
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   496
        itercache = self._calcstorehash(path)
25172
ca9c02cb81be subrepo: further replacement of try/except with 'next'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25121
diff changeset
   497
        for filehash in self._readstorehashcache(path):
ca9c02cb81be subrepo: further replacement of try/except with 'next'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25121
diff changeset
   498
            if filehash != next(itercache, None):
ca9c02cb81be subrepo: further replacement of try/except with 'next'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25121
diff changeset
   499
                clean = False
ca9c02cb81be subrepo: further replacement of try/except with 'next'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25121
diff changeset
   500
                break
ca9c02cb81be subrepo: further replacement of try/except with 'next'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25121
diff changeset
   501
        if clean:
ca9c02cb81be subrepo: further replacement of try/except with 'next'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25121
diff changeset
   502
            # if not empty:
18939
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   503
            # the cached and current pull states have a different size
25172
ca9c02cb81be subrepo: further replacement of try/except with 'next'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25121
diff changeset
   504
            clean = next(itercache, None) is None
18939
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   505
        return clean
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   506
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   507
    def _calcstorehash(self, remotepath):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   508
        """calculate a unique "store hash"
18939
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   509
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   510
        This method is used to to detect when there are changes that may
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   511
        require a push to a given remote path."""
18939
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   512
        # sort the files that will be hashed in increasing (likely) file size
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   513
        filelist = (b'bookmarks', b'store/phaseroots', b'store/00changelog.i')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   514
        yield b'# %s\n' % _expandedabspath(remotepath)
23365
2ff394bbfa74 subrepo: replace "_calcfilehash" invocation by "vfs.tryread"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23364
diff changeset
   515
        vfs = self._repo.vfs
18939
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   516
        for relname in filelist:
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   517
            filehash = hex(hashutil.sha1(vfs.tryread(relname)).digest())
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   518
            yield b'%s = %s\n' % (relname, filehash)
18939
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   519
23367
115af8de76a4 subrepo: add "_cachestorehashvfs" to handle cache store hash files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23366
diff changeset
   520
    @propertycache
115af8de76a4 subrepo: add "_cachestorehashvfs" to handle cache store hash files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23366
diff changeset
   521
    def _cachestorehashvfs(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   522
        return vfsmod.vfs(self._repo.vfs.join(b'cache/storehash'))
23367
115af8de76a4 subrepo: add "_cachestorehashvfs" to handle cache store hash files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23366
diff changeset
   523
18939
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   524
    def _readstorehashcache(self, remotepath):
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   525
        '''read the store hash cache for a given remote repository'''
23369
22e00674d17e subrepo: replace direct file APIs around "readlines" by "vfs.tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23367
diff changeset
   526
        cachefile = _getstorehashcachename(remotepath)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   527
        return self._cachestorehashvfs.tryreadlines(cachefile, b'r')
18939
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   528
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   529
    def _cachestorehash(self, remotepath):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   530
        """cache the current store hash
18939
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   531
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   532
        Each remote repo requires its own store hash cache, because a subrepo
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   533
        store may be "clean" versus a given remote repo, but not versus another
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   534
        """
23372
6cfa7a73b6e7 subrepo: replace direct file APIs around "writelines" by "vfs.writelines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23369
diff changeset
   535
        cachefile = _getstorehashcachename(remotepath)
27843
b2efdb66c406 with: use context manager in subrepo _cachestorehash
Bryan O'Sullivan <bryano@fb.com>
parents: 27651
diff changeset
   536
        with self._repo.lock():
21886
b9e8fdc35daf subrepo: ensure "lock.release()" execution at the end of "_cachestorehash()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21885
diff changeset
   537
            storehash = list(self._calcstorehash(remotepath))
23372
6cfa7a73b6e7 subrepo: replace direct file APIs around "writelines" by "vfs.writelines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23369
diff changeset
   538
            vfs = self._cachestorehashvfs
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   539
            vfs.writelines(cachefile, storehash, mode=b'wb', notindexed=True)
18939
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   540
25572
3d8c044ed513 subrepo: introduce hgsubrepo._getctx()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25416
diff changeset
   541
    def _getctx(self):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   542
        """fetch the context for this subrepo revision, possibly a workingctx"""
25572
3d8c044ed513 subrepo: introduce hgsubrepo._getctx()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25416
diff changeset
   543
        if self._ctx.rev() is None:
3d8c044ed513 subrepo: introduce hgsubrepo._getctx()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25416
diff changeset
   544
            return self._repo[None]  # workingctx if parent is workingctx
3d8c044ed513 subrepo: introduce hgsubrepo._getctx()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25416
diff changeset
   545
        else:
3d8c044ed513 subrepo: introduce hgsubrepo._getctx()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25416
diff changeset
   546
            rev = self._state[1]
3d8c044ed513 subrepo: introduce hgsubrepo._getctx()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25416
diff changeset
   547
            return self._repo[rev]
3d8c044ed513 subrepo: introduce hgsubrepo._getctx()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25416
diff changeset
   548
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   549
    @annotatesubrepoerror
14281
ccb7240acf32 subrepo: create subrepos using clone instead of pull
Martin Geisler <mg@aragost.com>
parents: 14221
diff changeset
   550
    def _initrepo(self, parentrepo, source, create):
ccb7240acf32 subrepo: create subrepos using clone instead of pull
Martin Geisler <mg@aragost.com>
parents: 14221
diff changeset
   551
        self._repo._subparent = parentrepo
ccb7240acf32 subrepo: create subrepos using clone instead of pull
Martin Geisler <mg@aragost.com>
parents: 14221
diff changeset
   552
        self._repo._subsource = source
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   553
10666
4c50a90b90fc subrepo: keep ui and hgrc in sync when creating new repo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10665
diff changeset
   554
        if create:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   555
            lines = [b'[paths]\n']
10666
4c50a90b90fc subrepo: keep ui and hgrc in sync when creating new repo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10665
diff changeset
   556
4c50a90b90fc subrepo: keep ui and hgrc in sync when creating new repo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10665
diff changeset
   557
            def addpathconfig(key, value):
12753
ef5eaf53f4f7 subrepo: abort instead of pushing/pulling to the repo itself
Mads Kiilerich <mads@kiilerich.com>
parents: 12752
diff changeset
   558
                if value:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   559
                    lines.append(b'%s = %s\n' % (key, value))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   560
                    self.ui.setconfig(b'paths', key, value, b'subrepo')
10666
4c50a90b90fc subrepo: keep ui and hgrc in sync when creating new repo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10665
diff changeset
   561
12753
ef5eaf53f4f7 subrepo: abort instead of pushing/pulling to the repo itself
Mads Kiilerich <mads@kiilerich.com>
parents: 12752
diff changeset
   562
            defpath = _abssource(self._repo, abort=False)
ef5eaf53f4f7 subrepo: abort instead of pushing/pulling to the repo itself
Mads Kiilerich <mads@kiilerich.com>
parents: 12752
diff changeset
   563
            defpushpath = _abssource(self._repo, True, abort=False)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   564
            addpathconfig(b'default', defpath)
10697
c90d923fff64 subrepo: fix hgrc paths section during subrepo pulling
Edouard Gomez <ed.gomez@free.fr>
parents: 10666
diff changeset
   565
            if defpath != defpushpath:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   566
                addpathconfig(b'default-push', defpushpath)
21891
db8a27d92818 subrepo: ensure "close()" execution at the end of "_initrepo()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21889
diff changeset
   567
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   568
            self._repo.vfs.write(b'hgrc', util.tonativeeol(b''.join(lines)))
10666
4c50a90b90fc subrepo: keep ui and hgrc in sync when creating new repo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10665
diff changeset
   569
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   570
    @annotatesubrepoerror
41650
f8b18583049f add: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41648
diff changeset
   571
    def add(self, ui, match, prefix, uipathfn, explicitonly, **opts):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   572
        return cmdutil.add(
50045
bbe3a65bbd96 subrepo: let black expand some call on multiple lines early
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49392
diff changeset
   573
            ui,
bbe3a65bbd96 subrepo: let black expand some call on multiple lines early
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49392
diff changeset
   574
            self._repo,
bbe3a65bbd96 subrepo: let black expand some call on multiple lines early
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49392
diff changeset
   575
            match,
bbe3a65bbd96 subrepo: let black expand some call on multiple lines early
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49392
diff changeset
   576
            prefix,
bbe3a65bbd96 subrepo: let black expand some call on multiple lines early
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49392
diff changeset
   577
            uipathfn,
bbe3a65bbd96 subrepo: let black expand some call on multiple lines early
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49392
diff changeset
   578
            explicitonly,
bbe3a65bbd96 subrepo: let black expand some call on multiple lines early
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49392
diff changeset
   579
            **opts,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   580
        )
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12210
diff changeset
   581
24132
b5898bf7119a subrepo: annotate addremove with @annotatesubrepoerror
Matt Harbison <matt_harbison@yahoo.com>
parents: 23991
diff changeset
   582
    @annotatesubrepoerror
41652
6a447a3d1bd0 addremove: pass around uipathfn and use instead of m.uipath() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41651
diff changeset
   583
    def addremove(self, m, prefix, uipathfn, opts):
23540
f274d27f1994 addremove: automatically process a subrepository's subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 23537
diff changeset
   584
        # In the same way as sub directories are processed, once in a subrepo,
f274d27f1994 addremove: automatically process a subrepository's subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 23537
diff changeset
   585
        # always entry any of its subrepos.  Don't corrupt the options that will
f274d27f1994 addremove: automatically process a subrepository's subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 23537
diff changeset
   586
        # be used to process sibling subrepos however.
f274d27f1994 addremove: automatically process a subrepository's subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 23537
diff changeset
   587
        opts = copy.copy(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   588
        opts[b'subrepos'] = True
41652
6a447a3d1bd0 addremove: pass around uipathfn and use instead of m.uipath() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41651
diff changeset
   589
        return scmutil.addremove(self._repo, m, prefix, uipathfn, opts)
23537
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23536
diff changeset
   590
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   591
    @annotatesubrepoerror
32584
746e12a767b3 cat: add formatter support
Yuya Nishihara <yuya@tcha.org>
parents: 32540
diff changeset
   592
    def cat(self, match, fm, fntemplate, prefix, **opts):
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 20970
diff changeset
   593
        rev = self._state[1]
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 20970
diff changeset
   594
        ctx = self._repo[rev]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   595
        return cmdutil.cat(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   596
            self.ui, self._repo, ctx, match, fm, fntemplate, prefix, **opts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   597
        )
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 20970
diff changeset
   598
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 20970
diff changeset
   599
    @annotatesubrepoerror
12166
441a74b8def1 status: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12162
diff changeset
   600
    def status(self, rev2, **opts):
441a74b8def1 status: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12162
diff changeset
   601
        try:
441a74b8def1 status: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12162
diff changeset
   602
            rev1 = self._state[1]
441a74b8def1 status: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12162
diff changeset
   603
            ctx1 = self._repo[rev1]
441a74b8def1 status: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12162
diff changeset
   604
            ctx2 = self._repo[rev2]
441a74b8def1 status: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12162
diff changeset
   605
            return self._repo.status(ctx1, ctx2, **opts)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25658
diff changeset
   606
        except error.RepoLookupError as inst:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   607
            self.ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   608
                _(b'warning: error "%s" in subrepository "%s"\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   609
                % (inst, subrelpath(self))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   610
            )
22914
c95db3208a33 status: update various other methods to return new class
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22695
diff changeset
   611
            return scmutil.status([], [], [], [], [], [], [])
12166
441a74b8def1 status: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12162
diff changeset
   612
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   613
    @annotatesubrepoerror
18006
0c10cf819146 subrepo: add argument to "diff()" to pass "ui" of caller side (issue3712) (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17895
diff changeset
   614
    def diff(self, ui, diffopts, node2, match, prefix, **opts):
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12166
diff changeset
   615
        try:
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   616
            node1 = bin(self._state[1])
12209
affec9fb56ef subrepos: handle diff nodeids in subrepos, not before
Patrick Mezard <pmezard@gmail.com>
parents: 12176
diff changeset
   617
            # We currently expect node2 to come from substate and be
affec9fb56ef subrepos: handle diff nodeids in subrepos, not before
Patrick Mezard <pmezard@gmail.com>
parents: 12176
diff changeset
   618
            # in hex format
12210
21eb85e9ea94 subrepo: handle diff with working copy
Martin Geisler <mg@lazybytes.net>
parents: 12209
diff changeset
   619
            if node2 is not None:
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   620
                node2 = bin(node2)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   621
            logcmdutil.diffordiffstat(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   622
                ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   623
                self._repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   624
                diffopts,
44823
3b7aabd02e11 cleanup: avoid extra node/ctx conversions in logcmdutil.diffordiffstat
Augie Fackler <augie@google.com>
parents: 44434
diff changeset
   625
                self._repo[node1],
3b7aabd02e11 cleanup: avoid extra node/ctx conversions in logcmdutil.diffordiffstat
Augie Fackler <augie@google.com>
parents: 44434
diff changeset
   626
                self._repo[node2],
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   627
                match,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   628
                prefix=prefix,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   629
                listsubrepos=True,
50045
bbe3a65bbd96 subrepo: let black expand some call on multiple lines early
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49392
diff changeset
   630
                **opts,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   631
            )
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25658
diff changeset
   632
        except error.RepoLookupError as inst:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   633
            self.ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   634
                _(b'warning: error "%s" in subrepository "%s"\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   635
                % (inst, subrelpath(self))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   636
            )
12167
d2c5b0927c28 diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12166
diff changeset
   637
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   638
    @annotatesubrepoerror
31099
b44ab288358e subrepo: run the repo decoders when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 30755
diff changeset
   639
    def archive(self, archiver, prefix, match=None, decode=True):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   640
        self._get(self._state + (b'hg',))
35925
533f04d4cb6d archive: call the storage prefetch hook
Matt Harbison <matt_harbison@yahoo.com>
parents: 35888
diff changeset
   641
        files = self.files()
533f04d4cb6d archive: call the storage prefetch hook
Matt Harbison <matt_harbison@yahoo.com>
parents: 35888
diff changeset
   642
        if match:
533f04d4cb6d archive: call the storage prefetch hook
Matt Harbison <matt_harbison@yahoo.com>
parents: 35888
diff changeset
   643
            files = [f for f in files if match(f)]
12323
f00953d9533c subrepo: add support for 'hg archive'
Martin Geisler <mg@aragost.com>
parents: 12322
diff changeset
   644
        rev = self._state[1]
f00953d9533c subrepo: add support for 'hg archive'
Martin Geisler <mg@aragost.com>
parents: 12322
diff changeset
   645
        ctx = self._repo[rev]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   646
        scmutil.prefetchfiles(
45072
a56ba57c837d scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 44823
diff changeset
   647
            self._repo, [(ctx.rev(), scmutil.matchfiles(self._repo, files))]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   648
        )
35925
533f04d4cb6d archive: call the storage prefetch hook
Matt Harbison <matt_harbison@yahoo.com>
parents: 35888
diff changeset
   649
        total = abstractsubrepo.archive(self, archiver, prefix, match)
12323
f00953d9533c subrepo: add support for 'hg archive'
Martin Geisler <mg@aragost.com>
parents: 12322
diff changeset
   650
        for subpath in ctx.substate:
25601
3ec8351fa6ed archive: support 'wdir()'
Matt Harbison <matt_harbison@yahoo.com>
parents: 25600
diff changeset
   651
            s = subrepo(ctx, subpath, True)
28017
d3f1b7ee5e70 match: rename "narrowmatcher" to "subdirmatcher" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27935
diff changeset
   652
            submatch = matchmod.subdirmatcher(subpath, match)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   653
            subprefix = prefix + subpath + b'/'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   654
            total += s.archive(archiver, subprefix, submatch, decode)
18967
88d1b59f6906 archive: raise error.Abort if the file pattern matches no files
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18964
diff changeset
   655
        return total
12323
f00953d9533c subrepo: add support for 'hg archive'
Martin Geisler <mg@aragost.com>
parents: 12322
diff changeset
   656
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   657
    @annotatesubrepoerror
33364
bf2daeddd42b subrepo: consider the parent repo dirty when a file is missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 32584
diff changeset
   658
    def dirty(self, ignoreupdate=False, missing=False):
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   659
        r = self._state[1]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   660
        if r == b'' and not ignoreupdate:  # no state recorded
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   661
            return True
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   662
        w = self._repo[None]
14316
d5b525697ddb extensions: drop maxlength from enabled and disabled
Matt Mackall <mpm@selenic.com>
parents: 14312
diff changeset
   663
        if r != w.p1().hex() and not ignoreupdate:
13325
7ebdfa37842e subrepo: clarify comments in dirty() methods
Kevin Bullock <kbullock@ringworld.org>
parents: 13324
diff changeset
   664
            # different version checked out
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   665
            return True
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   666
        return w.dirty(missing=missing)  # working directory changed
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   667
16072
bcb973abcc0b subrepo: add basestate method
Matt Mackall <mpm@selenic.com>
parents: 16022
diff changeset
   668
    def basestate(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   669
        return self._repo[b'.'].hex()
16072
bcb973abcc0b subrepo: add basestate method
Matt Mackall <mpm@selenic.com>
parents: 16022
diff changeset
   670
12162
af8c4929931c localrepo: add auditor attribute which knows about subrepos
Martin Geisler <mg@lazybytes.net>
parents: 12060
diff changeset
   671
    def checknested(self, path):
af8c4929931c localrepo: add auditor attribute which knows about subrepos
Martin Geisler <mg@lazybytes.net>
parents: 12060
diff changeset
   672
        return self._repo._checknested(self._repo.wjoin(path))
af8c4929931c localrepo: add auditor attribute which knows about subrepos
Martin Geisler <mg@lazybytes.net>
parents: 12060
diff changeset
   673
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   674
    @annotatesubrepoerror
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   675
    def commit(self, text, user, date):
14898
95ced9f5bf29 subrepo: don't commit in subrepo if it's clean
Kevin Bullock <kbullock@ringworld.org>
parents: 14820
diff changeset
   676
        # don't bother committing in the subrepo if it's only been
95ced9f5bf29 subrepo: don't commit in subrepo if it's clean
Kevin Bullock <kbullock@ringworld.org>
parents: 14820
diff changeset
   677
        # updated
95ced9f5bf29 subrepo: don't commit in subrepo if it's clean
Kevin Bullock <kbullock@ringworld.org>
parents: 14820
diff changeset
   678
        if not self.dirty(True):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   679
            return self._repo[b'.'].hex()
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   680
        self.ui.debug(b"committing subrepo %s\n" % subrelpath(self))
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   681
        n = self._repo.commit(text, user, date)
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   682
        if not n:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   683
            return self._repo[b'.'].hex()  # different version checked out
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   684
        return hex(n)
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   685
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   686
    @annotatesubrepoerror
20176
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   687
    def phase(self, state):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   688
        return self._repo[state or b'.'].phase()
20176
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   689
4c96c50ef937 subrepo: check phase of state in each subrepositories before committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20108
diff changeset
   690
    @annotatesubrepoerror
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   691
    def remove(self):
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   692
        # we can't fully delete the repository as it may contain
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   693
        # local-only history
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   694
        self.ui.note(_(b'removing subrepo %s\n') % subrelpath(self))
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46950
diff changeset
   695
        hg.clean(self._repo, self._repo.nullid, False)
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   696
9507
5987183d6e59 subrepo: add auto-pull for merge
Matt Mackall <mpm@selenic.com>
parents: 9186
diff changeset
   697
    def _get(self, state):
10177
5ca0d220ae21 subrepo: add table-based dispatch for subrepo types
Augie Fackler <durin42@gmail.com>
parents: 10175
diff changeset
   698
        source, revision, kind = state
34815
68e0bcb90357 subrepo: share instead of clone if the parent repo is shared (issue5675) (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents: 34645
diff changeset
   699
        parentrepo = self._repo._subparent
68e0bcb90357 subrepo: share instead of clone if the parent repo is shared (issue5675) (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents: 34645
diff changeset
   700
20317
d6939f29b3b3 subrepo: do not try to get hidden revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20176
diff changeset
   701
        if revision in self._repo.unfiltered():
34815
68e0bcb90357 subrepo: share instead of clone if the parent repo is shared (issue5675) (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents: 34645
diff changeset
   702
            # Allow shared subrepos tracked at null to setup the sharedpath
68e0bcb90357 subrepo: share instead of clone if the parent repo is shared (issue5675) (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents: 34645
diff changeset
   703
            if len(self._repo) != 0 or not parentrepo.shared():
68e0bcb90357 subrepo: share instead of clone if the parent repo is shared (issue5675) (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents: 34645
diff changeset
   704
                return True
20318
c5aef7a66607 subrepo: remove unnecessary else clause in hgsubrepo._get
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20317
diff changeset
   705
        self._repo._subsource = source
c5aef7a66607 subrepo: remove unnecessary else clause in hgsubrepo._get
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20317
diff changeset
   706
        srcurl = _abssource(self._repo)
40655
69d4c8c5c25e subrepo: print the status line before creating the peer for better diagnostics
Matt Harbison <matt_harbison@yahoo.com>
parents: 40342
diff changeset
   707
69d4c8c5c25e subrepo: print the status line before creating the peer for better diagnostics
Matt Harbison <matt_harbison@yahoo.com>
parents: 40342
diff changeset
   708
        # Defer creating the peer until after the status message is logged, in
69d4c8c5c25e subrepo: print the status line before creating the peer for better diagnostics
Matt Harbison <matt_harbison@yahoo.com>
parents: 40342
diff changeset
   709
        # case there are network problems.
69d4c8c5c25e subrepo: print the status line before creating the peer for better diagnostics
Matt Harbison <matt_harbison@yahoo.com>
parents: 40342
diff changeset
   710
        getpeer = lambda: hg.peer(self._repo, {}, srcurl)
69d4c8c5c25e subrepo: print the status line before creating the peer for better diagnostics
Matt Harbison <matt_harbison@yahoo.com>
parents: 40342
diff changeset
   711
20318
c5aef7a66607 subrepo: remove unnecessary else clause in hgsubrepo._get
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20317
diff changeset
   712
        if len(self._repo) == 0:
24690
d1ddf1fe5d33 subrepo: use vfs.rmtree instead of shutil.rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24688
diff changeset
   713
            # use self._repo.vfs instead of self.wvfs to remove .hg only
d1ddf1fe5d33 subrepo: use vfs.rmtree instead of shutil.rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24688
diff changeset
   714
            self._repo.vfs.rmtree()
36687
eed02e192770 subrepo: don't attempt to share remote sources (issue5793)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35777
diff changeset
   715
eed02e192770 subrepo: don't attempt to share remote sources (issue5793)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35777
diff changeset
   716
            # A remote subrepo could be shared if there is a local copy
eed02e192770 subrepo: don't attempt to share remote sources (issue5793)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35777
diff changeset
   717
            # relative to the parent's share source.  But clone pooling doesn't
eed02e192770 subrepo: don't attempt to share remote sources (issue5793)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35777
diff changeset
   718
            # assemble the repos in a tree, so that can't be consistently done.
eed02e192770 subrepo: don't attempt to share remote sources (issue5793)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35777
diff changeset
   719
            # A simpler option is for the user to configure clone pooling, and
eed02e192770 subrepo: don't attempt to share remote sources (issue5793)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35777
diff changeset
   720
            # work with that.
eed02e192770 subrepo: don't attempt to share remote sources (issue5793)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35777
diff changeset
   721
            if parentrepo.shared() and hg.islocal(srcurl):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   722
                self.ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   723
                    _(b'sharing subrepo %s from %s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   724
                    % (subrelpath(self), srcurl)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   725
                )
46663
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   726
                peer = getpeer()
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   727
                try:
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   728
                    shared = hg.share(
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   729
                        self._repo._subparent.baseui,
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   730
                        peer,
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   731
                        self._repo.root,
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   732
                        update=False,
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   733
                        bookmarks=False,
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   734
                    )
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   735
                finally:
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   736
                    peer.close()
34815
68e0bcb90357 subrepo: share instead of clone if the parent repo is shared (issue5675) (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents: 34645
diff changeset
   737
                self._repo = shared.local()
68e0bcb90357 subrepo: share instead of clone if the parent repo is shared (issue5675) (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents: 34645
diff changeset
   738
            else:
36688
fb278041df06 subrepo: activate clone pooling to enable sharing with remote URLs
Matt Harbison <matt_harbison@yahoo.com>
parents: 36687
diff changeset
   739
                # TODO: find a common place for this and this code in the
fb278041df06 subrepo: activate clone pooling to enable sharing with remote URLs
Matt Harbison <matt_harbison@yahoo.com>
parents: 36687
diff changeset
   740
                # share.py wrap of the clone command.
fb278041df06 subrepo: activate clone pooling to enable sharing with remote URLs
Matt Harbison <matt_harbison@yahoo.com>
parents: 36687
diff changeset
   741
                if parentrepo.shared():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   742
                    pool = self.ui.config(b'share', b'pool')
36688
fb278041df06 subrepo: activate clone pooling to enable sharing with remote URLs
Matt Harbison <matt_harbison@yahoo.com>
parents: 36687
diff changeset
   743
                    if pool:
fb278041df06 subrepo: activate clone pooling to enable sharing with remote URLs
Matt Harbison <matt_harbison@yahoo.com>
parents: 36687
diff changeset
   744
                        pool = util.expandpath(pool)
fb278041df06 subrepo: activate clone pooling to enable sharing with remote URLs
Matt Harbison <matt_harbison@yahoo.com>
parents: 36687
diff changeset
   745
fb278041df06 subrepo: activate clone pooling to enable sharing with remote URLs
Matt Harbison <matt_harbison@yahoo.com>
parents: 36687
diff changeset
   746
                    shareopts = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   747
                        b'pool': pool,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   748
                        b'mode': self.ui.config(b'share', b'poolnaming'),
36688
fb278041df06 subrepo: activate clone pooling to enable sharing with remote URLs
Matt Harbison <matt_harbison@yahoo.com>
parents: 36687
diff changeset
   749
                    }
fb278041df06 subrepo: activate clone pooling to enable sharing with remote URLs
Matt Harbison <matt_harbison@yahoo.com>
parents: 36687
diff changeset
   750
                else:
fb278041df06 subrepo: activate clone pooling to enable sharing with remote URLs
Matt Harbison <matt_harbison@yahoo.com>
parents: 36687
diff changeset
   751
                    shareopts = {}
fb278041df06 subrepo: activate clone pooling to enable sharing with remote URLs
Matt Harbison <matt_harbison@yahoo.com>
parents: 36687
diff changeset
   752
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   753
                self.ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   754
                    _(b'cloning subrepo %s from %s\n')
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
   755
                    % (subrelpath(self), urlutil.hidepassword(srcurl))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   756
                )
46663
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   757
                peer = getpeer()
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   758
                try:
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   759
                    other, cloned = hg.clone(
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   760
                        self._repo._subparent.baseui,
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   761
                        {},
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   762
                        peer,
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   763
                        self._repo.root,
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   764
                        update=False,
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   765
                        shareopts=shareopts,
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   766
                    )
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   767
                finally:
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   768
                    peer.close()
34815
68e0bcb90357 subrepo: share instead of clone if the parent repo is shared (issue5675) (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents: 34645
diff changeset
   769
                self._repo = cloned.local()
20318
c5aef7a66607 subrepo: remove unnecessary else clause in hgsubrepo._get
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20317
diff changeset
   770
            self._initrepo(parentrepo, source, create=True)
c5aef7a66607 subrepo: remove unnecessary else clause in hgsubrepo._get
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20317
diff changeset
   771
            self._cachestorehash(srcurl)
20317
d6939f29b3b3 subrepo: do not try to get hidden revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20176
diff changeset
   772
        else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   773
            self.ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   774
                _(b'pulling subrepo %s from %s\n')
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
   775
                % (subrelpath(self), urlutil.hidepassword(srcurl))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   776
            )
20318
c5aef7a66607 subrepo: remove unnecessary else clause in hgsubrepo._get
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20317
diff changeset
   777
            cleansub = self.storeclean(srcurl)
46663
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   778
            peer = getpeer()
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   779
            try:
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   780
                exchange.pull(self._repo, peer)
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   781
            finally:
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   782
                peer.close()
20318
c5aef7a66607 subrepo: remove unnecessary else clause in hgsubrepo._get
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20317
diff changeset
   783
            if cleansub:
c5aef7a66607 subrepo: remove unnecessary else clause in hgsubrepo._get
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20317
diff changeset
   784
                # keep the repo clean after pull
18939
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   785
                self._cachestorehash(srcurl)
20319
427d672c0e4e subrepo: make it possible to update to hidden subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20318
diff changeset
   786
        return False
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   787
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   788
    @annotatesubrepoerror
13322
c19b9282d3a7 subrepo: make update -C clean the working directory for svn subrepos
Erik Zielke <ez@aragost.com>
parents: 13287
diff changeset
   789
    def get(self, state, overwrite=False):
20319
427d672c0e4e subrepo: make it possible to update to hidden subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20318
diff changeset
   790
        inrepo = self._get(state)
10177
5ca0d220ae21 subrepo: add table-based dispatch for subrepo types
Augie Fackler <durin42@gmail.com>
parents: 10175
diff changeset
   791
        source, revision, kind = state
20319
427d672c0e4e subrepo: make it possible to update to hidden subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20318
diff changeset
   792
        repo = self._repo
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   793
        repo.ui.debug(b"getting subrepo %s\n" % self._path)
20319
427d672c0e4e subrepo: make it possible to update to hidden subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20318
diff changeset
   794
        if inrepo:
427d672c0e4e subrepo: make it possible to update to hidden subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20318
diff changeset
   795
            urepo = repo.unfiltered()
427d672c0e4e subrepo: make it possible to update to hidden subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20318
diff changeset
   796
            ctx = urepo[revision]
427d672c0e4e subrepo: make it possible to update to hidden subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20318
diff changeset
   797
            if ctx.hidden():
427d672c0e4e subrepo: make it possible to update to hidden subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20318
diff changeset
   798
                urepo.ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   799
                    _(b'revision %s in subrepository "%s" is hidden\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   800
                    % (revision[0:12], self._path)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   801
                )
20319
427d672c0e4e subrepo: make it possible to update to hidden subrepo revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20318
diff changeset
   802
                repo = urepo
45556
03726f5b6092 merge: use merge.clean_update() when applicable
Martin von Zweigbergk <martinvonz@google.com>
parents: 45375
diff changeset
   803
        if overwrite:
03726f5b6092 merge: use merge.clean_update() when applicable
Martin von Zweigbergk <martinvonz@google.com>
parents: 45375
diff changeset
   804
            merge.clean_update(repo[revision])
03726f5b6092 merge: use merge.clean_update() when applicable
Martin von Zweigbergk <martinvonz@google.com>
parents: 45375
diff changeset
   805
        else:
45577
5c8230ca37f2 merge: replace calls to hg.updaterepo() by merge.update()
Martin von Zweigbergk <martinvonz@google.com>
parents: 45556
diff changeset
   806
            merge.update(repo[revision])
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   807
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   808
    @annotatesubrepoerror
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   809
    def merge(self, state):
9507
5987183d6e59 subrepo: add auto-pull for merge
Matt Mackall <mpm@selenic.com>
parents: 9186
diff changeset
   810
        self._get(state)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   811
        cur = self._repo[b'.']
9781
eccc8aacd6f9 subrepo: do a linear update when appropriate
Matt Mackall <mpm@selenic.com>
parents: 9780
diff changeset
   812
        dst = self._repo[state[1]]
10251
a19d2993385d subrepo: fix merging of already merged subrepos (issue1986)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10068
diff changeset
   813
        anc = dst.ancestor(cur)
13417
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   814
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   815
        def mergefunc():
16196
8ae7626d8bf1 subrepo: fix for merge inconsistencies
Friedrich Kastner-Masilko <kastner_masilko@at.festo.com>
parents: 16022
diff changeset
   816
            if anc == cur and dst.branch() == cur.branch():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   817
                self.ui.debug(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   818
                    b'updating subrepository "%s"\n' % subrelpath(self)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   819
                )
13417
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   820
                hg.update(self._repo, state[1])
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   821
            elif anc == dst:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   822
                self.ui.debug(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   823
                    b'skipping subrepository "%s"\n' % subrelpath(self)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   824
                )
13417
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   825
            else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   826
                self.ui.debug(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   827
                    b'merging subrepository "%s"\n' % subrelpath(self)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   828
                )
44434
2f290136b7d6 merge: make hg.merge() take a context instead of a node
Martin von Zweigbergk <martinvonz@google.com>
parents: 44060
diff changeset
   829
                hg.merge(dst, remind=False)
13417
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   830
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   831
        wctx = self._repo[None]
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   832
        if self.dirty():
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   833
            if anc != dst:
23574
faa3d6af154e subrepo: use 'self.ui' instead of 'self._repo.ui'
Matt Harbison <matt_harbison@yahoo.com>
parents: 23573
diff changeset
   834
                if _updateprompt(self.ui, self, wctx.dirty(), cur, dst):
13417
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   835
                    mergefunc()
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   836
            else:
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   837
                mergefunc()
9781
eccc8aacd6f9 subrepo: do a linear update when appropriate
Matt Mackall <mpm@selenic.com>
parents: 9780
diff changeset
   838
        else:
13417
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
   839
            mergefunc()
8815
e87b0fc4750b subrepo: basic push support
Matt Mackall <mpm@selenic.com>
parents: 8814
diff changeset
   840
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   841
    @annotatesubrepoerror
15708
309e49491253 push: propagate --new-branch and --ssh options when pushing subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15614
diff changeset
   842
    def push(self, opts):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   843
        force = opts.get(b'force')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   844
        newbranch = opts.get(b'new_branch')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   845
        ssh = opts.get(b'ssh')
15708
309e49491253 push: propagate --new-branch and --ssh options when pushing subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15614
diff changeset
   846
8815
e87b0fc4750b subrepo: basic push support
Matt Mackall <mpm@selenic.com>
parents: 8814
diff changeset
   847
        # push subrepos depth-first for coherent ordering
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   848
        c = self._repo[b'.']
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   849
        subs = c.substate  # only repos that are committed
8815
e87b0fc4750b subrepo: basic push support
Matt Mackall <mpm@selenic.com>
parents: 8814
diff changeset
   850
        for s in sorted(subs):
16022
04604d1a9fc3 push: more precise failure check on subrepo push
Matt Mackall <mpm@selenic.com>
parents: 15912
diff changeset
   851
            if c.sub(s).push(opts) == 0:
11067
49e14ec67144 subrepo: propagate and catch push failures
Matt Mackall <mpm@selenic.com>
parents: 10954
diff changeset
   852
                return False
8815
e87b0fc4750b subrepo: basic push support
Matt Mackall <mpm@selenic.com>
parents: 8814
diff changeset
   853
e87b0fc4750b subrepo: basic push support
Matt Mackall <mpm@selenic.com>
parents: 8814
diff changeset
   854
        dsturl = _abssource(self._repo, True)
18940
798bdb7f1517 subrepo: do not push mercurial subrepos whose store is clean
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18939
diff changeset
   855
        if not force:
798bdb7f1517 subrepo: do not push mercurial subrepos whose store is clean
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18939
diff changeset
   856
            if self.storeclean(dsturl):
23574
faa3d6af154e subrepo: use 'self.ui' instead of 'self._repo.ui'
Matt Harbison <matt_harbison@yahoo.com>
parents: 23573
diff changeset
   857
                self.ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   858
                    _(b'no changes made to subrepo %s since last push to %s\n')
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
   859
                    % (subrelpath(self), urlutil.hidepassword(dsturl))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   860
                )
18940
798bdb7f1517 subrepo: do not push mercurial subrepos whose store is clean
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18939
diff changeset
   861
                return None
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   862
        self.ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   863
            _(b'pushing subrepo %s to %s\n')
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
   864
            % (subrelpath(self), urlutil.hidepassword(dsturl))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   865
        )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   866
        other = hg.peer(self._repo, {b'ssh': ssh}, dsturl)
46663
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   867
        try:
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   868
            res = exchange.push(self._repo, other, force, newbranch=newbranch)
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   869
        finally:
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46113
diff changeset
   870
            other.close()
18939
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   871
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   872
        # the repo is now clean
aab0c14c20d0 subrepo: implement "storeclean" method for mercurial subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18937
diff changeset
   873
        self._cachestorehash(dsturl)
22619
f6cf96804d27 push: `exchange.push` instead of `localrepo.push`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22590
diff changeset
   874
        return res.cgresult
10177
5ca0d220ae21 subrepo: add table-based dispatch for subrepo types
Augie Fackler <durin42@gmail.com>
parents: 10175
diff changeset
   875
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   876
    @annotatesubrepoerror
12272
42ecd56399d7 outgoing: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12270
diff changeset
   877
    def outgoing(self, ui, dest, opts):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   878
        if b'rev' in opts or b'branch' in opts:
24875
5135c2be6959 subrepo: don't pass the outer repo's --rev or --branch to subrepo outgoing()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24858
diff changeset
   879
            opts = copy.copy(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   880
            opts.pop(b'rev', None)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   881
            opts.pop(b'branch', None)
46930
0afe96e374a7 outgoing: pass subrepo path using function argument instead of abssource hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   882
        subpath = subrepoutil.repo_rel_or_abs_source(self._repo)
0afe96e374a7 outgoing: pass subrepo path using function argument instead of abssource hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46907
diff changeset
   883
        return hg.outgoing(ui, self._repo, dest, opts, subpath=subpath)
12272
42ecd56399d7 outgoing: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12270
diff changeset
   884
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   885
    @annotatesubrepoerror
12274
c02e1ed3d407 incoming: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12272
diff changeset
   886
    def incoming(self, ui, source, opts):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   887
        if b'rev' in opts or b'branch' in opts:
24876
b5513ee85dd8 subrepo: don't pass the outer repo's --rev or --branch to subrepo incoming()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24875
diff changeset
   888
            opts = copy.copy(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   889
            opts.pop(b'rev', None)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   890
            opts.pop(b'branch', None)
46950
279df499511e incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46930
diff changeset
   891
        subpath = subrepoutil.repo_rel_or_abs_source(self._repo)
279df499511e incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46930
diff changeset
   892
        return hg.incoming(ui, self._repo, source, opts, subpath=subpath)
12274
c02e1ed3d407 incoming: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12272
diff changeset
   893
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   894
    @annotatesubrepoerror
12322
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   895
    def files(self):
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   896
        rev = self._state[1]
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   897
        ctx = self._repo[rev]
24173
2cc8ee4c4e1c subrepo: return only the manifest keys from hgsubrepo.files()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24148
diff changeset
   898
        return ctx.manifest().keys()
12322
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   899
31099
b44ab288358e subrepo: run the repo decoders when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 30755
diff changeset
   900
    def filedata(self, name, decode):
12322
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   901
        rev = self._state[1]
31099
b44ab288358e subrepo: run the repo decoders when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 30755
diff changeset
   902
        data = self._repo[rev][name].data()
b44ab288358e subrepo: run the repo decoders when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 30755
diff changeset
   903
        if decode:
b44ab288358e subrepo: run the repo decoders when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 30755
diff changeset
   904
            data = self._repo.wwritedata(name, data)
b44ab288358e subrepo: run the repo decoders when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 30755
diff changeset
   905
        return data
12322
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   906
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   907
    def fileflags(self, name):
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   908
        rev = self._state[1]
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   909
        ctx = self._repo[rev]
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   910
        return ctx.flags(name)
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   911
24413
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24409
diff changeset
   912
    @annotatesubrepoerror
41748
980e05204ed8 subrepo: use root-repo-relative path from `hg files` with ui.relative-paths=no
Martin von Zweigbergk <martinvonz@google.com>
parents: 41679
diff changeset
   913
    def printfiles(self, ui, m, uipathfn, fm, fmt, subrepos):
24413
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24409
diff changeset
   914
        # If the parent context is a workingctx, use the workingctx here for
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24409
diff changeset
   915
        # consistency.
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24409
diff changeset
   916
        if self._ctx.rev() is None:
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24409
diff changeset
   917
            ctx = self._repo[None]
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24409
diff changeset
   918
        else:
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24409
diff changeset
   919
            rev = self._state[1]
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24409
diff changeset
   920
            ctx = self._repo[rev]
41748
980e05204ed8 subrepo: use root-repo-relative path from `hg files` with ui.relative-paths=no
Martin von Zweigbergk <martinvonz@google.com>
parents: 41679
diff changeset
   921
        return cmdutil.files(ui, ctx, m, uipathfn, fm, fmt, subrepos)
24413
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24409
diff changeset
   922
25121
df63d4843581 subrepo: introduce getfileset()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24943
diff changeset
   923
    @annotatesubrepoerror
44009
e685fac56693 match: resolve filesets against the passed `cwd`, not the current one
Matt Harbison <matt_harbison@yahoo.com>
parents: 43913
diff changeset
   924
    def matchfileset(self, cwd, expr, badfn=None):
25121
df63d4843581 subrepo: introduce getfileset()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24943
diff changeset
   925
        if self._ctx.rev() is None:
41676
0531dff73d0b match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41675
diff changeset
   926
            ctx = self._repo[None]
25121
df63d4843581 subrepo: introduce getfileset()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24943
diff changeset
   927
        else:
df63d4843581 subrepo: introduce getfileset()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24943
diff changeset
   928
            rev = self._state[1]
41676
0531dff73d0b match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41675
diff changeset
   929
            ctx = self._repo[rev]
25121
df63d4843581 subrepo: introduce getfileset()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24943
diff changeset
   930
44009
e685fac56693 match: resolve filesets against the passed `cwd`, not the current one
Matt Harbison <matt_harbison@yahoo.com>
parents: 43913
diff changeset
   931
        matchers = [ctx.matchfileset(cwd, expr, badfn=badfn)]
25121
df63d4843581 subrepo: introduce getfileset()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24943
diff changeset
   932
df63d4843581 subrepo: introduce getfileset()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24943
diff changeset
   933
        for subpath in ctx.substate:
df63d4843581 subrepo: introduce getfileset()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24943
diff changeset
   934
            sub = ctx.sub(subpath)
df63d4843581 subrepo: introduce getfileset()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24943
diff changeset
   935
df63d4843581 subrepo: introduce getfileset()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24943
diff changeset
   936
            try:
44009
e685fac56693 match: resolve filesets against the passed `cwd`, not the current one
Matt Harbison <matt_harbison@yahoo.com>
parents: 43913
diff changeset
   937
                sm = sub.matchfileset(cwd, expr, badfn=badfn)
41675
ddbebce94665 match: delete unused root and cwd arguments to constructors (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41673
diff changeset
   938
                pm = matchmod.prefixdirmatcher(subpath, sm, badfn=badfn)
38612
760cc5dc01e8 fileset: restrict getfileset() to not return a computed set (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38379
diff changeset
   939
                matchers.append(pm)
25121
df63d4843581 subrepo: introduce getfileset()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24943
diff changeset
   940
            except error.LookupError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   941
                self.ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   942
                    _(b"skipping missing subrepository: %s\n")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   943
                    % self.wvfs.reljoin(reporelpath(self), subpath)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   944
                )
38612
760cc5dc01e8 fileset: restrict getfileset() to not return a computed set (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38379
diff changeset
   945
        if len(matchers) == 1:
760cc5dc01e8 fileset: restrict getfileset() to not return a computed set (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38379
diff changeset
   946
            return matchers[0]
760cc5dc01e8 fileset: restrict getfileset() to not return a computed set (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38379
diff changeset
   947
        return matchmod.unionmatcher(matchers)
25121
df63d4843581 subrepo: introduce getfileset()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24943
diff changeset
   948
15410
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15287
diff changeset
   949
    def walk(self, match):
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15287
diff changeset
   950
        ctx = self._repo[None]
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15287
diff changeset
   951
        return ctx.walk(match)
12322
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   952
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   953
    @annotatesubrepoerror
41653
16a49c778bde forget: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41652
diff changeset
   954
    def forget(self, match, prefix, uipathfn, dryrun, interactive):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   955
        return cmdutil.forget(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   956
            self.ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   957
            self._repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   958
            match,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   959
            prefix,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   960
            uipathfn,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   961
            True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   962
            dryrun=dryrun,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   963
            interactive=interactive,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   964
        )
12322
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
   965
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
   966
    @annotatesubrepoerror
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   967
    def removefiles(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   968
        self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   969
        matcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   970
        prefix,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   971
        uipathfn,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   972
        after,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   973
        force,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   974
        subrepos,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   975
        dryrun,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   976
        warnings,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   977
    ):
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   978
        return cmdutil.remove(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   979
            self.ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   980
            self._repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   981
            matcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   982
            prefix,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   983
            uipathfn,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   984
            after,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   985
            force,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   986
            subrepos,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   987
            dryrun,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
   988
        )
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 22927
diff changeset
   989
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 22927
diff changeset
   990
    @annotatesubrepoerror
23579
e1c39f207719 subrepo: drop the 'ui' parameter to revert()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23578
diff changeset
   991
    def revert(self, substate, *pats, **opts):
16430
6883c2363f44 revert: add support for reverting subrepos without --no-backup and/or --all
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16429
diff changeset
   992
        # reverting a subrepo is a 2 step process:
6883c2363f44 revert: add support for reverting subrepos without --no-backup and/or --all
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16429
diff changeset
   993
        # 1. if the no_backup is not set, revert all modified
6883c2363f44 revert: add support for reverting subrepos without --no-backup and/or --all
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16429
diff changeset
   994
        #    files inside the subrepo
6883c2363f44 revert: add support for reverting subrepos without --no-backup and/or --all
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16429
diff changeset
   995
        # 2. update the subrepo to the revision specified in
6883c2363f44 revert: add support for reverting subrepos without --no-backup and/or --all
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16429
diff changeset
   996
        #    the corresponding substate dictionary
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   997
        self.ui.status(_(b'reverting subrepo %s\n') % substate[0])
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
   998
        if not opts.get('no_backup'):
16430
6883c2363f44 revert: add support for reverting subrepos without --no-backup and/or --all
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16429
diff changeset
   999
            # Revert all files on the subrepo, creating backups
6883c2363f44 revert: add support for reverting subrepos without --no-backup and/or --all
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16429
diff changeset
  1000
            # Note that this will not recursively revert subrepos
6883c2363f44 revert: add support for reverting subrepos without --no-backup and/or --all
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16429
diff changeset
  1001
            # We could do it if there was a set:subrepos() predicate
6883c2363f44 revert: add support for reverting subrepos without --no-backup and/or --all
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16429
diff changeset
  1002
            opts = opts.copy()
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1003
            opts['date'] = None
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1004
            opts['rev'] = substate[1]
16430
6883c2363f44 revert: add support for reverting subrepos without --no-backup and/or --all
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16429
diff changeset
  1005
23579
e1c39f207719 subrepo: drop the 'ui' parameter to revert()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23578
diff changeset
  1006
            self.filerevert(*pats, **opts)
16429
71dcce391a44 revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16197
diff changeset
  1007
71dcce391a44 revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16197
diff changeset
  1008
        # Update the repo to the revision specified in the given substate
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1009
        if not opts.get('dry_run'):
24134
afed5d2e7985 revert: display full subrepo output with --dry-run
Matt Harbison <matt_harbison@yahoo.com>
parents: 24132
diff changeset
  1010
            self.get(substate, overwrite=True)
16429
71dcce391a44 revert: add support for reverting subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16197
diff changeset
  1011
23579
e1c39f207719 subrepo: drop the 'ui' parameter to revert()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23578
diff changeset
  1012
    def filerevert(self, *pats, **opts):
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1013
        ctx = self._repo[opts['rev']]
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1014
        if opts.get('all'):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1015
            pats = [b'set:modified()']
16430
6883c2363f44 revert: add support for reverting subrepos without --no-backup and/or --all
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16429
diff changeset
  1016
        else:
6883c2363f44 revert: add support for reverting subrepos without --no-backup and/or --all
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16429
diff changeset
  1017
            pats = []
45375
8c466bcb0879 revert: remove dangerous `parents` argument from `cmdutil.revert()`
Martin von Zweigbergk <martinvonz@google.com>
parents: 45072
diff changeset
  1018
        cmdutil.revert(self.ui, self._repo, ctx, *pats, **opts)
16430
6883c2363f44 revert: add support for reverting subrepos without --no-backup and/or --all
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16429
diff changeset
  1019
21400
78a60daacea8 subrepo: add shortid() method to subrepo classes
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21041
diff changeset
  1020
    def shortid(self, revid):
78a60daacea8 subrepo: add shortid() method to subrepo classes
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21041
diff changeset
  1021
        return revid[:12]
78a60daacea8 subrepo: add shortid() method to subrepo classes
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21041
diff changeset
  1022
34879
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1023
    @annotatesubrepoerror
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1024
    def unshare(self):
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1025
        # subrepo inherently violates our import layering rules
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1026
        # because it wants to make repo objects from deep inside the stack
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1027
        # so we manually delay the circular imports to not break
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1028
        # scripts that don't use our demand-loading
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1029
        global hg
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1030
        from . import hg as h
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1031
34879
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1032
        hg = h
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1033
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1034
        # Nothing prevents a user from sharing in a repo, and then making that a
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1035
        # subrepo.  Alternately, the previous unshare attempt may have failed
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1036
        # part way through.  So recurse whether or not this layer is shared.
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1037
        if self._repo.shared():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1038
            self.ui.status(_(b"unsharing subrepo '%s'\n") % self._relpath)
34879
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1039
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1040
        hg.unshare(self.ui, self._repo)
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
  1041
43913
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1042
    def verify(self, onpush=False):
25591
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25572
diff changeset
  1043
        try:
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25572
diff changeset
  1044
            rev = self._state[1]
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25572
diff changeset
  1045
            ctx = self._repo.unfiltered()[rev]
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25572
diff changeset
  1046
            if ctx.hidden():
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25572
diff changeset
  1047
                # Since hidden revisions aren't pushed/pulled, it seems worth an
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25572
diff changeset
  1048
                # explicit warning.
43913
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1049
                msg = _(b"subrepo '%s' is hidden in revision %s") % (
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1050
                    self._relpath,
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
  1051
                    short(self._ctx.node()),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1052
                )
43913
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1053
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1054
                if onpush:
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1055
                    raise error.Abort(msg)
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1056
                else:
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1057
                    self._repo.ui.warn(b'%s\n' % msg)
25591
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25572
diff changeset
  1058
            return 0
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25572
diff changeset
  1059
        except error.RepoLookupError:
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25572
diff changeset
  1060
            # A missing subrepo revision may be a case of needing to pull it, so
43913
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1061
            # don't treat this as an error for `hg verify`.
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1062
            msg = _(b"subrepo '%s' not found in revision %s") % (
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1063
                self._relpath,
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
  1064
                short(self._ctx.node()),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1065
            )
43913
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1066
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1067
            if onpush:
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1068
                raise error.Abort(msg)
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1069
            else:
4b7d5d10c45d exchange: ensure all outgoing subrepo references are present before pushing
Matt Harbison <matt_harbison@yahoo.com>
parents: 43789
diff changeset
  1070
                self._repo.ui.warn(b'%s\n' % msg)
25591
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25572
diff changeset
  1071
            return 0
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25572
diff changeset
  1072
24672
dd0b86f740ef subrepo: add wvfs field to access the working directory via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24671
diff changeset
  1073
    @propertycache
dd0b86f740ef subrepo: add wvfs field to access the working directory via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24671
diff changeset
  1074
    def wvfs(self):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1075
        """return own wvfs for efficiency and consistency"""
24672
dd0b86f740ef subrepo: add wvfs field to access the working directory via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24671
diff changeset
  1076
        return self._repo.wvfs
dd0b86f740ef subrepo: add wvfs field to access the working directory via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24671
diff changeset
  1077
24786
56e15db9109f subrepo: calculate _relpath for hgsubrepo based on self instead of parent
Matt Harbison <matt_harbison@yahoo.com>
parents: 24785
diff changeset
  1078
    @propertycache
56e15db9109f subrepo: calculate _relpath for hgsubrepo based on self instead of parent
Matt Harbison <matt_harbison@yahoo.com>
parents: 24785
diff changeset
  1079
    def _relpath(self):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1080
        """return path to this subrepository as seen from outermost repository"""
24786
56e15db9109f subrepo: calculate _relpath for hgsubrepo based on self instead of parent
Matt Harbison <matt_harbison@yahoo.com>
parents: 24785
diff changeset
  1081
        # Keep consistent dir separators by avoiding vfs.join(self._path)
56e15db9109f subrepo: calculate _relpath for hgsubrepo based on self instead of parent
Matt Harbison <matt_harbison@yahoo.com>
parents: 24785
diff changeset
  1082
        return reporelpath(self._repo)
56e15db9109f subrepo: calculate _relpath for hgsubrepo based on self instead of parent
Matt Harbison <matt_harbison@yahoo.com>
parents: 24785
diff changeset
  1083
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1084
11559
9d88597470af subrepo: add abstract superclass for subrepo classes
Martin Geisler <mg@lazybytes.net>
parents: 11470
diff changeset
  1085
class svnsubrepo(abstractsubrepo):
29021
92d37fb3f1aa verify: don't init subrepo when missing one is referenced (issue5128) (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 28949
diff changeset
  1086
    def __init__(self, ctx, path, state, allowcreate):
24671
98ab035e9332 subrepo: change arguments of abstractsubrepo.__init__ (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24645
diff changeset
  1087
        super(svnsubrepo, self).__init__(ctx, path)
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1088
        self._state = state
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1089
        self._exe = procutil.findexe(b'svn')
15190
6dc67dced8c1 subrepo: improve error message when svn isn't found
Matt Mackall <mpm@selenic.com>
parents: 15150
diff changeset
  1090
        if not self._exe:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1091
            raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1092
                _(b"'svn' executable not found for subrepo '%s'") % self._path
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1093
            )
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1094
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1095
    def _svncommand(self, commands, filename=b'', failok=False):
15190
6dc67dced8c1 subrepo: improve error message when svn isn't found
Matt Mackall <mpm@selenic.com>
parents: 15150
diff changeset
  1096
        cmd = [self._exe]
14506
733af5d9f6b2 subrepo: make stdin for svn a pipe for non-interactive use (issue2759)
Augie Fackler <durin42@gmail.com>
parents: 14505
diff changeset
  1097
        extrakw = {}
23572
40e62fbd7356 subrepo: rename the '_ui' member to 'ui'
Matt Harbison <matt_harbison@yahoo.com>
parents: 23571
diff changeset
  1098
        if not self.ui.interactive():
14506
733af5d9f6b2 subrepo: make stdin for svn a pipe for non-interactive use (issue2759)
Augie Fackler <durin42@gmail.com>
parents: 14505
diff changeset
  1099
            # Making stdin be a pipe should prevent svn from behaving
733af5d9f6b2 subrepo: make stdin for svn a pipe for non-interactive use (issue2759)
Augie Fackler <durin42@gmail.com>
parents: 14505
diff changeset
  1100
            # interactively even if we can't pass --non-interactive.
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1101
            extrakw['stdin'] = subprocess.PIPE
14506
733af5d9f6b2 subrepo: make stdin for svn a pipe for non-interactive use (issue2759)
Augie Fackler <durin42@gmail.com>
parents: 14505
diff changeset
  1102
            # Starting in svn 1.5 --non-interactive is a global flag
733af5d9f6b2 subrepo: make stdin for svn a pipe for non-interactive use (issue2759)
Augie Fackler <durin42@gmail.com>
parents: 14505
diff changeset
  1103
            # instead of being per-command, but we need to support 1.4 so
733af5d9f6b2 subrepo: make stdin for svn a pipe for non-interactive use (issue2759)
Augie Fackler <durin42@gmail.com>
parents: 14505
diff changeset
  1104
            # we have to be intelligent about what commands take
733af5d9f6b2 subrepo: make stdin for svn a pipe for non-interactive use (issue2759)
Augie Fackler <durin42@gmail.com>
parents: 14505
diff changeset
  1105
            # --non-interactive.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1106
            if commands[0] in (b'update', b'checkout', b'commit'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1107
                cmd.append(b'--non-interactive')
49392
b9fcf54030d7 subrepo: avoid opening console window for non-native subrepos on Windows
derekbrowncmu@gmail.com
parents: 49389
diff changeset
  1108
        if util.safehasattr(subprocess, 'CREATE_NO_WINDOW'):
b9fcf54030d7 subrepo: avoid opening console window for non-native subrepos on Windows
derekbrowncmu@gmail.com
parents: 49389
diff changeset
  1109
            # On Windows, prevent command prompts windows from popping up when
b9fcf54030d7 subrepo: avoid opening console window for non-native subrepos on Windows
derekbrowncmu@gmail.com
parents: 49389
diff changeset
  1110
            # running in pythonw.
b9fcf54030d7 subrepo: avoid opening console window for non-native subrepos on Windows
derekbrowncmu@gmail.com
parents: 49389
diff changeset
  1111
            extrakw['creationflags'] = getattr(subprocess, 'CREATE_NO_WINDOW')
14025
1052b1421a48 subrepo: tell Subversion when we are non-interactive (issue2759)
Augie Fackler <durin42@gmail.com>
parents: 13912
diff changeset
  1112
        cmd.extend(commands)
14050
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 14025
diff changeset
  1113
        if filename is not None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1114
            path = self.wvfs.reljoin(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1115
                self._ctx.repo().origroot, self._path, filename
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1116
            )
14050
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 14025
diff changeset
  1117
            cmd.append(path)
30635
a150173da1c1 py3: replace os.environ with encoding.environ (part 2 of 5)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30615
diff changeset
  1118
        env = dict(encoding.environ)
10271
9b38bec5dc29 subrepo: make svn use C locale for portability
Patrick Mezard <pmezard@gmail.com>
parents: 10264
diff changeset
  1119
        # Avoid localized output, preserve current locale for everything else.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1120
        lc_all = env.get(b'LC_ALL')
17705
6929b9c70be9 subrepo: setting LC_MESSAGES only works if LC_ALL is empty or unset
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17441
diff changeset
  1121
        if lc_all:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1122
            env[b'LANG'] = lc_all
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1123
            del env[b'LC_ALL']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1124
        env[b'LC_MESSAGES'] = b'C'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1125
        p = subprocess.Popen(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1126
            pycompat.rapply(procutil.tonativestr, cmd),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1127
            bufsize=-1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1128
            close_fds=procutil.closefds,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1129
            stdout=subprocess.PIPE,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1130
            stderr=subprocess.PIPE,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1131
            env=procutil.tonativeenv(env),
50045
bbe3a65bbd96 subrepo: let black expand some call on multiple lines early
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49392
diff changeset
  1132
            **extrakw,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1133
        )
41517
549f956ba2a9 py3: don't use universal_newlines in svnsubrepo
Yuya Nishihara <yuya@tcha.org>
parents: 41516
diff changeset
  1134
        stdout, stderr = map(util.fromnativeeol, p.communicate())
13014
d1c52354b0a9 subrepo: use subprocess directly to avoid python 2.6 bug
Patrick Mezard <pmezard@gmail.com>
parents: 13013
diff changeset
  1135
        stderr = stderr.strip()
14664
0ae98cd2a83f svn subrepos: work around checkout obstructions (issue2752)
Augie Fackler <durin42@gmail.com>
parents: 14556
diff changeset
  1136
        if not failok:
0ae98cd2a83f svn subrepos: work around checkout obstructions (issue2752)
Augie Fackler <durin42@gmail.com>
parents: 14556
diff changeset
  1137
            if p.returncode:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1138
                raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1139
                    stderr or b'exited with code %d' % p.returncode
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1140
                )
14664
0ae98cd2a83f svn subrepos: work around checkout obstructions (issue2752)
Augie Fackler <durin42@gmail.com>
parents: 14556
diff changeset
  1141
            if stderr:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1142
                self.ui.warn(stderr + b'\n')
14664
0ae98cd2a83f svn subrepos: work around checkout obstructions (issue2752)
Augie Fackler <durin42@gmail.com>
parents: 14556
diff changeset
  1143
        return stdout, stderr
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1144
14050
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 14025
diff changeset
  1145
    @propertycache
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 14025
diff changeset
  1146
    def _svnversion(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1147
        output, err = self._svncommand(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1148
            [b'--version', b'--quiet'], filename=None
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1149
        )
34068
6d21737c35bf py3: fix type of regex literals in subrepo.py
Yuya Nishihara <yuya@tcha.org>
parents: 34022
diff changeset
  1150
        m = re.search(br'^(\d+)\.(\d+)', output)
14050
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 14025
diff changeset
  1151
        if not m:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1152
            raise error.Abort(_(b'cannot retrieve svn tool version'))
14050
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 14025
diff changeset
  1153
        return (int(m.group(1)), int(m.group(2)))
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 14025
diff changeset
  1154
35661
1c0ee0befba0 svnsubrepo: add new method _svnmissing
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 35660
diff changeset
  1155
    def _svnmissing(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1156
        return not self.wvfs.exists(b'.svn')
35661
1c0ee0befba0 svnsubrepo: add new method _svnmissing
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 35660
diff changeset
  1157
13287
d0e0d3d43e14 subrepo: compare svn subrepo state to last committed revision
Patrick Mezard <pmezard@gmail.com>
parents: 13117
diff changeset
  1158
    def _wcrevs(self):
d0e0d3d43e14 subrepo: compare svn subrepo state to last committed revision
Patrick Mezard <pmezard@gmail.com>
parents: 13117
diff changeset
  1159
        # Get the working directory revision as well as the last
d0e0d3d43e14 subrepo: compare svn subrepo state to last committed revision
Patrick Mezard <pmezard@gmail.com>
parents: 13117
diff changeset
  1160
        # commit revision so we can compare the subrepo state with
d0e0d3d43e14 subrepo: compare svn subrepo state to last committed revision
Patrick Mezard <pmezard@gmail.com>
parents: 13117
diff changeset
  1161
        # both. We used to store the working directory one.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1162
        output, err = self._svncommand([b'info', b'--xml'])
49389
093e5c274f54 typing: suppress a few pyi-errors with more recent pytype
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
  1163
        doc = xml.dom.minidom.parseString(output)  # pytype: disable=pyi-error
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1164
        entries = doc.getElementsByTagName('entry')
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1165
        lastrev, rev = b'0', b'0'
13287
d0e0d3d43e14 subrepo: compare svn subrepo state to last committed revision
Patrick Mezard <pmezard@gmail.com>
parents: 13117
diff changeset
  1166
        if entries:
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1167
            rev = pycompat.bytestr(entries[0].getAttribute('revision')) or b'0'
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1168
            commits = entries[0].getElementsByTagName('commit')
13287
d0e0d3d43e14 subrepo: compare svn subrepo state to last committed revision
Patrick Mezard <pmezard@gmail.com>
parents: 13117
diff changeset
  1169
            if commits:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1170
                lastrev = (
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1171
                    pycompat.bytestr(commits[0].getAttribute('revision'))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1172
                    or b'0'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1173
                )
13287
d0e0d3d43e14 subrepo: compare svn subrepo state to last committed revision
Patrick Mezard <pmezard@gmail.com>
parents: 13117
diff changeset
  1174
        return (lastrev, rev)
d0e0d3d43e14 subrepo: compare svn subrepo state to last committed revision
Patrick Mezard <pmezard@gmail.com>
parents: 13117
diff changeset
  1175
d0e0d3d43e14 subrepo: compare svn subrepo state to last committed revision
Patrick Mezard <pmezard@gmail.com>
parents: 13117
diff changeset
  1176
    def _wcrev(self):
d0e0d3d43e14 subrepo: compare svn subrepo state to last committed revision
Patrick Mezard <pmezard@gmail.com>
parents: 13117
diff changeset
  1177
        return self._wcrevs()[0]
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1178
10273
e898bc7810ad subrepo: handle svn externals and meta changes (issue1982)
Patrick Mezard <pmezard@gmail.com>
parents: 10272
diff changeset
  1179
    def _wcchanged(self):
16530
e37199a1f9d4 subrepo/svn: improve error message on missing files
Patrick Mezard <patrick@mezard.eu>
parents: 16529
diff changeset
  1180
        """Return (changes, extchanges, missing) where changes is True
e37199a1f9d4 subrepo/svn: improve error message on missing files
Patrick Mezard <patrick@mezard.eu>
parents: 16529
diff changeset
  1181
        if the working directory was changed, extchanges is
e37199a1f9d4 subrepo/svn: improve error message on missing files
Patrick Mezard <patrick@mezard.eu>
parents: 16529
diff changeset
  1182
        True if any of these changes concern an external entry and missing
e37199a1f9d4 subrepo/svn: improve error message on missing files
Patrick Mezard <patrick@mezard.eu>
parents: 16529
diff changeset
  1183
        is True if any change is a missing entry.
10273
e898bc7810ad subrepo: handle svn externals and meta changes (issue1982)
Patrick Mezard <pmezard@gmail.com>
parents: 10272
diff changeset
  1184
        """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1185
        output, err = self._svncommand([b'status', b'--xml'])
16530
e37199a1f9d4 subrepo/svn: improve error message on missing files
Patrick Mezard <patrick@mezard.eu>
parents: 16529
diff changeset
  1186
        externals, changes, missing = [], [], []
49389
093e5c274f54 typing: suppress a few pyi-errors with more recent pytype
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
  1187
        doc = xml.dom.minidom.parseString(output)  # pytype: disable=pyi-error
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1188
        for e in doc.getElementsByTagName('entry'):
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1189
            s = e.getElementsByTagName('wc-status')
10273
e898bc7810ad subrepo: handle svn externals and meta changes (issue1982)
Patrick Mezard <pmezard@gmail.com>
parents: 10272
diff changeset
  1190
            if not s:
e898bc7810ad subrepo: handle svn externals and meta changes (issue1982)
Patrick Mezard <pmezard@gmail.com>
parents: 10272
diff changeset
  1191
                continue
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1192
            item = s[0].getAttribute('item')
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1193
            props = s[0].getAttribute('props')
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1194
            path = e.getAttribute('path').encode('utf8')
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1195
            if item == 'external':
10273
e898bc7810ad subrepo: handle svn externals and meta changes (issue1982)
Patrick Mezard <pmezard@gmail.com>
parents: 10272
diff changeset
  1196
                externals.append(path)
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1197
            elif item == 'missing':
16530
e37199a1f9d4 subrepo/svn: improve error message on missing files
Patrick Mezard <patrick@mezard.eu>
parents: 16529
diff changeset
  1198
                missing.append(path)
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1199
            if (
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1200
                item
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1201
                not in (
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1202
                    '',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1203
                    'normal',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1204
                    'unversioned',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1205
                    'external',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1206
                )
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1207
                or props not in ('', 'none', 'normal')
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1208
            ):
10273
e898bc7810ad subrepo: handle svn externals and meta changes (issue1982)
Patrick Mezard <pmezard@gmail.com>
parents: 10272
diff changeset
  1209
                changes.append(path)
e898bc7810ad subrepo: handle svn externals and meta changes (issue1982)
Patrick Mezard <pmezard@gmail.com>
parents: 10272
diff changeset
  1210
        for path in changes:
e898bc7810ad subrepo: handle svn externals and meta changes (issue1982)
Patrick Mezard <pmezard@gmail.com>
parents: 10272
diff changeset
  1211
            for ext in externals:
30615
bb77654dc7ae py3: replace os.sep with pycompat.ossep (part 3 of 4)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30060
diff changeset
  1212
                if path == ext or path.startswith(ext + pycompat.ossep):
16530
e37199a1f9d4 subrepo/svn: improve error message on missing files
Patrick Mezard <patrick@mezard.eu>
parents: 16529
diff changeset
  1213
                    return True, True, bool(missing)
e37199a1f9d4 subrepo/svn: improve error message on missing files
Patrick Mezard <patrick@mezard.eu>
parents: 16529
diff changeset
  1214
        return bool(changes), False, bool(missing)
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1215
35660
73f51bdb0fea svnsubrepo: decorate dirty method with annotatesubrepoerror
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 35621
diff changeset
  1216
    @annotatesubrepoerror
33364
bf2daeddd42b subrepo: consider the parent repo dirty when a file is missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 32584
diff changeset
  1217
    def dirty(self, ignoreupdate=False, missing=False):
35676
9c575c22dcf4 svnsubrepo: check if subrepo is missing when checking dirty state (issue5657)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 35661
diff changeset
  1218
        if self._svnmissing():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1219
            return self._state[1] != b''
33364
bf2daeddd42b subrepo: consider the parent repo dirty when a file is missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 32584
diff changeset
  1220
        wcchanged = self._wcchanged()
bf2daeddd42b subrepo: consider the parent repo dirty when a file is missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 32584
diff changeset
  1221
        changed = wcchanged[0] or (missing and wcchanged[2])
bf2daeddd42b subrepo: consider the parent repo dirty when a file is missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 32584
diff changeset
  1222
        if not changed:
13288
9c3bfba3f48d Merge with stable
Patrick Mezard <pmezard@gmail.com>
parents: 13242 13287
diff changeset
  1223
            if self._state[1] in self._wcrevs() or ignoreupdate:
13174
be7e8e9bc5e5 mq: update .hgsubstate if subrepos are clean (issue2499)
Kevin Bullock <kbullock@ringworld.org>
parents: 13172
diff changeset
  1224
                return False
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1225
        return True
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1226
16072
bcb973abcc0b subrepo: add basestate method
Matt Mackall <mpm@selenic.com>
parents: 16022
diff changeset
  1227
    def basestate(self):
16554
ae2664ee0223 subrepo/svn: fix checked out rev number retrieval (issue2968)
Patrick Mezard <patrick@mezard.eu>
parents: 16530
diff changeset
  1228
        lastrev, rev = self._wcrevs()
ae2664ee0223 subrepo/svn: fix checked out rev number retrieval (issue2968)
Patrick Mezard <patrick@mezard.eu>
parents: 16530
diff changeset
  1229
        if lastrev != rev:
ae2664ee0223 subrepo/svn: fix checked out rev number retrieval (issue2968)
Patrick Mezard <patrick@mezard.eu>
parents: 16530
diff changeset
  1230
            # Last committed rev is not the same than rev. We would
ae2664ee0223 subrepo/svn: fix checked out rev number retrieval (issue2968)
Patrick Mezard <patrick@mezard.eu>
parents: 16530
diff changeset
  1231
            # like to take lastrev but we do not know if the subrepo
ae2664ee0223 subrepo/svn: fix checked out rev number retrieval (issue2968)
Patrick Mezard <patrick@mezard.eu>
parents: 16530
diff changeset
  1232
            # URL exists at lastrev.  Test it and fallback to rev it
ae2664ee0223 subrepo/svn: fix checked out rev number retrieval (issue2968)
Patrick Mezard <patrick@mezard.eu>
parents: 16530
diff changeset
  1233
            # is not there.
ae2664ee0223 subrepo/svn: fix checked out rev number retrieval (issue2968)
Patrick Mezard <patrick@mezard.eu>
parents: 16530
diff changeset
  1234
            try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1235
                self._svncommand(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1236
                    [b'list', b'%s@%s' % (self._state[0], lastrev)]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1237
                )
16554
ae2664ee0223 subrepo/svn: fix checked out rev number retrieval (issue2968)
Patrick Mezard <patrick@mezard.eu>
parents: 16530
diff changeset
  1238
                return lastrev
ae2664ee0223 subrepo/svn: fix checked out rev number retrieval (issue2968)
Patrick Mezard <patrick@mezard.eu>
parents: 16530
diff changeset
  1239
            except error.Abort:
ae2664ee0223 subrepo/svn: fix checked out rev number retrieval (issue2968)
Patrick Mezard <patrick@mezard.eu>
parents: 16530
diff changeset
  1240
                pass
ae2664ee0223 subrepo/svn: fix checked out rev number retrieval (issue2968)
Patrick Mezard <patrick@mezard.eu>
parents: 16530
diff changeset
  1241
        return rev
16072
bcb973abcc0b subrepo: add basestate method
Matt Mackall <mpm@selenic.com>
parents: 16022
diff changeset
  1242
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
  1243
    @annotatesubrepoerror
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1244
    def commit(self, text, user, date):
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1245
        # user and date are out of our hands since svn is centralized
16530
e37199a1f9d4 subrepo/svn: improve error message on missing files
Patrick Mezard <patrick@mezard.eu>
parents: 16529
diff changeset
  1246
        changed, extchanged, missing = self._wcchanged()
10273
e898bc7810ad subrepo: handle svn externals and meta changes (issue1982)
Patrick Mezard <pmezard@gmail.com>
parents: 10272
diff changeset
  1247
        if not changed:
16554
ae2664ee0223 subrepo/svn: fix checked out rev number retrieval (issue2968)
Patrick Mezard <patrick@mezard.eu>
parents: 16530
diff changeset
  1248
            return self.basestate()
10273
e898bc7810ad subrepo: handle svn externals and meta changes (issue1982)
Patrick Mezard <pmezard@gmail.com>
parents: 10272
diff changeset
  1249
        if extchanged:
e898bc7810ad subrepo: handle svn externals and meta changes (issue1982)
Patrick Mezard <pmezard@gmail.com>
parents: 10272
diff changeset
  1250
            # Do not try to commit externals
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1251
            raise error.Abort(_(b'cannot commit svn externals'))
16530
e37199a1f9d4 subrepo/svn: improve error message on missing files
Patrick Mezard <patrick@mezard.eu>
parents: 16529
diff changeset
  1252
        if missing:
e37199a1f9d4 subrepo/svn: improve error message on missing files
Patrick Mezard <patrick@mezard.eu>
parents: 16529
diff changeset
  1253
            # svn can commit with missing entries but aborting like hg
e37199a1f9d4 subrepo/svn: improve error message on missing files
Patrick Mezard <patrick@mezard.eu>
parents: 16529
diff changeset
  1254
            # seems a better approach.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1255
            raise error.Abort(_(b'cannot commit missing svn entries'))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1256
        commitinfo, err = self._svncommand([b'commit', b'-m', text])
23572
40e62fbd7356 subrepo: rename the '_ui' member to 'ui'
Matt Harbison <matt_harbison@yahoo.com>
parents: 23571
diff changeset
  1257
        self.ui.status(commitinfo)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1258
        newrev = re.search(b'Committed revision ([0-9]+).', commitinfo)
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1259
        if not newrev:
16529
3d5d204a08c7 subrepo/svn: abort on commit with missing file (issue3029)
Patrick Mezard <patrick@mezard.eu>
parents: 16527
diff changeset
  1260
            if not commitinfo.strip():
3d5d204a08c7 subrepo/svn: abort on commit with missing file (issue3029)
Patrick Mezard <patrick@mezard.eu>
parents: 16527
diff changeset
  1261
                # Sometimes, our definition of "changed" differs from
3d5d204a08c7 subrepo/svn: abort on commit with missing file (issue3029)
Patrick Mezard <patrick@mezard.eu>
parents: 16527
diff changeset
  1262
                # svn one. For instance, svn ignores missing files
3d5d204a08c7 subrepo/svn: abort on commit with missing file (issue3029)
Patrick Mezard <patrick@mezard.eu>
parents: 16527
diff changeset
  1263
                # when committing. If there are only missing files, no
3d5d204a08c7 subrepo/svn: abort on commit with missing file (issue3029)
Patrick Mezard <patrick@mezard.eu>
parents: 16527
diff changeset
  1264
                # commit is made, no output and no error code.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1265
                raise error.Abort(_(b'failed to commit svn changes'))
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25980
diff changeset
  1266
            raise error.Abort(commitinfo.splitlines()[-1])
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1267
        newrev = newrev.groups()[0]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1268
        self.ui.status(self._svncommand([b'update', b'-r', newrev])[0])
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1269
        return newrev
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1270
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
  1271
    @annotatesubrepoerror
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1272
    def remove(self):
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1273
        if self.dirty():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1274
            self.ui.warn(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
  1275
                _(b'not removing repo %s because it has changes.\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1276
                % self._path
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1277
            )
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1278
            return
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1279
        self.ui.note(_(b'removing subrepo %s\n') % self._path)
13013
92b0d669637f subrepo: fix removing read-only svn files on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 12930
diff changeset
  1280
24690
d1ddf1fe5d33 subrepo: use vfs.rmtree instead of shutil.rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24688
diff changeset
  1281
        self.wvfs.rmtree(forcibly=True)
13015
82ca0c43bc44 subrepo: prune empty directories when removing svn subrepo
Patrick Mezard <pmezard@gmail.com>
parents: 13014
diff changeset
  1282
        try:
25773
de654a83fe1c subrepo: use vfs.dirname instead of os.path.dirname
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25771
diff changeset
  1283
            pwvfs = self._ctx.repo().wvfs
de654a83fe1c subrepo: use vfs.dirname instead of os.path.dirname
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25771
diff changeset
  1284
            pwvfs.removedirs(pwvfs.dirname(self._path))
13015
82ca0c43bc44 subrepo: prune empty directories when removing svn subrepo
Patrick Mezard <pmezard@gmail.com>
parents: 13014
diff changeset
  1285
        except OSError:
82ca0c43bc44 subrepo: prune empty directories when removing svn subrepo
Patrick Mezard <pmezard@gmail.com>
parents: 13014
diff changeset
  1286
            pass
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1287
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
  1288
    @annotatesubrepoerror
13322
c19b9282d3a7 subrepo: make update -C clean the working directory for svn subrepos
Erik Zielke <ez@aragost.com>
parents: 13287
diff changeset
  1289
    def get(self, state, overwrite=False):
c19b9282d3a7 subrepo: make update -C clean the working directory for svn subrepos
Erik Zielke <ez@aragost.com>
parents: 13287
diff changeset
  1290
        if overwrite:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1291
            self._svncommand([b'revert', b'--recursive'])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1292
        args = [b'checkout']
14050
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 14025
diff changeset
  1293
        if self._svnversion >= (1, 5):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1294
            args.append(b'--force')
14820
7ef125fa9b35 subrepo: correct revision in svn checkout
Eli Carter <eli.carter@tektronix.com>
parents: 14766
diff changeset
  1295
        # The revision must be specified at the end of the URL to properly
7ef125fa9b35 subrepo: correct revision in svn checkout
Eli Carter <eli.carter@tektronix.com>
parents: 14766
diff changeset
  1296
        # update to a directory which has since been deleted and recreated.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1297
        args.append(b'%s@%s' % (state[0], state[1]))
33657
60ee7af2a2ba subrepo: add tests for svn rogue ssh urls (SEC)
Sean Farley <sean@farley.io>
parents: 33499
diff changeset
  1298
60ee7af2a2ba subrepo: add tests for svn rogue ssh urls (SEC)
Sean Farley <sean@farley.io>
parents: 33499
diff changeset
  1299
        # SEC: check that the ssh url is safe
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
  1300
        urlutil.checksafessh(state[0])
33657
60ee7af2a2ba subrepo: add tests for svn rogue ssh urls (SEC)
Sean Farley <sean@farley.io>
parents: 33499
diff changeset
  1301
14664
0ae98cd2a83f svn subrepos: work around checkout obstructions (issue2752)
Augie Fackler <durin42@gmail.com>
parents: 14556
diff changeset
  1302
        status, err = self._svncommand(args, failok=True)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1303
        _sanitize(self.ui, self.wvfs, b'.svn')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1304
        if not re.search(b'Checked out revision [0-9]+.', status):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1305
            if b'is already a working copy for a different URL' in err and (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1306
                self._wcchanged()[:2] == (False, False)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1307
            ):
14664
0ae98cd2a83f svn subrepos: work around checkout obstructions (issue2752)
Augie Fackler <durin42@gmail.com>
parents: 14556
diff changeset
  1308
                # obstructed but clean working copy, so just blow it away.
0ae98cd2a83f svn subrepos: work around checkout obstructions (issue2752)
Augie Fackler <durin42@gmail.com>
parents: 14556
diff changeset
  1309
                self.remove()
0ae98cd2a83f svn subrepos: work around checkout obstructions (issue2752)
Augie Fackler <durin42@gmail.com>
parents: 14556
diff changeset
  1310
                self.get(state, overwrite=False)
0ae98cd2a83f svn subrepos: work around checkout obstructions (issue2752)
Augie Fackler <durin42@gmail.com>
parents: 14556
diff changeset
  1311
                return
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25980
diff changeset
  1312
            raise error.Abort((status or err).splitlines()[-1])
23572
40e62fbd7356 subrepo: rename the '_ui' member to 'ui'
Matt Harbison <matt_harbison@yahoo.com>
parents: 23571
diff changeset
  1313
        self.ui.status(status)
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1314
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
  1315
    @annotatesubrepoerror
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1316
    def merge(self, state):
13417
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
  1317
        old = self._state[1]
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
  1318
        new = state[1]
16555
4955e7bf085c subrepo/svn: cache _wcrev() value in merge()
Patrick Mezard <patrick@mezard.eu>
parents: 16554
diff changeset
  1319
        wcrev = self._wcrev()
4955e7bf085c subrepo/svn: cache _wcrev() value in merge()
Patrick Mezard <patrick@mezard.eu>
parents: 16554
diff changeset
  1320
        if new != wcrev:
4955e7bf085c subrepo/svn: cache _wcrev() value in merge()
Patrick Mezard <patrick@mezard.eu>
parents: 16554
diff changeset
  1321
            dirty = old == wcrev or self._wcchanged()[0]
23572
40e62fbd7356 subrepo: rename the '_ui' member to 'ui'
Matt Harbison <matt_harbison@yahoo.com>
parents: 23571
diff changeset
  1322
            if _updateprompt(self.ui, self, dirty, wcrev, new):
13417
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
  1323
                self.get(state, False)
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1324
15708
309e49491253 push: propagate --new-branch and --ssh options when pushing subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15614
diff changeset
  1325
    def push(self, opts):
11455
3827728b54e2 subrepo: fix silent push failure for SVN (issue2241)
Matt Mackall <mpm@selenic.com>
parents: 11117
diff changeset
  1326
        # push is a no-op for SVN
3827728b54e2 subrepo: fix silent push failure for SVN (issue2241)
Matt Mackall <mpm@selenic.com>
parents: 11117
diff changeset
  1327
        return True
10178
cd477be6f2fc subrepo: Subversion support
Augie Fackler <durin42@gmail.com>
parents: 10177
diff changeset
  1328
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
  1329
    @annotatesubrepoerror
12322
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
  1330
    def files(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1331
        output = self._svncommand([b'list', b'--recursive', b'--xml'])[0]
49389
093e5c274f54 typing: suppress a few pyi-errors with more recent pytype
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
  1332
        doc = xml.dom.minidom.parseString(output)  # pytype: disable=pyi-error
16450
c9c8c9053119 archive: make it work with svn subrepos (issue3308)
Patrick Mezard <patrick@mezard.eu>
parents: 16196
diff changeset
  1333
        paths = []
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1334
        for e in doc.getElementsByTagName('entry'):
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1335
            kind = pycompat.bytestr(e.getAttribute('kind'))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1336
            if kind != b'file':
16450
c9c8c9053119 archive: make it work with svn subrepos (issue3308)
Patrick Mezard <patrick@mezard.eu>
parents: 16196
diff changeset
  1337
                continue
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1338
            name = ''.join(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1339
                c.data
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1340
                for c in e.getElementsByTagName('name')[0].childNodes
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1341
                if c.nodeType == c.TEXT_NODE
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1342
            )
41494
fa7d4e6a0c98 subrepo: clean up lingering bytes/str issues in svn support
Augie Fackler <augie@google.com>
parents: 41483
diff changeset
  1343
            paths.append(name.encode('utf8'))
16450
c9c8c9053119 archive: make it work with svn subrepos (issue3308)
Patrick Mezard <patrick@mezard.eu>
parents: 16196
diff changeset
  1344
        return paths
12322
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
  1345
31099
b44ab288358e subrepo: run the repo decoders when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 30755
diff changeset
  1346
    def filedata(self, name, decode):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1347
        return self._svncommand([b'cat'], name)[0]
12322
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
  1348
510afb31cf99 subrepo: introduce files and filedata methods for subrepo classes
Martin Geisler <mg@aragost.com>
parents: 12274
diff changeset
  1349
13106
c869bd9e1193 subrepo: gitsubrepo should inherit from abstractsubrepo
Eric Eisner <ede@mit.edu>
parents: 13097
diff changeset
  1350
class gitsubrepo(abstractsubrepo):
29021
92d37fb3f1aa verify: don't init subrepo when missing one is referenced (issue5128) (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 28949
diff changeset
  1351
    def __init__(self, ctx, path, state, allowcreate):
24671
98ab035e9332 subrepo: change arguments of abstractsubrepo.__init__ (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24645
diff changeset
  1352
        super(gitsubrepo, self).__init__(ctx, path)
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1353
        self._state = state
24302
6e092ea2eff1 subrepo: replace 'ctx._repo' with 'ctx.repo()'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24256
diff changeset
  1354
        self._abspath = ctx.repo().wjoin(path)
6e092ea2eff1 subrepo: replace 'ctx._repo' with 'ctx.repo()'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24256
diff changeset
  1355
        self._subparent = ctx.repo()
17024
33b057778cd2 subrepo: warn user if Git is not version 1.6.0 or higher
Benjamin Pollack <benjamin@bitquabit.com>
parents: 16596
diff changeset
  1356
        self._ensuregit()
33b057778cd2 subrepo: warn user if Git is not version 1.6.0 or higher
Benjamin Pollack <benjamin@bitquabit.com>
parents: 16596
diff changeset
  1357
33b057778cd2 subrepo: warn user if Git is not version 1.6.0 or higher
Benjamin Pollack <benjamin@bitquabit.com>
parents: 16596
diff changeset
  1358
    def _ensuregit(self):
17025
8ad08dcab7d9 subrepo: support Git being named "git.cmd" on Windows (issue3173)
Benjamin Pollack <benjamin@bitquabit.com>
parents: 17024
diff changeset
  1359
        try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1360
            self._gitexecutable = b'git'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1361
            out, err = self._gitnodir([b'--version'])
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25658
diff changeset
  1362
        except OSError as e:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1363
            genericerror = _(b"error executing git for subrepo '%s': %s")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1364
            notfoundhint = _(b"check git is installed and in your PATH")
27935
594bdc380aa2 subrepo: better error messages in _ensuregit
Mason Malone <mason.malone@gmail.com>
parents: 27844
diff changeset
  1365
            if e.errno != errno.ENOENT:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1366
                raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1367
                    genericerror % (self._path, encoding.strtolocal(e.strerror))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1368
                )
34645
75979c8d4572 codemod: use pycompat.iswindows
Jun Wu <quark@fb.com>
parents: 34382
diff changeset
  1369
            elif pycompat.iswindows:
27935
594bdc380aa2 subrepo: better error messages in _ensuregit
Mason Malone <mason.malone@gmail.com>
parents: 27844
diff changeset
  1370
                try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1371
                    self._gitexecutable = b'git.cmd'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1372
                    out, err = self._gitnodir([b'--version'])
27935
594bdc380aa2 subrepo: better error messages in _ensuregit
Mason Malone <mason.malone@gmail.com>
parents: 27844
diff changeset
  1373
                except OSError as e2:
594bdc380aa2 subrepo: better error messages in _ensuregit
Mason Malone <mason.malone@gmail.com>
parents: 27844
diff changeset
  1374
                    if e2.errno == errno.ENOENT:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1375
                        raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1376
                            _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1377
                                b"couldn't find 'git' or 'git.cmd'"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1378
                                b" for subrepo '%s'"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1379
                            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1380
                            % self._path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1381
                            hint=notfoundhint,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1382
                        )
27935
594bdc380aa2 subrepo: better error messages in _ensuregit
Mason Malone <mason.malone@gmail.com>
parents: 27844
diff changeset
  1383
                    else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1384
                        raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1385
                            genericerror
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1386
                            % (self._path, encoding.strtolocal(e2.strerror))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1387
                        )
27935
594bdc380aa2 subrepo: better error messages in _ensuregit
Mason Malone <mason.malone@gmail.com>
parents: 27844
diff changeset
  1388
            else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1389
                raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1390
                    _(b"couldn't find git for subrepo '%s'") % self._path,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1391
                    hint=notfoundhint,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1392
                )
20840
308344d80fe5 subrepo: factor out Git version check to add doctests
Siddharth Agarwal <sid0@fb.com>
parents: 20818
diff changeset
  1393
        versionstatus = self._checkversion(out)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1394
        if versionstatus == b'unknown':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1395
            self.ui.warn(_(b'cannot retrieve git version\n'))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1396
        elif versionstatus == b'abort':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1397
            raise error.Abort(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1398
                _(b'git subrepo requires at least 1.6.0 or later')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1399
            )
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1400
        elif versionstatus == b'warning':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1401
            self.ui.warn(_(b'git subrepo requires at least 1.6.0 or later\n'))
20840
308344d80fe5 subrepo: factor out Git version check to add doctests
Siddharth Agarwal <sid0@fb.com>
parents: 20818
diff changeset
  1402
308344d80fe5 subrepo: factor out Git version check to add doctests
Siddharth Agarwal <sid0@fb.com>
parents: 20818
diff changeset
  1403
    @staticmethod
23521
f5de2a82b77e subrepo: move git version check into a separate method
Mathias De Maré <mathias.demare@gmail.com>
parents: 23411
diff changeset
  1404
    def _gitversion(out):
34068
6d21737c35bf py3: fix type of regex literals in subrepo.py
Yuya Nishihara <yuya@tcha.org>
parents: 34022
diff changeset
  1405
        m = re.search(br'^git version (\d+)\.(\d+)\.(\d+)', out)
23522
49a58b33d1ce subrepo: extend git version check to 3 digits
Mathias De Maré <mathias.demare@gmail.com>
parents: 23521
diff changeset
  1406
        if m:
49a58b33d1ce subrepo: extend git version check to 3 digits
Mathias De Maré <mathias.demare@gmail.com>
parents: 23521
diff changeset
  1407
            return (int(m.group(1)), int(m.group(2)), int(m.group(3)))
49a58b33d1ce subrepo: extend git version check to 3 digits
Mathias De Maré <mathias.demare@gmail.com>
parents: 23521
diff changeset
  1408
34068
6d21737c35bf py3: fix type of regex literals in subrepo.py
Yuya Nishihara <yuya@tcha.org>
parents: 34022
diff changeset
  1409
        m = re.search(br'^git version (\d+)\.(\d+)', out)
23521
f5de2a82b77e subrepo: move git version check into a separate method
Mathias De Maré <mathias.demare@gmail.com>
parents: 23411
diff changeset
  1410
        if m:
23522
49a58b33d1ce subrepo: extend git version check to 3 digits
Mathias De Maré <mathias.demare@gmail.com>
parents: 23521
diff changeset
  1411
            return (int(m.group(1)), int(m.group(2)), 0)
23521
f5de2a82b77e subrepo: move git version check into a separate method
Mathias De Maré <mathias.demare@gmail.com>
parents: 23411
diff changeset
  1412
f5de2a82b77e subrepo: move git version check into a separate method
Mathias De Maré <mathias.demare@gmail.com>
parents: 23411
diff changeset
  1413
        return -1
f5de2a82b77e subrepo: move git version check into a separate method
Mathias De Maré <mathias.demare@gmail.com>
parents: 23411
diff changeset
  1414
f5de2a82b77e subrepo: move git version check into a separate method
Mathias De Maré <mathias.demare@gmail.com>
parents: 23411
diff changeset
  1415
    @staticmethod
20840
308344d80fe5 subrepo: factor out Git version check to add doctests
Siddharth Agarwal <sid0@fb.com>
parents: 20818
diff changeset
  1416
    def _checkversion(out):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1417
        """ensure git version is new enough
20840
308344d80fe5 subrepo: factor out Git version check to add doctests
Siddharth Agarwal <sid0@fb.com>
parents: 20818
diff changeset
  1418
308344d80fe5 subrepo: factor out Git version check to add doctests
Siddharth Agarwal <sid0@fb.com>
parents: 20818
diff changeset
  1419
        >>> _checkversion = gitsubrepo._checkversion
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 34068
diff changeset
  1420
        >>> _checkversion(b'git version 1.6.0')
20840
308344d80fe5 subrepo: factor out Git version check to add doctests
Siddharth Agarwal <sid0@fb.com>
parents: 20818
diff changeset
  1421
        'ok'
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 34068
diff changeset
  1422
        >>> _checkversion(b'git version 1.8.5')
20840
308344d80fe5 subrepo: factor out Git version check to add doctests
Siddharth Agarwal <sid0@fb.com>
parents: 20818
diff changeset
  1423
        'ok'
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 34068
diff changeset
  1424
        >>> _checkversion(b'git version 1.4.0')
20840
308344d80fe5 subrepo: factor out Git version check to add doctests
Siddharth Agarwal <sid0@fb.com>
parents: 20818
diff changeset
  1425
        'abort'
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 34068
diff changeset
  1426
        >>> _checkversion(b'git version 1.5.0')
20840
308344d80fe5 subrepo: factor out Git version check to add doctests
Siddharth Agarwal <sid0@fb.com>
parents: 20818
diff changeset
  1427
        'warning'
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 34068
diff changeset
  1428
        >>> _checkversion(b'git version 1.9-rc0')
20840
308344d80fe5 subrepo: factor out Git version check to add doctests
Siddharth Agarwal <sid0@fb.com>
parents: 20818
diff changeset
  1429
        'ok'
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 34068
diff changeset
  1430
        >>> _checkversion(b'git version 1.9.0.265.g81cdec2')
20840
308344d80fe5 subrepo: factor out Git version check to add doctests
Siddharth Agarwal <sid0@fb.com>
parents: 20818
diff changeset
  1431
        'ok'
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 34068
diff changeset
  1432
        >>> _checkversion(b'git version 1.9.0.GIT')
20840
308344d80fe5 subrepo: factor out Git version check to add doctests
Siddharth Agarwal <sid0@fb.com>
parents: 20818
diff changeset
  1433
        'ok'
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 34068
diff changeset
  1434
        >>> _checkversion(b'git version 12345')
20840
308344d80fe5 subrepo: factor out Git version check to add doctests
Siddharth Agarwal <sid0@fb.com>
parents: 20818
diff changeset
  1435
        'unknown'
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 34068
diff changeset
  1436
        >>> _checkversion(b'no')
20840
308344d80fe5 subrepo: factor out Git version check to add doctests
Siddharth Agarwal <sid0@fb.com>
parents: 20818
diff changeset
  1437
        'unknown'
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1438
        """
23521
f5de2a82b77e subrepo: move git version check into a separate method
Mathias De Maré <mathias.demare@gmail.com>
parents: 23411
diff changeset
  1439
        version = gitsubrepo._gitversion(out)
17024
33b057778cd2 subrepo: warn user if Git is not version 1.6.0 or higher
Benjamin Pollack <benjamin@bitquabit.com>
parents: 16596
diff changeset
  1440
        # git 1.4.0 can't work at all, but 1.5.X can in at least some cases,
33b057778cd2 subrepo: warn user if Git is not version 1.6.0 or higher
Benjamin Pollack <benjamin@bitquabit.com>
parents: 16596
diff changeset
  1441
        # despite the docstring comment.  For now, error on 1.4.0, warn on
33b057778cd2 subrepo: warn user if Git is not version 1.6.0 or higher
Benjamin Pollack <benjamin@bitquabit.com>
parents: 16596
diff changeset
  1442
        # 1.5.0 but attempt to continue.
23521
f5de2a82b77e subrepo: move git version check into a separate method
Mathias De Maré <mathias.demare@gmail.com>
parents: 23411
diff changeset
  1443
        if version == -1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1444
            return b'unknown'
23522
49a58b33d1ce subrepo: extend git version check to 3 digits
Mathias De Maré <mathias.demare@gmail.com>
parents: 23521
diff changeset
  1445
        if version < (1, 5, 0):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1446
            return b'abort'
23522
49a58b33d1ce subrepo: extend git version check to 3 digits
Mathias De Maré <mathias.demare@gmail.com>
parents: 23521
diff changeset
  1447
        elif version < (1, 6, 0):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1448
            return b'warning'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1449
        return b'ok'
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1450
13095
49c7e875482d subrepo: use environment variable instead of git commit's --date
Eric Eisner <ede@mit.edu>
parents: 13094
diff changeset
  1451
    def _gitcommand(self, commands, env=None, stream=False):
49c7e875482d subrepo: use environment variable instead of git commit's --date
Eric Eisner <ede@mit.edu>
parents: 13094
diff changeset
  1452
        return self._gitdir(commands, env=env, stream=stream)[0]
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1453
13095
49c7e875482d subrepo: use environment variable instead of git commit's --date
Eric Eisner <ede@mit.edu>
parents: 13094
diff changeset
  1454
    def _gitdir(self, commands, env=None, stream=False):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1455
        return self._gitnodir(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1456
            commands, env=env, stream=stream, cwd=self._abspath
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1457
        )
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1458
13095
49c7e875482d subrepo: use environment variable instead of git commit's --date
Eric Eisner <ede@mit.edu>
parents: 13094
diff changeset
  1459
    def _gitnodir(self, commands, env=None, stream=False, cwd=None):
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1460
        """Calls the git command
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1461
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17191
diff changeset
  1462
        The methods tries to call the git command. versions prior to 1.6.0
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1463
        are not supported and very probably fail.
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1464
        """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1465
        self.ui.debug(b'%s: git %s\n' % (self._relpath, b' '.join(commands)))
28658
34d43cb85de8 subrepo: set GIT_ALLOW_PROTOCOL to limit git clone protocols (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28618
diff changeset
  1466
        if env is None:
30635
a150173da1c1 py3: replace os.environ with encoding.environ (part 2 of 5)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30615
diff changeset
  1467
            env = encoding.environ.copy()
28949
9d3e280864fb subrepo: disable localizations when calling Git (issue5176)
Matt Mackall <mpm@selenic.com>
parents: 28670
diff changeset
  1468
        # disable localization for Git output (issue5176)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1469
        env[b'LC_ALL'] = b'C'
28658
34d43cb85de8 subrepo: set GIT_ALLOW_PROTOCOL to limit git clone protocols (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28618
diff changeset
  1470
        # fix for Git CVE-2015-7545
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1471
        if b'GIT_ALLOW_PROTOCOL' not in env:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1472
            env[b'GIT_ALLOW_PROTOCOL'] = b'file:git:http:https:ssh'
13111
560b8001f765 subrepo: silence git output when ui.quiet is set
Eric Eisner <ede@mit.edu>
parents: 13110
diff changeset
  1473
        # unless ui.quiet is set, print git's stderr,
560b8001f765 subrepo: silence git output when ui.quiet is set
Eric Eisner <ede@mit.edu>
parents: 13110
diff changeset
  1474
        # which is mostly progress and useful info
560b8001f765 subrepo: silence git output when ui.quiet is set
Eric Eisner <ede@mit.edu>
parents: 13110
diff changeset
  1475
        errpipe = None
23572
40e62fbd7356 subrepo: rename the '_ui' member to 'ui'
Matt Harbison <matt_harbison@yahoo.com>
parents: 23571
diff changeset
  1476
        if self.ui.quiet:
43789
aea70ca7dd85 subrepo: use pycompat.open directly instead of importing open from pycompat
Kyle Lippincott <spectral@google.com>
parents: 43787
diff changeset
  1477
            errpipe = pycompat.open(os.devnull, b'w')
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1478
        if self.ui._colormode and len(commands) and commands[0] == b"diff":
31102
96d561c90ad0 color: move git-subrepo support into the subrepo module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31099
diff changeset
  1479
            # insert the argument in the front,
96d561c90ad0 color: move git-subrepo support into the subrepo module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31099
diff changeset
  1480
            # the end of git diff arguments is used for paths
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1481
            commands.insert(1, b'--color')
49392
b9fcf54030d7 subrepo: avoid opening console window for non-native subrepos on Windows
derekbrowncmu@gmail.com
parents: 49389
diff changeset
  1482
        extrakw = {}
b9fcf54030d7 subrepo: avoid opening console window for non-native subrepos on Windows
derekbrowncmu@gmail.com
parents: 49389
diff changeset
  1483
        if util.safehasattr(subprocess, 'CREATE_NO_WINDOW'):
b9fcf54030d7 subrepo: avoid opening console window for non-native subrepos on Windows
derekbrowncmu@gmail.com
parents: 49389
diff changeset
  1484
            # On Windows, prevent command prompts windows from popping up when
b9fcf54030d7 subrepo: avoid opening console window for non-native subrepos on Windows
derekbrowncmu@gmail.com
parents: 49389
diff changeset
  1485
            # running in pythonw.
b9fcf54030d7 subrepo: avoid opening console window for non-native subrepos on Windows
derekbrowncmu@gmail.com
parents: 49389
diff changeset
  1486
            extrakw['creationflags'] = getattr(subprocess, 'CREATE_NO_WINDOW')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1487
        p = subprocess.Popen(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1488
            pycompat.rapply(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1489
                procutil.tonativestr, [self._gitexecutable] + commands
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1490
            ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1491
            bufsize=-1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1492
            cwd=pycompat.rapply(procutil.tonativestr, cwd),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1493
            env=procutil.tonativeenv(env),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1494
            close_fds=procutil.closefds,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1495
            stdout=subprocess.PIPE,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1496
            stderr=errpipe,
50045
bbe3a65bbd96 subrepo: let black expand some call on multiple lines early
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49392
diff changeset
  1497
            **extrakw,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1498
        )
13027
7f2ecb64140d subrepo: archive git subrepos
Eric Eisner <ede@mit.edu>
parents: 13018
diff changeset
  1499
        if stream:
7f2ecb64140d subrepo: archive git subrepos
Eric Eisner <ede@mit.edu>
parents: 13018
diff changeset
  1500
            return p.stdout, None
7f2ecb64140d subrepo: archive git subrepos
Eric Eisner <ede@mit.edu>
parents: 13018
diff changeset
  1501
13085
b4814f1f415c subrepo: strip gitcommand output
Eric Eisner <ede@mit.edu>
parents: 13029
diff changeset
  1502
        retdata = p.stdout.read().strip()
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1503
        # wait for the child to exit to avoid race condition.
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1504
        p.wait()
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1505
13107
3bc237b0eaea subrepo: treat git error code 1 as success
Eric Eisner <ede@mit.edu>
parents: 13106
diff changeset
  1506
        if p.returncode != 0 and p.returncode != 1:
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1507
            # there are certain error codes that are ok
13110
cad35f06c031 subrepo: show git command with --debug
Eric Eisner <ede@mit.edu>
parents: 13109
diff changeset
  1508
            command = commands[0]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1509
            if command in (b'cat-file', b'symbolic-ref'):
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1510
                return retdata, p.returncode
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1511
            # for all others, abort
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1512
            raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1513
                _(b'git %s error %d in %s')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1514
                % (command, p.returncode, self._relpath)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1515
            )
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1516
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1517
        return retdata, p.returncode
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1518
13553
dea6efdd7ec4 subrepo: don't crash when git repo is missing
Eric Eisner <ede@mit.edu>
parents: 13531
diff changeset
  1519
    def _gitmissing(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1520
        return not self.wvfs.exists(b'.git')
13553
dea6efdd7ec4 subrepo: don't crash when git repo is missing
Eric Eisner <ede@mit.edu>
parents: 13531
diff changeset
  1521
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1522
    def _gitstate(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1523
        return self._gitcommand([b'rev-parse', b'HEAD'])
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1524
13152
70d80907e4b8 subrepo: defer determination of git's current branch
Eric Eisner <ede@mit.edu>
parents: 13151
diff changeset
  1525
    def _gitcurrentbranch(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1526
        current, err = self._gitdir([b'symbolic-ref', b'HEAD', b'--quiet'])
13152
70d80907e4b8 subrepo: defer determination of git's current branch
Eric Eisner <ede@mit.edu>
parents: 13151
diff changeset
  1527
        if err:
70d80907e4b8 subrepo: defer determination of git's current branch
Eric Eisner <ede@mit.edu>
parents: 13151
diff changeset
  1528
            current = None
70d80907e4b8 subrepo: defer determination of git's current branch
Eric Eisner <ede@mit.edu>
parents: 13151
diff changeset
  1529
        return current
70d80907e4b8 subrepo: defer determination of git's current branch
Eric Eisner <ede@mit.edu>
parents: 13151
diff changeset
  1530
13569
3ab3b892d223 subrepo: show the source that git pulls
Eric Eisner <ede@mit.edu>
parents: 13560
diff changeset
  1531
    def _gitremote(self, remote):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1532
        out = self._gitcommand([b'remote', b'show', b'-n', remote])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1533
        line = out.split(b'\n')[1]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1534
        i = line.index(b'URL: ') + len(b'URL: ')
13569
3ab3b892d223 subrepo: show the source that git pulls
Eric Eisner <ede@mit.edu>
parents: 13560
diff changeset
  1535
        return line[i:]
3ab3b892d223 subrepo: show the source that git pulls
Eric Eisner <ede@mit.edu>
parents: 13560
diff changeset
  1536
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1537
    def _githavelocally(self, revision):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1538
        out, code = self._gitdir([b'cat-file', b'-e', revision])
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1539
        return code == 0
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1540
13029
f930032aa6d5 subrepo: lazier git push logic
Eric Eisner <ede@mit.edu>
parents: 13027
diff changeset
  1541
    def _gitisancestor(self, r1, r2):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1542
        base = self._gitcommand([b'merge-base', r1, r2])
13029
f930032aa6d5 subrepo: lazier git push logic
Eric Eisner <ede@mit.edu>
parents: 13027
diff changeset
  1543
        return base == r1
f930032aa6d5 subrepo: lazier git push logic
Eric Eisner <ede@mit.edu>
parents: 13027
diff changeset
  1544
14440
96f1c1b14154 subrepo: bare git repos considered dirty
Paul Molodowitch <pm@stanfordalumni.org>
parents: 14417
diff changeset
  1545
    def _gitisbare(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1546
        return self._gitcommand([b'config', b'--bool', b'core.bare']) == b'true'
14440
96f1c1b14154 subrepo: bare git repos considered dirty
Paul Molodowitch <pm@stanfordalumni.org>
parents: 14417
diff changeset
  1547
15531
0810ccc51f0a subrepo: fix git status false positive (issue3109)
Eric Roshan Eisner <ede@alum.mit.edu>
parents: 15498
diff changeset
  1548
    def _gitupdatestat(self):
0810ccc51f0a subrepo: fix git status false positive (issue3109)
Eric Roshan Eisner <ede@alum.mit.edu>
parents: 15498
diff changeset
  1549
        """This must be run before git diff-index.
0810ccc51f0a subrepo: fix git status false positive (issue3109)
Eric Roshan Eisner <ede@alum.mit.edu>
parents: 15498
diff changeset
  1550
        diff-index only looks at changes to file stat;
0810ccc51f0a subrepo: fix git status false positive (issue3109)
Eric Roshan Eisner <ede@alum.mit.edu>
parents: 15498
diff changeset
  1551
        this command looks at file contents and updates the stat."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1552
        self._gitcommand([b'update-index', b'-q', b'--refresh'])
15531
0810ccc51f0a subrepo: fix git status false positive (issue3109)
Eric Roshan Eisner <ede@alum.mit.edu>
parents: 15498
diff changeset
  1553
12995
d90fc91c8377 subrepo: update and merge works with any git branch
Eric Eisner <ede@mit.edu>
parents: 12994
diff changeset
  1554
    def _gitbranchmap(self):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1555
        """returns 2 things:
13086
8db85e39d59c subrepo: return both mapping directions from gitbranchmap
Eric Eisner <ede@mit.edu>
parents: 13085
diff changeset
  1556
        a map from git branch to revision
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
  1557
        a map from revision to branches"""
13086
8db85e39d59c subrepo: return both mapping directions from gitbranchmap
Eric Eisner <ede@mit.edu>
parents: 13085
diff changeset
  1558
        branch2rev = {}
8db85e39d59c subrepo: return both mapping directions from gitbranchmap
Eric Eisner <ede@mit.edu>
parents: 13085
diff changeset
  1559
        rev2branch = {}
13178
c4d857f5405d subrepo: backout 519ac79d680b
Eric Eisner <ede@mit.edu>
parents: 13174
diff changeset
  1560
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1561
        out = self._gitcommand(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1562
            [b'for-each-ref', b'--format', b'%(objectname) %(refname)']
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1563
        )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1564
        for line in out.split(b'\n'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1565
            revision, ref = line.split(b' ')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1566
            if not ref.startswith(b'refs/heads/') and not ref.startswith(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1567
                b'refs/remotes/'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1568
            ):
12995
d90fc91c8377 subrepo: update and merge works with any git branch
Eric Eisner <ede@mit.edu>
parents: 12994
diff changeset
  1569
                continue
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1570
            if ref.startswith(b'refs/remotes/') and ref.endswith(b'/HEAD'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1571
                continue  # ignore remote/HEAD redirects
13150
8617b8b74fae subrepo: use low-level git-for-each-ref command in branchmap
Eric Eisner <ede@mit.edu>
parents: 13144
diff changeset
  1572
            branch2rev[ref] = revision
8617b8b74fae subrepo: use low-level git-for-each-ref command in branchmap
Eric Eisner <ede@mit.edu>
parents: 13144
diff changeset
  1573
            rev2branch.setdefault(revision, []).append(ref)
13178
c4d857f5405d subrepo: backout 519ac79d680b
Eric Eisner <ede@mit.edu>
parents: 13174
diff changeset
  1574
        return branch2rev, rev2branch
c4d857f5405d subrepo: backout 519ac79d680b
Eric Eisner <ede@mit.edu>
parents: 13174
diff changeset
  1575
c4d857f5405d subrepo: backout 519ac79d680b
Eric Eisner <ede@mit.edu>
parents: 13174
diff changeset
  1576
    def _gittracking(self, branches):
43787
be8552f25cab cleanup: fix docstring formatting
Matt Harbison <matt_harbison@yahoo.com>
parents: 43651
diff changeset
  1577
        """return map of remote branch to local tracking branch"""
13178
c4d857f5405d subrepo: backout 519ac79d680b
Eric Eisner <ede@mit.edu>
parents: 13174
diff changeset
  1578
        # assumes no more than one local tracking branch for each remote
c4d857f5405d subrepo: backout 519ac79d680b
Eric Eisner <ede@mit.edu>
parents: 13174
diff changeset
  1579
        tracking = {}
c4d857f5405d subrepo: backout 519ac79d680b
Eric Eisner <ede@mit.edu>
parents: 13174
diff changeset
  1580
        for b in branches:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1581
            if b.startswith(b'refs/remotes/'):
13178
c4d857f5405d subrepo: backout 519ac79d680b
Eric Eisner <ede@mit.edu>
parents: 13174
diff changeset
  1582
                continue
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1583
            bname = b.split(b'/', 2)[2]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1584
            remote = self._gitcommand([b'config', b'branch.%s.remote' % bname])
13178
c4d857f5405d subrepo: backout 519ac79d680b
Eric Eisner <ede@mit.edu>
parents: 13174
diff changeset
  1585
            if remote:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1586
                ref = self._gitcommand([b'config', b'branch.%s.merge' % bname])
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1587
                tracking[
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1588
                    b'refs/remotes/%s/%s' % (remote, ref.split(b'/', 2)[2])
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1589
                ] = b
13178
c4d857f5405d subrepo: backout 519ac79d680b
Eric Eisner <ede@mit.edu>
parents: 13174
diff changeset
  1590
        return tracking
13087
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1591
13460
64bb8e586a92 subrepo: expand relative sources for git subrepos
Eric Eisner <ede@mit.edu>
parents: 13432
diff changeset
  1592
    def _abssource(self, source):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1593
        if b'://' not in source:
13692
a7c9735307bd subrepo: recognize scp-style paths as git URLs
Eric Eisner <ede@mit.edu>
parents: 13559
diff changeset
  1594
            # recognize the scp syntax as an absolute source
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1595
            colon = source.find(b':')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1596
            if colon != -1 and b'/' not in source[:colon]:
13692
a7c9735307bd subrepo: recognize scp-style paths as git URLs
Eric Eisner <ede@mit.edu>
parents: 13559
diff changeset
  1597
                return source
13460
64bb8e586a92 subrepo: expand relative sources for git subrepos
Eric Eisner <ede@mit.edu>
parents: 13432
diff changeset
  1598
        self._subsource = source
64bb8e586a92 subrepo: expand relative sources for git subrepos
Eric Eisner <ede@mit.edu>
parents: 13432
diff changeset
  1599
        return _abssource(self)
64bb8e586a92 subrepo: expand relative sources for git subrepos
Eric Eisner <ede@mit.edu>
parents: 13432
diff changeset
  1600
12993
a91334380699 subrepo: cloning and updating of git subrepos
Eric Eisner <ede@mit.edu>
parents: 12992
diff changeset
  1601
    def _fetch(self, source, revision):
13553
dea6efdd7ec4 subrepo: don't crash when git repo is missing
Eric Eisner <ede@mit.edu>
parents: 13531
diff changeset
  1602
        if self._gitmissing():
33658
db83a1df03fe subrepo: add tests for git rogue ssh urls (SEC)
Sean Farley <sean@farley.io>
parents: 33657
diff changeset
  1603
            # SEC: check for safe ssh url
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
  1604
            urlutil.checksafessh(source)
33658
db83a1df03fe subrepo: add tests for git rogue ssh urls (SEC)
Sean Farley <sean@farley.io>
parents: 33657
diff changeset
  1605
13525
c12088259f64 subrepo: show the source that git clones
Eric Eisner <ede@mit.edu>
parents: 13466
diff changeset
  1606
            source = self._abssource(source)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1607
            self.ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1608
                _(b'cloning subrepo %s from %s\n') % (self._relpath, source)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1609
            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1610
            self._gitnodir([b'clone', source, self._abspath])
12993
a91334380699 subrepo: cloning and updating of git subrepos
Eric Eisner <ede@mit.edu>
parents: 12992
diff changeset
  1611
        if self._githavelocally(revision):
a91334380699 subrepo: cloning and updating of git subrepos
Eric Eisner <ede@mit.edu>
parents: 12992
diff changeset
  1612
            return
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1613
        self.ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1614
            _(b'pulling subrepo %s from %s\n')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1615
            % (self._relpath, self._gitremote(b'origin'))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1616
        )
13466
f2295f7cd468 subrepo: only attempt pulling from git's origin
Eric Eisner <ede@mit.edu>
parents: 13465
diff changeset
  1617
        # try only origin: the originally cloned repo
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1618
        self._gitcommand([b'fetch'])
12993
a91334380699 subrepo: cloning and updating of git subrepos
Eric Eisner <ede@mit.edu>
parents: 12992
diff changeset
  1619
        if not self._githavelocally(revision):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1620
            raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
  1621
                _(b'revision %s does not exist in subrepository "%s"\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1622
                % (revision, self._relpath)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1623
            )
12993
a91334380699 subrepo: cloning and updating of git subrepos
Eric Eisner <ede@mit.edu>
parents: 12992
diff changeset
  1624
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
  1625
    @annotatesubrepoerror
33364
bf2daeddd42b subrepo: consider the parent repo dirty when a file is missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 32584
diff changeset
  1626
    def dirty(self, ignoreupdate=False, missing=False):
13553
dea6efdd7ec4 subrepo: don't crash when git repo is missing
Eric Eisner <ede@mit.edu>
parents: 13531
diff changeset
  1627
        if self._gitmissing():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1628
            return self._state[1] != b''
14440
96f1c1b14154 subrepo: bare git repos considered dirty
Paul Molodowitch <pm@stanfordalumni.org>
parents: 14417
diff changeset
  1629
        if self._gitisbare():
96f1c1b14154 subrepo: bare git repos considered dirty
Paul Molodowitch <pm@stanfordalumni.org>
parents: 14417
diff changeset
  1630
            return True
13179
b512a7074349 subrepo: support ignoreupdate in gitsubrepo's dirty()
Eric Eisner <ede@mit.edu>
parents: 13178
diff changeset
  1631
        if not ignoreupdate and self._state[1] != self._gitstate():
13325
7ebdfa37842e subrepo: clarify comments in dirty() methods
Kevin Bullock <kbullock@ringworld.org>
parents: 13324
diff changeset
  1632
            # different version checked out
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1633
            return True
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1634
        # check for staged changes or modified files; ignore untracked files
15531
0810ccc51f0a subrepo: fix git status false positive (issue3109)
Eric Roshan Eisner <ede@alum.mit.edu>
parents: 15498
diff changeset
  1635
        self._gitupdatestat()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1636
        out, code = self._gitdir([b'diff-index', b'--quiet', b'HEAD'])
13153
dca5488f0e4f subrepo: use low-level git-diff-index for dirty()
Eric Eisner <ede@mit.edu>
parents: 13152
diff changeset
  1637
        return code == 1
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1638
16072
bcb973abcc0b subrepo: add basestate method
Matt Mackall <mpm@selenic.com>
parents: 16022
diff changeset
  1639
    def basestate(self):
bcb973abcc0b subrepo: add basestate method
Matt Mackall <mpm@selenic.com>
parents: 16022
diff changeset
  1640
        return self._gitstate()
bcb973abcc0b subrepo: add basestate method
Matt Mackall <mpm@selenic.com>
parents: 16022
diff changeset
  1641
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
  1642
    @annotatesubrepoerror
13323
d8d478f9ee0f merge with stable
Martin Geisler <mg@aragost.com>
parents: 13288 13322
diff changeset
  1643
    def get(self, state, overwrite=False):
12993
a91334380699 subrepo: cloning and updating of git subrepos
Eric Eisner <ede@mit.edu>
parents: 12992
diff changeset
  1644
        source, revision, kind = state
14469
2fdea636f254 subrepo: don't crash when git .hgsubstate is empty (issue2716)
Eric Eisner <ede@alum.mit.edu>
parents: 14205
diff changeset
  1645
        if not revision:
2fdea636f254 subrepo: don't crash when git .hgsubstate is empty (issue2716)
Eric Eisner <ede@alum.mit.edu>
parents: 14205
diff changeset
  1646
            self.remove()
2fdea636f254 subrepo: don't crash when git .hgsubstate is empty (issue2716)
Eric Eisner <ede@alum.mit.edu>
parents: 14205
diff changeset
  1647
            return
12993
a91334380699 subrepo: cloning and updating of git subrepos
Eric Eisner <ede@mit.edu>
parents: 12992
diff changeset
  1648
        self._fetch(source, revision)
12996
3a42651b0a62 subrepo: removing (and restoring) git subrepo state
Eric Eisner <ede@mit.edu>
parents: 12995
diff changeset
  1649
        # if the repo was set to be bare, unbare it
14440
96f1c1b14154 subrepo: bare git repos considered dirty
Paul Molodowitch <pm@stanfordalumni.org>
parents: 14417
diff changeset
  1650
        if self._gitisbare():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1651
            self._gitcommand([b'config', b'core.bare', b'false'])
12996
3a42651b0a62 subrepo: removing (and restoring) git subrepo state
Eric Eisner <ede@mit.edu>
parents: 12995
diff changeset
  1652
            if self._gitstate() == revision:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1653
                self._gitcommand([b'reset', b'--hard', b'HEAD'])
12996
3a42651b0a62 subrepo: removing (and restoring) git subrepo state
Eric Eisner <ede@mit.edu>
parents: 12995
diff changeset
  1654
                return
3a42651b0a62 subrepo: removing (and restoring) git subrepo state
Eric Eisner <ede@mit.edu>
parents: 12995
diff changeset
  1655
        elif self._gitstate() == revision:
13324
e5617047c926 subrepo: make update -C clean the working directory for git subrepos
Erik Zielke <ez@aragost.com>
parents: 13323
diff changeset
  1656
            if overwrite:
13927
518344d02761 subrepo: trailing whitespace cleanup
Augie Fackler <durin42@gmail.com>
parents: 13913
diff changeset
  1657
                # first reset the index to unmark new files for commit, because
13324
e5617047c926 subrepo: make update -C clean the working directory for git subrepos
Erik Zielke <ez@aragost.com>
parents: 13323
diff changeset
  1658
                # reset --hard will otherwise throw away files added for commit,
e5617047c926 subrepo: make update -C clean the working directory for git subrepos
Erik Zielke <ez@aragost.com>
parents: 13323
diff changeset
  1659
                # not just unmark them.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1660
                self._gitcommand([b'reset', b'HEAD'])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1661
                self._gitcommand([b'reset', b'--hard', b'HEAD'])
12995
d90fc91c8377 subrepo: update and merge works with any git branch
Eric Eisner <ede@mit.edu>
parents: 12994
diff changeset
  1662
            return
13178
c4d857f5405d subrepo: backout 519ac79d680b
Eric Eisner <ede@mit.edu>
parents: 13174
diff changeset
  1663
        branch2rev, rev2branch = self._gitbranchmap()
13087
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1664
13324
e5617047c926 subrepo: make update -C clean the working directory for git subrepos
Erik Zielke <ez@aragost.com>
parents: 13323
diff changeset
  1665
        def checkout(args):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1666
            cmd = [b'checkout']
13324
e5617047c926 subrepo: make update -C clean the working directory for git subrepos
Erik Zielke <ez@aragost.com>
parents: 13323
diff changeset
  1667
            if overwrite:
e5617047c926 subrepo: make update -C clean the working directory for git subrepos
Erik Zielke <ez@aragost.com>
parents: 13323
diff changeset
  1668
                # first reset the index to unmark new files for commit, because
e5617047c926 subrepo: make update -C clean the working directory for git subrepos
Erik Zielke <ez@aragost.com>
parents: 13323
diff changeset
  1669
                # the -f option will otherwise throw away files added for
e5617047c926 subrepo: make update -C clean the working directory for git subrepos
Erik Zielke <ez@aragost.com>
parents: 13323
diff changeset
  1670
                # commit, not just unmark them.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1671
                self._gitcommand([b'reset', b'HEAD'])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1672
                cmd.append(b'-f')
13324
e5617047c926 subrepo: make update -C clean the working directory for git subrepos
Erik Zielke <ez@aragost.com>
parents: 13323
diff changeset
  1673
            self._gitcommand(cmd + args)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1674
            _sanitize(self.ui, self.wvfs, b'.git')
13324
e5617047c926 subrepo: make update -C clean the working directory for git subrepos
Erik Zielke <ez@aragost.com>
parents: 13323
diff changeset
  1675
13087
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1676
        def rawcheckout():
12995
d90fc91c8377 subrepo: update and merge works with any git branch
Eric Eisner <ede@mit.edu>
parents: 12994
diff changeset
  1677
            # no branch to checkout, check it out with no branch
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1678
            self.ui.warn(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
  1679
                _(b'checking out detached HEAD in subrepository "%s"\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1680
                % self._relpath
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1681
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1682
            self.ui.warn(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
  1683
                _(b'check out a git branch if you intend to make changes\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1684
            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1685
            checkout([b'-q', revision])
13087
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1686
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1687
        if revision not in rev2branch:
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1688
            rawcheckout()
12995
d90fc91c8377 subrepo: update and merge works with any git branch
Eric Eisner <ede@mit.edu>
parents: 12994
diff changeset
  1689
            return
13086
8db85e39d59c subrepo: return both mapping directions from gitbranchmap
Eric Eisner <ede@mit.edu>
parents: 13085
diff changeset
  1690
        branches = rev2branch[revision]
12995
d90fc91c8377 subrepo: update and merge works with any git branch
Eric Eisner <ede@mit.edu>
parents: 12994
diff changeset
  1691
        firstlocalbranch = None
d90fc91c8377 subrepo: update and merge works with any git branch
Eric Eisner <ede@mit.edu>
parents: 12994
diff changeset
  1692
        for b in branches:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1693
            if b == b'refs/heads/master':
12995
d90fc91c8377 subrepo: update and merge works with any git branch
Eric Eisner <ede@mit.edu>
parents: 12994
diff changeset
  1694
                # master trumps all other branches
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1695
                checkout([b'refs/heads/master'])
12995
d90fc91c8377 subrepo: update and merge works with any git branch
Eric Eisner <ede@mit.edu>
parents: 12994
diff changeset
  1696
                return
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1697
            if not firstlocalbranch and not b.startswith(b'refs/remotes/'):
12995
d90fc91c8377 subrepo: update and merge works with any git branch
Eric Eisner <ede@mit.edu>
parents: 12994
diff changeset
  1698
                firstlocalbranch = b
d90fc91c8377 subrepo: update and merge works with any git branch
Eric Eisner <ede@mit.edu>
parents: 12994
diff changeset
  1699
        if firstlocalbranch:
13324
e5617047c926 subrepo: make update -C clean the working directory for git subrepos
Erik Zielke <ez@aragost.com>
parents: 13323
diff changeset
  1700
            checkout([firstlocalbranch])
13087
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1701
            return
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1702
13178
c4d857f5405d subrepo: backout 519ac79d680b
Eric Eisner <ede@mit.edu>
parents: 13174
diff changeset
  1703
        tracking = self._gittracking(branch2rev.keys())
13087
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1704
        # choose a remote branch already tracked if possible
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1705
        remote = branches[0]
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1706
        if remote not in tracking:
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1707
            for b in branches:
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1708
                if b in tracking:
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1709
                    remote = b
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1710
                    break
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1711
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1712
        if remote not in tracking:
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1713
            # create a new local tracking branch
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1714
            local = remote.split(b'/', 3)[3]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1715
            checkout([b'-b', local, remote])
13087
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1716
        elif self._gitisancestor(branch2rev[tracking[remote]], remote):
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1717
            # When updating to a tracked remote branch,
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1718
            # if the local tracking branch is downstream of it,
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1719
            # a normal `git pull` would have performed a "fast-forward merge"
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1720
            # which is equivalent to updating the local branch to the remote.
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1721
            # Since we are only looking at branching at update, we need to
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1722
            # detect this situation and perform this action lazily.
13152
70d80907e4b8 subrepo: defer determination of git's current branch
Eric Eisner <ede@mit.edu>
parents: 13151
diff changeset
  1723
            if tracking[remote] != self._gitcurrentbranch():
13324
e5617047c926 subrepo: make update -C clean the working directory for git subrepos
Erik Zielke <ez@aragost.com>
parents: 13323
diff changeset
  1724
                checkout([tracking[remote]])
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1725
            self._gitcommand([b'merge', b'--ff', remote])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1726
            _sanitize(self.ui, self.wvfs, b'.git')
13087
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1727
        else:
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1728
            # a real merge would be required, just checkout the revision
cca0779b4832 subrepo: lazily update git's local tracking branches
Eric Eisner <ede@mit.edu>
parents: 13086
diff changeset
  1729
            rawcheckout()
12993
a91334380699 subrepo: cloning and updating of git subrepos
Eric Eisner <ede@mit.edu>
parents: 12992
diff changeset
  1730
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
  1731
    @annotatesubrepoerror
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1732
    def commit(self, text, user, date):
13553
dea6efdd7ec4 subrepo: don't crash when git repo is missing
Eric Eisner <ede@mit.edu>
parents: 13531
diff changeset
  1733
        if self._gitmissing():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1734
            raise error.Abort(_(b"subrepo %s is missing") % self._relpath)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1735
        cmd = [b'commit', b'-a', b'-m', text]
30635
a150173da1c1 py3: replace os.environ with encoding.environ (part 2 of 5)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30615
diff changeset
  1736
        env = encoding.environ.copy()
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1737
        if user:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1738
            cmd += [b'--author', user]
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1739
        if date:
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1740
            # git's date parser silently ignores when seconds < 1e9
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1741
            # convert to ISO8601
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1742
            env[b'GIT_AUTHOR_DATE'] = dateutil.datestr(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1743
                date, b'%Y-%m-%dT%H:%M:%S %1%2'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1744
            )
13095
49c7e875482d subrepo: use environment variable instead of git commit's --date
Eric Eisner <ede@mit.edu>
parents: 13094
diff changeset
  1745
        self._gitcommand(cmd, env=env)
12992
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1746
        # make sure commit works otherwise HEAD might not exist under certain
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1747
        # circumstances
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1748
        return self._gitstate()
2b73a3279a9f subrepo: support for adding a git subrepo
Eric Eisner <ede@mit.edu>
parents: 12930
diff changeset
  1749
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
  1750
    @annotatesubrepoerror
12994
845c602b8635 subrepo: allow git subrepos to push and merge
Eric Eisner <ede@mit.edu>
parents: 12993
diff changeset
  1751
    def merge(self, state):
845c602b8635 subrepo: allow git subrepos to push and merge
Eric Eisner <ede@mit.edu>
parents: 12993
diff changeset
  1752
        source, revision, kind = state
845c602b8635 subrepo: allow git subrepos to push and merge
Eric Eisner <ede@mit.edu>
parents: 12993
diff changeset
  1753
        self._fetch(source, revision)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1754
        base = self._gitcommand([b'merge-base', revision, self._state[1]])
15531
0810ccc51f0a subrepo: fix git status false positive (issue3109)
Eric Roshan Eisner <ede@alum.mit.edu>
parents: 15498
diff changeset
  1755
        self._gitupdatestat()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1756
        out, code = self._gitdir([b'diff-index', b'--quiet', b'HEAD'])
13417
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
  1757
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
  1758
        def mergefunc():
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
  1759
            if base == revision:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1760
                self.get(state)  # fast forward merge
13417
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
  1761
            elif base != self._state[1]:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1762
                self._gitcommand([b'merge', b'--no-commit', revision])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1763
            _sanitize(self.ui, self.wvfs, b'.git')
13417
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
  1764
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
  1765
        if self.dirty():
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
  1766
            if self._gitstate() != revision:
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
  1767
                dirty = self._gitstate() == self._state[1] or code != 0
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1768
                if _updateprompt(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1769
                    self.ui, self, dirty, self._state[1][:7], revision[:7]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1770
                ):
13417
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
  1771
                    mergefunc()
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
  1772
        else:
0748e18be470 subrepos: prompt on conflicts on update with dirty subrepos
Erik Zielke <ez@aragost.com>
parents: 13413
diff changeset
  1773
            mergefunc()
12994
845c602b8635 subrepo: allow git subrepos to push and merge
Eric Eisner <ede@mit.edu>
parents: 12993
diff changeset
  1774
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
  1775
    @annotatesubrepoerror
15708
309e49491253 push: propagate --new-branch and --ssh options when pushing subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15614
diff changeset
  1776
    def push(self, opts):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1777
        force = opts.get(b'force')
15708
309e49491253 push: propagate --new-branch and --ssh options when pushing subrepos
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15614
diff changeset
  1778
14469
2fdea636f254 subrepo: don't crash when git .hgsubstate is empty (issue2716)
Eric Eisner <ede@alum.mit.edu>
parents: 14205
diff changeset
  1779
        if not self._state[1]:
2fdea636f254 subrepo: don't crash when git .hgsubstate is empty (issue2716)
Eric Eisner <ede@alum.mit.edu>
parents: 14205
diff changeset
  1780
            return True
13553
dea6efdd7ec4 subrepo: don't crash when git repo is missing
Eric Eisner <ede@mit.edu>
parents: 13531
diff changeset
  1781
        if self._gitmissing():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1782
            raise error.Abort(_(b"subrepo %s is missing") % self._relpath)
13029
f930032aa6d5 subrepo: lazier git push logic
Eric Eisner <ede@mit.edu>
parents: 13027
diff changeset
  1783
        # if a branch in origin contains the revision, nothing to do
13178
c4d857f5405d subrepo: backout 519ac79d680b
Eric Eisner <ede@mit.edu>
parents: 13174
diff changeset
  1784
        branch2rev, rev2branch = self._gitbranchmap()
13109
53341289eaf8 subrepo: speed up git push logic
Eric Eisner <ede@mit.edu>
parents: 13108
diff changeset
  1785
        if self._state[1] in rev2branch:
53341289eaf8 subrepo: speed up git push logic
Eric Eisner <ede@mit.edu>
parents: 13108
diff changeset
  1786
            for b in rev2branch[self._state[1]]:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1787
                if b.startswith(b'refs/remotes/origin/'):
13109
53341289eaf8 subrepo: speed up git push logic
Eric Eisner <ede@mit.edu>
parents: 13108
diff changeset
  1788
                    return True
48913
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
  1789
        for b, revision in branch2rev.items():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1790
            if b.startswith(b'refs/remotes/origin/'):
13086
8db85e39d59c subrepo: return both mapping directions from gitbranchmap
Eric Eisner <ede@mit.edu>
parents: 13085
diff changeset
  1791
                if self._gitisancestor(self._state[1], revision):
8db85e39d59c subrepo: return both mapping directions from gitbranchmap
Eric Eisner <ede@mit.edu>
parents: 13085
diff changeset
  1792
                    return True
13029
f930032aa6d5 subrepo: lazier git push logic
Eric Eisner <ede@mit.edu>
parents: 13027
diff changeset
  1793
        # otherwise, try to push the currently checked out branch
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1794
        cmd = [b'push']
12994
845c602b8635 subrepo: allow git subrepos to push and merge
Eric Eisner <ede@mit.edu>
parents: 12993
diff changeset
  1795
        if force:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1796
            cmd.append(b'--force')
13152
70d80907e4b8 subrepo: defer determination of git's current branch
Eric Eisner <ede@mit.edu>
parents: 13151
diff changeset
  1797
70d80907e4b8 subrepo: defer determination of git's current branch
Eric Eisner <ede@mit.edu>
parents: 13151
diff changeset
  1798
        current = self._gitcurrentbranch()
12995
d90fc91c8377 subrepo: update and merge works with any git branch
Eric Eisner <ede@mit.edu>
parents: 12994
diff changeset
  1799
        if current:
13029
f930032aa6d5 subrepo: lazier git push logic
Eric Eisner <ede@mit.edu>
parents: 13027
diff changeset
  1800
            # determine if the current branch is even useful
f930032aa6d5 subrepo: lazier git push logic
Eric Eisner <ede@mit.edu>
parents: 13027
diff changeset
  1801
            if not self._gitisancestor(self._state[1], current):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1802
                self.ui.warn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1803
                    _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1804
                        b'unrelated git branch checked out '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1805
                        b'in subrepository "%s"\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1806
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1807
                    % self._relpath
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1808
                )
13029
f930032aa6d5 subrepo: lazier git push logic
Eric Eisner <ede@mit.edu>
parents: 13027
diff changeset
  1809
                return False
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1810
            self.ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1811
                _(b'pushing branch %s of subrepository "%s"\n')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1812
                % (current.split(b'/', 2)[2], self._relpath)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1813
            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1814
            ret = self._gitdir(cmd + [b'origin', current])
20970
70312c95f2f7 subrepo: check return code for git push (issue4223)
Matt Mackall <mpm@selenic.com>
parents: 20870
diff changeset
  1815
            return ret[1] == 0
12995
d90fc91c8377 subrepo: update and merge works with any git branch
Eric Eisner <ede@mit.edu>
parents: 12994
diff changeset
  1816
        else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1817
            self.ui.warn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1818
                _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1819
                    b'no branch checked out in subrepository "%s"\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1820
                    b'cannot push revision %s\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1821
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1822
                % (self._relpath, self._state[1])
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1823
            )
12995
d90fc91c8377 subrepo: update and merge works with any git branch
Eric Eisner <ede@mit.edu>
parents: 12994
diff changeset
  1824
            return False
12994
845c602b8635 subrepo: allow git subrepos to push and merge
Eric Eisner <ede@mit.edu>
parents: 12993
diff changeset
  1825
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
  1826
    @annotatesubrepoerror
41650
f8b18583049f add: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41648
diff changeset
  1827
    def add(self, ui, match, prefix, uipathfn, explicitonly, **opts):
24174
bd9f64ec891d subrepos: support adding files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24173
diff changeset
  1828
        if self._gitmissing():
bd9f64ec891d subrepos: support adding files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24173
diff changeset
  1829
            return []
24182
00ef3edcf1d5 subrepo: don't exclude files in .hgignore when adding to git
Matt Harbison <matt_harbison@yahoo.com>
parents: 24174
diff changeset
  1830
40342
6f152067ba57 subrepo: access status members by name instead of by position
Martin von Zweigbergk <martinvonz@google.com>
parents: 39826
diff changeset
  1831
        s = self.status(None, unknown=True, clean=True)
24174
bd9f64ec891d subrepos: support adding files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24173
diff changeset
  1832
24183
932de135041f subrepo: warn when adding already tracked files in gitsubrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 24182
diff changeset
  1833
        tracked = set()
932de135041f subrepo: warn when adding already tracked files in gitsubrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 24182
diff changeset
  1834
        # dirstates 'amn' warn, 'r' is added again
40342
6f152067ba57 subrepo: access status members by name instead of by position
Martin von Zweigbergk <martinvonz@google.com>
parents: 39826
diff changeset
  1835
        for l in (s.modified, s.added, s.deleted, s.clean):
24183
932de135041f subrepo: warn when adding already tracked files in gitsubrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 24182
diff changeset
  1836
            tracked.update(l)
932de135041f subrepo: warn when adding already tracked files in gitsubrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 24182
diff changeset
  1837
24182
00ef3edcf1d5 subrepo: don't exclude files in .hgignore when adding to git
Matt Harbison <matt_harbison@yahoo.com>
parents: 24174
diff changeset
  1838
        # Unknown files not of interest will be rejected by the matcher
40342
6f152067ba57 subrepo: access status members by name instead of by position
Martin von Zweigbergk <martinvonz@google.com>
parents: 39826
diff changeset
  1839
        files = s.unknown
24182
00ef3edcf1d5 subrepo: don't exclude files in .hgignore when adding to git
Matt Harbison <matt_harbison@yahoo.com>
parents: 24174
diff changeset
  1840
        files.extend(match.files())
00ef3edcf1d5 subrepo: don't exclude files in .hgignore when adding to git
Matt Harbison <matt_harbison@yahoo.com>
parents: 24174
diff changeset
  1841
24183
932de135041f subrepo: warn when adding already tracked files in gitsubrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 24182
diff changeset
  1842
        rejected = []
932de135041f subrepo: warn when adding already tracked files in gitsubrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 24182
diff changeset
  1843
24182
00ef3edcf1d5 subrepo: don't exclude files in .hgignore when adding to git
Matt Harbison <matt_harbison@yahoo.com>
parents: 24174
diff changeset
  1844
        files = [f for f in sorted(set(files)) if match(f)]
24174
bd9f64ec891d subrepos: support adding files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24173
diff changeset
  1845
        for f in files:
bd9f64ec891d subrepos: support adding files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24173
diff changeset
  1846
            exact = match.exact(f)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1847
            command = [b"add"]
24174
bd9f64ec891d subrepos: support adding files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24173
diff changeset
  1848
            if exact:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1849
                command.append(b"-f")  # should be added, even if ignored
24174
bd9f64ec891d subrepos: support adding files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24173
diff changeset
  1850
            if ui.verbose or not exact:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1851
                ui.status(_(b'adding %s\n') % uipathfn(f))
24183
932de135041f subrepo: warn when adding already tracked files in gitsubrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 24182
diff changeset
  1852
932de135041f subrepo: warn when adding already tracked files in gitsubrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 24182
diff changeset
  1853
            if f in tracked:  # hg prints 'adding' even if already tracked
932de135041f subrepo: warn when adding already tracked files in gitsubrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 24182
diff changeset
  1854
                if exact:
932de135041f subrepo: warn when adding already tracked files in gitsubrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 24182
diff changeset
  1855
                    rejected.append(f)
932de135041f subrepo: warn when adding already tracked files in gitsubrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 24182
diff changeset
  1856
                continue
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1857
            if not opts.get('dry_run'):
24174
bd9f64ec891d subrepos: support adding files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24173
diff changeset
  1858
                self._gitcommand(command + [f])
24183
932de135041f subrepo: warn when adding already tracked files in gitsubrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 24182
diff changeset
  1859
932de135041f subrepo: warn when adding already tracked files in gitsubrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 24182
diff changeset
  1860
        for f in rejected:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1861
            ui.warn(_(b"%s already tracked!\n") % uipathfn(f))
24183
932de135041f subrepo: warn when adding already tracked files in gitsubrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 24182
diff changeset
  1862
932de135041f subrepo: warn when adding already tracked files in gitsubrepo
Matt Harbison <matt_harbison@yahoo.com>
parents: 24182
diff changeset
  1863
        return rejected
24174
bd9f64ec891d subrepos: support adding files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24173
diff changeset
  1864
bd9f64ec891d subrepos: support adding files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24173
diff changeset
  1865
    @annotatesubrepoerror
12996
3a42651b0a62 subrepo: removing (and restoring) git subrepo state
Eric Eisner <ede@mit.edu>
parents: 12995
diff changeset
  1866
    def remove(self):
13553
dea6efdd7ec4 subrepo: don't crash when git repo is missing
Eric Eisner <ede@mit.edu>
parents: 13531
diff changeset
  1867
        if self._gitmissing():
dea6efdd7ec4 subrepo: don't crash when git repo is missing
Eric Eisner <ede@mit.edu>
parents: 13531
diff changeset
  1868
            return
12996
3a42651b0a62 subrepo: removing (and restoring) git subrepo state
Eric Eisner <ede@mit.edu>
parents: 12995
diff changeset
  1869
        if self.dirty():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1870
            self.ui.warn(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
  1871
                _(b'not removing repo %s because it has changes.\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1872
                % self._relpath
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1873
            )
12996
3a42651b0a62 subrepo: removing (and restoring) git subrepo state
Eric Eisner <ede@mit.edu>
parents: 12995
diff changeset
  1874
            return
3a42651b0a62 subrepo: removing (and restoring) git subrepo state
Eric Eisner <ede@mit.edu>
parents: 12995
diff changeset
  1875
        # we can't fully delete the repository as it may contain
3a42651b0a62 subrepo: removing (and restoring) git subrepo state
Eric Eisner <ede@mit.edu>
parents: 12995
diff changeset
  1876
        # local-only history
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1877
        self.ui.note(_(b'removing subrepo %s\n') % self._relpath)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1878
        self._gitcommand([b'config', b'core.bare', b'true'])
24688
897a0715ee71 subrepo: use vfs.readdir instead of os.listdir to avoid expensive stat calls
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24675
diff changeset
  1879
        for f, kind in self.wvfs.readdir():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1880
            if f == b'.git':
12996
3a42651b0a62 subrepo: removing (and restoring) git subrepo state
Eric Eisner <ede@mit.edu>
parents: 12995
diff changeset
  1881
                continue
24688
897a0715ee71 subrepo: use vfs.readdir instead of os.listdir to avoid expensive stat calls
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24675
diff changeset
  1882
            if kind == stat.S_IFDIR:
24690
d1ddf1fe5d33 subrepo: use vfs.rmtree instead of shutil.rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24688
diff changeset
  1883
                self.wvfs.rmtree(f)
12996
3a42651b0a62 subrepo: removing (and restoring) git subrepo state
Eric Eisner <ede@mit.edu>
parents: 12995
diff changeset
  1884
            else:
24691
def1145cec2d subrepo: use vfs.unlink instead of os.remove
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24690
diff changeset
  1885
                self.wvfs.unlink(f)
12996
3a42651b0a62 subrepo: removing (and restoring) git subrepo state
Eric Eisner <ede@mit.edu>
parents: 12995
diff changeset
  1886
31099
b44ab288358e subrepo: run the repo decoders when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 30755
diff changeset
  1887
    def archive(self, archiver, prefix, match=None, decode=True):
18967
88d1b59f6906 archive: raise error.Abort if the file pattern matches no files
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18964
diff changeset
  1888
        total = 0
13027
7f2ecb64140d subrepo: archive git subrepos
Eric Eisner <ede@mit.edu>
parents: 13018
diff changeset
  1889
        source, revision = self._state
14469
2fdea636f254 subrepo: don't crash when git .hgsubstate is empty (issue2716)
Eric Eisner <ede@alum.mit.edu>
parents: 14205
diff changeset
  1890
        if not revision:
18967
88d1b59f6906 archive: raise error.Abort if the file pattern matches no files
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18964
diff changeset
  1891
            return total
13027
7f2ecb64140d subrepo: archive git subrepos
Eric Eisner <ede@mit.edu>
parents: 13018
diff changeset
  1892
        self._fetch(source, revision)
7f2ecb64140d subrepo: archive git subrepos
Eric Eisner <ede@mit.edu>
parents: 13018
diff changeset
  1893
7f2ecb64140d subrepo: archive git subrepos
Eric Eisner <ede@mit.edu>
parents: 13018
diff changeset
  1894
        # Parse git's native archive command.
7f2ecb64140d subrepo: archive git subrepos
Eric Eisner <ede@mit.edu>
parents: 13018
diff changeset
  1895
        # This should be much faster than manually traversing the trees
7f2ecb64140d subrepo: archive git subrepos
Eric Eisner <ede@mit.edu>
parents: 13018
diff changeset
  1896
        # and objects with many subprocess calls.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1897
        tarstream = self._gitcommand([b'archive', revision], stream=True)
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1898
        tar = tarfile.open(fileobj=tarstream, mode='r|')
13144
aae2d5cbde64 subrepo: add progress bar support to archive
Martin Geisler <mg@aragost.com>
parents: 13137
diff changeset
  1899
        relpath = subrelpath(self)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1900
        progress = self.ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1901
            _(b'archiving (%s)') % relpath, unit=_(b'files')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1902
        )
38379
3a7c33a2cc5e subrepo: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38370
diff changeset
  1903
        progress.update(0)
3a7c33a2cc5e subrepo: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38370
diff changeset
  1904
        for info in tar:
13180
a79e0688a5ee subrepo: fix git archive parsing of directories and symfiles
Eric Eisner <ede@mit.edu>
parents: 13179
diff changeset
  1905
            if info.isdir():
a79e0688a5ee subrepo: fix git archive parsing of directories and symfiles
Eric Eisner <ede@mit.edu>
parents: 13179
diff changeset
  1906
                continue
41483
46ab0c6b28dc subrepo: bytes/str cleanups on Git support
Augie Fackler <augie@google.com>
parents: 40753
diff changeset
  1907
            bname = pycompat.fsencode(info.name)
46ab0c6b28dc subrepo: bytes/str cleanups on Git support
Augie Fackler <augie@google.com>
parents: 40753
diff changeset
  1908
            if match and not match(bname):
17108
1894dac619de subrepo: propagate matcher to subrepos when archiving
Matt Harbison <matt_harbison@yahoo.com>
parents: 17036
diff changeset
  1909
                continue
13180
a79e0688a5ee subrepo: fix git archive parsing of directories and symfiles
Eric Eisner <ede@mit.edu>
parents: 13179
diff changeset
  1910
            if info.issym():
a79e0688a5ee subrepo: fix git archive parsing of directories and symfiles
Eric Eisner <ede@mit.edu>
parents: 13179
diff changeset
  1911
                data = info.linkname
a79e0688a5ee subrepo: fix git archive parsing of directories and symfiles
Eric Eisner <ede@mit.edu>
parents: 13179
diff changeset
  1912
            else:
46694
d6601547f22b subrepo: handle unexpected file types from git gracefully
Matt Harbison <matt_harbison@yahoo.com>
parents: 46113
diff changeset
  1913
                f = tar.extractfile(info)
d6601547f22b subrepo: handle unexpected file types from git gracefully
Matt Harbison <matt_harbison@yahoo.com>
parents: 46113
diff changeset
  1914
                if f:
d6601547f22b subrepo: handle unexpected file types from git gracefully
Matt Harbison <matt_harbison@yahoo.com>
parents: 46113
diff changeset
  1915
                    data = f.read()
d6601547f22b subrepo: handle unexpected file types from git gracefully
Matt Harbison <matt_harbison@yahoo.com>
parents: 46113
diff changeset
  1916
                else:
d6601547f22b subrepo: handle unexpected file types from git gracefully
Matt Harbison <matt_harbison@yahoo.com>
parents: 46113
diff changeset
  1917
                    self.ui.warn(_(b'skipping "%s" (unknown type)') % bname)
d6601547f22b subrepo: handle unexpected file types from git gracefully
Matt Harbison <matt_harbison@yahoo.com>
parents: 46113
diff changeset
  1918
                    continue
41631
3d9d5e612e67 subrepo: adjust subrepo prefix before calling subrepo.archive() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41630
diff changeset
  1919
            archiver.addfile(prefix + bname, info.mode, info.issym(), data)
18967
88d1b59f6906 archive: raise error.Abort if the file pattern matches no files
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18964
diff changeset
  1920
            total += 1
38379
3a7c33a2cc5e subrepo: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38370
diff changeset
  1921
            progress.increment()
3a7c33a2cc5e subrepo: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38370
diff changeset
  1922
        progress.complete()
18967
88d1b59f6906 archive: raise error.Abort if the file pattern matches no files
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18964
diff changeset
  1923
        return total
13144
aae2d5cbde64 subrepo: add progress bar support to archive
Martin Geisler <mg@aragost.com>
parents: 13137
diff changeset
  1924
18109
9e3910db4e78 subrepo: append subrepo path to subrepo error messages
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 18031
diff changeset
  1925
    @annotatesubrepoerror
32584
746e12a767b3 cat: add formatter support
Yuya Nishihara <yuya@tcha.org>
parents: 32540
diff changeset
  1926
    def cat(self, match, fm, fntemplate, prefix, **opts):
23991
07c1a7d1ef69 subrepo: add 'cat' support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23963
diff changeset
  1927
        rev = self._state[1]
07c1a7d1ef69 subrepo: add 'cat' support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23963
diff changeset
  1928
        if match.anypats():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1929
            return 1  # No support for include/exclude yet
23991
07c1a7d1ef69 subrepo: add 'cat' support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23963
diff changeset
  1930
07c1a7d1ef69 subrepo: add 'cat' support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23963
diff changeset
  1931
        if not match.files():
07c1a7d1ef69 subrepo: add 'cat' support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23963
diff changeset
  1932
            return 1
07c1a7d1ef69 subrepo: add 'cat' support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23963
diff changeset
  1933
32584
746e12a767b3 cat: add formatter support
Yuya Nishihara <yuya@tcha.org>
parents: 32540
diff changeset
  1934
        # TODO: add support for non-plain formatter (see cmdutil.cat())
23991
07c1a7d1ef69 subrepo: add 'cat' support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23963
diff changeset
  1935
        for f in match.files():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1936
            output = self._gitcommand([b"show", b"%s:%s" % (rev, f)])
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1937
            fp = cmdutil.makefileobj(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1938
                self._ctx, fntemplate, pathname=self.wvfs.reljoin(prefix, f)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1939
            )
23991
07c1a7d1ef69 subrepo: add 'cat' support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23963
diff changeset
  1940
            fp.write(output)
07c1a7d1ef69 subrepo: add 'cat' support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23963
diff changeset
  1941
            fp.close()
07c1a7d1ef69 subrepo: add 'cat' support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23963
diff changeset
  1942
        return 0
07c1a7d1ef69 subrepo: add 'cat' support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23963
diff changeset
  1943
07c1a7d1ef69 subrepo: add 'cat' support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23963
diff changeset
  1944
    @annotatesubrepoerror
13182
2537bd17421d subrepo: basic support for status of git subrepos
Eric Eisner <ede@mit.edu>
parents: 13181
diff changeset
  1945
    def status(self, rev2, **opts):
14469
2fdea636f254 subrepo: don't crash when git .hgsubstate is empty (issue2716)
Eric Eisner <ede@alum.mit.edu>
parents: 14205
diff changeset
  1946
        rev1 = self._state[1]
2fdea636f254 subrepo: don't crash when git .hgsubstate is empty (issue2716)
Eric Eisner <ede@alum.mit.edu>
parents: 14205
diff changeset
  1947
        if self._gitmissing() or not rev1:
13553
dea6efdd7ec4 subrepo: don't crash when git repo is missing
Eric Eisner <ede@mit.edu>
parents: 13531
diff changeset
  1948
            # if the repo is missing, return no results
24210
99362821b25b subrepo: always return scmutil.status() from gitsubrepo.status()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24209
diff changeset
  1949
            return scmutil.status([], [], [], [], [], [], [])
13182
2537bd17421d subrepo: basic support for status of git subrepos
Eric Eisner <ede@mit.edu>
parents: 13181
diff changeset
  1950
        modified, added, removed = [], [], []
15531
0810ccc51f0a subrepo: fix git status false positive (issue3109)
Eric Roshan Eisner <ede@alum.mit.edu>
parents: 15498
diff changeset
  1951
        self._gitupdatestat()
13182
2537bd17421d subrepo: basic support for status of git subrepos
Eric Eisner <ede@mit.edu>
parents: 13181
diff changeset
  1952
        if rev2:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1953
            command = [b'diff-tree', b'--no-renames', b'-r', rev1, rev2]
13182
2537bd17421d subrepo: basic support for status of git subrepos
Eric Eisner <ede@mit.edu>
parents: 13181
diff changeset
  1954
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1955
            command = [b'diff-index', b'--no-renames', rev1]
13182
2537bd17421d subrepo: basic support for status of git subrepos
Eric Eisner <ede@mit.edu>
parents: 13181
diff changeset
  1956
        out = self._gitcommand(command)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1957
        for line in out.split(b'\n'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1958
            tab = line.find(b'\t')
13182
2537bd17421d subrepo: basic support for status of git subrepos
Eric Eisner <ede@mit.edu>
parents: 13181
diff changeset
  1959
            if tab == -1:
2537bd17421d subrepo: basic support for status of git subrepos
Eric Eisner <ede@mit.edu>
parents: 13181
diff changeset
  1960
                continue
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1961
            status, f = line[tab - 1 : tab], line[tab + 1 :]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1962
            if status == b'M':
13182
2537bd17421d subrepo: basic support for status of git subrepos
Eric Eisner <ede@mit.edu>
parents: 13181
diff changeset
  1963
                modified.append(f)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1964
            elif status == b'A':
13182
2537bd17421d subrepo: basic support for status of git subrepos
Eric Eisner <ede@mit.edu>
parents: 13181
diff changeset
  1965
                added.append(f)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1966
            elif status == b'D':
13182
2537bd17421d subrepo: basic support for status of git subrepos
Eric Eisner <ede@mit.edu>
parents: 13181
diff changeset
  1967
                removed.append(f)
2537bd17421d subrepo: basic support for status of git subrepos
Eric Eisner <ede@mit.edu>
parents: 13181
diff changeset
  1968
22927
7d754b7acd55 subrepo: use separate instances of empty lists in status
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22914
diff changeset
  1969
        deleted, unknown, ignored, clean = [], [], [], []
23411
2d86f4e38c08 subrepo: add status support for ignored files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23373
diff changeset
  1970
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1971
        command = [b'status', b'--porcelain', b'-z']
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1972
        if opts.get('unknown'):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1973
            command += [b'--untracked-files=all']
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  1974
        if opts.get('ignored'):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1975
            command += [b'--ignored']
24256
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1976
        out = self._gitcommand(command)
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1977
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1978
        changedfiles = set()
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1979
        changedfiles.update(modified)
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1980
        changedfiles.update(added)
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1981
        changedfiles.update(removed)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1982
        for line in out.split(b'\0'):
24256
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1983
            if not line:
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1984
                continue
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1985
            st = line[0:2]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  1986
            # moves and copies show 2 files on one line
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1987
            if line.find(b'\0') >= 0:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1988
                filename1, filename2 = line[3:].split(b'\0')
24256
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1989
            else:
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1990
                filename1 = line[3:]
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1991
                filename2 = None
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1992
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1993
            changedfiles.add(filename1)
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1994
            if filename2:
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1995
                changedfiles.add(filename2)
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1996
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1997
            if st == b'??':
24256
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  1998
                unknown.append(filename1)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1999
            elif st == b'!!':
24256
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  2000
                ignored.append(filename1)
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  2001
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  2002
        if opts.get('clean'):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2003
            out = self._gitcommand([b'ls-files'])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2004
            for f in out.split(b'\n'):
24256
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  2005
                if not f in changedfiles:
e964edc3274e subrepo: add status support for ignored and clean files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24211
diff changeset
  2006
                    clean.append(f)
23411
2d86f4e38c08 subrepo: add status support for ignored files in git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23373
diff changeset
  2007
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2008
        return scmutil.status(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2009
            modified, added, removed, deleted, unknown, ignored, clean
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2010
        )
13182
2537bd17421d subrepo: basic support for status of git subrepos
Eric Eisner <ede@mit.edu>
parents: 13181
diff changeset
  2011
23523
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2012
    @annotatesubrepoerror
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2013
    def diff(self, ui, diffopts, node2, match, prefix, **opts):
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2014
        node1 = self._state[1]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2015
        cmd = [b'diff', b'--no-renames']
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  2016
        if opts['stat']:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2017
            cmd.append(b'--stat')
23523
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2018
        else:
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2019
            # for Git, this also implies '-p'
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2020
            cmd.append(b'-U%d' % diffopts.context)
23523
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2021
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2022
        if diffopts.noprefix:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2023
            cmd.extend(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2024
                [b'--src-prefix=%s/' % prefix, b'--dst-prefix=%s/' % prefix]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2025
            )
23523
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2026
        else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2027
            cmd.extend(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2028
                [b'--src-prefix=a/%s/' % prefix, b'--dst-prefix=b/%s/' % prefix]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2029
            )
23523
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2030
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2031
        if diffopts.ignorews:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2032
            cmd.append(b'--ignore-all-space')
23523
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2033
        if diffopts.ignorewsamount:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2034
            cmd.append(b'--ignore-space-change')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2035
        if (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2036
            self._gitversion(self._gitcommand([b'--version'])) >= (1, 8, 4)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2037
            and diffopts.ignoreblanklines
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2038
        ):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2039
            cmd.append(b'--ignore-blank-lines')
23523
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2040
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2041
        cmd.append(node1)
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2042
        if node2:
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2043
            cmd.append(node2)
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2044
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2045
        output = b""
23523
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2046
        if match.always():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2047
            output += self._gitcommand(cmd) + b'\n'
24778
a48b65ab428d subrepo: add include/exclude support for diffing git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24726
diff changeset
  2048
        else:
43651
aeed2f106213 subrepo: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43506
diff changeset
  2049
            st = self.status(node2)
aeed2f106213 subrepo: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43506
diff changeset
  2050
            files = [
aeed2f106213 subrepo: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43506
diff changeset
  2051
                f
aeed2f106213 subrepo: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43506
diff changeset
  2052
                for sublist in (st.modified, st.added, st.removed)
aeed2f106213 subrepo: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43506
diff changeset
  2053
                for f in sublist
aeed2f106213 subrepo: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43506
diff changeset
  2054
            ]
24778
a48b65ab428d subrepo: add include/exclude support for diffing git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24726
diff changeset
  2055
            for f in files:
a48b65ab428d subrepo: add include/exclude support for diffing git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 24726
diff changeset
  2056
                if match(f):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2057
                    output += self._gitcommand(cmd + [b'--', f]) + b'\n'
23938
de519517f597 subrepo: correctly add newline for git subrepo diffs
Mathias De Maré <mathias.demare@gmail.com>
parents: 23885
diff changeset
  2058
de519517f597 subrepo: correctly add newline for git subrepo diffs
Mathias De Maré <mathias.demare@gmail.com>
parents: 23885
diff changeset
  2059
        if output.strip():
de519517f597 subrepo: correctly add newline for git subrepo diffs
Mathias De Maré <mathias.demare@gmail.com>
parents: 23885
diff changeset
  2060
            ui.write(output)
23523
01a8dfc79cdc subrepo: add partial diff support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23522
diff changeset
  2061
23679
dd1e73c4be13 subrepo: add forgotten annotation for reverting git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23678
diff changeset
  2062
    @annotatesubrepoerror
23580
e20f36ad092e subrepo: fix git subrepo ui argument
Matt Mackall <mpm@selenic.com>
parents: 23579
diff changeset
  2063
    def revert(self, substate, *pats, **opts):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2064
        self.ui.status(_(b'reverting subrepo %s\n') % substate[0])
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  2065
        if not opts.get('no_backup'):
23678
194d2f185008 subrepo: add full revert support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23666
diff changeset
  2066
            status = self.status(None)
194d2f185008 subrepo: add full revert support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23666
diff changeset
  2067
            names = status.modified
194d2f185008 subrepo: add full revert support for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23666
diff changeset
  2068
            for name in names:
41603
ea5ebb8f72bd subrepo: migrate to scmutil.backuppath()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41593
diff changeset
  2069
                # backuppath() expects a path relative to the parent repo (the
ea5ebb8f72bd subrepo: migrate to scmutil.backuppath()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41593
diff changeset
  2070
                # repo that ui.origbackuppath is relative to)
ea5ebb8f72bd subrepo: migrate to scmutil.backuppath()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41593
diff changeset
  2071
                parentname = os.path.join(self._path, name)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2072
                bakname = scmutil.backuppath(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2073
                    self.ui, self._subparent, parentname
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2074
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2075
                self.ui.note(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2076
                    _(b'saving current version of %s as %s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2077
                    % (name, os.path.relpath(bakname))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2078
                )
41603
ea5ebb8f72bd subrepo: migrate to scmutil.backuppath()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41593
diff changeset
  2079
                util.rename(self.wvfs.join(name), bakname)
23550
7fa2189c1e87 subrepo: add revert support without backup for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23540
diff changeset
  2080
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
  2081
        if not opts.get('dry_run'):
24134
afed5d2e7985 revert: display full subrepo output with --dry-run
Matt Harbison <matt_harbison@yahoo.com>
parents: 24132
diff changeset
  2082
            self.get(substate, overwrite=True)
23550
7fa2189c1e87 subrepo: add revert support without backup for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23540
diff changeset
  2083
        return []
7fa2189c1e87 subrepo: add revert support without backup for git subrepos
Mathias De Maré <mathias.demare@gmail.com>
parents: 23540
diff changeset
  2084
21400
78a60daacea8 subrepo: add shortid() method to subrepo classes
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21041
diff changeset
  2085
    def shortid(self, revid):
78a60daacea8 subrepo: add shortid() method to subrepo classes
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21041
diff changeset
  2086
        return revid[:7]
78a60daacea8 subrepo: add shortid() method to subrepo classes
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21041
diff changeset
  2087
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2088
10177
5ca0d220ae21 subrepo: add table-based dispatch for subrepo types
Augie Fackler <durin42@gmail.com>
parents: 10175
diff changeset
  2089
types = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2090
    b'hg': hgsubrepo,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2091
    b'svn': svnsubrepo,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2092
    b'git': gitsubrepo,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42588
diff changeset
  2093
}