Mercurial > hg
annotate mercurial/hg.py @ 51691:3cb2b5b6626f
hghave: update detection of black version to a newer minimum
The CI has moved to version 23.3.0, which is the last one to support 3.7 at
runtime.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 18 Jul 2024 12:37:13 +0200 |
parents | e8f58714bcf0 |
children | f4733654f144 |
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 # |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents:
46794
diff
changeset
|
3 # Copyright 2005-2007 Olivia Mackall <olivia@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 |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
10 import os |
48551
f98d4d0a299a
subrepo: make -S work again on Windows for incoming/outgoing to remote repos
Matt Harbison <matt_harbison@yahoo.com>
parents:
48494
diff
changeset
|
11 import posixpath |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
12 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
|
13 import stat |
51674
e8f58714bcf0
typing: add a type hint to `mercurial/hg.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51612
diff
changeset
|
14 import typing |
48494
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
15 import weakref |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
16 |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
17 from .i18n import _ |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45942
diff
changeset
|
18 from .node import ( |
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45942
diff
changeset
|
19 hex, |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46953
diff
changeset
|
20 sha1nodeconstants, |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45942
diff
changeset
|
21 short, |
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45942
diff
changeset
|
22 ) |
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
|
23 |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
24 from . import ( |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
25 bookmarks, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
26 bundlerepo, |
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, |
46915
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
33 graphmod, |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
34 httppeer, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
35 localrepo, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
36 lock, |
35888
c8e2d6ed1f9e
cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35766
diff
changeset
|
37 logcmdutil, |
35347
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35331
diff
changeset
|
38 logexchange, |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
39 merge as mergemod, |
44856
b7808443ed6a
mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents:
44657
diff
changeset
|
40 mergestate as mergestatemod, |
39550
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
41 narrowspec, |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
42 phases, |
45372
77b8588dd84e
requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
43 requirements, |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
44 scmutil, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
45 sshpeer, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
46 statichttprepo, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
47 ui as uimod, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
48 unionrepo, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
49 url, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
50 util, |
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
51 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
|
52 vfs as vfsmod, |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
53 ) |
47299
7edaf91c7886
updatecaches: use the `caches` argument instead of a special `full` value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47233
diff
changeset
|
54 from .interfaces import repository as repositorymod |
46691
1099541b6462
hg: convert an exception to bytes in the repo creation exception handler
Matt Harbison <matt_harbison@yahoo.com>
parents:
46314
diff
changeset
|
55 from .utils import ( |
1099541b6462
hg: convert an exception to bytes in the repo creation exception handler
Matt Harbison <matt_harbison@yahoo.com>
parents:
46314
diff
changeset
|
56 hashutil, |
1099541b6462
hg: convert an exception to bytes in the repo creation exception handler
Matt Harbison <matt_harbison@yahoo.com>
parents:
46314
diff
changeset
|
57 stringutil, |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46819
diff
changeset
|
58 urlutil, |
46691
1099541b6462
hg: convert an exception to bytes in the repo creation exception handler
Matt Harbison <matt_harbison@yahoo.com>
parents:
46314
diff
changeset
|
59 ) |
1099541b6462
hg: convert an exception to bytes in the repo creation exception handler
Matt Harbison <matt_harbison@yahoo.com>
parents:
46314
diff
changeset
|
60 |
51674
e8f58714bcf0
typing: add a type hint to `mercurial/hg.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51612
diff
changeset
|
61 if typing.TYPE_CHECKING: |
e8f58714bcf0
typing: add a type hint to `mercurial/hg.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51612
diff
changeset
|
62 from typing import ( |
e8f58714bcf0
typing: add a type hint to `mercurial/hg.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51612
diff
changeset
|
63 List, |
e8f58714bcf0
typing: add a type hint to `mercurial/hg.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51612
diff
changeset
|
64 Tuple, |
e8f58714bcf0
typing: add a type hint to `mercurial/hg.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51612
diff
changeset
|
65 ) |
42813
268662aac075
interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42604
diff
changeset
|
66 |
25939
130c0b83e963
hg: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25761
diff
changeset
|
67 release = lock.release |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
68 |
29424
f21e0d91d386
share: move magic string to a constant
Martijn Pieters <mjpieters@fb.com>
parents:
29389
diff
changeset
|
69 # shared features |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
70 sharedbookmarks = b'bookmarks' |
29424
f21e0d91d386
share: move magic string to a constant
Martijn Pieters <mjpieters@fb.com>
parents:
29389
diff
changeset
|
71 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
72 |
50440
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50191
diff
changeset
|
73 def addbranchrevs(lrepo, other, branches, revs, remotehidden=False): |
50928
d718eddf01d9
safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50911
diff
changeset
|
74 if hasattr(other, 'peer'): |
49746
2a5feacc4085
addbranchrevs: explicitly detect the need to fetch a peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49745
diff
changeset
|
75 # a courtesy to callers using a localrepo for other |
50440
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50191
diff
changeset
|
76 peer = other.peer(remotehidden=remotehidden) |
49746
2a5feacc4085
addbranchrevs: explicitly detect the need to fetch a peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49745
diff
changeset
|
77 else: |
2a5feacc4085
addbranchrevs: explicitly detect the need to fetch a peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49745
diff
changeset
|
78 peer = other |
11322
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
79 hashbranch, branches = branches |
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
80 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
|
81 x = revs or None |
37481
7c848ab13eff
addbranchrevs: no longer accept revset as "revs" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37480
diff
changeset
|
82 if revs: |
22818
d7b114493315
repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22648
diff
changeset
|
83 y = revs[0] |
d7b114493315
repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22648
diff
changeset
|
84 else: |
d7b114493315
repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22648
diff
changeset
|
85 y = None |
d7b114493315
repair: use `first` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22648
diff
changeset
|
86 return x, y |
24306
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24290
diff
changeset
|
87 if revs: |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24290
diff
changeset
|
88 revs = list(revs) |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24290
diff
changeset
|
89 else: |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24290
diff
changeset
|
90 revs = [] |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24290
diff
changeset
|
91 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
92 if not peer.capable(b'branchmap'): |
11322
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
93 if branches: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
94 raise error.Abort(_(b"remote branch lookup not supported")) |
11322
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
95 revs.append(hashbranch) |
10380
ee72d89c0d9f
addbranchrevs: fallback for older servers
Sune Foldager <cryo@cyanite.org>
parents:
10379
diff
changeset
|
96 return revs, revs[0] |
37640
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
97 |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
98 with peer.commandexecutor() as e: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
99 branchmap = e.callcommand(b'branchmap', {}).result() |
11322
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
100 |
13047
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
12735
diff
changeset
|
101 def primary(branch): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
102 if branch == b'.': |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
103 if not lrepo: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
104 raise error.Abort(_(b"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
|
105 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
|
106 if branch in branchmap: |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45942
diff
changeset
|
107 revs.extend(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
|
108 return True |
10365
d757bc0c7865
interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents:
10358
diff
changeset
|
109 else: |
11322
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
110 return False |
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
111 |
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
112 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
|
113 if not primary(branch): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
114 raise error.RepoLookupError(_(b"unknown branch '%s'") % branch) |
11322
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
115 if hashbranch: |
13047
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
12735
diff
changeset
|
116 if not primary(hashbranch): |
11322
3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Sune Foldager <cryo@cyanite.org>
parents:
11312
diff
changeset
|
117 revs.append(hashbranch) |
10365
d757bc0c7865
interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents:
10358
diff
changeset
|
118 return revs, revs[0] |
d757bc0c7865
interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents:
10358
diff
changeset
|
119 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
120 |
49683
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
121 def _isfile(path): |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
122 try: |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
123 # we use os.stat() directly here instead of os.path.isfile() |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
124 # because the latter started returning `False` on invalid path |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
125 # exceptions starting in 3.8 and we care about handling |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
126 # invalid paths specially here. |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
127 st = os.stat(path) |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
128 except ValueError as e: |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
129 msg = stringutil.forcebytestr(e) |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
130 raise error.Abort(_(b'invalid path %s: %s') % (path, msg)) |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
131 except OSError: |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
132 return False |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
133 else: |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
134 return stat.S_ISREG(st.st_mode) |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
135 |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
136 |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
137 class LocalFactory: |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
138 """thin wrapper to dispatch between localrepo and bundle repo""" |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
139 |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
140 @staticmethod |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
141 def islocal(path: bytes) -> bool: |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
142 path = util.expandpath(urlutil.urllocalpath(path)) |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
143 return not _isfile(path) |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
144 |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
145 @staticmethod |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
146 def instance(ui, path, *args, **kwargs): |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
147 path = util.expandpath(urlutil.urllocalpath(path)) |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
148 if _isfile(path): |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
149 cls = bundlerepo |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
150 else: |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
151 cls = localrepo |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
152 return cls.instance(ui, path, *args, **kwargs) |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
153 |
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
154 |
49688
f73f02ef8cb6
peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49687
diff
changeset
|
155 repo_schemes = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
156 b'bundle': bundlerepo, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
157 b'union': unionrepo, |
49683
d9791643aab7
peer-or-repo: make sure object in "scheme" have a `instance` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49682
diff
changeset
|
158 b'file': LocalFactory, |
49688
f73f02ef8cb6
peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49687
diff
changeset
|
159 } |
f73f02ef8cb6
peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49687
diff
changeset
|
160 |
f73f02ef8cb6
peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49687
diff
changeset
|
161 peer_schemes = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
162 b'http': httppeer, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
163 b'https': httppeer, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
164 b'ssh': sshpeer, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
165 b'static-http': statichttprepo, |
14568
5f002e3336ba
hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
166 } |
5f002e3336ba
hg: split peer and repo lookup tables
Matt Mackall <mpm@selenic.com>
parents:
14556
diff
changeset
|
167 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
168 |
14605
9f1139cf5c76
hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents:
14568
diff
changeset
|
169 def islocal(repo): |
20355
7d269e7620c4
hg: note that islocal only accepts paths pointing to repos
Siddharth Agarwal <sid0@fb.com>
parents:
20354
diff
changeset
|
170 '''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
|
171 if isinstance(repo, bytes): |
49749
be3fcd9e5e52
peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49748
diff
changeset
|
172 u = urlutil.url(repo) |
be3fcd9e5e52
peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49748
diff
changeset
|
173 scheme = u.scheme or b'file' |
be3fcd9e5e52
peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49748
diff
changeset
|
174 if scheme in peer_schemes: |
be3fcd9e5e52
peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49748
diff
changeset
|
175 cls = peer_schemes[scheme] |
49750
f075a9463ee7
peer: use a dedicated name for the `peer` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49749
diff
changeset
|
176 cls.make_peer # make sure we load the module |
49749
be3fcd9e5e52
peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49748
diff
changeset
|
177 elif scheme in repo_schemes: |
be3fcd9e5e52
peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49748
diff
changeset
|
178 cls = repo_schemes[scheme] |
49750
f075a9463ee7
peer: use a dedicated name for the `peer` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49749
diff
changeset
|
179 cls.instance # make sure we load the module |
49749
be3fcd9e5e52
peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49748
diff
changeset
|
180 else: |
be3fcd9e5e52
peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49748
diff
changeset
|
181 cls = LocalFactory |
50928
d718eddf01d9
safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50911
diff
changeset
|
182 if hasattr(cls, 'islocal'): |
49687
0d5b2e010614
peer-or-repo: stop relying on AttributeError in `islocal`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49686
diff
changeset
|
183 return cls.islocal(repo) # pytype: disable=module-attr |
0d5b2e010614
peer-or-repo: stop relying on AttributeError in `islocal`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49686
diff
changeset
|
184 return False |
49686
b478e1b132e9
repo-or-peer: deprecate calling `islocal` on non-path object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49684
diff
changeset
|
185 repo.ui.deprecwarn(b"use obj.local() instead of islocal(obj)", b"6.4") |
14605
9f1139cf5c76
hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents:
14568
diff
changeset
|
186 return repo.local() |
9f1139cf5c76
hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents:
14568
diff
changeset
|
187 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
188 |
42109
2a3c0106ded9
import: suppress accept: header
timeless <timeless@mozdev.org>
parents:
41484
diff
changeset
|
189 def openpath(ui, path, sendaccept=True): |
17887
0e2846b2482c
url: use open and not url.open for local files (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents:
17882
diff
changeset
|
190 '''open path with open if local, url.open if remote''' |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46819
diff
changeset
|
191 pathurl = urlutil.url(path, parsequery=False, parsefragment=False) |
20354
b433b43364e4
hg.openpath: use url.islocal to tell if the path is local (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents:
20185
diff
changeset
|
192 if pathurl.islocal(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
193 return util.posixfile(pathurl.localpath(), b'rb') |
17887
0e2846b2482c
url: use open and not url.open for local files (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents:
17882
diff
changeset
|
194 else: |
42109
2a3c0106ded9
import: suppress accept: header
timeless <timeless@mozdev.org>
parents:
41484
diff
changeset
|
195 return url.open(ui, path, sendaccept=sendaccept) |
17887
0e2846b2482c
url: use open and not url.open for local files (issue3624)
Siddharth Agarwal <sid0@fb.com>
parents:
17882
diff
changeset
|
196 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
197 |
20858
bc56ec9e64df
hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20825
diff
changeset
|
198 # 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
|
199 wirepeersetupfuncs = [] |
bc56ec9e64df
hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20825
diff
changeset
|
200 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
201 |
49682
1e6c37360527
peer-or-repo: move the object setup in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49305
diff
changeset
|
202 def _setup_repo_or_peer(ui, obj, presetupfuncs=None): |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
203 ui = getattr(obj, "ui", ui) |
32379
71e735bd8170
dispatch: make request accept additional reposetups
Jun Wu <quark@fb.com>
parents:
32172
diff
changeset
|
204 for f in presetupfuncs or []: |
71e735bd8170
dispatch: make request accept additional reposetups
Jun Wu <quark@fb.com>
parents:
32172
diff
changeset
|
205 f(ui, obj) |
40996
6f2510b581a0
extensions: use ui.log() interface to provide detailed loading information
Yuya Nishihara <yuya@tcha.org>
parents:
40639
diff
changeset
|
206 ui.log(b'extension', b'- executing reposetup hooks\n') |
43238
101ae8bbfa02
cleanup: hgdemandimport.tracing accepts strings, not bytes
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
207 with util.timedcm('all reposetup') as allreposetupstats: |
39510
340170192874
extensions: trace the total time of running all reposetup callbacks
Boris Feld <boris.feld@octobus.net>
parents:
39507
diff
changeset
|
208 for name, module in extensions.extensions(ui): |
40996
6f2510b581a0
extensions: use ui.log() interface to provide detailed loading information
Yuya Nishihara <yuya@tcha.org>
parents:
40639
diff
changeset
|
209 ui.log(b'extension', b' - running reposetup for %s\n', name) |
39510
340170192874
extensions: trace the total time of running all reposetup callbacks
Boris Feld <boris.feld@octobus.net>
parents:
39507
diff
changeset
|
210 hook = getattr(module, 'reposetup', None) |
340170192874
extensions: trace the total time of running all reposetup callbacks
Boris Feld <boris.feld@octobus.net>
parents:
39507
diff
changeset
|
211 if hook: |
43238
101ae8bbfa02
cleanup: hgdemandimport.tracing accepts strings, not bytes
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
212 with util.timedcm('reposetup %r', name) as stats: |
39510
340170192874
extensions: trace the total time of running all reposetup callbacks
Boris Feld <boris.feld@octobus.net>
parents:
39507
diff
changeset
|
213 hook(ui, obj) |
49682
1e6c37360527
peer-or-repo: move the object setup in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49305
diff
changeset
|
214 msg = b' > reposetup for %s took %s\n' |
1e6c37360527
peer-or-repo: move the object setup in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49305
diff
changeset
|
215 ui.log(b'extension', msg, name, stats) |
40996
6f2510b581a0
extensions: use ui.log() interface to provide detailed loading information
Yuya Nishihara <yuya@tcha.org>
parents:
40639
diff
changeset
|
216 ui.log(b'extension', b'> all reposetup took %s\n', allreposetupstats) |
20858
bc56ec9e64df
hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20825
diff
changeset
|
217 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
|
218 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
|
219 f(ui, obj) |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
220 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
221 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
222 def repository( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
223 ui, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
224 path=b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
225 create=False, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
226 presetupfuncs=None, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
227 intents=None, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
228 createopts=None, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
229 ): |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
230 """return a repository object for the specified path""" |
49692
ebb5e38fdafc
peer-or-repo: build a repo directly in the `repo` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49691
diff
changeset
|
231 scheme = urlutil.url(path).scheme |
ebb5e38fdafc
peer-or-repo: build a repo directly in the `repo` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49691
diff
changeset
|
232 if scheme is None: |
ebb5e38fdafc
peer-or-repo: build a repo directly in the `repo` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49691
diff
changeset
|
233 scheme = b'file' |
ebb5e38fdafc
peer-or-repo: build a repo directly in the `repo` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49691
diff
changeset
|
234 cls = repo_schemes.get(scheme) |
ebb5e38fdafc
peer-or-repo: build a repo directly in the `repo` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49691
diff
changeset
|
235 if cls is None: |
ebb5e38fdafc
peer-or-repo: build a repo directly in the `repo` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49691
diff
changeset
|
236 if scheme in peer_schemes: |
ebb5e38fdafc
peer-or-repo: build a repo directly in the `repo` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49691
diff
changeset
|
237 raise error.Abort(_(b"repository '%s' is not local") % path) |
ebb5e38fdafc
peer-or-repo: build a repo directly in the `repo` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49691
diff
changeset
|
238 cls = LocalFactory |
ebb5e38fdafc
peer-or-repo: build a repo directly in the `repo` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49691
diff
changeset
|
239 repo = cls.instance( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
240 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
241 path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
242 create, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
243 intents=intents, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
244 createopts=createopts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
245 ) |
49692
ebb5e38fdafc
peer-or-repo: build a repo directly in the `repo` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49691
diff
changeset
|
246 _setup_repo_or_peer(ui, repo, presetupfuncs=presetupfuncs) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
247 return repo.filtered(b'visible') |
14605
9f1139cf5c76
hg: rearrange peer scheme lookup
Matt Mackall <mpm@selenic.com>
parents:
14568
diff
changeset
|
248 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
249 |
50440
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50191
diff
changeset
|
250 def peer( |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50191
diff
changeset
|
251 uiorrepo, |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50191
diff
changeset
|
252 opts, |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50191
diff
changeset
|
253 path, |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50191
diff
changeset
|
254 create=False, |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50191
diff
changeset
|
255 intents=None, |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50191
diff
changeset
|
256 createopts=None, |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50191
diff
changeset
|
257 remotehidden=False, |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50191
diff
changeset
|
258 ): |
14554 | 259 '''return a repository peer for the specified path''' |
49754
ec30fe6917ec
peer: build a `path` object on the fly when needed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49750
diff
changeset
|
260 ui = getattr(uiorrepo, 'ui', uiorrepo) |
14839
510c893a726f
peer: change arg name to convey it can be a repo as well
Idan Kamara <idankk86@gmail.com>
parents:
14825
diff
changeset
|
261 rui = remoteui(uiorrepo, opts) |
50928
d718eddf01d9
safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50911
diff
changeset
|
262 if hasattr(path, 'url'): |
49754
ec30fe6917ec
peer: build a `path` object on the fly when needed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49750
diff
changeset
|
263 # this is already a urlutil.path object |
ec30fe6917ec
peer: build a `path` object on the fly when needed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49750
diff
changeset
|
264 peer_path = path |
49707
aa36771ef505
path: have `peer` constructor accept a `path` object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49701
diff
changeset
|
265 else: |
49754
ec30fe6917ec
peer: build a `path` object on the fly when needed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49750
diff
changeset
|
266 peer_path = urlutil.path(ui, None, rawloc=path, validate_path=False) |
ec30fe6917ec
peer: build a `path` object on the fly when needed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49750
diff
changeset
|
267 scheme = peer_path.url.scheme # pytype: disable=attribute-error |
49691
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
268 if scheme in peer_schemes: |
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
269 cls = peer_schemes[scheme] |
49750
f075a9463ee7
peer: use a dedicated name for the `peer` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49749
diff
changeset
|
270 peer = cls.make_peer( |
49691
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
271 rui, |
49757
5f71fff8dc74
peer: pass the `path` object to `make_peer`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49755
diff
changeset
|
272 peer_path, |
49691
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
273 create, |
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
274 intents=intents, |
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
275 createopts=createopts, |
50440
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50191
diff
changeset
|
276 remotehidden=remotehidden, |
49691
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
277 ) |
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
278 _setup_repo_or_peer(rui, peer) |
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
279 else: |
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
280 # this is a repository |
49754
ec30fe6917ec
peer: build a `path` object on the fly when needed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49750
diff
changeset
|
281 repo_path = peer_path.loc # pytype: disable=attribute-error |
ec30fe6917ec
peer: build a `path` object on the fly when needed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49750
diff
changeset
|
282 if not repo_path: |
ec30fe6917ec
peer: build a `path` object on the fly when needed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49750
diff
changeset
|
283 repo_path = peer_path.rawloc # pytype: disable=attribute-error |
49691
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
284 repo = repository( |
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
285 rui, |
49754
ec30fe6917ec
peer: build a `path` object on the fly when needed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49750
diff
changeset
|
286 repo_path, |
49691
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
287 create, |
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
288 intents=intents, |
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
289 createopts=createopts, |
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
290 ) |
50440
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50191
diff
changeset
|
291 peer = repo.peer(path=peer_path, remotehidden=remotehidden) |
49691
c0acf5440fe1
peer-or-repo: build a peer directly in the `peer` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49690
diff
changeset
|
292 return peer |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
293 |
14554 | 294 |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
295 def defaultdest(source): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
296 """return default destination of clone if none is given |
20799
069bf1b821c8
clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents:
20790
diff
changeset
|
297 |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
33687
diff
changeset
|
298 >>> defaultdest(b'foo') |
20799
069bf1b821c8
clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents:
20790
diff
changeset
|
299 'foo' |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
33687
diff
changeset
|
300 >>> defaultdest(b'/foo/bar') |
20799
069bf1b821c8
clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents:
20790
diff
changeset
|
301 'bar' |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
33687
diff
changeset
|
302 >>> defaultdest(b'/') |
20799
069bf1b821c8
clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents:
20790
diff
changeset
|
303 '' |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
33687
diff
changeset
|
304 >>> defaultdest(b'') |
20800
8253e55930a3
clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
20799
diff
changeset
|
305 '' |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
33687
diff
changeset
|
306 >>> 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
|
307 '' |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
33687
diff
changeset
|
308 >>> defaultdest(b'http://example.org/foo/') |
20799
069bf1b821c8
clone: add doctest for default destination
Yuya Nishihara <yuya@tcha.org>
parents:
20790
diff
changeset
|
309 'foo' |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
310 """ |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46819
diff
changeset
|
311 path = urlutil.url(source).path |
20800
8253e55930a3
clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
20799
diff
changeset
|
312 if not path: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
313 return b'' |
20800
8253e55930a3
clone: abort if default destination has no meaningful name (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
20799
diff
changeset
|
314 return os.path.basename(os.path.normpath(path)) |
2774 | 315 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
316 |
36159
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
317 def sharedreposource(repo): |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
318 """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
|
319 |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
320 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
|
321 """ |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
322 if repo.sharedpath == repo.path: |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
323 return None |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
324 |
50928
d718eddf01d9
safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50911
diff
changeset
|
325 if hasattr(repo, 'srcrepo') and repo.srcrepo: |
36159
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
326 return repo.srcrepo |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
327 |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
328 # 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
|
329 source = repo.vfs.split(repo.sharedpath)[0] |
46908
4452cb788404
urlutil: extract `parseurl` from `hg` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46907
diff
changeset
|
330 srcurl, branches = urlutil.parseurl(source) |
36159
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
331 srcrepo = repository(repo.ui, srcurl) |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
332 repo.srcrepo = srcrepo |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
333 return srcrepo |
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36049
diff
changeset
|
334 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
335 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
336 def share( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
337 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
338 source, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
339 dest=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
340 update=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
341 bookmarks=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
342 defaultpath=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
343 relative=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
344 ): |
8800
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
345 '''create a shared repository''' |
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
346 |
49684
229e0ed88895
share: stop using 'islocal' with repo instance
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49683
diff
changeset
|
347 not_local_msg = _(b'can only share local repositories') |
50928
d718eddf01d9
safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50911
diff
changeset
|
348 if hasattr(source, 'local'): |
49684
229e0ed88895
share: stop using 'islocal' with repo instance
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49683
diff
changeset
|
349 if source.local() is None: |
229e0ed88895
share: stop using 'islocal' with repo instance
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49683
diff
changeset
|
350 raise error.Abort(not_local_msg) |
229e0ed88895
share: stop using 'islocal' with repo instance
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49683
diff
changeset
|
351 elif not islocal(source): |
229e0ed88895
share: stop using 'islocal' with repo instance
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49683
diff
changeset
|
352 # XXX why are we getting bytes here ? |
229e0ed88895
share: stop using 'islocal' with repo instance
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49683
diff
changeset
|
353 raise error.Abort(not_local_msg) |
8800
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
354 |
8807
8bf6eb68ddaf
share: allow dest to default to the basename of source
Matt Mackall <mpm@selenic.com>
parents:
8800
diff
changeset
|
355 if not dest: |
10099
f5e46dfb38c7
share: use defaultdest to compute unspecified destination
Brendan Cully <brendan@kublai.com>
parents:
9984
diff
changeset
|
356 dest = defaultdest(source) |
9344 | 357 else: |
49744
5f36784c300f
path: use `get_clone_path_obj` in share
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49718
diff
changeset
|
358 dest = urlutil.get_clone_path_obj(ui, dest).loc |
8807
8bf6eb68ddaf
share: allow dest to default to the basename of source
Matt Mackall <mpm@selenic.com>
parents:
8800
diff
changeset
|
359 |
36049
488e313954ea
py3: check for bytes instead of str in hg.share()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36003
diff
changeset
|
360 if isinstance(source, bytes): |
49744
5f36784c300f
path: use `get_clone_path_obj` in share
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49718
diff
changeset
|
361 source_path = urlutil.get_clone_path_obj(ui, source) |
5f36784c300f
path: use `get_clone_path_obj` in share
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49718
diff
changeset
|
362 srcrepo = repository(ui, source_path.loc) |
5f36784c300f
path: use `get_clone_path_obj` in share
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49718
diff
changeset
|
363 branches = (source_path.branch, []) |
10365
d757bc0c7865
interpret repo#name url syntax as branch instead of revision
Sune Foldager <cryo@cyanite.org>
parents:
10358
diff
changeset
|
364 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
|
365 else: |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
366 srcrepo = source.local() |
8800
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
367 checkout = None |
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
368 |
39849
d3d4b4b5f725
localrepo: support writing shared file (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39848
diff
changeset
|
369 shareditems = set() |
d3d4b4b5f725
localrepo: support writing shared file (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39848
diff
changeset
|
370 if bookmarks: |
d3d4b4b5f725
localrepo: support writing shared file (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39848
diff
changeset
|
371 shareditems.add(sharedbookmarks) |
d3d4b4b5f725
localrepo: support writing shared file (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39848
diff
changeset
|
372 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
373 r = repository( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
374 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
375 dest, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
376 create=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
377 createopts={ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
378 b'sharedrepo': srcrepo, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
379 b'sharedrelative': relative, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
380 b'shareditems': shareditems, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
381 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
382 ) |
8800
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
383 |
39849
d3d4b4b5f725
localrepo: support writing shared file (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39848
diff
changeset
|
384 postshare(srcrepo, r, defaultpath=defaultpath) |
40575
fb490d798be0
share: reload repo after adjusting it in postshare()
Martin von Zweigbergk <martinvonz@google.com>
parents:
40440
diff
changeset
|
385 r = repository(ui, dest) |
28632
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
386 _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
|
387 return r |
8800
971e38a9344b
add helper function to create shared repos
Matt Mackall <mpm@selenic.com>
parents:
8649
diff
changeset
|
388 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
389 |
45485
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
390 def _prependsourcehgrc(repo): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
391 """copies the source repo config and prepend it in current repo .hg/hgrc |
45485
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
392 on unshare. This is only done if the share was perfomed using share safe |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
393 method where we share config of source in shares""" |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
394 srcvfs = vfsmod.vfs(repo.sharedpath) |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
395 dstvfs = vfsmod.vfs(repo.path) |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
396 |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
397 if not srcvfs.exists(b'hgrc'): |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
398 return |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
399 |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
400 currentconfig = b'' |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
401 if dstvfs.exists(b'hgrc'): |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
402 currentconfig = dstvfs.read(b'hgrc') |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
403 |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
404 with dstvfs(b'hgrc', b'wb') as fp: |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
405 sourceconfig = srcvfs.read(b'hgrc') |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
406 fp.write(b"# Config copied from shared source\n") |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
407 fp.write(sourceconfig) |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
408 fp.write(b'\n') |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
409 fp.write(currentconfig) |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
410 |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
411 |
34878
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
412 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
|
413 """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
|
414 |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
415 Copy the store data to the repo and remove the sharedpath data. |
39606
c5e6c1ba1c79
hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39555
diff
changeset
|
416 |
c5e6c1ba1c79
hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39555
diff
changeset
|
417 Returns a new repository object representing the unshared repository. |
c5e6c1ba1c79
hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39555
diff
changeset
|
418 |
c5e6c1ba1c79
hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39555
diff
changeset
|
419 The passed repository object is not usable after this function is |
c5e6c1ba1c79
hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39555
diff
changeset
|
420 called. |
34878
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
421 """ |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
422 |
41391
bc843e251134
unshare: use context manager for locks
Martin von Zweigbergk <martinvonz@google.com>
parents:
41365
diff
changeset
|
423 with repo.lock(): |
34878
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
424 # 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
|
425 # 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
|
426 # 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
|
427 # fail |
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
428 destlock = copystore(ui, repo, repo.path) |
41391
bc843e251134
unshare: use context manager for locks
Martin von Zweigbergk <martinvonz@google.com>
parents:
41365
diff
changeset
|
429 with destlock or util.nullcontextmanager(): |
45485
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
430 if requirements.SHARESAFE_REQUIREMENT in repo.requirements: |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
431 # we were sharing .hg/hgrc of the share source with the current |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
432 # repo. We need to copy that while unsharing otherwise it can |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
433 # disable hooks and other checks |
b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45386
diff
changeset
|
434 _prependsourcehgrc(repo) |
34878
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
435 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
436 sharefile = repo.vfs.join(b'sharedpath') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
437 util.rename(sharefile, sharefile + b'.old') |
41391
bc843e251134
unshare: use context manager for locks
Martin von Zweigbergk <martinvonz@google.com>
parents:
41365
diff
changeset
|
438 |
45386
034d94f8761b
requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45372
diff
changeset
|
439 repo.requirements.discard(requirements.SHARED_REQUIREMENT) |
034d94f8761b
requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45372
diff
changeset
|
440 repo.requirements.discard(requirements.RELATIVE_SHARED_REQUIREMENT) |
45106
a03c177a4679
scmutil: add writereporequirements() and route requires writing through it
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44856
diff
changeset
|
441 scmutil.writereporequirements(repo) |
34878
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
442 |
39606
c5e6c1ba1c79
hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39555
diff
changeset
|
443 # Removing share changes some fundamental properties of the repo instance. |
c5e6c1ba1c79
hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39555
diff
changeset
|
444 # So we instantiate a new repo object and operate on it rather than |
c5e6c1ba1c79
hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39555
diff
changeset
|
445 # try to keep the existing repo usable. |
c5e6c1ba1c79
hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39555
diff
changeset
|
446 newrepo = repository(repo.baseui, repo.root, create=False) |
34878
9f7ecc5bbc28
share: move the implementation of 'unshare' to the 'hg' module
Matt Harbison <matt_harbison@yahoo.com>
parents:
34815
diff
changeset
|
447 |
34879
7d51a7792f52
subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
34878
diff
changeset
|
448 # 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
|
449 # removed from .hgsub |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
450 c = newrepo[b'.'] |
34879
7d51a7792f52
subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
34878
diff
changeset
|
451 subs = c.substate |
7d51a7792f52
subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
34878
diff
changeset
|
452 for s in sorted(subs): |
7d51a7792f52
subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
34878
diff
changeset
|
453 c.sub(s).unshare() |
7d51a7792f52
subrepo: implement 'unshare' for Mercurial subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
34878
diff
changeset
|
454 |
39606
c5e6c1ba1c79
hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39555
diff
changeset
|
455 localrepo.poisonrepository(repo) |
c5e6c1ba1c79
hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39555
diff
changeset
|
456 |
c5e6c1ba1c79
hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39555
diff
changeset
|
457 return newrepo |
c5e6c1ba1c79
hg: don't reuse repo instance after unshare()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39555
diff
changeset
|
458 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
459 |
39849
d3d4b4b5f725
localrepo: support writing shared file (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39848
diff
changeset
|
460 def postshare(sourcerepo, destrepo, defaultpath=None): |
27354
bced7180db19
hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27344
diff
changeset
|
461 """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
|
462 |
bced7180db19
hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27344
diff
changeset
|
463 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
|
464 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
|
465 |
bced7180db19
hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27344
diff
changeset
|
466 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
|
467 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
|
468 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
469 default = defaultpath or sourcerepo.ui.config(b'paths', b'default') |
27354
bced7180db19
hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27344
diff
changeset
|
470 if default: |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43089
diff
changeset
|
471 template = b'[paths]\ndefault = %s\n' |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
472 destrepo.vfs.write(b'hgrc', util.tonativeeol(template % default)) |
45372
77b8588dd84e
requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
473 if requirements.NARROW_REQUIREMENT in sourcerepo.requirements: |
50191
99faa396e186
narrow: write the narrow spec in a transaction during share
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50189
diff
changeset
|
474 with destrepo.wlock(), destrepo.lock(), destrepo.transaction( |
99faa396e186
narrow: write the narrow spec in a transaction during share
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50189
diff
changeset
|
475 b"narrow-share" |
99faa396e186
narrow: write the narrow spec in a transaction during share
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50189
diff
changeset
|
476 ): |
41229
50ca531f1f24
narrow: copy store narrowspec to working copy immediately
Martin von Zweigbergk <martinvonz@google.com>
parents:
41043
diff
changeset
|
477 narrowspec.copytoworkingcopy(destrepo) |
27354
bced7180db19
hg: establish function for performing post-share actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27344
diff
changeset
|
478 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
479 |
28632
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
480 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
|
481 """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
|
482 |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
483 ``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
|
484 """ |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
485 if not update: |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
486 return |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
487 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
488 repo.ui.status(_(b"updating working directory\n")) |
28632
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
489 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
|
490 checkout = update |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
491 for test in (checkout, b'default', b'tip'): |
28632
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
492 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
|
493 continue |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
494 try: |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
495 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
|
496 break |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
497 except error.RepoLookupError: |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
498 continue |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
499 _update(repo, uprev) |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
500 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
501 |
15078
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
502 def copystore(ui, srcrepo, destpath): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
503 """copy files from store of srcrepo in destpath |
15078
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
504 |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
505 returns destlock |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
506 """ |
15078
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
507 destlock = None |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
508 try: |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
509 hardlink = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
510 topic = _(b'linking') if hardlink else _(b'copying') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
511 with ui.makeprogress(topic, unit=_(b'files')) as progress: |
39388
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
512 num = 0 |
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
513 srcpublishing = srcrepo.publishing() |
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
514 srcvfs = vfsmod.vfs(srcrepo.sharedpath) |
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
515 dstvfs = vfsmod.vfs(destpath) |
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
516 for f in srcrepo.store.copylist(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
517 if srcpublishing and f.endswith(b'phaseroots'): |
39388
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
518 continue |
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
519 dstbase = os.path.dirname(f) |
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
520 if dstbase and not dstvfs.exists(dstbase): |
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
521 dstvfs.mkdir(dstbase) |
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
522 if srcvfs.exists(f): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
523 if f.endswith(b'data'): |
39388
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
524 # 'dstbase' may be empty (e.g. revlog format 0) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
525 lockfile = os.path.join(dstbase, b"lock") |
39388
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
526 # lock to avoid premature writing to the target |
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
527 destlock = lock.lock(dstvfs, lockfile) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
528 hardlink, n = util.copyfiles( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
529 srcvfs.join(f), dstvfs.join(f), hardlink, progress |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
530 ) |
39388
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
531 num += n |
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
532 if hardlink: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
533 ui.debug(b"linked %d files\n" % num) |
39388
ddfd80029306
hg: ensure the progress bar is completed when copying the store
Matt Harbison <matt_harbison@yahoo.com>
parents:
39186
diff
changeset
|
534 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
535 ui.debug(b"copied %d files\n" % num) |
15078
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
536 return destlock |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
537 except: # re-raises |
15078
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
538 release(destlock) |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
539 raise |
193e7018dc8c
hg: extract copying the store out of clone
Simon Heimberg <simohe@besonet.ch>
parents:
14952
diff
changeset
|
540 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
541 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
542 def clonewithshare( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
543 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
544 peeropts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
545 sharepath, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
546 source, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
547 srcpeer, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
548 dest, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
549 pull=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
550 rev=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
551 update=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
552 stream=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
553 ): |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
554 """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
|
555 |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
556 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
|
557 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
|
558 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
|
559 True. |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
560 """ |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
561 revs = None |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
562 if rev: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
563 if not srcpeer.capable(b'lookup'): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
564 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
565 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
566 b"src repository does not support " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
567 b"revision lookup and so doesn't " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
568 b"support clone by revision" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
569 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
570 ) |
37640
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
571 |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
572 # TODO this is batchable. |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
573 remoterevs = [] |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
574 for r in rev: |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
575 with srcpeer.commandexecutor() as e: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
576 remoterevs.append( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
577 e.callcommand( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
578 b'lookup', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
579 { |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
580 b'key': r, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
581 }, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
582 ).result() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
583 ) |
37640
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
584 revs = remoterevs |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
585 |
28289
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
586 # 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
|
587 # 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
|
588 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
|
589 # 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
|
590 try: |
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
591 util.makedir(pooldir, False) |
49305
53e9422a9b45
py3: catch FileExistsError instead of checking errno == EEXIST
Manuel Jacob <me@manueljacob.de>
parents:
49301
diff
changeset
|
592 except FileExistsError: |
53e9422a9b45
py3: catch FileExistsError instead of checking errno == EEXIST
Manuel Jacob <me@manueljacob.de>
parents:
49301
diff
changeset
|
593 pass |
28289
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
594 |
31218
4cc3797aa59c
vfs: use 'vfs' module directly in 'mercurial.hg'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31168
diff
changeset
|
595 poolvfs = vfsmod.vfs(pooldir) |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
596 basename = os.path.basename(sharepath) |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
597 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
598 with lock.lock(poolvfs, b'%s.lock' % basename): |
28289
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
599 if os.path.exists(sharepath): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
600 ui.status( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
601 _(b'(sharing from existing pooled repository %s)\n') % basename |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
602 ) |
28289
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
603 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
604 ui.status( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
605 _(b'(sharing from new pooled repository %s)\n') % basename |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
606 ) |
28289
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27637
diff
changeset
|
607 # 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
|
608 # 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
|
609 # share mode. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
610 clone( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
611 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
612 peeropts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
613 source, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
614 dest=sharepath, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
615 pull=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
616 revs=rev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
617 update=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
618 stream=stream, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
619 ) |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
620 |
30041
1779dde4c9ef
hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29902
diff
changeset
|
621 # 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
|
622 if islocal(source): |
47626
1fdf315eff66
windows: use abspath in mercurial/hg.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47447
diff
changeset
|
623 defaultpath = util.abspath(urlutil.urllocalpath(source)) |
30041
1779dde4c9ef
hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29902
diff
changeset
|
624 else: |
1779dde4c9ef
hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29902
diff
changeset
|
625 defaultpath = source |
1779dde4c9ef
hg: set default path correctly when doing a clone+share (issue5378)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29902
diff
changeset
|
626 |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
627 sharerepo = repository(ui, path=sharepath) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
628 destrepo = share( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
629 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
630 sharerepo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
631 dest=dest, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
632 update=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
633 bookmarks=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
634 defaultpath=defaultpath, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
635 ) |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
636 |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
637 # 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
|
638 # 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
|
639 # 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
|
640 # 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
|
641 # 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
|
642 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
|
643 |
28632
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
644 _postshareupdate(destrepo, update) |
a2c2dd399f3b
hg: perform update after pulling during clone with share (issue5103)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28289
diff
changeset
|
645 |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
646 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
|
647 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
648 |
46123
5b9bb4e9a3bf
share: properly copy cache files when cloning from a share
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
649 # Recomputing caches is often slow on big repos, so copy them. |
32492
963de566de2f
local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32379
diff
changeset
|
650 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
|
651 """copy a cache from srcrepo to destcachedir (if it exists)""" |
46123
5b9bb4e9a3bf
share: properly copy cache files when cloning from a share
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
652 srcfname = srcrepo.cachevfs.join(fname) |
5b9bb4e9a3bf
share: properly copy cache files when cloning from a share
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
653 dstfname = os.path.join(dstcachedir, fname) |
5b9bb4e9a3bf
share: properly copy cache files when cloning from a share
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
654 if os.path.exists(srcfname): |
32492
963de566de2f
local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32379
diff
changeset
|
655 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
|
656 os.mkdir(dstcachedir) |
46123
5b9bb4e9a3bf
share: properly copy cache files when cloning from a share
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
657 util.copyfile(srcfname, dstfname) |
32492
963de566de2f
local-clone: extract the closure copying caches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32379
diff
changeset
|
658 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
659 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
660 def clone( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
661 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
662 peeropts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
663 source, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
664 dest=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
665 pull=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
666 revs=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
667 update=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
668 stream=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
669 branch=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
670 shareopts=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
671 storeincludepats=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
672 storeexcludepats=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
673 depth=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
674 ): |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
675 """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
|
676 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
677 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
|
678 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
|
679 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
|
680 newly created destination. |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
681 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
682 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
|
683 .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
|
684 pushes. |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
685 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
686 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
|
687 repository will be deleted. |
2600
c4325f0a9b91
clean up trailing white space.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2597
diff
changeset
|
688 |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
689 Arguments: |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
690 |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
691 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
|
692 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
693 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
|
694 name of source repository) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
695 |
23545
68c434799559
hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents:
23139
diff
changeset
|
696 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
|
697 server prefers streaming |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
698 |
2621
5a5852a417b1
clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2613
diff
changeset
|
699 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
|
700 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
|
701 |
37262
54435fd09f1d
clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents:
37261
diff
changeset
|
702 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
|
703 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
704 update: update working directory after clone completes, if |
6526
cfeeac24fc1e
repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents:
6525
diff
changeset
|
705 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
|
706 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
|
707 |
a78bfaf988e1
add -b/--branch option to clone, bundle, incoming, outgoing, pull, push
Sune Foldager <cryo@cyanite.org>
parents:
10365
diff
changeset
|
708 branch: branches to clone |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
709 |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
710 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
|
711 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
|
712 "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
|
713 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
|
714 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
|
715 remote's path/URL. Defaults to "identity." |
39550
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
716 |
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
717 storeincludepats and storeexcludepats: sets of file patterns to include and |
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
718 exclude in the repository copy, respectively. If not defined, all files |
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
719 will be included (a "full" clone). Otherwise a "narrow" clone containing |
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
720 only the requested files will be performed. If ``storeincludepats`` is not |
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
721 defined but ``storeexcludepats`` is, ``storeincludepats`` is assumed to be |
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
722 ``path:.``. If both are empty sets, no files will be cloned. |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
723 """ |
4478
b2b55acbacdd
Add support for url#id syntax
Matt Mackall <mpm@selenic.com>
parents:
4477
diff
changeset
|
724 |
32970
11c0bb4ccc76
py3: replace str with bytes in isinstance()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32495
diff
changeset
|
725 if isinstance(source, bytes): |
49745
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
726 src_path = urlutil.get_clone_path_obj(ui, source) |
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
727 if src_path is None: |
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
728 srcpeer = peer(ui, peeropts, b'') |
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
729 origsource = source = b'' |
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
730 branches = (None, branch or []) |
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
731 else: |
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
732 srcpeer = peer(ui, peeropts, src_path) |
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
733 origsource = src_path.rawloc |
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
734 branches = (src_path.branch, branch or []) |
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
735 source = src_path.loc |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
736 else: |
50928
d718eddf01d9
safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50911
diff
changeset
|
737 if hasattr(source, 'peer'): |
49747
8a38cd76588f
clone: explicitly detect the need to fetch a peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49746
diff
changeset
|
738 srcpeer = source.peer() # in case we were called with a localrepo |
8a38cd76588f
clone: explicitly detect the need to fetch a peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49746
diff
changeset
|
739 else: |
8a38cd76588f
clone: explicitly detect the need to fetch a peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49746
diff
changeset
|
740 srcpeer = source |
37261
3809eafedf2c
parseurl: consistently call second output "branches"
Martin von Zweigbergk <martinvonz@google.com>
parents:
37125
diff
changeset
|
741 branches = (None, branch or []) |
49745
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
742 # XXX path: simply use the peer `path` object when this become available |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
743 origsource = source = srcpeer.url() |
48494
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
744 srclock = destlock = destwlock = cleandir = None |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
745 destpeer = None |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
746 try: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
747 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
|
748 |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
749 if dest is None: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
750 dest = defaultdest(source) |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
751 if dest: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
752 ui.status(_(b"destination directory: %s\n") % dest) |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
753 else: |
49745
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
754 dest_path = urlutil.get_clone_path_obj(ui, dest) |
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
755 if dest_path is not None: |
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
756 dest = dest_path.rawloc |
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
757 else: |
0d7ecac8b6f7
path: pass `path` to `peer` in `hg clone`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49744
diff
changeset
|
758 dest = b'' |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
759 |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46819
diff
changeset
|
760 dest = urlutil.urllocalpath(dest) |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46819
diff
changeset
|
761 source = urlutil.urllocalpath(source) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
762 |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
763 if not dest: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
764 raise error.InputError(_(b"empty destination path is not valid")) |
21803
62cc4055c6c8
hg: use vfs functions in clone
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21802
diff
changeset
|
765 |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
766 destvfs = vfsmod.vfs(dest, expandpath=True) |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
767 if destvfs.lexists(): |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
768 if not destvfs.isdir(): |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
769 raise error.InputError( |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
770 _(b"destination '%s' already exists") % dest |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
771 ) |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
772 elif destvfs.listdir(): |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
773 raise error.InputError( |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
774 _(b"destination '%s' is not empty") % dest |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
775 ) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
776 |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
777 createopts = {} |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
778 narrow = False |
39550
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
779 |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
780 if storeincludepats is not None: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
781 narrowspec.validatepatterns(storeincludepats) |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
782 narrow = True |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
783 |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
784 if storeexcludepats is not None: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
785 narrowspec.validatepatterns(storeexcludepats) |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
786 narrow = True |
39550
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
787 |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
788 if narrow: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
789 # Include everything by default if only exclusion patterns defined. |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
790 if storeexcludepats and not storeincludepats: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
791 storeincludepats = {b'path:.'} |
39550
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
792 |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
793 createopts[b'narrowfiles'] = True |
39550
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
794 |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
795 if depth: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
796 createopts[b'shallowfilestore'] = True |
40390
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40366
diff
changeset
|
797 |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
798 if srcpeer.capable(b'lfs-serve'): |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
799 # Repository creation honors the config if it disabled the extension, so |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
800 # we can't just announce that lfs will be enabled. This check avoids |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
801 # saying that lfs will be enabled, and then saying it's an unknown |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
802 # feature. The lfs creation option is set in either case so that a |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
803 # requirement is added. If the extension is explicitly disabled but the |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
804 # requirement is set, the clone aborts early, before transferring any |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
805 # data. |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
806 createopts[b'lfs'] = True |
40324
6637b079ae45
lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
39849
diff
changeset
|
807 |
49779
7d6c8943353a
hg: show the correct message when cloning an LFS repo with extension disabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
49305
diff
changeset
|
808 if b'lfs' in extensions.disabled(): |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
809 ui.status( |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
810 _( |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
811 b'(remote is using large file support (lfs), but it is ' |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
812 b'explicitly disabled in the local configuration)\n' |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
813 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
814 ) |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
815 else: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
816 ui.status( |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
817 _( |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
818 b'(remote is using large file support (lfs); lfs will ' |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
819 b'be enabled for this repository)\n' |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
820 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
821 ) |
40324
6637b079ae45
lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
39849
diff
changeset
|
822 |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
823 shareopts = shareopts or {} |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
824 sharepool = shareopts.get(b'pool') |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
825 sharenamemode = shareopts.get(b'mode') |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
826 if sharepool and islocal(dest): |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
827 sharepath = None |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
828 if sharenamemode == b'identity': |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
829 # Resolve the name from the initial changeset in the remote |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
830 # repository. This returns nullid when the remote is empty. It |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
831 # raises RepoLookupError if revision 0 is filtered or otherwise |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
832 # not available. If we fail to resolve, sharing is not enabled. |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
833 try: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
834 with srcpeer.commandexecutor() as e: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
835 rootnode = e.callcommand( |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
836 b'lookup', |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
837 { |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
838 b'key': b'0', |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
839 }, |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
840 ).result() |
37640
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
841 |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46953
diff
changeset
|
842 if rootnode != sha1nodeconstants.nullid: |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
843 sharepath = os.path.join(sharepool, hex(rootnode)) |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
844 else: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
845 ui.status( |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
846 _( |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
847 b'(not using pooled storage: ' |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
848 b'remote appears to be empty)\n' |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
849 ) |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
850 ) |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
851 except error.RepoLookupError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
852 ui.status( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
853 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
854 b'(not using pooled storage: ' |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
855 b'unable to resolve identity of remote)\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
856 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
857 ) |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
858 elif sharenamemode == b'remote': |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
859 sharepath = os.path.join( |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
860 sharepool, hex(hashutil.sha1(source).digest()) |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
861 ) |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
862 else: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
863 raise error.Abort( |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
864 _(b'unknown share naming mode: %s') % sharenamemode |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
865 ) |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
866 |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
867 # TODO this is a somewhat arbitrary restriction. |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
868 if narrow: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
869 ui.status( |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
870 _(b'(pooled storage not supported for narrow clones)\n') |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
871 ) |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
872 sharepath = None |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
873 |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
874 if sharepath: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
875 return clonewithshare( |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
876 ui, |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
877 peeropts, |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
878 sharepath, |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
879 source, |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
880 srcpeer, |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
881 dest, |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
882 pull=pull, |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
883 rev=revs, |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
884 update=update, |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
885 stream=stream, |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
886 ) |
39550
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
887 |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
888 srcrepo = srcpeer.local() |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
889 |
14377
f90d5641c78b
clone: make default path absolute for all local paths
Brendan Cully <brendan@kublai.com>
parents:
14213
diff
changeset
|
890 abspath = origsource |
f90d5641c78b
clone: make default path absolute for all local paths
Brendan Cully <brendan@kublai.com>
parents:
14213
diff
changeset
|
891 if islocal(origsource): |
47626
1fdf315eff66
windows: use abspath in mercurial/hg.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47447
diff
changeset
|
892 abspath = util.abspath(urlutil.urllocalpath(origsource)) |
14377
f90d5641c78b
clone: make default path absolute for all local paths
Brendan Cully <brendan@kublai.com>
parents:
14213
diff
changeset
|
893 |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
894 if islocal(dest): |
47416
1c7f3d911d0f
clone: cleanup the "cleanup dir" logic used during local clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47299
diff
changeset
|
895 if os.path.exists(dest): |
1c7f3d911d0f
clone: cleanup the "cleanup dir" logic used during local clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47299
diff
changeset
|
896 # only clean up directories we create ourselves |
1c7f3d911d0f
clone: cleanup the "cleanup dir" logic used during local clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47299
diff
changeset
|
897 hgdir = os.path.realpath(os.path.join(dest, b".hg")) |
1c7f3d911d0f
clone: cleanup the "cleanup dir" logic used during local clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47299
diff
changeset
|
898 cleandir = hgdir |
1c7f3d911d0f
clone: cleanup the "cleanup dir" logic used during local clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47299
diff
changeset
|
899 else: |
1c7f3d911d0f
clone: cleanup the "cleanup dir" logic used during local clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47299
diff
changeset
|
900 cleandir = dest |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
901 |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
902 copy = False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
903 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
904 srcrepo |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
905 and srcrepo.cancopy() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
906 and islocal(dest) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
907 and not phases.hassecret(srcrepo) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
908 ): |
37262
54435fd09f1d
clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents:
37261
diff
changeset
|
909 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
|
910 |
39550
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
911 # TODO this is a somewhat arbitrary restriction. |
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
912 if narrow: |
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
913 copy = False |
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
914 |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
915 if copy: |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
916 try: |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
917 # 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
|
918 # 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
|
919 # 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
|
920 # fail |
14463
81f559d1b9b2
hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents:
14377
diff
changeset
|
921 srclock = srcrepo.lock(wait=False) |
7640 | 922 except error.LockError: |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
923 copy = False |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
924 |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
925 if copy: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
926 srcrepo.hook(b'preoutgoing', throw=True, source=b'clone') |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
927 |
47442
d1c1fd7ac46d
clone: use "official" API to create local clone destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47416
diff
changeset
|
928 destrootpath = urlutil.urllocalpath(dest) |
d1c1fd7ac46d
clone: use "official" API to create local clone destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47416
diff
changeset
|
929 dest_reqs = localrepo.clone_requirements(ui, createopts, srcrepo) |
d1c1fd7ac46d
clone: use "official" API to create local clone destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47416
diff
changeset
|
930 localrepo.createrepository( |
d1c1fd7ac46d
clone: use "official" API to create local clone destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47416
diff
changeset
|
931 ui, |
d1c1fd7ac46d
clone: use "official" API to create local clone destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47416
diff
changeset
|
932 destrootpath, |
d1c1fd7ac46d
clone: use "official" API to create local clone destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47416
diff
changeset
|
933 requirements=dest_reqs, |
d1c1fd7ac46d
clone: use "official" API to create local clone destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47416
diff
changeset
|
934 ) |
d1c1fd7ac46d
clone: use "official" API to create local clone destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47416
diff
changeset
|
935 destrepo = localrepo.makelocalrepository(ui, destrootpath) |
48494
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
936 |
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
937 destwlock = destrepo.wlock() |
47447
377d8fc20e34
clone: reuse the stream clone logic for local clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47442
diff
changeset
|
938 destlock = destrepo.lock() |
377d8fc20e34
clone: reuse the stream clone logic for local clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47442
diff
changeset
|
939 from . import streamclone # avoid cycle |
47442
d1c1fd7ac46d
clone: use "official" API to create local clone destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47416
diff
changeset
|
940 |
47447
377d8fc20e34
clone: reuse the stream clone logic for local clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47442
diff
changeset
|
941 streamclone.local_copy(srcrepo, destrepo) |
17740
e6067bec18da
branchcache: fetch source branchcache during clone (issue3378)
Tomasz Kleczek <tomasz.kleczek@fb.com>
parents:
17704
diff
changeset
|
942 |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
943 # 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
|
944 # 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
|
945 destpeer = peer(srcrepo, peeropts, dest) |
48494
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
946 |
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
947 # make the peer aware that is it already locked |
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
948 # |
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
949 # important: |
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
950 # |
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
951 # We still need to release that lock at the end of the function |
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
952 destpeer.local()._lockref = weakref.ref(destlock) |
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
953 destpeer.local()._wlockref = weakref.ref(destwlock) |
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
954 # dirstate also needs to be copied because `_wlockref` has a reference |
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
955 # to it: this dirstate is saved to disk when the wlock is released |
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
956 destpeer.local().dirstate = destrepo.dirstate |
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
957 |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46953
diff
changeset
|
958 srcrepo.hook( |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46953
diff
changeset
|
959 b'outgoing', source=b'clone', node=srcrepo.nodeconstants.nullhex |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46953
diff
changeset
|
960 ) |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
961 else: |
5569
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
962 try: |
39550
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
963 # only pass ui when no srcrepo |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
964 destpeer = peer( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
965 srcrepo or ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
966 peeropts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
967 dest, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
968 create=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
969 createopts=createopts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
970 ) |
49305
53e9422a9b45
py3: catch FileExistsError instead of checking errno == EEXIST
Manuel Jacob <me@manueljacob.de>
parents:
49301
diff
changeset
|
971 except FileExistsError: |
53e9422a9b45
py3: catch FileExistsError instead of checking errno == EEXIST
Manuel Jacob <me@manueljacob.de>
parents:
49301
diff
changeset
|
972 cleandir = None |
53e9422a9b45
py3: catch FileExistsError instead of checking errno == EEXIST
Manuel Jacob <me@manueljacob.de>
parents:
49301
diff
changeset
|
973 raise error.Abort(_(b"destination '%s' already exists") % dest) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
974 |
37262
54435fd09f1d
clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents:
37261
diff
changeset
|
975 if revs: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
976 if not srcpeer.capable(b'lookup'): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
977 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
978 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
979 b"src repository does not support " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
980 b"revision lookup and so doesn't " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
981 b"support clone by revision" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
982 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
983 ) |
37640
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
984 |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
985 # TODO this is batchable. |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
986 remoterevs = [] |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
987 for rev in revs: |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
988 with srcpeer.commandexecutor() as e: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
989 remoterevs.append( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
990 e.callcommand( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
991 b'lookup', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
992 { |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
993 b'key': rev, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
994 }, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
995 ).result() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
996 ) |
37640
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
997 revs = remoterevs |
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
998 |
8417
39cf453da958
clone: try updating to the actual changeset specified in options
Brett Carter <brett@rdnzl.net>
parents:
8312
diff
changeset
|
999 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
|
1000 else: |
54435fd09f1d
clone: rename "rev" to "revs" since there can be many
Martin von Zweigbergk <martinvonz@google.com>
parents:
37261
diff
changeset
|
1001 revs = None |
27165
70884715725e
localrepo: remove clone method by hoisting into hg.py
Augie Fackler <augie@google.com>
parents:
26781
diff
changeset
|
1002 local = destpeer.local() |
70884715725e
localrepo: remove clone method by hoisting into hg.py
Augie Fackler <augie@google.com>
parents:
26781
diff
changeset
|
1003 if local: |
39555
cb675e95a2c2
hg: write narrow patterns after repo creation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39553
diff
changeset
|
1004 if narrow: |
50189
6065a8936b00
narrow: write the narrow spec in a transaction during clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49845
diff
changeset
|
1005 with local.wlock(), local.lock(), local.transaction( |
6065a8936b00
narrow: write the narrow spec in a transaction during clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49845
diff
changeset
|
1006 b'narrow-clone' |
6065a8936b00
narrow: write the narrow spec in a transaction during clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49845
diff
changeset
|
1007 ): |
39555
cb675e95a2c2
hg: write narrow patterns after repo creation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39553
diff
changeset
|
1008 local.setnarrowpats(storeincludepats, storeexcludepats) |
41236
44a51c1c8e17
narrow: move copytonarrowspec() out of setnarrowpats()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41229
diff
changeset
|
1009 narrowspec.copytoworkingcopy(local) |
39555
cb675e95a2c2
hg: write narrow patterns after repo creation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39553
diff
changeset
|
1010 |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46819
diff
changeset
|
1011 u = urlutil.url(abspath) |
35565
bdae51a83dfb
clonebundle: make it possible to retrieve the initial bundle through largefile
Boris Feld <boris.feld@octobus.net>
parents:
35438
diff
changeset
|
1012 defaulturl = bytes(u) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1013 local.ui.setconfig(b'paths', b'default', defaulturl, b'clone') |
23545
68c434799559
hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents:
23139
diff
changeset
|
1014 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
|
1015 if pull: |
68c434799559
hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents:
23139
diff
changeset
|
1016 stream = False |
68c434799559
hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents:
23139
diff
changeset
|
1017 else: |
68c434799559
hg.clone: set 'stream' depending on whether --pull was requested or not
Siddharth Agarwal <sid0@fb.com>
parents:
23139
diff
changeset
|
1018 stream = None |
27165
70884715725e
localrepo: remove clone method by hoisting into hg.py
Augie Fackler <augie@google.com>
parents:
26781
diff
changeset
|
1019 # internal config: ui.quietbookmarkmove |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1020 overrides = {(b'ui', b'quietbookmarkmove'): True} |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1021 with local.ui.configoverride(overrides, b'clone'): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1022 exchange.pull( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1023 local, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1024 srcpeer, |
48241
7d1e60244561
path: keep the path instance in the `pulloperation`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48240
diff
changeset
|
1025 heads=revs, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1026 streamclonerequested=stream, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1027 includepats=storeincludepats, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1028 excludepats=storeexcludepats, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1029 depth=depth, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1030 ) |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
1031 elif srcrepo: |
39550
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
1032 # TODO lift restriction once exchange.push() accepts narrow |
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
1033 # push. |
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
1034 if narrow: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1035 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1036 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1037 b'narrow clone not available for ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1038 b'remote destinations' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1039 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1040 ) |
39550
65b5900f30be
hg: recognize include and exclude patterns when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39549
diff
changeset
|
1041 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1042 exchange.push( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1043 srcrepo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1044 destpeer, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1045 revs=revs, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1046 bookmarks=srcrepo._bookmarks.keys(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1047 ) |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
1048 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1049 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1050 _(b"clone from remote to remote not supported") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1051 ) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
1052 |
18441
1f794204abbd
hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents:
18382
diff
changeset
|
1053 cleandir = None |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
1054 |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
1055 destrepo = destpeer.local() |
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
1056 if destrepo: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1057 template = uimod.samplehgrcs[b'cloned'] |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46819
diff
changeset
|
1058 u = urlutil.url(abspath) |
15552
62c9183a0bbb
clone: don't save user's password in .hg/hgrc (Issue3122)
Augie Fackler <durin42@gmail.com>
parents:
15381
diff
changeset
|
1059 u.passwd = None |
33687
6294654453ee
py3: use bytes IO to write sample hgrc
Yuya Nishihara <yuya@tcha.org>
parents:
33018
diff
changeset
|
1060 defaulturl = bytes(u) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1061 destrepo.vfs.write(b'hgrc', util.tonativeeol(template % defaulturl)) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1062 destrepo.ui.setconfig(b'paths', b'default', defaulturl, b'clone') |
8814
ab668c92a036
subrepo: add update/merge logic
Matt Mackall <mpm@selenic.com>
parents:
8807
diff
changeset
|
1063 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1064 if ui.configbool(b'experimental', b'remotenames'): |
35347
a29fe459fc49
remotenames: rename related file and storage dir to logexchange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35331
diff
changeset
|
1065 logexchange.pullremotenames(destrepo, srcpeer) |
35331
773a9a06047c
clone: add support for storing remotenames while cloning
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34979
diff
changeset
|
1066 |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
1067 if update: |
6526
cfeeac24fc1e
repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents:
6525
diff
changeset
|
1068 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
|
1069 with srcpeer.commandexecutor() as e: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1070 checkout = e.callcommand( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
1071 b'lookup', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
1072 { |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
1073 b'key': update, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
1074 }, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1075 ).result() |
37640
ce8828217369
hg: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37579
diff
changeset
|
1076 |
17867
c9339efed653
clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17844
diff
changeset
|
1077 uprev = None |
17882
36ed69d4593d
clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents:
17875
diff
changeset
|
1078 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
|
1079 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
|
1080 # 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
|
1081 # 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
|
1082 # 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
|
1083 # out a better solution. |
e06a10d3b926
clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents:
38380
diff
changeset
|
1084 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
|
1085 uprev = checkout |
38753
e06a10d3b926
clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents:
38380
diff
changeset
|
1086 elif scmutil.isrevsymbol(destrepo, checkout): |
e06a10d3b926
clone: process 'lookup' return as an arbitrary symbol
Boris Feld <boris.feld@octobus.net>
parents:
38380
diff
changeset
|
1087 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
|
1088 else: |
26354
c1fb2cab6260
clone: check update rev for being True
Sean Farley <sean@farley.io>
parents:
26353
diff
changeset
|
1089 if update is not True: |
c1fb2cab6260
clone: check update rev for being True
Sean Farley <sean@farley.io>
parents:
26353
diff
changeset
|
1090 try: |
c1fb2cab6260
clone: check update rev for being True
Sean Farley <sean@farley.io>
parents:
26353
diff
changeset
|
1091 uprev = destrepo.lookup(update) |
c1fb2cab6260
clone: check update rev for being True
Sean Farley <sean@farley.io>
parents:
26353
diff
changeset
|
1092 except error.RepoLookupError: |
c1fb2cab6260
clone: check update rev for being True
Sean Farley <sean@farley.io>
parents:
26353
diff
changeset
|
1093 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
|
1094 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
|
1095 try: |
46198
72007a9ac064
clone: update to active bookmark, if set
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
46123
diff
changeset
|
1096 if destrepo._activebookmark: |
72007a9ac064
clone: update to active bookmark, if set
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
46123
diff
changeset
|
1097 uprev = destrepo.lookup(destrepo._activebookmark) |
72007a9ac064
clone: update to active bookmark, if set
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
46123
diff
changeset
|
1098 update = destrepo._activebookmark |
72007a9ac064
clone: update to active bookmark, if set
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
46123
diff
changeset
|
1099 else: |
72007a9ac064
clone: update to active bookmark, if set
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
46123
diff
changeset
|
1100 uprev = destrepo._bookmarks[b'@'] |
72007a9ac064
clone: update to active bookmark, if set
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
46123
diff
changeset
|
1101 update = b'@' |
17882
36ed69d4593d
clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents:
17875
diff
changeset
|
1102 bn = destrepo[uprev].branch() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1103 if bn == b'default': |
46198
72007a9ac064
clone: update to active bookmark, if set
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
46123
diff
changeset
|
1104 status = _(b"updating to bookmark %s\n" % update) |
17882
36ed69d4593d
clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents:
17875
diff
changeset
|
1105 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1106 status = ( |
46198
72007a9ac064
clone: update to active bookmark, if set
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
46123
diff
changeset
|
1107 _(b"updating to bookmark %s on branch %s\n") |
72007a9ac064
clone: update to active bookmark, if set
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
46123
diff
changeset
|
1108 ) % (update, 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
|
1109 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
|
1110 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1111 uprev = destrepo.branchtip(b'default') |
17867
c9339efed653
clone: make sure to use "@" as bookmark and "default" as branch (issue3677)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17844
diff
changeset
|
1112 except error.RepoLookupError: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1113 uprev = destrepo.lookup(b'tip') |
17882
36ed69d4593d
clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents:
17875
diff
changeset
|
1114 if not status: |
36ed69d4593d
clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents:
17875
diff
changeset
|
1115 bn = destrepo[uprev].branch() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1116 status = _(b"updating to branch %s\n") % bn |
17882
36ed69d4593d
clone: show status "updating to bookmark @"
Adrian Buehlmann <adrian@cadifra.com>
parents:
17875
diff
changeset
|
1117 destrepo.ui.status(status) |
14463
81f559d1b9b2
hg: remove underscores in clone function
Martin Geisler <mg@aragost.com>
parents:
14377
diff
changeset
|
1118 _update(destrepo, uprev) |
17703
4a07d2ff7c66
clone: activate bookmark specified with --updaterev
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17342
diff
changeset
|
1119 if update in destrepo._bookmarks: |
24945
e0b0fbd47491
bookmarks: rename setcurrent to activate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24440
diff
changeset
|
1120 bookmarks.activate(destrepo, update) |
46314
95a615dd77bf
clone: make sure we warm the cache after a clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46198
diff
changeset
|
1121 if destlock is not None: |
95a615dd77bf
clone: make sure we warm the cache after a clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46198
diff
changeset
|
1122 release(destlock) |
48494
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
1123 if destwlock is not None: |
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
1124 release(destlock) |
46314
95a615dd77bf
clone: make sure we warm the cache after a clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46198
diff
changeset
|
1125 # here is a tiny windows were someone could end up writing the |
95a615dd77bf
clone: make sure we warm the cache after a clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46198
diff
changeset
|
1126 # repository before the cache are sure to be warm. This is "fine" |
95a615dd77bf
clone: make sure we warm the cache after a clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46198
diff
changeset
|
1127 # as the only "bad" outcome would be some slowness. That potential |
95a615dd77bf
clone: make sure we warm the cache after a clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46198
diff
changeset
|
1128 # slowness already affect reader. |
95a615dd77bf
clone: make sure we warm the cache after a clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46198
diff
changeset
|
1129 with destrepo.lock(): |
47299
7edaf91c7886
updatecaches: use the `caches` argument instead of a special `full` value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47233
diff
changeset
|
1130 destrepo.updatecaches(caches=repositorymod.CACHES_POST_CLONE) |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
1131 finally: |
48494
b74ee41addee
sparse: lock the store when updating requirements config
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48241
diff
changeset
|
1132 release(srclock, destlock, destwlock) |
18441
1f794204abbd
hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents:
18382
diff
changeset
|
1133 if cleandir is not None: |
1f794204abbd
hg: replace DirCleanup class with normal try/finally use
Augie Fackler <raf@durin42.com>
parents:
18382
diff
changeset
|
1134 shutil.rmtree(cleandir, True) |
17191
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
1135 if srcpeer is not None: |
5884812686f7
peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents:
17159
diff
changeset
|
1136 srcpeer.close() |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
1137 if destpeer and destpeer.local() is None: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
1138 destpeer.close() |
19313
3b96d6e44a4d
hg: move return statement after finally block
simon@laptop-tosh
parents:
18944
diff
changeset
|
1139 return srcpeer, destpeer |
2775
b550cd82f92a
Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents:
2774
diff
changeset
|
1140 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1141 |
27402
5184089f5d30
hg: add quietempty flag to _showstats
timeless <timeless@mozdev.org>
parents:
27354
diff
changeset
|
1142 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
|
1143 if quietempty and stats.isempty(): |
27402
5184089f5d30
hg: add quietempty flag to _showstats
timeless <timeless@mozdev.org>
parents:
27354
diff
changeset
|
1144 return |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1145 repo.ui.status( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1146 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1147 b"%d files updated, %d files merged, " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1148 b"%d files removed, %d files unresolved\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1149 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1150 % ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1151 stats.updatedcount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1152 stats.mergedcount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1153 stats.removedcount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1154 stats.unresolvedcount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1155 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1156 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1157 |
3316
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
1158 |
31166
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
1159 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
|
1160 """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
|
1161 |
17c030014ddf
subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents:
17887
diff
changeset
|
1162 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
|
1163 |
17c030014ddf
subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents:
17887
diff
changeset
|
1164 returns stats (see pydoc mercurial.merge.applyupdates)""" |
45605
00402df57db7
updaterepo: add deprecation warning
Martin von Zweigbergk <martinvonz@google.com>
parents:
45577
diff
changeset
|
1165 repo.ui.deprecwarn( |
00402df57db7
updaterepo: add deprecation warning
Martin von Zweigbergk <martinvonz@google.com>
parents:
45577
diff
changeset
|
1166 b'prefer merge.update() or merge.clean_update() over hg.updaterepo()', |
00402df57db7
updaterepo: add deprecation warning
Martin von Zweigbergk <martinvonz@google.com>
parents:
45577
diff
changeset
|
1167 b'5.7', |
00402df57db7
updaterepo: add deprecation warning
Martin von Zweigbergk <martinvonz@google.com>
parents:
45577
diff
changeset
|
1168 ) |
45557
2c86b9587740
merge: make low-level update() private (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
45556
diff
changeset
|
1169 return mergemod._update( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1170 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1171 node, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1172 branchmerge=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1173 force=overwrite, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1174 labels=[b'working copy', b'destination'], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1175 updatecheck=updatecheck, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1176 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1177 |
17895
17c030014ddf
subrepo: only do clean update when overwrite is set (issue3276)
Simon Heimberg <simohe@besonet.ch>
parents:
17887
diff
changeset
|
1178 |
31166
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
1179 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
|
1180 """update the working directory to node""" |
45577
5c8230ca37f2
merge: replace calls to hg.updaterepo() by merge.update()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45557
diff
changeset
|
1181 stats = mergemod.update(repo[node], updatecheck=updatecheck) |
27404
1cf3543cc780
update: add quietempty flag to _showstats
timeless <timeless@mozdev.org>
parents:
27403
diff
changeset
|
1182 _showstats(repo, stats, quietempty) |
37125
6f570c501e3e
merge: deprecate accessing update results by index
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37107
diff
changeset
|
1183 if stats.unresolvedcount: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1184 repo.ui.status(_(b"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
|
1185 return stats.unresolvedcount > 0 |
2775
b550cd82f92a
Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents:
2774
diff
changeset
|
1186 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1187 |
7546
c7f48414f3ad
add a comment about the need of hg._update()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7280
diff
changeset
|
1188 # 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
|
1189 _update = update |
c7f48414f3ad
add a comment about the need of hg._update()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7280
diff
changeset
|
1190 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1191 |
27403
50b6a04f817f
histedit: omit useless message from abort
timeless <timeless@mozdev.org>
parents:
27402
diff
changeset
|
1192 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
|
1193 """forcibly switch the working directory to node, clobbering changes""" |
45556
03726f5b6092
merge: use merge.clean_update() when applicable
Martin von Zweigbergk <martinvonz@google.com>
parents:
45485
diff
changeset
|
1194 stats = mergemod.clean_update(repo[node]) |
44160
abcc82bf0717
clean: check that there are no conflicts after
Martin von Zweigbergk <martinvonz@google.com>
parents:
44060
diff
changeset
|
1195 assert stats.unresolvedcount == 0 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
1196 if show_stats: |
27403
50b6a04f817f
histedit: omit useless message from abort
timeless <timeless@mozdev.org>
parents:
27402
diff
changeset
|
1197 _showstats(repo, stats, quietempty) |
46761
af7535249ea9
hg: make `clean` return consistent with the `update` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46720
diff
changeset
|
1198 return False |
2775
b550cd82f92a
Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents:
2774
diff
changeset
|
1199 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1200 |
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
|
1201 # 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
|
1202 _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
|
1203 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1204 _VALID_UPDATECHECKS = { |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1205 mergemod.UPDATECHECK_ABORT, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1206 mergemod.UPDATECHECK_NONE, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1207 mergemod.UPDATECHECK_LINEAR, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1208 mergemod.UPDATECHECK_NO_CONFLICT, |
42971
ee1ef76d7339
hg: have `updatetotally` more thoroughly check updatecheck argument (API)
Augie Fackler <augie@google.com>
parents:
42970
diff
changeset
|
1209 } |
ee1ef76d7339
hg: have `updatetotally` more thoroughly check updatecheck argument (API)
Augie Fackler <augie@google.com>
parents:
42970
diff
changeset
|
1210 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1211 |
31166
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
1212 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
|
1213 """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
|
1214 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
1215 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
|
1216 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
1217 :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
|
1218 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
1219 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
|
1220 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
1221 :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
|
1222 :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
|
1223 :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
|
1224 :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
|
1225 |
42970
1ad3ebb39c61
merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents:
42813
diff
changeset
|
1226 Valid values for updatecheck are the UPDATECHECK_* constants |
1ad3ebb39c61
merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents:
42813
diff
changeset
|
1227 defined in the merge module. Passing `None` will result in using the |
1ad3ebb39c61
merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents:
42813
diff
changeset
|
1228 configured default. |
31166
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
1229 |
42970
1ad3ebb39c61
merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents:
42813
diff
changeset
|
1230 * ABORT: abort if the working directory is dirty |
1ad3ebb39c61
merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents:
42813
diff
changeset
|
1231 * NONE: don't check (merge working directory changes into destination) |
1ad3ebb39c61
merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents:
42813
diff
changeset
|
1232 * LINEAR: check that update is linear before merging working directory |
31166
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
1233 changes into destination |
42970
1ad3ebb39c61
merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents:
42813
diff
changeset
|
1234 * NO_CONFLICT: 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
|
1235 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
1236 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
|
1237 """ |
31166
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
1238 if updatecheck is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1239 updatecheck = ui.config(b'commands', b'update.check') |
42971
ee1ef76d7339
hg: have `updatetotally` more thoroughly check updatecheck argument (API)
Augie Fackler <augie@google.com>
parents:
42970
diff
changeset
|
1240 if updatecheck not in _VALID_UPDATECHECKS: |
31167
696e321b304d
update: add experimental config for default way of handling dirty wdir
Martin von Zweigbergk <martinvonz@google.com>
parents:
31166
diff
changeset
|
1241 # If not configured, or invalid value configured |
42970
1ad3ebb39c61
merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents:
42813
diff
changeset
|
1242 updatecheck = mergemod.UPDATECHECK_LINEAR |
42971
ee1ef76d7339
hg: have `updatetotally` more thoroughly check updatecheck argument (API)
Augie Fackler <augie@google.com>
parents:
42970
diff
changeset
|
1243 if updatecheck not in _VALID_UPDATECHECKS: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1244 raise ValueError( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1245 r'Invalid updatecheck value %r (can accept %r)' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1246 % (updatecheck, _VALID_UPDATECHECKS) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1247 ) |
28503
138ec8835e63
hg: acquire wlock while updating the working directory via updatetotally
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28501
diff
changeset
|
1248 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
|
1249 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
|
1250 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
|
1251 if checkout is None: |
30962
11c253997b0e
destutil: drop now-unused "check" parameter from destupdate()
Martin von Zweigbergk <martinvonz@google.com>
parents:
30062
diff
changeset
|
1252 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
|
1253 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
|
1254 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
|
1255 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
1256 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
|
1257 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
|
1258 else: |
42970
1ad3ebb39c61
merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents:
42813
diff
changeset
|
1259 if updatecheck == mergemod.UPDATECHECK_ABORT: |
30963
7beb3ec34443
update: move check for dirty wdir into hg.updatetotally()
Martin von Zweigbergk <martinvonz@google.com>
parents:
30962
diff
changeset
|
1260 cmdutil.bailifchanged(repo, merge=False) |
42970
1ad3ebb39c61
merge: replace magic strings with NAMED_CONSTANTS (API)
Augie Fackler <augie@google.com>
parents:
42813
diff
changeset
|
1261 updatecheck = mergemod.UPDATECHECK_NONE |
31166
fad5e299cfc7
update: accept --merge to allow merging across topo branches (issue5125)
Martin von Zweigbergk <martinvonz@google.com>
parents:
31133
diff
changeset
|
1262 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
|
1263 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
1264 if not ret and movemarkfrom: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1265 if movemarkfrom == repo[b'.'].node(): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1266 pass # no-op update |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1267 elif bookmarks.update(repo, [movemarkfrom], repo[b'.'].node()): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1268 b = ui.label(repo._activebookmark, b'bookmarks.active') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1269 ui.status(_(b"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
|
1270 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
|
1271 # this can happen with a non-linear update |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1272 b = ui.label(repo._activebookmark, b'bookmarks') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1273 ui.status(_(b"(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
|
1274 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
|
1275 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
|
1276 if brev != repo._activebookmark: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1277 b = ui.label(brev, b'bookmarks.active') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1278 ui.status(_(b"(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
|
1279 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
|
1280 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
|
1281 if repo._activebookmark: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1282 b = ui.label(repo._activebookmark, b'bookmarks') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1283 ui.status(_(b"(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
|
1284 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
|
1285 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
1286 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
|
1287 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
|
1288 |
66513f6ca038
commands: centralize code to update with extra care for non-file components
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28324
diff
changeset
|
1289 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
|
1290 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1291 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1292 def merge( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
1293 ctx, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
1294 force=False, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
1295 remind=True, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45847
diff
changeset
|
1296 labels=None, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1297 ): |
13162
115a9760c382
merge: document some internal return values.
Greg Ward <greg-hg@gerg.ca>
parents:
13047
diff
changeset
|
1298 """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
|
1299 unresolved conflicts.""" |
44434
2f290136b7d6
merge: make hg.merge() take a context instead of a node
Martin von Zweigbergk <martinvonz@google.com>
parents:
44399
diff
changeset
|
1300 repo = ctx.repo() |
2f290136b7d6
merge: make hg.merge() take a context instead of a node
Martin von Zweigbergk <martinvonz@google.com>
parents:
44399
diff
changeset
|
1301 stats = mergemod.merge(ctx, force=force, labels=labels) |
3316
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
1302 _showstats(repo, stats) |
37125
6f570c501e3e
merge: deprecate accessing update results by index
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37107
diff
changeset
|
1303 if stats.unresolvedcount: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1304 repo.ui.status( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1305 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1306 b"use 'hg resolve' to retry unresolved file merges " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1307 b"or 'hg merge --abort' to abandon\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1308 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1309 ) |
42600
3bc400ccbf99
abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents:
42155
diff
changeset
|
1310 elif remind: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1311 repo.ui.status(_(b"(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
|
1312 return stats.unresolvedcount > 0 |
2808
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
1313 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1314 |
42604
209f2b8a50dc
abort: removed labels argument from abortmerge()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42600
diff
changeset
|
1315 def abortmerge(ui, repo): |
44856
b7808443ed6a
mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents:
44657
diff
changeset
|
1316 ms = mergestatemod.mergestate.read(repo) |
42600
3bc400ccbf99
abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents:
42155
diff
changeset
|
1317 if ms.active(): |
3bc400ccbf99
abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents:
42155
diff
changeset
|
1318 # there were conflicts |
3bc400ccbf99
abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents:
42155
diff
changeset
|
1319 node = ms.localctx.hex() |
3bc400ccbf99
abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents:
42155
diff
changeset
|
1320 else: |
3bc400ccbf99
abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents:
42155
diff
changeset
|
1321 # there were no conficts, mergestate was not stored |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1322 node = repo[b'.'].hex() |
42600
3bc400ccbf99
abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents:
42155
diff
changeset
|
1323 |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43089
diff
changeset
|
1324 repo.ui.status(_(b"aborting the merge, updating back to %s\n") % node[:12]) |
44270
f546d2170b0f
merge: introduce a clean_update() for that use-case
Martin von Zweigbergk <martinvonz@google.com>
parents:
44178
diff
changeset
|
1325 stats = mergemod.clean_update(repo[node]) |
44175
2b6632d64328
merge: check that there are no conflicts after --abort
Martin von Zweigbergk <martinvonz@google.com>
parents:
44160
diff
changeset
|
1326 assert stats.unresolvedcount == 0 |
42600
3bc400ccbf99
abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents:
42155
diff
changeset
|
1327 _showstats(repo, stats) |
3bc400ccbf99
abort: added support for merge
Taapas Agrawal <taapas2897@gmail.com>
parents:
42155
diff
changeset
|
1328 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1329 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1330 def _incoming( |
46950
279df499511e
incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
1331 displaychlist, |
279df499511e
incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
1332 subreporecurse, |
279df499511e
incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
1333 ui, |
279df499511e
incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
1334 repo, |
279df499511e
incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
1335 source, |
279df499511e
incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
1336 opts, |
279df499511e
incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
1337 buffered=False, |
279df499511e
incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
1338 subpath=None, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1339 ): |
12730
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
1340 """ |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
1341 Helper for incoming / gincoming. |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
1342 displaychlist gets called with |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
1343 (remoterepo, incomingchangesetlist, displayer) parameters, |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
1344 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
|
1345 """ |
48240
607e9322fc89
path: return path instance directly from get_pull_paths
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48173
diff
changeset
|
1346 srcs = urlutil.get_pull_paths(repo, ui, [source]) |
46932
dec31caf5fd6
incoming: use `urlutil.get_pull_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46931
diff
changeset
|
1347 srcs = list(srcs) |
dec31caf5fd6
incoming: use `urlutil.get_pull_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46931
diff
changeset
|
1348 if len(srcs) != 1: |
47005
27602e030a1f
incoming: use bytes for an error message
Matt Harbison <matt_harbison@yahoo.com>
parents:
46953
diff
changeset
|
1349 msg = _(b'for now, incoming supports only a single source, %d provided') |
46932
dec31caf5fd6
incoming: use `urlutil.get_pull_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46931
diff
changeset
|
1350 msg %= len(srcs) |
dec31caf5fd6
incoming: use `urlutil.get_pull_paths`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46931
diff
changeset
|
1351 raise error.Abort(msg) |
48240
607e9322fc89
path: return path instance directly from get_pull_paths
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48173
diff
changeset
|
1352 path = srcs[0] |
49718
e64b1e9f4892
path: pass `path` to `peer` in `hg incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49707
diff
changeset
|
1353 if subpath is None: |
e64b1e9f4892
path: pass `path` to `peer` in `hg incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49707
diff
changeset
|
1354 peer_path = path |
e64b1e9f4892
path: pass `path` to `peer` in `hg incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49707
diff
changeset
|
1355 url = path.loc |
e64b1e9f4892
path: pass `path` to `peer` in `hg incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49707
diff
changeset
|
1356 else: |
e64b1e9f4892
path: pass `path` to `peer` in `hg incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49707
diff
changeset
|
1357 # XXX path: we are losing the `path` object here. Keeping it would be |
e64b1e9f4892
path: pass `path` to `peer` in `hg incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49707
diff
changeset
|
1358 # valuable. For example as a "variant" as we do for pushes. |
46950
279df499511e
incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
1359 subpath = urlutil.url(subpath) |
279df499511e
incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
1360 if subpath.isabs(): |
49718
e64b1e9f4892
path: pass `path` to `peer` in `hg incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49707
diff
changeset
|
1361 peer_path = url = bytes(subpath) |
46950
279df499511e
incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
1362 else: |
49718
e64b1e9f4892
path: pass `path` to `peer` in `hg incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49707
diff
changeset
|
1363 p = urlutil.url(path.loc) |
48551
f98d4d0a299a
subrepo: make -S work again on Windows for incoming/outgoing to remote repos
Matt Harbison <matt_harbison@yahoo.com>
parents:
48494
diff
changeset
|
1364 if p.islocal(): |
f98d4d0a299a
subrepo: make -S work again on Windows for incoming/outgoing to remote repos
Matt Harbison <matt_harbison@yahoo.com>
parents:
48494
diff
changeset
|
1365 normpath = os.path.normpath |
f98d4d0a299a
subrepo: make -S work again on Windows for incoming/outgoing to remote repos
Matt Harbison <matt_harbison@yahoo.com>
parents:
48494
diff
changeset
|
1366 else: |
f98d4d0a299a
subrepo: make -S work again on Windows for incoming/outgoing to remote repos
Matt Harbison <matt_harbison@yahoo.com>
parents:
48494
diff
changeset
|
1367 normpath = posixpath.normpath |
f98d4d0a299a
subrepo: make -S work again on Windows for incoming/outgoing to remote repos
Matt Harbison <matt_harbison@yahoo.com>
parents:
48494
diff
changeset
|
1368 p.path = normpath(b'%s/%s' % (p.path, subpath)) |
49718
e64b1e9f4892
path: pass `path` to `peer` in `hg incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49707
diff
changeset
|
1369 peer_path = url = bytes(p) |
e64b1e9f4892
path: pass `path` to `peer` in `hg incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49707
diff
changeset
|
1370 other = peer(repo, opts, peer_path) |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
1371 cleanupfn = other.close |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
1372 try: |
49718
e64b1e9f4892
path: pass `path` to `peer` in `hg incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49707
diff
changeset
|
1373 ui.status(_(b'comparing with %s\n') % urlutil.hidepassword(url)) |
e64b1e9f4892
path: pass `path` to `peer` in `hg incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49707
diff
changeset
|
1374 branches = (path.branch, opts.get(b'branch', [])) |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
1375 revs, checkout = addbranchrevs(repo, other, branches, opts.get(b'rev')) |
12730
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
1376 |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
1377 if revs: |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
1378 revs = [other.lookup(rev) for rev in revs] |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
1379 other, chlist, cleanupfn = bundlerepo.getremotechanges( |
48173
1d70fb83ff4a
hg: let extensions call the func without populating opts keys
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
48116
diff
changeset
|
1380 ui, repo, other, revs, opts.get(b"bundle"), opts.get(b"force") |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
1381 ) |
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
1382 |
14161
8a0fca925992
bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14156
diff
changeset
|
1383 if not chlist: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1384 ui.status(_(b"no changes found\n")) |
14161
8a0fca925992
bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14156
diff
changeset
|
1385 return subreporecurse() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1386 ui.pager(b'incoming') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1387 displayer = logcmdutil.changesetdisplayer( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1388 ui, other, opts, buffered=buffered |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1389 ) |
12730
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
1390 displaychlist(other, chlist, displayer) |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
1391 displayer.close() |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
1392 finally: |
14161
8a0fca925992
bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14156
diff
changeset
|
1393 cleanupfn() |
12730
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
1394 subreporecurse() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1395 return 0 # exit code is zero since we found incoming changes |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1396 |
12730
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
1397 |
46950
279df499511e
incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
1398 def incoming(ui, repo, source, opts, subpath=None): |
12730
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
1399 def subreporecurse(): |
12400
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1400 ret = 1 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1401 if opts.get(b'subrepos'): |
12400
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1402 ctx = repo[None] |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1403 for subpath in sorted(ctx.substate): |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1404 sub = ctx.sub(subpath) |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1405 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
|
1406 return ret |
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1407 |
12730
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12729
diff
changeset
|
1408 def display(other, chlist, displayer): |
35888
c8e2d6ed1f9e
cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35766
diff
changeset
|
1409 limit = logcmdutil.getlimit(opts) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1410 if opts.get(b'newest_first'): |
12729
55f0648c7e2d
incoming: rename variable
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12400
diff
changeset
|
1411 chlist.reverse() |
12273
e392d00ab5b0
incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12271
diff
changeset
|
1412 count = 0 |
12729
55f0648c7e2d
incoming: rename variable
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12400
diff
changeset
|
1413 for n in chlist: |
12273
e392d00ab5b0
incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12271
diff
changeset
|
1414 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
|
1415 break |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46953
diff
changeset
|
1416 parents = [ |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46953
diff
changeset
|
1417 p for p in other.changelog.parents(n) if p != repo.nullid |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46953
diff
changeset
|
1418 ] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1419 if opts.get(b'no_merges') and len(parents) == 2: |
12273
e392d00ab5b0
incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12271
diff
changeset
|
1420 continue |
e392d00ab5b0
incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12271
diff
changeset
|
1421 count += 1 |
e392d00ab5b0
incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12271
diff
changeset
|
1422 displayer.show(other[n]) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1423 |
46950
279df499511e
incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
1424 return _incoming( |
279df499511e
incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
1425 display, subreporecurse, ui, repo, source, opts, subpath=subpath |
279df499511e
incoming: kill the `repo._subtoppath =` hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46934
diff
changeset
|
1426 ) |
12273
e392d00ab5b0
incoming: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12271
diff
changeset
|
1427 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1428 |
46931
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1429 def _outgoing(ui, repo, dests, opts, subpath=None): |
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1430 out = set() |
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1431 others = [] |
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1432 for path in urlutil.get_push_paths(repo, ui, dests): |
49701
1470a533d28a
path: directly use the push_variant in outgoing internals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49693
diff
changeset
|
1433 dest = path.loc |
51611
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1434 if subpath is not None: |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1435 subpath = urlutil.url(subpath) |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1436 if subpath.isabs(): |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1437 dest = bytes(subpath) |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1438 else: |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1439 p = urlutil.url(dest) |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1440 if p.islocal(): |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1441 normpath = os.path.normpath |
48551
f98d4d0a299a
subrepo: make -S work again on Windows for incoming/outgoing to remote repos
Matt Harbison <matt_harbison@yahoo.com>
parents:
48494
diff
changeset
|
1442 else: |
51611
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1443 normpath = posixpath.normpath |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1444 p.path = normpath(b'%s/%s' % (p.path, subpath)) |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1445 dest = bytes(p) |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1446 branches = path.branch, opts.get(b'branch') or [] |
46930
0afe96e374a7
outgoing: pass subrepo path using function argument instead of abssource hack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46915
diff
changeset
|
1447 |
51611
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1448 ui.status(_(b'comparing with %s\n') % urlutil.hidepassword(dest)) |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1449 revs, checkout = addbranchrevs(repo, repo, branches, opts.get(b'rev')) |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1450 if revs: |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1451 revs = [repo[rev].node() for rev in logcmdutil.revrange(repo, revs)] |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1452 |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1453 other = peer(repo, opts, dest) |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1454 try: |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1455 outgoing = discovery.findcommonoutgoing( |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1456 repo, other, revs, force=opts.get(b'force') |
51609
fc317bd5b637
fold-or-prune-me: update proposal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51608
diff
changeset
|
1457 ) |
51611
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1458 o = outgoing.missing |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1459 out.update(o) |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1460 if not o: |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1461 scmutil.nochangesfound(repo.ui, repo, outgoing.excluded) |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1462 others.append(other) |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1463 except: # re-raises |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1464 other.close() |
436aee94f2d7
Backed out changeset fc317bd5b637
Raphaël Gomès <rgomes@octobus.net>
parents:
51609
diff
changeset
|
1465 raise |
46931
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1466 # make sure this is ordered by revision number |
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1467 outgoing_revs = list(out) |
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1468 cl = repo.changelog |
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1469 outgoing_revs.sort(key=cl.rev) |
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1470 return outgoing_revs, others |
12735
8888e56ac417
outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12734
diff
changeset
|
1471 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1472 |
46931
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1473 def _outgoing_recurse(ui, repo, dests, opts): |
46913
b2740c547243
outgoing: make `recurse` a real function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46912
diff
changeset
|
1474 ret = 1 |
b2740c547243
outgoing: make `recurse` a real function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46912
diff
changeset
|
1475 if opts.get(b'subrepos'): |
b2740c547243
outgoing: make `recurse` a real function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46912
diff
changeset
|
1476 ctx = repo[None] |
b2740c547243
outgoing: make `recurse` a real function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46912
diff
changeset
|
1477 for subpath in sorted(ctx.substate): |
b2740c547243
outgoing: make `recurse` a real function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46912
diff
changeset
|
1478 sub = ctx.sub(subpath) |
46931
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1479 ret = min(ret, sub.outgoing(ui, dests, opts)) |
46913
b2740c547243
outgoing: make `recurse` a real function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46912
diff
changeset
|
1480 return ret |
b2740c547243
outgoing: make `recurse` a real function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46912
diff
changeset
|
1481 |
b2740c547243
outgoing: make `recurse` a real function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46912
diff
changeset
|
1482 |
46914
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1483 def _outgoing_filter(repo, revs, opts): |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1484 """apply revision filtering/ordering option for outgoing""" |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1485 limit = logcmdutil.getlimit(opts) |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1486 no_merges = opts.get(b'no_merges') |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1487 if opts.get(b'newest_first'): |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1488 revs.reverse() |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1489 if limit is None and not no_merges: |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1490 for r in revs: |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1491 yield r |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1492 return |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1493 |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1494 count = 0 |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1495 cl = repo.changelog |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1496 for n in revs: |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1497 if limit is not None and count >= limit: |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1498 break |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46953
diff
changeset
|
1499 parents = [p for p in cl.parents(n) if p != repo.nullid] |
46914
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1500 if no_merges and len(parents) == 2: |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1501 continue |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1502 count += 1 |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1503 yield n |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1504 |
50b79f8b802d
outgoing: move filtering logic in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46913
diff
changeset
|
1505 |
46931
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1506 def outgoing(ui, repo, dests, opts, subpath=None): |
46915
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1507 if opts.get(b'graph'): |
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1508 logcmdutil.checkunsupportedgraphflags([], opts) |
46931
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1509 o, others = _outgoing(ui, repo, dests, opts, subpath=subpath) |
46912
627bb1875fee
outgoing: remove some early return
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
1510 ret = 1 |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
1511 try: |
46912
627bb1875fee
outgoing: remove some early return
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
1512 if o: |
627bb1875fee
outgoing: remove some early return
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
1513 ret = 0 |
12400
40852b4b910c
incoming/outgoing: Fix recursion on sub repositories
Erik Zielke <ez@aragost.com>
parents:
12314
diff
changeset
|
1514 |
46915
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1515 if opts.get(b'graph'): |
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1516 revdag = logcmdutil.graphrevs(repo, o, opts) |
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1517 ui.pager(b'outgoing') |
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1518 displayer = logcmdutil.changesetdisplayer( |
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1519 ui, repo, opts, buffered=True |
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1520 ) |
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1521 logcmdutil.displaygraph( |
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1522 ui, repo, revdag, displayer, graphmod.asciiedges |
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1523 ) |
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1524 else: |
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1525 ui.pager(b'outgoing') |
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1526 displayer = logcmdutil.changesetdisplayer(ui, repo, opts) |
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1527 for n in _outgoing_filter(repo, o, opts): |
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1528 displayer.show(repo[n]) |
efc6f6a794bd
outgoing: merge the code handling --graph with the main one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46914
diff
changeset
|
1529 displayer.close() |
46931
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1530 for oth in others: |
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1531 cmdutil.outgoinghooks(ui, repo, oth, opts, o) |
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1532 ret = min(ret, _outgoing_recurse(ui, repo, dests, opts)) |
46912
627bb1875fee
outgoing: remove some early return
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46908
diff
changeset
|
1533 return ret # exit code is zero since we found outgoing changes |
46663
a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
46314
diff
changeset
|
1534 finally: |
46931
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1535 for oth in others: |
d4e4ccb75f99
outgoing: accept multiple destinations
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46930
diff
changeset
|
1536 oth.close() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1537 |
12271
01dc8ba3e032
outgoing: move code from commands to cmdutil
Martin Geisler <mg@lazybytes.net>
parents:
12144
diff
changeset
|
1538 |
42155
57539e5ea2e0
verify: introduce a notion of "level"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42109
diff
changeset
|
1539 def verify(repo, level=None): |
2778 | 1540 """verify the consistency of a repository""" |
42155
57539e5ea2e0
verify: introduce a notion of "level"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42109
diff
changeset
|
1541 ret = verifymod.verify(repo, level=level) |
25591
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1542 |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1543 # 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
|
1544 # 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
|
1545 # concern. |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1546 |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1547 # pathto() is needed for -R case |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1548 revs = repo.revs( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1549 b"filelog(%s)", util.pathto(repo.root, repo.getcwd(), b'.hgsubstate') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1550 ) |
25591
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1551 |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1552 if revs: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1553 repo.ui.status(_(b'checking subrepo links\n')) |
25591
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1554 for rev in revs: |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1555 ctx = repo[rev] |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1556 try: |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1557 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
|
1558 try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1559 ret = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1560 ctx.sub(subpath, allowcreate=False).verify() or ret |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1561 ) |
29021
92d37fb3f1aa
verify: don't init subrepo when missing one is referenced (issue5128) (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
28655
diff
changeset
|
1562 except error.RepoError as e: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1563 repo.ui.warn(b'%d: %s\n' % (rev, e)) |
25591
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1564 except Exception: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1565 repo.ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1566 _(b'.hgsubstate is corrupt in revision %s\n') |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45942
diff
changeset
|
1567 % short(ctx.node()) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1568 ) |
25591
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1569 |
f1d46075b13a
verify: check the subrepository references in .hgsubstate
Matt Harbison <matt_harbison@yahoo.com>
parents:
25365
diff
changeset
|
1570 return ret |
11273
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1571 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1572 |
11273
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1573 def remoteui(src, opts): |
43787
be8552f25cab
cleanup: fix docstring formatting
Matt Harbison <matt_harbison@yahoo.com>
parents:
43238
diff
changeset
|
1574 """build a remote ui from ui or repo and opts""" |
50928
d718eddf01d9
safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50911
diff
changeset
|
1575 if hasattr(src, 'baseui'): # looks like a repository |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1576 dst = src.baseui.copy() # drop repo-specific config |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1577 src = src.ui # copy target options from repo |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1578 else: # assume it's a global ui object |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1579 dst = src.copy() # keep all global options |
11273
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1580 |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1581 # copy ssh-specific options |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1582 for o in b'ssh', b'remotecmd': |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1583 v = opts.get(o) or src.config(b'ui', o) |
11273
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1584 if v: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1585 dst.setconfig(b"ui", o, v, b'copied') |
11273
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1586 |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1587 # copy bundle-specific options |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1588 r = src.config(b'bundle', b'mainreporoot') |
11273
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1589 if r: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1590 dst.setconfig(b'bundle', b'mainreporoot', r, b'copied') |
11273
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1591 |
13192
4d03707916d3
https: use web.cacerts configuration from local repo to validate remote repo
Mads Kiilerich <mads@kiilerich.com>
parents:
12735
diff
changeset
|
1592 # copy selected local settings to the remote ui |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1593 for sect in (b'auth', b'hostfingerprints', b'hostsecurity', b'http_proxy'): |
11273
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1594 for key, val in src.configitems(sect): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1595 dst.setconfig(sect, key, val, b'copied') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1596 v = src.config(b'web', b'cacerts') |
29594
e417664a3339
ssl: remove special case of web.cacerts=! from remoteui()
Yuya Nishihara <yuya@tcha.org>
parents:
29424
diff
changeset
|
1597 if v: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1598 dst.setconfig(b'web', b'cacerts', util.expandpath(v), b'copied') |
11273
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1599 |
d1908cb95a82
remoteui: move from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
11256
diff
changeset
|
1600 return dst |
26219
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1601 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1602 |
26219
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1603 # Files of interest |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1604 # 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
|
1605 # these files. |
51674
e8f58714bcf0
typing: add a type hint to `mercurial/hg.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51612
diff
changeset
|
1606 foi: "List[Tuple[str, bytes]]" = [ |
50911
1339158a8a40
cachedlocalrepo: use sysstr for attribute name of "file of interest"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50575
diff
changeset
|
1607 ('spath', b'00changelog.i'), |
1339158a8a40
cachedlocalrepo: use sysstr for attribute name of "file of interest"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50575
diff
changeset
|
1608 ('spath', b'phaseroots'), # ! phase can change content at the same size |
1339158a8a40
cachedlocalrepo: use sysstr for attribute name of "file of interest"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50575
diff
changeset
|
1609 ('spath', b'obsstore'), |
1339158a8a40
cachedlocalrepo: use sysstr for attribute name of "file of interest"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50575
diff
changeset
|
1610 ('path', b'bookmarks'), # ! bookmark can change content at the same size |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1611 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1612 |
26219
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1613 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
1614 class cachedlocalrepo: |
26219
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1615 """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
|
1616 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1617 def __init__(self, repo): |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1618 """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
|
1619 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1620 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
|
1621 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
|
1622 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
|
1623 """ |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1624 assert isinstance(repo, localrepo.localrepository) |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1625 self._repo = repo |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1626 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
|
1627 self._filtername = repo.filtername |
26219
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1628 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1629 def fetch(self): |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1630 """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
|
1631 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1632 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
|
1633 automatically and returned. |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1634 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1635 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
|
1636 repo instance was created. |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1637 """ |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1638 # 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
|
1639 # 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
|
1640 # 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
|
1641 # 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
|
1642 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1643 state, mtime = self._repostate() |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1644 if state == self._state: |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1645 return self._repo, False |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1646 |
28119
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1647 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
|
1648 if self._filtername: |
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1649 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
|
1650 else: |
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1651 self._repo = repo.unfiltered() |
26219
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1652 self._state = state |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1653 self.mtime = mtime |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1654 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1655 return self._repo, True |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1656 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1657 def _repostate(self): |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1658 state = [] |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1659 maxmtime = -1 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1660 for attr, fname in foi: |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1661 prefix = getattr(self._repo, attr) |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1662 p = os.path.join(prefix, fname) |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1663 try: |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1664 st = os.stat(p) |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1665 except OSError: |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1666 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
|
1667 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
|
1668 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
|
1669 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1670 return tuple(state), maxmtime |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1671 |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1672 def copy(self): |
26240
2b1434e5eaa0
hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26219
diff
changeset
|
1673 """Obtain a copy of this class instance. |
2b1434e5eaa0
hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26219
diff
changeset
|
1674 |
2b1434e5eaa0
hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26219
diff
changeset
|
1675 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
|
1676 completely independent of the original. |
2b1434e5eaa0
hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26219
diff
changeset
|
1677 """ |
2b1434e5eaa0
hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26219
diff
changeset
|
1678 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
|
1679 if self._filtername: |
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1680 repo = repo.filtered(self._filtername) |
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1681 else: |
91a827e760df
hg: make cachedlocalrepo cache appropriate repoview object
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28020
diff
changeset
|
1682 repo = repo.unfiltered() |
26240
2b1434e5eaa0
hg: always create new localrepository instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26219
diff
changeset
|
1683 c = cachedlocalrepo(repo) |
26219
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1684 c._state = self._state |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1685 c.mtime = self.mtime |
ae33fff17c1e
hg: establish a cache for localrepository instances
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26103
diff
changeset
|
1686 return c |