annotate mercurial/hg.py @ 6317:b0d937869417

hgwebdir: Tiny fix for webdir on non-symlink capable platforms.
author Eric Hopper <hopper@omnifarious.org>
date Mon, 17 Mar 2008 12:40:02 -0700
parents 5c96a4bca66b
children 0750f11152fe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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 #
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
3891
6b4127c7d52a Simplify i18n imports
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
9 from i18n import _
3877
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3869
diff changeset
10 import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo
5177
92236732d5a1 move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 4917
diff changeset
11 import errno, lock, os, shutil, util, extensions
3877
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3869
diff changeset
12 import merge as _merge
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3869
diff changeset
13 import verify as _verify
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
14
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
15 def _local(path):
3195
705e30c0a230 Make hg.repository work with no path argument
Brendan Cully <brendan@kublai.com>
parents: 3072
diff changeset
16 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
17 bundlerepo or localrepo)
2469
2e91ba371c4c hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2431
diff changeset
18
5177
92236732d5a1 move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 4917
diff changeset
19 def parseurl(url, revs):
92236732d5a1 move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 4917
diff changeset
20 '''parse url#branch, returning url, branch + revs'''
92236732d5a1 move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 4917
diff changeset
21
92236732d5a1 move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 4917
diff changeset
22 if '#' not in url:
5248
5517aa5aafb0 Merge with crew-stable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5192 5225
diff changeset
23 return url, (revs or None), None
5177
92236732d5a1 move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 4917
diff changeset
24
92236732d5a1 move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 4917
diff changeset
25 url, rev = url.split('#', 1)
5248
5517aa5aafb0 Merge with crew-stable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5192 5225
diff changeset
26 return url, revs + [rev], rev
5177
92236732d5a1 move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 4917
diff changeset
27
2472
e6ec81a8feea make repo scheme table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2431
diff changeset
28 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
29 '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
30 '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
31 '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
32 '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
33 '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
34 'static-http': statichttprepo,
4853
bf10a03a6b24 Removed deprecated hg:// and old-http:// protocols (issue406)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4818
diff changeset
35 }
2469
2e91ba371c4c hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2431
diff changeset
36
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
37 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
38 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
39 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
40 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
41 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
42 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
43 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
44 try:
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
45 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
46 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
47 return thing
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
48
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
49 def islocal(repo):
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
50 '''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
51 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
52 try:
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
53 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
54 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
55 return False
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
56 return repo.local()
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
57
3195
705e30c0a230 Make hg.repository work with no path argument
Brendan Cully <brendan@kublai.com>
parents: 3072
diff changeset
58 def repository(ui, path='', create=False):
2774
8cd3e19bf4a5 Add a doc string
Matt Mackall <mpm@selenic.com>
parents: 2768
diff changeset
59 """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
60 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
61 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
62 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
63 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
64 if hook:
60acf1432ee0 Move cmdtable and reposetup handling out of extensions.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5187
diff changeset
65 hook(ui, repo)
2847
2ff57e3113a4 call reposetup functions of extension modules whenever repo created
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2830
diff changeset
66 return repo
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
67
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
68 def defaultdest(source):
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
69 '''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
70 return os.path.basename(os.path.normpath(source))
2774
8cd3e19bf4a5 Add a doc string
Matt Mackall <mpm@selenic.com>
parents: 2768
diff changeset
71
2613
479e26afa10f clone: do not make streaming default. add --stream option instead.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
72 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
73 stream=False):
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
74 """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
75
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
76 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
77 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
78 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
79 newly created destination.
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
80
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
81 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
82 .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
83 pushes.
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
84
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
85 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
86 repository will be deleted.
2600
c4325f0a9b91 clean up trailing white space.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2597
diff changeset
87
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
88 Arguments:
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
89
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
90 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
91
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
92 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
93 name of source repository)
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
94
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
95 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
96
2621
5a5852a417b1 clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2613
diff changeset
97 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
98 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
99
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
100 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
101
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
102 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
103 destination is local repository
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
104 """
4478
b2b55acbacdd Add support for url#id syntax
Matt Mackall <mpm@selenic.com>
parents: 4477
diff changeset
105
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
106 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
107 origsource = ui.expandpath(source)
28054773438c clone: make things work when source is a repo object
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 6088
diff changeset
108 source, rev, checkout = parseurl(origsource, rev)
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
109 src_repo = repository(ui, source)
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
110 else:
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
111 src_repo = source
6089
28054773438c clone: make things work when source is a repo object
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 6088
diff changeset
112 origsource = source = src_repo.url()
28054773438c clone: make things work when source is a repo object
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 6088
diff changeset
113 checkout = None
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
114
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
115 if dest is None:
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
116 dest = defaultdest(source)
3841
aaeb7f5d1052 Show the destionation for clone if not specified manually.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3791
diff changeset
117 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
118
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
119 def localpath(path):
6165
0d36de68669c Allow "file://localhost/" in addition to "file:///" (issue728)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6090
diff changeset
120 if path.startswith('file://localhost/'):
0d36de68669c Allow "file://localhost/" in addition to "file:///" (issue728)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6090
diff changeset
121 return path[16:]
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
122 if path.startswith('file://'):
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
123 return path[7:]
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
124 if path.startswith('file:'):
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
125 return path[5:]
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
126 return path
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
127
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
128 dest = localpath(dest)
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
129 source = localpath(source)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
130
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
131 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
132 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
133
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
134 class DirCleanup(object):
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
135 def __init__(self, dir_):
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
136 self.rmtree = shutil.rmtree
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
137 self.dir_ = dir_
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
138 def close(self):
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
139 self.dir_ = None
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
140 def __del__(self):
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
141 if self.dir_:
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
142 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
143
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
144 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
145 try:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
146 if islocal(dest):
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
147 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
148
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
149 abspath = origsource
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
150 copy = False
6315
5c96a4bca66b clone: use cancopy
Matt Mackall <mpm@selenic.com>
parents: 6217
diff changeset
151 if src_repo.cancopy() and islocal(dest):
5248
5517aa5aafb0 Merge with crew-stable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5192 5225
diff changeset
152 abspath = os.path.abspath(util.drop_scheme('file', origsource))
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
153 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
154
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
155 if copy:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
156 try:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
157 # 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
158 # 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
159 # 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
160 # fail
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
161 src_lock = src_repo.lock()
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
162 except lock.LockException:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
163 copy = False
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
164
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
165 if copy:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
166 def force_copy(src, dst):
5699
4cf5a4950fc9 hg: fail upon copy/link errors while cloning locally
Patrick Mezard <pmezard@gmail.com>
parents: 5635
diff changeset
167 if not os.path.exists(src):
4cf5a4950fc9 hg: fail upon copy/link errors while cloning locally
Patrick Mezard <pmezard@gmail.com>
parents: 5635
diff changeset
168 # Tolerate empty source repository and optional files
4cf5a4950fc9 hg: fail upon copy/link errors while cloning locally
Patrick Mezard <pmezard@gmail.com>
parents: 5635
diff changeset
169 return
4cf5a4950fc9 hg: fail upon copy/link errors while cloning locally
Patrick Mezard <pmezard@gmail.com>
parents: 5635
diff changeset
170 util.copyfiles(src, dst)
3851
8f18e31c4441 add "requires" file to the repo, specifying the requirements
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3849
diff changeset
171
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
172 src_store = os.path.realpath(src_repo.spath)
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
173 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
174 os.mkdir(dest)
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
175 try:
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
176 dest_path = os.path.realpath(os.path.join(dest, ".hg"))
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
177 os.mkdir(dest_path)
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
178 except OSError, inst:
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
179 if inst.errno == errno.EEXIST:
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
180 dir_cleanup.close()
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
181 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
182 % dest)
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
183 raise
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
184 if src_repo.spath != src_repo.path:
5277
a32a8e50d233 merge with crew
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 5248 5233
diff changeset
185 # XXX racy
a32a8e50d233 merge with crew
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 5248 5233
diff changeset
186 dummy_changelog = os.path.join(dest_path, "00changelog.i")
a32a8e50d233 merge with crew
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 5248 5233
diff changeset
187 # copy the dummy changelog
a32a8e50d233 merge with crew
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 5248 5233
diff changeset
188 force_copy(src_repo.join("00changelog.i"), dummy_changelog)
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
189 dest_store = os.path.join(dest_path, "store")
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
190 os.mkdir(dest_store)
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
191 else:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
192 dest_store = dest_path
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
193 # copy the requires file
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
194 force_copy(src_repo.join("requires"),
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
195 os.path.join(dest_path, "requires"))
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
196 # we lock here to avoid premature writing to the target
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
197 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
198
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
199 files = ("data",
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
200 "00manifest.d", "00manifest.i",
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
201 "00changelog.d", "00changelog.i")
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
202 for f in files:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
203 src = os.path.join(src_store, f)
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
204 dst = os.path.join(dest_store, f)
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
205 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
206
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
207 # 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
208 # into it
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
209 dest_repo = repository(ui, dest)
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
210
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
211 else:
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
212 try:
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
213 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
214 except OSError, inst:
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
215 if inst.errno == errno.EEXIST:
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
216 dir_cleanup.close()
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
217 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
218 % dest)
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
219 raise
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
220
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
221 revs = None
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
222 if rev:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
223 if 'lookup' not in src_repo.capabilities:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
224 raise util.Abort(_("src repository does not support revision "
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
225 "lookup and so doesn't support clone by "
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
226 "revision"))
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
227 revs = [src_repo.lookup(r) for r in rev]
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
228
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
229 if dest_repo.local():
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
230 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
231 elif src_repo.local():
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
232 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
233 else:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
234 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
235
5186
0d5d03844927 merge with -stable
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 4917 5185
diff changeset
236 if dir_cleanup:
0d5d03844927 merge with -stable
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 4917 5185
diff changeset
237 dir_cleanup.close()
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
238
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
239 if dest_repo.local():
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
240 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
241 fp.write("[paths]\n")
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
242 fp.write("default = %s\n" % abspath)
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
243 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
244
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
245 if update:
5248
5517aa5aafb0 Merge with crew-stable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5192 5225
diff changeset
246 if not checkout:
5517aa5aafb0 Merge with crew-stable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5192 5225
diff changeset
247 try:
5517aa5aafb0 Merge with crew-stable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5192 5225
diff changeset
248 checkout = dest_repo.lookup("default")
5517aa5aafb0 Merge with crew-stable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5192 5225
diff changeset
249 except:
5517aa5aafb0 Merge with crew-stable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5192 5225
diff changeset
250 checkout = dest_repo.changelog.tip()
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
251 _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
252
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
253 return src_repo, dest_repo
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
254 finally:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
255 del src_lock, dest_lock, dir_cleanup
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
256
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
257 def _showstats(repo, stats):
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
258 stats = ((stats[0], _("updated")),
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
259 (stats[1], _("merged")),
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
260 (stats[2], _("removed")),
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
261 (stats[3], _("unresolved")))
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
262 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
263 repo.ui.status("%s\n" % note)
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
264
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
265 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
266
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
267 def update(repo, node):
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
268 """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
269 pl = repo.parents()
4917
126f527b3ba3 Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents: 4915
diff changeset
270 stats = _merge.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
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 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
274 " 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
275 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
276 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
277 else:
ad6f34c83c3d Add instructions how to redo/finish failed merge with local working directory.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3854
diff changeset
278 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
279 # 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
280 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
281 % (pl[0].rev(), repo.changectx(node).rev()))
5635
0c608a8d9c5f merge: make return codes more sensible
Matt Mackall <mpm@selenic.com>
parents: 5569
diff changeset
282 return stats[3] > 0
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
283
4917
126f527b3ba3 Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents: 4915
diff changeset
284 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
285 """forcibly switch the working directory to node, clobbering changes"""
4917
126f527b3ba3 Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents: 4915
diff changeset
286 stats = _merge.update(repo, node, False, True, None)
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
287 if show_stats: _showstats(repo, stats)
5635
0c608a8d9c5f merge: make return codes more sensible
Matt Mackall <mpm@selenic.com>
parents: 5569
diff changeset
288 return stats[3] > 0
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
289
4917
126f527b3ba3 Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents: 4915
diff changeset
290 def merge(repo, node, force=None, remind=True):
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
291 """branch merge with node, resolving changes"""
4917
126f527b3ba3 Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents: 4915
diff changeset
292 stats = _merge.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
293 _showstats(repo, stats)
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
294 if stats[3]:
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
295 pl = repo.parents()
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
296 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
297 " 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
298 " hg update -C %s\n"
3679
2956948b81f3 fix warnings generated by pygettext.py.
Marcos Chaves <marcos.nospam@gmail.com>
parents: 3448
diff changeset
299 " hg merge %s\n")
3680
69cf255a55a1 Indentation cleanups for 2956948b81f3.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3679
diff changeset
300 % (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
301 elif remind:
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
302 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
303 return stats[3] > 0
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
304
4917
126f527b3ba3 Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents: 4915
diff changeset
305 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
306 """revert changes to revision in node without updating dirstate"""
5635
0c608a8d9c5f merge: make return codes more sensible
Matt Mackall <mpm@selenic.com>
parents: 5569
diff changeset
307 return _merge.update(repo, node, False, True, choose)[3] > 0
2778
fdc232d8a193 Move repo.verify
Matt Mackall <mpm@selenic.com>
parents: 2775
diff changeset
308
fdc232d8a193 Move repo.verify
Matt Mackall <mpm@selenic.com>
parents: 2775
diff changeset
309 def verify(repo):
fdc232d8a193 Move repo.verify
Matt Mackall <mpm@selenic.com>
parents: 2775
diff changeset
310 """verify the consistency of a repository"""
fdc232d8a193 Move repo.verify
Matt Mackall <mpm@selenic.com>
parents: 2775
diff changeset
311 return _verify.verify(repo)