mercurial/hg.py
author Giorgos Keramidas <keramida@ceid.upatras.gr>
Wed, 13 Jun 2007 15:02:09 +0300
changeset 4568 9b3a818adae6
parent 4478 b2b55acbacdd
child 4635 63b9d2deed48
permissions -rw-r--r--
test-patchbomb: sed -e may not work with extended regexps Non-GNU versions of the sed(1) utility (i.e. on Solaris or BSD) may not support extended regexps (i.e. including \| branches), or may need a special option to enable it (like -E instead of -e). Expand the sed RE in tests/test-patchbomb to fix running this test on FreeBSD and Solaris.
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
#
2859
345bac2bc4ec update copyrights.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2847
diff changeset
     3
# Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
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
#
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     6
# This software may be used and distributed according to the terms
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     7
# of the GNU General Public License, incorporated herein by reference.
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     8
1089
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents: 1072
diff changeset
     9
from node import *
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents: 1072
diff changeset
    10
from repo import *
3891
6b4127c7d52a Simplify i18n imports
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
    11
from i18n import _
3877
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3869
diff changeset
    12
import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo
4478
b2b55acbacdd Add support for url#id syntax
Matt Mackall <mpm@selenic.com>
parents: 4477
diff changeset
    13
import errno, lock, os, shutil, util, cmdutil
3877
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3869
diff changeset
    14
import merge as _merge
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3869
diff changeset
    15
import verify as _verify
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    16
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    17
def _local(path):
3195
705e30c0a230 Make hg.repository work with no path argument
Brendan Cully <brendan@kublai.com>
parents: 3072
diff changeset
    18
    return (os.path.isfile(util.drop_scheme('file', path)) and
2768
b1b1aa6f275c allow None for path of hg.repository
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2740
diff changeset
    19
            bundlerepo or localrepo)
2469
2e91ba371c4c hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2431
diff changeset
    20
2472
e6ec81a8feea make repo scheme table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2431
diff changeset
    21
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
    22
    '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
    23
    '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
    24
    'hg': httprepo,
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    25
    '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
    26
    '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
    27
    'old-http': statichttprepo,
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    28
    '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
    29
    'static-http': statichttprepo,
2469
2e91ba371c4c hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2431
diff changeset
    30
    }
2e91ba371c4c hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2431
diff changeset
    31
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    32
def _lookup(path):
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    33
    scheme = 'file'
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    34
    if path:
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    35
        c = path.find(':')
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    36
        if c > 0:
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    37
            scheme = path[:c]
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    38
    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
    39
    try:
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    40
        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
    41
    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
    42
        return thing
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
    43
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
    44
def islocal(repo):
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
    45
    '''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
    46
    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
    47
        try:
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
    48
            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
    49
        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
    50
            return False
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
    51
    return repo.local()
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
    52
2847
2ff57e3113a4 call reposetup functions of extension modules whenever repo created
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2830
diff changeset
    53
repo_setup_hooks = []
2ff57e3113a4 call reposetup functions of extension modules whenever repo created
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2830
diff changeset
    54
3195
705e30c0a230 Make hg.repository work with no path argument
Brendan Cully <brendan@kublai.com>
parents: 3072
diff changeset
    55
def repository(ui, path='', create=False):
2774
8cd3e19bf4a5 Add a doc string
Matt Mackall <mpm@selenic.com>
parents: 2768
diff changeset
    56
    """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
    57
    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
    58
    ui = getattr(repo, "ui", ui)
2847
2ff57e3113a4 call reposetup functions of extension modules whenever repo created
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2830
diff changeset
    59
    for hook in repo_setup_hooks:
2ff57e3113a4 call reposetup functions of extension modules whenever repo created
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2830
diff changeset
    60
        hook(ui, repo)
2ff57e3113a4 call reposetup functions of extension modules whenever repo created
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2830
diff changeset
    61
    return repo
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
    62
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
    63
def defaultdest(source):
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
    64
    '''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
    65
    return os.path.basename(os.path.normpath(source))
2774
8cd3e19bf4a5 Add a doc string
Matt Mackall <mpm@selenic.com>
parents: 2768
diff changeset
    66
