mercurial/hg.py
author Brodie Rao <brodie@bitheap.org>
Wed, 30 Mar 2011 20:03:05 -0700
changeset 13826 e574207e3bcd
parent 13824 ec1695350361
child 13897 375872fdadba
permissions -rw-r--r--
url: refactor util.drop_scheme() and hg.localpath() into url.localpath() This replaces util.drop_scheme() with url.localpath(), using url.url for parsing instead of doing it on its own. The function is moved from util to url to avoid an import cycle. hg.localpath() is removed in favor of using url.localpath(). This provides more consistent behavior between "hg clone" and other commands. To preserve backwards compatibility, URLs like bundle://../foo still refer to ../foo, not /foo. If a URL contains a scheme, percent-encoded entities are decoded. When there's no scheme, all characters are left untouched. Comparison of old and new behaviors: URL drop_scheme() hg.localpath() url.localpath() === ============= ============== =============== file://foo/foo /foo foo/foo /foo file://localhost:80/foo /foo localhost:80/foo /foo file://localhost:/foo /foo localhost:/foo /foo file://localhost/foo /foo /foo /foo file:///foo /foo /foo /foo file://foo (empty string) foo / file:/foo /foo /foo /foo file:foo foo foo foo file:foo%23bar foo%23bar foo%23bar foo#bar foo%23bar foo%23bar foo%23bar foo%23bar /foo /foo /foo /foo Windows-related paths on Windows: URL drop_scheme() hg.localpath() url.localpath() === ============= ============== =============== file:///C:/foo C:/C:/foo /C:/foo C:/foo file:///D:/foo C:/D:/foo /D:/foo D:/foo file://C:/foo C:/foo C:/foo C:/foo file://D:/foo C:/foo D:/foo D:/foo file:////foo/bar //foo/bar //foo/bar //foo/bar //foo/bar //foo/bar //foo/bar //foo/bar \\foo\bar //foo/bar //foo/bar \\foo\bar Windows-related paths on other platforms: file:///C:/foo C:/C:/foo /C:/foo C:/foo file:///D:/foo C:/D:/foo /D:/foo D:/foo file://C:/foo C:/foo C:/foo C:/foo file://D:/foo C:/foo D:/foo D:/foo file:////foo/bar //foo/bar //foo/bar //foo/bar //foo/bar //foo/bar //foo/bar //foo/bar \\foo\bar //foo/bar //foo/bar \\foo\bar For more information about file:// URL handling, see: http://www-archive.mozilla.org/quality/networking/testing/filetests.html Related issues: - issue1153: File URIs aren't handled correctly in windows This patch should preserve the fix implemented in 2770d03ae49f. However, it goes a step further and "promotes" Windows-style drive letters from being interpreted as host names to being part of the path. - issue2154: Cannot escape '#' in Mercurial URLs (#1172 in THG) The fragment is still interpreted as a revision or a branch, even in paths to bundles. However, when file: is used, percent-encoded entities are decoded, so file:test%23bundle.hg can refer to test#bundle.hg ond isk.
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
3891
6b4127c7d52a Simplify i18n imports
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
     9
from i18n import _
8109
496ae1ea4698 switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 7935
diff changeset
    10
from lock import release
12271
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
    11
from node import hex, nullid, nullrev, short
13604
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
    12
import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo, bookmarks
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
    13
import lock, util, extensions, error, encoding, node
12734
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12730
diff changeset
    14
import cmdutil, discovery, url
10651
5f091fc1bab7 style: use consistent variable names (*mod) with imports which would shadow
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10380
diff changeset
    15
import merge as mergemod
5f091fc1bab7 style: use consistent variable names (*mod) with imports which would shadow
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10380
diff changeset
    16
import verify as verifymod
8312
b87a50b7125c separate import lines from mercurial and general python modules
Simon Heimberg <simohe@besonet.ch>
parents: 8225
diff changeset
    17
import errno, os, shutil
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    18
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    19
def _local(path):
13826
e574207e3bcd url: refactor util.drop_scheme() and hg.localpath() into url.localpath()
Brodie Rao <brodie@bitheap.org>
parents: 13824
diff changeset
    20
    path = util.expandpath(url.localpath(path))
11154
17031fea4e95 expand paths to local repository or bundle in appropriate classes
Alexander Solovyov <piranha@piranha.org.ua>
parents: 10728
diff changeset
    21
    return (os.path.isfile(path) and bundlerepo or localrepo)
2469
2e91ba371c4c hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2431
diff changeset
    22
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
    23
def addbranchrevs(lrepo, repo, branches, revs):
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    24
    hashbranch, branches = branches
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    25
    if not hashbranch and not branches:
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
    26
        return revs or None, revs and revs[0] or None
10380
ee72d89c0d9f addbranchrevs: fallback for older servers
Sune Foldager <cryo@cyanite.org>
parents: 10379
diff changeset
    27
    revs = revs and list(revs) or []
ee72d89c0d9f addbranchrevs: fallback for older servers
Sune Foldager <cryo@cyanite.org>
parents: 10379
diff changeset
    28
    if not repo.capable('branchmap'):
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    29
        if branches:
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    30
            raise util.Abort(_("remote branch lookup not supported"))
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    31
        revs.append(hashbranch)
