mercurial/hg.py
author Augie Fackler <augie@google.com>
Sun, 06 Oct 2019 09:45:02 -0400
changeset 43076 2372284d9457
parent 42973 ee1ef76d7339
child 43077 687b865b95ad
permissions -rw-r--r--
formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     1
# hg.py - repository classes for mercurial
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     2
#
4635
63b9d2deed48 Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4478
diff changeset
     3
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
2859
345bac2bc4ec update copyrights.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2847
diff changeset
     4
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     5
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8179
diff changeset
     6
# 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: 10099
diff changeset
     7
# GNU General Public License version 2 or any later version.
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     8
25939
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
     9
from __future__ import absolute_import
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    10
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    11
import errno
29341
0d83ad967bf8 cleanup: replace uses of util.(md5|sha1|sha256|sha512) with hashlib.\1
Augie Fackler <raf@durin42.com>
parents: 29021
diff changeset
    12
import hashlib
25939
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    13
import os
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    14
import shutil
36789
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36725
diff changeset
    15
import stat
25939
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    16
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    17
from .i18n import _
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
    18
from .node import nullid
22837
2be7d5ebd4d0 config: use the same hgrc for a cloned repo as for an uninitted repo
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 22818
diff changeset
    19
25939
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    20
from . import (
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    21
    bookmarks,
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    22
    bundlerepo,
35766
72fdd99eb526 caches: make 'cachetocopy' available in scmutil
Boris Feld <boris.feld@octobus.net>
parents: 35713
diff changeset
    23
    cacheutil,
25939
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    24
    cmdutil,
28501
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
    25
    destutil,
25939
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    26
    discovery,
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    27
    error,
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    28
    exchange,
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    29
    extensions,
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    30
    httppeer,
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    31
    localrepo,
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    32
    lock,
35928
c8e2d6ed1f9e cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35766
diff changeset
    33
    logcmdutil,
35356
a29fe459fc49 remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35340
diff changeset
    34
    logexchange,
25939
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    35
    merge as mergemod,
39566
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
    36
    narrowspec,
25939
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    37
    node,
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    38
    phases,
41498
7f366dd3df1f hg: raise Abort on invalid path
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41413
diff changeset
    39
    pycompat,
25939
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    40
    scmutil,
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    41
    sshpeer,
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    42
    statichttprepo,
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    43
    ui as uimod,
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    44
    unionrepo,
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    45
    url,
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    46
    util,
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    47
    verify as verifymod,
31228
4cc3797aa59c vfs: use 'vfs' module directly in 'mercurial.hg'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31178
diff changeset
    48
    vfs as vfsmod,
25939
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    49
)
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    50
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
    51
from .interfaces import repository as repositorymod
42823
268662aac075 interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42604
diff changeset
    52
25939
130c0b83e963 hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25761
diff changeset
    53
release = lock.release
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    54
29424
f21e0d91d386 share: move magic string to a constant
Martijn Pieters <mjpieters@fb.com>
parents: 29389
diff changeset
    55
# shared features
f21e0d91d386 share: move magic string to a constant
Martijn Pieters <mjpieters@fb.com>
parents: 29389
diff changeset
    56
sharedbookmarks = 'bookmarks'
f21e0d91d386 share: move magic string to a constant
Martijn Pieters <mjpieters@fb.com>
parents: 29389
diff changeset
    57
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
    58
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    59
def _local(path):
14825
de9eb6b1da4f util: rename the util.localpath that uses url to urllocalpath (issue2875)
Mads Kiilerich <mads@kiilerich.com>
parents: 14737
diff changeset
    60
    path = util.expandpath(util.urllocalpath(path))
41498
7f366dd3df1f hg: raise Abort on invalid path
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41413
diff changeset
    61
7f366dd3df1f hg: raise Abort on invalid path
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41413
diff changeset
    62
    try:
7f366dd3df1f hg: raise Abort on invalid path
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41413
diff changeset
    63
        isfile = os.path.isfile(path)
7f366dd3df1f hg: raise Abort on invalid path
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41413
diff changeset
    64
    # Python 2 raises TypeError, Python 3 ValueError.
7f366dd3df1f hg: raise Abort on invalid path
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41413
diff changeset
    65
    except (TypeError, ValueError) as e:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
    66
        raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
    67
            _('invalid path %s: %s') % (path, pycompat.bytestr(e))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
    68
        )
41498
7f366dd3df1f hg: raise Abort on invalid path
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41413
diff changeset
    69
7f366dd3df1f hg: raise Abort on invalid path
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41413
diff changeset
    70
    return isfile and bundlerepo or localrepo
2469
2e91ba371c4c hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2431
diff changeset
    71
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
    72
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
    73
def addbranchrevs(lrepo, other, branches, revs):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
    74
    peer = other.peer()  # a courtesy to callers using a localrepo for other
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    75
    hashbranch, branches = branches
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    76
    if not hashbranch and not branches:
22818
d7b114493315 repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22648
diff changeset
    77
        x = revs or None
37481
7c848ab13eff addbranchrevs: no longer accept revset as "revs" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 37480
diff changeset
    78
        if revs:
22818
d7b114493315 repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22648
diff changeset
    79
            y = revs[0]
d7b114493315 repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22648
diff changeset
    80
        else:
d7b114493315 repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22648
diff changeset
    81
            y = None
d7b114493315 repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22648
diff changeset
    82
        return x, y
24306
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24290
diff changeset
    83
    if revs:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24290
diff changeset
    84
        revs = list(revs)
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24290
diff changeset
    85
    else:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24290
diff changeset
    86
        revs = []
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24290
diff changeset
    87
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
    88
    if not peer.capable('branchmap'):
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    89
        if branches:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26354
diff changeset
    90
            raise error.Abort(_("remote branch lookup not supported"))
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    91
        revs.append(hashbranch)
10380
ee72d89c0d9f addbranchrevs: fallback for older servers
Sune Foldager <cryo@cyanite.org>
parents: 10379
diff changeset
    92
        return revs, revs[0]
37640
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
    93
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
    94
    with peer.commandexecutor() as e:
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
    95
        branchmap = e.callcommand('branchmap', {}).result()
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    96
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
    97
    def primary(branch):
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
    98
        if branch == '.':
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
    99
            if not lrepo:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26354
diff changeset
   100
                raise error.Abort(_("dirstate branch not accessible"))
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
   101
            branch = lrepo.dirstate.branch()
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
   102
        if branch in branchmap:
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
   103
            revs.extend(node.hex(r) for r in reversed(branchmap[branch]))
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
   104
            return True
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
   105
        else:
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
   106
            return False
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
   107
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
   108
    for branch in branches:
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
   109
        if not primary(branch):
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
   110
            raise error.RepoLookupError(_("unknown branch '%s'") % branch)
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
   111
    if hashbranch:
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
   112
        if not primary(hashbranch):
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
   113
            revs.append(hashbranch)
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
   114
    return revs, revs[0]
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
   115
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   116
13824
ec1695350361 hg: use url.url to parse branch names in parseurl()
Brodie Rao <brodie@bitheap.org>
parents: 13823
diff changeset
   117
def parseurl(path, branches=None):
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
   118
    '''parse url#branch, returning (url, (branch, branches))'''
5177
92236732d5a1 move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 4917
diff changeset
   119
14076
924c82157d46 url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents: 14073
diff changeset
   120
    u = util.url(path)
13897
375872fdadba hg: make parseurl() consistently return normalised path
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13826
diff changeset
   121
    branch = None
375872fdadba hg: make parseurl() consistently return normalised path
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13826
diff changeset
   122
    if u.fragment:
375872fdadba hg: make parseurl() consistently return normalised path
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13826
diff changeset
   123
        branch = u.fragment
375872fdadba hg: make parseurl() consistently return normalised path
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13826
diff changeset
   124
        u.fragment = None
31841
9ff5a124d111 py3: replace str() with bytes()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 31465
diff changeset
   125
    return bytes(u), (branch, branches or [])
5177
92236732d5a1 move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 4917
diff changeset
   126
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   127
14606
6e631c24c6d9 hg: move peerschemes back to schemes
Matt Mackall <mpm@selenic.com>
parents: 14605
diff changeset
   128
schemes = {
14568
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
   129
    'bundle': bundlerepo,
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents: 18553
diff changeset
   130
    'union': unionrepo,
14568
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
   131
    'file': _local,
17192
1ac628cd7113 peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 17191
diff changeset
   132
    'http': httppeer,
1ac628cd7113 peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 17191
diff changeset
   133
    'https': httppeer,
1ac628cd7113 peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 17191
diff changeset
   134
    'ssh': sshpeer,
14568
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
   135
    'static-http': statichttprepo,
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
   136
}
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
   137
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   138
14568
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
   139
def _peerlookup(path):
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
   140
    u = util.url(path)
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
   141
    scheme = u.scheme or 'file'
14606
6e631c24c6d9 hg: move peerschemes back to schemes
Matt Mackall <mpm@selenic.com>
parents: 14605
diff changeset
   142
    thing = schemes.get(scheme) or schemes['file']
14568
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
   143
    try:
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
   144
        return thing(path)
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
   145
    except TypeError:
25365
4cc3fb23881d hg: explicitly check that peer lookup object has instance() if call failed
Yuya Nishihara <yuya@tcha.org>
parents: 24945
diff changeset
   146
        # we can't test callable(thing) because 'thing' can be an unloaded
4cc3fb23881d hg: explicitly check that peer lookup object has instance() if call failed
Yuya Nishihara <yuya@tcha.org>
parents: 24945
diff changeset
   147
        # module that implements __call__
4cc3fb23881d hg: explicitly check that peer lookup object has instance() if call failed
Yuya Nishihara <yuya@tcha.org>
parents: 24945
diff changeset
   148
        if not util.safehasattr(thing, 'instance'):
4cc3fb23881d hg: explicitly check that peer lookup object has instance() if call failed
Yuya Nishihara <yuya@tcha.org>
parents: 24945
diff changeset
   149
            raise
14568
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
   150
        return thing
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
   151
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   152
14605
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
   153
def islocal(repo):
20355
7d269e7620c4 hg: note that islocal only accepts paths pointing to repos
Siddharth Agarwal <sid0@fb.com>
parents: 20354
diff changeset
   154
    '''return true if repo (or path pointing to repo) is local'''
33034
071732d9c210 py3: check for bytes instead of str in isinstance
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32988
diff changeset
   155
    if isinstance(repo, bytes):
14605
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
   156
        try:
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
   157
            return _peerlookup(repo).islocal(repo)
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
   158
        except AttributeError:
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
   159
            return False
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
   160
    return repo.local()
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
   161
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   162
42109
2a3c0106ded9 import: suppress accept: header
timeless <timeless@mozdev.org>
parents: 41498
diff changeset
   163
