Mercurial > hg
annotate mercurial/hg.py @ 39122:5d3b58472660
filemerge: set actual capabilities of internal merge tools
This information is used to detect actual capabilities of internal
merge tools by subsequent patches.
For convenience, this patch assumes that merge tools typed as
"nomerge" have both binary files and symlinks capabilities.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Tue, 14 Aug 2018 20:08:27 +0900 |
parents | d58958676b3c |
children | 143efea71c2a |
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 | 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 | 7 # GNU General Public License version 2 or any later version. |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
8 |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
9 from __future__ import absolute_import |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
10 |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
11 import errno |
38798
d58958676b3c
extensions: add detailed loading information
Martijn Pieters <mj@zopatista.com>
parents:
38753
diff
changeset
|
12 import functools |
29341
0d83ad967bf8
cleanup: replace uses of util.(md5|sha1|sha256|sha512) with hashlib.\1
Augie Fackler <raf@durin42.com>
parents:
29021
diff
changeset
|
13 import hashlib |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
14 import os |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
15 import shutil |
36781
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36702
diff
changeset
|
16 import stat |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
17 |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
18 from .i18n import _ |
35704
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
19 from .node import ( |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
20 nullid, |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
21 ) |
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
|
22 |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
23 from . import ( |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
24 bookmarks, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
25 bundlerepo, |
35766
72fdd99eb526
caches: make 'cachetocopy' available in scmutil
Boris Feld <boris.feld@octobus.net>
parents:
35713
diff
changeset
|
26 cacheutil, |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
27 cmdutil, |
28501
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
28 destutil, |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
29 discovery, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
30 error, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
31 exchange, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
32 extensions, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
33 httppeer, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
34 localrepo, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
35 lock, |
35888
c8e2d6ed1f9e
cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35766
diff
changeset
|
36 logcmdutil, |
35347
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35331
diff
changeset
|
37 logexchange, |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
38 merge as mergemod, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
39 node, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
40 phases, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
41 scmutil, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
42 sshpeer, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
43 statichttprepo, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
44 ui as uimod, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
45 unionrepo, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
46 url, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
47 util, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
48 verify as verifymod, |
31218
4cc3797aa59c
vfs: use 'vfs' module directly in 'mercurial.hg'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31168
diff
changeset
|
49 vfs as vfsmod, |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
50 ) |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
51 |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36781
diff
changeset
|
52 from .utils import ( |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36781
diff
changeset
|
53 stringutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36781
diff
changeset
|
54 ) |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36781
diff
changeset
|
55 |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
56 release = lock.release |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
57 |
29424
f21e0d91d386
share: move magic string to a constant
Martijn Pieters <mjpieters@fb.com>
parents:
29389
diff
changeset
|
58 # shared features |
f21e0d91d386
share: move magic string to a constant
Martijn Pieters <mjpieters@fb.com>
parents:
29389
diff
changeset
|
59 sharedbookmarks = 'bookmarks' |
f21e0d91d386
share: move magic string to a constant
Martijn Pieters <mjpieters@fb.com>
parents:
29389
diff
changeset
|
60 |
2740
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
61 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
|
62 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
|
63 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
|
64 |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
65 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
|
66 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
|
67 hashbranch, branches = branches |
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
68 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
|
69 x = revs or None |
37481
7c848ab13eff
addbranchrevs: no longer accept revset as "revs" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37480
diff
changeset
|
70 if revs: |
22818
d7b114493315
repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22648
diff
changeset
|
71 y = revs[0] |
d7b114493315
repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22648
diff
changeset
|
72 else: |
d7b114493315
repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22648
diff
changeset
|
73 y = None |
d7b114493315
repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22648
diff
changeset
|
74 return x, y |
24306
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24290
diff
changeset
|
75 if revs: |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24290
diff
changeset
|
76 revs = list(revs) |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24290
diff
changeset
|
77 else: |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24290
diff
changeset
|
78 revs = [] |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24290
diff
changeset
|
79 |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
80 if not peer.capable('branchmap'): |
11322
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
81 if branches: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26354
diff
changeset
|
82 raise error.Abort(_("remote branch lookup not supported")) |
11322
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
83 revs.append(hashbranch) |
10380
ee72d89c0d9f
addbranchrevs: fallback for older servers
Sune Foldager <cryo@cyanite.org>
parents:
10379
diff
changeset
|
84 return revs, revs[0] |
37640
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
85 |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
86 with peer.commandexecutor() as e: |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
87 branchmap = e.callcommand('branchmap', {}).result() |
11322
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
88 |
13047
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
12735
diff
changeset
|
89 def primary(branch): |
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
12735
diff
changeset
|
90 if branch == '.': |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
91 if not lrepo: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26354
diff
changeset
|
92 raise error.Abort(_("dirstate branch not accessible")) |
13047
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
12735
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 return True |
10365
d757bc0c7865
interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents:
10358
diff
changeset
|
97 else: |
11322
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
98 return False |
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
99 |
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
100 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
|
101 if not primary(branch): |
11322
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
102 raise error.RepoLookupError(_("unknown branch '%s'") % branch) |
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
103 if hashbranch: |
13047
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
12735
diff
changeset
|
104 if not primary(hashbranch): |
11322
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
105 revs.append(hashbranch) |
10365
d757bc0c7865
interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents:
10358
diff
changeset
|
106 return revs, revs[0] |
d757bc0c7865
interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents:
10358
diff
changeset
|
107 |
13824
ec1695350361
hg: use url.url to parse branch names in parseurl()
Brodie Rao <brodie@bitheap.org>
parents:
13823
diff
changeset
|
108 def parseurl(path, branches=None): |
11322
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
109 '''parse url#branch, returning (url, (branch, branches))''' |
5177
92236732d5a1
move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
4917
diff
changeset
|
110 |
14076
924c82157d46
url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents:
14073
diff
changeset
|
111 u = util.url(path) |
13897
375872fdadba
hg: make parseurl() consistently return normalised path
Thomas Arendsen Hein <thomas@intevation.de>
parents:
13826
diff
changeset
|
112 branch = None |
375872fdadba
hg: make parseurl() consistently return normalised path
Thomas Arendsen Hein <thomas@intevation.de>
parents:
13826
diff
changeset
|
113 if u.fragment: |
375872fdadba
hg: make parseurl() consistently return normalised path
Thomas Arendsen Hein <thomas@intevation.de>
parents:
13826
diff
changeset
|
114 branch = u.fragment |
375872fdadba
hg: make parseurl() consistently return normalised path
Thomas Arendsen Hein <thomas@intevation.de>
parents:
13826
diff
changeset
|
115 u.fragment = None |
31841
9ff5a124d111
py3: replace str() with bytes()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31456
diff
changeset
|
116 return bytes(u), (branch, branches or []) |
5177
92236732d5a1
move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
4917
diff
changeset
|
117 |
14606
6e631c24c6d9
hg: move peerschemes back to schemes
Matt Mackall <mpm@selenic.com>
parents:
14605
diff
changeset
|
118 schemes = { |
14568
5f002e3336ba
hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
119 'bundle': bundlerepo, |
18944
a9c443b3b240
unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
18553
diff
changeset
|
120 'union': unionrepo, |
14568
5f002e3336ba
hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
121 'file': _local, |
17192
1ac628cd7113
peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
17191
diff
changeset
|
122 'http': httppeer, |
1ac628cd7113
peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
17191
diff
changeset
|
123 'https': httppeer, |
1ac628cd7113
peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
17191
diff
changeset
|
124 'ssh': sshpeer, |
14568
5f002e3336ba
hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
125 'static-http': statichttprepo, |
5f002e3336ba
hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
126 } |
5f002e3336ba
hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
127 |
5f002e3336ba
hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
128 def _peerlookup(path): |
5f002e3336ba
hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
129 u = util.url(path) |
5f002e3336ba
hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
130 scheme = u.scheme or 'file' |
14606
6e631c24c6d9
hg: move peerschemes back to schemes
Matt Mackall <mpm@selenic.com>
parents:
14605
diff
changeset
|
131 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
|
132 try: |
5f002e3336ba
hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
133 return thing(path) |
5f002e3336ba
hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
134 except TypeError: |
25365
4cc3fb23881d
hg: explicitly check that peer lookup object has instance() if call failed
Yuya Nishihara <yuya@tcha.org>
parents:
24945
diff
changeset
|
135 # we can't test callable(thing) because 'thing' can be an unloaded |
4cc3fb23881d
hg: explicitly check that peer lookup object has instance() if call failed
Yuya Nishihara <yuya@tcha.org>
parents:
24945
diff
changeset
|
136 # module that implements __call__ |
4cc3fb23881d
hg: explicitly check that peer lookup object has instance() if call failed
Yuya Nishihara <yuya@tcha.org>
parents:
24945
diff
changeset
|
137 if not util.safehasattr(thing, 'instance'): |
4cc3fb23881d
hg: explicitly check that peer lookup object has instance() if call failed
Yuya Nishihara <yuya@tcha.org>
parents:
24945
diff
changeset
|
138 raise |
14568
5f002e3336ba
hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
139 return thing |
5f002e3336ba
hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
140 |
14605
9f1139cf5c76
hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents:
14568
diff
changeset
|
141 def islocal(repo): |
20355
7d269e7620c4
hg: note that islocal only accepts paths pointing to repos
Siddharth Agarwal <sid0@fb.com>
parents:
20354
diff
changeset
|
142 '''return true if repo (or path pointing to repo) is local''' |
33018
071732d9c210
py3: check for bytes instead of str in isinstance
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32970
diff
changeset
|
143 if isinstance(repo, bytes): |
14605
9f1139cf5c76
hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents:
14568
diff
changeset
|
144 try: |
9f1139cf5c76
hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents:
14568
diff
changeset
|
145 return _peerlookup(repo).islocal(repo) |
9f1139cf5c76
hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents:
14568
diff
changeset
|
146 except AttributeError: |
9f1139cf5c76
hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents:
14568
diff
changeset
|
147 return False |
9f1139cf5c76
hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents:
14568
diff
changeset
|
148 return repo.local() |
9f1139cf5c76
hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents:
14568
diff
changeset
|
149 |
17887
0e2846b2482c
url: use open and not url.open for local files (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents:
17882
diff
changeset
|
150 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
|
151 '''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
|
152 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
|
153 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
|
154 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
|
155 else: |
0e2846b2482c
url: use open and not url.open for local files (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents:
17882
diff
changeset
|
156 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
|
157 |
20858
bc56ec9e64df
hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20825
diff
changeset
|
158 # 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
|
159 wirepeersetupfuncs = [] |
bc56ec9e64df
hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20825
diff
changeset
|
160 |
37717
0664be4f0c1f
hg: pass command intents to repo/peer creation (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37640
diff
changeset
|
161 def _peerorrepo(ui, path, create=False, presetupfuncs=None, |
0664be4f0c1f
hg: pass command intents to repo/peer creation (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37640
diff
changeset
|
162 intents=None): |
14605
9f1139cf5c76
hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents:
14568
diff
changeset
|
163 """return a repository object for the specified path""" |
37717
0664be4f0c1f
hg: pass command intents to repo/peer creation (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37640
diff
changeset
|
164 obj = _peerlookup(path).instance(ui, path, create, intents=intents) |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
165 ui = getattr(obj, "ui", ui) |
38798
d58958676b3c
extensions: add detailed loading information
Martijn Pieters <mj@zopatista.com>
parents:
38753
diff
changeset
|
166 if ui.configbool('devel', 'debug.extensions'): |
d58958676b3c
extensions: add detailed loading information
Martijn Pieters <mj@zopatista.com>
parents:
38753
diff
changeset
|
167 log = functools.partial( |
d58958676b3c
extensions: add detailed loading information
Martijn Pieters <mj@zopatista.com>
parents:
38753
diff
changeset
|
168 ui.debug, 'debug.extensions: ', label='debug.extensions') |
d58958676b3c
extensions: add detailed loading information
Martijn Pieters <mj@zopatista.com>
parents:
38753
diff
changeset
|
169 else: |
d58958676b3c
extensions: add detailed loading information
Martijn Pieters <mj@zopatista.com>
parents:
38753
diff
changeset
|
170 log = lambda *a, **kw: None |
32379
71e735bd8170
dispatch: make request accept additional reposetups
Jun Wu <quark@fb.com>
parents:
32172
diff
changeset
|
171 for f in presetupfuncs or []: |
71e735bd8170
dispatch: make request accept additional reposetups
Jun Wu <quark@fb.com>
parents:
32172
diff
changeset
|
172 f(ui, obj) |
38798
d58958676b3c
extensions: add detailed loading information
Martijn Pieters <mj@zopatista.com>
parents:
38753
diff
changeset
|
173 log('- executing reposetup hooks\n') |
19777
6f72e7d28b35
extensions: list up only enabled extensions, if "ui" is specified
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19371
diff
changeset
|
174 for name, module in extensions.extensions(ui): |
38798
d58958676b3c
extensions: add detailed loading information
Martijn Pieters <mj@zopatista.com>
parents:
38753
diff
changeset
|
175 log(' - running reposetup for %s\n' % (name,)) |
14605
9f1139cf5c76
hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents:
14568
diff
changeset
|
176 hook = getattr(module, 'reposetup', None) |
9f1139cf5c76
hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents:
14568
diff
changeset
|
177 if hook: |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
178 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
|
179 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
|
180 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
|
181 f(ui, obj) |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
182 return obj |
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
183 |
37717
0664be4f0c1f
hg: pass command intents to repo/peer creation (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37640
diff
changeset
|
184 def repository(ui, path='', create=False, presetupfuncs=None, intents=None): |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
185 """return a repository object for the specified path""" |
37717
0664be4f0c1f
hg: pass command intents to repo/peer creation (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37640
diff
changeset
|
186 peer = _peerorrepo(ui, path, create, presetupfuncs=presetupfuncs, |
0664be4f0c1f
hg: pass command intents to repo/peer creation (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37640
diff
changeset
|
187 intents=intents) |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
188 repo = peer.local() |
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
189 if not repo: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26354
diff
changeset
|
190 raise error.Abort(_("repository '%s' is not local") % |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
191 (path or peer.url())) |
18382
f3b21beb9802
filtering: rename filters to their antonyms
Kevin Bullock <kbullock@ringworld.org>
parents:
18303
diff
changeset
|
192 return repo.filtered('visible') |
14605
9f1139cf5c76
hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents:
14568
diff
changeset
|
193 |
37717
0664be4f0c1f
hg: pass command intents to repo/peer creation (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37640
diff
changeset
|
194 def peer(uiorrepo, opts, path, create=False, intents=None): |
14554 | 195 '''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
|
196 rui = remoteui(uiorrepo, opts) |
37717
0664be4f0c1f
hg: pass command intents to repo/peer creation (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37640
diff
changeset
|
197 return _peerorrepo(rui, path, create, intents=intents).peer() |
14554 | 198 |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
199 def defaultdest(source): |
20799
069bf1b821c8
clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents:
20790
diff
changeset
|
200 '''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
|
201 |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
33687
diff
changeset
|
202 >>> defaultdest(b'foo') |
20799
069bf1b821c8
clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents:
20790
diff
changeset
|
203 'foo' |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
33687
diff
changeset
|
204 >>> defaultdest(b'/foo/bar') |
20799
069bf1b821c8
clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents:
20790
diff
changeset
|
205 'bar' |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
33687
diff
changeset
|
206 >>> defaultdest(b'/') |
20799
069bf1b821c8
clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents:
20790
diff
changeset
|
207 '' |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
33687
diff
changeset
|
208 >>> defaultdest(b'') |
20800
8253e55930a3
clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
20799
diff
changeset
|
209 '' |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
33687
diff
changeset
|
210 >>> defaultdest(b'http://example.org/') |
20800
8253e55930a3
clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
20799
diff
changeset
|
211 '' |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
33687
diff
changeset
|
212 >>> defaultdest(b'http://example.org/foo/') |
20799
069bf1b821c8
clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents:
20790
diff
changeset
|
213 'foo' |
069bf1b821c8
clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents:
20790
diff
changeset
|
214 ''' |
20800
8253e55930a3
clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
20799
diff
changeset
|
215 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
|
216 if not path: |
8253e55930a3
clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
20799
diff
changeset
|
217 return '' |
8253e55930a3
clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
20799
diff
changeset
|
218 return os.path.basename(os.path.normpath(path)) |
2774 | 219 |
36159
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
220 def sharedreposource(repo): |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
221 """Returns repository object for source repository of a shared repo. |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
222 |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
223 If repo is not a shared repository, returns None. |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
224 """ |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
225 if repo.sharedpath == repo.path: |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
226 return None |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
227 |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
228 if util.safehasattr(repo, 'srcrepo') and repo.srcrepo: |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
229 return repo.srcrepo |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
230 |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
231 # the sharedpath always ends in the .hg; we want the path to the repo |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
232 source = repo.vfs.split(repo.sharedpath)[0] |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
233 srcurl, branches = parseurl(source) |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
234 srcrepo = repository(repo.ui, srcurl) |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
235 repo.srcrepo = srcrepo |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
236 return srcrepo |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
237 |
31133
23080c03a604
share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
31058
diff
changeset
|
238 def share(ui, source, dest=None, update=True, bookmarks=True, defaultpath=None, |
23080c03a604
share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
31058
diff
changeset
|
239 relative=False): |
8800
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
240 '''create a shared repository''' |
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
241 |
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
242 if not islocal(source): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26354
diff
changeset
|
243 raise error.Abort(_('can only share local repositories')) |
8800
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
244 |
8807
8bf6eb68ddaf
share: allow dest to default to the basename of source
Matt Mackall <mpm@selenic.com>
parents:
8800
diff
changeset
|
245 if not dest: |
10099
f5e46dfb38c7
share: use defaultdest to compute unspecified destination
Brendan Cully <brendan@kublai.com>
parents:
9984
diff
changeset
|
246 dest = defaultdest(source) |
9344 | 247 else: |
248 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
|
249 |
36049
488e313954ea
py3: check for bytes instead of str in hg.share()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36003
diff
changeset
|
250 if isinstance(source, bytes): |
8800
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
251 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
|
252 source, branches = parseurl(origsource) |
8800
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
253 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
|
254 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
|
255 else: |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
256 srcrepo = source.local() |
8800
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
257 origsource = source = srcrepo.url() |
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
258 checkout = None |
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
259 |
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
260 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
|
261 |
31218
4cc3797aa59c
vfs: use 'vfs' module directly in 'mercurial.hg'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31168
diff
changeset
|
262 destwvfs = vfsmod.vfs(dest, realpath=True) |
4cc3797aa59c
vfs: use 'vfs' module directly in 'mercurial.hg'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31168
diff
changeset
|
263 destvfs = vfsmod.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
|
264 |
21801
2ccd71bbd0f7
hg: update to use vfs functions in shared destination repository
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21800
diff
changeset
|
265 if destvfs.lexists(): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26354
diff
changeset
|
266 raise error.Abort(_('destination already exists')) |
8800
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
267 |
21800
219af1521a6a
hg: use vfs functions in destination repository with share
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21537
diff
changeset
|
268 if not destwvfs.isdir(): |
219af1521a6a
hg: use vfs functions in destination repository with share
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21537
diff
changeset
|
269 destwvfs.mkdir() |
21801
2ccd71bbd0f7
hg: update to use vfs functions in shared destination repository
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21800
diff
changeset
|
270 destvfs.makedir() |
8800
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
271 |
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
272 requirements = '' |
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
273 try: |
23877
7cc77030c557
localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
23614
diff
changeset
|
274 requirements = srcrepo.vfs.read('requires') |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25624
diff
changeset
|
275 except IOError as inst: |
8800
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
276 if inst.errno != errno.ENOENT: |
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
277 raise |
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
278 |
31133
23080c03a604
share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
31058
diff
changeset
|
279 if relative: |
23080c03a604
share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
31058
diff
changeset
|
280 try: |
23080c03a604
share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
31058
diff
changeset
|
281 sharedpath = os.path.relpath(sharedpath, destvfs.base) |
23080c03a604
share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
31058
diff
changeset
|
282 requirements += 'relshared\n' |
34979
b64ea7fb9599
share: handle --relative shares to a different drive letter gracefully
Matt Harbison <matt_harbison@yahoo.com>
parents:
34879
diff
changeset
|
283 except (IOError, ValueError) as e: |
b64ea7fb9599
share: handle --relative shares to a different drive letter gracefully
Matt Harbison <matt_harbison@yahoo.com>
parents:
34879
diff
changeset
|
284 # ValueError is raised on Windows if the drive letters differ on |
b64ea7fb9599
share: handle --relative shares to a different drive letter gracefully
Matt Harbison <matt_harbison@yahoo.com>
parents:
34879
diff
changeset
|
285 # each path |
31133
23080c03a604
share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
31058
diff
changeset
|
286 raise error.Abort(_('cannot calculate relative path'), |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36781
diff
changeset
|
287 hint=stringutil.forcebytestr(e)) |
31133
23080c03a604
share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
31058
diff
changeset
|
288 else: |
23080c03a604
share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
31058
diff
changeset
|
289 requirements += 'shared\n' |
23080c03a604
share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
31058
diff
changeset
|
290 |
21802
ff27fad408c4
hg: update util.writefile method to use write with vfs in share
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21801
diff
changeset
|
291 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
|
292 destvfs.write('sharedpath', sharedpath) |
8800
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
293 |
21800
219af1521a6a
hg: use vfs functions in destination repository with share
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21537
diff
changeset
|
294 r = repository(ui, destwvfs.base) |
30041
1779dde4c9ef
hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29902
diff
changeset
|
295 postshare(srcrepo, r, bookmarks=bookmarks, defaultpath=defaultpath) |
28632
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
296 _postshareupdate(r, update, checkout=checkout) |
34815
68e0bcb90357
subrepo: share instead of clone if the parent repo is shared (issue5675) (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
34805
diff
changeset
|
297 return r |
8800
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
298 |
34878
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
299 def unshare(ui, repo): |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
300 """convert a shared repository to a normal one |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
301 |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
302 Copy the store data to the repo and remove the sharedpath data. |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
303 """ |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
304 |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
305 destlock = lock = None |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
306 lock = repo.lock() |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
307 try: |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
308 # we use locks here because if we race with commit, we |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
309 # can end up with extra data in the cloned revlogs that's |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
310 # not pointed to by changesets, thus causing verify to |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
311 # fail |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
312 |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
313 destlock = copystore(ui, repo, repo.path) |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
314 |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
315 sharefile = repo.vfs.join('sharedpath') |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
316 util.rename(sharefile, sharefile + '.old') |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
317 |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
318 repo.requirements.discard('shared') |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
319 repo.requirements.discard('relshared') |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
320 repo._writerequirements() |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
321 finally: |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
322 destlock and destlock.release() |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
323 lock and lock.release() |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
324 |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
325 # update store, spath, svfs and sjoin of repo |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
326 repo.unfiltered().__init__(repo.baseui, repo.root) |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
327 |
34879
7d51a7792f52
subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
34878
diff
changeset
|
328 # TODO: figure out how to access subrepos that exist, but were previously |
7d51a7792f52
subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
34878
diff
changeset
|
329 # removed from .hgsub |
7d51a7792f52
subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
34878
diff
changeset
|
330 c = repo['.'] |
7d51a7792f52
subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
34878
diff
changeset
|
331 subs = c.substate |
7d51a7792f52
subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
34878
diff
changeset
|
332 for s in sorted(subs): |
7d51a7792f52
subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
34878
diff
changeset
|
333 c.sub(s).unshare() |
7d51a7792f52
subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
34878
diff
changeset
|
334 |
30041
1779dde4c9ef
hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29902
diff
changeset
|
335 def postshare(sourcerepo, destrepo, bookmarks=True, defaultpath=None): |
27354
bced7180db19
hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27344
diff
changeset
|
336 """Called after a new shared repo is created. |
bced7180db19
hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27344
diff
changeset
|
337 |
bced7180db19
hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27344
diff
changeset
|
338 The new repo only has a requirements file and pointer to the source. |
bced7180db19
hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27344
diff
changeset
|
339 This function configures additional shared data. |
bced7180db19
hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27344
diff
changeset
|
340 |
bced7180db19
hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27344
diff
changeset
|
341 Extensions can wrap this function and write additional entries to |
bced7180db19
hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27344
diff
changeset
|
342 destrepo/.hg/shared to indicate additional pieces of data to be shared. |
bced7180db19
hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27344
diff
changeset
|
343 """ |
30041
1779dde4c9ef
hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29902
diff
changeset
|
344 default = defaultpath or sourcerepo.ui.config('paths', 'default') |
27354
bced7180db19
hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27344
diff
changeset
|
345 if default: |
35622
e925f33ac088
share: convert EOL of hgrc before writing to bytes IO
Yuya Nishihara <yuya@tcha.org>
parents:
35620
diff
changeset
|
346 template = ('[paths]\n' |
e925f33ac088
share: convert EOL of hgrc before writing to bytes IO
Yuya Nishihara <yuya@tcha.org>
parents:
35620
diff
changeset
|
347 'default = %s\n') |
e925f33ac088
share: convert EOL of hgrc before writing to bytes IO
Yuya Nishihara <yuya@tcha.org>
parents:
35620
diff
changeset
|
348 destrepo.vfs.write('hgrc', util.tonativeeol(template % default)) |
27354
bced7180db19
hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27344
diff
changeset
|
349 |
29753
e93408080646
shared: take wlock for writting the 'shared' file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29645
diff
changeset
|
350 with destrepo.wlock(): |
e93408080646
shared: take wlock for writting the 'shared' file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29645
diff
changeset
|
351 if bookmarks: |
35619
c751b9fdbc40
share: use context manager or utility function to write file
Yuya Nishihara <yuya@tcha.org>
parents:
35582
diff
changeset
|
352 destrepo.vfs.write('shared', sharedbookmarks + '\n') |
23614
cd79fb4d75fd
share: add option to share bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents:
23545
diff
changeset
|
353 |
28632
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
354 def _postshareupdate(repo, update, checkout=None): |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
355 """Maybe perform a working directory update after a shared repo is created. |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
356 |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
357 ``update`` can be a boolean or a revision to update to. |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
358 """ |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
359 if not update: |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
360 return |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
361 |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
362 repo.ui.status(_("updating working directory\n")) |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
363 if update is not True: |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
364 checkout = update |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
365 for test in (checkout, 'default', 'tip'): |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
366 if test is None: |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
367 continue |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
368 try: |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
369 uprev = repo.lookup(test) |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
370 break |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
371 except error.RepoLookupError: |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
372 continue |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
373 _update(repo, uprev) |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
374 |
15078
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
375 def copystore(ui, srcrepo, destpath): |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
376 '''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
|
377 |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
378 returns destlock |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
379 ''' |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
380 destlock = None |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
381 try: |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
382 hardlink = None |
38380
63e6f5ae84bc
copystore: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
37717
diff
changeset
|
383 topic = _('linking') if hardlink else _('copying') |
63e6f5ae84bc
copystore: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
37717
diff
changeset
|
384 progress = ui.makeprogress(topic) |
15078
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
385 num = 0 |
25624
f0745da75056
publishing: use new helper method
Matt Mackall <mpm@selenic.com>
parents:
25591
diff
changeset
|
386 srcpublishing = srcrepo.publishing() |
31218
4cc3797aa59c
vfs: use 'vfs' module directly in 'mercurial.hg'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31168
diff
changeset
|
387 srcvfs = vfsmod.vfs(srcrepo.sharedpath) |
4cc3797aa59c
vfs: use 'vfs' module directly in 'mercurial.hg'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31168
diff
changeset
|
388 dstvfs = vfsmod.vfs(destpath) |
15078
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
389 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
|
390 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
|
391 continue |
20089
2d0ab571b822
hg: rewrite "copystore()" with vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19777
diff
changeset
|
392 dstbase = os.path.dirname(f) |
2d0ab571b822
hg: rewrite "copystore()" with vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19777
diff
changeset
|
393 if dstbase and not dstvfs.exists(dstbase): |
2d0ab571b822
hg: rewrite "copystore()" with vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19777
diff
changeset
|
394 dstvfs.mkdir(dstbase) |
2d0ab571b822
hg: rewrite "copystore()" with vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19777
diff
changeset
|
395 if srcvfs.exists(f): |
2d0ab571b822
hg: rewrite "copystore()" with vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19777
diff
changeset
|
396 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
|
397 # '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
|
398 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
|
399 # 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
|
400 destlock = lock.lock(dstvfs, lockfile) |
20089
2d0ab571b822
hg: rewrite "copystore()" with vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19777
diff
changeset
|
401 hardlink, n = util.copyfiles(srcvfs.join(f), dstvfs.join(f), |
38380
63e6f5ae84bc
copystore: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
37717
diff
changeset
|
402 hardlink, progress) |
15078
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
403 num += n |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
404 if hardlink: |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
405 ui.debug("linked %d files\n" % num) |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
406 else: |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
407 ui.debug("copied %d files\n" % num) |
38380
63e6f5ae84bc
copystore: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
37717
diff
changeset
|
408 progress.complete() |
15078
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
409 return destlock |
16705
c2d9ef43ff6c
check-code: ignore naked excepts with a "re-raise" comment
Brodie Rao <brodie@sf.io>
parents:
16352
diff
changeset
|
410 except: # re-raises |
15078
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
411 release(destlock) |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
412 raise |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
413 |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
414 def clonewithshare(ui, peeropts, sharepath, source, srcpeer, dest, pull=False, |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
415 rev=None, update=True, stream=False): |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
416 """Perform a clone using a shared repo. |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
417 |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
418 The store for the repository will be located at <sharepath>/.hg. The |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
419 specified revisions will be cloned or pulled from "source". A shared repo |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
420 will be created at "dest" and a working copy will be created if "update" is |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
421 True. |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
422 """ |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
423 revs = None |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
424 if rev: |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
425 if not srcpeer.capable('lookup'): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26354
diff
changeset
|
426 raise error.Abort(_("src repository does not support " |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
427 "revision lookup and so doesn't " |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
428 "support clone by revision")) |
37640
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
429 |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
430 # TODO this is batchable. |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
431 remoterevs = [] |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
432 for r in rev: |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
433 with srcpeer.commandexecutor() as e: |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
434 remoterevs.append(e.callcommand('lookup', { |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
435 'key': r, |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
436 }).result()) |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
437 revs = remoterevs |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
438 |
28289
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
439 # Obtain a lock before checking for or cloning the pooled repo otherwise |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
440 # 2 clients may race creating or populating it. |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
441 pooldir = os.path.dirname(sharepath) |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
442 # lock class requires the directory to exist. |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
443 try: |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
444 util.makedir(pooldir, False) |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
445 except OSError as e: |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
446 if e.errno != errno.EEXIST: |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
447 raise |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
448 |
31218
4cc3797aa59c
vfs: use 'vfs' module directly in 'mercurial.hg'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31168
diff
changeset
|
449 poolvfs = vfsmod.vfs(pooldir) |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
450 basename = os.path.basename(sharepath) |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
451 |
28289
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
452 with lock.lock(poolvfs, '%s.lock' % basename): |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
453 if os.path.exists(sharepath): |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
454 ui.status(_('(sharing from existing pooled repository %s)\n') % |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
455 basename) |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
456 else: |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
457 ui.status(_('(sharing from new pooled repository %s)\n') % basename) |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
458 # Always use pull mode because hardlinks in share mode don't work |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
459 # well. Never update because working copies aren't necessary in |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
460 # share mode. |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
461 clone(ui, peeropts, source, dest=sharepath, pull=True, |
37262
54435fd09f1d
clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents:
37261
diff
changeset
|
462 revs=rev, update=False, stream=stream) |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
463 |
30041
1779dde4c9ef
hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29902
diff
changeset
|
464 # Resolve the value to put in [paths] section for the source. |
1779dde4c9ef
hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29902
diff
changeset
|
465 if islocal(source): |
1779dde4c9ef
hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29902
diff
changeset
|
466 defaultpath = os.path.abspath(util.urllocalpath(source)) |
1779dde4c9ef
hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29902
diff
changeset
|
467 else: |
1779dde4c9ef
hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29902
diff
changeset
|
468 defaultpath = source |
1779dde4c9ef
hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29902
diff
changeset
|
469 |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
470 sharerepo = repository(ui, path=sharepath) |
30041
1779dde4c9ef
hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29902
diff
changeset
|
471 share(ui, sharerepo, dest=dest, update=False, bookmarks=False, |
1779dde4c9ef
hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29902
diff
changeset
|
472 defaultpath=defaultpath) |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
473 |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
474 # We need to perform a pull against the dest repo to fetch bookmarks |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
475 # and other non-store data that isn't shared by default. In the case of |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
476 # non-existing shared repo, this means we pull from the remote twice. This |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
477 # is a bit weird. But at the time it was implemented, there wasn't an easy |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
478 # way to pull just non-changegroup data. |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
479 destrepo = repository(ui, path=dest) |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
480 exchange.pull(destrepo, srcpeer, heads=revs) |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
481 |
28632
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
482 _postshareupdate(destrepo, update) |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
483 |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
484 return srcpeer, peer(ui, peeropts, dest) |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
485 |
32492
963de566de2f
local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32379
diff
changeset
|
486 # Recomputing branch cache might be slow on big repos, |
963de566de2f
local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32379
diff
changeset
|
487 # so just copy it |
963de566de2f
local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32379
diff
changeset
|
488 def _copycache(srcrepo, dstcachedir, fname): |
963de566de2f
local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32379
diff
changeset
|
489 """copy a cache from srcrepo to destcachedir (if it exists)""" |
963de566de2f
local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32379
diff
changeset
|
490 srcbranchcache = srcrepo.vfs.join('cache/%s' % fname) |
963de566de2f
local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32379
diff
changeset
|
491 dstbranchcache = os.path.join(dstcachedir, fname) |
963de566de2f
local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32379
diff
changeset
|
492 if os.path.exists(srcbranchcache): |
963de566de2f
local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32379
diff
changeset
|
493 if not os.path.exists(dstcachedir): |
963de566de2f
local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32379
diff
changeset
|
494 os.mkdir(dstcachedir) |
963de566de2f
local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32379
diff
changeset
|
495 util.copyfile(srcbranchcache, dstbranchcache) |
963de566de2f
local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32379
diff
changeset
|
496 |
37262
54435fd09f1d
clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents:
37261
diff
changeset
|
497 def clone(ui, peeropts, source, dest=None, pull=False, revs=None, |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
498 update=True, stream=False, branch=None, shareopts=None): |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
499 """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
|
500 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
501 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
|
502 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
|
503 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
|
504 newly created destination. |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
505 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
506 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
|
507 .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
|
508 pushes. |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
509 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
510 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
|
511 repository will be deleted. |
2600
c4325f0a9b91
clean up trailing white space.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2597
diff
changeset
|
512 |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
513 Arguments: |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
514 |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
515 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
|
516 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
517 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
|
518 name of source repository) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
519 |
23545
68c434799559
hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents:
23139
diff
changeset
|
520 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
|
521 server prefers streaming |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
522 |
2621
5a5852a417b1
clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2613
diff
changeset
|
523 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
|
524 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
|
525 |
37262
54435fd09f1d
clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents:
37261
diff
changeset
|
526 revs: revision to clone up to (implies pull=True) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
527 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
528 update: update working directory after clone completes, if |
6526
cfeeac24fc1e
repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents:
6525
diff
changeset
|
529 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
|
530 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
|
531 |
a78bfaf988e1
add -b/--branch option to clone, bundle, incoming, outgoing, pull, push
Sune Foldager <cryo@cyanite.org>
parents:
10365
diff
changeset
|
532 branch: branches to clone |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
533 |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
534 shareopts: dict of options to control auto sharing behavior. The "pool" key |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
535 activates auto sharing mode and defines the directory for stores. The |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
536 "mode" key determines how to construct the directory name of the shared |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
537 repository. "identity" means the name is derived from the node of the first |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
538 changeset in the repository. "remote" means the name is derived from the |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
539 remote's path/URL. Defaults to "identity." |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
540 """ |
4478
b2b55acbacdd
Add support for url#id syntax
Matt Mackall <mpm@selenic.com>
parents:
4477
diff
changeset
|
541 |
32970
11c0bb4ccc76
py3: replace str with bytes in isinstance()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32495
diff
changeset
|
542 if isinstance(source, bytes): |
6089
28054773438c
clone: make things work when source is a repo object
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
6088
diff
changeset
|
543 origsource = ui.expandpath(source) |
37261
3809eafedf2c
parseurl: consistently call second output "branches"
Martin von Zweigbergk <martinvonz@google.com>
parents:
37125
diff
changeset
|
544 source, branches = parseurl(origsource, branch) |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
545 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
|
546 else: |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
547 srcpeer = source.peer() # in case we were called with a localrepo |
37261
3809eafedf2c
parseurl: consistently call second output "branches"
Martin von Zweigbergk <martinvonz@google.com>
parents:
37125
diff
changeset
|
548 branches = (None, branch or []) |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
549 origsource = source = srcpeer.url() |
37262
54435fd09f1d
clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents:
37261
diff
changeset
|
550 revs, checkout = addbranchrevs(srcpeer, srcpeer, branches, revs) |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
551 |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
552 if dest is None: |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
553 dest = defaultdest(source) |
20800
8253e55930a3
clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
20799
diff
changeset
|
554 if dest: |
8253e55930a3
clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
20799
diff
changeset
|
555 ui.status(_("destination directory: %s\n") % dest) |
9344 | 556 else: |
557 dest = ui.expandpath(dest) | |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
558 |
14825
de9eb6b1da4f
util: rename the util.localpath that uses url to urllocalpath (issue2875)
Mads Kiilerich <mads@kiilerich.com>
parents:
14737
diff
changeset
|
559 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
|
560 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
|
561 |
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
|
562 if not dest: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26354
diff
changeset
|
563 raise error.Abort(_("empty destination path is not valid")) |
21803
62cc4055c6c8
hg: use vfs functions in clone
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21802
diff
changeset
|
564 |
31218
4cc3797aa59c
vfs: use 'vfs' module directly in 'mercurial.hg'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31168
diff
changeset
|
565 destvfs = vfsmod.vfs(dest, expandpath=True) |
21803
62cc4055c6c8
hg: use vfs functions in clone
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21802
diff
changeset
|
566 if destvfs.lexists(): |
62cc4055c6c8
hg: use vfs functions in clone
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21802
diff
changeset
|
567 if not destvfs.isdir(): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26354
diff
changeset
|
568 raise error.Abort(_("destination '%s' already exists") % dest) |
21804
becb61de90a1
hg: update newly added listdir function of vfs in clone
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21803
diff
changeset
|
569 elif destvfs.listdir(): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26354
diff
changeset
|
570 raise error.Abort(_("destination '%s' is not empty") % dest) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
571 |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
572 shareopts = shareopts or {} |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
573 sharepool = shareopts.get('pool') |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
574 sharenamemode = shareopts.get('mode') |
26026
d08e7449ff27
hg: avoid auto sharing when the clone destination is remote
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25761
diff
changeset
|
575 if sharepool and islocal(dest): |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
576 sharepath = None |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
577 if sharenamemode == 'identity': |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
578 # Resolve the name from the initial changeset in the remote |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
579 # repository. This returns nullid when the remote is empty. It |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
580 # raises RepoLookupError if revision 0 is filtered or otherwise |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
581 # not available. If we fail to resolve, sharing is not enabled. |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
582 try: |
37640
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
583 with srcpeer.commandexecutor() as e: |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
584 rootnode = e.callcommand('lookup', { |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
585 'key': '0', |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
586 }).result() |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
587 |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
588 if rootnode != node.nullid: |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
589 sharepath = os.path.join(sharepool, node.hex(rootnode)) |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
590 else: |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
591 ui.status(_('(not using pooled storage: ' |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
592 'remote appears to be empty)\n')) |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
593 except error.RepoLookupError: |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
594 ui.status(_('(not using pooled storage: ' |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
595 'unable to resolve identity of remote)\n')) |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
596 elif sharenamemode == 'remote': |
29341
0d83ad967bf8
cleanup: replace uses of util.(md5|sha1|sha256|sha512) with hashlib.\1
Augie Fackler <raf@durin42.com>
parents:
29021
diff
changeset
|
597 sharepath = os.path.join( |
35582
72b91f905065
py3: use node.hex(h.digest()) instead of h.hexdigest()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35565
diff
changeset
|
598 sharepool, node.hex(hashlib.sha1(source).digest())) |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
599 else: |
29389
98e8313dcd9e
i18n: translate abort messages
liscju <piotr.listkiewicz@gmail.com>
parents:
29341
diff
changeset
|
600 raise error.Abort(_('unknown share naming mode: %s') % |
98e8313dcd9e
i18n: translate abort messages
liscju <piotr.listkiewicz@gmail.com>
parents:
29341
diff
changeset
|
601 sharenamemode) |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
602 |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
603 if sharepath: |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
604 return clonewithshare(ui, peeropts, sharepath, source, srcpeer, |
37262
54435fd09f1d
clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents:
37261
diff
changeset
|
605 dest, pull=pull, rev=revs, update=update, |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
606 stream=stream) |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
607 |
18441
1f794204abbd
hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents:
18382
diff
changeset
|
608 srclock = destlock = cleandir = None |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
609 srcrepo = srcpeer.local() |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
610 try: |
14377
f90d5641c78b
clone: make default path absolute for all local paths
Brendan Cully <brendan@kublai.com>
parents:
14213
diff
changeset
|
611 abspath = origsource |
f90d5641c78b
clone: make default path absolute for all local paths
Brendan Cully <brendan@kublai.com>
parents:
14213
diff
changeset
|
612 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
|
613 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
|
614 |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
615 if islocal(dest): |
18441
1f794204abbd
hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents:
18382
diff
changeset
|
616 cleandir = dest |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
617 |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
618 copy = False |
17194
32a6a33b9a35
peer: remove cancopy from peer api; use directly on repo instead
Sune Foldager <cryo@cyanite.org>
parents:
17192
diff
changeset
|
619 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
|
620 and not phases.hassecret(srcrepo)): |
37262
54435fd09f1d
clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents:
37261
diff
changeset
|
621 copy = not pull and not revs |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
622 |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
623 if copy: |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
624 try: |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
625 # 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
|
626 # 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
|
627 # 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
|
628 # fail |
14463
81f559d1b9b2
hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents:
14377
diff
changeset
|
629 srclock = srcrepo.lock(wait=False) |
7640 | 630 except error.LockError: |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
631 copy = False |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
632 |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
633 if copy: |
14463
81f559d1b9b2
hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents:
14377
diff
changeset
|
634 srcrepo.hook('preoutgoing', throw=True, source='clone') |
15381
c519cd8f0169
backout dbdb777502dc (issue3077) (issue3071)
Matt Mackall <mpm@selenic.com>
parents:
15355
diff
changeset
|
635 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
|
636 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
|
637 os.mkdir(dest) |
7935
39566bb99a9c
on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents:
7927
diff
changeset
|
638 else: |
39566bb99a9c
on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents:
7927
diff
changeset
|
639 # 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
|
640 cleandir = hgdir |
5569
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
641 try: |
14463
81f559d1b9b2
hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents:
14377
diff
changeset
|
642 destpath = hgdir |
81f559d1b9b2
hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents:
14377
diff
changeset
|
643 util.makedir(destpath, notindexed=True) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25624
diff
changeset
|
644 except OSError as inst: |
5569
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
645 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
|
646 cleandir = None |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26354
diff
changeset
|
647 raise error.Abort(_("destination '%s' already exists") |
5569
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
648 % dest) |
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
649 raise |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
650 |
15078
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
651 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
|
652 # copy bookmarks over |
31322
4282feb79432
hg-mod: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31311
diff
changeset
|
653 srcbookmarks = srcrepo.vfs.join('bookmarks') |
22646
d6ecdb8bfa16
clone: copy `.hg/bookmarks` during copy clone
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22618
diff
changeset
|
654 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
|
655 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
|
656 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
|
657 |
17740
e6067bec18da
branchcache: fetch source branchcache during clone (issue3378)
Tomasz Kleczek <tomasz.kleczek@fb.com>
parents:
17704
diff
changeset
|
658 dstcachedir = os.path.join(destpath, 'cache') |
35766
72fdd99eb526
caches: make 'cachetocopy' available in scmutil
Boris Feld <boris.feld@octobus.net>
parents:
35713
diff
changeset
|
659 for cache in cacheutil.cachetocopy(srcrepo): |
32493
3c8a71a8df11
local-clone: extract the listing of caches to copy
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32492
diff
changeset
|
660 _copycache(srcrepo, dstcachedir, cache) |
17740
e6067bec18da
branchcache: fetch source branchcache during clone (issue3378)
Tomasz Kleczek <tomasz.kleczek@fb.com>
parents:
17704
diff
changeset
|
661 |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
662 # 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
|
663 # 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
|
664 destpeer = peer(srcrepo, peeropts, dest) |
14463
81f559d1b9b2
hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents:
14377
diff
changeset
|
665 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
|
666 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
|
667 else: |
5569
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
668 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
|
669 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
|
670 # only pass ui when no srcrepo |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25624
diff
changeset
|
671 except OSError as inst: |
5569
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
672 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
|
673 cleandir = None |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26354
diff
changeset
|
674 raise error.Abort(_("destination '%s' already exists") |
5569
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
675 % dest) |
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
676 raise |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
677 |
37262
54435fd09f1d
clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents:
37261
diff
changeset
|
678 if revs: |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
679 if not srcpeer.capable('lookup'): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26354
diff
changeset
|
680 raise error.Abort(_("src repository does not support " |
9171
a458b9bf4f3a
hg: better wrapping of string literal
Martin Geisler <mg@lazybytes.net>
parents:
8907
diff
changeset
|
681 "revision lookup and so doesn't " |
a458b9bf4f3a
hg: better wrapping of string literal
Martin Geisler <mg@lazybytes.net>
parents:
8907
diff
changeset
|
682 "support clone by revision")) |
37640
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
683 |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
684 # TODO this is batchable. |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
685 remoterevs = [] |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
686 for rev in revs: |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
687 with srcpeer.commandexecutor() as e: |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
688 remoterevs.append(e.callcommand('lookup', { |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
689 'key': rev, |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
690 }).result()) |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
691 revs = remoterevs |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
692 |
8417
39cf453da958
clone: try updating to the actual changeset specified in options
Brett Carter <brett@rdnzl.net>
parents:
8312
diff
changeset
|
693 checkout = revs[0] |
37262
54435fd09f1d
clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents:
37261
diff
changeset
|
694 else: |
54435fd09f1d
clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents:
37261
diff
changeset
|
695 revs = None |
27165
70884715725e
localrepo: remove clone method by hoisting into hg.py
Augie Fackler <augie@google.com>
parents:
26781
diff
changeset
|
696 local = destpeer.local() |
70884715725e
localrepo: remove clone method by hoisting into hg.py
Augie Fackler <augie@google.com>
parents:
26781
diff
changeset
|
697 if local: |
35565
bdae51a83dfb
clonebundle: make it possible to retrieve the initial bundle through largefile
Boris Feld <boris.feld@octobus.net>
parents:
35438
diff
changeset
|
698 u = util.url(abspath) |
bdae51a83dfb
clonebundle: make it possible to retrieve the initial bundle through largefile
Boris Feld <boris.feld@octobus.net>
parents:
35438
diff
changeset
|
699 defaulturl = bytes(u) |
bdae51a83dfb
clonebundle: make it possible to retrieve the initial bundle through largefile
Boris Feld <boris.feld@octobus.net>
parents:
35438
diff
changeset
|
700 local.ui.setconfig('paths', 'default', defaulturl, 'clone') |
23545
68c434799559
hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents:
23139
diff
changeset
|
701 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
|
702 if pull: |
68c434799559
hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents:
23139
diff
changeset
|
703 stream = False |
68c434799559
hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents:
23139
diff
changeset
|
704 else: |
68c434799559
hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents:
23139
diff
changeset
|
705 stream = None |
27165
70884715725e
localrepo: remove clone method by hoisting into hg.py
Augie Fackler <augie@google.com>
parents:
26781
diff
changeset
|
706 # internal config: ui.quietbookmarkmove |
31456 | 707 overrides = {('ui', 'quietbookmarkmove'): True} |
708 with local.ui.configoverride(overrides, 'clone'): | |
27165
70884715725e
localrepo: remove clone method by hoisting into hg.py
Augie Fackler <augie@google.com>
parents:
26781
diff
changeset
|
709 exchange.pull(local, srcpeer, revs, |
70884715725e
localrepo: remove clone method by hoisting into hg.py
Augie Fackler <augie@google.com>
parents:
26781
diff
changeset
|
710 streamclonerequested=stream) |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
711 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
|
712 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
|
713 bookmarks=srcrepo._bookmarks.keys()) |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
714 else: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26354
diff
changeset
|
715 raise error.Abort(_("clone from remote to remote not supported") |
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26354
diff
changeset
|
716 ) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
717 |
18441
1f794204abbd
hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents:
18382
diff
changeset
|
718 cleandir = None |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
719 |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
720 destrepo = destpeer.local() |
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
721 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
|
722 template = uimod.samplehgrcs['cloned'] |
15552
62c9183a0bbb
clone: don't save user's password in .hg/hgrc (Issue3122)
Augie Fackler <durin42@gmail.com>
parents:
15381
diff
changeset
|
723 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
|
724 u.passwd = None |
33687
6294654453ee
py3: use bytes IO to write sample hgrc
Yuya Nishihara <yuya@tcha.org>
parents:
33018
diff
changeset
|
725 defaulturl = bytes(u) |
35620
545967ec33dc
clone: use utility function to write hgrc
Yuya Nishihara <yuya@tcha.org>
parents:
35619
diff
changeset
|
726 destrepo.vfs.write('hgrc', util.tonativeeol(template % defaulturl)) |
20790
49f2d5644f04
config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents:
20355
diff
changeset
|
727 destrepo.ui.setconfig('paths', 'default', defaulturl, 'clone') |
8814
ab668c92a036
subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents:
8807
diff
changeset
|
728 |
35331
773a9a06047c
clone: add support for storing remotenames while cloning
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34979
diff
changeset
|
729 if ui.configbool('experimental', 'remotenames'): |
35347
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35331
diff
changeset
|
730 logexchange.pullremotenames(destrepo, srcpeer) |
35331
773a9a06047c
clone: add support for storing remotenames while cloning
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34979
diff
changeset
|
731 |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
732 if update: |
6526
cfeeac24fc1e
repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents:
6525
diff
changeset
|
733 if update is not True: |
37640
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
734 with srcpeer.commandexecutor() as e: |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
735 checkout = e.callcommand('lookup', { |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
736 'key': update, |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
737 }).result() |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
738 |
17867
c9339efed653
clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17844
diff
changeset
|
739 uprev = None |
17882
36ed69d4593d
clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents:
17875
diff
changeset
|
740 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
|
741 if checkout is not None: |
38753
e06a10d3b926
clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents:
38380
diff
changeset
|
742 # Some extensions (at least hg-git and hg-subversion) have |
e06a10d3b926
clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents:
38380
diff
changeset
|
743 # a peer.lookup() implementation that returns a name instead |
e06a10d3b926
clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents:
38380
diff
changeset
|
744 # of a nodeid. We work around it here until we've figured |
e06a10d3b926
clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents:
38380
diff
changeset
|
745 # out a better solution. |
e06a10d3b926
clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents:
38380
diff
changeset
|
746 if len(checkout) == 20 and checkout in destrepo: |
37480
c569e51ee449
clone: avoid using repo.lookup() with binary nodeid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37313
diff
changeset
|
747 uprev = checkout |
38753
e06a10d3b926
clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents:
38380
diff
changeset
|
748 elif scmutil.isrevsymbol(destrepo, checkout): |
e06a10d3b926
clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents:
38380
diff
changeset
|
749 uprev = scmutil.revsymbol(destrepo, checkout).node() |
37480
c569e51ee449
clone: avoid using repo.lookup() with binary nodeid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37313
diff
changeset
|
750 else: |
26354
c1fb2cab6260
clone: check update rev for being True
Sean Farley <sean@farley.io>
parents:
26353
diff
changeset
|
751 if update is not True: |
c1fb2cab6260
clone: check update rev for being True
Sean Farley <sean@farley.io>
parents:
26353
diff
changeset
|
752 try: |
c1fb2cab6260
clone: check update rev for being True
Sean Farley <sean@farley.io>
parents:
26353
diff
changeset
|
753 uprev = destrepo.lookup(update) |
c1fb2cab6260
clone: check update rev for being True
Sean Farley <sean@farley.io>
parents:
26353
diff
changeset
|
754 except error.RepoLookupError: |
c1fb2cab6260
clone: check update rev for being True
Sean Farley <sean@farley.io>
parents:
26353
diff
changeset
|
755 pass |
17867
c9339efed653
clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17844
diff
changeset
|
756 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
|
757 try: |
c9339efed653
clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17844
diff
changeset
|
758 uprev = destrepo._bookmarks['@'] |
17870
7d2dd10ce9ea
clone: activate @ bookmark if updating to it
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17867
diff
changeset
|
759 update = '@' |
17882
36ed69d4593d
clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents:
17875
diff
changeset
|
760 bn = destrepo[uprev].branch() |
36ed69d4593d
clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents:
17875
diff
changeset
|
761 if bn == 'default': |
36ed69d4593d
clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents:
17875
diff
changeset
|
762 status = _("updating to bookmark @\n") |
36ed69d4593d
clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents:
17875
diff
changeset
|
763 else: |
20868
5db105f216c3
i18n: fix "% inside _()" problems
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20858
diff
changeset
|
764 status = (_("updating to bookmark @ on branch %s\n") |
26353
7c20d501709b
clone: fix over-indented continuation line
Sean Farley <sean@farley.io>
parents:
26240
diff
changeset
|
765 % 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
|
766 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
|
767 try: |
c9339efed653
clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17844
diff
changeset
|
768 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
|
769 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
|
770 uprev = destrepo.lookup('tip') |
17882
36ed69d4593d
clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents:
17875
diff
changeset
|
771 if not status: |
36ed69d4593d
clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents:
17875
diff
changeset
|
772 bn = destrepo[uprev].branch() |
36ed69d4593d
clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents:
17875
diff
changeset
|
773 status = _("updating to branch %s\n") % bn |
36ed69d4593d
clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents:
17875
diff
changeset
|
774 destrepo.ui.status(status) |
14463
81f559d1b9b2
hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents:
14377
diff
changeset
|
775 _update(destrepo, uprev) |
17703
4a07d2ff7c66
clone: activate bookmark specified with --updaterev
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17342
diff
changeset
|
776 if update in destrepo._bookmarks: |
24945
e0b0fbd47491
bookmarks: rename setcurrent to activate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24440
diff
changeset
|
777 bookmarks.activate(destrepo, update) |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
778 finally: |
15908
60cb4f381a78
bookmarks: backout locking change in 12dea4d998ec
Matt Mackall <mpm@selenic.com>
parents:
15887
diff
changeset
|
779 release(srclock, destlock) |
18441
1f794204abbd
hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents:
18382
diff
changeset
|
780 if cleandir is not None: |
1f794204abbd
hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents:
18382
diff
changeset
|
781 shutil.rmtree(cleandir, True) |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
782 if srcpeer is not None: |
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
783 srcpeer.close() |
19313
3b96d6e44a4d
hg: move return statement after finally block
simon@laptop-tosh
parents:
18944
diff
changeset
|
784 return srcpeer, destpeer |
2775
b550cd82f92a
Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents:
2774
diff
changeset
|
785 |
27402
5184089f5d30
hg: add quietempty flag to _showstats
timeless <timeless@mozdev.org>
parents:
27354
diff
changeset
|
786 def _showstats(repo, stats, quietempty=False): |
37125
6f570c501e3e
merge: deprecate accessing update results by index
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37107
diff
changeset
|
787 if quietempty and stats.isempty(): |
27402
5184089f5d30
hg: add quietempty flag to _showstats
timeless <timeless@mozdev.org>
parents:
27354
diff
changeset
|
788 return |
9454
dafadd7ff07e
hg: avoid combining translated strings
Martin Geisler <mg@lazybytes.net>
parents:
9425
diff
changeset
|
789 repo.ui.status(_("%d files updated, %d files merged, " |
37107
71543b942eea
merge: return an attrs class from update() and applyupdates()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37084
diff
changeset
|
790 "%d files removed, %d files unresolved\n") % ( |
71543b942eea
merge: return an attrs class from update() and applyupdates()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37084
diff
changeset
|
791 stats.updatedcount, stats.mergedcount, |
71543b942eea
merge: return an attrs class from update() and applyupdates()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37084
diff
changeset
|
792 stats.removedcount, stats.unresolvedcount)) |
3316
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
793 |
31166
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
794 def updaterepo(repo, node, overwrite, updatecheck=None): |
17895
17c030014ddf
subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents:
17887
diff
changeset
|
795 """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
|
796 |
17c030014ddf
subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents:
17887
diff
changeset
|
797 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
|
798 |
17c030014ddf
subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents:
17887
diff
changeset
|
799 returns stats (see pydoc mercurial.merge.applyupdates)""" |
27344
43c00ca887d1
merge: have merge.update use a matcher instead of partial fn
Augie Fackler <augie@google.com>
parents:
27165
diff
changeset
|
800 return mergemod.update(repo, node, False, overwrite, |
31166
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
801 labels=['working copy', 'destination'], |
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
802 updatecheck=updatecheck) |
17895
17c030014ddf
subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents:
17887
diff
changeset
|
803 |
31166
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
804 def update(repo, node, quietempty=False, updatecheck=None): |
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
805 """update the working directory to node""" |
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
806 stats = updaterepo(repo, node, False, updatecheck=updatecheck) |
27404
1cf3543cc780
update: add quietempty flag to _showstats
timeless <timeless@mozdev.org>
parents:
27403
diff
changeset
|
807 _showstats(repo, stats, quietempty) |
37125
6f570c501e3e
merge: deprecate accessing update results by index
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37107
diff
changeset
|
808 if stats.unresolvedcount: |
6518 | 809 repo.ui.status(_("use 'hg resolve' to retry unresolved file merges\n")) |
37125
6f570c501e3e
merge: deprecate accessing update results by index
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37107
diff
changeset
|
810 return stats.unresolvedcount > 0 |
2775
b550cd82f92a
Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents:
2774
diff
changeset
|
811 |
7546
c7f48414f3ad
add a comment about the need of hg._update()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7280
diff
changeset
|
812 # 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
|
813 _update = update |
c7f48414f3ad
add a comment about the need of hg._update()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7280
diff
changeset
|
814 |
27403
50b6a04f817f
histedit: omit useless message from abort
timeless <timeless@mozdev.org>
parents:
27402
diff
changeset
|
815 def clean(repo, node, show_stats=True, quietempty=False): |
2808
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
816 """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
|
817 stats = updaterepo(repo, node, True) |
31311
f59b6cf663a9
vfs: use repo.vfs.unlinkpath
Mads Kiilerich <mads@kiilerich.com>
parents:
31218
diff
changeset
|
818 repo.vfs.unlinkpath('graftstate', ignoremissing=True) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
819 if show_stats: |
27403
50b6a04f817f
histedit: omit useless message from abort
timeless <timeless@mozdev.org>
parents:
27402
diff
changeset
|
820 _showstats(repo, stats, quietempty) |
37125
6f570c501e3e
merge: deprecate accessing update results by index
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37107
diff
changeset
|
821 return stats.unresolvedcount > 0 |
2775
b550cd82f92a
Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents:
2774
diff
changeset
|
822 |
28501
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
823 # naming conflict in updatetotally() |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
824 _clean = clean |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
825 |
31166
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
826 def updatetotally(ui, repo, checkout, brev, clean=False, updatecheck=None): |
28501
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
827 """Update the working directory with extra care for non-file components |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
828 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
829 This takes care of non-file components below: |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
830 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
831 :bookmark: might be advanced or (in)activated |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
832 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
833 This takes arguments below: |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
834 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
835 :checkout: to which revision the working directory is updated |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
836 :brev: a name, which might be a bookmark to be activated after updating |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
837 :clean: whether changes in the working directory can be discarded |
31166
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
838 :updatecheck: how to deal with a dirty working directory |
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
839 |
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
840 Valid values for updatecheck are (None => linear): |
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
841 |
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
842 * abort: abort if the working directory is dirty |
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
843 * none: don't check (merge working directory changes into destination) |
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
844 * linear: check that update is linear before merging working directory |
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
845 changes into destination |
31168
41a9edc5d00f
update: allow setting default update check to "noconflict"
Martin von Zweigbergk <martinvonz@google.com>
parents:
31167
diff
changeset
|
846 * noconflict: check that the update does not result in file merges |
28501
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
847 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
848 This returns whether conflict is detected at updating or not. |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
849 """ |
31166
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
850 if updatecheck is None: |
34705
23ed47a895d5
config: graduate experimental.updatecheck to commands.update.check
Augie Fackler <augie@google.com>
parents:
34131
diff
changeset
|
851 updatecheck = ui.config('commands', 'update.check') |
31168
41a9edc5d00f
update: allow setting default update check to "noconflict"
Martin von Zweigbergk <martinvonz@google.com>
parents:
31167
diff
changeset
|
852 if updatecheck not in ('abort', 'none', 'linear', 'noconflict'): |
31167
696e321b304d
update: add experimental config for default way of handling dirty wdir
Martin von Zweigbergk <martinvonz@google.com>
parents:
31166
diff
changeset
|
853 # If not configured, or invalid value configured |
696e321b304d
update: add experimental config for default way of handling dirty wdir
Martin von Zweigbergk <martinvonz@google.com>
parents:
31166
diff
changeset
|
854 updatecheck = 'linear' |
28503
138ec8835e63
hg: acquire wlock while updating the working directory via updatetotally
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28501
diff
changeset
|
855 with repo.wlock(): |
28501
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
856 movemarkfrom = None |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
857 warndest = False |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
858 if checkout is None: |
30962
11c253997b0e
destutil: drop now-unused "check" parameter from destupdate()
Martin von Zweigbergk <martinvonz@google.com>
parents:
30062
diff
changeset
|
859 updata = destutil.destupdate(repo, clean=clean) |
28501
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
860 checkout, movemarkfrom, brev = updata |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
861 warndest = True |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
862 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
863 if clean: |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
864 ret = _clean(repo, checkout) |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
865 else: |
31166
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
866 if updatecheck == 'abort': |
30963
7beb3ec34443
update: move check for dirty wdir into hg.updatetotally()
Martin von Zweigbergk <martinvonz@google.com>
parents:
30962
diff
changeset
|
867 cmdutil.bailifchanged(repo, merge=False) |
31166
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
868 updatecheck = 'none' |
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
869 ret = _update(repo, checkout, updatecheck=updatecheck) |
28501
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
870 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
871 if not ret and movemarkfrom: |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
872 if movemarkfrom == repo['.'].node(): |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
873 pass # no-op update |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
874 elif bookmarks.update(repo, [movemarkfrom], repo['.'].node()): |
29902
a77d48219edd
update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29753
diff
changeset
|
875 b = ui.label(repo._activebookmark, 'bookmarks.active') |
a77d48219edd
update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29753
diff
changeset
|
876 ui.status(_("updating bookmark %s\n") % b) |
28501
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
877 else: |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
878 # this can happen with a non-linear update |
29902
a77d48219edd
update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29753
diff
changeset
|
879 b = ui.label(repo._activebookmark, 'bookmarks') |
a77d48219edd
update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29753
diff
changeset
|
880 ui.status(_("(leaving bookmark %s)\n") % b) |
28501
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
881 bookmarks.deactivate(repo) |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
882 elif brev in repo._bookmarks: |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
883 if brev != repo._activebookmark: |
29902
a77d48219edd
update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29753
diff
changeset
|
884 b = ui.label(brev, 'bookmarks.active') |
a77d48219edd
update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29753
diff
changeset
|
885 ui.status(_("(activating bookmark %s)\n") % b) |
28501
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
886 bookmarks.activate(repo, brev) |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
887 elif brev: |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
888 if repo._activebookmark: |
29902
a77d48219edd
update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29753
diff
changeset
|
889 b = ui.label(repo._activebookmark, 'bookmarks') |
a77d48219edd
update: label bookmark name in message
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29753
diff
changeset
|
890 ui.status(_("(leaving bookmark %s)\n") % b) |
28501
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
891 bookmarks.deactivate(repo) |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
892 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
893 if warndest: |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
894 destutil.statusotherdests(ui, repo) |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
895 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
896 return ret |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
897 |
35704
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
898 def merge(repo, node, force=None, remind=True, mergeforce=False, labels=None, |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
899 abort=False): |
13162
115a9760c382
merge: document some internal return values.
Greg Ward <greg-hg@gerg.ca>
parents:
13047
diff
changeset
|
900 """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
|
901 unresolved conflicts.""" |
35704
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
902 if not abort: |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
903 stats = mergemod.update(repo, node, True, force, mergeforce=mergeforce, |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
904 labels=labels) |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
905 else: |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
906 ms = mergemod.mergestate.read(repo) |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
907 if ms.active(): |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
908 # there were conflicts |
35713
7ffbd911dbc9
merge: use public interface ms.localctx instead of ms._local
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35704
diff
changeset
|
909 node = ms.localctx.hex() |
35704
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
910 else: |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
911 # there were no conficts, mergestate was not stored |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
912 node = repo['.'].hex() |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
913 |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
914 repo.ui.status(_("aborting the merge, updating back to" |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
915 " %s\n") % node[:12]) |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
916 stats = mergemod.update(repo, node, branchmerge=False, force=True, |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
917 labels=labels) |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
918 |
3316
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
919 _showstats(repo, stats) |
37125
6f570c501e3e
merge: deprecate accessing update results by index
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37107
diff
changeset
|
920 if stats.unresolvedcount: |
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
|
921 repo.ui.status(_("use 'hg resolve' to retry unresolved file merges " |
35704
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
922 "or 'hg merge --abort' to abandon\n")) |
41ef02ba329b
merge: add `--abort` flag which can abort the merge
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35622
diff
changeset
|
923 elif remind and not abort: |
3316
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
924 repo.ui.status(_("(branch merge, don't forget to commit)\n")) |
37125
6f570c501e3e
merge: deprecate accessing update results by index
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37107
diff
changeset
|
925 return stats.unresolvedcount > 0 |
2808
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
926 |
12730
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
927 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
|
928 opts, buffered=False): |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
929 """ |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
930 Helper for incoming / gincoming. |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
931 displaychlist gets called with |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
932 (remoterepo, incomingchangesetlist, displayer) parameters, |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
933 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
|
934 """ |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
935 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
|
936 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
|
937 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
|
938 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
|
939 |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
940 if revs: |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
941 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
|
942 other, chlist, cleanupfn = bundlerepo.getremotechanges(ui, repo, other, |
8a0fca925992
bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14156
diff
changeset
|
943 revs, opts["bundle"], opts["force"]) |
8a0fca925992
bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14156
diff
changeset
|
944 try: |
8a0fca925992
bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14156
diff
changeset
|
945 if not chlist: |
8a0fca925992
bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14156
diff
changeset
|
946 ui.status(_("no changes found\n")) |
8a0fca925992
bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14156
diff
changeset
|
947 return subreporecurse() |
31057
16d7db8f752c
incoming: delay pager activation until right before printing changes
Augie Fackler <augie@google.com>
parents:
30963
diff
changeset
|
948 ui.pager('incoming') |
36003
fcde8946c553
logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35888
diff
changeset
|
949 displayer = logcmdutil.changesetdisplayer(ui, other, opts, |
fcde8946c553
logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35888
diff
changeset
|
950 buffered=buffered) |
12730
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
951 displaychlist(other, chlist, displayer) |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
952 displayer.close() |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
953 finally: |
14161
8a0fca925992
bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14156
diff
changeset
|
954 cleanupfn() |
12730
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
955 subreporecurse() |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
956 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
|
957 |
12273
e392d00ab5b0
incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12271
diff
changeset
|
958 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
|
959 def subreporecurse(): |
12400
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
960 ret = 1 |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
961 if opts.get('subrepos'): |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
962 ctx = repo[None] |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
963 for subpath in sorted(ctx.substate): |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
964 sub = ctx.sub(subpath) |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
965 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
|
966 return ret |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
967 |
12730
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
968 def display(other, chlist, displayer): |
35888
c8e2d6ed1f9e
cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35766
diff
changeset
|
969 limit = logcmdutil.getlimit(opts) |
12273
e392d00ab5b0
incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12271
diff
changeset
|
970 if opts.get('newest_first'): |
12729
55f0648c7e2d
incoming: rename variable
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12400
diff
changeset
|
971 chlist.reverse() |
12273
e392d00ab5b0
incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12271
diff
changeset
|
972 count = 0 |
12729
55f0648c7e2d
incoming: rename variable
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12400
diff
changeset
|
973 for n in chlist: |
12273
e392d00ab5b0
incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12271
diff
changeset
|
974 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
|
975 break |
e392d00ab5b0
incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12271
diff
changeset
|
976 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
|
977 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
|
978 continue |
e392d00ab5b0
incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12271
diff
changeset
|
979 count += 1 |
e392d00ab5b0
incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12271
diff
changeset
|
980 displayer.show(other[n]) |
12730
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
981 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
|
982 |
12735
8888e56ac417
outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12734
diff
changeset
|
983 def _outgoing(ui, repo, dest, opts): |
35438
0ebd94ac56d1
outgoing: respect ":pushurl" paths (issue5365)
Hollis Blanchard <hollis_blanchard@mentor.com>
parents:
35347
diff
changeset
|
984 path = ui.paths.getpath(dest, default=('default-push', 'default')) |
0ebd94ac56d1
outgoing: respect ":pushurl" paths (issue5365)
Hollis Blanchard <hollis_blanchard@mentor.com>
parents:
35347
diff
changeset
|
985 if not path: |
0ebd94ac56d1
outgoing: respect ":pushurl" paths (issue5365)
Hollis Blanchard <hollis_blanchard@mentor.com>
parents:
35347
diff
changeset
|
986 raise error.Abort(_('default repository not configured!'), |
0ebd94ac56d1
outgoing: respect ":pushurl" paths (issue5365)
Hollis Blanchard <hollis_blanchard@mentor.com>
parents:
35347
diff
changeset
|
987 hint=_("see 'hg help config.paths'")) |
0ebd94ac56d1
outgoing: respect ":pushurl" paths (issue5365)
Hollis Blanchard <hollis_blanchard@mentor.com>
parents:
35347
diff
changeset
|
988 dest = path.pushloc or path.loc |
0ebd94ac56d1
outgoing: respect ":pushurl" paths (issue5365)
Hollis Blanchard <hollis_blanchard@mentor.com>
parents:
35347
diff
changeset
|
989 branches = path.branch, opts.get('branch') or [] |
0ebd94ac56d1
outgoing: respect ":pushurl" paths (issue5365)
Hollis Blanchard <hollis_blanchard@mentor.com>
parents:
35347
diff
changeset
|
990 |
14076
924c82157d46
url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents:
14073
diff
changeset
|
991 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
|
992 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
|
993 if revs: |
37313
70c52800940b
outgoing: avoid repo.lookup() for converting revnum to nodeid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37262
diff
changeset
|
994 revs = [repo[rev].node() for rev in scmutil.revrange(repo, revs)] |
12735
8888e56ac417
outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12734
diff
changeset
|
995 |
14556
517e1d88bf7e
hg: change various repository() users to use peer() where appropriate
Matt Mackall <mpm@selenic.com>
parents:
14555
diff
changeset
|
996 other = peer(repo, opts, dest) |
32172
448ed4d3ee90
outgoing: run on filtered repo
Martin von Zweigbergk <martinvonz@google.com>
parents:
31841
diff
changeset
|
997 outgoing = discovery.findcommonoutgoing(repo, 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
|
998 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
|
999 o = outgoing.missing |
12735
8888e56ac417
outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12734
diff
changeset
|
1000 if not o: |
17248
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17198
diff
changeset
|
1001 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
|
1002 return o, other |
12735
8888e56ac417
outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12734
diff
changeset
|
1003 |
12271
01dc8ba3e032
outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12144
diff
changeset
|
1004 def outgoing(ui, repo, dest, opts): |
12400
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1005 def recurse(): |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1006 ret = 1 |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1007 if opts.get('subrepos'): |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1008 ctx = repo[None] |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1009 for subpath in sorted(ctx.substate): |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1010 sub = ctx.sub(subpath) |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1011 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
|
1012 return ret |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1013 |
35888
c8e2d6ed1f9e
cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35766
diff
changeset
|
1014 limit = logcmdutil.getlimit(opts) |
21050
025ec0f08cb6
hg: make "_outgoing()" return peer object for remote repository
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21049
diff
changeset
|
1015 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
|
1016 if not o: |
21051
1004d3cd65fd
outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21050
diff
changeset
|
1017 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
|
1018 return recurse() |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1019 |
12271
01dc8ba3e032
outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12144
diff
changeset
|
1020 if opts.get('newest_first'): |
01dc8ba3e032
outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12144
diff
changeset
|
1021 o.reverse() |
31058
d2ed0abce08e
outgoing: avoid running pager until we're actually showing changes
Augie Fackler <augie@google.com>
parents:
31057
diff
changeset
|
1022 ui.pager('outgoing') |
35888
c8e2d6ed1f9e
cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35766
diff
changeset
|
1023 displayer = logcmdutil.changesetdisplayer(ui, repo, opts) |
12271
01dc8ba3e032
outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12144
diff
changeset
|
1024 count = 0 |
01dc8ba3e032
outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12144
diff
changeset
|
1025 for n in o: |
01dc8ba3e032
outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12144
diff
changeset
|
1026 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
|
1027 break |
01dc8ba3e032
outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12144
diff
changeset
|
1028 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
|
1029 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
|
1030 continue |
01dc8ba3e032
outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12144
diff
changeset
|
1031 count += 1 |
01dc8ba3e032
outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12144
diff
changeset
|
1032 displayer.show(repo[n]) |
01dc8ba3e032
outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12144
diff
changeset
|
1033 displayer.close() |
21051
1004d3cd65fd
outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21050
diff
changeset
|
1034 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
|
1035 recurse() |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1036 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
|
1037 |
2778 | 1038 def verify(repo): |
1039 """verify the consistency of a repository""" | |
25591
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1040 ret = verifymod.verify(repo) |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1041 |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1042 # Broken subrepo references in hidden csets don't seem worth worrying about, |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1043 # since they can't be pushed/pulled, and --hidden can be used if they are a |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1044 # concern. |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1045 |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1046 # pathto() is needed for -R case |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1047 revs = repo.revs("filelog(%s)", |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1048 util.pathto(repo.root, repo.getcwd(), '.hgsubstate')) |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1049 |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1050 if revs: |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1051 repo.ui.status(_('checking subrepo links\n')) |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1052 for rev in revs: |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1053 ctx = repo[rev] |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1054 try: |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1055 for subpath in ctx.substate: |
29021
92d37fb3f1aa
verify: don't init subrepo when missing one is referenced (issue5128) (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
28655
diff
changeset
|
1056 try: |
92d37fb3f1aa
verify: don't init subrepo when missing one is referenced (issue5128) (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
28655
diff
changeset
|
1057 ret = (ctx.sub(subpath, allowcreate=False).verify() |
92d37fb3f1aa
verify: don't init subrepo when missing one is referenced (issue5128) (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
28655
diff
changeset
|
1058 or ret) |
92d37fb3f1aa
verify: don't init subrepo when missing one is referenced (issue5128) (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
28655
diff
changeset
|
1059 except error.RepoError as e: |
37579
ce566e0f73d0
py3: use '%d' for integers instead of '%s'
Pulkit Goyal <7895pulkit@gmail.com>
parents:
37481
diff
changeset
|
1060 repo.ui.warn(('%d: %s\n') % (rev, e)) |
25591
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1061 except Exception: |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1062 repo.ui.warn(_('.hgsubstate is corrupt in revision %s\n') % |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1063 node.short(ctx.node())) |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1064 |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1065 return ret |
11273
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1066 |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1067 def remoteui(src, opts): |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1068 '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
|
1069 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
|
1070 dst = src.baseui.copy() # drop repo-specific config |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1071 src = src.ui # copy target options from repo |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1072 else: # assume it's a global ui object |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1073 dst = src.copy() # keep all global options |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1074 |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1075 # copy ssh-specific options |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1076 for o in 'ssh', 'remotecmd': |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1077 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
|
1078 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
|
1079 dst.setconfig("ui", o, v, 'copied') |
11273
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1080 |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1081 # copy bundle-specific options |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1082 r = src.config('bundle', 'mainreporoot') |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1083 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
|
1084 dst.setconfig('bundle', 'mainreporoot', r, 'copied') |
11273
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1085 |
13192
4d03707916d3
https: use web.cacerts configuration from local repo to validate remote repo
Mads Kiilerich <mads@kiilerich.com>
parents:
12735
diff
changeset
|
1086 # copy selected local settings to the remote ui |
29616
3fde328d0913
hg: copy [hostsecurity] options to remote ui instances (issue5305)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29594
diff
changeset
|
1087 for sect in ('auth', 'hostfingerprints', 'hostsecurity', 'http_proxy'): |
11273
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1088 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
|
1089 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
|
1090 v = src.config('web', 'cacerts') |
29594
e417664a3339
ssl: remove special case of web.cacerts=! from remoteui()
Yuya Nishihara <yuya@tcha.org>
parents:
29424
diff
changeset
|
1091 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
|
1092 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
|
1093 |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1094 return dst |
26219
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1095 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1096 # Files of interest |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1097 # Used to check if the repository has changed looking at mtime and size of |
26781
1aee2ab0f902
spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents:
26654
diff
changeset
|
1098 # these files. |
26219
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1099 foi = [('spath', '00changelog.i'), |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1100 ('spath', 'phaseroots'), # ! phase can change content at the same size |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1101 ('spath', 'obsstore'), |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1102 ('path', 'bookmarks'), # ! bookmark can change content at the same size |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1103 ] |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1104 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1105 class cachedlocalrepo(object): |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1106 """Holds a localrepository that can be cached and reused.""" |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1107 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1108 def __init__(self, repo): |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1109 """Create a new cached repo from an existing repo. |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1110 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1111 We assume the passed in repo was recently created. If the |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1112 repo has changed between when it was created and when it was |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1113 turned into a cache, it may not refresh properly. |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1114 """ |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1115 assert isinstance(repo, localrepo.localrepository) |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1116 self._repo = repo |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1117 self._state, self.mtime = self._repostate() |
28119
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1118 self._filtername = repo.filtername |
26219
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1119 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1120 def fetch(self): |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1121 """Refresh (if necessary) and return a repository. |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1122 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1123 If the cached instance is out of date, it will be recreated |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1124 automatically and returned. |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1125 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1126 Returns a tuple of the repo and a boolean indicating whether a new |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1127 repo instance was created. |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1128 """ |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1129 # We compare the mtimes and sizes of some well-known files to |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1130 # determine if the repo changed. This is not precise, as mtimes |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1131 # are susceptible to clock skew and imprecise filesystems and |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1132 # file content can change while maintaining the same size. |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1133 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1134 state, mtime = self._repostate() |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1135 if state == self._state: |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1136 return self._repo, False |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1137 |
28119
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1138 repo = repository(self._repo.baseui, self._repo.url()) |
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1139 if self._filtername: |
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1140 self._repo = repo.filtered(self._filtername) |
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1141 else: |
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1142 self._repo = repo.unfiltered() |
26219
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1143 self._state = state |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1144 self.mtime = mtime |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1145 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1146 return self._repo, True |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1147 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1148 def _repostate(self): |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1149 state = [] |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1150 maxmtime = -1 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1151 for attr, fname in foi: |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1152 prefix = getattr(self._repo, attr) |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1153 p = os.path.join(prefix, fname) |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1154 try: |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1155 st = os.stat(p) |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1156 except OSError: |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1157 st = os.stat(prefix) |
36781
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36702
diff
changeset
|
1158 state.append((st[stat.ST_MTIME], st.st_size)) |
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36702
diff
changeset
|
1159 maxmtime = max(maxmtime, st[stat.ST_MTIME]) |
26219
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1160 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1161 return tuple(state), maxmtime |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1162 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1163 def copy(self): |
26240
2b1434e5eaa0
hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26219
diff
changeset
|
1164 """Obtain a copy of this class instance. |
2b1434e5eaa0
hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26219
diff
changeset
|
1165 |
2b1434e5eaa0
hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26219
diff
changeset
|
1166 A new localrepository instance is obtained. The new instance should be |
2b1434e5eaa0
hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26219
diff
changeset
|
1167 completely independent of the original. |
2b1434e5eaa0
hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26219
diff
changeset
|
1168 """ |
2b1434e5eaa0
hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26219
diff
changeset
|
1169 repo = repository(self._repo.baseui, self._repo.origroot) |
28119
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1170 if self._filtername: |
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1171 repo = repo.filtered(self._filtername) |
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1172 else: |
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1173 repo = repo.unfiltered() |
26240
2b1434e5eaa0
hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26219
diff
changeset
|
1174 c = cachedlocalrepo(repo) |
26219
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1175 c._state = self._state |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1176 c.mtime = self.mtime |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1177 return c |