10380
ee72d89c0d9f addbranchrevs: fallback for older servers
Sune Foldager <cryo@cyanite.org>
parents: 10379
diff changeset
    32
        return revs, revs[0]
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
    33
    branchmap = repo.branchmap()
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    34
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
    35
    def primary(branch):
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
    36
        if branch == '.':
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
    37
            if not lrepo or not lrepo.local():
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
    38
                raise util.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
    39
            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
    40
        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
    41
            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
    42
            return True
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
    43
        else:
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    44
            return False
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    45
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    46
    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
    47
        if not primary(branch):
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    48
            raise error.RepoLookupError(_("unknown branch '%s'") % branch)
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    49
    if hashbranch:
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
    50
        if not primary(hashbranch):
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    51
            revs.append(hashbranch)
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
    52
    return revs, revs[0]
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
    53
13824
ec1695350361 hg: use url.url to parse branch names in parseurl()
Brodie Rao <brodie@bitheap.org>
parents: 13823
diff changeset
    54
def parseurl(path, branches=None):
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
    55
    '''parse url#branch, returning (url, (branch, branches))'''
5177
92236732d5a1 move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 4917
diff changeset
    56
13824
ec1695350361 hg: use url.url to parse branch names in parseurl()
Brodie Rao <brodie@bitheap.org>
parents: 13823
diff changeset
    57
    u = url.url(path)
ec1695350361 hg: use url.url to parse branch names in parseurl()
Brodie Rao <brodie@bitheap.org>
parents: 13823
diff changeset
    58
    if not u.fragment:
ec1695350361 hg: use url.url to parse branch names in parseurl()
Brodie Rao <brodie@bitheap.org>
parents: 13823
diff changeset
    59
        return path, (None, branches or [])
ec1695350361 hg: use url.url to parse branch names in parseurl()
Brodie Rao <brodie@bitheap.org>
parents: 13823
diff changeset
    60
    branch = u.fragment
ec1695350361 hg: use url.url to parse branch names in parseurl()
Brodie Rao <brodie@bitheap.org>
parents: 13823
diff changeset
    61
    u.fragment = None
ec1695350361 hg: use url.url to parse branch names in parseurl()
Brodie Rao <brodie@bitheap.org>
parents: 13823
diff changeset
    62
    return str(u), (branch, branches or [])
5177
92236732d5a1 move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 4917
diff changeset
    63
2472
e6ec81a8feea make repo scheme table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2431
diff changeset
    64
schemes = {
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    65
    'bundle': bundlerepo,
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    66
    'file': _local,
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    67
    'http': httprepo,
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    68
    'https': httprepo,
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    69
    'ssh': sshrepo,
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    70
    'static-http': statichttprepo,
4853
bf10a03a6b24 Removed deprecated hg:// and old-http:// protocols (issue406)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4818
diff changeset
    71
}
2469
2e91ba371c4c hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2431
diff changeset
    72
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    73
def _lookup(path):
13823
ad179644750f hg: look up schemes using url.url
Brodie Rao <brodie@bitheap.org>
parents: 13795
diff changeset
    74
    u = url.url(path)
ad179644750f hg: look up schemes using url.url
Brodie Rao <brodie@bitheap.org>
parents: 13795
diff changeset
    75
    scheme = u.scheme or 'file'
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    76
    thing = schemes.get(scheme) or schemes['file']
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    77
    try:
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    78
        return thing(path)
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    79
    except TypeError:
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    80
        return thing
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
    81
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
    82
def islocal(repo):
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
    83
    '''return true if repo or path is local'''
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
    84
    if isinstance(repo, str):
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    85
        try:
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    86
            return _lookup(repo).islocal(repo)
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    87
        except AttributeError:
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    88
            return False
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
    89
    return repo.local()
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
    90
3195
705e30c0a230 Make hg.repository work with no path argument
Brendan Cully <brendan@kublai.com>
parents: 3072
diff changeset
    91
def repository(ui, path='', create=False):
2774
8cd3e19bf4a5 Add a doc string
Matt Mackall <mpm@selenic.com>
parents: 2768
diff changeset
    92
    """return a repository object for the specified path"""
2847
2ff57e3113a4 call reposetup functions of extension modules whenever repo created
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2830
diff changeset
    93
    repo = _lookup(path).instance(ui, path, create)
4074
0f9381cf9723 Try to pass repo.ui to reposetup hooks
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3869
diff changeset
    94
    ui = getattr(repo, "ui", ui)
5192
60acf1432ee0 Move cmdtable and reposetup handling out of extensions.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5187
diff changeset
    95
    for name, module in extensions.extensions():
60acf1432ee0 Move cmdtable and reposetup handling out of extensions.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5187
diff changeset
    96
        hook = getattr(module, 'reposetup', None)
60acf1432ee0 Move cmdtable and reposetup handling out of extensions.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5187
diff changeset
    97
        if hook:
60acf1432ee0 Move cmdtable and reposetup handling out of extensions.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5187
diff changeset
    98
            hook(ui, repo)
2847
2ff57e3113a4 call reposetup functions of extension modules whenever repo created
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2830
diff changeset
    99
    return repo
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   100
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   101
def defaultdest(source):
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   102
    '''return default destination of clone if none is given'''
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   103
    return os.path.basename(os.path.normpath(source))
2774
8cd3e19bf4a5 Add a doc string
Matt Mackall <mpm@selenic.com>
parents: 2768
diff changeset
   104
8807
8bf6eb68ddaf share: allow dest to default to the basename of source
Matt Mackall <mpm@selenic.com>
parents: 8800
diff changeset
   105