2613
479e26afa10f clone: do not make streaming default. add --stream option instead.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
    67
def clone(ui, source, dest=None, pull=False, rev=None, update=True,
479e26afa10f clone: do not make streaming default. add --stream option instead.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
    68
          stream=False):
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
    69
    """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
    70
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
    71
    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
    72
    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
    73
    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
    74
    newly created destination.
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
    75
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
    76
    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
    77
    .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
    78
    pushes.
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
    79
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
    80
    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
    81
    repository will be deleted.
2600
c4325f0a9b91 clean up trailing white space.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2597
diff changeset
    82
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
    83
    Arguments:
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
    84
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
    85
    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
    86
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
    87
    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
    88
    name of source repository)
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
    89
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
    90
    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
    91
2621
5a5852a417b1 clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2613
diff changeset
    92
    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
    93
    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
    94
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
    95
    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
    96
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
    97
    update: update working directory after clone completes, if
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
    98
    destination is local repository
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
    99
    """
4478
b2b55acbacdd Add support for url#id syntax
Matt Mackall <mpm@selenic.com>
parents: 4477
diff changeset
   100
b2b55acbacdd Add support for url#id syntax
Matt Mackall <mpm@selenic.com>
parents: 4477
diff changeset
   101
    origsource = source
b2b55acbacdd Add support for url#id syntax
Matt Mackall <mpm@selenic.com>
parents: 4477
diff changeset
   102
    source, rev = cmdutil.parseurl(ui.expandpath(source), rev)
b2b55acbacdd Add support for url#id syntax
Matt Mackall <mpm@selenic.com>
parents: 4477
diff changeset
   103
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   104
    if isinstance(source, str):
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   105
        src_repo = repository(ui, source)
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   106
    else:
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   107
        src_repo = source
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   108
        source = src_repo.url()
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   109
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   110
    if dest is None:
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   111
        dest = defaultdest(source)
3841
aaeb7f5d1052 Show the destionation for clone if not specified manually.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3791
diff changeset
   112
        ui.status(_("destination directory: %s\n") % dest)
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   113
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   114
    def localpath(path):
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   115
        if path.startswith('file://'):
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   116
            return path[7:]
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   117
        if path.startswith('file:'):
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   118
            return path[5:]
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   119
        return path
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   120
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   121
    dest = localpath(dest)
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
   122
    source = localpath(source)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   123
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   124
    if os.path.exists(dest):
3072
bc3fe3b5b785 Never apply string formatting to generated errors with util.Abort.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3037
diff changeset
   125
        raise util.Abort(_("destination '%s' already exists") % dest)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   126
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   127
    class DirCleanup(object):
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   128
        def __init__(self, dir_):
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   129
            self.rmtree = shutil.rmtree
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   130
            self.dir_ = dir_
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   131
        def close(self):
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   132
            self.dir_ = None
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   133
        def __del__(self):
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   134
            if self.dir_:
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   135
                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
   136
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   137
    dir_cleanup = None
3849
972d14a5a227 don't use localrepo.__init__ to create the dest repo with clone+hardlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3791
diff changeset
   138
    if islocal(dest):
972d14a5a227 don't use localrepo.__init__ to create the dest repo with clone+hardlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3791
diff changeset
   139
        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
   140
4478
b2b55acbacdd Add support for url#id syntax
Matt Mackall <mpm@selenic.com>
parents: 4477
diff changeset
   141
    abspath = origsource
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   142
    copy = False
3849
972d14a5a227 don't use localrepo.__init__ to create the dest repo with clone+hardlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3791
diff changeset
   143
    if src_repo.local() and islocal(dest):
4478
b2b55acbacdd Add support for url#id syntax
Matt Mackall <mpm@selenic.com>
parents: 4477
diff changeset
   144
        abspath = os.path.abspath(origsource)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   145
        copy = not pull and not rev
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   146
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   147
    src_lock, dest_lock = None, None
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   148
    if copy:
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   149
        try:
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   150
            # we use a lock here because if we race with commit, we
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   151
            # can end up with extra data in the cloned revlogs that's
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   152
            # not pointed to by changesets, thus causing verify to
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   153
            # fail
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   154
            src_lock = src_repo.lock()
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   155
        except lock.LockException:
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   156
            copy = False
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   157
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   158
    if copy:
