annotate mercurial/hg.py @ 24945:e0b0fbd47491

bookmarks: rename setcurrent to activate (API) Today, the terms 'active' and 'current' are interchangeably used throughout the codebase in reference to the active bookmark (the bookmark that will be updated with the next commit). This leads to confusion among developers and users. This patch is part of a series to standardize the usage to 'active' throughout the mercurial codebase and user interface.
author Ryan McElroy <rmcelroy@fb.com>
date Mon, 13 Apr 2015 22:27:01 -0700
parents 27ad6b91f5c2
children 4cc3fb23881d
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 #
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8179
diff changeset
6 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 10099
diff changeset
7 # GNU General Public License version 2 or any later version.
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
8
3891
6b4127c7d52a Simplify i18n imports
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
9 from i18n import _
8109
496ae1ea4698 switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 7935
diff changeset
10 from lock import release
22648
ef62c66bee1b clone: remove duplicated bookmark pulling
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22647
diff changeset
11 from node import nullid
22837
2be7d5ebd4d0 config: use the same hgrc for a cloned repo as for an uninitted repo
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 22818
diff changeset
12
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents: 18553
diff changeset
13 import localrepo, bundlerepo, unionrepo, httppeer, sshpeer, statichttprepo
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents: 18553
diff changeset
14 import bookmarks, lock, util, extensions, error, node, scmutil, phases, url
22618
ce95c15f680b clone: use `exchange.push` instead of `localrepo.push`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22380
diff changeset
15 import cmdutil, discovery, repoview, exchange
22837
2be7d5ebd4d0 config: use the same hgrc for a cloned repo as for an uninitted repo
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 22818
diff changeset
16 import ui as uimod
10651
5f091fc1bab7 style: use consistent variable names (*mod) with imports which would shadow
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10380
diff changeset
17 import merge as mergemod
5f091fc1bab7 style: use consistent variable names (*mod) with imports which would shadow
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10380
diff changeset
18 import verify as verifymod
8312
b87a50b7125c separate import lines from mercurial and general python modules
Simon Heimberg <simohe@besonet.ch>
parents: 8225
diff changeset
19 import errno, os, shutil
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
20
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2738
diff changeset
21 def _local(path):
14825
de9eb6b1da4f util: rename the util.localpath that uses url to urllocalpath (issue2875)
Mads Kiilerich <mads@kiilerich.com>
parents: 14737
diff changeset
22 path = util.expandpath(util.urllocalpath(path))
11154
17031fea4e95 expand paths to local repository or bundle in appropriate classes
Alexander Solovyov <piranha@piranha.org.ua>
parents: 10728
diff changeset
23 return (os.path.isfile(path) and bundlerepo or localrepo)
2469
2e91ba371c4c hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2431
diff changeset
24
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
25 def addbranchrevs(lrepo, other, branches, revs):
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
26 peer = other.peer() # a courtesy to callers using a localrepo for other
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
27 hashbranch, branches = branches
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
28 if not hashbranch and not branches:
22818
d7b114493315 repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22648
diff changeset
29 x = revs or None
d7b114493315 repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22648
diff changeset
30 if util.safehasattr(revs, 'first'):
d7b114493315 repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22648
diff changeset
31 y = revs.first()
d7b114493315 repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22648
diff changeset
32 elif revs:
d7b114493315 repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22648
diff changeset
33 y = revs[0]
d7b114493315 repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22648
diff changeset
34 else:
d7b114493315 repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22648
diff changeset
35 y = None
d7b114493315 repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22648
diff changeset
36 return x, y
24306
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24290
diff changeset
37 if revs:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24290
diff changeset
38 revs = list(revs)
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24290
diff changeset
39 else:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24290
diff changeset
40 revs = []
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24290
diff changeset
41
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
42 if not peer.capable('branchmap'):
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
43 if branches:
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
44 raise util.Abort(_("remote branch lookup not supported"))
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
45 revs.append(hashbranch)
10380
ee72d89c0d9f addbranchrevs: fallback for older servers
Sune Foldager <cryo@cyanite.org>
parents: 10379
diff changeset
46 return revs, revs[0]
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
47 branchmap = peer.branchmap()
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
48
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
49 def primary(branch):
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
50 if branch == '.':
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
51 if not lrepo:
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
52 raise util.Abort(_("dirstate branch not accessible"))
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
53 branch = lrepo.dirstate.branch()
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
54 if branch in branchmap:
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
55 revs.extend(node.hex(r) for r in reversed(branchmap[branch]))
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
56 return True
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
57 else:
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
58 return False
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
59
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
60 for branch in branches:
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
61 if not primary(branch):
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
62 raise error.RepoLookupError(_("unknown branch '%s'") % branch)
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
63 if hashbranch:
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 12735
diff changeset
64 if not primary(hashbranch):
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
65 revs.append(hashbranch)
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
66 return revs, revs[0]
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
67
13824
ec1695350361 hg: use url.url to parse branch names in parseurl()
Brodie Rao <brodie@bitheap.org>
parents: 13823
diff changeset
68 def parseurl(path, branches=None):
11322
3d6915f5a2bb improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents: 11312
diff changeset
69 '''parse url#branch, returning (url, (branch, branches))'''
5177
92236732d5a1 move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 4917
diff changeset
70
14076
924c82157d46 url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents: 14073
diff changeset
71 u = util.url(path)
13897
375872fdadba hg: make parseurl() consistently return normalised path
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13826
diff changeset
72 branch = None
375872fdadba hg: make parseurl() consistently return normalised path
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13826
diff changeset
73 if u.fragment:
375872fdadba hg: make parseurl() consistently return normalised path
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13826
diff changeset
74 branch = u.fragment
375872fdadba hg: make parseurl() consistently return normalised path
Thomas Arendsen Hein <thomas@intevation.de>
parents: 13826
diff changeset
75 u.fragment = None
13824
ec1695350361 hg: use url.url to parse branch names in parseurl()
Brodie Rao <brodie@bitheap.org>
parents: 13823
diff changeset
76 return str(u), (branch, branches or [])
5177
92236732d5a1 move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 4917
diff changeset
77
14606
6e631c24c6d9 hg: move peerschemes back to schemes
Matt Mackall <mpm@selenic.com>
parents: 14605
diff changeset
78 schemes = {
14568
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
79 'bundle': bundlerepo,
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents: 18553
diff changeset
80 'union': unionrepo,
14568
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
81 'file': _local,
17192
1ac628cd7113 peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 17191
diff changeset
82 'http': httppeer,
1ac628cd7113 peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 17191
diff changeset
83 'https': httppeer,
1ac628cd7113 peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 17191
diff changeset
84 'ssh': sshpeer,
14568
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
85 'static-http': statichttprepo,
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
86 }
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
87
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
88 def _peerlookup(path):
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
89 u = util.url(path)
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
90 scheme = u.scheme or 'file'
14606
6e631c24c6d9 hg: move peerschemes back to schemes
Matt Mackall <mpm@selenic.com>
parents: 14605
diff changeset
91 thing = schemes.get(scheme) or schemes['file']
14568
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
92 try:
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
93 return thing(path)
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
94 except TypeError:
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
95 return thing
5f002e3336ba hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents: 14556
diff changeset
96
14605
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
97 def islocal(repo):
20355
7d269e7620c4 hg: note that islocal only accepts paths pointing to repos
Siddharth Agarwal <sid0@fb.com>
parents: 20354
diff changeset
98 '''return true if repo (or path pointing to repo) is local'''
14605
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
99 if isinstance(repo, str):
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
100 try:
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
101 return _peerlookup(repo).islocal(repo)
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
102 except AttributeError:
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
103 return False
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
104 return repo.local()
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
105
17887
0e2846b2482c url: use open and not url.open for local files (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents: 17882
diff changeset
106 def openpath(ui, path):
0e2846b2482c url: use open and not url.open for local files (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents: 17882
diff changeset
107 '''open path with open if local, url.open if remote'''
20354
b433b43364e4 hg.openpath: use url.islocal to tell if the path is local (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents: 20185
diff changeset
108 pathurl = util.url(path, parsequery=False, parsefragment=False)
b433b43364e4 hg.openpath: use url.islocal to tell if the path is local (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents: 20185
diff changeset
109 if pathurl.islocal():
b433b43364e4 hg.openpath: use url.islocal to tell if the path is local (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents: 20185
diff changeset
110 return util.posixfile(pathurl.localpath(), 'rb')
17887
0e2846b2482c url: use open and not url.open for local files (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents: 17882
diff changeset
111 else:
0e2846b2482c url: use open and not url.open for local files (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents: 17882
diff changeset
112 return url.open(ui, path)
0e2846b2482c url: use open and not url.open for local files (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents: 17882
diff changeset
113
20858
bc56ec9e64df hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20825
diff changeset
114 # a list of (ui, repo) functions called for wire peer initialization
bc56ec9e64df hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20825
diff changeset
115 wirepeersetupfuncs = []
bc56ec9e64df hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20825
diff changeset
116
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
117 def _peerorrepo(ui, path, create=False):
14605
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
118 """return a repository object for the specified path"""
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
119 obj = _peerlookup(path).instance(ui, path, create)
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
120 ui = getattr(obj, "ui", ui)
19777
6f72e7d28b35 extensions: list up only enabled extensions, if "ui" is specified
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19371
diff changeset
121 for name, module in extensions.extensions(ui):
14605
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
122 hook = getattr(module, 'reposetup', None)
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
123 if hook:
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
124 hook(ui, obj)
20858
bc56ec9e64df hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20825
diff changeset
125 if not obj.local():
bc56ec9e64df hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20825
diff changeset
126 for f in wirepeersetupfuncs:
bc56ec9e64df hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20825
diff changeset
127 f(ui, obj)
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
128 return obj
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
129
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
130 def repository(ui, path='', create=False):
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
131 """return a repository object for the specified path"""
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
132 peer = _peerorrepo(ui, path, create)
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
133 repo = peer.local()
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
134 if not repo:
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
135 raise util.Abort(_("repository '%s' is not local") %
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
136 (path or peer.url()))
18382
f3b21beb9802 filtering: rename filters to their antonyms
Kevin Bullock <kbullock@ringworld.org>
parents: 18303
diff changeset
137 return repo.filtered('visible')
14605
9f1139cf5c76 hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents: 14568
diff changeset
138
14839
510c893a726f peer: change arg name to convey it can be a repo as well
Idan Kamara <idankk86@gmail.com>
parents: 14825
diff changeset
139 def peer(uiorrepo, opts, path, create=False):
14554
68db17047637 hg: add peer method
Matt Mackall <mpm@selenic.com>
parents: 14553
diff changeset
140 '''return a repository peer for the specified path'''
14839
510c893a726f peer: change arg name to convey it can be a repo as well
Idan Kamara <idankk86@gmail.com>
parents: 14825
diff changeset
141 rui = remoteui(uiorrepo, opts)
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
142 return _peerorrepo(rui, path, create).peer()
14554
68db17047637 hg: add peer method
Matt Mackall <mpm@selenic.com>
parents: 14553
diff changeset
143
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
144 def defaultdest(source):
20799
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
145 '''return default destination of clone if none is given
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
146
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
147 >>> defaultdest('foo')
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
148 'foo'
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
149 >>> defaultdest('/foo/bar')
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
150 'bar'
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
151 >>> defaultdest('/')
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
152 ''
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
153 >>> defaultdest('')
20800
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
154 ''
20799
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
155 >>> defaultdest('http://example.org/')
20800
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
156 ''
20799
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
157 >>> defaultdest('http://example.org/foo/')
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
158 'foo'
069bf1b821c8 clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents: 20790
diff changeset
159 '''
20800
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
160 path = util.url(source).path
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
161 if not path:
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
162 return ''
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
163 return os.path.basename(os.path.normpath(path))
2774
8cd3e19bf4a5 Add a doc string
Matt Mackall <mpm@selenic.com>
parents: 2768
diff changeset
164
23614
cd79fb4d75fd share: add option to share bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents: 23545
diff changeset
165 def share(ui, source, dest=None, update=True, bookmarks=True):
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
166 '''create a shared repository'''
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
167
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
168 if not islocal(source):
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
169 raise util.Abort(_('can only share local repositories'))
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
170
8807
8bf6eb68ddaf share: allow dest to default to the basename of source
Matt Mackall <mpm@selenic.com>
parents: 8800
diff changeset
171 if not dest:
10099
f5e46dfb38c7 share: use defaultdest to compute unspecified destination
Brendan Cully <brendan@kublai.com>
parents: 9984
diff changeset
172 dest = defaultdest(source)
9344
eb6af02307ec Merge with i18n-stable
Matt Mackall <mpm@selenic.com>
parents: 9245
diff changeset
173 else:
eb6af02307ec Merge with i18n-stable
Matt Mackall <mpm@selenic.com>
parents: 9245
diff changeset
174 dest = ui.expandpath(dest)
8807
8bf6eb68ddaf share: allow dest to default to the basename of source
Matt Mackall <mpm@selenic.com>
parents: 8800
diff changeset
175
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
176 if isinstance(source, str):
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
177 origsource = ui.expandpath(source)
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
178 source, branches = parseurl(origsource)
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
179 srcrepo = repository(ui, source)
10365
d757bc0c7865 interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents: 10358
diff changeset
180 rev, checkout = addbranchrevs(srcrepo, srcrepo, branches, None)
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
181 else:
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
182 srcrepo = source.local()
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
183 origsource = source = srcrepo.url()
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
184 checkout = None
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
185
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
186 sharedpath = srcrepo.sharedpath # if our source is already sharing
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
187
21800
219af1521a6a hg: use vfs functions in destination repository with share
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21537
diff changeset
188 destwvfs = scmutil.vfs(dest, realpath=True)
21801
2ccd71bbd0f7 hg: update to use vfs functions in shared destination repository
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21800
diff changeset
189 destvfs = scmutil.vfs(os.path.join(destwvfs.base, '.hg'), realpath=True)
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
190
21801
2ccd71bbd0f7 hg: update to use vfs functions in shared destination repository
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21800
diff changeset
191 if destvfs.lexists():
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
192 raise util.Abort(_('destination already exists'))
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
193
21800
219af1521a6a hg: use vfs functions in destination repository with share
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21537
diff changeset
194 if not destwvfs.isdir():
219af1521a6a hg: use vfs functions in destination repository with share
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21537
diff changeset
195 destwvfs.mkdir()
21801
2ccd71bbd0f7 hg: update to use vfs functions in shared destination repository
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21800
diff changeset
196 destvfs.makedir()
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
197
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
198 requirements = ''
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
199 try:
23877
7cc77030c557 localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 23614
diff changeset
200 requirements = srcrepo.vfs.read('requires')
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
201 except IOError, inst:
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
202 if inst.errno != errno.ENOENT:
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
203 raise
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
204
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
205 requirements += 'shared\n'
21802
ff27fad408c4 hg: update util.writefile method to use write with vfs in share
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21801
diff changeset
206 destvfs.write('requires', requirements)
ff27fad408c4 hg: update util.writefile method to use write with vfs in share
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21801
diff changeset
207 destvfs.write('sharedpath', sharedpath)
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
208
21800
219af1521a6a hg: use vfs functions in destination repository with share
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21537
diff changeset
209 r = repository(ui, destwvfs.base)
14156
839086b25c36 share: create 'hgrc' using an opener, like clone
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 14076
diff changeset
210
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
211 default = srcrepo.ui.config('paths', 'default')
18511
798ab869b2ee share: backout fd903f89e42b, except the test
Matt Harbison <matt_harbison@yahoo.com>
parents: 18493
diff changeset
212 if default:
23877
7cc77030c557 localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 23614
diff changeset
213 fp = r.vfs("hgrc", "w", text=True)
18511
798ab869b2ee share: backout fd903f89e42b, except the test
Matt Harbison <matt_harbison@yahoo.com>
parents: 18493
diff changeset
214 fp.write("[paths]\n")
798ab869b2ee share: backout fd903f89e42b, except the test
Matt Harbison <matt_harbison@yahoo.com>
parents: 18493
diff changeset
215 fp.write("default = %s\n" % default)
798ab869b2ee share: backout fd903f89e42b, except the test
Matt Harbison <matt_harbison@yahoo.com>
parents: 18493
diff changeset
216 fp.close()
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
217
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
218 if update:
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
219 r.ui.status(_("updating working directory\n"))
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
220 if update is not True:
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
221 checkout = update
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
222 for test in (checkout, 'default', 'tip'):
9423
1444a42f6052 Make distinct lookup error for localrepo.lookup
Matt Mackall <mpm@selenic.com>
parents: 9344
diff changeset
223 if test is None:
1444a42f6052 Make distinct lookup error for localrepo.lookup
Matt Mackall <mpm@selenic.com>
parents: 9344
diff changeset
224 continue
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
225 try:
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
226 uprev = r.lookup(test)
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
227 break
9423
1444a42f6052 Make distinct lookup error for localrepo.lookup
Matt Mackall <mpm@selenic.com>
parents: 9344
diff changeset
228 except error.RepoLookupError:
8800
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
229 continue
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
230 _update(r, uprev)
971e38a9344b add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents: 8649
diff changeset
231
23614
cd79fb4d75fd share: add option to share bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents: 23545
diff changeset
232 if bookmarks:
23883
7e71898a7cdc share: replace the bookmarks.shared file with an entry on a new "shared" file
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 23877
diff changeset
233 fp = r.vfs('shared', 'w')
7e71898a7cdc share: replace the bookmarks.shared file with an entry on a new "shared" file
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 23877
diff changeset
234 fp.write('bookmarks\n')
7e71898a7cdc share: replace the bookmarks.shared file with an entry on a new "shared" file
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 23877
diff changeset
235 fp.close()
23614
cd79fb4d75fd share: add option to share bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents: 23545
diff changeset
236
15078
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
237 def copystore(ui, srcrepo, destpath):
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
238 '''copy files from store of srcrepo in destpath
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
239
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
240 returns destlock
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
241 '''
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
242 destlock = None
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
243 try:
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
244 hardlink = None
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
245 num = 0
24440
27ad6b91f5c2 clone: add progress support to hardlink clones (issue3059)
Augie Fackler <augie@google.com>
parents: 24306
diff changeset
246 closetopic = [None]
27ad6b91f5c2 clone: add progress support to hardlink clones (issue3059)
Augie Fackler <augie@google.com>
parents: 24306
diff changeset
247 def prog(topic, pos):
27ad6b91f5c2 clone: add progress support to hardlink clones (issue3059)
Augie Fackler <augie@google.com>
parents: 24306
diff changeset
248 if pos is None:
27ad6b91f5c2 clone: add progress support to hardlink clones (issue3059)
Augie Fackler <augie@google.com>
parents: 24306
diff changeset
249 closetopic[0] = topic
27ad6b91f5c2 clone: add progress support to hardlink clones (issue3059)
Augie Fackler <augie@google.com>
parents: 24306
diff changeset
250 else:
27ad6b91f5c2 clone: add progress support to hardlink clones (issue3059)
Augie Fackler <augie@google.com>
parents: 24306
diff changeset
251 ui.progress(topic, pos + num)
15741
60344b83e442 phases: on copy clone, do not copy phases data if repote is publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15590
diff changeset
252 srcpublishing = srcrepo.ui.configbool('phases', 'publish', True)
20089
2d0ab571b822 hg: rewrite "copystore()" with vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19777
diff changeset
253 srcvfs = scmutil.vfs(srcrepo.sharedpath)
2d0ab571b822 hg: rewrite "copystore()" with vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19777
diff changeset
254 dstvfs = scmutil.vfs(destpath)
15078
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
255 for f in srcrepo.store.copylist():
15741
60344b83e442 phases: on copy clone, do not copy phases data if repote is publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15590
diff changeset
256 if srcpublishing and f.endswith('phaseroots'):
60344b83e442 phases: on copy clone, do not copy phases data if repote is publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15590
diff changeset
257 continue
20089
2d0ab571b822 hg: rewrite "copystore()" with vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19777
diff changeset
258 dstbase = os.path.dirname(f)
2d0ab571b822 hg: rewrite "copystore()" with vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19777
diff changeset
259 if dstbase and not dstvfs.exists(dstbase):
2d0ab571b822 hg: rewrite "copystore()" with vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19777
diff changeset
260 dstvfs.mkdir(dstbase)
2d0ab571b822 hg: rewrite "copystore()" with vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19777
diff changeset
261 if srcvfs.exists(f):
2d0ab571b822 hg: rewrite "copystore()" with vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19777
diff changeset
262 if f.endswith('data'):
20825
dda11e799529 hg: use "os.path.join()" to join path components which may be empty (issue4203)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20355
diff changeset
263 # 'dstbase' may be empty (e.g. revlog format 0)
dda11e799529 hg: use "os.path.join()" to join path components which may be empty (issue4203)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20355
diff changeset
264 lockfile = os.path.join(dstbase, "lock")
15078
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
265 # lock to avoid premature writing to the target
20825
dda11e799529 hg: use "os.path.join()" to join path components which may be empty (issue4203)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20355
diff changeset
266 destlock = lock.lock(dstvfs, lockfile)
20089
2d0ab571b822 hg: rewrite "copystore()" with vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19777
diff changeset
267 hardlink, n = util.copyfiles(srcvfs.join(f), dstvfs.join(f),
24440
27ad6b91f5c2 clone: add progress support to hardlink clones (issue3059)
Augie Fackler <augie@google.com>
parents: 24306
diff changeset
268 hardlink, progress=prog)
15078
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
269 num += n
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
270 if hardlink:
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
271 ui.debug("linked %d files\n" % num)
24440
27ad6b91f5c2 clone: add progress support to hardlink clones (issue3059)
Augie Fackler <augie@google.com>
parents: 24306
diff changeset
272 if closetopic[0]:
27ad6b91f5c2 clone: add progress support to hardlink clones (issue3059)
Augie Fackler <augie@google.com>
parents: 24306
diff changeset
273 ui.progress(closetopic[0], None)
15078
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
274 else:
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
275 ui.debug("copied %d files\n" % num)
24440
27ad6b91f5c2 clone: add progress support to hardlink clones (issue3059)
Augie Fackler <augie@google.com>
parents: 24306
diff changeset
276 if closetopic[0]:
27ad6b91f5c2 clone: add progress support to hardlink clones (issue3059)
Augie Fackler <augie@google.com>
parents: 24306
diff changeset
277 ui.progress(closetopic[0], None)
15078
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
278 return destlock
16705
c2d9ef43ff6c check-code: ignore naked excepts with a "re-raise" comment
Brodie Rao <brodie@sf.io>
parents: 16352
diff changeset
279 except: # re-raises
15078
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
280 release(destlock)
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
281 raise
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
282
14607
bd1acea552ff hg: rename opts argument to peeropts in clone
Martin Geisler <mg@aragost.com>
parents: 14606
diff changeset
283 def clone(ui, peeropts, source, dest=None, pull=False, rev=None,
bd1acea552ff hg: rename opts argument to peeropts in clone
Martin Geisler <mg@aragost.com>
parents: 14606
diff changeset
284 update=True, stream=False, branch=None):
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
285 """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
286
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
287 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
288 source and destination are URLs, as passed to the repository
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
289 function. Returns a pair of repository peers, the source and
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
290 newly created destination.
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
291
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
292 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
293 .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
294 pushes.
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
295
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
296 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
297 repository will be deleted.
2600
c4325f0a9b91 clean up trailing white space.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2597
diff changeset
298
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
299 Arguments:
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
300
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
301 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
302
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
303 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
304 name of source repository)
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
305
23545
68c434799559 hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents: 23139
diff changeset
306 pull: always pull from source repository, even in local case or if the
68c434799559 hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents: 23139
diff changeset
307 server prefers streaming
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
308
2621
5a5852a417b1 clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2613
diff changeset
309 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
310 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
311
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
312 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
313
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
314 update: update working directory after clone completes, if
6526
cfeeac24fc1e repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents: 6525
diff changeset
315 destination is local repository (True means update to default rev,
cfeeac24fc1e repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents: 6525
diff changeset
316 anything else is treated as a revision)
10379
a78bfaf988e1 add -b/--branch option to clone, bundle, incoming, outgoing, pull, push
Sune Foldager <cryo@cyanite.org>
parents: 10365
diff changeset
317
a78bfaf988e1 add -b/--branch option to clone, bundle, incoming, outgoing, pull, push
Sune Foldager <cryo@cyanite.org>
parents: 10365
diff changeset
318 branch: branches to clone
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
319 """
4478
b2b55acbacdd Add support for url#id syntax
Matt Mackall <mpm@selenic.com>
parents: 4477
diff changeset
320
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
321 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
322 origsource = ui.expandpath(source)
10379
a78bfaf988e1 add -b/--branch option to clone, bundle, incoming, outgoing, pull, push
Sune Foldager <cryo@cyanite.org>
parents: 10365
diff changeset
323 source, branch = parseurl(origsource, branch)
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
324 srcpeer = peer(ui, peeropts, source)
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
325 else:
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
326 srcpeer = source.peer() # in case we were called with a localrepo
11818
b1ae33b813cb hg.clone: do not ignore branch argument when source is a repo object
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11544
diff changeset
327 branch = (None, branch or [])
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
328 origsource = source = srcpeer.url()
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
329 rev, checkout = addbranchrevs(srcpeer, srcpeer, branch, rev)
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
330
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
331 if dest is None:
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
332 dest = defaultdest(source)
20800
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
333 if dest:
8253e55930a3 clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 20799
diff changeset
334 ui.status(_("destination directory: %s\n") % dest)
9344
eb6af02307ec Merge with i18n-stable
Matt Mackall <mpm@selenic.com>
parents: 9245
diff changeset
335 else:
eb6af02307ec Merge with i18n-stable
Matt Mackall <mpm@selenic.com>
parents: 9245
diff changeset
336 dest = ui.expandpath(dest)
2719
532809ba1db5 hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2631
diff changeset
337
14825
de9eb6b1da4f util: rename the util.localpath that uses url to urllocalpath (issue2875)
Mads Kiilerich <mads@kiilerich.com>
parents: 14737
diff changeset
338 dest = util.urllocalpath(dest)
de9eb6b1da4f util: rename the util.localpath that uses url to urllocalpath (issue2875)
Mads Kiilerich <mads@kiilerich.com>
parents: 14737
diff changeset
339 source = util.urllocalpath(source)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
340
17159
36a3016811d1 localrepo: use the path relative to "self.vfs" instead of "path" argument
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16705
diff changeset
341 if not dest:
36a3016811d1 localrepo: use the path relative to "self.vfs" instead of "path" argument
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16705
diff changeset
342 raise util.Abort(_("empty destination path is not valid"))
21803
62cc4055c6c8 hg: use vfs functions in clone
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21802
diff changeset
343
62cc4055c6c8 hg: use vfs functions in clone
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21802
diff changeset
344 destvfs = scmutil.vfs(dest, expandpath=True)
62cc4055c6c8 hg: use vfs functions in clone
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21802
diff changeset
345 if destvfs.lexists():
62cc4055c6c8 hg: use vfs functions in clone
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21802
diff changeset
346 if not destvfs.isdir():
7927
a218ba5f60df allow clone into existing but empty directories
Steve Borho <steve@borho.org>
parents: 7821
diff changeset
347 raise util.Abort(_("destination '%s' already exists") % dest)
21804
becb61de90a1 hg: update newly added listdir function of vfs in clone
Chinmay Joshi <c@chinmayjoshi.com>
parents: 21803
diff changeset
348 elif destvfs.listdir():
7927
a218ba5f60df allow clone into existing but empty directories
Steve Borho <steve@borho.org>
parents: 7821
diff changeset
349 raise util.Abort(_("destination '%s' is not empty") % dest)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
350
18441
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
351 srclock = destlock = cleandir = None
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
352 srcrepo = srcpeer.local()
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
353 try:
14377
f90d5641c78b clone: make default path absolute for all local paths
Brendan Cully <brendan@kublai.com>
parents: 14213
diff changeset
354 abspath = origsource
f90d5641c78b clone: make default path absolute for all local paths
Brendan Cully <brendan@kublai.com>
parents: 14213
diff changeset
355 if islocal(origsource):
14825
de9eb6b1da4f util: rename the util.localpath that uses url to urllocalpath (issue2875)
Mads Kiilerich <mads@kiilerich.com>
parents: 14737
diff changeset
356 abspath = os.path.abspath(util.urllocalpath(origsource))
14377
f90d5641c78b clone: make default path absolute for all local paths
Brendan Cully <brendan@kublai.com>
parents: 14213
diff changeset
357
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
358 if islocal(dest):
18441
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
359 cleandir = dest
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
360
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
361 copy = False
17194
32a6a33b9a35 peer: remove cancopy from peer api; use directly on repo instead
Sune Foldager <cryo@cyanite.org>
parents: 17192
diff changeset
362 if (srcrepo and srcrepo.cancopy() and islocal(dest)
17671
fdd0fc046cf1 clfilter: introduce a `hassecret` function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17342
diff changeset
363 and not phases.hassecret(srcrepo)):
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
364 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
365
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
366 if copy:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
367 try:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
368 # 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
369 # 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
370 # 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
371 # fail
14463
81f559d1b9b2 hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents: 14377
diff changeset
372 srclock = srcrepo.lock(wait=False)
7640
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7546
diff changeset
373 except error.LockError:
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
374 copy = False
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
375
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
376 if copy:
14463
81f559d1b9b2 hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents: 14377
diff changeset
377 srcrepo.hook('preoutgoing', throw=True, source='clone')
15381
c519cd8f0169 backout dbdb777502dc (issue3077) (issue3071)
Matt Mackall <mpm@selenic.com>
parents: 15355
diff changeset
378 hgdir = os.path.realpath(os.path.join(dest, ".hg"))
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
379 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
380 os.mkdir(dest)
7935
39566bb99a9c on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents: 7927
diff changeset
381 else:
39566bb99a9c on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents: 7927
diff changeset
382 # only clean up directories we create ourselves
18441
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
383 cleandir = hgdir
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
384 try:
14463
81f559d1b9b2 hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents: 14377
diff changeset
385 destpath = hgdir
81f559d1b9b2 hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents: 14377
diff changeset
386 util.makedir(destpath, notindexed=True)
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
387 except OSError, inst:
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
388 if inst.errno == errno.EEXIST:
18441
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
389 cleandir = None
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
390 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
391 % dest)
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
392 raise
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
393
15078
193e7018dc8c hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents: 14952
diff changeset
394 destlock = copystore(ui, srcrepo, destpath)
22646
d6ecdb8bfa16 clone: copy `.hg/bookmarks` during copy clone
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22618
diff changeset
395 # copy bookmarks over
d6ecdb8bfa16 clone: copy `.hg/bookmarks` during copy clone
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22618
diff changeset
396 srcbookmarks = srcrepo.join('bookmarks')
d6ecdb8bfa16 clone: copy `.hg/bookmarks` during copy clone
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22618
diff changeset
397 dstbookmarks = os.path.join(destpath, 'bookmarks')
d6ecdb8bfa16 clone: copy `.hg/bookmarks` during copy clone
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22618
diff changeset
398 if os.path.exists(srcbookmarks):
d6ecdb8bfa16 clone: copy `.hg/bookmarks` during copy clone
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22618
diff changeset
399 util.copyfile(srcbookmarks, dstbookmarks)
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
400
17740
e6067bec18da branchcache: fetch source branchcache during clone (issue3378)
Tomasz Kleczek <tomasz.kleczek@fb.com>
parents: 17704
diff changeset
401 # Recomputing branch cache might be slow on big repos,
e6067bec18da branchcache: fetch source branchcache during clone (issue3378)
Tomasz Kleczek <tomasz.kleczek@fb.com>
parents: 17704
diff changeset
402 # so just copy it
22264
4bc1fd86e915 clone: for local clones, copy over filtered branchcaches as well (issue4286)
Siddharth Agarwal <sid0@fb.com>
parents: 22263
diff changeset
403 def copybranchcache(fname):
4bc1fd86e915 clone: for local clones, copy over filtered branchcaches as well (issue4286)
Siddharth Agarwal <sid0@fb.com>
parents: 22263
diff changeset
404 srcbranchcache = srcrepo.join('cache/%s' % fname)
4bc1fd86e915 clone: for local clones, copy over filtered branchcaches as well (issue4286)
Siddharth Agarwal <sid0@fb.com>
parents: 22263
diff changeset
405 dstbranchcache = os.path.join(dstcachedir, fname)
4bc1fd86e915 clone: for local clones, copy over filtered branchcaches as well (issue4286)
Siddharth Agarwal <sid0@fb.com>
parents: 22263
diff changeset
406 if os.path.exists(srcbranchcache):
4bc1fd86e915 clone: for local clones, copy over filtered branchcaches as well (issue4286)
Siddharth Agarwal <sid0@fb.com>
parents: 22263
diff changeset
407 if not os.path.exists(dstcachedir):
4bc1fd86e915 clone: for local clones, copy over filtered branchcaches as well (issue4286)
Siddharth Agarwal <sid0@fb.com>
parents: 22263
diff changeset
408 os.mkdir(dstcachedir)
4bc1fd86e915 clone: for local clones, copy over filtered branchcaches as well (issue4286)
Siddharth Agarwal <sid0@fb.com>
parents: 22263
diff changeset
409 util.copyfile(srcbranchcache, dstbranchcache)
4bc1fd86e915 clone: for local clones, copy over filtered branchcaches as well (issue4286)
Siddharth Agarwal <sid0@fb.com>
parents: 22263
diff changeset
410
17740
e6067bec18da branchcache: fetch source branchcache during clone (issue3378)
Tomasz Kleczek <tomasz.kleczek@fb.com>
parents: 17704
diff changeset
411 dstcachedir = os.path.join(destpath, 'cache')
22264
4bc1fd86e915 clone: for local clones, copy over filtered branchcaches as well (issue4286)
Siddharth Agarwal <sid0@fb.com>
parents: 22263
diff changeset
412 # In local clones we're copying all nodes, not just served
23139
e53f6b72a0e4 spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 22837
diff changeset
413 # ones. Therefore copy all branch caches over.
22264
4bc1fd86e915 clone: for local clones, copy over filtered branchcaches as well (issue4286)
Siddharth Agarwal <sid0@fb.com>
parents: 22263
diff changeset
414 copybranchcache('branch2')
4bc1fd86e915 clone: for local clones, copy over filtered branchcaches as well (issue4286)
Siddharth Agarwal <sid0@fb.com>
parents: 22263
diff changeset
415 for cachename in repoview.filtertable:
4bc1fd86e915 clone: for local clones, copy over filtered branchcaches as well (issue4286)
Siddharth Agarwal <sid0@fb.com>
parents: 22263
diff changeset
416 copybranchcache('branch2-%s' % cachename)
17740
e6067bec18da branchcache: fetch source branchcache during clone (issue3378)
Tomasz Kleczek <tomasz.kleczek@fb.com>
parents: 17704
diff changeset
417
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
418 # 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
419 # into it
17874
2ba70eec1cf0 peer: subrepo isolation, pass repo instead of repo.ui to hg.peer
Simon Heimberg <simohe@besonet.ch>
parents: 17872
diff changeset
420 destpeer = peer(srcrepo, peeropts, dest)
14463
81f559d1b9b2 hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents: 14377
diff changeset
421 srcrepo.hook('outgoing', source='clone',
12144
be9c4131a8f4 clone, patch, convert: use hex(nullid) instead of '0'*40
Martin Geisler <mg@lazybytes.net>
parents: 11818
diff changeset
422 node=node.hex(node.nullid))
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
423 else:
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
424 try:
17875
92ba3cd55be6 subrepo: more isolation, only use ui for hg.peer when there is no repo
Simon Heimberg <simohe@besonet.ch>
parents: 17874
diff changeset
425 destpeer = peer(srcrepo or ui, peeropts, dest, create=True)
92ba3cd55be6 subrepo: more isolation, only use ui for hg.peer when there is no repo
Simon Heimberg <simohe@besonet.ch>
parents: 17874
diff changeset
426 # only pass ui when no srcrepo
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
427 except OSError, inst:
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
428 if inst.errno == errno.EEXIST:
18441
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
429 cleandir = None
5569
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
430 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
431 % dest)
9e209193f18d clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents: 5277
diff changeset
432 raise
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
433
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
434 revs = None
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
435 if rev:
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
436 if not srcpeer.capable('lookup'):
9171
a458b9bf4f3a hg: better wrapping of string literal
Martin Geisler <mg@lazybytes.net>
parents: 8907
diff changeset
437 raise util.Abort(_("src repository does not support "
a458b9bf4f3a hg: better wrapping of string literal
Martin Geisler <mg@lazybytes.net>
parents: 8907
diff changeset
438 "revision lookup and so doesn't "
a458b9bf4f3a hg: better wrapping of string literal
Martin Geisler <mg@lazybytes.net>
parents: 8907
diff changeset
439 "support clone by revision"))
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
440 revs = [srcpeer.lookup(r) for r in rev]
8417
39cf453da958 clone: try updating to the actual changeset specified in options
Brett Carter <brett@rdnzl.net>
parents: 8312
diff changeset
441 checkout = revs[0]
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
442 if destpeer.local():
23545
68c434799559 hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents: 23139
diff changeset
443 if not stream:
68c434799559 hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents: 23139
diff changeset
444 if pull:
68c434799559 hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents: 23139
diff changeset
445 stream = False
68c434799559 hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents: 23139
diff changeset
446 else:
68c434799559 hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents: 23139
diff changeset
447 stream = None
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
448 destpeer.local().clone(srcpeer, heads=revs, stream=stream)
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
449 elif srcrepo:
22647
5b6cd8526d56 clone: explicitly push bookmarks when cloning from local to remote
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22646
diff changeset
450 exchange.push(srcrepo, destpeer, revs=revs,
5b6cd8526d56 clone: explicitly push bookmarks when cloning from local to remote
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22646
diff changeset
451 bookmarks=srcrepo._bookmarks.keys())
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
452 else:
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
453 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
454
18441
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
455 cleandir = None
2597
5ba8be56fa8f clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2595
diff changeset
456
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
457 destrepo = destpeer.local()
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
458 if destrepo:
22837
2be7d5ebd4d0 config: use the same hgrc for a cloned repo as for an uninitted repo
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 22818
diff changeset
459 template = uimod.samplehgrcs['cloned']
23877
7cc77030c557 localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 23614
diff changeset
460 fp = destrepo.vfs("hgrc", "w", text=True)
15552
62c9183a0bbb clone: don't save user's password in .hg/hgrc (Issue3122)
Augie Fackler <durin42@gmail.com>
parents: 15381
diff changeset
461 u = util.url(abspath)
62c9183a0bbb clone: don't save user's password in .hg/hgrc (Issue3122)
Augie Fackler <durin42@gmail.com>
parents: 15381
diff changeset
462 u.passwd = None
62c9183a0bbb clone: don't save user's password in .hg/hgrc (Issue3122)
Augie Fackler <durin42@gmail.com>
parents: 15381
diff changeset
463 defaulturl = str(u)
22380
82b2ba904e3e clone: provide sample username = config entry in .hg/hgrc (issue4359)
Augie Fackler <raf@durin42.com>
parents: 22264
diff changeset
464 fp.write(template % defaulturl)
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
465 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
466
20790
49f2d5644f04 config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents: 20355
diff changeset
467 destrepo.ui.setconfig('paths', 'default', defaulturl, 'clone')
8814
ab668c92a036 subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents: 8807
diff changeset
468
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
469 if update:
6526
cfeeac24fc1e repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents: 6525
diff changeset
470 if update is not True:
17342
471f30d360ea clone: don't fail with --update for non-local clones (issue3578)
Augie Fackler <raf@durin42.com>
parents: 17248
diff changeset
471 checkout = srcpeer.lookup(update)
17867
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
472 uprev = None
17882
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
473 status = None
17867
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
474 if checkout is not None:
5248
5517aa5aafb0 Merge with crew-stable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5192 5225
diff changeset
475 try:
17867
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
476 uprev = destrepo.lookup(checkout)
9423
1444a42f6052 Make distinct lookup error for localrepo.lookup
Matt Mackall <mpm@selenic.com>
parents: 9344
diff changeset
477 except error.RepoLookupError:
17867
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
478 pass
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
479 if uprev is None:
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
480 try:
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
481 uprev = destrepo._bookmarks['@']
17870
7d2dd10ce9ea clone: activate @ bookmark if updating to it
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17867
diff changeset
482 update = '@'
17882
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
483 bn = destrepo[uprev].branch()
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
484 if bn == 'default':
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
485 status = _("updating to bookmark @\n")
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
486 else:
20868
5db105f216c3 i18n: fix "% inside _()" problems
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20858
diff changeset
487 status = (_("updating to bookmark @ on branch %s\n")
17882
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
488 % bn)
17867
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
489 except KeyError:
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
490 try:
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
491 uprev = destrepo.branchtip('default')
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
492 except error.RepoLookupError:
c9339efed653 clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17844
diff changeset
493 uprev = destrepo.lookup('tip')
17882
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
494 if not status:
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
495 bn = destrepo[uprev].branch()
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
496 status = _("updating to branch %s\n") % bn
36ed69d4593d clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents: 17875
diff changeset
497 destrepo.ui.status(status)
14463
81f559d1b9b2 hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents: 14377
diff changeset
498 _update(destrepo, uprev)
17703
4a07d2ff7c66 clone: activate bookmark specified with --updaterev
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17342
diff changeset
499 if update in destrepo._bookmarks:
24945
e0b0fbd47491 bookmarks: rename setcurrent to activate (API)
Ryan McElroy <rmcelroy@fb.com>
parents: 24440
diff changeset
500 bookmarks.activate(destrepo, update)
4915
97b734fb9c6f Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents: 4853
diff changeset
501 finally:
15908
60cb4f381a78 bookmarks: backout locking change in 12dea4d998ec
Matt Mackall <mpm@selenic.com>
parents: 15887
diff changeset
502 release(srclock, destlock)
18441
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
503 if cleandir is not None:
1f794204abbd hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents: 18382
diff changeset
504 shutil.rmtree(cleandir, True)
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
505 if srcpeer is not None:
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 17159
diff changeset
506 srcpeer.close()
19313
3b96d6e44a4d hg: move return statement after finally block
simon@laptop-tosh
parents: 18944
diff changeset
507 return srcpeer, destpeer
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
508
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
509 def _showstats(repo, stats):
9454
dafadd7ff07e hg: avoid combining translated strings
Martin Geisler <mg@lazybytes.net>
parents: 9425
diff changeset
510 repo.ui.status(_("%d files updated, %d files merged, "
dafadd7ff07e hg: avoid combining translated strings
Martin Geisler <mg@lazybytes.net>
parents: 9425
diff changeset
511 "%d files removed, %d files unresolved\n") % stats)
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
512
17895
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
513 def updaterepo(repo, node, overwrite):
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
514 """Update the working directory to node.
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
515
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
516 When overwrite is set, changes are clobbered, merged else
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
517
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
518 returns stats (see pydoc mercurial.merge.applyupdates)"""
21537
1ab30e9ba0fc update: specify custom conflict markers for update (BC)
Durham Goode <durham@fb.com>
parents: 21051
diff changeset
519 return mergemod.update(repo, node, False, overwrite, None,
1ab30e9ba0fc update: specify custom conflict markers for update (BC)
Durham Goode <durham@fb.com>
parents: 21051
diff changeset
520 labels=['working copy', 'destination'])
17895
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
521
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
522 def update(repo, node):
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
523 """update the working directory to node, merging linear changes"""
17895
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
524 stats = updaterepo(repo, node, False)
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
525 _showstats(repo, stats)
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
526 if stats[3]:
6518
92ccccb55ba3 resolve: new command
Matt Mackall <mpm@selenic.com>
parents: 6338
diff changeset
527 repo.ui.status(_("use 'hg resolve' to retry unresolved file merges\n"))
5635
0c608a8d9c5f merge: make return codes more sensible
Matt Mackall <mpm@selenic.com>
parents: 5569
diff changeset
528 return stats[3] > 0
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
529
7546
c7f48414f3ad add a comment about the need of hg._update()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7280
diff changeset
530 # naming conflict in clone()
c7f48414f3ad add a comment about the need of hg._update()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7280
diff changeset
531 _update = update
c7f48414f3ad add a comment about the need of hg._update()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7280
diff changeset
532
4917
126f527b3ba3 Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents: 4915
diff changeset
533 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
534 """forcibly switch the working directory to node, clobbering changes"""
17895
17c030014ddf subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents: 17887
diff changeset
535 stats = updaterepo(repo, node, True)
19332
0af993732f66 update: remove .hg/graftstate on clean (issue3970)
Siddharth Agarwal <sid0@fb.com>
parents: 18944
diff changeset
536 util.unlinkpath(repo.join('graftstate'), ignoremissing=True)
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
537 if show_stats:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
538 _showstats(repo, stats)
5635
0c608a8d9c5f merge: make return codes more sensible
Matt Mackall <mpm@selenic.com>
parents: 5569
diff changeset
539 return stats[3] > 0
2775
b550cd82f92a Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents: 2774
diff changeset
540
4917
126f527b3ba3 Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents: 4915
diff changeset
541 def merge(repo, node, force=None, remind=True):
13162
115a9760c382 merge: document some internal return values.
Greg Ward <greg-hg@gerg.ca>
parents: 13047
diff changeset
542 """Branch merge with node, resolving changes. Return true if any
115a9760c382 merge: document some internal return values.
Greg Ward <greg-hg@gerg.ca>
parents: 13047
diff changeset
543 unresolved conflicts."""
10651
5f091fc1bab7 style: use consistent variable names (*mod) with imports which would shadow
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10380
diff changeset
544 stats = mergemod.update(repo, node, True, force, False)
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
545 _showstats(repo, stats)
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
546 if stats[3]:
7821
9fe7e6acf525 merge: better error messages to lead users to hg update --clean to abandon merges.
Augie Fackler <durin42@gmail.com>
parents: 7640
diff changeset
547 repo.ui.status(_("use 'hg resolve' to retry unresolved file merges "
12314
f2daa6ab514a merge: suggest 'hg up -C .' for discarding changes, not 'hg up -C'
Brodie Rao <brodie@bitheap.org>
parents: 12273
diff changeset
548 "or 'hg update -C .' to abandon\n"))
3316
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
549 elif remind:
39fd6e82ea38 merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents: 3195
diff changeset
550 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
551 return stats[3] > 0
2808
30f59f4a327e Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents: 2778
diff changeset
552
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
553 def _incoming(displaychlist, subreporecurse, ui, repo, source,
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
554 opts, buffered=False):
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
555 """
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
556 Helper for incoming / gincoming.
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
557 displaychlist gets called with
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
558 (remoterepo, incomingchangesetlist, displayer) parameters,
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
559 and is supposed to contain only code that can't be unified.
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
560 """
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
561 source, branches = parseurl(ui.expandpath(source), opts.get('branch'))
14556
517e1d88bf7e hg: change various repository() users to use peer() where appropriate
Matt Mackall <mpm@selenic.com>
parents: 14555
diff changeset
562 other = peer(repo, opts, source)
14076
924c82157d46 url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents: 14073
diff changeset
563 ui.status(_('comparing with %s\n') % util.hidepassword(source))
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
564 revs, checkout = addbranchrevs(repo, other, branches, opts.get('rev'))
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
565
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
566 if revs:
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
567 revs = [other.lookup(rev) for rev in revs]
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14156
diff changeset
568 other, chlist, cleanupfn = bundlerepo.getremotechanges(ui, repo, other,
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14156
diff changeset
569 revs, opts["bundle"], opts["force"])
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14156
diff changeset
570 try:
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14156
diff changeset
571 if not chlist:
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14156
diff changeset
572 ui.status(_("no changes found\n"))
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14156
diff changeset
573 return subreporecurse()
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
574
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
575 displayer = cmdutil.show_changeset(ui, other, opts, buffered)
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
576 displaychlist(other, chlist, displayer)
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
577 displayer.close()
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
578 finally:
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14156
diff changeset
579 cleanupfn()
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
580 subreporecurse()
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
581 return 0 # exit code is zero since we found incoming changes
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
582
12273
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
583 def incoming(ui, repo, source, opts):
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
584 def subreporecurse():
12400
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
585 ret = 1
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
586 if opts.get('subrepos'):
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
587 ctx = repo[None]
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
588 for subpath in sorted(ctx.substate):
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
589 sub = ctx.sub(subpath)
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
590 ret = min(ret, sub.incoming(ui, source, opts))
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
591 return ret
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
592
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
593 def display(other, chlist, displayer):
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
594 limit = cmdutil.loglimit(opts)
12273
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
595 if opts.get('newest_first'):
12729
55f0648c7e2d incoming: rename variable
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12400
diff changeset
596 chlist.reverse()
12273
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
597 count = 0
12729
55f0648c7e2d incoming: rename variable
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12400
diff changeset
598 for n in chlist:
12273
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
599 if limit is not None and count >= limit:
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
600 break
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
601 parents = [p for p in other.changelog.parents(n) if p != nullid]
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
602 if opts.get('no_merges') and len(parents) == 2:
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
603 continue
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
604 count += 1
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
605 displayer.show(other[n])
12730
33e1fd2aeb3c incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12729
diff changeset
606 return _incoming(display, subreporecurse, ui, repo, source, opts)
12273
e392d00ab5b0 incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12271
diff changeset
607
12735
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
608 def _outgoing(ui, repo, dest, opts):
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
609 dest = ui.expandpath(dest or 'default-push', dest or 'default')
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
610 dest, branches = parseurl(dest, opts.get('branch'))
14076
924c82157d46 url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents: 14073
diff changeset
611 ui.status(_('comparing with %s\n') % util.hidepassword(dest))
12735
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
612 revs, checkout = addbranchrevs(repo, repo, branches, opts.get('rev'))
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
613 if revs:
17198
ecde35a1af9e outgoing: accept revset argument for --rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 17194
diff changeset
614 revs = [repo.lookup(rev) for rev in scmutil.revrange(repo, revs)]
12735
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
615
14556
517e1d88bf7e hg: change various repository() users to use peer() where appropriate
Matt Mackall <mpm@selenic.com>
parents: 14555
diff changeset
616 other = peer(repo, opts, dest)
18493
fe67107094fd discovery: outgoing pass unfiltered repo to findcommonincoming (issue3776)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18441
diff changeset
617 outgoing = discovery.findcommonoutgoing(repo.unfiltered(), other, revs,
15837
cd956049fc14 discovery: introduce outgoing object for result of findcommonoutgoing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15741
diff changeset
618 force=opts.get('force'))
cd956049fc14 discovery: introduce outgoing object for result of findcommonoutgoing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15741
diff changeset
619 o = outgoing.missing
12735
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
620 if not o:
17248
6ffb35b2284c discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents: 17198
diff changeset
621 scmutil.nochangesfound(repo.ui, repo, outgoing.excluded)
21050
025ec0f08cb6 hg: make "_outgoing()" return peer object for remote repository
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21049
diff changeset
622 return o, other
12735
8888e56ac417 outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12734
diff changeset
623
12271
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
624 def outgoing(ui, repo, dest, opts):
12400
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
625 def recurse():
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
626 ret = 1
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
627 if opts.get('subrepos'):
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
628 ctx = repo[None]
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
629 for subpath in sorted(ctx.substate):
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
630 sub = ctx.sub(subpath)
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
631 ret = min(ret, sub.outgoing(ui, dest, opts))
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
632 return ret
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
633
12271
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
634 limit = cmdutil.loglimit(opts)
21050
025ec0f08cb6 hg: make "_outgoing()" return peer object for remote repository
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21049
diff changeset
635 o, other = _outgoing(ui, repo, dest, opts)
21049
f117a0ba5289 hg: make "_outgoing()" return empty list instead of "None"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20870
diff changeset
636 if not o:
21051
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21050
diff changeset
637 cmdutil.outgoinghooks(ui, repo, other, opts, o)
12400
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
638 return recurse()
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
639
12271
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
640 if opts.get('newest_first'):
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
641 o.reverse()
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
642 displayer = cmdutil.show_changeset(ui, repo, opts)
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
643 count = 0
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
644 for n in o:
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
645 if limit is not None and count >= limit:
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
646 break
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
647 parents = [p for p in repo.changelog.parents(n) if p != nullid]
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
648 if opts.get('no_merges') and len(parents) == 2:
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
649 continue
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
650 count += 1
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
651 displayer.show(repo[n])
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
652 displayer.close()
21051
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21050
diff changeset
653 cmdutil.outgoinghooks(ui, repo, other, opts, o)
12400
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
654 recurse()
40852b4b910c incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents: 12314
diff changeset
655 return 0 # exit code is zero since we found outgoing changes
12271
01dc8ba3e032 outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents: 12144
diff changeset
656
4917
126f527b3ba3 Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents: 4915
diff changeset
657 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
658 """revert changes to revision in node without updating dirstate"""
10651
5f091fc1bab7 style: use consistent variable names (*mod) with imports which would shadow
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10380
diff changeset
659 return mergemod.update(repo, node, False, True, choose)[3] > 0
2778
fdc232d8a193 Move repo.verify
Matt Mackall <mpm@selenic.com>
parents: 2775
diff changeset
660
fdc232d8a193 Move repo.verify
Matt Mackall <mpm@selenic.com>
parents: 2775
diff changeset
661 def verify(repo):
fdc232d8a193 Move repo.verify
Matt Mackall <mpm@selenic.com>
parents: 2775
diff changeset
662 """verify the consistency of a repository"""
10651
5f091fc1bab7 style: use consistent variable names (*mod) with imports which would shadow
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10380
diff changeset
663 return verifymod.verify(repo)
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
664
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
665 def remoteui(src, opts):
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
666 'build a remote ui from ui or repo and opts'
14952
4c523a2af6e7 hg: use safehasattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents: 14839
diff changeset
667 if util.safehasattr(src, 'baseui'): # looks like a repository
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
668 dst = src.baseui.copy() # drop repo-specific config
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
669 src = src.ui # copy target options from repo
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
670 else: # assume it's a global ui object
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
671 dst = src.copy() # keep all global options
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
672
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
673 # copy ssh-specific options
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
674 for o in 'ssh', 'remotecmd':
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
675 v = opts.get(o) or src.config('ui', o)
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
676 if v:
20790
49f2d5644f04 config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents: 20355
diff changeset
677 dst.setconfig("ui", o, v, 'copied')
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
678
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
679 # copy bundle-specific options
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
680 r = src.config('bundle', 'mainreporoot')
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
681 if r:
20790
49f2d5644f04 config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents: 20355
diff changeset
682 dst.setconfig('bundle', 'mainreporoot', r, 'copied')
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
683
13192
4d03707916d3 https: use web.cacerts configuration from local repo to validate remote repo
Mads Kiilerich <mads@kiilerich.com>
parents: 12735
diff changeset
684 # copy selected local settings to the remote ui
13314
8dc488dfcdb4 url: 'ssh known host'-like checking of fingerprints of HTTPS certificates
Mads Kiilerich <mads@kiilerich.com>
parents: 13231
diff changeset
685 for sect in ('auth', 'hostfingerprints', 'http_proxy'):
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
686 for key, val in src.configitems(sect):
20790
49f2d5644f04 config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents: 20355
diff changeset
687 dst.setconfig(sect, key, val, 'copied')
13192
4d03707916d3 https: use web.cacerts configuration from local repo to validate remote repo
Mads Kiilerich <mads@kiilerich.com>
parents: 12735
diff changeset
688 v = src.config('web', 'cacerts')
24290
b76d8c641746 ssl: set explicit symbol "!" to web.cacerts to disable SSL verification (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 23883
diff changeset
689 if v == '!':
b76d8c641746 ssl: set explicit symbol "!" to web.cacerts to disable SSL verification (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 23883
diff changeset
690 dst.setconfig('web', 'cacerts', v, 'copied')
b76d8c641746 ssl: set explicit symbol "!" to web.cacerts to disable SSL verification (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 23883
diff changeset
691 elif v:
20790
49f2d5644f04 config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents: 20355
diff changeset
692 dst.setconfig('web', 'cacerts', util.expandpath(v), 'copied')
11273
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
693
d1908cb95a82 remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents: 11256
diff changeset
694 return dst