def share(ui, source, dest=None, update=True):
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   106
    '''create a shared repository'''
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   107
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   108
    if not islocal(source):
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   109
        raise util.Abort(_('can only share local repositories'))
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   110
8807
8bf6eb68ddaf share: allow dest to default to the basename of source
Matt Mackall <mpm@selenic.com>
parents: 8800
diff changeset
   111
    if not dest:
10099
f5e46dfb38c7 share: use defaultdest to compute unspecified destination
Brendan Cully <brendan@kublai.com>
parents: 9984
diff changeset
   112
        dest = defaultdest(source)
9344
eb6af02307ec Merge with i18n-stable
Matt Mackall <mpm@selenic.com>
parents: 9245
diff changeset
   113
    else:
eb6af02307ec Merge with i18n-stable
Matt Mackall <mpm@selenic.com>
parents: 9245
diff changeset
   114
        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
   115
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   116
    if isinstance(source, str):
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   117
        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
   118
        source, branches = parseurl(origsource)
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   119
        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
   120
        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
   121
    else:
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   122
        srcrepo = source
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   123
        origsource = source = srcrepo.url()
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   124
        checkout = None
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   125
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   126
    sharedpath = srcrepo.sharedpath # if our source is already sharing
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   127
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   128
    root = os.path.realpath(dest)
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   129
    roothg = os.path.join(root, '.hg')
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   130
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   131
    if os.path.exists(roothg):
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   132
        raise util.Abort(_('destination already exists'))
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   133
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   134
    if not os.path.isdir(root):
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   135
        os.mkdir(root)
13795
43b5fe18ea6c set NOT_CONTENT_INDEXED on .hg dir (issue2694)
Adrian Buehlmann <adrian@cadifra.com>
parents: 13742
diff changeset
   136
    util.makedir(roothg, notindexed=True)
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   137
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   138
    requirements = ''
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   139
    try:
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   140
        requirements = srcrepo.opener('requires').read()
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   141
    except IOError, inst:
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   142
        if inst.errno != errno.ENOENT:
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   143
            raise
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   144
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   145
    requirements += 'shared\n'
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   146
    file(os.path.join(roothg, 'requires'), 'w').write(requirements)
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   147
    file(os.path.join(roothg, 'sharedpath'), 'w').write(sharedpath)
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   148
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   149
    default = srcrepo.ui.config('paths', 'default')
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   150
    if default:
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   151
        f = file(os.path.join(roothg, 'hgrc'), 'w')
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   152
        f.write('[paths]\ndefault = %s\n' % default)
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   153
        f.close()
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   154
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   155
    r = repository(ui, root)
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   156
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   157
    if update:
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   158
        r.ui.status(_("updating working directory\n"))
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   159
        if update is not True:
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   160
            checkout = update
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   161
        for test in (checkout, 'default', 'tip'):
9423
1444a42f6052 Make distinct lookup error for localrepo.lookup
Matt Mackall <mpm@selenic.com>
parents: 9344
diff changeset
   162
            if test is None:
1444a42f6052 Make distinct lookup error for localrepo.lookup
Matt Mackall <mpm@selenic.com>
parents: 9344
diff changeset
   163
                continue
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   164
            try:
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   165
                uprev = r.lookup(test)
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   166
                break
9423
1444a42f6052 Make distinct lookup error for localrepo.lookup
Matt Mackall <mpm@selenic.com>
parents: 9344
diff changeset
   167
            except error.RepoLookupError:
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   168
                continue
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   169
        _update(r, uprev)
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
   170
2613
479e26afa10f clone: do not make streaming default. add --stream option instead.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
   171
def clone(ui, source, dest=None, pull=False, rev=None, update=True,
10379
a78bfaf988e1 add -b/--branch option to clone, bundle, incoming, outgoing, pull, push
Sune Foldager <cryo@cyanite.org>
parents: 10365
diff changeset
   172
          stream=False, branch=None):
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   173
    """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
   174
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   175
    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
   176
    source and destination are URLs, as passed to the repository
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   177
    function.  Returns a pair of repository objects, the source and
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   178
    newly created destination.
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   179
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   180
    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
   181
    .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
   182
    pushes.
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   183
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   184
    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
   185
    repository will be deleted.
2600
c4325f0a9b91 clean up trailing white space.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2597
diff changeset
   186
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   187
    Arguments:
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   188
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   189
    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
   190
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   191
    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
   192
    name of source repository)
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   193
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   194
    pull: always pull from source repository, even in local case
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   195
2621
5a5852a417b1 clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2613
diff changeset
   196
    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
   197
    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
   198
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   199
    rev: revision to clone up to (implies pull=True)
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   200
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   201
    update: update working directory after clone completes, if
6526
cfeeac24fc1e repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents: 6525
diff changeset
   202
    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
   203
    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
   204
a78bfaf988e1 add -b/--branch option to clone, bundle, incoming, outgoing, pull, push
Sune Foldager <cryo@cyanite.org>
parents: 10365
diff changeset
   205
    branch: branches to clone
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   206
    """
4478
b2b55acbacdd Add support for url#id syntax
Matt Mackall <mpm@selenic.com>
parents: 4477
diff changeset
   207
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   208
    if isinstance(source, str):
6089
28054773438c clone: make things work when source is a repo object
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 6088
diff changeset
   209
        origsource = ui.expandpath(source)