3851
8f18e31c4441 add "requires" file to the repo, specifying the requirements
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3849
diff changeset
   159
        def force_copy(src, dst):
8f18e31c4441 add "requires" file to the repo, specifying the requirements
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3849
diff changeset
   160
            try:
8f18e31c4441 add "requires" file to the repo, specifying the requirements
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3849
diff changeset
   161
                util.copyfiles(src, dst)
8f18e31c4441 add "requires" file to the repo, specifying the requirements
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3849
diff changeset
   162
            except OSError, inst:
8f18e31c4441 add "requires" file to the repo, specifying the requirements
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3849
diff changeset
   163
                if inst.errno != errno.ENOENT:
8f18e31c4441 add "requires" file to the repo, specifying the requirements
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3849
diff changeset
   164
                    raise
8f18e31c4441 add "requires" file to the repo, specifying the requirements
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3849
diff changeset
   165
3791
8643b9f90b51 introduce localrepo.spath for the store path, sopener fixes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3713
diff changeset
   166
        src_store = os.path.realpath(src_repo.spath)
3849
972d14a5a227 don't use localrepo.__init__ to create the dest repo with clone+hardlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3791
diff changeset
   167
        if not os.path.exists(dest):
972d14a5a227 don't use localrepo.__init__ to create the dest repo with clone+hardlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3791
diff changeset
   168
            os.mkdir(dest)
3853
c0b449154a90 switch to the .hg/store layout, fix the tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3851
diff changeset
   169
        dest_path = os.path.realpath(os.path.join(dest, ".hg"))
3849
972d14a5a227 don't use localrepo.__init__ to create the dest repo with clone+hardlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3791
diff changeset
   170
        os.mkdir(dest_path)
3853
c0b449154a90 switch to the .hg/store layout, fix the tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3851
diff changeset
   171
        if src_repo.spath != src_repo.path:
c0b449154a90 switch to the .hg/store layout, fix the tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3851
diff changeset
   172
            dest_store = os.path.join(dest_path, "store")
c0b449154a90 switch to the .hg/store layout, fix the tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3851
diff changeset
   173
            os.mkdir(dest_store)
c0b449154a90 switch to the .hg/store layout, fix the tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3851
diff changeset
   174
        else:
c0b449154a90 switch to the .hg/store layout, fix the tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3851
diff changeset
   175
            dest_store = dest_path
3851
8f18e31c4441 add "requires" file to the repo, specifying the requirements
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3849
diff changeset
   176
        # copy the requires file
8f18e31c4441 add "requires" file to the repo, specifying the requirements
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3849
diff changeset
   177
        force_copy(src_repo.join("requires"),
8f18e31c4441 add "requires" file to the repo, specifying the requirements
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3849
diff changeset
   178
                   os.path.join(dest_path, "requires"))
8f18e31c4441 add "requires" file to the repo, specifying the requirements
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3849
diff changeset
   179
        # we lock here to avoid premature writing to the target
3791
8643b9f90b51 introduce localrepo.spath for the store path, sopener fixes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3713
diff changeset
   180
        dest_lock = lock.lock(os.path.join(dest_store, "lock"))
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   181
3713
8ae88ed2a3b6 don't create the .hg/data at init time
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3680
diff changeset
   182
        files = ("data",
8ae88ed2a3b6 don't create the .hg/data at init time
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3680
diff changeset
   183
                 "00manifest.d", "00manifest.i",
8ae88ed2a3b6 don't create the .hg/data at init time
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3680
diff changeset
   184
                 "00changelog.d", "00changelog.i")
8ae88ed2a3b6 don't create the .hg/data at init time
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3680
diff changeset
   185
        for f in files:
3791
8643b9f90b51 introduce localrepo.spath for the store path, sopener fixes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3713
diff changeset
   186
            src = os.path.join(src_store, f)
