author | Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de> |
Wed, 22 Apr 2009 02:01:22 +0200 | |
changeset 8110 | b616f328af9f |
parent 8109 | 496ae1ea4698 |
child 8174 | 29bc5d18714a |
permissions | -rw-r--r-- |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
1 |
# hg.py - repository classes for mercurial |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
2 |
# |
4635
63b9d2deed48
Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4478
diff
changeset
|
3 |
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
2859 | 4 |
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
5 |
# |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
6 |
# This software may be used and distributed according to the terms |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
7 |
# of the GNU General Public License, incorporated herein by reference. |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
8 |
|
3891 | 9 |
from i18n import _ |
8109
496ae1ea4698
switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7935
diff
changeset
|
10 |
from lock import release |
3877
abaee83ce0a6
Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents:
3869
diff
changeset
|
11 |
import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo |
7640 | 12 |
import errno, lock, os, shutil, util, extensions, error |
3877
abaee83ce0a6
Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents:
3869
diff
changeset
|
13 |
import merge as _merge |
abaee83ce0a6
Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents:
3869
diff
changeset
|
14 |
import verify as _verify |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
15 |
|
2740
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
16 |
def _local(path): |
3195
705e30c0a230
Make hg.repository work with no path argument
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
17 |
return (os.path.isfile(util.drop_scheme('file', path)) and |
2768
b1b1aa6f275c
allow None for path of hg.repository
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2740
diff
changeset
|
18 |
bundlerepo or localrepo) |
2469
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
19 |
|
6525
a020247d75e5
parseurl: make revs optional
Bryan O'Sullivan <bos@serpentine.com>
parents:
6524
diff
changeset
|
20 |
def parseurl(url, revs=[]): |
5177
92236732d5a1
move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
4917
diff
changeset
|
21 |
'''parse url#branch, returning url, branch + revs''' |
92236732d5a1
move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
4917
diff
changeset
|
22 |
|
92236732d5a1
move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
4917
diff
changeset
|
23 |
if '#' not in url: |
7045
f82938c87b92
clone: honor -r even when pulling named branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7044
diff
changeset
|
24 |
return url, (revs or None), revs and revs[-1] or None |
5177
92236732d5a1
move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
4917
diff
changeset
|
25 |
|
7045
f82938c87b92
clone: honor -r even when pulling named branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7044
diff
changeset
|
26 |
url, branch = url.split('#', 1) |
f82938c87b92
clone: honor -r even when pulling named branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7044
diff
changeset
|
27 |
checkout = revs and revs[-1] or branch |
f82938c87b92
clone: honor -r even when pulling named branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7044
diff
changeset
|
28 |
return url, revs + [branch], checkout |
5177
92236732d5a1
move parseurl from cmdutil to hg
Matt Mackall <mpm@selenic.com>
parents:
4917
diff
changeset
|
29 |
|
2472
e6ec81a8feea
make repo scheme table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
30 |
schemes = { |
2740
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
31 |
'bundle': bundlerepo, |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
32 |
'file': _local, |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
33 |
'http': httprepo, |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
34 |
'https': httprepo, |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
35 |
'ssh': sshrepo, |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
36 |
'static-http': statichttprepo, |
4853
bf10a03a6b24
Removed deprecated hg:// and old-http:// protocols (issue406)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4818
diff
changeset
|
37 |
} |
2469
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
38 |
|
2740
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
39 |
def _lookup(path): |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
40 |
scheme = 'file' |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
41 |
if path: |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
42 |
c = path.find(':') |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
43 |
if c > 0: |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
44 |
scheme = path[:c] |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
45 |
thing = schemes.get(scheme) or schemes['file'] |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
46 |
try: |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
47 |
return thing(path) |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
48 |
except TypeError: |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
49 |
return thing |
2775
b550cd82f92a
Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents:
2774
diff
changeset
|
50 |
|
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
51 |
def islocal(repo): |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
52 |
'''return true if repo or path is local''' |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
53 |
if isinstance(repo, str): |
2740
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
54 |
try: |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
55 |
return _lookup(repo).islocal(repo) |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
56 |
except AttributeError: |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
57 |
return False |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
58 |
return repo.local() |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
59 |
|
3195
705e30c0a230
Make hg.repository work with no path argument
Brendan Cully <brendan@kublai.com>
parents:
3072
diff
changeset
|
60 |
def repository(ui, path='', create=False): |
2774 | 61 |
"""return a repository object for the specified path""" |
2847
2ff57e3113a4
call reposetup functions of extension modules whenever repo created
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2830
diff
changeset
|
62 |
repo = _lookup(path).instance(ui, path, create) |
4074
0f9381cf9723
Try to pass repo.ui to reposetup hooks
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3869
diff
changeset
|
63 |
ui = getattr(repo, "ui", ui) |
5192
60acf1432ee0
Move cmdtable and reposetup handling out of extensions.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5187
diff
changeset
|
64 |
for name, module in extensions.extensions(): |
60acf1432ee0
Move cmdtable and reposetup handling out of extensions.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5187
diff
changeset
|
65 |
hook = getattr(module, 'reposetup', None) |
60acf1432ee0
Move cmdtable and reposetup handling out of extensions.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5187
diff
changeset
|
66 |
if hook: |
60acf1432ee0
Move cmdtable and reposetup handling out of extensions.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5187
diff
changeset
|
67 |
hook(ui, repo) |
2847
2ff57e3113a4
call reposetup functions of extension modules whenever repo created
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2830
diff
changeset
|
68 |
return repo |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
69 |
|
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
70 |
def defaultdest(source): |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
71 |
'''return default destination of clone if none is given''' |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
72 |
return os.path.basename(os.path.normpath(source)) |
2774 | 73 |
|
6524
23ef198efce9
Hoist localpath to the top level
Bryan O'Sullivan <bos@serpentine.com>
parents:
6518
diff
changeset
|
74 |
def localpath(path): |
23ef198efce9
Hoist localpath to the top level
Bryan O'Sullivan <bos@serpentine.com>
parents:
6518
diff
changeset
|
75 |
if path.startswith('file://localhost/'): |
23ef198efce9
Hoist localpath to the top level
Bryan O'Sullivan <bos@serpentine.com>
parents:
6518
diff
changeset
|
76 |
return path[16:] |
23ef198efce9
Hoist localpath to the top level
Bryan O'Sullivan <bos@serpentine.com>
parents:
6518
diff
changeset
|
77 |
if path.startswith('file://'): |
23ef198efce9
Hoist localpath to the top level
Bryan O'Sullivan <bos@serpentine.com>
parents:
6518
diff
changeset
|
78 |
return path[7:] |
23ef198efce9
Hoist localpath to the top level
Bryan O'Sullivan <bos@serpentine.com>
parents:
6518
diff
changeset
|
79 |
if path.startswith('file:'): |
23ef198efce9
Hoist localpath to the top level
Bryan O'Sullivan <bos@serpentine.com>
parents:
6518
diff
changeset
|
80 |
return path[5:] |
23ef198efce9
Hoist localpath to the top level
Bryan O'Sullivan <bos@serpentine.com>
parents:
6518
diff
changeset
|
81 |
return path |
23ef198efce9
Hoist localpath to the top level
Bryan O'Sullivan <bos@serpentine.com>
parents:
6518
diff
changeset
|
82 |
|
2613
479e26afa10f
clone: do not make streaming default. add --stream option instead.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
83 |
def clone(ui, source, dest=None, pull=False, rev=None, update=True, |
479e26afa10f
clone: do not make streaming default. add --stream option instead.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
84 |
stream=False): |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
85 |
"""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
|
86 |
|
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
87 |
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
|
88 |
source and destination are URLs, as passed to the repository |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
89 |
function. Returns a pair of repository objects, the source and |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
90 |
newly created destination. |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
91 |
|
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
92 |
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
|
93 |
.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
|
94 |
pushes. |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
95 |
|
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
96 |
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
|
97 |
repository will be deleted. |
2600
c4325f0a9b91
clean up trailing white space.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2597
diff
changeset
|
98 |
|
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
99 |
Arguments: |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
100 |
|
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
101 |
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
|
102 |
|
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
103 |
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
|
104 |
name of source repository) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
105 |
|
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
106 |
pull: always pull from source repository, even in local case |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
107 |
|
2621
5a5852a417b1
clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2613
diff
changeset
|
108 |
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
|
109 |
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
|
110 |
|
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
111 |
rev: revision to clone up to (implies pull=True) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
112 |
|
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
113 |
update: update working directory after clone completes, if |
6526
cfeeac24fc1e
repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents:
6525
diff
changeset
|
114 |
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
|
115 |
anything else is treated as a revision) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
116 |
""" |
4478
b2b55acbacdd
Add support for url#id syntax
Matt Mackall <mpm@selenic.com>
parents:
4477
diff
changeset
|
117 |
|
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
118 |
if isinstance(source, str): |
6089
28054773438c
clone: make things work when source is a repo object
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
6088
diff
changeset
|
119 |
origsource = ui.expandpath(source) |
28054773438c
clone: make things work when source is a repo object
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
6088
diff
changeset
|
120 |
source, rev, checkout = parseurl(origsource, rev) |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
121 |
src_repo = repository(ui, source) |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
122 |
else: |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
123 |
src_repo = source |
6089
28054773438c
clone: make things work when source is a repo object
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
6088
diff
changeset
|
124 |
origsource = source = src_repo.url() |
7045
f82938c87b92
clone: honor -r even when pulling named branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7044
diff
changeset
|
125 |
checkout = rev and rev[-1] or None |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
126 |
|
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
127 |
if dest is None: |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
128 |
dest = defaultdest(source) |
3841
aaeb7f5d1052
Show the destionation for clone if not specified manually.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3791
diff
changeset
|
129 |
ui.status(_("destination directory: %s\n") % dest) |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
130 |
|
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
131 |
dest = localpath(dest) |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
132 |
source = localpath(source) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
133 |
|
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
134 |
if os.path.exists(dest): |
7927
a218ba5f60df
allow clone into existing but empty directories
Steve Borho <steve@borho.org>
parents:
7821
diff
changeset
|
135 |
if not os.path.isdir(dest): |
a218ba5f60df
allow clone into existing but empty directories
Steve Borho <steve@borho.org>
parents:
7821
diff
changeset
|
136 |
raise util.Abort(_("destination '%s' already exists") % dest) |
a218ba5f60df
allow clone into existing but empty directories
Steve Borho <steve@borho.org>
parents:
7821
diff
changeset
|
137 |
elif os.listdir(dest): |
a218ba5f60df
allow clone into existing but empty directories
Steve Borho <steve@borho.org>
parents:
7821
diff
changeset
|
138 |
raise util.Abort(_("destination '%s' is not empty") % dest) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
139 |
|
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
140 |
class DirCleanup(object): |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
141 |
def __init__(self, dir_): |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
142 |
self.rmtree = shutil.rmtree |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
143 |
self.dir_ = dir_ |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
144 |
def close(self): |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
145 |
self.dir_ = None |
8110
b616f328af9f
switch dircleanup in mercurial.hg.clone from gc based to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
8109
diff
changeset
|
146 |
def cleanup(self): |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
147 |
if self.dir_: |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
148 |
self.rmtree(self.dir_, True) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
149 |
|
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
150 |
src_lock = dest_lock = dir_cleanup = None |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
151 |
try: |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
152 |
if islocal(dest): |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
153 |
dir_cleanup = DirCleanup(dest) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
154 |
|
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
155 |
abspath = origsource |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
156 |
copy = False |
6315 | 157 |
if src_repo.cancopy() and islocal(dest): |
5248 | 158 |
abspath = os.path.abspath(util.drop_scheme('file', origsource)) |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
159 |
copy = not pull and not rev |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
160 |
|
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
161 |
if copy: |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
162 |
try: |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
163 |
# 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
|
164 |
# 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
|
165 |
# 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
|
166 |
# fail |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
167 |
src_lock = src_repo.lock() |
7640 | 168 |
except error.LockError: |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
169 |
copy = False |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
170 |
|
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
171 |
if copy: |
7935
39566bb99a9c
on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents:
7927
diff
changeset
|
172 |
hgdir = os.path.realpath(os.path.join(dest, ".hg")) |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
173 |
if not os.path.exists(dest): |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
174 |
os.mkdir(dest) |
7935
39566bb99a9c
on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents:
7927
diff
changeset
|
175 |
else: |
39566bb99a9c
on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents:
7927
diff
changeset
|
176 |
# only clean up directories we create ourselves |
39566bb99a9c
on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents:
7927
diff
changeset
|
177 |
dir_cleanup.dir_ = hgdir |
5569
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
178 |
try: |
7935
39566bb99a9c
on clone failure, only remove directories we created
Steve Borho <steve@borho.org>
parents:
7927
diff
changeset
|
179 |
dest_path = hgdir |
5569
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
180 |
os.mkdir(dest_path) |
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
181 |
except OSError, inst: |
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
182 |
if inst.errno == errno.EEXIST: |
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
183 |
dir_cleanup.close() |
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
184 |
raise util.Abort(_("destination '%s' already exists") |
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
185 |
% dest) |
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
186 |
raise |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
187 |
|
6903
0642d9d7ec80
clone: get a list of files to clone from store
Matt Mackall <mpm@selenic.com>
parents:
6526
diff
changeset
|
188 |
for f in src_repo.store.copylist(): |
0642d9d7ec80
clone: get a list of files to clone from store
Matt Mackall <mpm@selenic.com>
parents:
6526
diff
changeset
|
189 |
src = os.path.join(src_repo.path, f) |
6944
7e5f3480c45b
fix regression on empty repo cloning introduced by 0642d9d7ec80
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6903
diff
changeset
|
190 |
dst = os.path.join(dest_path, f) |
7e5f3480c45b
fix regression on empty repo cloning introduced by 0642d9d7ec80
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6903
diff
changeset
|
191 |
dstbase = os.path.dirname(dst) |
7e5f3480c45b
fix regression on empty repo cloning introduced by 0642d9d7ec80
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6903
diff
changeset
|
192 |
if dstbase and not os.path.exists(dstbase): |
7e5f3480c45b
fix regression on empty repo cloning introduced by 0642d9d7ec80
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6903
diff
changeset
|
193 |
os.mkdir(dstbase) |
6903
0642d9d7ec80
clone: get a list of files to clone from store
Matt Mackall <mpm@selenic.com>
parents:
6526
diff
changeset
|
194 |
if os.path.exists(src): |
0642d9d7ec80
clone: get a list of files to clone from store
Matt Mackall <mpm@selenic.com>
parents:
6526
diff
changeset
|
195 |
if dst.endswith('data'): |
0642d9d7ec80
clone: get a list of files to clone from store
Matt Mackall <mpm@selenic.com>
parents:
6526
diff
changeset
|
196 |
# lock to avoid premature writing to the target |
0642d9d7ec80
clone: get a list of files to clone from store
Matt Mackall <mpm@selenic.com>
parents:
6526
diff
changeset
|
197 |
dest_lock = lock.lock(os.path.join(dstbase, "lock")) |
0642d9d7ec80
clone: get a list of files to clone from store
Matt Mackall <mpm@selenic.com>
parents:
6526
diff
changeset
|
198 |
util.copyfiles(src, dst) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
199 |
|
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
200 |
# 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
|
201 |
# into it |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
202 |
dest_repo = repository(ui, dest) |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
203 |
|
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
204 |
else: |
5569
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
205 |
try: |
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
206 |
dest_repo = repository(ui, dest, create=True) |
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
207 |
except OSError, inst: |
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
208 |
if inst.errno == errno.EEXIST: |
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
209 |
dir_cleanup.close() |
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
210 |
raise util.Abort(_("destination '%s' already exists") |
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
211 |
% dest) |
9e209193f18d
clone: fix race with same target directory (issue716)
Matt Mackall <mpm@selenic.com>
parents:
5277
diff
changeset
|
212 |
raise |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
213 |
|
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
214 |
revs = None |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
215 |
if rev: |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
216 |
if 'lookup' not in src_repo.capabilities: |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
217 |
raise util.Abort(_("src repository does not support revision " |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
218 |
"lookup and so doesn't support clone by " |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
219 |
"revision")) |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
220 |
revs = [src_repo.lookup(r) for r in rev] |
3849
972d14a5a227
don't use localrepo.__init__ to create the dest repo with clone+hardlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3791
diff
changeset
|
221 |
|
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
222 |
if dest_repo.local(): |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
223 |
dest_repo.clone(src_repo, heads=revs, stream=stream) |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
224 |
elif src_repo.local(): |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
225 |
src_repo.push(dest_repo, revs=revs) |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
226 |
else: |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
227 |
raise util.Abort(_("clone from remote to remote not supported")) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
228 |
|
5186 | 229 |
if dir_cleanup: |
230 |
dir_cleanup.close() |
|
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
231 |
|
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
232 |
if dest_repo.local(): |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
233 |
fp = dest_repo.opener("hgrc", "w", text=True) |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
234 |
fp.write("[paths]\n") |
7044
e51c0f41f271
Escape '%' when writing to hgrc (issue1199)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6338
diff
changeset
|
235 |
# percent needs to be escaped for ConfigParser |
e51c0f41f271
Escape '%' when writing to hgrc (issue1199)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6338
diff
changeset
|
236 |
fp.write("default = %s\n" % abspath.replace('%', '%%')) |
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
237 |
fp.close() |
5185
156f4c8a12aa
clone: do not delete the target if only the update fails
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4635
diff
changeset
|
238 |
|
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
239 |
if update: |
6338
0750f11152fe
clone: print "updating working directory" status message
Adrian Buehlmann <adrian@cadifra.com>
parents:
6315
diff
changeset
|
240 |
dest_repo.ui.status(_("updating working directory\n")) |
6526
cfeeac24fc1e
repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents:
6525
diff
changeset
|
241 |
if update is not True: |
cfeeac24fc1e
repo: add rjoin method
Bryan O'Sullivan <bos@serpentine.com>
parents:
6525
diff
changeset
|
242 |
checkout = update |
7045
f82938c87b92
clone: honor -r even when pulling named branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7044
diff
changeset
|
243 |
for test in (checkout, 'default', 'tip'): |
5248 | 244 |
try: |
7045
f82938c87b92
clone: honor -r even when pulling named branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7044
diff
changeset
|
245 |
uprev = dest_repo.lookup(test) |
f82938c87b92
clone: honor -r even when pulling named branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7044
diff
changeset
|
246 |
break |
5248 | 247 |
except: |
7045
f82938c87b92
clone: honor -r even when pulling named branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7044
diff
changeset
|
248 |
continue |
f82938c87b92
clone: honor -r even when pulling named branches
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7044
diff
changeset
|
249 |
_update(dest_repo, uprev) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
250 |
|
4915
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
251 |
return src_repo, dest_repo |
97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
Matt Mackall <mpm@selenic.com>
parents:
4853
diff
changeset
|
252 |
finally: |
8109
496ae1ea4698
switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7935
diff
changeset
|
253 |
release(src_lock, dest_lock) |
8110
b616f328af9f
switch dircleanup in mercurial.hg.clone from gc based to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
8109
diff
changeset
|
254 |
if dir_cleanup is not None: |
b616f328af9f
switch dircleanup in mercurial.hg.clone from gc based to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
8109
diff
changeset
|
255 |
dir_cleanup.cleanup() |
2775
b550cd82f92a
Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents:
2774
diff
changeset
|
256 |
|
3316
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
257 |
def _showstats(repo, stats): |
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
258 |
stats = ((stats[0], _("updated")), |
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
259 |
(stats[1], _("merged")), |
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
260 |
(stats[2], _("removed")), |
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
261 |
(stats[3], _("unresolved"))) |
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
262 |
note = ", ".join([_("%d files %s") % s for s in stats]) |
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
263 |
repo.ui.status("%s\n" % note) |
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
264 |
|
2808
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
265 |
def update(repo, node): |
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
266 |
"""update the working directory to node, merging linear changes""" |
4917
126f527b3ba3
Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents:
4915
diff
changeset
|
267 |
stats = _merge.update(repo, node, False, False, None) |
3316
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
268 |
_showstats(repo, stats) |
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
269 |
if stats[3]: |
6518 | 270 |
repo.ui.status(_("use 'hg resolve' to retry unresolved file merges\n")) |
5635
0c608a8d9c5f
merge: make return codes more sensible
Matt Mackall <mpm@selenic.com>
parents:
5569
diff
changeset
|
271 |
return stats[3] > 0 |
2775
b550cd82f92a
Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents:
2774
diff
changeset
|
272 |
|
7546
c7f48414f3ad
add a comment about the need of hg._update()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7280
diff
changeset
|
273 |
# 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
|
274 |
_update = update |
c7f48414f3ad
add a comment about the need of hg._update()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7280
diff
changeset
|
275 |
|
4917
126f527b3ba3
Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents:
4915
diff
changeset
|
276 |
def clean(repo, node, show_stats=True): |
2808
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
277 |
"""forcibly switch the working directory to node, clobbering changes""" |
4917
126f527b3ba3
Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents:
4915
diff
changeset
|
278 |
stats = _merge.update(repo, node, False, True, None) |
3316
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
279 |
if show_stats: _showstats(repo, stats) |
5635
0c608a8d9c5f
merge: make return codes more sensible
Matt Mackall <mpm@selenic.com>
parents:
5569
diff
changeset
|
280 |
return stats[3] > 0 |
2775
b550cd82f92a
Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents:
2774
diff
changeset
|
281 |
|
4917
126f527b3ba3
Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents:
4915
diff
changeset
|
282 |
def merge(repo, node, force=None, remind=True): |
2808
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
283 |
"""branch merge with node, resolving changes""" |
4917
126f527b3ba3
Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents:
4915
diff
changeset
|
284 |
stats = _merge.update(repo, node, True, force, False) |
3316
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
285 |
_showstats(repo, stats) |
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
286 |
if stats[3]: |
7821
9fe7e6acf525
merge: better error messages to lead users to hg update --clean to abandon merges.
Augie Fackler <durin42@gmail.com>
parents:
7640
diff
changeset
|
287 |
repo.ui.status(_("use 'hg resolve' to retry unresolved file merges " |
9fe7e6acf525
merge: better error messages to lead users to hg update --clean to abandon merges.
Augie Fackler <durin42@gmail.com>
parents:
7640
diff
changeset
|
288 |
"or 'hg up --clean' to abandon\n")) |
3316
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
289 |
elif remind: |
39fd6e82ea38
merge: pull user messages out to hg.py
Matt Mackall <mpm@selenic.com>
parents:
3195
diff
changeset
|
290 |
repo.ui.status(_("(branch merge, don't forget to commit)\n")) |
5635
0c608a8d9c5f
merge: make return codes more sensible
Matt Mackall <mpm@selenic.com>
parents:
5569
diff
changeset
|
291 |
return stats[3] > 0 |
2808
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
292 |
|
4917
126f527b3ba3
Make repo locks recursive, eliminate all passing of lock/wlock
Matt Mackall <mpm@selenic.com>
parents:
4915
diff
changeset
|
293 |
def revert(repo, node, choose): |
2808
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
294 |
"""revert changes to revision in node without updating dirstate""" |
5635
0c608a8d9c5f
merge: make return codes more sensible
Matt Mackall <mpm@selenic.com>
parents:
5569
diff
changeset
|
295 |
return _merge.update(repo, node, False, True, choose)[3] > 0 |
2778 | 296 |
|
297 |
def verify(repo): |
|
298 |
"""verify the consistency of a repository""" |
|
299 |
return _verify.verify(repo) |