10379
a78bfaf988e1 add -b/--branch option to clone, bundle, incoming, outgoing, pull, push
Sune Foldager <cryo@cyanite.org>
parents: 10365
diff changeset
   210
        source, branch = parseurl(origsource, branch)
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   211
        src_repo = repository(ui, source)
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   212
    else:
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   213
        src_repo = source
11818
b1ae33b813cb hg.clone: do not ignore branch argument when source is a repo object
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11544
diff changeset
   214
        branch = (None, branch or [])
6089
28054773438c clone: make things work when source is a repo object
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 6088
diff changeset
   215
        origsource = source = src_repo.url()
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
   216
    rev, checkout = addbranchrevs(src_repo, src_repo, branch, rev)
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   217
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   218
    if dest is None:
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   219
        dest = defaultdest(source)
3841
aaeb7f5d1052 Show the destionation for clone if not specified manually.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3791
diff changeset
   220
        ui.status(_("destination directory: %s\n") % dest)
9344
eb6af02307ec Merge with i18n-stable
Matt Mackall <mpm@selenic.com>
parents: 9245
diff changeset
   221
    else:
eb6af02307ec Merge with i18n-stable
Matt Mackall <mpm@selenic.com>
parents: 9245
diff changeset
   222
        dest = ui.expandpath(dest)
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   223
13826
e574207e3bcd url: refactor util.drop_scheme() and hg.localpath() into url.localpath()
Brodie Rao <brodie@bitheap.org>
parents: 13824
diff changeset
   224
    dest = url.localpath(dest)
e574207e3bcd url: refactor util.drop_scheme() and hg.localpath() into url.localpath()
Brodie Rao <brodie@bitheap.org>
parents: 13824
diff changeset
   225
    source = url.localpath(source)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   226
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   227
    if os.path.exists(dest):
7927
a218ba5f60df allow clone into existing but empty directories
Steve Borho <steve@borho.org>
parents: 7821
diff changeset
   228
        if not os.path.isdir(dest):
a218ba5f60df allow clone into existing but empty directories
Steve Borho <steve@borho.org>
parents: 7821
diff changeset
   229
            raise util.Abort(_("destination '%s' already exists") % dest)
a218ba5f60df allow clone into existing but empty directories
Steve Borho <steve@borho.org>
parents: 7821
diff changeset
   230
        elif os.listdir(dest):
a218ba5f60df allow clone into existing but empty directories
Steve Borho <steve@borho.org>
parents: 7821
diff changeset
   231
            raise util.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
   232
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   233
    class DirCleanup(object):
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   234
        def __init__(self, dir_):
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   235
            self.rmtree = shutil.rmtree
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   236
            self.dir_ = dir_
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   237
        def close(self):
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   238
            self.dir_ = None
8110
b616f328af9f switch dircleanup in mercurial.hg.clone from gc based to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 8109
diff changeset
   239
        def cleanup(self):
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   240
            if self.dir_:
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   241
                self.rmtree(self.dir_, True)
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   242
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   243
    src_lock = dest_lock = dir_cleanup = None
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   244
    try:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   245
        if islocal(dest):
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   246
            dir_cleanup = DirCleanup(dest)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   247
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   248
        abspath = origsource
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   249
        copy = False
6315
5c96a4bca66b clone: use cancopy
Matt Mackall <mpm@selenic.com>
parents: 6217
diff changeset
   250
        if src_repo.cancopy() and islocal(dest):
13826
e574207e3bcd url: refactor util.drop_scheme() and hg.localpath() into url.localpath()
Brodie Rao <brodie@bitheap.org>
parents: 13824
diff changeset
   251
            abspath = os.path.abspath(url.localpath(origsource))
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   252
            copy = not pull and not rev
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   253
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   254
        if copy:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   255
            try:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   256
                # 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
   257
                # 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
   258
                # 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
   259
                # fail
8649
2c097e22492c clone: fall back to pull source repo cannot be locked, 937ee88da3ef was a noop
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8417
diff changeset
   260
                src_lock = src_repo.lock(wait=False)
7640
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7546
diff changeset
   261
            except error.LockError:
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   262
                copy = False
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   263
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   264
        if copy:
8907
e9ef409e6399 Add (pre)outgoing hooks for local clones.
Fred Wulff <frew@cs.stanford.edu>
parents: 8814
diff changeset
   265
            src_repo.hook('preoutgoing', throw=True, source='clone')
7935
39566bb99a9c on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents: 7927
diff changeset
   266
            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
   267
            if not os.path.exists(dest):
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   268
                os.mkdir(dest)
7935
39566bb99a9c on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents: 7927
diff changeset
   269
            else:
39566bb99a9c on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents: 7927
diff changeset
   270
                # only clean up directories we create ourselves
39566bb99a9c on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents: 7927
diff changeset
   271
                dir_cleanup.dir_ = hgdir
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   272
            try:
7935
39566bb99a9c on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents: 7927
diff changeset
   273
                dest_path = hgdir
13795
43b5fe18ea6c set NOT_CONTENT_INDEXED on .hg dir (issue2694)
Adrian Buehlmann <adrian@cadifra.com>
parents: 13742
diff changeset
   274
                util.makedir(dest_path, notindexed=True)
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   275
            except OSError, inst:
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   276
                if inst.errno == errno.EEXIST:
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   277
                    dir_cleanup.close()
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   278
                    raise util.Abort(_("destination '%s' already exists")
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   279
                                     % dest)
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   280
                raise
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   281
11255
e4dbaa40096d clone: save hardlink state of util.copyfiles()
Adrian Buehlmann <adrian@cadifra.com>
parents: 11154
diff changeset
   282
            hardlink = None