8643b9f90b51 introduce localrepo.spath for the store path, sopener fixes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3713
diff changeset
   187
            dst = os.path.join(dest_store, f)
3851
8f18e31c4441 add "requires" file to the repo, specifying the requirements
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3849
diff changeset
   188
            force_copy(src, dst)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   189
2631
8f564a875b50 codingstyle: use spaces instead of tabs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2621
diff changeset
   190
        # we need to re-init the repo after manually copying the data
8f564a875b50 codingstyle: use spaces instead of tabs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2621
diff changeset
   191
        # into it
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   192
        dest_repo = repository(ui, dest)
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
    else:
3849
972d14a5a227 don't use localrepo.__init__ to create the dest repo with clone+hardlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3791
diff changeset
   195
        dest_repo = repository(ui, dest, create=True)
972d14a5a227 don't use localrepo.__init__ to create the dest repo with clone+hardlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3791
diff changeset
   196
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   197
        revs = None
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   198
        if rev:
3448
6ca49c5fe268 Stop erroring out pull -r and clone -r if repository isn't local.
Eric Hopper <hopper@omnifarious.org>
parents: 3441
diff changeset
   199
            if 'lookup' not in src_repo.capabilities:
6ca49c5fe268 Stop erroring out pull -r and clone -r if repository isn't local.
Eric Hopper <hopper@omnifarious.org>
parents: 3441
diff changeset
   200
                raise util.Abort(_("src repository does not support revision "
6ca49c5fe268 Stop erroring out pull -r and clone -r if repository isn't local.
Eric Hopper <hopper@omnifarious.org>
parents: 3441
diff changeset
   201
                                   "lookup and so doesn't support clone by "
6ca49c5fe268 Stop erroring out pull -r and clone -r if repository isn't local.
Eric Hopper <hopper@omnifarious.org>
parents: 3441
diff changeset
   202
                                   "revision"))
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   203
            revs = [src_repo.lookup(r) for r in rev]
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   204
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   205
        if dest_repo.local():
2613
479e26afa10f clone: do not make streaming default. add --stream option instead.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
   206
            dest_repo.clone(src_repo, heads=revs, stream=stream)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   207
        elif src_repo.local():
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   208
            src_repo.push(dest_repo, revs=revs)
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   209
        else:
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   210
            raise util.Abort(_("clone from remote to remote not supported"))
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   211
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   212
    if src_lock:
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   213
        src_lock.release()
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   214
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   215
    if dest_repo.local():
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   216
        fp = dest_repo.opener("hgrc", "w", text=True)
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   217
        fp.write("[paths]\n")
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   218
        fp.write("default = %s\n" % abspath)
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   219
        fp.close()
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   220
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   221
        if dest_lock:
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   222
            dest_lock.release()
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   223
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   224
        if update:
4477
6cbfa740c129 clone: checkout the "default" branch if available
Matt Mackall <mpm@selenic.com>
parents: 4081
diff changeset
   225
            try:
6cbfa740c129 clone: checkout the "default" branch if available
Matt Mackall <mpm@selenic.com>
parents: 4081
diff changeset
   226
                checkout = dest_repo.lookup("default")
6cbfa740c129 clone: checkout the "default" branch if available
Matt Mackall <mpm@selenic.com>
parents: 4081
diff changeset
   227
            except:
6cbfa740c129 clone: checkout the "default" branch if available
Matt Mackall <mpm@selenic.com>
parents: 4081
diff changeset
   228
                checkout = dest_repo.changelog.tip()
6cbfa740c129 clone: checkout the "default" branch if available
Matt Mackall <mpm@selenic.com>
parents: 4081
diff changeset
   229
            _update(dest_repo, checkout)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   230
    if dir_cleanup:
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
   231
        dir_cleanup.close()
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
    return src_repo, dest_repo
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
   234
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   235
def _showstats(repo, stats):
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   236
    stats = ((stats[0], _("updated")),
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   237
             (stats[1], _("merged")),
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   238
             (stats[2], _("removed")),
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   239
             (stats[3], _("unresolved")))
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   240
    note = ", ".join([_("%d files %s") % s for s in stats])
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   241
    repo.ui.status("%s\n" % note)
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   242
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   243
def _update(repo, node): return update(repo, node)
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   244
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
   245
