Mercurial > hg
annotate mercurial/hg.py @ 3082:bed7cb835d8d
Fixed python2.3 incompatibility (rsplit) in qpush/qpop with index.
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Tue, 12 Sep 2006 17:27:41 +0200 |
parents | bc3fe3b5b785 |
children | 705e30c0a230 |
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 # |
2859 | 3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
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 |
1089 | 9 from node import * |
10 from repo import * | |
262 | 11 from demandload import * |
2431
d90a9d7c7d4d
replace old-http:// syntax by static-http:// and deprecate the redundant hg://
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1945
diff
changeset
|
12 from i18n import gettext as _ |
1945
dec6d3c13dbf
new type of repo: bundle://path/to/repo+/path/to/bundlename
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1102
diff
changeset
|
13 demandload(globals(), "localrepo bundlerepo httprepo sshrepo statichttprepo") |
2809 | 14 demandload(globals(), "errno lock os shutil util merge@_merge verify@_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): |
2768
b1b1aa6f275c
allow None for path of hg.repository
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2740
diff
changeset
|
17 return (os.path.isfile(path and util.drop_scheme('file', path)) and |
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 |
2472
e6ec81a8feea
make repo scheme table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
20 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
|
21 '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
|
22 '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
|
23 'hg': httprepo, |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
24 '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
|
25 '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
|
26 'old-http': statichttprepo, |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
27 '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
|
28 'static-http': statichttprepo, |
2469
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
29 } |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
30 |
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 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 try: |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2738
diff
changeset
|
39 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
|
40 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
|
41 return thing |
2775
b550cd82f92a
Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents:
2774
diff
changeset
|
42 |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
43 def islocal(repo): |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
44 '''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
|
45 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
|
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 _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
|
48 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
|
49 return False |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
50 return repo.local() |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
51 |
2847
2ff57e3113a4
call reposetup functions of extension modules whenever repo created
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2830
diff
changeset
|
52 repo_setup_hooks = [] |
2ff57e3113a4
call reposetup functions of extension modules whenever repo created
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2830
diff
changeset
|
53 |
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 def repository(ui, path=None, create=False): |
2774 | 55 """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
|
56 repo = _lookup(path).instance(ui, path, create) |
2ff57e3113a4
call reposetup functions of extension modules whenever repo created
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2830
diff
changeset
|
57 for hook in repo_setup_hooks: |
2ff57e3113a4
call reposetup functions of extension modules whenever repo created
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2830
diff
changeset
|
58 hook(ui, repo) |
2ff57e3113a4
call reposetup functions of extension modules whenever repo created
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2830
diff
changeset
|
59 return repo |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
60 |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
61 def defaultdest(source): |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
62 '''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
|
63 return os.path.basename(os.path.normpath(source)) |
2774 | 64 |
2613
479e26afa10f
clone: do not make streaming default. add --stream option instead.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
65 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
|
66 stream=False): |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
67 """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
|
68 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 newly created destination. |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
73 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
74 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
|
75 .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
|
76 pushes. |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
77 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
78 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
|
79 repository will be deleted. |
2600
c4325f0a9b91
clean up trailing white space.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2597
diff
changeset
|
80 |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
81 Arguments: |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
82 |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
83 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
|
84 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
85 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
|
86 name of source repository) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
87 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
88 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
|
89 |
2621
5a5852a417b1
clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2613
diff
changeset
|
90 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
|
91 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
|
92 |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
93 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
|
94 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
95 update: update working directory after clone completes, if |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
96 destination is local repository |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
97 """ |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
98 if isinstance(source, str): |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
99 src_repo = repository(ui, source) |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
100 else: |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
101 src_repo = source |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
102 source = src_repo.url() |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
103 |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
104 if dest is None: |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
105 dest = defaultdest(source) |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
106 |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
107 def localpath(path): |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
108 if path.startswith('file://'): |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
109 return path[7:] |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
110 if path.startswith('file:'): |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
111 return path[5:] |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
112 return path |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
113 |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
114 dest = localpath(dest) |
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
115 source = localpath(source) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
116 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
117 if os.path.exists(dest): |
3072
bc3fe3b5b785
Never apply string formatting to generated errors with util.Abort.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3037
diff
changeset
|
118 raise util.Abort(_("destination '%s' already exists") % dest) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
119 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
120 class DirCleanup(object): |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
121 def __init__(self, dir_): |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
122 self.rmtree = shutil.rmtree |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
123 self.dir_ = dir_ |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
124 def close(self): |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
125 self.dir_ = None |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
126 def __del__(self): |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
127 if self.dir_: |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
128 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
|
129 |
3037
3acb76f0124d
clone: simplifying dest repo creation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2859
diff
changeset
|
130 dest_repo = repository(ui, dest, create=True) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
131 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
132 dest_path = None |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
133 dir_cleanup = None |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
134 if dest_repo.local(): |
2719
532809ba1db5
hg.py: add islocal() and defaultdest() functions, refactor
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2631
diff
changeset
|
135 dest_path = os.path.realpath(dest_repo.root) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
136 dir_cleanup = DirCleanup(dest_path) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
137 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
138 abspath = source |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
139 copy = False |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
140 if src_repo.local() and dest_repo.local(): |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
141 abspath = os.path.abspath(source) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
142 copy = not pull and not rev |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
143 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
144 src_lock, dest_lock = None, None |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
145 if copy: |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
146 try: |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
147 # we use a lock here because if we race with commit, we |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
148 # can end up with extra data in the cloned revlogs that's |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
149 # not pointed to by changesets, thus causing verify to |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
150 # fail |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
151 src_lock = src_repo.lock() |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
152 except lock.LockException: |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
153 copy = False |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
154 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
155 if copy: |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
156 # we lock here to avoid premature writing to the target |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
157 dest_lock = lock.lock(os.path.join(dest_path, ".hg", "lock")) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
158 |
2631
8f564a875b50
codingstyle: use spaces instead of tabs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2621
diff
changeset
|
159 # we need to remove the (empty) data dir in dest so copyfiles |
8f564a875b50
codingstyle: use spaces instead of tabs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2621
diff
changeset
|
160 # can do its work |
8f564a875b50
codingstyle: use spaces instead of tabs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2621
diff
changeset
|
161 os.rmdir(os.path.join(dest_path, ".hg", "data")) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
162 files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
163 for f in files.split(): |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
164 src = os.path.join(source, ".hg", f) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
165 dst = os.path.join(dest_path, ".hg", f) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
166 try: |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
167 util.copyfiles(src, dst) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
168 except OSError, inst: |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
169 if inst.errno != errno.ENOENT: |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
170 raise |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
171 |
2631
8f564a875b50
codingstyle: use spaces instead of tabs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2621
diff
changeset
|
172 # we need to re-init the repo after manually copying the data |
8f564a875b50
codingstyle: use spaces instead of tabs
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2621
diff
changeset
|
173 # into it |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
174 dest_repo = repository(ui, dest) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
175 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
176 else: |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
177 revs = None |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
178 if rev: |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
179 if not src_repo.local(): |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
180 raise util.Abort(_("clone by revision not supported yet " |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
181 "for remote repositories")) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
182 revs = [src_repo.lookup(r) for r in rev] |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
183 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
184 if dest_repo.local(): |
2613
479e26afa10f
clone: do not make streaming default. add --stream option instead.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
185 dest_repo.clone(src_repo, heads=revs, stream=stream) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
186 elif src_repo.local(): |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
187 src_repo.push(dest_repo, revs=revs) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
188 else: |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
189 raise util.Abort(_("clone from remote to remote not supported")) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
190 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
191 if src_lock: |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
192 src_lock.release() |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
193 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
194 if dest_repo.local(): |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
195 fp = dest_repo.opener("hgrc", "w", text=True) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
196 fp.write("[paths]\n") |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
197 fp.write("default = %s\n" % abspath) |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
198 fp.close() |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
199 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
200 if dest_lock: |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
201 dest_lock.release() |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
202 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
203 if update: |
2808
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
204 _merge.update(dest_repo, dest_repo.changelog.tip()) |
2597
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
205 if dir_cleanup: |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
206 dir_cleanup.close() |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
207 |
5ba8be56fa8f
clone: move code into hg module. make doc better.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2595
diff
changeset
|
208 return src_repo, dest_repo |
2775
b550cd82f92a
Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents:
2774
diff
changeset
|
209 |
2808
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
210 def update(repo, node): |
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
211 """update the working directory to node, merging linear changes""" |
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
212 return _merge.update(repo, node) |
2775
b550cd82f92a
Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents:
2774
diff
changeset
|
213 |
2808
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
214 def clean(repo, node, wlock=None, show_stats=True): |
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
215 """forcibly switch the working directory to node, clobbering changes""" |
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
216 return _merge.update(repo, node, force=True, wlock=wlock, |
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
217 show_stats=show_stats) |
2775
b550cd82f92a
Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents:
2774
diff
changeset
|
218 |
2808
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
219 def merge(repo, node, force=None, remind=True, wlock=None): |
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
220 """branch merge with node, resolving changes""" |
2815
4870f795f681
Merge: combine force and forcemerge arguments
Matt Mackall <mpm@selenic.com>
parents:
2812
diff
changeset
|
221 return _merge.update(repo, node, branchmerge=True, force=force, |
2808
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
222 remind=remind, wlock=wlock) |
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
223 |
2812
3aeab7bb5adc
Refactor update locking slightly
Matt Mackall <mpm@selenic.com>
parents:
2811
diff
changeset
|
224 def revert(repo, node, choose, wlock): |
2808
30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
Matt Mackall <mpm@selenic.com>
parents:
2778
diff
changeset
|
225 """revert changes to revision in node without updating dirstate""" |
2811
1ea086bc2086
Merge: combine choose and moddirstate to partial
Matt Mackall <mpm@selenic.com>
parents:
2810
diff
changeset
|
226 return _merge.update(repo, node, force=True, partial=choose, |
2812
3aeab7bb5adc
Refactor update locking slightly
Matt Mackall <mpm@selenic.com>
parents:
2811
diff
changeset
|
227 show_stats=False, wlock=wlock) |
2778 | 228 |
229 def verify(repo): | |
230 """verify the consistency of a repository""" | |
231 return _verify.verify(repo) |