11251
c61442f6d106 clone: print number of linked/copied files on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents: 11233
diff changeset
   283
            num = 0
6903
0642d9d7ec80 clone: get a list of files to clone from store
Matt Mackall <mpm@selenic.com>
parents: 6526
diff changeset
   284
            for f in src_repo.store.copylist():
9984
439d7ea6fe3a share: fix interaction with clone
Matt Mackall <mpm@selenic.com>
parents: 9788
diff changeset
   285
                src = os.path.join(src_repo.sharedpath, f)
6944
7e5f3480c45b fix regression on empty repo cloning introduced by 0642d9d7ec80
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6903
diff changeset
   286
                dst = os.path.join(dest_path, f)
7e5f3480c45b fix regression on empty repo cloning introduced by 0642d9d7ec80
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6903
diff changeset
   287
                dstbase = os.path.dirname(dst)
7e5f3480c45b fix regression on empty repo cloning introduced by 0642d9d7ec80
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6903
diff changeset
   288
                if dstbase and not os.path.exists(dstbase):
7e5f3480c45b fix regression on empty repo cloning introduced by 0642d9d7ec80
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6903
diff changeset
   289
                    os.mkdir(dstbase)
6903
0642d9d7ec80 clone: get a list of files to clone from store
Matt Mackall <mpm@selenic.com>
parents: 6526
diff changeset
   290
                if os.path.exists(src):
0642d9d7ec80 clone: get a list of files to clone from store
Matt Mackall <mpm@selenic.com>
parents: 6526
diff changeset
   291
                    if dst.endswith('data'):
0642d9d7ec80 clone: get a list of files to clone from store
Matt Mackall <mpm@selenic.com>
parents: 6526
diff changeset
   292
                        # lock to avoid premature writing to the target
0642d9d7ec80 clone: get a list of files to clone from store
Matt Mackall <mpm@selenic.com>
parents: 6526
diff changeset
   293
                        dest_lock = lock.lock(os.path.join(dstbase, "lock"))
11251
c61442f6d106 clone: print number of linked/copied files on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents: 11233
diff changeset
   294
                    hardlink, n = util.copyfiles(src, dst, hardlink)
c61442f6d106 clone: print number of linked/copied files on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents: 11233
diff changeset
   295
                    num += n
c61442f6d106 clone: print number of linked/copied files on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents: 11233
diff changeset
   296
            if hardlink:
c61442f6d106 clone: print number of linked/copied files on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents: 11233
diff changeset
   297
                ui.debug("linked %d files\n" % num)
c61442f6d106 clone: print number of linked/copied files on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents: 11233
diff changeset
   298
            else:
c61442f6d106 clone: print number of linked/copied files on --debug
Adrian Buehlmann <adrian@cadifra.com>
parents: 11233
diff changeset
   299
                ui.debug("copied %d files\n" % num)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   300
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   301
            # 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
   302
            # into it
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   303
            dest_repo = repository(ui, dest)