def update(repo, node):
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
   246
    """update the working directory to node, merging linear changes"""
3869
ad6f34c83c3d Add instructions how to redo/finish failed merge with local working directory.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3854
diff changeset
   247
    pl = repo.parents()
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   248
    stats = _merge.update(repo, node, False, False, None, None)
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   249
    _showstats(repo, stats)
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   250
    if stats[3]:
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   251
        repo.ui.status(_("There are unresolved merges with"
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   252
                         " locally modified files.\n"))
3869
ad6f34c83c3d Add instructions how to redo/finish failed merge with local working directory.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3854
diff changeset
   253
        if stats[1]:
ad6f34c83c3d Add instructions how to redo/finish failed merge with local working directory.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3854
diff changeset
   254
            repo.ui.status(_("You can finish the partial merge using:\n"))
ad6f34c83c3d Add instructions how to redo/finish failed merge with local working directory.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3854
diff changeset
   255
        else:
ad6f34c83c3d Add instructions how to redo/finish failed merge with local working directory.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3854
diff changeset
   256
            repo.ui.status(_("You can redo the full merge using:\n"))
ad6f34c83c3d Add instructions how to redo/finish failed merge with local working directory.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3854
diff changeset
   257
        # len(pl)==1, otherwise _merge.update() would have raised util.Abort:
ad6f34c83c3d Add instructions how to redo/finish failed merge with local working directory.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3854
diff changeset
   258
        repo.ui.status(_("  hg update %s\n  hg update %s\n")
ad6f34c83c3d Add instructions how to redo/finish failed merge with local working directory.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3854
diff changeset
   259
                       % (pl[0].rev(), repo.changectx(node).rev()))
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   260
    return stats[3]
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
   261
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
   262
def clean(repo, node, wlock=None, show_stats=True):
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
   263
    """forcibly switch the working directory to node, clobbering changes"""
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   264
    stats = _merge.update(repo, node, False, True, None, wlock)
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   265
    if show_stats: _showstats(repo, stats)
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   266
    return stats[3]
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
   267
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
   268
def merge(repo, node, force=None, remind=True, wlock=None):
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
   269
    """branch merge with node, resolving changes"""
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   270
    stats = _merge.update(repo, node, True, force, False, wlock)
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   271
    _showstats(repo, stats)
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   272
    if stats[3]:
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   273
        pl = repo.parents()
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   274
        repo.ui.status(_("There are unresolved merges,"
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   275
                         " you can redo the full merge using:\n"
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   276
                         "  hg update -C %s\n"
3679
2956948b81f3 fix warnings generated by pygettext.py.
Marcos Chaves <marcos.nospam@gmail.com>
parents: 3448
diff changeset
   277
                         "  hg merge %s\n")
3680
69cf255a55a1 Indentation cleanups for 2956948b81f3.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3679
diff changeset
   278
                       % (pl[0].rev(), pl[1].rev()))
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   279
    elif remind:
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   280
        repo.ui.status(_("(branch merge, don't forget to commit)\n"))
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   281
    return stats[3]
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
   282
2812
3aeab7bb5adc Refactor update locking slightly
Matt Mackall <mpm@selenic.com>
parents: 2811
diff changeset
   283
def revert(repo, node, choose, wlock):
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
   284
    """revert changes to revision in node without updating dirstate"""
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
   285
    return _merge.update(repo, node, False, True, choose, wlock)[3]
2778
fdc232d8a193 Move repo.verify
Matt Mackall <mpm@selenic.com>
parents: 2775
diff changeset
   286
fdc232d8a193 Move repo.verify
Matt Mackall <mpm@selenic.com>
parents: 2775
diff changeset
   287
def verify(repo):
fdc232d8a193 Move repo.verify
Matt Mackall <mpm@selenic.com>
parents: 2775
diff changeset
   288
    """verify the consistency of a repository"""
fdc232d8a193 Move repo.verify
Matt Mackall <mpm@selenic.com>
parents: 2775
diff changeset
   289
    return _verify.verify(repo)