def openpath(ui, path, sendaccept=True):
17887
0e2846b2482c url: use open and not url.open for local files (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents: 17882
diff changeset
   164
    '''open path with open if local, url.open if remote'''
20354
b433b43364e4 hg.openpath: use url.islocal to tell if the path is local (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents: 20185
diff changeset
   165
    pathurl = util.url(path, parsequery=False, parsefragment=False)
b433b43364e4 hg.openpath: use url.islocal to tell if the path is local (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents: 20185
diff changeset
   166
    if pathurl.islocal():
b433b43364e4 hg.openpath: use url.islocal to tell if the path is local (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents: 20185
diff changeset
   167
        return util.posixfile(pathurl.localpath(), 'rb')
17887
0e2846b2482c url: use open and not url.open for local files (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents: 17882
diff changeset
   168
    else:
42109
2a3c0106ded9 import: suppress accept: header
timeless <timeless@mozdev.org>
parents: 41498
diff changeset
   169
        return url.open(ui, path, sendaccept=sendaccept)
17887
0e2846b2482c url: use open and not url.open for local files (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents: 17882
diff changeset
   170
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   171
20858
bc56ec9e64df hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20825
diff changeset
   172
# a list of (ui, repo) functions called for wire peer initialization
bc56ec9e64df hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20825
diff changeset
   173
wirepeersetupfuncs = []
bc56ec9e64df hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20825
diff changeset
   174
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   175
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   176
def _peerorrepo(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   177
    ui, path, create=False, presetupfuncs=None, intents=None, createopts=None
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   178
):
14605
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
   179
    """return a repository object for the specified path"""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   180
    obj = _peerlookup(path).instance(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   181
        ui, path, create, intents=intents, createopts=createopts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   182
    )
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   183
    ui = getattr(obj, "ui", ui)
32418
71e735bd8170 dispatch: make request accept additional reposetups
Jun Wu <quark@fb.com>
parents: 32221
diff changeset
   184
    for f in presetupfuncs or []:
71e735bd8170 dispatch: make request accept additional reposetups
Jun Wu <quark@fb.com>
parents: 32221
diff changeset
   185
        f(ui, obj)
41006
6f2510b581a0 extensions: use ui.log() interface to provide detailed loading information
Yuya Nishihara <yuya@tcha.org>
parents: 40682
diff changeset
   186
    ui.log(b'extension', b'- executing reposetup hooks\n')
39527
340170192874 extensions: trace the total time of running all reposetup callbacks
Boris Feld <boris.feld@octobus.net>
parents: 39524
diff changeset
   187
    with util.timedcm('all reposetup') as allreposetupstats:
340170192874 extensions: trace the total time of running all reposetup callbacks
Boris Feld <boris.feld@octobus.net>
parents: 39524
diff changeset
   188
        for name, module in extensions.extensions(ui):
41006
6f2510b581a0 extensions: use ui.log() interface to provide detailed loading information
Yuya Nishihara <yuya@tcha.org>
parents: 40682
diff changeset
   189
            ui.log(b'extension', b'  - running reposetup for %s\n', name)
39527
340170192874 extensions: trace the total time of running all reposetup callbacks
Boris Feld <boris.feld@octobus.net>
parents: 39524
diff changeset
   190
            hook = getattr(module, 'reposetup', None)
340170192874 extensions: trace the total time of running all reposetup callbacks
Boris Feld <boris.feld@octobus.net>
parents: 39524
diff changeset
   191
            if hook:
340170192874 extensions: trace the total time of running all reposetup callbacks
Boris Feld <boris.feld@octobus.net>
parents: 39524
diff changeset
   192
                with util.timedcm('reposetup %r', name) as stats:
340170192874 extensions: trace the total time of running all reposetup callbacks
Boris Feld <boris.feld@octobus.net>
parents: 39524
diff changeset
   193
                    hook(ui, obj)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   194
                ui.log(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   195
                    b'extension', b'  > reposetup for %s took %s\n', name, stats
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   196
                )
41006
6f2510b581a0 extensions: use ui.log() interface to provide detailed loading information
Yuya Nishihara <yuya@tcha.org>
parents: 40682
diff changeset
   197
    ui.log(b'extension', b'> all reposetup took %s\n', allreposetupstats)
20858
bc56ec9e64df hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20825
diff changeset
   198
    if not obj.local():
bc56ec9e64df hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20825
diff changeset
   199
        for f in wirepeersetupfuncs:
bc56ec9e64df hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20825
diff changeset
   200
            f(ui, obj)
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   201
    return obj
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   202
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   203
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   204
def repository(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   205
    ui, path='', create=False, presetupfuncs=None, intents=None, createopts=None
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   206
):
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   207
    """return a repository object for the specified path"""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   208
    peer = _peerorrepo(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   209
        ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   210
        path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   211
        create,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   212
        presetupfuncs=presetupfuncs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   213
        intents=intents,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   214
        createopts=createopts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   215
    )
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   216
    repo = peer.local()
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   217
    if not repo:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   218
        raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   219
            _("repository '%s' is not local") % (path or peer.url())
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   220
        )
18382
f3b21beb9802 filtering: rename filters to their antonyms
Kevin Bullock <kbullock@ringworld.org>
parents: 18303
diff changeset
   221
    return repo.filtered('visible')
14605
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
   222
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   223
39565
089fc0db0954 hg: allow extra arguments to be passed to repo creation (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39527
diff changeset
   224
def peer(uiorrepo, opts, path, create=False, intents=None, createopts=None):
14554
68db17047637 hg: add peer method
Matt Mackall <mpm@selenic.com>
parents: 14553
diff changeset
   225
    '''return a repository peer for the specified path'''
14839
510c893a726f peer: change arg name to convey it can be a repo as well
Idan Kamara <idankk86@gmail.com>
parents: 14825
diff changeset
   226
    rui = remoteui(uiorrepo, opts)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   227
    return _peerorrepo(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   228
        rui, path, create, intents=intents, createopts=createopts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   229
    ).peer()
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   230
14554
68db17047637 hg: add peer method
Matt Mackall <mpm@selenic.com>
parents: 14553
diff changeset
   231
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   232
def defaultdest(source):
20799
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
   233
    '''return default destination of clone if none is given
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
   234
34146
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33713
diff changeset
   235
    >>> defaultdest(b'foo')
20799
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
   236
    'foo'
34146
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33713
diff changeset
   237
    >>> defaultdest(b'/foo/bar')
20799
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
   238
    'bar'
34146
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33713
diff changeset
   239
    >>> defaultdest(b'/')
20799
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
   240
    ''
34146
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33713
diff changeset
   241
    >>> defaultdest(b'')
20800
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
   242
    ''
34146
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33713
diff changeset
   243
    >>> defaultdest(b'http://example.org/')
20800
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
   244
    ''
34146
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33713
diff changeset
   245
    >>> defaultdest(b'http://example.org/foo/')
20799
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
   246
    'foo'
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
   247
    '''
20800
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
   248
    path = util.url(source).path
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
   249
    if not path:
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
   250
        return ''
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
   251
    return os.path.basename(os.path.normpath(path))
2774
8cd3e19bf4a5 Add a doc string
Matt Mackall <mpm@selenic.com>
parents: 2768
diff changeset
   252
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   253
36197
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   254
def sharedreposource(repo):
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   255
    """Returns repository object for source repository of a shared repo.
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   256
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   257
    If repo is not a shared repository, returns None.
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   258
    """
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   259
    if repo.sharedpath == repo.path:
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   260
        return None
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   261
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   262
    if util.safehasattr(repo, 'srcrepo') and repo.srcrepo:
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   263
        return repo.srcrepo
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   264
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   265
    # the sharedpath always ends in the .hg; we want the path to the repo
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   266
    source = repo.vfs.split(repo.sharedpath)[0]
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   267
    srcurl, branches = parseurl(source)
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   268
    srcrepo = repository(repo.ui, srcurl)
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   269
    repo.srcrepo = srcrepo
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   270
    return srcrepo
0fe7e39dc683 hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36087
diff changeset
   271
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   272
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   273
def share(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   274
    ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   275
    source,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   276
    dest=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   277
    update=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   278
    bookmarks=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   279
    defaultpath=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   280
    relative=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   281
):
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   282
    '''create a shared repository'''
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   283
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   284
    if not islocal(source):
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26354
diff changeset
   285
        raise error.Abort(_('can only share local repositories'))
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   286
8807
8bf6eb68ddaf share: allow dest to default to the basename of source
Matt Mackall <mpm@selenic.com>
parents: 8800
diff changeset
   287
    if not dest:
10099
f5e46dfb38c7 share: use defaultdest to compute unspecified destination
Brendan Cully <brendan@kublai.com>
parents: 9984
diff changeset
   288
        dest = defaultdest(source)
9344
eb6af02307ec Merge with i18n-stable
Matt Mackall <mpm@selenic.com>
parents: 9245
diff changeset
   289
    else:
eb6af02307ec Merge with i18n-stable
Matt Mackall <mpm@selenic.com>
parents: 9245
diff changeset
   290
        dest = ui.expandpath(dest)
8807
8bf6eb68ddaf share: allow dest to default to the basename of source
Matt Mackall <mpm@selenic.com>
parents: 8800
diff changeset
   291
36087
488e313954ea py3: check for bytes instead of str in hg.share()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36041
diff changeset
   292
    if isinstance(source, bytes):
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   293
        origsource = ui.expandpath(source)
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
   294
        source, branches = parseurl(origsource)
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   295
        srcrepo = repository(ui, source)
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
   296
        rev, checkout = addbranchrevs(srcrepo, srcrepo, branches, None)
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   297
    else:
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   298
        srcrepo = source.local()
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   299
        checkout = None
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   300
39854
d3d4b4b5f725 localrepo: support writing shared file (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39853
diff changeset
   301
    shareditems = set()
d3d4b4b5f725 localrepo: support writing shared file (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39853
diff changeset
   302
    if bookmarks:
d3d4b4b5f725 localrepo: support writing shared file (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39853
diff changeset
   303
        shareditems.add(sharedbookmarks)
d3d4b4b5f725 localrepo: support writing shared file (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39853
diff changeset
   304
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   305
    r = repository(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   306
        ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   307
        dest,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   308
        create=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   309
        createopts={
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   310
            'sharedrepo': srcrepo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   311
            'sharedrelative': relative,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   312
            'shareditems': shareditems,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   313
        },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   314
    )
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   315
39854
d3d4b4b5f725 localrepo: support writing shared file (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39853
diff changeset
   316
    postshare(srcrepo, r, defaultpath=defaultpath)
40622
fb490d798be0 share: reload repo after adjusting it in postshare()
Martin von Zweigbergk <martinvonz@google.com>
parents: 40505
diff changeset
   317
    r = repository(ui, dest)
28632
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   318
    _postshareupdate(r, update, checkout=checkout)
34815
68e0bcb90357 subrepo: share instead of clone if the parent repo is shared (issue5675) (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents: 34805
diff changeset
   319
    return r
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   320
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   321
34878
9f7ecc5bbc28 share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   322
def unshare(ui, repo):
9f7ecc5bbc28 share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   323
    """convert a shared repository to a normal one
9f7ecc5bbc28 share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   324
9f7ecc5bbc28 share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   325
    Copy the store data to the repo and remove the sharedpath data.
39622
c5e6c1ba1c79 hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39571
diff changeset
   326
c5e6c1ba1c79 hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39571
diff changeset
   327
    Returns a new repository object representing the unshared repository.
c5e6c1ba1c79 hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39571
diff changeset
   328
c5e6c1ba1c79 hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39571
diff changeset
   329
    The passed repository object is not usable after this function is
c5e6c1ba1c79 hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39571
diff changeset
   330
    called.
34878
9f7ecc5bbc28 share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   331
    """
9f7ecc5bbc28 share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   332
41413
bc843e251134 unshare: use context manager for locks
Martin von Zweigbergk <martinvonz@google.com>
parents: 41387
diff changeset
   333
    with repo.lock():
34878
9f7ecc5bbc28 share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   334
        # we use locks here because if we race with commit, we
9f7ecc5bbc28 share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   335
        # can end up with extra data in the cloned revlogs that's
9f7ecc5bbc28 share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   336
        # not pointed to by changesets, thus causing verify to
9f7ecc5bbc28 share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   337
        # fail
9f7ecc5bbc28 share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   338
        destlock = copystore(ui, repo, repo.path)
41413
bc843e251134 unshare: use context manager for locks
Martin von Zweigbergk <martinvonz@google.com>
parents: 41387
diff changeset
   339
        with destlock or util.nullcontextmanager():
34878
9f7ecc5bbc28 share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   340
41413
bc843e251134 unshare: use context manager for locks
Martin von Zweigbergk <martinvonz@google.com>
parents: 41387
diff changeset
   341
            sharefile = repo.vfs.join('sharedpath')
bc843e251134 unshare: use context manager for locks
Martin von Zweigbergk <martinvonz@google.com>
parents: 41387
diff changeset
   342
            util.rename(sharefile, sharefile + '.old')
bc843e251134 unshare: use context manager for locks
Martin von Zweigbergk <martinvonz@google.com>
parents: 41387
diff changeset
   343
bc843e251134 unshare: use context manager for locks
Martin von Zweigbergk <martinvonz@google.com>
parents: 41387
diff changeset
   344
            repo.requirements.discard('shared')
bc843e251134 unshare: use context manager for locks
Martin von Zweigbergk <martinvonz@google.com>
parents: 41387
diff changeset
   345
            repo.requirements.discard('relshared')
bc843e251134 unshare: use context manager for locks
Martin von Zweigbergk <martinvonz@google.com>
parents: 41387
diff changeset
   346
            repo._writerequirements()
34878
9f7ecc5bbc28 share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   347
39622
c5e6c1ba1c79 hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39571
diff changeset
   348
    # Removing share changes some fundamental properties of the repo instance.
c5e6c1ba1c79 hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39571
diff changeset
   349
    # So we instantiate a new repo object and operate on it rather than
c5e6c1ba1c79 hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39571
diff changeset
   350
    # try to keep the existing repo usable.
c5e6c1ba1c79 hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39571
diff changeset
   351
    newrepo = repository(repo.baseui, repo.root, create=False)
34878
9f7ecc5bbc28 share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents: 34815
diff changeset
   352
34879
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34878
diff changeset
   353
    # TODO: figure out how to access subrepos that exist, but were previously
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34878
diff changeset
   354
    #       removed from .hgsub
39622
c5e6c1ba1c79 hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39571
diff changeset
   355
    c = newrepo['.']
34879
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34878
diff changeset
   356
    subs = c.substate
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34878
diff changeset
   357
    for s in sorted(subs):
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34878
diff changeset
   358
        c.sub(s).unshare()
7d51a7792f52 subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 34878
diff changeset
   359
39622
c5e6c1ba1c79 hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39571
diff changeset
   360
    localrepo.poisonrepository(repo)
c5e6c1ba1c79 hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39571
diff changeset
   361
c5e6c1ba1c79 hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39571
diff changeset
   362
    return newrepo
c5e6c1ba1c79 hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39571
diff changeset
   363
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   364
39854
d3d4b4b5f725 localrepo: support writing shared file (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39853
diff changeset
   365
def postshare(sourcerepo, destrepo, defaultpath=None):
27354
bced7180db19 hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27344
diff changeset
   366
    """Called after a new shared repo is created.
bced7180db19 hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27344
diff changeset
   367
bced7180db19 hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27344
diff changeset
   368
    The new repo only has a requirements file and pointer to the source.
bced7180db19 hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27344
diff changeset
   369
    This function configures additional shared data.
bced7180db19 hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27344
diff changeset
   370
bced7180db19 hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27344
diff changeset
   371
    Extensions can wrap this function and write additional entries to
bced7180db19 hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27344
diff changeset
   372
    destrepo/.hg/shared to indicate additional pieces of data to be shared.
bced7180db19 hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27344
diff changeset
   373
    """
30041
1779dde4c9ef hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29906
diff changeset
   374
    default = defaultpath or sourcerepo.ui.config('paths', 'default')
27354
bced7180db19 hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27344
diff changeset
   375
    if default:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   376
        template = '[paths]\n' 'default = %s\n'
35622
e925f33ac088 share: convert EOL of hgrc before writing to bytes IO
Yuya Nishihara <yuya@tcha.org>
parents: 35620
diff changeset
   377
        destrepo.vfs.write('hgrc', util.tonativeeol(template % default))
41046
ce0bc2952e2a narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents: 41006
diff changeset
   378
    if repositorymod.NARROW_REQUIREMENT in sourcerepo.requirements:
ce0bc2952e2a narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents: 41006
diff changeset
   379
        with destrepo.wlock():
41229
50ca531f1f24 narrow: copy store narrowspec to working copy immediately
Martin von Zweigbergk <martinvonz@google.com>
parents: 41046
diff changeset
   380
            narrowspec.copytoworkingcopy(destrepo)
27354
bced7180db19 hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27344
diff changeset
   381
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   382
28632
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   383
def _postshareupdate(repo, update, checkout=None):
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   384
    """Maybe perform a working directory update after a shared repo is created.
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   385
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   386
    ``update`` can be a boolean or a revision to update to.
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   387
    """
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   388
    if not update:
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   389
        return
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   390
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   391
    repo.ui.status(_("updating working directory\n"))
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   392
    if update is not True:
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   393
        checkout = update
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   394
    for test in (checkout, 'default', 'tip'):
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   395
        if test is None:
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   396
            continue
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   397
        try:
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   398
            uprev = repo.lookup(test)
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   399
            break
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   400
        except error.RepoLookupError:
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   401
            continue
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   402
    _update(repo, uprev)
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   403
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   404
15078
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
   405
def copystore(ui, srcrepo, destpath):
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
   406
    '''copy files from store of srcrepo in destpath
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
   407
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
   408
    returns destlock
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
   409
    '''
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
   410
    destlock = None
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
   411
    try:
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
   412
        hardlink = None
38386
63e6f5ae84bc copystore: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 37717
diff changeset
   413
        topic = _('linking') if hardlink else _('copying')
40438
e5f54c4ec075 copystore: provide unit to ui.makeprogress()
Anton Shestakov <av6@dwimlabs.net>
parents: 40390
diff changeset
   414
        with ui.makeprogress(topic, unit=_('files')) as progress:
39415
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   415
            num = 0
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   416
            srcpublishing = srcrepo.publishing()
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   417
            srcvfs = vfsmod.vfs(srcrepo.sharedpath)
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   418
            dstvfs = vfsmod.vfs(destpath)
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   419
            for f in srcrepo.store.copylist():
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   420
                if srcpublishing and f.endswith('phaseroots'):
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   421
                    continue
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   422
                dstbase = os.path.dirname(f)
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   423
                if dstbase and not dstvfs.exists(dstbase):
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   424
                    dstvfs.mkdir(dstbase)
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   425
                if srcvfs.exists(f):
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   426
                    if f.endswith('data'):
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   427
                        # 'dstbase' may be empty (e.g. revlog format 0)
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   428
                        lockfile = os.path.join(dstbase, "lock")
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   429
                        # lock to avoid premature writing to the target
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   430
                        destlock = lock.lock(dstvfs, lockfile)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   431
                    hardlink, n = util.copyfiles(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   432
                        srcvfs.join(f), dstvfs.join(f), hardlink, progress
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   433
                    )
39415
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   434
                    num += n
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   435
            if hardlink:
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   436
                ui.debug("linked %d files\n" % num)
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   437
            else:
ddfd80029306 hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents: 39219
diff changeset
   438
                ui.debug("copied %d files\n" % num)
15078
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
   439
        return destlock
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   440
    except:  # re-raises
15078
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
   441
        release(destlock)
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
   442
        raise
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
   443
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   444
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   445
def clonewithshare(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   446
    ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   447
    peeropts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   448
    sharepath,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   449
    source,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   450
    srcpeer,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   451
    dest,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   452
    pull=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   453
    rev=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   454
    update=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   455
    stream=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   456
):
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   457
    """Perform a clone using a shared repo.
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   458
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   459
    The store for the repository will be located at <sharepath>/.hg. The
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   460
    specified revisions will be cloned or pulled from "source". A shared repo
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   461
    will be created at "dest" and a working copy will be created if "update" is
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   462
    True.
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   463
    """
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   464
    revs = None
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   465
    if rev:
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   466
        if not srcpeer.capable('lookup'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   467
            raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   468
                _(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   469
                    "src repository does not support "
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   470
                    "revision lookup and so doesn't "
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   471
                    "support clone by revision"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   472
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   473
            )
37640
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   474
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   475
        # TODO this is batchable.
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   476
        remoterevs = []
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   477
        for r in rev:
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   478
            with srcpeer.commandexecutor() as e:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   479
                remoterevs.append(e.callcommand('lookup', {'key': r,}).result())
37640
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   480
        revs = remoterevs
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   481
28289
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   482
    # Obtain a lock before checking for or cloning the pooled repo otherwise
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   483
    # 2 clients may race creating or populating it.
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   484
    pooldir = os.path.dirname(sharepath)
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   485
    # lock class requires the directory to exist.
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   486
    try:
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   487
        util.makedir(pooldir, False)
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   488
    except OSError as e:
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   489
        if e.errno != errno.EEXIST:
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   490
            raise
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   491
31228
4cc3797aa59c vfs: use 'vfs' module directly in 'mercurial.hg'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31178
diff changeset
   492
    poolvfs = vfsmod.vfs(pooldir)
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   493
    basename = os.path.basename(sharepath)
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   494
28289
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   495
    with lock.lock(poolvfs, '%s.lock' % basename):
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   496
        if os.path.exists(sharepath):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   497
            ui.status(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   498
                _('(sharing from existing pooled repository %s)\n') % basename
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   499
            )
28289
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   500
        else:
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   501
            ui.status(_('(sharing from new pooled repository %s)\n') % basename)
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   502
            # Always use pull mode because hardlinks in share mode don't work
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   503
            # well. Never update because working copies aren't necessary in
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27637
diff changeset
   504
            # share mode.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   505
            clone(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   506
                ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   507
                peeropts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   508
                source,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   509
                dest=sharepath,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   510
                pull=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   511
                revs=rev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   512
                update=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   513
                stream=stream,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   514
            )
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   515
30041
1779dde4c9ef hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29906
diff changeset
   516
    # Resolve the value to put in [paths] section for the source.
1779dde4c9ef hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29906
diff changeset
   517
    if islocal(source):
1779dde4c9ef hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29906
diff changeset
   518
        defaultpath = os.path.abspath(util.urllocalpath(source))
1779dde4c9ef hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29906
diff changeset
   519
    else:
1779dde4c9ef hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29906
diff changeset
   520
        defaultpath = source
1779dde4c9ef hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29906
diff changeset
   521
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   522
    sharerepo = repository(ui, path=sharepath)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   523
    destrepo = share(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   524
        ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   525
        sharerepo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   526
        dest=dest,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   527
        update=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   528
        bookmarks=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   529
        defaultpath=defaultpath,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   530
    )
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   531
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   532
    # We need to perform a pull against the dest repo to fetch bookmarks
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   533
    # and other non-store data that isn't shared by default. In the case of
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   534
    # non-existing shared repo, this means we pull from the remote twice. This
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   535
    # is a bit weird. But at the time it was implemented, there wasn't an easy
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   536
    # way to pull just non-changegroup data.
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   537
    exchange.pull(destrepo, srcpeer, heads=revs)
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   538
28632
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   539
    _postshareupdate(destrepo, update)
a2c2dd399f3b hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28289
diff changeset
   540
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   541
    return srcpeer, peer(ui, peeropts, dest)
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   542
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   543
32525
963de566de2f local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32418
diff changeset
   544
# Recomputing branch cache might be slow on big repos,
963de566de2f local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32418
diff changeset
   545
# so just copy it
963de566de2f local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32418
diff changeset
   546
def _copycache(srcrepo, dstcachedir, fname):
963de566de2f local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32418
diff changeset
   547
    """copy a cache from srcrepo to destcachedir (if it exists)"""
963de566de2f local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32418
diff changeset
   548
    srcbranchcache = srcrepo.vfs.join('cache/%s' % fname)
963de566de2f local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32418
diff changeset
   549
    dstbranchcache = os.path.join(dstcachedir, fname)
963de566de2f local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32418
diff changeset
   550
    if os.path.exists(srcbranchcache):
963de566de2f local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32418
diff changeset
   551
        if not os.path.exists(dstcachedir):
963de566de2f local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32418
diff changeset
   552
            os.mkdir(dstcachedir)
963de566de2f local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32418
diff changeset
   553
        util.copyfile(srcbranchcache, dstbranchcache)
963de566de2f local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32418
diff changeset
   554
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   555
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   556
def clone(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   557
    ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   558
    peeropts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   559
    source,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   560
    dest=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   561
    pull=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   562
    revs=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   563
    update=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   564
    stream=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   565
    branch=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   566
    shareopts=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   567
    storeincludepats=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   568
    storeexcludepats=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   569
    depth=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   570
):
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   571
    """Make a copy of an existing repository.
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   572
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   573
    Create a copy of an existing repository in a new directory.  The
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   574
    source and destination are URLs, as passed to the repository
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   575
    function.  Returns a pair of repository peers, the source and
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   576
    newly created destination.
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   577
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   578
    The location of the source is added to the new repository's
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   579
    .hg/hgrc file, as the default to be used for future pulls and
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   580
    pushes.
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   581
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   582
    If an exception is raised, the partly cloned/updated destination
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   583
    repository will be deleted.
2600
c4325f0a9b91 clean up trailing white space.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2597
diff changeset
   584
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   585
    Arguments:
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   586
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   587
    source: repository object or URL
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   588
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   589
    dest: URL of destination repository to create (defaults to base
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   590
    name of source repository)
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   591
23545
68c434799559 hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents: 23139
diff changeset
   592
    pull: always pull from source repository, even in local case or if the
68c434799559 hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents: 23139
diff changeset
   593
    server prefers streaming
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   594
2621
5a5852a417b1 clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2613
diff changeset
   595
    stream: stream raw data uncompressed from repository (fast over
5a5852a417b1 clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2613
diff changeset
   596
    LAN, slow over WAN)
2613
479e26afa10f clone: do not make streaming default. add --stream option instead.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
   597
37264
54435fd09f1d clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents: 37263
diff changeset
   598
    revs: revision to clone up to (implies pull=True)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   599
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   600
    update: update working directory after clone completes, if
6526
cfeeac24fc1e repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents: 6525
diff changeset
   601
    destination is local repository (True means update to default rev,
cfeeac24fc1e repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents: 6525
diff changeset
   602
    anything else is treated as a revision)
10379
a78bfaf988e1 add -b/--branch option to clone, bundle, incoming, outgoing, pull, push
Sune Foldager <cryo@cyanite.org>
parents: 10365
diff changeset
   603
a78bfaf988e1 add -b/--branch option to clone, bundle, incoming, outgoing, pull, push
Sune Foldager <cryo@cyanite.org>
parents: 10365
diff changeset
   604
    branch: branches to clone
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   605
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   606
    shareopts: dict of options to control auto sharing behavior. The "pool" key
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   607
    activates auto sharing mode and defines the directory for stores. The
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   608
    "mode" key determines how to construct the directory name of the shared
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   609
    repository. "identity" means the name is derived from the node of the first
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   610
    changeset in the repository. "remote" means the name is derived from the
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   611
    remote's path/URL. Defaults to "identity."
39566
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   612
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   613
    storeincludepats and storeexcludepats: sets of file patterns to include and
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   614
    exclude in the repository copy, respectively. If not defined, all files
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   615
    will be included (a "full" clone). Otherwise a "narrow" clone containing
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   616
    only the requested files will be performed. If ``storeincludepats`` is not
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   617
    defined but ``storeexcludepats`` is, ``storeincludepats`` is assumed to be
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   618
    ``path:.``. If both are empty sets, no files will be cloned.
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   619
    """
4478
b2b55acbacdd Add support for url#id syntax
Matt Mackall <mpm@selenic.com>
parents: 4477
diff changeset
   620
32988
11c0bb4ccc76 py3: replace str with bytes in isinstance()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32528
diff changeset
   621
    if isinstance(source, bytes):
6089
28054773438c clone: make things work when source is a repo object
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 6088
diff changeset
   622
        origsource = ui.expandpath(source)
37263
3809eafedf2c parseurl: consistently call second output "branches"
Martin von Zweigbergk <martinvonz@google.com>
parents: 37128
diff changeset
   623
        source, branches = parseurl(origsource, branch)
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   624
        srcpeer = peer(ui, peeropts, source)
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   625
    else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   626
        srcpeer = source.peer()  # in case we were called with a localrepo
37263
3809eafedf2c parseurl: consistently call second output "branches"
Martin von Zweigbergk <martinvonz@google.com>
parents: 37128
diff changeset
   627
        branches = (None, branch or [])
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   628
        origsource = source = srcpeer.url()
37264
54435fd09f1d clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents: 37263
diff changeset
   629
    revs, checkout = addbranchrevs(srcpeer, srcpeer, branches, revs)
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   630
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   631
    if dest is None:
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   632
        dest = defaultdest(source)
20800
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
   633
        if dest:
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
   634
            ui.status(_("destination directory: %s\n") % dest)
9344
eb6af02307ec Merge with i18n-stable
Matt Mackall <mpm@selenic.com>
parents: 9245
diff changeset
   635
    else:
eb6af02307ec Merge with i18n-stable
Matt Mackall <mpm@selenic.com>
parents: 9245
diff changeset
   636
        dest = ui.expandpath(dest)
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   637
14825
de9eb6b1da4f util: rename the util.localpath that uses url to urllocalpath (issue2875)
Mads Kiilerich <mads@kiilerich.com>
parents: 14737
diff changeset
   638
    dest = util.urllocalpath(dest)
de9eb6b1da4f util: rename the util.localpath that uses url to urllocalpath (issue2875)
Mads Kiilerich <mads@kiilerich.com>
parents: 14737
diff changeset
   639
    source = util.urllocalpath(source)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   640
17159
36a3016811d1 localrepo: use the path relative to "self.vfs" instead of "path" argument
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16705
diff changeset
   641
    if not dest:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26354
diff changeset
   642
        raise error.Abort(_("empty destination path is not valid"))
21803
62cc4055c6c8 hg: use vfs functions in clone
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21802
diff changeset
   643
31228
4cc3797aa59c vfs: use 'vfs' module directly in 'mercurial.hg'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31178
diff changeset
   644
    destvfs = vfsmod.vfs(dest, expandpath=True)
21803
62cc4055c6c8 hg: use vfs functions in clone
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21802
diff changeset
   645
    if destvfs.lexists():
62cc4055c6c8 hg: use vfs functions in clone
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21802
diff changeset
   646
        if not destvfs.isdir():
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26354
diff changeset
   647
            raise error.Abort(_("destination '%s' already exists") % dest)
21804
becb61de90a1 hg: update newly added listdir function of vfs in clone
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21803
diff changeset
   648
        elif destvfs.listdir():
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26354
diff changeset
   649
            raise error.Abort(_("destination '%s' is not empty") % dest)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   650
39566
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   651
    createopts = {}
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   652
    narrow = False
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   653
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   654
    if storeincludepats is not None:
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   655
        narrowspec.validatepatterns(storeincludepats)
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   656
        narrow = True
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   657
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   658
    if storeexcludepats is not None:
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   659
        narrowspec.validatepatterns(storeexcludepats)
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   660
        narrow = True
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   661
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   662
    if narrow:
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   663
        # Include everything by default if only exclusion patterns defined.
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   664
        if storeexcludepats and not storeincludepats:
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   665
            storeincludepats = {'path:.'}
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   666
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   667
        createopts['narrowfiles'] = True
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   668
40390
7e3b6c4f01a2 localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40366
diff changeset
   669
    if depth:
7e3b6c4f01a2 localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40366
diff changeset
   670
        createopts['shallowfilestore'] = True
7e3b6c4f01a2 localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40366
diff changeset
   671
40324
6637b079ae45 lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 39854
diff changeset
   672
    if srcpeer.capable(b'lfs-serve'):
6637b079ae45 lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 39854
diff changeset
   673
        # Repository creation honors the config if it disabled the extension, so
6637b079ae45 lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 39854
diff changeset
   674
        # we can't just announce that lfs will be enabled.  This check avoids
6637b079ae45 lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 39854
diff changeset
   675
        # saying that lfs will be enabled, and then saying it's an unknown
6637b079ae45 lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 39854
diff changeset
   676
        # feature.  The lfs creation option is set in either case so that a
6637b079ae45 lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 39854
diff changeset
   677
        # requirement is added.  If the extension is explicitly disabled but the
6637b079ae45 lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 39854
diff changeset
   678
        # requirement is set, the clone aborts early, before transferring any
6637b079ae45 lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 39854
diff changeset
   679
        # data.
6637b079ae45 lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 39854
diff changeset
   680
        createopts['lfs'] = True
6637b079ae45 lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 39854
diff changeset
   681
6637b079ae45 lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 39854
diff changeset
   682
        if extensions.disabledext('lfs'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   683
            ui.status(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   684
                _(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   685
                    '(remote is using large file support (lfs), but it is '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   686
                    'explicitly disabled in the local configuration)\n'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   687
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   688
            )
40324
6637b079ae45 lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 39854
diff changeset
   689
        else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   690
            ui.status(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   691
                _(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   692
                    '(remote is using large file support (lfs); lfs will '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   693
                    'be enabled for this repository)\n'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   694
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   695
            )
40324
6637b079ae45 lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 39854
diff changeset
   696
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   697
    shareopts = shareopts or {}
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   698
    sharepool = shareopts.get('pool')
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   699
    sharenamemode = shareopts.get('mode')
26026
d08e7449ff27 hg: avoid auto sharing when the clone destination is remote
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25761
diff changeset
   700
    if sharepool and islocal(dest):
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   701
        sharepath = None
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   702
        if sharenamemode == 'identity':
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   703
            # Resolve the name from the initial changeset in the remote
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   704
            # repository. This returns nullid when the remote is empty. It
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   705
            # raises RepoLookupError if revision 0 is filtered or otherwise
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   706
            # not available. If we fail to resolve, sharing is not enabled.
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   707
            try:
37640
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   708
                with srcpeer.commandexecutor() as e:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   709
                    rootnode = e.callcommand('lookup', {'key': '0',}).result()
37640
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   710
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   711
                if rootnode != node.nullid:
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   712
                    sharepath = os.path.join(sharepool, node.hex(rootnode))
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   713
                else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   714
                    ui.status(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   715
                        _(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   716
                            '(not using pooled storage: '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   717
                            'remote appears to be empty)\n'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   718
                        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   719
                    )
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   720
            except error.RepoLookupError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   721
                ui.status(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   722
                    _(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   723
                        '(not using pooled storage: '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   724
                        'unable to resolve identity of remote)\n'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   725
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   726
                )
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   727
        elif sharenamemode == 'remote':
29341
0d83ad967bf8 cleanup: replace uses of util.(md5|sha1|sha256|sha512) with hashlib.\1
Augie Fackler <raf@durin42.com>
parents: 29021
diff changeset
   728
            sharepath = os.path.join(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   729
                sharepool, node.hex(hashlib.sha1(source).digest())
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   730
            )
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   731
        else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   732
            raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   733
                _('unknown share naming mode: %s') % sharenamemode
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   734
            )
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   735
39566
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   736
        # TODO this is a somewhat arbitrary restriction.
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   737
        if narrow:
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   738
            ui.status(_('(pooled storage not supported for narrow clones)\n'))
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   739
            sharepath = None
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   740
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   741
        if sharepath:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   742
            return clonewithshare(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   743
                ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   744
                peeropts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   745
                sharepath,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   746
                source,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   747
                srcpeer,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   748
                dest,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   749
                pull=pull,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   750
                rev=revs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   751
                update=update,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   752
                stream=stream,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   753
            )
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
   754
18441
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
   755
    srclock = destlock = cleandir = None
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   756
    srcrepo = srcpeer.local()
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   757
    try:
14377
f90d5641c78b clone: make default path absolute for all local paths
Brendan Cully <brendan@kublai.com>
parents: 14213
diff changeset
   758
        abspath = origsource
f90d5641c78b clone: make default path absolute for all local paths
Brendan Cully <brendan@kublai.com>
parents: 14213
diff changeset
   759
        if islocal(origsource):
14825
de9eb6b1da4f util: rename the util.localpath that uses url to urllocalpath (issue2875)
Mads Kiilerich <mads@kiilerich.com>
parents: 14737
diff changeset
   760
            abspath = os.path.abspath(util.urllocalpath(origsource))
14377
f90d5641c78b clone: make default path absolute for all local paths
Brendan Cully <brendan@kublai.com>
parents: 14213
diff changeset
   761
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   762
        if islocal(dest):
18441
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
   763
            cleandir = dest
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   764
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   765
        copy = False
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   766
        if (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   767
            srcrepo
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   768
            and srcrepo.cancopy()
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   769
            and islocal(dest)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   770
            and not phases.hassecret(srcrepo)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   771
        ):
37264
54435fd09f1d clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents: 37263
diff changeset
   772
            copy = not pull and not revs
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   773
39566
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   774
        # TODO this is a somewhat arbitrary restriction.
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   775
        if narrow:
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   776
            copy = False
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   777
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   778
        if copy:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   779
            try:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   780
                # we use a lock here because if we race with commit, we
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   781
                # can end up with extra data in the cloned revlogs that's
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   782
                # not pointed to by changesets, thus causing verify to
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   783
                # fail
14463
81f559d1b9b2 hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents: 14377
diff changeset
   784
                srclock = srcrepo.lock(wait=False)
7640
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7546
diff changeset
   785
            except error.LockError:
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   786
                copy = False
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   787
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   788
        if copy:
14463
81f559d1b9b2 hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents: 14377
diff changeset
   789
            srcrepo.hook('preoutgoing', throw=True, source='clone')
15381
c519cd8f0169 backout dbdb777502dc (issue3077) (issue3071)
Matt Mackall <mpm@selenic.com>
parents: 15355
diff changeset
   790
            hgdir = os.path.realpath(os.path.join(dest, ".hg"))
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   791
            if not os.path.exists(dest):
39218
143efea71c2a clone: allow local cloning to create more than one level of directories
Matt Harbison <matt_harbison@yahoo.com>
parents: 38838
diff changeset
   792
                util.makedirs(dest)
7935
39566bb99a9c on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents: 7927
diff changeset
   793
            else:
39566bb99a9c on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents: 7927
diff changeset
   794
                # only clean up directories we create ourselves
18441
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
   795
                cleandir = hgdir
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   796
            try:
14463
81f559d1b9b2 hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents: 14377
diff changeset
   797
                destpath = hgdir
81f559d1b9b2 hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents: 14377
diff changeset
   798
                util.makedir(destpath, notindexed=True)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25624
diff changeset
   799
            except OSError as inst:
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   800
                if inst.errno == errno.EEXIST:
18441
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
   801
                    cleandir = None
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   802
                    raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   803
                        _("destination '%s' already exists") % dest
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   804
                    )
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   805
                raise
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   806
15078
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
   807
            destlock = copystore(ui, srcrepo, destpath)
22646
d6ecdb8bfa16 clone: copy `.hg/bookmarks` during copy clone
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22618
diff changeset
   808
            # copy bookmarks over
31331
4282feb79432 hg-mod: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31320
diff changeset
   809
            srcbookmarks = srcrepo.vfs.join('bookmarks')
22646
d6ecdb8bfa16 clone: copy `.hg/bookmarks` during copy clone
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22618
diff changeset
   810
            dstbookmarks = os.path.join(destpath, 'bookmarks')
d6ecdb8bfa16 clone: copy `.hg/bookmarks` during copy clone
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22618
diff changeset
   811
            if os.path.exists(srcbookmarks):
d6ecdb8bfa16 clone: copy `.hg/bookmarks` during copy clone
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22618
diff changeset
   812
                util.copyfile(srcbookmarks, dstbookmarks)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   813
17740
e6067bec18da branchcache: fetch source branchcache during clone (issue3378)
Tomasz Kleczek <tomasz.kleczek@fb.com>
parents: 17704
diff changeset
   814
            dstcachedir = os.path.join(destpath, 'cache')
35766
72fdd99eb526 caches: make 'cachetocopy' available in scmutil
Boris Feld <boris.feld@octobus.net>
parents: 35713
diff changeset
   815
            for cache in cacheutil.cachetocopy(srcrepo):
32526
3c8a71a8df11 local-clone: extract the listing of caches to copy
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32525
diff changeset
   816
                _copycache(srcrepo, dstcachedir, cache)
17740
e6067bec18da branchcache: fetch source branchcache during clone (issue3378)
Tomasz Kleczek <tomasz.kleczek@fb.com>
parents: 17704
diff changeset
   817
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   818
            # we need to re-init the repo after manually copying the data
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   819
            # into it
17874
2ba70eec1cf0 peer: subrepo isolation, pass repo instead of repo.ui to hg.peer
Simon Heimberg <simohe@besonet.ch>
parents: 17872
diff changeset
   820
            destpeer = peer(srcrepo, peeropts, dest)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   821
            srcrepo.hook('outgoing', source='clone', node=node.hex(node.nullid))
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   822
        else:
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   823
            try:
39566
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   824
                # only pass ui when no srcrepo
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   825
                destpeer = peer(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   826
                    srcrepo or ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   827
                    peeropts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   828
                    dest,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   829
                    create=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   830
                    createopts=createopts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   831
                )
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25624
diff changeset
   832
            except OSError as inst:
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   833
                if inst.errno == errno.EEXIST:
18441
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
   834
                    cleandir = None
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   835
                    raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   836
                        _("destination '%s' already exists") % dest
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   837
                    )
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   838
                raise
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   839
37264
54435fd09f1d clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents: 37263
diff changeset
   840
            if revs:
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   841
                if not srcpeer.capable('lookup'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   842
                    raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   843
                        _(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   844
                            "src repository does not support "
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   845
                            "revision lookup and so doesn't "
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   846
                            "support clone by revision"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   847
                        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   848
                    )
37640
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   849
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   850
                # TODO this is batchable.
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   851
                remoterevs = []
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   852
                for rev in revs:
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   853
                    with srcpeer.commandexecutor() as e:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   854
                        remoterevs.append(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   855
                            e.callcommand('lookup', {'key': rev,}).result()
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   856
                        )
37640
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   857
                revs = remoterevs
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   858
8417
39cf453da958 clone: try updating to the actual changeset specified in options
Brett Carter <brett@rdnzl.net>
parents: 8312
diff changeset
   859
                checkout = revs[0]
37264
54435fd09f1d clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents: 37263
diff changeset
   860
            else:
54435fd09f1d clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents: 37263
diff changeset
   861
                revs = None
27165
70884715725e localrepo: remove clone method by hoisting into hg.py
Augie Fackler <augie@google.com>
parents: 26781
diff changeset
   862
            local = destpeer.local()
70884715725e localrepo: remove clone method by hoisting into hg.py
Augie Fackler <augie@google.com>
parents: 26781
diff changeset
   863
            if local:
39571
cb675e95a2c2 hg: write narrow patterns after repo creation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39569
diff changeset
   864
                if narrow:
41046
ce0bc2952e2a narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents: 41006
diff changeset
   865
                    with local.wlock(), local.lock():
39571
cb675e95a2c2 hg: write narrow patterns after repo creation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39569
diff changeset
   866
                        local.setnarrowpats(storeincludepats, storeexcludepats)
41236
44a51c1c8e17 narrow: move copytonarrowspec() out of setnarrowpats()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41229
diff changeset
   867
                        narrowspec.copytoworkingcopy(local)
39571
cb675e95a2c2 hg: write narrow patterns after repo creation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39569
diff changeset
   868
35565
bdae51a83dfb clonebundle: make it possible to retrieve the initial bundle through largefile
Boris Feld <boris.feld@octobus.net>
parents: 35442
diff changeset
   869
                u = util.url(abspath)
bdae51a83dfb clonebundle: make it possible to retrieve the initial bundle through largefile
Boris Feld <boris.feld@octobus.net>
parents: 35442
diff changeset
   870
                defaulturl = bytes(u)
bdae51a83dfb clonebundle: make it possible to retrieve the initial bundle through largefile
Boris Feld <boris.feld@octobus.net>
parents: 35442
diff changeset
   871
                local.ui.setconfig('paths', 'default', defaulturl, 'clone')
23545
68c434799559 hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents: 23139
diff changeset
   872
                if not stream:
68c434799559 hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents: 23139
diff changeset
   873
                    if pull:
68c434799559 hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents: 23139
diff changeset
   874
                        stream = False
68c434799559 hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents: 23139
diff changeset
   875
                    else:
68c434799559 hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents: 23139
diff changeset
   876
                        stream = None
27165
70884715725e localrepo: remove clone method by hoisting into hg.py
Augie Fackler <augie@google.com>
parents: 26781
diff changeset
   877
                # internal config: ui.quietbookmarkmove
31465
2545ee88a57e clone: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31331
diff changeset
   878
                overrides = {('ui', 'quietbookmarkmove'): True}
2545ee88a57e clone: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31331
diff changeset
   879
                with local.ui.configoverride(overrides, 'clone'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   880
                    exchange.pull(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   881
                        local,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   882
                        srcpeer,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   883
                        revs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   884
                        streamclonerequested=stream,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   885
                        includepats=storeincludepats,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   886
                        excludepats=storeexcludepats,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   887
                        depth=depth,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   888
                    )
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   889
            elif srcrepo:
39566
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   890
                # TODO lift restriction once exchange.push() accepts narrow
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   891
                # push.
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   892
                if narrow:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   893
                    raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   894
                        _(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   895
                            'narrow clone not available for '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   896
                            'remote destinations'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   897
                        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   898
                    )
39566
65b5900f30be hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39565
diff changeset
   899
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   900
                exchange.push(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   901
                    srcrepo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   902
                    destpeer,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   903
                    revs=revs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   904
                    bookmarks=srcrepo._bookmarks.keys(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   905
                )
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   906
            else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   907
                raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   908
                    _("clone from remote to remote not supported")
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   909
                )
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   910
18441
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
   911
        cleandir = None
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   912
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   913
        destrepo = destpeer.local()
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   914
        if destrepo:
22837
2be7d5ebd4d0 config: use the same hgrc for a cloned repo as for an uninitted repo
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 22818
diff changeset
   915
            template = uimod.samplehgrcs['cloned']
15552
62c9183a0bbb clone: don't save user's password in .hg/hgrc (Issue3122)
Augie Fackler <durin42@gmail.com>
parents: 15381
diff changeset
   916
            u = util.url(abspath)
62c9183a0bbb clone: don't save user's password in .hg/hgrc (Issue3122)
Augie Fackler <durin42@gmail.com>
parents: 15381
diff changeset
   917
            u.passwd = None
33713
6294654453ee py3: use bytes IO to write sample hgrc
Yuya Nishihara <yuya@tcha.org>
parents: 33034
diff changeset
   918
            defaulturl = bytes(u)
35620
545967ec33dc clone: use utility function to write hgrc
Yuya Nishihara <yuya@tcha.org>
parents: 35619
diff changeset
   919
            destrepo.vfs.write('hgrc', util.tonativeeol(template % defaulturl))
20790
49f2d5644f04 config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents: 20355
diff changeset
   920
            destrepo.ui.setconfig('paths', 'default', defaulturl, 'clone')
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8807
diff changeset
   921
35340
773a9a06047c clone: add support for storing remotenames while cloning
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34957
diff changeset
   922
            if ui.configbool('experimental', 'remotenames'):
35356
a29fe459fc49 remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35340
diff changeset
   923
                logexchange.pullremotenames(destrepo, srcpeer)
35340
773a9a06047c clone: add support for storing remotenames while cloning
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34957
diff changeset
   924
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   925
            if update:
6526
cfeeac24fc1e repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents: 6525
diff changeset
   926
                if update is not True:
37640
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   927
                    with srcpeer.commandexecutor() as e:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   928
                        checkout = e.callcommand(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   929
                            'lookup', {'key': update,}
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   930
                        ).result()
37640
ce8828217369 hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   931
17867
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
   932
                uprev = None
17882
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
   933
                status = None
17867
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
   934
                if checkout is not None:
38753
e06a10d3b926 clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents: 38386
diff changeset
   935
                    # Some extensions (at least hg-git and hg-subversion) have
e06a10d3b926 clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents: 38386
diff changeset
   936
                    # a peer.lookup() implementation that returns a name instead
e06a10d3b926 clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents: 38386
diff changeset
   937
                    # of a nodeid. We work around it here until we've figured
e06a10d3b926 clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents: 38386
diff changeset
   938
                    # out a better solution.
e06a10d3b926 clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents: 38386
diff changeset
   939
                    if len(checkout) == 20 and checkout in destrepo:
37480
c569e51ee449 clone: avoid using repo.lookup() with binary nodeid
Martin von Zweigbergk <martinvonz@google.com>
parents: 37313
diff changeset
   940
                        uprev = checkout
38753
e06a10d3b926 clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents: 38386
diff changeset
   941
                    elif scmutil.isrevsymbol(destrepo, checkout):
e06a10d3b926 clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents: 38386
diff changeset
   942
                        uprev = scmutil.revsymbol(destrepo, checkout).node()
37480
c569e51ee449 clone: avoid using repo.lookup() with binary nodeid
Martin von Zweigbergk <martinvonz@google.com>
parents: 37313
diff changeset
   943
                    else:
26354
c1fb2cab6260 clone: check update rev for being True
Sean Farley <sean@farley.io>
parents: 26353
diff changeset
   944
                        if update is not True:
c1fb2cab6260 clone: check update rev for being True
Sean Farley <sean@farley.io>
parents: 26353
diff changeset
   945
                            try:
c1fb2cab6260 clone: check update rev for being True
Sean Farley <sean@farley.io>
parents: 26353
diff changeset
   946
                                uprev = destrepo.lookup(update)
c1fb2cab6260 clone: check update rev for being True
Sean Farley <sean@farley.io>
parents: 26353
diff changeset
   947
                            except error.RepoLookupError:
c1fb2cab6260 clone: check update rev for being True
Sean Farley <sean@farley.io>
parents: 26353
diff changeset
   948
                                pass
17867
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
   949
                if uprev is None:
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
   950
                    try:
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
   951
                        uprev = destrepo._bookmarks['@']
17870
7d2dd10ce9ea clone: activate @ bookmark if updating to it
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17867
diff changeset
   952
                        update = '@'
17882
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
   953
                        bn = destrepo[uprev].branch()
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
   954
                        if bn == 'default':
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
   955
                            status = _("updating to bookmark @\n")
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
   956
                        else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   957
                            status = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   958
                                _("updating to bookmark @ on branch %s\n") % bn
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   959
                            )
17867
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
   960
                    except KeyError:
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
   961
                        try:
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
   962
                            uprev = destrepo.branchtip('default')
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
   963
                        except error.RepoLookupError:
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
   964
                            uprev = destrepo.lookup('tip')
17882
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
   965
                if not status:
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
   966
                    bn = destrepo[uprev].branch()
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
   967
                    status = _("updating to branch %s\n") % bn
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
   968
                destrepo.ui.status(status)
14463
81f559d1b9b2 hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents: 14377
diff changeset
   969
                _update(destrepo, uprev)
17703
4a07d2ff7c66 clone: activate bookmark specified with --updaterev
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17342
diff changeset
   970
                if update in destrepo._bookmarks:
24945
e0b0fbd47491 bookmarks: rename setcurrent to activate (API)
Ryan McElroy <rmcelroy@fb.com>
parents: 24440
diff changeset
   971
                    bookmarks.activate(destrepo, update)
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   972
    finally:
15908
60cb4f381a78 bookmarks: backout locking change in 12dea4d998ec
Matt Mackall <mpm@selenic.com>
parents: 15887
diff changeset
   973
        release(srclock, destlock)
18441
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
   974
        if cleandir is not None:
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
   975
            shutil.rmtree(cleandir, True)
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   976
        if srcpeer is not None:
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
   977
            srcpeer.close()
19313
3b96d6e44a4d hg: move return statement after finally block
simon@laptop-tosh
parents: 18944
diff changeset
   978
    return srcpeer, destpeer
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
   979
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   980
27402
5184089f5d30 hg: add quietempty flag to _showstats
timeless <timeless@mozdev.org>
parents: 27354
diff changeset
   981
def _showstats(repo, stats, quietempty=False):
37128
6f570c501e3e merge: deprecate accessing update results by index
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37110
diff changeset
   982
    if quietempty and stats.isempty():
27402
5184089f5d30 hg: add quietempty flag to _showstats
timeless <timeless@mozdev.org>
parents: 27354
diff changeset
   983
        return
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   984
    repo.ui.status(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   985
        _(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   986
            "%d files updated, %d files merged, "
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   987
            "%d files removed, %d files unresolved\n"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   988
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   989
        % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   990
            stats.updatedcount,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   991
            stats.mergedcount,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   992
            stats.removedcount,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   993
            stats.unresolvedcount,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   994
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   995
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
   996
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   997
31176
fad5e299cfc7 update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents: 31148
diff changeset
   998
def updaterepo(repo, node, overwrite, updatecheck=None):
17895
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
   999
    """Update the working directory to node.
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
  1000
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
  1001
    When overwrite is set, changes are clobbered, merged else
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
  1002
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
  1003
    returns stats (see pydoc mercurial.merge.applyupdates)"""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1004
    return mergemod.update(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1005
        repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1006
        node,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1007
        branchmerge=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1008
        force=overwrite,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1009
        labels=['working copy', 'destination'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1010
        updatecheck=updatecheck,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1011
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1012
17895
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
  1013
31176
fad5e299cfc7 update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents: 31148
diff changeset
  1014
def update(repo, node, quietempty=False, updatecheck=None):
fad5e299cfc7 update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents: 31148
diff changeset
  1015
    """update the working directory to node"""
fad5e299cfc7 update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents: 31148
diff changeset
  1016
    stats = updaterepo(repo, node, False, updatecheck=updatecheck)
27404
1cf3543cc780 update: add quietempty flag to _showstats
timeless <timeless@mozdev.org>
parents: 27403
diff changeset
  1017
    _showstats(repo, stats, quietempty)
37128
6f570c501e3e merge: deprecate accessing update results by index
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37110
diff changeset
  1018
    if stats.unresolvedcount:
6518
92ccccb55ba3 resolve: new command
Matt Mackall <mpm@selenic.com>
parents: 6338
diff changeset
  1019
        repo.ui.status(_("use 'hg resolve' to retry unresolved file merges\n"))
37128
6f570c501e3e merge: deprecate accessing update results by index
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37110
diff changeset
  1020
    return stats.unresolvedcount > 0
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
  1021
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1022
7546
c7f48414f3ad add a comment about the need of hg._update()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7280
diff changeset
  1023
# naming conflict in clone()
c7f48414f3ad add a comment about the need of hg._update()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7280
diff changeset
  1024
_update = update
c7f48414f3ad add a comment about the need of hg._update()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7280
diff changeset
  1025
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1026
27403
50b6a04f817f histedit: omit useless message from abort
timeless <timeless@mozdev.org>
parents: 27402
diff changeset
  1027
def clean(repo, node, show_stats=True, quietempty=False):
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
  1028
    """forcibly switch the working directory to node, clobbering changes"""
17895
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
  1029
    stats = updaterepo(repo, node, True)
31320
f59b6cf663a9 vfs: use repo.vfs.unlinkpath
Mads Kiilerich <mads@kiilerich.com>
parents: 31228
diff changeset
  1030
    repo.vfs.unlinkpath('graftstate', ignoremissing=True)
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
  1031
    if show_stats:
27403
50b6a04f817f histedit: omit useless message from abort
timeless <timeless@mozdev.org>
parents: 27402
diff changeset
  1032
        _showstats(repo, stats, quietempty)
37128
6f570c501e3e merge: deprecate accessing update results by index
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37110
diff changeset
  1033
    return stats.unresolvedcount > 0
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
  1034
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1035
28501
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1036
# naming conflict in updatetotally()
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1037
_clean = clean
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1038
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1039
_VALID_UPDATECHECKS = {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1040
    mergemod.UPDATECHECK_ABORT,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1041
    mergemod.UPDATECHECK_NONE,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1042
    mergemod.UPDATECHECK_LINEAR,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1043
    mergemod.UPDATECHECK_NO_CONFLICT,
42973
ee1ef76d7339 hg: have `updatetotally` more thoroughly check updatecheck argument (API)
Augie Fackler <augie@google.com>
parents: 42972
diff changeset
  1044
}
ee1ef76d7339 hg: have `updatetotally` more thoroughly check updatecheck argument (API)
Augie Fackler <augie@google.com>
parents: 42972
diff changeset
  1045
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1046
31176
fad5e299cfc7 update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents: 31148
diff changeset
  1047
def updatetotally(ui, repo, checkout, brev, clean=False, updatecheck=None):
28501
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1048
    """Update the working directory with extra care for non-file components
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1049
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1050
    This takes care of non-file components below:
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1051
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1052
    :bookmark: might be advanced or (in)activated
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1053
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1054
    This takes arguments below:
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1055
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1056
    :checkout: to which revision the working directory is updated
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1057
    :brev: a name, which might be a bookmark to be activated after updating
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1058
    :clean: whether changes in the working directory can be discarded
31176
fad5e299cfc7 update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents: 31148
diff changeset
  1059
    :updatecheck: how to deal with a dirty working directory
fad5e299cfc7 update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents: 31148
diff changeset
  1060
42972
1ad3ebb39c61 merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents: 42823
diff changeset
  1061
    Valid values for updatecheck are the UPDATECHECK_* constants
1ad3ebb39c61 merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents: 42823
diff changeset
  1062
    defined in the merge module. Passing `None` will result in using the
1ad3ebb39c61 merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents: 42823
diff changeset
  1063
    configured default.
31176
fad5e299cfc7 update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents: 31148
diff changeset
  1064
42972
1ad3ebb39c61 merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents: 42823
diff changeset
  1065
     * ABORT: abort if the working directory is dirty
1ad3ebb39c61 merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents: 42823
diff changeset
  1066
     * NONE: don't check (merge working directory changes into destination)
1ad3ebb39c61 merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents: 42823
diff changeset
  1067
     * LINEAR: check that update is linear before merging working directory
31176
fad5e299cfc7 update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents: 31148
diff changeset
  1068
               changes into destination
42972
1ad3ebb39c61 merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents: 42823
diff changeset
  1069
     * NO_CONFLICT: check that the update does not result in file merges
28501
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1070
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1071
    This returns whether conflict is detected at updating or not.
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1072
    """
31176
fad5e299cfc7 update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents: 31148
diff changeset
  1073
    if updatecheck is None:
34705
23ed47a895d5 config: graduate experimental.updatecheck to commands.update.check
Augie Fackler <augie@google.com>
parents: 34146
diff changeset
  1074
        updatecheck = ui.config('commands', 'update.check')
42973
ee1ef76d7339 hg: have `updatetotally` more thoroughly check updatecheck argument (API)
Augie Fackler <augie@google.com>
parents: 42972
diff changeset
  1075
        if updatecheck not in _VALID_UPDATECHECKS:
31177
696e321b304d update: add experimental config for default way of handling dirty wdir
Martin von Zweigbergk <martinvonz@google.com>
parents: 31176
diff changeset
  1076
            # If not configured, or invalid value configured
42972
1ad3ebb39c61 merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents: 42823
diff changeset
  1077
            updatecheck = mergemod.UPDATECHECK_LINEAR
42973
ee1ef76d7339 hg: have `updatetotally` more thoroughly check updatecheck argument (API)
Augie Fackler <augie@google.com>
parents: 42972
diff changeset
  1078
    if updatecheck not in _VALID_UPDATECHECKS:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1079
        raise ValueError(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1080
            r'Invalid updatecheck value %r (can accept %r)'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1081
            % (updatecheck, _VALID_UPDATECHECKS)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1082
        )
28503
138ec8835e63 hg: acquire wlock while updating the working directory via updatetotally
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28501
diff changeset
  1083
    with repo.wlock():
28501
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1084
        movemarkfrom = None
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1085
        warndest = False
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1086
        if checkout is None:
30982
11c253997b0e destutil: drop now-unused "check" parameter from destupdate()
Martin von Zweigbergk <martinvonz@google.com>
parents: 30062
diff changeset
  1087
            updata = destutil.destupdate(repo, clean=clean)
28501
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1088
            checkout, movemarkfrom, brev = updata
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1089
            warndest = True
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1090
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1091
        if clean:
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1092
            ret = _clean(repo, checkout)
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1093
        else:
42972
1ad3ebb39c61 merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents: 42823
diff changeset
  1094
            if updatecheck == mergemod.UPDATECHECK_ABORT:
30983
7beb3ec34443 update: move check for dirty wdir into hg.updatetotally()
Martin von Zweigbergk <martinvonz@google.com>
parents: 30982
diff changeset
  1095
                cmdutil.bailifchanged(repo, merge=False)
42972
1ad3ebb39c61 merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents: 42823
diff changeset
  1096
                updatecheck = mergemod.UPDATECHECK_NONE
31176
fad5e299cfc7 update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents: 31148
diff changeset
  1097
            ret = _update(repo, checkout, updatecheck=updatecheck)
28501
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1098
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1099
        if not ret and movemarkfrom:
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1100
            if movemarkfrom == repo['.'].node():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1101
                pass  # no-op update
28501
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1102
            elif bookmarks.update(repo, [movemarkfrom], repo['.'].node()):
29906
a77d48219edd update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 29765
diff changeset
  1103
                b = ui.label(repo._activebookmark, 'bookmarks.active')
a77d48219edd update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 29765
diff changeset
  1104
                ui.status(_("updating bookmark %s\n") % b)
28501
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1105
            else:
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1106
                # this can happen with a non-linear update
29906
a77d48219edd update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 29765
diff changeset
  1107
                b = ui.label(repo._activebookmark, 'bookmarks')
a77d48219edd update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 29765
diff changeset
  1108
                ui.status(_("(leaving bookmark %s)\n") % b)
28501
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1109
                bookmarks.deactivate(repo)
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1110
        elif brev in repo._bookmarks:
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1111
            if brev != repo._activebookmark:
29906
a77d48219edd update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 29765
diff changeset
  1112
                b = ui.label(brev, 'bookmarks.active')
a77d48219edd update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 29765
diff changeset
  1113
                ui.status(_("(activating bookmark %s)\n") % b)
28501
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1114
            bookmarks.activate(repo, brev)
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1115
        elif brev:
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1116
            if repo._activebookmark:
29906
a77d48219edd update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 29765
diff changeset
  1117
                b = ui.label(repo._activebookmark, 'bookmarks')
a77d48219edd update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 29765
diff changeset
  1118
                ui.status(_("(leaving bookmark %s)\n") % b)
28501
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1119
            bookmarks.deactivate(repo)
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1120
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1121
        if warndest:
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1122
            destutil.statusotherdests(ui, repo)
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1123
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1124
    return ret
66513f6ca038 commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28324
diff changeset
  1125
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1126
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1127
def merge(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1128
    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1129
    node,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1130
    force=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1131
    remind=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1132
    mergeforce=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1133
    labels=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1134
    abort=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1135
):
13162
115a9760c382 merge: document some internal return values.
Greg Ward <greg-hg@gerg.ca>
parents: 13047
diff changeset
  1136
    """Branch merge with node, resolving changes. Return true if any
115a9760c382 merge: document some internal return values.
Greg Ward <greg-hg@gerg.ca>
parents: 13047
diff changeset
  1137
    unresolved conflicts."""
42600
3bc400ccbf99 abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents: 42197
diff changeset
  1138
    if abort:
42604
209f2b8a50dc abort: removed labels argument from abortmerge()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42600
diff changeset
  1139
        return abortmerge(repo.ui, repo)
35704
41ef02ba329b merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35622
diff changeset
  1140
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1141
    stats = mergemod.update(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1142
        repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1143
        node,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1144
        branchmerge=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1145
        force=force,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1146
        mergeforce=mergeforce,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1147
        labels=labels,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1148
    )
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
  1149
    _showstats(repo, stats)
37128
6f570c501e3e merge: deprecate accessing update results by index
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37110
diff changeset
  1150
    if stats.unresolvedcount:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1151
        repo.ui.status(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1152
            _(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1153
                "use 'hg resolve' to retry unresolved file merges "
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1154
                "or 'hg merge --abort' to abandon\n"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1155
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1156
        )
42600
3bc400ccbf99 abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents: 42197
diff changeset
  1157
    elif remind:
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
  1158
        repo.ui.status(_("(branch merge, don't forget to commit)\n"))
37128
6f570c501e3e merge: deprecate accessing update results by index
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37110
diff changeset
  1159
    return stats.unresolvedcount > 0
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
  1160
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1161
42604
209f2b8a50dc abort: removed labels argument from abortmerge()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42600
diff changeset
  1162
def abortmerge(ui, repo):
42600
3bc400ccbf99 abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents: 42197
diff changeset
  1163
    ms = mergemod.mergestate.read(repo)
3bc400ccbf99 abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents: 42197
diff changeset
  1164
    if ms.active():
3bc400ccbf99 abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents: 42197
diff changeset
  1165
        # there were conflicts
3bc400ccbf99 abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents: 42197
diff changeset
  1166
        node = ms.localctx.hex()
3bc400ccbf99 abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents: 42197
diff changeset
  1167
    else:
3bc400ccbf99 abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents: 42197
diff changeset
  1168
        # there were no conficts, mergestate was not stored
3bc400ccbf99 abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents: 42197
diff changeset
  1169
        node = repo['.'].hex()
3bc400ccbf99 abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents: 42197
diff changeset
  1170
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1171
    repo.ui.status(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1172
        _("aborting the merge, updating back to" " %s\n") % node[:12]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1173
    )
42604
209f2b8a50dc abort: removed labels argument from abortmerge()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42600
diff changeset
  1174
    stats = mergemod.update(repo, node, branchmerge=False, force=True)
42600
3bc400ccbf99 abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents: 42197
diff changeset
  1175
    _showstats(repo, stats)
3bc400ccbf99 abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents: 42197
diff changeset
  1176
    return stats.unresolvedcount > 0
3bc400ccbf99 abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents: 42197
diff changeset
  1177
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1178
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1179
def _incoming(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1180
    displaychlist, subreporecurse, ui, repo, source, opts, buffered=False
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1181
):
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1182
    """
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1183
    Helper for incoming / gincoming.
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1184
    displaychlist gets called with
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1185
        (remoterepo, incomingchangesetlist, displayer) parameters,
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1186
    and is supposed to contain only code that can't be unified.
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1187
    """
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1188
    source, branches = parseurl(ui.expandpath(source), opts.get('branch'))
14556
517e1d88bf7e hg: change various repository() users to use peer() where appropriate
Matt Mackall <mpm@selenic.com>
parents: 14555
diff changeset
  1189
    other = peer(repo, opts, source)
14076
924c82157d46 url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents: 14073
diff changeset
  1190
    ui.status(_('comparing with %s\n') % util.hidepassword(source))
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1191
    revs, checkout = addbranchrevs(repo, other, branches, opts.get('rev'))
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1192
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1193
    if revs:
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1194
        revs = [other.lookup(rev) for rev in revs]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1195
    other, chlist, cleanupfn = bundlerepo.getremotechanges(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1196
        ui, repo, other, revs, opts["bundle"], opts["force"]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1197
    )
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14156
diff changeset
  1198
    try:
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14156
diff changeset
  1199
        if not chlist:
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14156
diff changeset
  1200
            ui.status(_("no changes found\n"))
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14156
diff changeset
  1201
            return subreporecurse()
31077
16d7db8f752c incoming: delay pager activation until right before printing changes
Augie Fackler <augie@google.com>
parents: 30983
diff changeset
  1202
        ui.pager('incoming')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1203
        displayer = logcmdutil.changesetdisplayer(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1204
            ui, other, opts, buffered=buffered
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1205
        )
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1206
        displaychlist(other, chlist, displayer)
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1207
        displayer.close()
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1208
    finally:
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14156
diff changeset
  1209
        cleanupfn()
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1210
    subreporecurse()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1211
    return 0  # exit code is zero since we found incoming changes
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1212
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1213
12273
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
  1214
def incoming(ui, repo, source, opts):
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1215
    def subreporecurse():
12400
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1216
        ret = 1
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1217
        if opts.get('subrepos'):
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1218
            ctx = repo[None]
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1219
            for subpath in sorted(ctx.substate):
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1220
                sub = ctx.sub(subpath)
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1221
                ret = min(ret, sub.incoming(ui, source, opts))
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1222
        return ret
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1223
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1224
    def display(other, chlist, displayer):
35928
c8e2d6ed1f9e cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35766
diff changeset
  1225
        limit = logcmdutil.getlimit(opts)
12273
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
  1226
        if opts.get('newest_first'):
12729
55f0648c7e2d incoming: rename variable
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12400
diff changeset
  1227
            chlist.reverse()
12273
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
  1228
        count = 0
12729
55f0648c7e2d incoming: rename variable
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12400
diff changeset
  1229
        for n in chlist:
12273
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
  1230
            if limit is not None and count >= limit:
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
  1231
                break
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
  1232
            parents = [p for p in other.changelog.parents(n) if p != nullid]
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
  1233
            if opts.get('no_merges') and len(parents) == 2:
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
  1234
                continue
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
  1235
            count += 1
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
  1236
            displayer.show(other[n])
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1237
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
  1238
    return _incoming(display, subreporecurse, ui, repo, source, opts)
12273
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
  1239
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1240
12735
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
  1241
def _outgoing(ui, repo, dest, opts):
35442
0ebd94ac56d1 outgoing: respect ":pushurl" paths (issue5365)
Hollis Blanchard <hollis_blanchard@mentor.com>
parents: 35356
diff changeset
  1242
    path = ui.paths.getpath(dest, default=('default-push', 'default'))
0ebd94ac56d1 outgoing: respect ":pushurl" paths (issue5365)
Hollis Blanchard <hollis_blanchard@mentor.com>
parents: 35356
diff changeset
  1243
    if not path:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1244
        raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1245
            _('default repository not configured!'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1246
            hint=_("see 'hg help config.paths'"),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1247
        )
35442
0ebd94ac56d1 outgoing: respect ":pushurl" paths (issue5365)
Hollis Blanchard <hollis_blanchard@mentor.com>
parents: 35356
diff changeset
  1248
    dest = path.pushloc or path.loc
0ebd94ac56d1 outgoing: respect ":pushurl" paths (issue5365)
Hollis Blanchard <hollis_blanchard@mentor.com>
parents: 35356
diff changeset
  1249
    branches = path.branch, opts.get('branch') or []
0ebd94ac56d1 outgoing: respect ":pushurl" paths (issue5365)
Hollis Blanchard <hollis_blanchard@mentor.com>
parents: 35356
diff changeset
  1250
14076
924c82157d46 url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents: 14073
diff changeset
  1251
    ui.status(_('comparing with %s\n') % util.hidepassword(dest))
12735
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
  1252
    revs, checkout = addbranchrevs(repo, repo, branches, opts.get('rev'))
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
  1253
    if revs:
37313
70c52800940b outgoing: avoid repo.lookup() for converting revnum to nodeid
Martin von Zweigbergk <martinvonz@google.com>
parents: 37264
diff changeset
  1254
        revs = [repo[rev].node() for rev in scmutil.revrange(repo, revs)]
12735
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
  1255
14556
517e1d88bf7e hg: change various repository() users to use peer() where appropriate
Matt Mackall <mpm@selenic.com>
parents: 14555
diff changeset
  1256
    other = peer(repo, opts, dest)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1257
    outgoing = discovery.findcommonoutgoing(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1258
        repo, other, revs, force=opts.get('force')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1259
    )
15837
cd956049fc14 discovery: introduce outgoing object for result of findcommonoutgoing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15741
diff changeset
  1260
    o = outgoing.missing
12735
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
  1261
    if not o:
17248
6ffb35b2284c discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents: 17198
diff changeset
  1262
        scmutil.nochangesfound(repo.ui, repo, outgoing.excluded)
21050
025ec0f08cb6 hg: make "_outgoing()" return peer object for remote repository
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21049
diff changeset
  1263
    return o, other
12735
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
  1264
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1265
12271
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
  1266
def outgoing(ui, repo, dest, opts):
12400
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1267
    def recurse():
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1268
        ret = 1
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1269
        if opts.get('subrepos'):
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1270
            ctx = repo[None]
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1271
            for subpath in sorted(ctx.substate):
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1272
                sub = ctx.sub(subpath)
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1273
                ret = min(ret, sub.outgoing(ui, dest, opts))
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1274
        return ret
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1275
35928
c8e2d6ed1f9e cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35766
diff changeset
  1276
    limit = logcmdutil.getlimit(opts)
21050
025ec0f08cb6 hg: make "_outgoing()" return peer object for remote repository
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21049
diff changeset
  1277
    o, other = _outgoing(ui, repo, dest, opts)
21049
f117a0ba5289 hg: make "_outgoing()" return empty list instead of "None"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20870
diff changeset
  1278
    if not o:
21051
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21050
diff changeset
  1279
        cmdutil.outgoinghooks(ui, repo, other, opts, o)
12400
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1280
        return recurse()
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1281
12271
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
  1282
    if opts.get('newest_first'):
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
  1283
        o.reverse()
31078
d2ed0abce08e outgoing: avoid running pager until we're actually showing changes
Augie Fackler <augie@google.com>
parents: 31077
diff changeset
  1284
    ui.pager('outgoing')
35928
c8e2d6ed1f9e cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35766
diff changeset
  1285
    displayer = logcmdutil.changesetdisplayer(ui, repo, opts)
12271
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
  1286
    count = 0
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
  1287
    for n in o:
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
  1288
        if limit is not None and count >= limit:
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
  1289
            break
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
  1290
        parents = [p for p in repo.changelog.parents(n) if p != nullid]
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
  1291
        if opts.get('no_merges') and len(parents) == 2:
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
  1292
            continue
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
  1293
        count += 1
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
  1294
        displayer.show(repo[n])
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
  1295
    displayer.close()
21051
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21050
diff changeset
  1296
    cmdutil.outgoinghooks(ui, repo, other, opts, o)
12400
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
  1297
    recurse()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1298
    return 0  # exit code is zero since we found outgoing changes
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1299
12271
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
  1300
42197
57539e5ea2e0 verify: introduce a notion of "level"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42109
diff changeset
  1301
def verify(repo, level=None):
2778
fdc232d8a193 Move repo.verify
Matt Mackall <mpm@selenic.com>
parents: 2775
diff changeset
  1302
    """verify the consistency of a repository"""
42197
57539e5ea2e0 verify: introduce a notion of "level"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42109
diff changeset
  1303
    ret = verifymod.verify(repo, level=level)
25591
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1304
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1305
    # Broken subrepo references in hidden csets don't seem worth worrying about,
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1306
    # since they can't be pushed/pulled, and --hidden can be used if they are a
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1307
    # concern.
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1308
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1309
    # pathto() is needed for -R case
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1310
    revs = repo.revs(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1311
        "filelog(%s)", util.pathto(repo.root, repo.getcwd(), '.hgsubstate')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1312
    )
25591
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1313
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1314
    if revs:
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1315
        repo.ui.status(_('checking subrepo links\n'))
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1316
        for rev in revs:
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1317
            ctx = repo[rev]
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1318
            try:
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1319
                for subpath in ctx.substate:
29021
92d37fb3f1aa verify: don't init subrepo when missing one is referenced (issue5128) (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 28655
diff changeset
  1320
                    try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1321
                        ret = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1322
                            ctx.sub(subpath, allowcreate=False).verify() or ret
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1323
                        )
29021
92d37fb3f1aa verify: don't init subrepo when missing one is referenced (issue5128) (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 28655
diff changeset
  1324
                    except error.RepoError as e:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1325
                        repo.ui.warn('%d: %s\n' % (rev, e))
25591
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1326
            except Exception:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1327
                repo.ui.warn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1328
                    _('.hgsubstate is corrupt in revision %s\n')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1329
                    % node.short(ctx.node())
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1330
                )
25591
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1331
f1d46075b13a verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 25365
diff changeset
  1332
    return ret
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1333
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1334
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1335
def remoteui(src, opts):
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1336
    'build a remote ui from ui or repo and opts'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1337
    if util.safehasattr(src, 'baseui'):  # looks like a repository
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1338
        dst = src.baseui.copy()  # drop repo-specific config
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1339
        src = src.ui  # copy target options from repo
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1340
    else:  # assume it's a global ui object
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1341
        dst = src.copy()  # keep all global options
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1342
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1343
    # copy ssh-specific options
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1344
    for o in 'ssh', 'remotecmd':
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1345
        v = opts.get(o) or src.config('ui', o)
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1346
        if v:
20790
49f2d5644f04 config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents: 20355
diff changeset
  1347
            dst.setconfig("ui", o, v, 'copied')
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1348
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1349
    # copy bundle-specific options
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1350
    r = src.config('bundle', 'mainreporoot')
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1351
    if r:
20790
49f2d5644f04 config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents: 20355
diff changeset
  1352
        dst.setconfig('bundle', 'mainreporoot', r, 'copied')
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1353
13192
4d03707916d3 https: use web.cacerts configuration from local repo to validate remote repo
Mads Kiilerich <mads@kiilerich.com>
parents: 12735
diff changeset
  1354
    # copy selected local settings to the remote ui
29616
3fde328d0913 hg: copy [hostsecurity] options to remote ui instances (issue5305)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29594
diff changeset
  1355
    for sect in ('auth', 'hostfingerprints', 'hostsecurity', 'http_proxy'):
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1356
        for key, val in src.configitems(sect):
20790
49f2d5644f04 config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents: 20355
diff changeset
  1357
            dst.setconfig(sect, key, val, 'copied')
13192
4d03707916d3 https: use web.cacerts configuration from local repo to validate remote repo
Mads Kiilerich <mads@kiilerich.com>
parents: 12735
diff changeset
  1358
    v = src.config('web', 'cacerts')
29594
e417664a3339 ssl: remove special case of web.cacerts=! from remoteui()
Yuya Nishihara <yuya@tcha.org>
parents: 29424
diff changeset
  1359
    if v:
20790
49f2d5644f04 config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents: 20355
diff changeset
  1360
        dst.setconfig('web', 'cacerts', util.expandpath(v), 'copied')
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1361
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
  1362
    return dst
26219
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1363
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1364
26219
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1365
# Files of interest
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1366
# Used to check if the repository has changed looking at mtime and size of
26781
1aee2ab0f902 spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents: 26654
diff changeset
  1367
# these files.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1368
foi = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1369
    ('spath', '00changelog.i'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1370
    ('spath', 'phaseroots'),  # ! phase can change content at the same size
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1371
    ('spath', 'obsstore'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1372
    ('path', 'bookmarks'),  # ! bookmark can change content at the same size
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1373
]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42973
diff changeset
  1374
26219
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1375
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1376
class cachedlocalrepo(object):
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1377
    """Holds a localrepository that can be cached and reused."""
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1378
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1379
    def __init__(self, repo):
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1380
        """Create a new cached repo from an existing repo.
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1381
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1382
        We assume the passed in repo was recently created. If the
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1383
        repo has changed between when it was created and when it was
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1384
        turned into a cache, it may not refresh properly.
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1385
        """
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1386
        assert isinstance(repo, localrepo.localrepository)
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1387
        self._repo = repo
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1388
        self._state, self.mtime = self._repostate()
28119
91a827e760df hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28020
diff changeset
  1389
        self._filtername = repo.filtername
26219
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1390
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1391
    def fetch(self):
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1392
        """Refresh (if necessary) and return a repository.
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1393
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1394
        If the cached instance is out of date, it will be recreated
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1395
        automatically and returned.
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1396
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1397
        Returns a tuple of the repo and a boolean indicating whether a new
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1398
        repo instance was created.
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1399
        """
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1400
        # We compare the mtimes and sizes of some well-known files to
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1401
        # determine if the repo changed. This is not precise, as mtimes
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1402
        # are susceptible to clock skew and imprecise filesystems and
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1403
        # file content can change while maintaining the same size.
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1404
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1405
        state, mtime = self._repostate()
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1406
        if state == self._state:
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1407
            return self._repo, False
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1408
28119
91a827e760df hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28020
diff changeset
  1409
        repo = repository(self._repo.baseui, self._repo.url())
91a827e760df hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28020
diff changeset
  1410
        if self._filtername:
91a827e760df hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28020
diff changeset
  1411
            self._repo = repo.filtered(self._filtername)
91a827e760df hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28020
diff changeset
  1412
        else:
91a827e760df hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28020
diff changeset
  1413
            self._repo = repo.unfiltered()
26219
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1414
        self._state = state
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1415
        self.mtime = mtime
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1416
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1417
        return self._repo, True
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1418
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1419
    def _repostate(self):
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1420
        state = []
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1421
        maxmtime = -1
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1422
        for attr, fname in foi:
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1423
            prefix = getattr(self._repo, attr)
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1424
            p = os.path.join(prefix, fname)
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1425
            try:
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1426
                st = os.stat(p)
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1427
            except OSError:
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1428
                st = os.stat(prefix)
36789
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36725
diff changeset
  1429
            state.append((st[stat.ST_MTIME], st.st_size))
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36725
diff changeset
  1430
            maxmtime = max(maxmtime, st[stat.ST_MTIME])
26219
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1431
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1432
        return tuple(state), maxmtime
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1433
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1434
    def copy(self):
26240
2b1434e5eaa0 hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26219
diff changeset
  1435
        """Obtain a copy of this class instance.
2b1434e5eaa0 hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26219
diff changeset
  1436
2b1434e5eaa0 hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26219
diff changeset
  1437
        A new localrepository instance is obtained. The new instance should be
2b1434e5eaa0 hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26219
diff changeset
  1438
        completely independent of the original.
2b1434e5eaa0 hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26219
diff changeset
  1439
        """
2b1434e5eaa0 hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26219
diff changeset
  1440
        repo = repository(self._repo.baseui, self._repo.origroot)
28119
91a827e760df hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28020
diff changeset
  1441
        if self._filtername:
91a827e760df hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28020
diff changeset
  1442
            repo = repo.filtered(self._filtername)
91a827e760df hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28020
diff changeset
  1443
        else:
91a827e760df hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28020
diff changeset
  1444
            repo = repo.unfiltered()
26240
2b1434e5eaa0 hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26219
diff changeset
  1445
        c = cachedlocalrepo(repo)
26219
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1446
        c._state = self._state
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1447
        c.mtime = self.mtime
ae33fff17c1e hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26103
diff changeset
  1448
        return c