12144
be9c4131a8f4 clone, patch, convert: use hex(nullid) instead of '0'*40
Martin Geisler <mg@lazybytes.net>
parents: 11818
diff changeset
   304
            src_repo.hook('outgoing', source='clone',
be9c4131a8f4 clone, patch, convert: use hex(nullid) instead of '0'*40
Martin Geisler <mg@lazybytes.net>
parents: 11818
diff changeset
   305
                          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
   306
        else:
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   307
            try:
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   308
                dest_repo = repository(ui, dest, create=True)
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   309
            except OSError, inst:
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   310
                if inst.errno == errno.EEXIST:
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   311
                    dir_cleanup.close()
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   312
                    raise util.Abort(_("destination '%s' already exists")
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   313
                                     % dest)
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
   314
                raise
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   315
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   316
            revs = None
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   317
            if rev:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   318
                if 'lookup' not in src_repo.capabilities:
9171
a458b9bf4f3a hg: better wrapping of string literal
Martin Geisler <mg@lazybytes.net>
parents: 8907
diff changeset
   319
                    raise util.Abort(_("src repository does not support "
a458b9bf4f3a hg: better wrapping of string literal
Martin Geisler <mg@lazybytes.net>
parents: 8907
diff changeset
   320
                                       "revision lookup and so doesn't "
a458b9bf4f3a hg: better wrapping of string literal
Martin Geisler <mg@lazybytes.net>
parents: 8907
diff changeset
   321
                                       "support clone by revision"))
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   322
                revs = [src_repo.lookup(r) for r in rev]
8417
39cf453da958 clone: try updating to the actual changeset specified in options
Brett Carter <brett@rdnzl.net>
parents: 8312
diff changeset
   323
                checkout = revs[0]
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   324
            if dest_repo.local():
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   325
                dest_repo.clone(src_repo, heads=revs, stream=stream)
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   326
            elif src_repo.local():
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   327
                src_repo.push(dest_repo, revs=revs)
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   328
            else:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   329
                raise util.Abort(_("clone from remote to remote not supported"))
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   330
5186
0d5d03844927 merge with -stable
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 4917 5185
diff changeset
   331
        if dir_cleanup:
0d5d03844927 merge with -stable
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 4917 5185
diff changeset
   332
            dir_cleanup.close()
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   333
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   334
        if dest_repo.local():
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   335
            fp = dest_repo.opener("hgrc", "w", text=True)
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   336
            fp.write("[paths]\n")
8179
0f3b8404051b clone: config escaping no longer needed
Matt Mackall <mpm@selenic.com>
parents: 8174
diff changeset
   337
            fp.write("default = %s\n" % abspath)
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   338
            fp.close()
5185
156f4c8a12aa clone: do not delete the target if only the update fails
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 4635
diff changeset
   339
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8807
diff changeset
   340
            dest_repo.ui.setconfig('paths', 'default', abspath)
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8807
diff changeset
   341
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   342
            if update:
6526
cfeeac24fc1e repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents: 6525
diff changeset
   343
                if update is not True:
cfeeac24fc1e repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents: 6525
diff changeset
   344
                    checkout = update
9714
2f1ab7f77ddc clone: add option -u/--updaterev
Adrian Buehlmann <adrian@cadifra.com>
parents: 9611
diff changeset
   345
                    if src_repo.local():
2f1ab7f77ddc clone: add option -u/--updaterev
Adrian Buehlmann <adrian@cadifra.com>
parents: 9611
diff changeset
   346
                        checkout = src_repo.lookup(update)
7045
f82938c87b92 clone: honor -r even when pulling named branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7044
diff changeset
   347
                for test in (checkout, 'default', 'tip'):
9423
1444a42f6052 Make distinct lookup error for localrepo.lookup
Matt Mackall <mpm@selenic.com>
parents: 9344
diff changeset
   348
                    if test is None:
1444a42f6052 Make distinct lookup error for localrepo.lookup
Matt Mackall <mpm@selenic.com>
parents: 9344
diff changeset
   349
                        continue
5248
5517aa5aafb0 Merge with crew-stable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5192 5225
diff changeset
   350
                    try:
7045
f82938c87b92 clone: honor -r even when pulling named branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7044
diff changeset
   351
                        uprev = dest_repo.lookup(test)
f82938c87b92 clone: honor -r even when pulling named branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7044
diff changeset
   352
                        break
9423
1444a42f6052 Make distinct lookup error for localrepo.lookup
Matt Mackall <mpm@selenic.com>
parents: 9344
diff changeset
   353
                    except error.RepoLookupError:
7045
f82938c87b92 clone: honor -r even when pulling named branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7044
diff changeset
   354
                        continue
9611
a3d73b3e1f8a hg.clone: report branch name on update
Adrian Buehlmann <adrian@cadifra.com>
parents: 9468
diff changeset
   355
                bn = dest_repo[uprev].branch()
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
   356
                dest_repo.ui.status(_("updating to branch %s\n") % bn)
7045
f82938c87b92 clone: honor -r even when pulling named branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7044
diff changeset
   357
                _update(dest_repo, uprev)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   358
13604
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
   359
        # clone all bookmarks
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
   360
        if dest_repo.local() and src_repo.capable("pushkey"):
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
   361
            rb = src_repo.listkeys('bookmarks')
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
   362
            for k, n in rb.iteritems():
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
   363
                try:
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
   364
                    m = dest_repo.lookup(n)
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
   365
                    dest_repo._bookmarks[k] = m
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
   366
                except:
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
   367
                    pass
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
   368
            if rb:
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
   369
                bookmarks.write(dest_repo)
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
   370
        elif src_repo.local() and dest_repo.capable("pushkey"):
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
   371
            for k, n in src_repo._bookmarks.iteritems():
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
   372
                dest_repo.pushkey('bookmarks', k, '', hex(n))
3f6a4579f803 hg: add support for cloning bookmarks
David Soria Parra <dsp@php.net>
parents: 13315
diff changeset
   373
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   374
        return src_repo, dest_repo
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
   375
    finally:
8109
496ae1ea4698 switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 7935
diff changeset
   376
        release(src_lock, dest_lock)
8110
b616f328af9f switch dircleanup in mercurial.hg.clone from gc based to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 8109
diff changeset
   377
        if dir_cleanup is not None:
b616f328af9f switch dircleanup in mercurial.hg.clone from gc based to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 8109
diff changeset
   378
            dir_cleanup.cleanup()
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
   379
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   380
def _showstats(repo, stats):
9454
dafadd7ff07e hg: avoid combining translated strings
Martin Geisler <mg@lazybytes.net>
parents: 9425
diff changeset
   381
    repo.ui.status(_("%d files updated, %d files merged, "
dafadd7ff07e hg: avoid combining translated strings
Martin Geisler <mg@lazybytes.net>
parents: 9425
diff changeset
   382
                     "%d files removed, %d files unresolved\n") % stats)
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   383
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
   384
def update(repo, node):
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
   385
    """update the working directory to node, merging linear changes"""
10651
5f091fc1bab7 style: use consistent variable names (*mod) with imports which would shadow
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10380
diff changeset
   386
    stats = mergemod.update(repo, node, False, False, None)
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   387
    _showstats(repo, stats)
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   388
    if stats[3]:
6518
92ccccb55ba3 resolve: new command
Matt Mackall <mpm@selenic.com>
parents: 6338
diff changeset
   389
        repo.ui.status(_("use 'hg resolve' to retry unresolved file merges\n"))
5635
0c608a8d9c5f merge: make return codes more sensible
Matt Mackall <mpm@selenic.com>
parents: 5569
diff changeset
   390
    return stats[3] > 0
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
   391
7546
c7f48414f3ad add a comment about the need of hg._update()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7280
diff changeset
   392
# 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
   393
_update = update
c7f48414f3ad add a comment about the need of hg._update()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7280
diff changeset
   394
4917
126f527b3ba3 Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents: 4915
diff changeset
   395
def clean(repo, node, show_stats=True):
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
   396
    """forcibly switch the working directory to node, clobbering changes"""
10651
5f091fc1bab7 style: use consistent variable names (*mod) with imports which would shadow
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10380
diff changeset
   397
    stats = mergemod.update(repo, node, False, True, None)
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   398
    if show_stats:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   399
        _showstats(repo, stats)
5635
0c608a8d9c5f merge: make return codes more sensible
Matt Mackall <mpm@selenic.com>
parents: 5569
diff changeset
   400
    return stats[3] > 0
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
   401
4917
126f527b3ba3 Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents: 4915
diff changeset
   402
def merge(repo, node, force=None, remind=True):
13162
115a9760c382 merge: document some internal return values.
Greg Ward <greg-hg@gerg.ca>
parents: 13047
diff changeset
   403
    """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
   404
    unresolved conflicts."""
10651
5f091fc1bab7 style: use consistent variable names (*mod) with imports which would shadow
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10380
diff changeset
   405
    stats = mergemod.update(repo, node, True, force, False)
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   406
    _showstats(repo, stats)
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   407
    if stats[3]:
7821
9fe7e6acf525 merge: better error messages to lead users to hg update --clean to abandon merges.
Augie Fackler <durin42@gmail.com>
parents: 7640
diff changeset
   408
        repo.ui.status(_("use 'hg resolve' to retry unresolved file merges "
12314
f2daa6ab514a merge: suggest 'hg up -C .' for discarding changes, not 'hg up -C'
Brodie Rao <brodie@bitheap.org>
parents: 12273
diff changeset
   409
                         "or 'hg update -C .' to abandon\n"))
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   410
    elif remind:
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   411
        repo.ui.status(_("(branch merge, don't forget to commit)\n"))
5635
0c608a8d9c5f merge: make return codes more sensible
Matt Mackall <mpm@selenic.com>
parents: 5569
diff changeset
   412
    return stats[3] > 0
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
   413
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   414
def _incoming(displaychlist, subreporecurse, ui, repo, source,
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   415
        opts, buffered=False):
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   416
    """
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   417
    Helper for incoming / gincoming.
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   418
    displaychlist gets called with
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   419
        (remoterepo, incomingchangesetlist, displayer) parameters,
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   420
    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
   421
    """
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   422
    source, branches = parseurl(ui.expandpath(source), opts.get('branch'))
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   423
    other = repository(remoteui(repo, opts), source)
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   424
    ui.status(_('comparing with %s\n') % url.hidepassword(source))
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   425
    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
   426
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   427
    if revs:
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   428
        revs = [other.lookup(rev) for rev in revs]
13742
7abab875e647 discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 13694
diff changeset
   429
    usecommon = other.capable('getbundle')
7abab875e647 discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 13694
diff changeset
   430
    other, common, incoming, bundle = bundlerepo.getremotechanges(ui, repo, other,
7abab875e647 discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 13694
diff changeset
   431
                                       revs, opts["bundle"], opts["force"],
7abab875e647 discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 13694
diff changeset
   432
                                       usecommon=usecommon)
7abab875e647 discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 13694
diff changeset
   433
    if not incoming:
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   434
        ui.status(_("no changes found\n"))
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   435
        return subreporecurse()
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   436
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   437
    try:
13742
7abab875e647 discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 13694
diff changeset
   438
        if usecommon:
7abab875e647 discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 13694
diff changeset
   439
            chlist = other.changelog.findmissing(common, revs)
7abab875e647 discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 13694
diff changeset
   440
        else:
7abab875e647 discovery: avoid discovery when local graph is a subset of remote
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 13694
diff changeset
   441
            chlist = other.changelog.nodesbetween(incoming, revs)[0]
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   442
        displayer = cmdutil.show_changeset(ui, other, opts, buffered)
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   443
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   444
        # XXX once graphlog extension makes it into core,
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   445
        # should be replaced by a if graph/else
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   446
        displaychlist(other, chlist, displayer)
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   447
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   448
        displayer.close()
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   449
    finally:
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   450
        if hasattr(other, 'close'):
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   451
            other.close()
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   452
        if bundle:
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   453
            os.unlink(bundle)
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   454
    subreporecurse()
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   455
    return 0 # exit code is zero since we found incoming changes
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   456
12273
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
   457
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
   458
    def subreporecurse():
12400
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   459
        ret = 1
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   460
        if opts.get('subrepos'):
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   461
            ctx = repo[None]
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   462
            for subpath in sorted(ctx.substate):
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   463
                sub = ctx.sub(subpath)
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   464
                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
   465
        return ret
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   466
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   467
    def display(other, chlist, displayer):
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   468
        limit = cmdutil.loglimit(opts)
12273
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
   469
        if opts.get('newest_first'):
12729
55f0648c7e2d incoming: rename variable
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12400
diff changeset
   470
            chlist.reverse()
12273
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
   471
        count = 0
12729
55f0648c7e2d incoming: rename variable
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12400
diff changeset
   472
        for n in chlist:
12273
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
   473
            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
   474
                break
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
   475
            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
   476
            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
   477
                continue
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
   478
            count += 1
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
   479
            displayer.show(other[n])
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
   480
    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
   481
12735
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   482
def _outgoing(ui, repo, dest, opts):
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   483
    dest = ui.expandpath(dest or 'default-push', dest or 'default')
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   484
    dest, branches = parseurl(dest, opts.get('branch'))
13693
adf3c4401c5d push/outgoing: print remote target path even if there's an error (issue2561)
Miloš Hadžić <milos.hadzic@gmail.com>
parents: 13315
diff changeset
   485
    ui.status(_('comparing with %s\n') % url.hidepassword(dest))
12735
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   486
    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
   487
    if revs:
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   488
        revs = [repo.lookup(rev) for rev in revs]
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   489
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   490
    other = repository(remoteui(repo, opts), dest)
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   491
    o = discovery.findoutgoing(repo, other, force=opts.get('force'))
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   492
    if not o:
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   493
        ui.status(_("no changes found\n"))
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   494
        return None
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   495
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   496
    return repo.changelog.nodesbetween(o, revs)[0]
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   497
12271
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
   498
def outgoing(ui, repo, dest, opts):
12400
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   499
    def recurse():
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   500
        ret = 1
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   501
        if opts.get('subrepos'):
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   502
            ctx = repo[None]
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   503
            for subpath in sorted(ctx.substate):
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   504
                sub = ctx.sub(subpath)
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   505
                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
   506
        return ret
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   507
12271
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
   508
    limit = cmdutil.loglimit(opts)
12735
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   509
    o = _outgoing(ui, repo, dest, opts)
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
   510
    if o is None:
12400
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   511
        return recurse()
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   512
12271
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
   513
    if opts.get('newest_first'):
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
   514
        o.reverse()
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
   515
    displayer = cmdutil.show_changeset(ui, repo, opts)
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
   516
    count = 0
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
   517
    for n in o:
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
   518
        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
   519
            break
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
   520
        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
   521
        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
   522
            continue
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
   523
        count += 1
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
   524
        displayer.show(repo[n])
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
   525
    displayer.close()
12400
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   526
    recurse()
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
   527
    return 0 # exit code is zero since we found outgoing changes
12271
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
   528
4917
126f527b3ba3 Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents: 4915
diff changeset
   529
def revert(repo, node, choose):
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
   530
    """revert changes to revision in node without updating dirstate"""
10651
5f091fc1bab7 style: use consistent variable names (*mod) with imports which would shadow
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10380
diff changeset
   531
    return mergemod.update(repo, node, False, True, choose)[3] > 0
2778
fdc232d8a193 Move repo.verify
Matt Mackall <mpm@selenic.com>
parents: 2775
diff changeset
   532
fdc232d8a193 Move repo.verify
Matt Mackall <mpm@selenic.com>
parents: 2775
diff changeset
   533
def verify(repo):
fdc232d8a193 Move repo.verify
Matt Mackall <mpm@selenic.com>
parents: 2775
diff changeset
   534
    """verify the consistency of a repository"""
10651
5f091fc1bab7 style: use consistent variable names (*mod) with imports which would shadow
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10380
diff changeset
   535
    return verifymod.verify(repo)
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   536
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   537
def remoteui(src, opts):
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   538
    'build a remote ui from ui or repo and opts'
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   539
    if hasattr(src, 'baseui'): # looks like a repository
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   540
        dst = src.baseui.copy() # drop repo-specific config
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   541
        src = src.ui # copy target options from repo
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   542
    else: # assume it's a global ui object
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   543
        dst = src.copy() # keep all global options
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   544
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   545
    # copy ssh-specific options
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   546
    for o in 'ssh', 'remotecmd':
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   547
        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
   548
        if v:
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   549
            dst.setconfig("ui", o, v)
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   550
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   551
    # copy bundle-specific options
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   552
    r = src.config('bundle', 'mainreporoot')
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   553
    if r:
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   554
        dst.setconfig('bundle', 'mainreporoot', r)
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   555
13192
4d03707916d3 https: use web.cacerts configuration from local repo to validate remote repo
Mads Kiilerich <mads@kiilerich.com>
parents: 12735
diff changeset
   556
    # copy selected local settings to the remote ui
13314
8dc488dfcdb4 url: 'ssh known host'-like checking of fingerprints of HTTPS certificates
Mads Kiilerich <mads@kiilerich.com>
parents: 13231
diff changeset
   557
    for sect in ('auth', 'hostfingerprints', 'http_proxy'):
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   558
        for key, val in src.configitems(sect):
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   559
            dst.setconfig(sect, key, val)
13192
4d03707916d3 https: use web.cacerts configuration from local repo to validate remote repo
Mads Kiilerich <mads@kiilerich.com>
parents: 12735
diff changeset
   560
    v = src.config('web', 'cacerts')
4d03707916d3 https: use web.cacerts configuration from local repo to validate remote repo
Mads Kiilerich <mads@kiilerich.com>
parents: 12735
diff changeset
   561
    if v:
13231
b335882c2f21 url: expand path for web.cacerts
Eduard-Cristian Stefan <alexandrul.ct@gmail.com>
parents: 13192
diff changeset
   562
        dst.setconfig('web', 'cacerts', util.expandpath(v))
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   563
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
   564
    return dst