Show More
@@ -1,208 +1,211 | |||||
1 | """ |
|
1 | """ | |
2 | bundlerepo.py - repository class for viewing uncompressed bundles |
|
2 | bundlerepo.py - repository class for viewing uncompressed bundles | |
3 |
|
3 | |||
4 | This provides a read-only repository interface to bundles as if |
|
4 | This provides a read-only repository interface to bundles as if | |
5 | they were part of the actual repository. |
|
5 | they were part of the actual repository. | |
6 |
|
6 | |||
7 | Copyright 2006 Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
|
7 | Copyright 2006 Benoit Boissinot <benoit.boissinot@ens-lyon.org> | |
8 |
|
8 | |||
9 | This software may be used and distributed according to the terms |
|
9 | This software may be used and distributed according to the terms | |
10 | of the GNU General Public License, incorporated herein by reference. |
|
10 | of the GNU General Public License, incorporated herein by reference. | |
11 | """ |
|
11 | """ | |
12 |
|
12 | |||
13 | from node import * |
|
13 | from node import * | |
14 | from i18n import gettext as _ |
|
14 | from i18n import gettext as _ | |
15 | from demandload import demandload |
|
15 | from demandload import demandload | |
16 | demandload(globals(), "util os struct") |
|
16 | demandload(globals(), "util os struct") | |
17 |
|
17 | |||
18 | import localrepo, changelog, manifest, filelog, revlog |
|
18 | import localrepo, changelog, manifest, filelog, revlog | |
19 |
|
19 | |||
20 | def getchunk(source): |
|
20 | def getchunk(source): | |
21 | """get a chunk from a group""" |
|
21 | """get a chunk from a group""" | |
22 | d = source.read(4) |
|
22 | d = source.read(4) | |
23 | if not d: |
|
23 | if not d: | |
24 | return "" |
|
24 | return "" | |
25 | l = struct.unpack(">l", d)[0] |
|
25 | l = struct.unpack(">l", d)[0] | |
26 | if l <= 4: |
|
26 | if l <= 4: | |
27 | return "" |
|
27 | return "" | |
28 | d = source.read(l - 4) |
|
28 | d = source.read(l - 4) | |
29 | if len(d) < l - 4: |
|
29 | if len(d) < l - 4: | |
30 | raise util.Abort(_("premature EOF reading chunk" |
|
30 | raise util.Abort(_("premature EOF reading chunk" | |
31 | " (got %d bytes, expected %d)") |
|
31 | " (got %d bytes, expected %d)") | |
32 | % (len(d), l - 4)) |
|
32 | % (len(d), l - 4)) | |
33 | return d |
|
33 | return d | |
34 |
|
34 | |||
35 | class bundlerevlog(revlog.revlog): |
|
35 | class bundlerevlog(revlog.revlog): | |
36 | def __init__(self, opener, indexfile, datafile, bundlefile, |
|
36 | def __init__(self, opener, indexfile, datafile, bundlefile, | |
37 | linkmapper=None): |
|
37 | linkmapper=None): | |
38 | # How it works: |
|
38 | # How it works: | |
39 | # to retrieve a revision, we need to know the offset of |
|
39 | # to retrieve a revision, we need to know the offset of | |
40 | # the revision in the bundlefile (an opened file). |
|
40 | # the revision in the bundlefile (an opened file). | |
41 | # |
|
41 | # | |
42 | # We store this offset in the index (start), to differentiate a |
|
42 | # We store this offset in the index (start), to differentiate a | |
43 | # rev in the bundle and from a rev in the revlog, we check |
|
43 | # rev in the bundle and from a rev in the revlog, we check | |
44 | # len(index[r]). If the tuple is bigger than 7, it is a bundle |
|
44 | # len(index[r]). If the tuple is bigger than 7, it is a bundle | |
45 | # (it is bigger since we store the node to which the delta is) |
|
45 | # (it is bigger since we store the node to which the delta is) | |
46 | # |
|
46 | # | |
47 | revlog.revlog.__init__(self, opener, indexfile, datafile) |
|
47 | revlog.revlog.__init__(self, opener, indexfile, datafile) | |
48 | self.bundlefile = bundlefile |
|
48 | self.bundlefile = bundlefile | |
49 | def genchunk(): |
|
49 | def genchunk(): | |
50 | while 1: |
|
50 | while 1: | |
51 | pos = bundlefile.tell() |
|
51 | pos = bundlefile.tell() | |
52 | chunk = getchunk(bundlefile) |
|
52 | chunk = getchunk(bundlefile) | |
53 | if not chunk: |
|
53 | if not chunk: | |
54 | break |
|
54 | break | |
55 | yield chunk, pos + 4 # XXX struct.calcsize(">l") == 4 |
|
55 | yield chunk, pos + 4 # XXX struct.calcsize(">l") == 4 | |
56 | n = self.count() |
|
56 | n = self.count() | |
57 | prev = None |
|
57 | prev = None | |
58 | for chunk, start in genchunk(): |
|
58 | for chunk, start in genchunk(): | |
59 | size = len(chunk) |
|
59 | size = len(chunk) | |
60 | if size < 80: |
|
60 | if size < 80: | |
61 | raise util.Abort("invalid changegroup") |
|
61 | raise util.Abort("invalid changegroup") | |
62 | start += 80 |
|
62 | start += 80 | |
63 | size -= 80 |
|
63 | size -= 80 | |
64 | node, p1, p2, cs = struct.unpack("20s20s20s20s", chunk[:80]) |
|
64 | node, p1, p2, cs = struct.unpack("20s20s20s20s", chunk[:80]) | |
65 | if node in self.nodemap: |
|
65 | if node in self.nodemap: | |
66 | prev = node |
|
66 | prev = node | |
67 | continue |
|
67 | continue | |
68 | for p in (p1, p2): |
|
68 | for p in (p1, p2): | |
69 | if not p in self.nodemap: |
|
69 | if not p in self.nodemap: | |
70 | raise RevlogError(_("unknown parent %s") % short(p1)) |
|
70 | raise RevlogError(_("unknown parent %s") % short(p1)) | |
71 | if linkmapper is None: |
|
71 | if linkmapper is None: | |
72 | link = n |
|
72 | link = n | |
73 | else: |
|
73 | else: | |
74 | link = linkmapper(cs) |
|
74 | link = linkmapper(cs) | |
75 |
|
75 | |||
76 | if not prev: |
|
76 | if not prev: | |
77 | prev = p1 |
|
77 | prev = p1 | |
78 | # start, size, base is not used, link, p1, p2, delta ref |
|
78 | # start, size, base is not used, link, p1, p2, delta ref | |
79 | e = (start, size, None, link, p1, p2, node, prev) |
|
79 | e = (start, size, None, link, p1, p2, node, prev) | |
80 | self.index.append(e) |
|
80 | self.index.append(e) | |
81 | self.nodemap[node] = n |
|
81 | self.nodemap[node] = n | |
82 | prev = node |
|
82 | prev = node | |
83 | n += 1 |
|
83 | n += 1 | |
84 |
|
84 | |||
85 | def bundle(self, rev): |
|
85 | def bundle(self, rev): | |
86 | """is rev from the bundle""" |
|
86 | """is rev from the bundle""" | |
87 | if rev < 0: |
|
87 | if rev < 0: | |
88 | return False |
|
88 | return False | |
89 | return len(self.index[rev]) > 7 |
|
89 | return len(self.index[rev]) > 7 | |
90 | def bundlebase(self, rev): return self.index[rev][7] |
|
90 | def bundlebase(self, rev): return self.index[rev][7] | |
91 | def chunk(self, rev): |
|
91 | def chunk(self, rev): | |
92 | # Warning: in case of bundle, the diff is against bundlebase, |
|
92 | # Warning: in case of bundle, the diff is against bundlebase, | |
93 | # not against rev - 1 |
|
93 | # not against rev - 1 | |
94 | # XXX: could use some caching |
|
94 | # XXX: could use some caching | |
95 | if not self.bundle(rev): |
|
95 | if not self.bundle(rev): | |
96 | return revlog.revlog.chunk(self, rev) |
|
96 | return revlog.revlog.chunk(self, rev) | |
97 | self.bundlefile.seek(self.start(rev)) |
|
97 | self.bundlefile.seek(self.start(rev)) | |
98 | return self.bundlefile.read(self.length(rev)) |
|
98 | return self.bundlefile.read(self.length(rev)) | |
99 |
|
99 | |||
100 | def revdiff(self, rev1, rev2): |
|
100 | def revdiff(self, rev1, rev2): | |
101 | """return or calculate a delta between two revisions""" |
|
101 | """return or calculate a delta between two revisions""" | |
102 | if self.bundle(rev1) and self.bundle(rev2): |
|
102 | if self.bundle(rev1) and self.bundle(rev2): | |
103 | # hot path for bundle |
|
103 | # hot path for bundle | |
104 | revb = self.rev(self.bundlebase(rev2)) |
|
104 | revb = self.rev(self.bundlebase(rev2)) | |
105 | if revb == rev1: |
|
105 | if revb == rev1: | |
106 | return self.chunk(rev2) |
|
106 | return self.chunk(rev2) | |
107 | elif not self.bundle(rev1) and not self.bundle(rev2): |
|
107 | elif not self.bundle(rev1) and not self.bundle(rev2): | |
108 | return revlog.revlog.chunk(self, rev1, rev2) |
|
108 | return revlog.revlog.chunk(self, rev1, rev2) | |
109 |
|
109 | |||
110 | return self.diff(self.revision(self.node(rev1)), |
|
110 | return self.diff(self.revision(self.node(rev1)), | |
111 | self.revision(self.node(rev2))) |
|
111 | self.revision(self.node(rev2))) | |
112 |
|
112 | |||
113 | def revision(self, node): |
|
113 | def revision(self, node): | |
114 | """return an uncompressed revision of a given""" |
|
114 | """return an uncompressed revision of a given""" | |
115 | if node == nullid: return "" |
|
115 | if node == nullid: return "" | |
116 |
|
116 | |||
117 | text = None |
|
117 | text = None | |
118 | chain = [] |
|
118 | chain = [] | |
119 | iter_node = node |
|
119 | iter_node = node | |
120 | rev = self.rev(iter_node) |
|
120 | rev = self.rev(iter_node) | |
121 | # reconstruct the revision if it is from a changegroup |
|
121 | # reconstruct the revision if it is from a changegroup | |
122 | while self.bundle(rev): |
|
122 | while self.bundle(rev): | |
123 | if self.cache and self.cache[0] == iter_node: |
|
123 | if self.cache and self.cache[0] == iter_node: | |
124 | text = self.cache[2] |
|
124 | text = self.cache[2] | |
125 | break |
|
125 | break | |
126 | chain.append(rev) |
|
126 | chain.append(rev) | |
127 | iter_node = self.bundlebase(rev) |
|
127 | iter_node = self.bundlebase(rev) | |
128 | rev = self.rev(iter_node) |
|
128 | rev = self.rev(iter_node) | |
129 | if text is None: |
|
129 | if text is None: | |
130 | text = revlog.revlog.revision(self, iter_node) |
|
130 | text = revlog.revlog.revision(self, iter_node) | |
131 |
|
131 | |||
132 | while chain: |
|
132 | while chain: | |
133 | delta = self.chunk(chain.pop()) |
|
133 | delta = self.chunk(chain.pop()) | |
134 | text = self.patches(text, [delta]) |
|
134 | text = self.patches(text, [delta]) | |
135 |
|
135 | |||
136 | p1, p2 = self.parents(node) |
|
136 | p1, p2 = self.parents(node) | |
137 | if node != revlog.hash(text, p1, p2): |
|
137 | if node != revlog.hash(text, p1, p2): | |
138 | raise RevlogError(_("integrity check failed on %s:%d") |
|
138 | raise RevlogError(_("integrity check failed on %s:%d") | |
139 | % (self.datafile, self.rev(node))) |
|
139 | % (self.datafile, self.rev(node))) | |
140 |
|
140 | |||
141 | self.cache = (node, rev, text) |
|
141 | self.cache = (node, rev, text) | |
142 | return text |
|
142 | return text | |
143 |
|
143 | |||
144 | def addrevision(self, text, transaction, link, p1=None, p2=None, d=None): |
|
144 | def addrevision(self, text, transaction, link, p1=None, p2=None, d=None): | |
145 | raise NotImplementedError |
|
145 | raise NotImplementedError | |
146 | def addgroup(self, revs, linkmapper, transaction, unique=0): |
|
146 | def addgroup(self, revs, linkmapper, transaction, unique=0): | |
147 | raise NotImplementedError |
|
147 | raise NotImplementedError | |
148 | def strip(self, rev, minlink): |
|
148 | def strip(self, rev, minlink): | |
149 | raise NotImplementedError |
|
149 | raise NotImplementedError | |
150 | def checksize(self): |
|
150 | def checksize(self): | |
151 | raise NotImplementedError |
|
151 | raise NotImplementedError | |
152 |
|
152 | |||
153 | class bundlechangelog(bundlerevlog, changelog.changelog): |
|
153 | class bundlechangelog(bundlerevlog, changelog.changelog): | |
154 | def __init__(self, opener, bundlefile): |
|
154 | def __init__(self, opener, bundlefile): | |
155 | changelog.changelog.__init__(self, opener) |
|
155 | changelog.changelog.__init__(self, opener) | |
156 | bundlerevlog.__init__(self, opener, "00changelog.i", "00changelog.d", |
|
156 | bundlerevlog.__init__(self, opener, "00changelog.i", "00changelog.d", | |
157 | bundlefile) |
|
157 | bundlefile) | |
158 |
|
158 | |||
159 | class bundlemanifest(bundlerevlog, manifest.manifest): |
|
159 | class bundlemanifest(bundlerevlog, manifest.manifest): | |
160 | def __init__(self, opener, bundlefile, linkmapper): |
|
160 | def __init__(self, opener, bundlefile, linkmapper): | |
161 | manifest.manifest.__init__(self, opener) |
|
161 | manifest.manifest.__init__(self, opener) | |
162 | bundlerevlog.__init__(self, opener, self.indexfile, self.datafile, |
|
162 | bundlerevlog.__init__(self, opener, self.indexfile, self.datafile, | |
163 | bundlefile, linkmapper) |
|
163 | bundlefile, linkmapper) | |
164 |
|
164 | |||
165 | class bundlefilelog(bundlerevlog, filelog.filelog): |
|
165 | class bundlefilelog(bundlerevlog, filelog.filelog): | |
166 | def __init__(self, opener, path, bundlefile, linkmapper): |
|
166 | def __init__(self, opener, path, bundlefile, linkmapper): | |
167 | filelog.filelog.__init__(self, opener, path) |
|
167 | filelog.filelog.__init__(self, opener, path) | |
168 | bundlerevlog.__init__(self, opener, self.indexfile, self.datafile, |
|
168 | bundlerevlog.__init__(self, opener, self.indexfile, self.datafile, | |
169 | bundlefile, linkmapper) |
|
169 | bundlefile, linkmapper) | |
170 |
|
170 | |||
171 | class bundlerepository(localrepo.localrepository): |
|
171 | class bundlerepository(localrepo.localrepository): | |
172 | def __init__(self, ui, path, bundlename): |
|
172 | def __init__(self, ui, path, bundlename): | |
173 | localrepo.localrepository.__init__(self, ui, path) |
|
173 | localrepo.localrepository.__init__(self, ui, path) | |
174 | f = open(bundlename, "rb") |
|
174 | f = open(bundlename, "rb") | |
175 | s = os.fstat(f.fileno()) |
|
175 | s = os.fstat(f.fileno()) | |
176 | self.bundlefile = f |
|
176 | self.bundlefile = f | |
177 | header = self.bundlefile.read(4) |
|
177 | header = self.bundlefile.read(4) | |
178 | if header == "HG10": |
|
178 | if header == "HG10": | |
179 | raise util.Abort(_("%s: compressed bundle not supported") |
|
179 | raise util.Abort(_("%s: compressed bundle not supported") | |
180 | % bundlename) |
|
180 | % bundlename) | |
181 | elif header != "HG11": |
|
181 | elif header != "HG11": | |
182 | raise util.Abort(_("%s: not a Mercurial bundle file") % bundlename) |
|
182 | raise util.Abort(_("%s: not a Mercurial bundle file") % bundlename) | |
183 | self.changelog = bundlechangelog(self.opener, self.bundlefile) |
|
183 | self.changelog = bundlechangelog(self.opener, self.bundlefile) | |
184 | self.manifest = bundlemanifest(self.opener, self.bundlefile, |
|
184 | self.manifest = bundlemanifest(self.opener, self.bundlefile, | |
185 | self.changelog.rev) |
|
185 | self.changelog.rev) | |
186 | # dict with the mapping 'filename' -> position in the bundle |
|
186 | # dict with the mapping 'filename' -> position in the bundle | |
187 | self.bundlefilespos = {} |
|
187 | self.bundlefilespos = {} | |
188 | while 1: |
|
188 | while 1: | |
189 | f = getchunk(self.bundlefile) |
|
189 | f = getchunk(self.bundlefile) | |
190 | if not f: |
|
190 | if not f: | |
191 | break |
|
191 | break | |
192 | self.bundlefilespos[f] = self.bundlefile.tell() |
|
192 | self.bundlefilespos[f] = self.bundlefile.tell() | |
193 | while getchunk(self.bundlefile): |
|
193 | while getchunk(self.bundlefile): | |
194 | pass |
|
194 | pass | |
195 |
|
195 | |||
196 | def dev(self): |
|
196 | def dev(self): | |
197 | return -1 |
|
197 | return -1 | |
198 |
|
198 | |||
199 | def file(self, f): |
|
199 | def file(self, f): | |
200 | if f[0] == '/': |
|
200 | if f[0] == '/': | |
201 | f = f[1:] |
|
201 | f = f[1:] | |
202 | if f in self.bundlefilespos: |
|
202 | if f in self.bundlefilespos: | |
203 | self.bundlefile.seek(self.bundlefilespos[f]) |
|
203 | self.bundlefile.seek(self.bundlefilespos[f]) | |
204 | return bundlefilelog(self.opener, f, self.bundlefile, |
|
204 | return bundlefilelog(self.opener, f, self.bundlefile, | |
205 | self.changelog.rev) |
|
205 | self.changelog.rev) | |
206 | else: |
|
206 | else: | |
207 | return filelog.filelog(self.opener, f) |
|
207 | return filelog.filelog(self.opener, f) | |
208 |
|
208 | |||
|
209 | def close(self): | |||
|
210 | """Close assigned bundle file immediately.""" | |||
|
211 | self.bundlefile.close() |
@@ -1,3267 +1,3267 | |||||
1 | # commands.py - command processing for mercurial |
|
1 | # commands.py - command processing for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms |
|
5 | # This software may be used and distributed according to the terms | |
6 | # of the GNU General Public License, incorporated herein by reference. |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
7 |
|
7 | |||
8 | from demandload import demandload |
|
8 | from demandload import demandload | |
9 | from node import * |
|
9 | from node import * | |
10 | from i18n import gettext as _ |
|
10 | from i18n import gettext as _ | |
11 | demandload(globals(), "os re sys signal shutil imp urllib pdb") |
|
11 | demandload(globals(), "os re sys signal shutil imp urllib pdb") | |
12 | demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo") |
|
12 | demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo") | |
13 | demandload(globals(), "fnmatch hgweb mdiff random signal tempfile time") |
|
13 | demandload(globals(), "fnmatch hgweb mdiff random signal tempfile time") | |
14 | demandload(globals(), "traceback errno socket version struct atexit sets bz2") |
|
14 | demandload(globals(), "traceback errno socket version struct atexit sets bz2") | |
15 |
|
15 | |||
16 | class UnknownCommand(Exception): |
|
16 | class UnknownCommand(Exception): | |
17 | """Exception raised if command is not in the command table.""" |
|
17 | """Exception raised if command is not in the command table.""" | |
18 | class AmbiguousCommand(Exception): |
|
18 | class AmbiguousCommand(Exception): | |
19 | """Exception raised if command shortcut matches more than one command.""" |
|
19 | """Exception raised if command shortcut matches more than one command.""" | |
20 |
|
20 | |||
21 | def filterfiles(filters, files): |
|
21 | def filterfiles(filters, files): | |
22 | l = [x for x in files if x in filters] |
|
22 | l = [x for x in files if x in filters] | |
23 |
|
23 | |||
24 | for t in filters: |
|
24 | for t in filters: | |
25 | if t and t[-1] != "/": |
|
25 | if t and t[-1] != "/": | |
26 | t += "/" |
|
26 | t += "/" | |
27 | l += [x for x in files if x.startswith(t)] |
|
27 | l += [x for x in files if x.startswith(t)] | |
28 | return l |
|
28 | return l | |
29 |
|
29 | |||
30 | def relpath(repo, args): |
|
30 | def relpath(repo, args): | |
31 | cwd = repo.getcwd() |
|
31 | cwd = repo.getcwd() | |
32 | if cwd: |
|
32 | if cwd: | |
33 | return [util.normpath(os.path.join(cwd, x)) for x in args] |
|
33 | return [util.normpath(os.path.join(cwd, x)) for x in args] | |
34 | return args |
|
34 | return args | |
35 |
|
35 | |||
36 | def matchpats(repo, pats=[], opts={}, head=''): |
|
36 | def matchpats(repo, pats=[], opts={}, head=''): | |
37 | cwd = repo.getcwd() |
|
37 | cwd = repo.getcwd() | |
38 | if not pats and cwd: |
|
38 | if not pats and cwd: | |
39 | opts['include'] = [os.path.join(cwd, i) for i in opts['include']] |
|
39 | opts['include'] = [os.path.join(cwd, i) for i in opts['include']] | |
40 | opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] |
|
40 | opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] | |
41 | cwd = '' |
|
41 | cwd = '' | |
42 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), |
|
42 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), | |
43 | opts.get('exclude'), head) |
|
43 | opts.get('exclude'), head) | |
44 |
|
44 | |||
45 | def makewalk(repo, pats, opts, node=None, head=''): |
|
45 | def makewalk(repo, pats, opts, node=None, head=''): | |
46 | files, matchfn, anypats = matchpats(repo, pats, opts, head) |
|
46 | files, matchfn, anypats = matchpats(repo, pats, opts, head) | |
47 | exact = dict(zip(files, files)) |
|
47 | exact = dict(zip(files, files)) | |
48 | def walk(): |
|
48 | def walk(): | |
49 | for src, fn in repo.walk(node=node, files=files, match=matchfn): |
|
49 | for src, fn in repo.walk(node=node, files=files, match=matchfn): | |
50 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact |
|
50 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact | |
51 | return files, matchfn, walk() |
|
51 | return files, matchfn, walk() | |
52 |
|
52 | |||
53 | def walk(repo, pats, opts, node=None, head=''): |
|
53 | def walk(repo, pats, opts, node=None, head=''): | |
54 | files, matchfn, results = makewalk(repo, pats, opts, node, head) |
|
54 | files, matchfn, results = makewalk(repo, pats, opts, node, head) | |
55 | for r in results: |
|
55 | for r in results: | |
56 | yield r |
|
56 | yield r | |
57 |
|
57 | |||
58 | def walkchangerevs(ui, repo, pats, opts): |
|
58 | def walkchangerevs(ui, repo, pats, opts): | |
59 | '''Iterate over files and the revs they changed in. |
|
59 | '''Iterate over files and the revs they changed in. | |
60 |
|
60 | |||
61 | Callers most commonly need to iterate backwards over the history |
|
61 | Callers most commonly need to iterate backwards over the history | |
62 | it is interested in. Doing so has awful (quadratic-looking) |
|
62 | it is interested in. Doing so has awful (quadratic-looking) | |
63 | performance, so we use iterators in a "windowed" way. |
|
63 | performance, so we use iterators in a "windowed" way. | |
64 |
|
64 | |||
65 | We walk a window of revisions in the desired order. Within the |
|
65 | We walk a window of revisions in the desired order. Within the | |
66 | window, we first walk forwards to gather data, then in the desired |
|
66 | window, we first walk forwards to gather data, then in the desired | |
67 | order (usually backwards) to display it. |
|
67 | order (usually backwards) to display it. | |
68 |
|
68 | |||
69 | This function returns an (iterator, getchange, matchfn) tuple. The |
|
69 | This function returns an (iterator, getchange, matchfn) tuple. The | |
70 | getchange function returns the changelog entry for a numeric |
|
70 | getchange function returns the changelog entry for a numeric | |
71 | revision. The iterator yields 3-tuples. They will be of one of |
|
71 | revision. The iterator yields 3-tuples. They will be of one of | |
72 | the following forms: |
|
72 | the following forms: | |
73 |
|
73 | |||
74 | "window", incrementing, lastrev: stepping through a window, |
|
74 | "window", incrementing, lastrev: stepping through a window, | |
75 | positive if walking forwards through revs, last rev in the |
|
75 | positive if walking forwards through revs, last rev in the | |
76 | sequence iterated over - use to reset state for the current window |
|
76 | sequence iterated over - use to reset state for the current window | |
77 |
|
77 | |||
78 | "add", rev, fns: out-of-order traversal of the given file names |
|
78 | "add", rev, fns: out-of-order traversal of the given file names | |
79 | fns, which changed during revision rev - use to gather data for |
|
79 | fns, which changed during revision rev - use to gather data for | |
80 | possible display |
|
80 | possible display | |
81 |
|
81 | |||
82 | "iter", rev, None: in-order traversal of the revs earlier iterated |
|
82 | "iter", rev, None: in-order traversal of the revs earlier iterated | |
83 | over with "add" - use to display data''' |
|
83 | over with "add" - use to display data''' | |
84 |
|
84 | |||
85 | def increasing_windows(start, end, windowsize=8, sizelimit=512): |
|
85 | def increasing_windows(start, end, windowsize=8, sizelimit=512): | |
86 | if start < end: |
|
86 | if start < end: | |
87 | while start < end: |
|
87 | while start < end: | |
88 | yield start, min(windowsize, end-start) |
|
88 | yield start, min(windowsize, end-start) | |
89 | start += windowsize |
|
89 | start += windowsize | |
90 | if windowsize < sizelimit: |
|
90 | if windowsize < sizelimit: | |
91 | windowsize *= 2 |
|
91 | windowsize *= 2 | |
92 | else: |
|
92 | else: | |
93 | while start > end: |
|
93 | while start > end: | |
94 | yield start, min(windowsize, start-end-1) |
|
94 | yield start, min(windowsize, start-end-1) | |
95 | start -= windowsize |
|
95 | start -= windowsize | |
96 | if windowsize < sizelimit: |
|
96 | if windowsize < sizelimit: | |
97 | windowsize *= 2 |
|
97 | windowsize *= 2 | |
98 |
|
98 | |||
99 |
|
99 | |||
100 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
100 | files, matchfn, anypats = matchpats(repo, pats, opts) | |
101 |
|
101 | |||
102 | if repo.changelog.count() == 0: |
|
102 | if repo.changelog.count() == 0: | |
103 | return [], False, matchfn |
|
103 | return [], False, matchfn | |
104 |
|
104 | |||
105 | revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) |
|
105 | revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) | |
106 | wanted = {} |
|
106 | wanted = {} | |
107 | slowpath = anypats |
|
107 | slowpath = anypats | |
108 | fncache = {} |
|
108 | fncache = {} | |
109 |
|
109 | |||
110 | chcache = {} |
|
110 | chcache = {} | |
111 | def getchange(rev): |
|
111 | def getchange(rev): | |
112 | ch = chcache.get(rev) |
|
112 | ch = chcache.get(rev) | |
113 | if ch is None: |
|
113 | if ch is None: | |
114 | chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) |
|
114 | chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) | |
115 | return ch |
|
115 | return ch | |
116 |
|
116 | |||
117 | if not slowpath and not files: |
|
117 | if not slowpath and not files: | |
118 | # No files, no patterns. Display all revs. |
|
118 | # No files, no patterns. Display all revs. | |
119 | wanted = dict(zip(revs, revs)) |
|
119 | wanted = dict(zip(revs, revs)) | |
120 | if not slowpath: |
|
120 | if not slowpath: | |
121 | # Only files, no patterns. Check the history of each file. |
|
121 | # Only files, no patterns. Check the history of each file. | |
122 | def filerevgen(filelog): |
|
122 | def filerevgen(filelog): | |
123 | for i, window in increasing_windows(filelog.count()-1, -1): |
|
123 | for i, window in increasing_windows(filelog.count()-1, -1): | |
124 | revs = [] |
|
124 | revs = [] | |
125 | for j in xrange(i - window, i + 1): |
|
125 | for j in xrange(i - window, i + 1): | |
126 | revs.append(filelog.linkrev(filelog.node(j))) |
|
126 | revs.append(filelog.linkrev(filelog.node(j))) | |
127 | revs.reverse() |
|
127 | revs.reverse() | |
128 | for rev in revs: |
|
128 | for rev in revs: | |
129 | yield rev |
|
129 | yield rev | |
130 |
|
130 | |||
131 | minrev, maxrev = min(revs), max(revs) |
|
131 | minrev, maxrev = min(revs), max(revs) | |
132 | for file_ in files: |
|
132 | for file_ in files: | |
133 | filelog = repo.file(file_) |
|
133 | filelog = repo.file(file_) | |
134 | # A zero count may be a directory or deleted file, so |
|
134 | # A zero count may be a directory or deleted file, so | |
135 | # try to find matching entries on the slow path. |
|
135 | # try to find matching entries on the slow path. | |
136 | if filelog.count() == 0: |
|
136 | if filelog.count() == 0: | |
137 | slowpath = True |
|
137 | slowpath = True | |
138 | break |
|
138 | break | |
139 | for rev in filerevgen(filelog): |
|
139 | for rev in filerevgen(filelog): | |
140 | if rev <= maxrev: |
|
140 | if rev <= maxrev: | |
141 | if rev < minrev: |
|
141 | if rev < minrev: | |
142 | break |
|
142 | break | |
143 | fncache.setdefault(rev, []) |
|
143 | fncache.setdefault(rev, []) | |
144 | fncache[rev].append(file_) |
|
144 | fncache[rev].append(file_) | |
145 | wanted[rev] = 1 |
|
145 | wanted[rev] = 1 | |
146 | if slowpath: |
|
146 | if slowpath: | |
147 | # The slow path checks files modified in every changeset. |
|
147 | # The slow path checks files modified in every changeset. | |
148 | def changerevgen(): |
|
148 | def changerevgen(): | |
149 | for i, window in increasing_windows(repo.changelog.count()-1, -1): |
|
149 | for i, window in increasing_windows(repo.changelog.count()-1, -1): | |
150 | for j in xrange(i - window, i + 1): |
|
150 | for j in xrange(i - window, i + 1): | |
151 | yield j, getchange(j)[3] |
|
151 | yield j, getchange(j)[3] | |
152 |
|
152 | |||
153 | for rev, changefiles in changerevgen(): |
|
153 | for rev, changefiles in changerevgen(): | |
154 | matches = filter(matchfn, changefiles) |
|
154 | matches = filter(matchfn, changefiles) | |
155 | if matches: |
|
155 | if matches: | |
156 | fncache[rev] = matches |
|
156 | fncache[rev] = matches | |
157 | wanted[rev] = 1 |
|
157 | wanted[rev] = 1 | |
158 |
|
158 | |||
159 | def iterate(): |
|
159 | def iterate(): | |
160 | for i, window in increasing_windows(0, len(revs)): |
|
160 | for i, window in increasing_windows(0, len(revs)): | |
161 | yield 'window', revs[0] < revs[-1], revs[-1] |
|
161 | yield 'window', revs[0] < revs[-1], revs[-1] | |
162 | nrevs = [rev for rev in revs[i:i+window] |
|
162 | nrevs = [rev for rev in revs[i:i+window] | |
163 | if rev in wanted] |
|
163 | if rev in wanted] | |
164 | srevs = list(nrevs) |
|
164 | srevs = list(nrevs) | |
165 | srevs.sort() |
|
165 | srevs.sort() | |
166 | for rev in srevs: |
|
166 | for rev in srevs: | |
167 | fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) |
|
167 | fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) | |
168 | yield 'add', rev, fns |
|
168 | yield 'add', rev, fns | |
169 | for rev in nrevs: |
|
169 | for rev in nrevs: | |
170 | yield 'iter', rev, None |
|
170 | yield 'iter', rev, None | |
171 | return iterate(), getchange, matchfn |
|
171 | return iterate(), getchange, matchfn | |
172 |
|
172 | |||
173 | revrangesep = ':' |
|
173 | revrangesep = ':' | |
174 |
|
174 | |||
175 | def revrange(ui, repo, revs, revlog=None): |
|
175 | def revrange(ui, repo, revs, revlog=None): | |
176 | """Yield revision as strings from a list of revision specifications.""" |
|
176 | """Yield revision as strings from a list of revision specifications.""" | |
177 | if revlog is None: |
|
177 | if revlog is None: | |
178 | revlog = repo.changelog |
|
178 | revlog = repo.changelog | |
179 | revcount = revlog.count() |
|
179 | revcount = revlog.count() | |
180 | def fix(val, defval): |
|
180 | def fix(val, defval): | |
181 | if not val: |
|
181 | if not val: | |
182 | return defval |
|
182 | return defval | |
183 | try: |
|
183 | try: | |
184 | num = int(val) |
|
184 | num = int(val) | |
185 | if str(num) != val: |
|
185 | if str(num) != val: | |
186 | raise ValueError |
|
186 | raise ValueError | |
187 | if num < 0: |
|
187 | if num < 0: | |
188 | num += revcount |
|
188 | num += revcount | |
189 | if num < 0: |
|
189 | if num < 0: | |
190 | num = 0 |
|
190 | num = 0 | |
191 | elif num >= revcount: |
|
191 | elif num >= revcount: | |
192 | raise ValueError |
|
192 | raise ValueError | |
193 | except ValueError: |
|
193 | except ValueError: | |
194 | try: |
|
194 | try: | |
195 | num = repo.changelog.rev(repo.lookup(val)) |
|
195 | num = repo.changelog.rev(repo.lookup(val)) | |
196 | except KeyError: |
|
196 | except KeyError: | |
197 | try: |
|
197 | try: | |
198 | num = revlog.rev(revlog.lookup(val)) |
|
198 | num = revlog.rev(revlog.lookup(val)) | |
199 | except KeyError: |
|
199 | except KeyError: | |
200 | raise util.Abort(_('invalid revision identifier %s'), val) |
|
200 | raise util.Abort(_('invalid revision identifier %s'), val) | |
201 | return num |
|
201 | return num | |
202 | seen = {} |
|
202 | seen = {} | |
203 | for spec in revs: |
|
203 | for spec in revs: | |
204 | if spec.find(revrangesep) >= 0: |
|
204 | if spec.find(revrangesep) >= 0: | |
205 | start, end = spec.split(revrangesep, 1) |
|
205 | start, end = spec.split(revrangesep, 1) | |
206 | start = fix(start, 0) |
|
206 | start = fix(start, 0) | |
207 | end = fix(end, revcount - 1) |
|
207 | end = fix(end, revcount - 1) | |
208 | step = start > end and -1 or 1 |
|
208 | step = start > end and -1 or 1 | |
209 | for rev in xrange(start, end+step, step): |
|
209 | for rev in xrange(start, end+step, step): | |
210 | if rev in seen: |
|
210 | if rev in seen: | |
211 | continue |
|
211 | continue | |
212 | seen[rev] = 1 |
|
212 | seen[rev] = 1 | |
213 | yield str(rev) |
|
213 | yield str(rev) | |
214 | else: |
|
214 | else: | |
215 | rev = fix(spec, None) |
|
215 | rev = fix(spec, None) | |
216 | if rev in seen: |
|
216 | if rev in seen: | |
217 | continue |
|
217 | continue | |
218 | seen[rev] = 1 |
|
218 | seen[rev] = 1 | |
219 | yield str(rev) |
|
219 | yield str(rev) | |
220 |
|
220 | |||
221 | def make_filename(repo, r, pat, node=None, |
|
221 | def make_filename(repo, r, pat, node=None, | |
222 | total=None, seqno=None, revwidth=None, pathname=None): |
|
222 | total=None, seqno=None, revwidth=None, pathname=None): | |
223 | node_expander = { |
|
223 | node_expander = { | |
224 | 'H': lambda: hex(node), |
|
224 | 'H': lambda: hex(node), | |
225 | 'R': lambda: str(r.rev(node)), |
|
225 | 'R': lambda: str(r.rev(node)), | |
226 | 'h': lambda: short(node), |
|
226 | 'h': lambda: short(node), | |
227 | } |
|
227 | } | |
228 | expander = { |
|
228 | expander = { | |
229 | '%': lambda: '%', |
|
229 | '%': lambda: '%', | |
230 | 'b': lambda: os.path.basename(repo.root), |
|
230 | 'b': lambda: os.path.basename(repo.root), | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | try: |
|
233 | try: | |
234 | if node: |
|
234 | if node: | |
235 | expander.update(node_expander) |
|
235 | expander.update(node_expander) | |
236 | if node and revwidth is not None: |
|
236 | if node and revwidth is not None: | |
237 | expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) |
|
237 | expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) | |
238 | if total is not None: |
|
238 | if total is not None: | |
239 | expander['N'] = lambda: str(total) |
|
239 | expander['N'] = lambda: str(total) | |
240 | if seqno is not None: |
|
240 | if seqno is not None: | |
241 | expander['n'] = lambda: str(seqno) |
|
241 | expander['n'] = lambda: str(seqno) | |
242 | if total is not None and seqno is not None: |
|
242 | if total is not None and seqno is not None: | |
243 | expander['n'] = lambda:str(seqno).zfill(len(str(total))) |
|
243 | expander['n'] = lambda:str(seqno).zfill(len(str(total))) | |
244 | if pathname is not None: |
|
244 | if pathname is not None: | |
245 | expander['s'] = lambda: os.path.basename(pathname) |
|
245 | expander['s'] = lambda: os.path.basename(pathname) | |
246 | expander['d'] = lambda: os.path.dirname(pathname) or '.' |
|
246 | expander['d'] = lambda: os.path.dirname(pathname) or '.' | |
247 | expander['p'] = lambda: pathname |
|
247 | expander['p'] = lambda: pathname | |
248 |
|
248 | |||
249 | newname = [] |
|
249 | newname = [] | |
250 | patlen = len(pat) |
|
250 | patlen = len(pat) | |
251 | i = 0 |
|
251 | i = 0 | |
252 | while i < patlen: |
|
252 | while i < patlen: | |
253 | c = pat[i] |
|
253 | c = pat[i] | |
254 | if c == '%': |
|
254 | if c == '%': | |
255 | i += 1 |
|
255 | i += 1 | |
256 | c = pat[i] |
|
256 | c = pat[i] | |
257 | c = expander[c]() |
|
257 | c = expander[c]() | |
258 | newname.append(c) |
|
258 | newname.append(c) | |
259 | i += 1 |
|
259 | i += 1 | |
260 | return ''.join(newname) |
|
260 | return ''.join(newname) | |
261 | except KeyError, inst: |
|
261 | except KeyError, inst: | |
262 | raise util.Abort(_("invalid format spec '%%%s' in output file name"), |
|
262 | raise util.Abort(_("invalid format spec '%%%s' in output file name"), | |
263 | inst.args[0]) |
|
263 | inst.args[0]) | |
264 |
|
264 | |||
265 | def make_file(repo, r, pat, node=None, |
|
265 | def make_file(repo, r, pat, node=None, | |
266 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): |
|
266 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): | |
267 | if not pat or pat == '-': |
|
267 | if not pat or pat == '-': | |
268 | return 'w' in mode and sys.stdout or sys.stdin |
|
268 | return 'w' in mode and sys.stdout or sys.stdin | |
269 | if hasattr(pat, 'write') and 'w' in mode: |
|
269 | if hasattr(pat, 'write') and 'w' in mode: | |
270 | return pat |
|
270 | return pat | |
271 | if hasattr(pat, 'read') and 'r' in mode: |
|
271 | if hasattr(pat, 'read') and 'r' in mode: | |
272 | return pat |
|
272 | return pat | |
273 | return open(make_filename(repo, r, pat, node, total, seqno, revwidth, |
|
273 | return open(make_filename(repo, r, pat, node, total, seqno, revwidth, | |
274 | pathname), |
|
274 | pathname), | |
275 | mode) |
|
275 | mode) | |
276 |
|
276 | |||
277 | def write_bundle(cg, filename, compress=True, fh=None): |
|
277 | def write_bundle(cg, filename, compress=True, fh=None): | |
278 | if fh is None: |
|
278 | if fh is None: | |
279 | fh = open(filename, "wb") |
|
279 | fh = open(filename, "wb") | |
280 |
|
280 | |||
281 | class nocompress(object): |
|
281 | class nocompress(object): | |
282 | def compress(self, x): |
|
282 | def compress(self, x): | |
283 | return x |
|
283 | return x | |
284 | def flush(self): |
|
284 | def flush(self): | |
285 | return "" |
|
285 | return "" | |
286 | try: |
|
286 | try: | |
287 | if compress: |
|
287 | if compress: | |
288 | fh.write("HG10") |
|
288 | fh.write("HG10") | |
289 | z = bz2.BZ2Compressor(9) |
|
289 | z = bz2.BZ2Compressor(9) | |
290 | else: |
|
290 | else: | |
291 | fh.write("HG11") |
|
291 | fh.write("HG11") | |
292 | z = nocompress() |
|
292 | z = nocompress() | |
293 | while 1: |
|
293 | while 1: | |
294 | chunk = cg.read(4096) |
|
294 | chunk = cg.read(4096) | |
295 | if not chunk: |
|
295 | if not chunk: | |
296 | break |
|
296 | break | |
297 | fh.write(z.compress(chunk)) |
|
297 | fh.write(z.compress(chunk)) | |
298 | fh.write(z.flush()) |
|
298 | fh.write(z.flush()) | |
299 | except: |
|
299 | except: | |
300 | fh.close() |
|
300 | fh.close() | |
301 | os.unlink(filename) |
|
301 | os.unlink(filename) | |
302 | raise |
|
302 | raise | |
303 | fh.close() |
|
303 | fh.close() | |
304 |
|
304 | |||
305 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, |
|
305 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, | |
306 | changes=None, text=False, opts={}): |
|
306 | changes=None, text=False, opts={}): | |
307 | if not node1: |
|
307 | if not node1: | |
308 | node1 = repo.dirstate.parents()[0] |
|
308 | node1 = repo.dirstate.parents()[0] | |
309 | # reading the data for node1 early allows it to play nicely |
|
309 | # reading the data for node1 early allows it to play nicely | |
310 | # with repo.changes and the revlog cache. |
|
310 | # with repo.changes and the revlog cache. | |
311 | change = repo.changelog.read(node1) |
|
311 | change = repo.changelog.read(node1) | |
312 | mmap = repo.manifest.read(change[0]) |
|
312 | mmap = repo.manifest.read(change[0]) | |
313 | date1 = util.datestr(change[2]) |
|
313 | date1 = util.datestr(change[2]) | |
314 |
|
314 | |||
315 | if not changes: |
|
315 | if not changes: | |
316 | changes = repo.changes(node1, node2, files, match=match) |
|
316 | changes = repo.changes(node1, node2, files, match=match) | |
317 | modified, added, removed, deleted, unknown = changes |
|
317 | modified, added, removed, deleted, unknown = changes | |
318 | if files: |
|
318 | if files: | |
319 | modified, added, removed = map(lambda x: filterfiles(files, x), |
|
319 | modified, added, removed = map(lambda x: filterfiles(files, x), | |
320 | (modified, added, removed)) |
|
320 | (modified, added, removed)) | |
321 |
|
321 | |||
322 | if not modified and not added and not removed: |
|
322 | if not modified and not added and not removed: | |
323 | return |
|
323 | return | |
324 |
|
324 | |||
325 | if node2: |
|
325 | if node2: | |
326 | change = repo.changelog.read(node2) |
|
326 | change = repo.changelog.read(node2) | |
327 | mmap2 = repo.manifest.read(change[0]) |
|
327 | mmap2 = repo.manifest.read(change[0]) | |
328 | date2 = util.datestr(change[2]) |
|
328 | date2 = util.datestr(change[2]) | |
329 | def read(f): |
|
329 | def read(f): | |
330 | return repo.file(f).read(mmap2[f]) |
|
330 | return repo.file(f).read(mmap2[f]) | |
331 | else: |
|
331 | else: | |
332 | date2 = util.datestr() |
|
332 | date2 = util.datestr() | |
333 | def read(f): |
|
333 | def read(f): | |
334 | return repo.wread(f) |
|
334 | return repo.wread(f) | |
335 |
|
335 | |||
336 | if ui.quiet: |
|
336 | if ui.quiet: | |
337 | r = None |
|
337 | r = None | |
338 | else: |
|
338 | else: | |
339 | hexfunc = ui.verbose and hex or short |
|
339 | hexfunc = ui.verbose and hex or short | |
340 | r = [hexfunc(node) for node in [node1, node2] if node] |
|
340 | r = [hexfunc(node) for node in [node1, node2] if node] | |
341 |
|
341 | |||
342 | diffopts = ui.diffopts() |
|
342 | diffopts = ui.diffopts() | |
343 | showfunc = opts.get('show_function') or diffopts['showfunc'] |
|
343 | showfunc = opts.get('show_function') or diffopts['showfunc'] | |
344 | ignorews = opts.get('ignore_all_space') or diffopts['ignorews'] |
|
344 | ignorews = opts.get('ignore_all_space') or diffopts['ignorews'] | |
345 | for f in modified: |
|
345 | for f in modified: | |
346 | to = None |
|
346 | to = None | |
347 | if f in mmap: |
|
347 | if f in mmap: | |
348 | to = repo.file(f).read(mmap[f]) |
|
348 | to = repo.file(f).read(mmap[f]) | |
349 | tn = read(f) |
|
349 | tn = read(f) | |
350 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
350 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
351 | showfunc=showfunc, ignorews=ignorews)) |
|
351 | showfunc=showfunc, ignorews=ignorews)) | |
352 | for f in added: |
|
352 | for f in added: | |
353 | to = None |
|
353 | to = None | |
354 | tn = read(f) |
|
354 | tn = read(f) | |
355 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
355 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
356 | showfunc=showfunc, ignorews=ignorews)) |
|
356 | showfunc=showfunc, ignorews=ignorews)) | |
357 | for f in removed: |
|
357 | for f in removed: | |
358 | to = repo.file(f).read(mmap[f]) |
|
358 | to = repo.file(f).read(mmap[f]) | |
359 | tn = None |
|
359 | tn = None | |
360 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
360 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
361 | showfunc=showfunc, ignorews=ignorews)) |
|
361 | showfunc=showfunc, ignorews=ignorews)) | |
362 |
|
362 | |||
363 | def trimuser(ui, name, rev, revcache): |
|
363 | def trimuser(ui, name, rev, revcache): | |
364 | """trim the name of the user who committed a change""" |
|
364 | """trim the name of the user who committed a change""" | |
365 | user = revcache.get(rev) |
|
365 | user = revcache.get(rev) | |
366 | if user is None: |
|
366 | if user is None: | |
367 | user = revcache[rev] = ui.shortuser(name) |
|
367 | user = revcache[rev] = ui.shortuser(name) | |
368 | return user |
|
368 | return user | |
369 |
|
369 | |||
370 | class changeset_templater(object): |
|
370 | class changeset_templater(object): | |
371 | '''use templater module to format changeset information.''' |
|
371 | '''use templater module to format changeset information.''' | |
372 |
|
372 | |||
373 | def __init__(self, ui, repo, mapfile): |
|
373 | def __init__(self, ui, repo, mapfile): | |
374 | self.t = templater.templater(mapfile, templater.common_filters, |
|
374 | self.t = templater.templater(mapfile, templater.common_filters, | |
375 | cache={'parent': '{rev}:{node|short} ', |
|
375 | cache={'parent': '{rev}:{node|short} ', | |
376 | 'manifest': '{rev}:{node|short}'}) |
|
376 | 'manifest': '{rev}:{node|short}'}) | |
377 | self.ui = ui |
|
377 | self.ui = ui | |
378 | self.repo = repo |
|
378 | self.repo = repo | |
379 |
|
379 | |||
380 | def use_template(self, t): |
|
380 | def use_template(self, t): | |
381 | '''set template string to use''' |
|
381 | '''set template string to use''' | |
382 | self.t.cache['changeset'] = t |
|
382 | self.t.cache['changeset'] = t | |
383 |
|
383 | |||
384 | def write(self, thing): |
|
384 | def write(self, thing): | |
385 | '''write expanded template. |
|
385 | '''write expanded template. | |
386 | uses in-order recursive traverse of iterators.''' |
|
386 | uses in-order recursive traverse of iterators.''' | |
387 | for t in thing: |
|
387 | for t in thing: | |
388 | if hasattr(t, '__iter__'): |
|
388 | if hasattr(t, '__iter__'): | |
389 | self.write(t) |
|
389 | self.write(t) | |
390 | else: |
|
390 | else: | |
391 | self.ui.write(t) |
|
391 | self.ui.write(t) | |
392 |
|
392 | |||
393 | def show(self, rev=0, changenode=None, brinfo=None): |
|
393 | def show(self, rev=0, changenode=None, brinfo=None): | |
394 | '''show a single changeset or file revision''' |
|
394 | '''show a single changeset or file revision''' | |
395 | log = self.repo.changelog |
|
395 | log = self.repo.changelog | |
396 | if changenode is None: |
|
396 | if changenode is None: | |
397 | changenode = log.node(rev) |
|
397 | changenode = log.node(rev) | |
398 | elif not rev: |
|
398 | elif not rev: | |
399 | rev = log.rev(changenode) |
|
399 | rev = log.rev(changenode) | |
400 |
|
400 | |||
401 | changes = log.read(changenode) |
|
401 | changes = log.read(changenode) | |
402 |
|
402 | |||
403 | def showlist(name, values, plural=None, **args): |
|
403 | def showlist(name, values, plural=None, **args): | |
404 | '''expand set of values. |
|
404 | '''expand set of values. | |
405 | name is name of key in template map. |
|
405 | name is name of key in template map. | |
406 | values is list of strings or dicts. |
|
406 | values is list of strings or dicts. | |
407 | plural is plural of name, if not simply name + 's'. |
|
407 | plural is plural of name, if not simply name + 's'. | |
408 |
|
408 | |||
409 | expansion works like this, given name 'foo'. |
|
409 | expansion works like this, given name 'foo'. | |
410 |
|
410 | |||
411 | if values is empty, expand 'no_foos'. |
|
411 | if values is empty, expand 'no_foos'. | |
412 |
|
412 | |||
413 | if 'foo' not in template map, return values as a string, |
|
413 | if 'foo' not in template map, return values as a string, | |
414 | joined by space. |
|
414 | joined by space. | |
415 |
|
415 | |||
416 | expand 'start_foos'. |
|
416 | expand 'start_foos'. | |
417 |
|
417 | |||
418 | for each value, expand 'foo'. if 'last_foo' in template |
|
418 | for each value, expand 'foo'. if 'last_foo' in template | |
419 | map, expand it instead of 'foo' for last key. |
|
419 | map, expand it instead of 'foo' for last key. | |
420 |
|
420 | |||
421 | expand 'end_foos'. |
|
421 | expand 'end_foos'. | |
422 | ''' |
|
422 | ''' | |
423 | if plural: names = plural |
|
423 | if plural: names = plural | |
424 | else: names = name + 's' |
|
424 | else: names = name + 's' | |
425 | if not values: |
|
425 | if not values: | |
426 | noname = 'no_' + names |
|
426 | noname = 'no_' + names | |
427 | if noname in self.t: |
|
427 | if noname in self.t: | |
428 | yield self.t(noname, **args) |
|
428 | yield self.t(noname, **args) | |
429 | return |
|
429 | return | |
430 | if name not in self.t: |
|
430 | if name not in self.t: | |
431 | if isinstance(values[0], str): |
|
431 | if isinstance(values[0], str): | |
432 | yield ' '.join(values) |
|
432 | yield ' '.join(values) | |
433 | else: |
|
433 | else: | |
434 | for v in values: |
|
434 | for v in values: | |
435 | yield dict(v, **args) |
|
435 | yield dict(v, **args) | |
436 | return |
|
436 | return | |
437 | startname = 'start_' + names |
|
437 | startname = 'start_' + names | |
438 | if startname in self.t: |
|
438 | if startname in self.t: | |
439 | yield self.t(startname, **args) |
|
439 | yield self.t(startname, **args) | |
440 | vargs = args.copy() |
|
440 | vargs = args.copy() | |
441 | def one(v, tag=name): |
|
441 | def one(v, tag=name): | |
442 | try: |
|
442 | try: | |
443 | vargs.update(v) |
|
443 | vargs.update(v) | |
444 | except (AttributeError, ValueError): |
|
444 | except (AttributeError, ValueError): | |
445 | try: |
|
445 | try: | |
446 | for a, b in v: |
|
446 | for a, b in v: | |
447 | vargs[a] = b |
|
447 | vargs[a] = b | |
448 | except ValueError: |
|
448 | except ValueError: | |
449 | vargs[name] = v |
|
449 | vargs[name] = v | |
450 | return self.t(tag, **vargs) |
|
450 | return self.t(tag, **vargs) | |
451 | lastname = 'last_' + name |
|
451 | lastname = 'last_' + name | |
452 | if lastname in self.t: |
|
452 | if lastname in self.t: | |
453 | last = values.pop() |
|
453 | last = values.pop() | |
454 | else: |
|
454 | else: | |
455 | last = None |
|
455 | last = None | |
456 | for v in values: |
|
456 | for v in values: | |
457 | yield one(v) |
|
457 | yield one(v) | |
458 | if last is not None: |
|
458 | if last is not None: | |
459 | yield one(last, tag=lastname) |
|
459 | yield one(last, tag=lastname) | |
460 | endname = 'end_' + names |
|
460 | endname = 'end_' + names | |
461 | if endname in self.t: |
|
461 | if endname in self.t: | |
462 | yield self.t(endname, **args) |
|
462 | yield self.t(endname, **args) | |
463 |
|
463 | |||
464 | if brinfo: |
|
464 | if brinfo: | |
465 | def showbranches(**args): |
|
465 | def showbranches(**args): | |
466 | if changenode in brinfo: |
|
466 | if changenode in brinfo: | |
467 | for x in showlist('branch', brinfo[changenode], |
|
467 | for x in showlist('branch', brinfo[changenode], | |
468 | plural='branches', **args): |
|
468 | plural='branches', **args): | |
469 | yield x |
|
469 | yield x | |
470 | else: |
|
470 | else: | |
471 | showbranches = '' |
|
471 | showbranches = '' | |
472 |
|
472 | |||
473 | if self.ui.debugflag: |
|
473 | if self.ui.debugflag: | |
474 | def showmanifest(**args): |
|
474 | def showmanifest(**args): | |
475 | args = args.copy() |
|
475 | args = args.copy() | |
476 | args.update(dict(rev=self.repo.manifest.rev(changes[0]), |
|
476 | args.update(dict(rev=self.repo.manifest.rev(changes[0]), | |
477 | node=hex(changes[0]))) |
|
477 | node=hex(changes[0]))) | |
478 | yield self.t('manifest', **args) |
|
478 | yield self.t('manifest', **args) | |
479 | else: |
|
479 | else: | |
480 | showmanifest = '' |
|
480 | showmanifest = '' | |
481 |
|
481 | |||
482 | def showparents(**args): |
|
482 | def showparents(**args): | |
483 | parents = [[('rev', log.rev(p)), ('node', hex(p))] |
|
483 | parents = [[('rev', log.rev(p)), ('node', hex(p))] | |
484 | for p in log.parents(changenode) |
|
484 | for p in log.parents(changenode) | |
485 | if self.ui.debugflag or p != nullid] |
|
485 | if self.ui.debugflag or p != nullid] | |
486 | if (not self.ui.debugflag and len(parents) == 1 and |
|
486 | if (not self.ui.debugflag and len(parents) == 1 and | |
487 | parents[0][0][1] == rev - 1): |
|
487 | parents[0][0][1] == rev - 1): | |
488 | return |
|
488 | return | |
489 | for x in showlist('parent', parents, **args): |
|
489 | for x in showlist('parent', parents, **args): | |
490 | yield x |
|
490 | yield x | |
491 |
|
491 | |||
492 | def showtags(**args): |
|
492 | def showtags(**args): | |
493 | for x in showlist('tag', self.repo.nodetags(changenode), **args): |
|
493 | for x in showlist('tag', self.repo.nodetags(changenode), **args): | |
494 | yield x |
|
494 | yield x | |
495 |
|
495 | |||
496 | if self.ui.debugflag: |
|
496 | if self.ui.debugflag: | |
497 | files = self.repo.changes(log.parents(changenode)[0], changenode) |
|
497 | files = self.repo.changes(log.parents(changenode)[0], changenode) | |
498 | def showfiles(**args): |
|
498 | def showfiles(**args): | |
499 | for x in showlist('file', files[0], **args): yield x |
|
499 | for x in showlist('file', files[0], **args): yield x | |
500 | def showadds(**args): |
|
500 | def showadds(**args): | |
501 | for x in showlist('file_add', files[1], **args): yield x |
|
501 | for x in showlist('file_add', files[1], **args): yield x | |
502 | def showdels(**args): |
|
502 | def showdels(**args): | |
503 | for x in showlist('file_del', files[2], **args): yield x |
|
503 | for x in showlist('file_del', files[2], **args): yield x | |
504 | else: |
|
504 | else: | |
505 | def showfiles(**args): |
|
505 | def showfiles(**args): | |
506 | for x in showlist('file', changes[3], **args): yield x |
|
506 | for x in showlist('file', changes[3], **args): yield x | |
507 | showadds = '' |
|
507 | showadds = '' | |
508 | showdels = '' |
|
508 | showdels = '' | |
509 |
|
509 | |||
510 | props = { |
|
510 | props = { | |
511 | 'author': changes[1], |
|
511 | 'author': changes[1], | |
512 | 'branches': showbranches, |
|
512 | 'branches': showbranches, | |
513 | 'date': changes[2], |
|
513 | 'date': changes[2], | |
514 | 'desc': changes[4], |
|
514 | 'desc': changes[4], | |
515 | 'file_adds': showadds, |
|
515 | 'file_adds': showadds, | |
516 | 'file_dels': showdels, |
|
516 | 'file_dels': showdels, | |
517 | 'files': showfiles, |
|
517 | 'files': showfiles, | |
518 | 'manifest': showmanifest, |
|
518 | 'manifest': showmanifest, | |
519 | 'node': hex(changenode), |
|
519 | 'node': hex(changenode), | |
520 | 'parents': showparents, |
|
520 | 'parents': showparents, | |
521 | 'rev': rev, |
|
521 | 'rev': rev, | |
522 | 'tags': showtags, |
|
522 | 'tags': showtags, | |
523 | } |
|
523 | } | |
524 |
|
524 | |||
525 | try: |
|
525 | try: | |
526 | if self.ui.debugflag and 'changeset_debug' in self.t: |
|
526 | if self.ui.debugflag and 'changeset_debug' in self.t: | |
527 | key = 'changeset_debug' |
|
527 | key = 'changeset_debug' | |
528 | elif self.ui.quiet and 'changeset_quiet' in self.t: |
|
528 | elif self.ui.quiet and 'changeset_quiet' in self.t: | |
529 | key = 'changeset_quiet' |
|
529 | key = 'changeset_quiet' | |
530 | elif self.ui.verbose and 'changeset_verbose' in self.t: |
|
530 | elif self.ui.verbose and 'changeset_verbose' in self.t: | |
531 | key = 'changeset_verbose' |
|
531 | key = 'changeset_verbose' | |
532 | else: |
|
532 | else: | |
533 | key = 'changeset' |
|
533 | key = 'changeset' | |
534 | self.write(self.t(key, **props)) |
|
534 | self.write(self.t(key, **props)) | |
535 | except KeyError, inst: |
|
535 | except KeyError, inst: | |
536 | raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile, |
|
536 | raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile, | |
537 | inst.args[0])) |
|
537 | inst.args[0])) | |
538 | except SyntaxError, inst: |
|
538 | except SyntaxError, inst: | |
539 | raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0])) |
|
539 | raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0])) | |
540 |
|
540 | |||
541 | class changeset_printer(object): |
|
541 | class changeset_printer(object): | |
542 | '''show changeset information when templating not requested.''' |
|
542 | '''show changeset information when templating not requested.''' | |
543 |
|
543 | |||
544 | def __init__(self, ui, repo): |
|
544 | def __init__(self, ui, repo): | |
545 | self.ui = ui |
|
545 | self.ui = ui | |
546 | self.repo = repo |
|
546 | self.repo = repo | |
547 |
|
547 | |||
548 | def show(self, rev=0, changenode=None, brinfo=None): |
|
548 | def show(self, rev=0, changenode=None, brinfo=None): | |
549 | '''show a single changeset or file revision''' |
|
549 | '''show a single changeset or file revision''' | |
550 | log = self.repo.changelog |
|
550 | log = self.repo.changelog | |
551 | if changenode is None: |
|
551 | if changenode is None: | |
552 | changenode = log.node(rev) |
|
552 | changenode = log.node(rev) | |
553 | elif not rev: |
|
553 | elif not rev: | |
554 | rev = log.rev(changenode) |
|
554 | rev = log.rev(changenode) | |
555 |
|
555 | |||
556 | if self.ui.quiet: |
|
556 | if self.ui.quiet: | |
557 | self.ui.write("%d:%s\n" % (rev, short(changenode))) |
|
557 | self.ui.write("%d:%s\n" % (rev, short(changenode))) | |
558 | return |
|
558 | return | |
559 |
|
559 | |||
560 | changes = log.read(changenode) |
|
560 | changes = log.read(changenode) | |
561 | date = util.datestr(changes[2]) |
|
561 | date = util.datestr(changes[2]) | |
562 |
|
562 | |||
563 | parents = [(log.rev(p), self.ui.verbose and hex(p) or short(p)) |
|
563 | parents = [(log.rev(p), self.ui.verbose and hex(p) or short(p)) | |
564 | for p in log.parents(changenode) |
|
564 | for p in log.parents(changenode) | |
565 | if self.ui.debugflag or p != nullid] |
|
565 | if self.ui.debugflag or p != nullid] | |
566 | if (not self.ui.debugflag and len(parents) == 1 and |
|
566 | if (not self.ui.debugflag and len(parents) == 1 and | |
567 | parents[0][0] == rev-1): |
|
567 | parents[0][0] == rev-1): | |
568 | parents = [] |
|
568 | parents = [] | |
569 |
|
569 | |||
570 | if self.ui.verbose: |
|
570 | if self.ui.verbose: | |
571 | self.ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) |
|
571 | self.ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) | |
572 | else: |
|
572 | else: | |
573 | self.ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) |
|
573 | self.ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) | |
574 |
|
574 | |||
575 | for tag in self.repo.nodetags(changenode): |
|
575 | for tag in self.repo.nodetags(changenode): | |
576 | self.ui.status(_("tag: %s\n") % tag) |
|
576 | self.ui.status(_("tag: %s\n") % tag) | |
577 | for parent in parents: |
|
577 | for parent in parents: | |
578 | self.ui.write(_("parent: %d:%s\n") % parent) |
|
578 | self.ui.write(_("parent: %d:%s\n") % parent) | |
579 |
|
579 | |||
580 | if brinfo and changenode in brinfo: |
|
580 | if brinfo and changenode in brinfo: | |
581 | br = brinfo[changenode] |
|
581 | br = brinfo[changenode] | |
582 | self.ui.write(_("branch: %s\n") % " ".join(br)) |
|
582 | self.ui.write(_("branch: %s\n") % " ".join(br)) | |
583 |
|
583 | |||
584 | self.ui.debug(_("manifest: %d:%s\n") % |
|
584 | self.ui.debug(_("manifest: %d:%s\n") % | |
585 | (self.repo.manifest.rev(changes[0]), hex(changes[0]))) |
|
585 | (self.repo.manifest.rev(changes[0]), hex(changes[0]))) | |
586 | self.ui.status(_("user: %s\n") % changes[1]) |
|
586 | self.ui.status(_("user: %s\n") % changes[1]) | |
587 | self.ui.status(_("date: %s\n") % date) |
|
587 | self.ui.status(_("date: %s\n") % date) | |
588 |
|
588 | |||
589 | if self.ui.debugflag: |
|
589 | if self.ui.debugflag: | |
590 | files = self.repo.changes(log.parents(changenode)[0], changenode) |
|
590 | files = self.repo.changes(log.parents(changenode)[0], changenode) | |
591 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], |
|
591 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], | |
592 | files): |
|
592 | files): | |
593 | if value: |
|
593 | if value: | |
594 | self.ui.note("%-12s %s\n" % (key, " ".join(value))) |
|
594 | self.ui.note("%-12s %s\n" % (key, " ".join(value))) | |
595 | else: |
|
595 | else: | |
596 | self.ui.note(_("files: %s\n") % " ".join(changes[3])) |
|
596 | self.ui.note(_("files: %s\n") % " ".join(changes[3])) | |
597 |
|
597 | |||
598 | description = changes[4].strip() |
|
598 | description = changes[4].strip() | |
599 | if description: |
|
599 | if description: | |
600 | if self.ui.verbose: |
|
600 | if self.ui.verbose: | |
601 | self.ui.status(_("description:\n")) |
|
601 | self.ui.status(_("description:\n")) | |
602 | self.ui.status(description) |
|
602 | self.ui.status(description) | |
603 | self.ui.status("\n\n") |
|
603 | self.ui.status("\n\n") | |
604 | else: |
|
604 | else: | |
605 | self.ui.status(_("summary: %s\n") % |
|
605 | self.ui.status(_("summary: %s\n") % | |
606 | description.splitlines()[0]) |
|
606 | description.splitlines()[0]) | |
607 | self.ui.status("\n") |
|
607 | self.ui.status("\n") | |
608 |
|
608 | |||
609 | def show_changeset(ui, repo, opts): |
|
609 | def show_changeset(ui, repo, opts): | |
610 | '''show one changeset. uses template or regular display. caller |
|
610 | '''show one changeset. uses template or regular display. caller | |
611 | can pass in 'style' and 'template' options in opts.''' |
|
611 | can pass in 'style' and 'template' options in opts.''' | |
612 |
|
612 | |||
613 | tmpl = opts.get('template') |
|
613 | tmpl = opts.get('template') | |
614 | if tmpl: |
|
614 | if tmpl: | |
615 | tmpl = templater.parsestring(tmpl, quoted=False) |
|
615 | tmpl = templater.parsestring(tmpl, quoted=False) | |
616 | else: |
|
616 | else: | |
617 | tmpl = ui.config('ui', 'logtemplate') |
|
617 | tmpl = ui.config('ui', 'logtemplate') | |
618 | if tmpl: tmpl = templater.parsestring(tmpl) |
|
618 | if tmpl: tmpl = templater.parsestring(tmpl) | |
619 | mapfile = opts.get('style') or ui.config('ui', 'style') |
|
619 | mapfile = opts.get('style') or ui.config('ui', 'style') | |
620 | if tmpl or mapfile: |
|
620 | if tmpl or mapfile: | |
621 | if mapfile: |
|
621 | if mapfile: | |
622 | if not os.path.isfile(mapfile): |
|
622 | if not os.path.isfile(mapfile): | |
623 | mapname = templater.templatepath('map-cmdline.' + mapfile) |
|
623 | mapname = templater.templatepath('map-cmdline.' + mapfile) | |
624 | if not mapname: mapname = templater.templatepath(mapfile) |
|
624 | if not mapname: mapname = templater.templatepath(mapfile) | |
625 | if mapname: mapfile = mapname |
|
625 | if mapname: mapfile = mapname | |
626 | try: |
|
626 | try: | |
627 | t = changeset_templater(ui, repo, mapfile) |
|
627 | t = changeset_templater(ui, repo, mapfile) | |
628 | except SyntaxError, inst: |
|
628 | except SyntaxError, inst: | |
629 | raise util.Abort(inst.args[0]) |
|
629 | raise util.Abort(inst.args[0]) | |
630 | if tmpl: t.use_template(tmpl) |
|
630 | if tmpl: t.use_template(tmpl) | |
631 | return t |
|
631 | return t | |
632 | return changeset_printer(ui, repo) |
|
632 | return changeset_printer(ui, repo) | |
633 |
|
633 | |||
634 | def show_version(ui): |
|
634 | def show_version(ui): | |
635 | """output version and copyright information""" |
|
635 | """output version and copyright information""" | |
636 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
636 | ui.write(_("Mercurial Distributed SCM (version %s)\n") | |
637 | % version.get_version()) |
|
637 | % version.get_version()) | |
638 | ui.status(_( |
|
638 | ui.status(_( | |
639 | "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" |
|
639 | "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" | |
640 | "This is free software; see the source for copying conditions. " |
|
640 | "This is free software; see the source for copying conditions. " | |
641 | "There is NO\nwarranty; " |
|
641 | "There is NO\nwarranty; " | |
642 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
642 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | |
643 | )) |
|
643 | )) | |
644 |
|
644 | |||
645 | def help_(ui, cmd=None, with_version=False): |
|
645 | def help_(ui, cmd=None, with_version=False): | |
646 | """show help for a given command or all commands""" |
|
646 | """show help for a given command or all commands""" | |
647 | option_lists = [] |
|
647 | option_lists = [] | |
648 | if cmd and cmd != 'shortlist': |
|
648 | if cmd and cmd != 'shortlist': | |
649 | if with_version: |
|
649 | if with_version: | |
650 | show_version(ui) |
|
650 | show_version(ui) | |
651 | ui.write('\n') |
|
651 | ui.write('\n') | |
652 | aliases, i = find(cmd) |
|
652 | aliases, i = find(cmd) | |
653 | # synopsis |
|
653 | # synopsis | |
654 | ui.write("%s\n\n" % i[2]) |
|
654 | ui.write("%s\n\n" % i[2]) | |
655 |
|
655 | |||
656 | # description |
|
656 | # description | |
657 | doc = i[0].__doc__ |
|
657 | doc = i[0].__doc__ | |
658 | if not doc: |
|
658 | if not doc: | |
659 | doc = _("(No help text available)") |
|
659 | doc = _("(No help text available)") | |
660 | if ui.quiet: |
|
660 | if ui.quiet: | |
661 | doc = doc.splitlines(0)[0] |
|
661 | doc = doc.splitlines(0)[0] | |
662 | ui.write("%s\n" % doc.rstrip()) |
|
662 | ui.write("%s\n" % doc.rstrip()) | |
663 |
|
663 | |||
664 | if not ui.quiet: |
|
664 | if not ui.quiet: | |
665 | # aliases |
|
665 | # aliases | |
666 | if len(aliases) > 1: |
|
666 | if len(aliases) > 1: | |
667 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) |
|
667 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) | |
668 |
|
668 | |||
669 | # options |
|
669 | # options | |
670 | if i[1]: |
|
670 | if i[1]: | |
671 | option_lists.append(("options", i[1])) |
|
671 | option_lists.append(("options", i[1])) | |
672 |
|
672 | |||
673 | else: |
|
673 | else: | |
674 | # program name |
|
674 | # program name | |
675 | if ui.verbose or with_version: |
|
675 | if ui.verbose or with_version: | |
676 | show_version(ui) |
|
676 | show_version(ui) | |
677 | else: |
|
677 | else: | |
678 | ui.status(_("Mercurial Distributed SCM\n")) |
|
678 | ui.status(_("Mercurial Distributed SCM\n")) | |
679 | ui.status('\n') |
|
679 | ui.status('\n') | |
680 |
|
680 | |||
681 | # list of commands |
|
681 | # list of commands | |
682 | if cmd == "shortlist": |
|
682 | if cmd == "shortlist": | |
683 | ui.status(_('basic commands (use "hg help" ' |
|
683 | ui.status(_('basic commands (use "hg help" ' | |
684 | 'for the full list or option "-v" for details):\n\n')) |
|
684 | 'for the full list or option "-v" for details):\n\n')) | |
685 | elif ui.verbose: |
|
685 | elif ui.verbose: | |
686 | ui.status(_('list of commands:\n\n')) |
|
686 | ui.status(_('list of commands:\n\n')) | |
687 | else: |
|
687 | else: | |
688 | ui.status(_('list of commands (use "hg help -v" ' |
|
688 | ui.status(_('list of commands (use "hg help -v" ' | |
689 | 'to show aliases and global options):\n\n')) |
|
689 | 'to show aliases and global options):\n\n')) | |
690 |
|
690 | |||
691 | h = {} |
|
691 | h = {} | |
692 | cmds = {} |
|
692 | cmds = {} | |
693 | for c, e in table.items(): |
|
693 | for c, e in table.items(): | |
694 | f = c.split("|")[0] |
|
694 | f = c.split("|")[0] | |
695 | if cmd == "shortlist" and not f.startswith("^"): |
|
695 | if cmd == "shortlist" and not f.startswith("^"): | |
696 | continue |
|
696 | continue | |
697 | f = f.lstrip("^") |
|
697 | f = f.lstrip("^") | |
698 | if not ui.debugflag and f.startswith("debug"): |
|
698 | if not ui.debugflag and f.startswith("debug"): | |
699 | continue |
|
699 | continue | |
700 | doc = e[0].__doc__ |
|
700 | doc = e[0].__doc__ | |
701 | if not doc: |
|
701 | if not doc: | |
702 | doc = _("(No help text available)") |
|
702 | doc = _("(No help text available)") | |
703 | h[f] = doc.splitlines(0)[0].rstrip() |
|
703 | h[f] = doc.splitlines(0)[0].rstrip() | |
704 | cmds[f] = c.lstrip("^") |
|
704 | cmds[f] = c.lstrip("^") | |
705 |
|
705 | |||
706 | fns = h.keys() |
|
706 | fns = h.keys() | |
707 | fns.sort() |
|
707 | fns.sort() | |
708 | m = max(map(len, fns)) |
|
708 | m = max(map(len, fns)) | |
709 | for f in fns: |
|
709 | for f in fns: | |
710 | if ui.verbose: |
|
710 | if ui.verbose: | |
711 | commands = cmds[f].replace("|",", ") |
|
711 | commands = cmds[f].replace("|",", ") | |
712 | ui.write(" %s:\n %s\n"%(commands, h[f])) |
|
712 | ui.write(" %s:\n %s\n"%(commands, h[f])) | |
713 | else: |
|
713 | else: | |
714 | ui.write(' %-*s %s\n' % (m, f, h[f])) |
|
714 | ui.write(' %-*s %s\n' % (m, f, h[f])) | |
715 |
|
715 | |||
716 | # global options |
|
716 | # global options | |
717 | if ui.verbose: |
|
717 | if ui.verbose: | |
718 | option_lists.append(("global options", globalopts)) |
|
718 | option_lists.append(("global options", globalopts)) | |
719 |
|
719 | |||
720 | # list all option lists |
|
720 | # list all option lists | |
721 | opt_output = [] |
|
721 | opt_output = [] | |
722 | for title, options in option_lists: |
|
722 | for title, options in option_lists: | |
723 | opt_output.append(("\n%s:\n" % title, None)) |
|
723 | opt_output.append(("\n%s:\n" % title, None)) | |
724 | for shortopt, longopt, default, desc in options: |
|
724 | for shortopt, longopt, default, desc in options: | |
725 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, |
|
725 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, | |
726 | longopt and " --%s" % longopt), |
|
726 | longopt and " --%s" % longopt), | |
727 | "%s%s" % (desc, |
|
727 | "%s%s" % (desc, | |
728 | default |
|
728 | default | |
729 | and _(" (default: %s)") % default |
|
729 | and _(" (default: %s)") % default | |
730 | or ""))) |
|
730 | or ""))) | |
731 |
|
731 | |||
732 | if opt_output: |
|
732 | if opt_output: | |
733 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) |
|
733 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) | |
734 | for first, second in opt_output: |
|
734 | for first, second in opt_output: | |
735 | if second: |
|
735 | if second: | |
736 | ui.write(" %-*s %s\n" % (opts_len, first, second)) |
|
736 | ui.write(" %-*s %s\n" % (opts_len, first, second)) | |
737 | else: |
|
737 | else: | |
738 | ui.write("%s\n" % first) |
|
738 | ui.write("%s\n" % first) | |
739 |
|
739 | |||
740 | # Commands start here, listed alphabetically |
|
740 | # Commands start here, listed alphabetically | |
741 |
|
741 | |||
742 | def add(ui, repo, *pats, **opts): |
|
742 | def add(ui, repo, *pats, **opts): | |
743 | """add the specified files on the next commit |
|
743 | """add the specified files on the next commit | |
744 |
|
744 | |||
745 | Schedule files to be version controlled and added to the repository. |
|
745 | Schedule files to be version controlled and added to the repository. | |
746 |
|
746 | |||
747 | The files will be added to the repository at the next commit. |
|
747 | The files will be added to the repository at the next commit. | |
748 |
|
748 | |||
749 | If no names are given, add all files in the repository. |
|
749 | If no names are given, add all files in the repository. | |
750 | """ |
|
750 | """ | |
751 |
|
751 | |||
752 | names = [] |
|
752 | names = [] | |
753 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
753 | for src, abs, rel, exact in walk(repo, pats, opts): | |
754 | if exact: |
|
754 | if exact: | |
755 | if ui.verbose: |
|
755 | if ui.verbose: | |
756 | ui.status(_('adding %s\n') % rel) |
|
756 | ui.status(_('adding %s\n') % rel) | |
757 | names.append(abs) |
|
757 | names.append(abs) | |
758 | elif repo.dirstate.state(abs) == '?': |
|
758 | elif repo.dirstate.state(abs) == '?': | |
759 | ui.status(_('adding %s\n') % rel) |
|
759 | ui.status(_('adding %s\n') % rel) | |
760 | names.append(abs) |
|
760 | names.append(abs) | |
761 | repo.add(names) |
|
761 | repo.add(names) | |
762 |
|
762 | |||
763 | def addremove(ui, repo, *pats, **opts): |
|
763 | def addremove(ui, repo, *pats, **opts): | |
764 | """add all new files, delete all missing files |
|
764 | """add all new files, delete all missing files | |
765 |
|
765 | |||
766 | Add all new files and remove all missing files from the repository. |
|
766 | Add all new files and remove all missing files from the repository. | |
767 |
|
767 | |||
768 | New files are ignored if they match any of the patterns in .hgignore. As |
|
768 | New files are ignored if they match any of the patterns in .hgignore. As | |
769 | with add, these changes take effect at the next commit. |
|
769 | with add, these changes take effect at the next commit. | |
770 | """ |
|
770 | """ | |
771 | return addremove_lock(ui, repo, pats, opts) |
|
771 | return addremove_lock(ui, repo, pats, opts) | |
772 |
|
772 | |||
773 | def addremove_lock(ui, repo, pats, opts, wlock=None): |
|
773 | def addremove_lock(ui, repo, pats, opts, wlock=None): | |
774 | add, remove = [], [] |
|
774 | add, remove = [], [] | |
775 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
775 | for src, abs, rel, exact in walk(repo, pats, opts): | |
776 | if src == 'f' and repo.dirstate.state(abs) == '?': |
|
776 | if src == 'f' and repo.dirstate.state(abs) == '?': | |
777 | add.append(abs) |
|
777 | add.append(abs) | |
778 | if ui.verbose or not exact: |
|
778 | if ui.verbose or not exact: | |
779 | ui.status(_('adding %s\n') % ((pats and rel) or abs)) |
|
779 | ui.status(_('adding %s\n') % ((pats and rel) or abs)) | |
780 | if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): |
|
780 | if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): | |
781 | remove.append(abs) |
|
781 | remove.append(abs) | |
782 | if ui.verbose or not exact: |
|
782 | if ui.verbose or not exact: | |
783 | ui.status(_('removing %s\n') % ((pats and rel) or abs)) |
|
783 | ui.status(_('removing %s\n') % ((pats and rel) or abs)) | |
784 | repo.add(add, wlock=wlock) |
|
784 | repo.add(add, wlock=wlock) | |
785 | repo.remove(remove, wlock=wlock) |
|
785 | repo.remove(remove, wlock=wlock) | |
786 |
|
786 | |||
787 | def annotate(ui, repo, *pats, **opts): |
|
787 | def annotate(ui, repo, *pats, **opts): | |
788 | """show changeset information per file line |
|
788 | """show changeset information per file line | |
789 |
|
789 | |||
790 | List changes in files, showing the revision id responsible for each line |
|
790 | List changes in files, showing the revision id responsible for each line | |
791 |
|
791 | |||
792 | This command is useful to discover who did a change or when a change took |
|
792 | This command is useful to discover who did a change or when a change took | |
793 | place. |
|
793 | place. | |
794 |
|
794 | |||
795 | Without the -a option, annotate will avoid processing files it |
|
795 | Without the -a option, annotate will avoid processing files it | |
796 | detects as binary. With -a, annotate will generate an annotation |
|
796 | detects as binary. With -a, annotate will generate an annotation | |
797 | anyway, probably with undesirable results. |
|
797 | anyway, probably with undesirable results. | |
798 | """ |
|
798 | """ | |
799 | def getnode(rev): |
|
799 | def getnode(rev): | |
800 | return short(repo.changelog.node(rev)) |
|
800 | return short(repo.changelog.node(rev)) | |
801 |
|
801 | |||
802 | ucache = {} |
|
802 | ucache = {} | |
803 | def getname(rev): |
|
803 | def getname(rev): | |
804 | cl = repo.changelog.read(repo.changelog.node(rev)) |
|
804 | cl = repo.changelog.read(repo.changelog.node(rev)) | |
805 | return trimuser(ui, cl[1], rev, ucache) |
|
805 | return trimuser(ui, cl[1], rev, ucache) | |
806 |
|
806 | |||
807 | dcache = {} |
|
807 | dcache = {} | |
808 | def getdate(rev): |
|
808 | def getdate(rev): | |
809 | datestr = dcache.get(rev) |
|
809 | datestr = dcache.get(rev) | |
810 | if datestr is None: |
|
810 | if datestr is None: | |
811 | cl = repo.changelog.read(repo.changelog.node(rev)) |
|
811 | cl = repo.changelog.read(repo.changelog.node(rev)) | |
812 | datestr = dcache[rev] = util.datestr(cl[2]) |
|
812 | datestr = dcache[rev] = util.datestr(cl[2]) | |
813 | return datestr |
|
813 | return datestr | |
814 |
|
814 | |||
815 | if not pats: |
|
815 | if not pats: | |
816 | raise util.Abort(_('at least one file name or pattern required')) |
|
816 | raise util.Abort(_('at least one file name or pattern required')) | |
817 |
|
817 | |||
818 | opmap = [['user', getname], ['number', str], ['changeset', getnode], |
|
818 | opmap = [['user', getname], ['number', str], ['changeset', getnode], | |
819 | ['date', getdate]] |
|
819 | ['date', getdate]] | |
820 | if not opts['user'] and not opts['changeset'] and not opts['date']: |
|
820 | if not opts['user'] and not opts['changeset'] and not opts['date']: | |
821 | opts['number'] = 1 |
|
821 | opts['number'] = 1 | |
822 |
|
822 | |||
823 | if opts['rev']: |
|
823 | if opts['rev']: | |
824 | node = repo.changelog.lookup(opts['rev']) |
|
824 | node = repo.changelog.lookup(opts['rev']) | |
825 | else: |
|
825 | else: | |
826 | node = repo.dirstate.parents()[0] |
|
826 | node = repo.dirstate.parents()[0] | |
827 | change = repo.changelog.read(node) |
|
827 | change = repo.changelog.read(node) | |
828 | mmap = repo.manifest.read(change[0]) |
|
828 | mmap = repo.manifest.read(change[0]) | |
829 |
|
829 | |||
830 | for src, abs, rel, exact in walk(repo, pats, opts, node=node): |
|
830 | for src, abs, rel, exact in walk(repo, pats, opts, node=node): | |
831 | f = repo.file(abs) |
|
831 | f = repo.file(abs) | |
832 | if not opts['text'] and util.binary(f.read(mmap[abs])): |
|
832 | if not opts['text'] and util.binary(f.read(mmap[abs])): | |
833 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) |
|
833 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) | |
834 | continue |
|
834 | continue | |
835 |
|
835 | |||
836 | lines = f.annotate(mmap[abs]) |
|
836 | lines = f.annotate(mmap[abs]) | |
837 | pieces = [] |
|
837 | pieces = [] | |
838 |
|
838 | |||
839 | for o, f in opmap: |
|
839 | for o, f in opmap: | |
840 | if opts[o]: |
|
840 | if opts[o]: | |
841 | l = [f(n) for n, dummy in lines] |
|
841 | l = [f(n) for n, dummy in lines] | |
842 | if l: |
|
842 | if l: | |
843 | m = max(map(len, l)) |
|
843 | m = max(map(len, l)) | |
844 | pieces.append(["%*s" % (m, x) for x in l]) |
|
844 | pieces.append(["%*s" % (m, x) for x in l]) | |
845 |
|
845 | |||
846 | if pieces: |
|
846 | if pieces: | |
847 | for p, l in zip(zip(*pieces), lines): |
|
847 | for p, l in zip(zip(*pieces), lines): | |
848 | ui.write("%s: %s" % (" ".join(p), l[1])) |
|
848 | ui.write("%s: %s" % (" ".join(p), l[1])) | |
849 |
|
849 | |||
850 | def bundle(ui, repo, fname, dest="default-push", **opts): |
|
850 | def bundle(ui, repo, fname, dest="default-push", **opts): | |
851 | """create a changegroup file |
|
851 | """create a changegroup file | |
852 |
|
852 | |||
853 | Generate a compressed changegroup file collecting all changesets |
|
853 | Generate a compressed changegroup file collecting all changesets | |
854 | not found in the other repository. |
|
854 | not found in the other repository. | |
855 |
|
855 | |||
856 | This file can then be transferred using conventional means and |
|
856 | This file can then be transferred using conventional means and | |
857 | applied to another repository with the unbundle command. This is |
|
857 | applied to another repository with the unbundle command. This is | |
858 | useful when native push and pull are not available or when |
|
858 | useful when native push and pull are not available or when | |
859 | exporting an entire repository is undesirable. The standard file |
|
859 | exporting an entire repository is undesirable. The standard file | |
860 | extension is ".hg". |
|
860 | extension is ".hg". | |
861 |
|
861 | |||
862 | Unlike import/export, this exactly preserves all changeset |
|
862 | Unlike import/export, this exactly preserves all changeset | |
863 | contents including permissions, rename data, and revision history. |
|
863 | contents including permissions, rename data, and revision history. | |
864 | """ |
|
864 | """ | |
865 | dest = ui.expandpath(dest) |
|
865 | dest = ui.expandpath(dest) | |
866 | other = hg.repository(ui, dest) |
|
866 | other = hg.repository(ui, dest) | |
867 | o = repo.findoutgoing(other, force=opts['force']) |
|
867 | o = repo.findoutgoing(other, force=opts['force']) | |
868 | cg = repo.changegroup(o, 'bundle') |
|
868 | cg = repo.changegroup(o, 'bundle') | |
869 | write_bundle(cg, fname) |
|
869 | write_bundle(cg, fname) | |
870 |
|
870 | |||
871 | def cat(ui, repo, file1, *pats, **opts): |
|
871 | def cat(ui, repo, file1, *pats, **opts): | |
872 | """output the latest or given revisions of files |
|
872 | """output the latest or given revisions of files | |
873 |
|
873 | |||
874 | Print the specified files as they were at the given revision. |
|
874 | Print the specified files as they were at the given revision. | |
875 | If no revision is given then the tip is used. |
|
875 | If no revision is given then the tip is used. | |
876 |
|
876 | |||
877 | Output may be to a file, in which case the name of the file is |
|
877 | Output may be to a file, in which case the name of the file is | |
878 | given using a format string. The formatting rules are the same as |
|
878 | given using a format string. The formatting rules are the same as | |
879 | for the export command, with the following additions: |
|
879 | for the export command, with the following additions: | |
880 |
|
880 | |||
881 | %s basename of file being printed |
|
881 | %s basename of file being printed | |
882 | %d dirname of file being printed, or '.' if in repo root |
|
882 | %d dirname of file being printed, or '.' if in repo root | |
883 | %p root-relative path name of file being printed |
|
883 | %p root-relative path name of file being printed | |
884 | """ |
|
884 | """ | |
885 | mf = {} |
|
885 | mf = {} | |
886 | rev = opts['rev'] |
|
886 | rev = opts['rev'] | |
887 | if rev: |
|
887 | if rev: | |
888 | node = repo.lookup(rev) |
|
888 | node = repo.lookup(rev) | |
889 | else: |
|
889 | else: | |
890 | node = repo.changelog.tip() |
|
890 | node = repo.changelog.tip() | |
891 | change = repo.changelog.read(node) |
|
891 | change = repo.changelog.read(node) | |
892 | mf = repo.manifest.read(change[0]) |
|
892 | mf = repo.manifest.read(change[0]) | |
893 | for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): |
|
893 | for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): | |
894 | r = repo.file(abs) |
|
894 | r = repo.file(abs) | |
895 | n = mf[abs] |
|
895 | n = mf[abs] | |
896 | fp = make_file(repo, r, opts['output'], node=n, pathname=abs) |
|
896 | fp = make_file(repo, r, opts['output'], node=n, pathname=abs) | |
897 | fp.write(r.read(n)) |
|
897 | fp.write(r.read(n)) | |
898 |
|
898 | |||
899 | def clone(ui, source, dest=None, **opts): |
|
899 | def clone(ui, source, dest=None, **opts): | |
900 | """make a copy of an existing repository |
|
900 | """make a copy of an existing repository | |
901 |
|
901 | |||
902 | Create a copy of an existing repository in a new directory. |
|
902 | Create a copy of an existing repository in a new directory. | |
903 |
|
903 | |||
904 | If no destination directory name is specified, it defaults to the |
|
904 | If no destination directory name is specified, it defaults to the | |
905 | basename of the source. |
|
905 | basename of the source. | |
906 |
|
906 | |||
907 | The location of the source is added to the new repository's |
|
907 | The location of the source is added to the new repository's | |
908 | .hg/hgrc file, as the default to be used for future pulls. |
|
908 | .hg/hgrc file, as the default to be used for future pulls. | |
909 |
|
909 | |||
910 | For efficiency, hardlinks are used for cloning whenever the source |
|
910 | For efficiency, hardlinks are used for cloning whenever the source | |
911 | and destination are on the same filesystem. Some filesystems, |
|
911 | and destination are on the same filesystem. Some filesystems, | |
912 | such as AFS, implement hardlinking incorrectly, but do not report |
|
912 | such as AFS, implement hardlinking incorrectly, but do not report | |
913 | errors. In these cases, use the --pull option to avoid |
|
913 | errors. In these cases, use the --pull option to avoid | |
914 | hardlinking. |
|
914 | hardlinking. | |
915 |
|
915 | |||
916 | See pull for valid source format details. |
|
916 | See pull for valid source format details. | |
917 | """ |
|
917 | """ | |
918 | if dest is None: |
|
918 | if dest is None: | |
919 | dest = os.path.basename(os.path.normpath(source)) |
|
919 | dest = os.path.basename(os.path.normpath(source)) | |
920 |
|
920 | |||
921 | if os.path.exists(dest): |
|
921 | if os.path.exists(dest): | |
922 | raise util.Abort(_("destination '%s' already exists"), dest) |
|
922 | raise util.Abort(_("destination '%s' already exists"), dest) | |
923 |
|
923 | |||
924 | dest = os.path.realpath(dest) |
|
924 | dest = os.path.realpath(dest) | |
925 |
|
925 | |||
926 | class Dircleanup(object): |
|
926 | class Dircleanup(object): | |
927 | def __init__(self, dir_): |
|
927 | def __init__(self, dir_): | |
928 | self.rmtree = shutil.rmtree |
|
928 | self.rmtree = shutil.rmtree | |
929 | self.dir_ = dir_ |
|
929 | self.dir_ = dir_ | |
930 | os.mkdir(dir_) |
|
930 | os.mkdir(dir_) | |
931 | def close(self): |
|
931 | def close(self): | |
932 | self.dir_ = None |
|
932 | self.dir_ = None | |
933 | def __del__(self): |
|
933 | def __del__(self): | |
934 | if self.dir_: |
|
934 | if self.dir_: | |
935 | self.rmtree(self.dir_, True) |
|
935 | self.rmtree(self.dir_, True) | |
936 |
|
936 | |||
937 | if opts['ssh']: |
|
937 | if opts['ssh']: | |
938 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
938 | ui.setconfig("ui", "ssh", opts['ssh']) | |
939 | if opts['remotecmd']: |
|
939 | if opts['remotecmd']: | |
940 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
940 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
941 |
|
941 | |||
942 | source = ui.expandpath(source) |
|
942 | source = ui.expandpath(source) | |
943 |
|
943 | |||
944 | d = Dircleanup(dest) |
|
944 | d = Dircleanup(dest) | |
945 | abspath = source |
|
945 | abspath = source | |
946 | other = hg.repository(ui, source) |
|
946 | other = hg.repository(ui, source) | |
947 |
|
947 | |||
948 | copy = False |
|
948 | copy = False | |
949 | if other.dev() != -1: |
|
949 | if other.dev() != -1: | |
950 | abspath = os.path.abspath(source) |
|
950 | abspath = os.path.abspath(source) | |
951 | if not opts['pull'] and not opts['rev']: |
|
951 | if not opts['pull'] and not opts['rev']: | |
952 | copy = True |
|
952 | copy = True | |
953 |
|
953 | |||
954 | if copy: |
|
954 | if copy: | |
955 | try: |
|
955 | try: | |
956 | # we use a lock here because if we race with commit, we |
|
956 | # we use a lock here because if we race with commit, we | |
957 | # can end up with extra data in the cloned revlogs that's |
|
957 | # can end up with extra data in the cloned revlogs that's | |
958 | # not pointed to by changesets, thus causing verify to |
|
958 | # not pointed to by changesets, thus causing verify to | |
959 | # fail |
|
959 | # fail | |
960 | l1 = other.lock() |
|
960 | l1 = other.lock() | |
961 | except lock.LockException: |
|
961 | except lock.LockException: | |
962 | copy = False |
|
962 | copy = False | |
963 |
|
963 | |||
964 | if copy: |
|
964 | if copy: | |
965 | # we lock here to avoid premature writing to the target |
|
965 | # we lock here to avoid premature writing to the target | |
966 | os.mkdir(os.path.join(dest, ".hg")) |
|
966 | os.mkdir(os.path.join(dest, ".hg")) | |
967 | l2 = lock.lock(os.path.join(dest, ".hg", "lock")) |
|
967 | l2 = lock.lock(os.path.join(dest, ".hg", "lock")) | |
968 |
|
968 | |||
969 | files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" |
|
969 | files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" | |
970 | for f in files.split(): |
|
970 | for f in files.split(): | |
971 | src = os.path.join(source, ".hg", f) |
|
971 | src = os.path.join(source, ".hg", f) | |
972 | dst = os.path.join(dest, ".hg", f) |
|
972 | dst = os.path.join(dest, ".hg", f) | |
973 | try: |
|
973 | try: | |
974 | util.copyfiles(src, dst) |
|
974 | util.copyfiles(src, dst) | |
975 | except OSError, inst: |
|
975 | except OSError, inst: | |
976 | if inst.errno != errno.ENOENT: |
|
976 | if inst.errno != errno.ENOENT: | |
977 | raise |
|
977 | raise | |
978 |
|
978 | |||
979 | repo = hg.repository(ui, dest) |
|
979 | repo = hg.repository(ui, dest) | |
980 |
|
980 | |||
981 | else: |
|
981 | else: | |
982 | revs = None |
|
982 | revs = None | |
983 | if opts['rev']: |
|
983 | if opts['rev']: | |
984 | if not other.local(): |
|
984 | if not other.local(): | |
985 | error = _("clone -r not supported yet for remote repositories.") |
|
985 | error = _("clone -r not supported yet for remote repositories.") | |
986 | raise util.Abort(error) |
|
986 | raise util.Abort(error) | |
987 | else: |
|
987 | else: | |
988 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
988 | revs = [other.lookup(rev) for rev in opts['rev']] | |
989 | repo = hg.repository(ui, dest, create=1) |
|
989 | repo = hg.repository(ui, dest, create=1) | |
990 | repo.pull(other, heads = revs) |
|
990 | repo.pull(other, heads = revs) | |
991 |
|
991 | |||
992 | f = repo.opener("hgrc", "w", text=True) |
|
992 | f = repo.opener("hgrc", "w", text=True) | |
993 | f.write("[paths]\n") |
|
993 | f.write("[paths]\n") | |
994 | f.write("default = %s\n" % abspath) |
|
994 | f.write("default = %s\n" % abspath) | |
995 | f.close() |
|
995 | f.close() | |
996 |
|
996 | |||
997 | if not opts['noupdate']: |
|
997 | if not opts['noupdate']: | |
998 | update(repo.ui, repo) |
|
998 | update(repo.ui, repo) | |
999 |
|
999 | |||
1000 | d.close() |
|
1000 | d.close() | |
1001 |
|
1001 | |||
1002 | def commit(ui, repo, *pats, **opts): |
|
1002 | def commit(ui, repo, *pats, **opts): | |
1003 | """commit the specified files or all outstanding changes |
|
1003 | """commit the specified files or all outstanding changes | |
1004 |
|
1004 | |||
1005 | Commit changes to the given files into the repository. |
|
1005 | Commit changes to the given files into the repository. | |
1006 |
|
1006 | |||
1007 | If a list of files is omitted, all changes reported by "hg status" |
|
1007 | If a list of files is omitted, all changes reported by "hg status" | |
1008 | will be commited. |
|
1008 | will be commited. | |
1009 |
|
1009 | |||
1010 | The HGEDITOR or EDITOR environment variables are used to start an |
|
1010 | The HGEDITOR or EDITOR environment variables are used to start an | |
1011 | editor to add a commit comment. |
|
1011 | editor to add a commit comment. | |
1012 | """ |
|
1012 | """ | |
1013 | message = opts['message'] |
|
1013 | message = opts['message'] | |
1014 | logfile = opts['logfile'] |
|
1014 | logfile = opts['logfile'] | |
1015 |
|
1015 | |||
1016 | if message and logfile: |
|
1016 | if message and logfile: | |
1017 | raise util.Abort(_('options --message and --logfile are mutually ' |
|
1017 | raise util.Abort(_('options --message and --logfile are mutually ' | |
1018 | 'exclusive')) |
|
1018 | 'exclusive')) | |
1019 | if not message and logfile: |
|
1019 | if not message and logfile: | |
1020 | try: |
|
1020 | try: | |
1021 | if logfile == '-': |
|
1021 | if logfile == '-': | |
1022 | message = sys.stdin.read() |
|
1022 | message = sys.stdin.read() | |
1023 | else: |
|
1023 | else: | |
1024 | message = open(logfile).read() |
|
1024 | message = open(logfile).read() | |
1025 | except IOError, inst: |
|
1025 | except IOError, inst: | |
1026 | raise util.Abort(_("can't read commit message '%s': %s") % |
|
1026 | raise util.Abort(_("can't read commit message '%s': %s") % | |
1027 | (logfile, inst.strerror)) |
|
1027 | (logfile, inst.strerror)) | |
1028 |
|
1028 | |||
1029 | if opts['addremove']: |
|
1029 | if opts['addremove']: | |
1030 | addremove(ui, repo, *pats, **opts) |
|
1030 | addremove(ui, repo, *pats, **opts) | |
1031 | fns, match, anypats = matchpats(repo, pats, opts) |
|
1031 | fns, match, anypats = matchpats(repo, pats, opts) | |
1032 | if pats: |
|
1032 | if pats: | |
1033 | modified, added, removed, deleted, unknown = ( |
|
1033 | modified, added, removed, deleted, unknown = ( | |
1034 | repo.changes(files=fns, match=match)) |
|
1034 | repo.changes(files=fns, match=match)) | |
1035 | files = modified + added + removed |
|
1035 | files = modified + added + removed | |
1036 | else: |
|
1036 | else: | |
1037 | files = [] |
|
1037 | files = [] | |
1038 | try: |
|
1038 | try: | |
1039 | repo.commit(files, message, opts['user'], opts['date'], match) |
|
1039 | repo.commit(files, message, opts['user'], opts['date'], match) | |
1040 | except ValueError, inst: |
|
1040 | except ValueError, inst: | |
1041 | raise util.Abort(str(inst)) |
|
1041 | raise util.Abort(str(inst)) | |
1042 |
|
1042 | |||
1043 | def docopy(ui, repo, pats, opts, wlock): |
|
1043 | def docopy(ui, repo, pats, opts, wlock): | |
1044 | # called with the repo lock held |
|
1044 | # called with the repo lock held | |
1045 | cwd = repo.getcwd() |
|
1045 | cwd = repo.getcwd() | |
1046 | errors = 0 |
|
1046 | errors = 0 | |
1047 | copied = [] |
|
1047 | copied = [] | |
1048 | targets = {} |
|
1048 | targets = {} | |
1049 |
|
1049 | |||
1050 | def okaytocopy(abs, rel, exact): |
|
1050 | def okaytocopy(abs, rel, exact): | |
1051 | reasons = {'?': _('is not managed'), |
|
1051 | reasons = {'?': _('is not managed'), | |
1052 | 'a': _('has been marked for add'), |
|
1052 | 'a': _('has been marked for add'), | |
1053 | 'r': _('has been marked for remove')} |
|
1053 | 'r': _('has been marked for remove')} | |
1054 | state = repo.dirstate.state(abs) |
|
1054 | state = repo.dirstate.state(abs) | |
1055 | reason = reasons.get(state) |
|
1055 | reason = reasons.get(state) | |
1056 | if reason: |
|
1056 | if reason: | |
1057 | if state == 'a': |
|
1057 | if state == 'a': | |
1058 | origsrc = repo.dirstate.copied(abs) |
|
1058 | origsrc = repo.dirstate.copied(abs) | |
1059 | if origsrc is not None: |
|
1059 | if origsrc is not None: | |
1060 | return origsrc |
|
1060 | return origsrc | |
1061 | if exact: |
|
1061 | if exact: | |
1062 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) |
|
1062 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) | |
1063 | else: |
|
1063 | else: | |
1064 | return abs |
|
1064 | return abs | |
1065 |
|
1065 | |||
1066 | def copy(origsrc, abssrc, relsrc, target, exact): |
|
1066 | def copy(origsrc, abssrc, relsrc, target, exact): | |
1067 | abstarget = util.canonpath(repo.root, cwd, target) |
|
1067 | abstarget = util.canonpath(repo.root, cwd, target) | |
1068 | reltarget = util.pathto(cwd, abstarget) |
|
1068 | reltarget = util.pathto(cwd, abstarget) | |
1069 | prevsrc = targets.get(abstarget) |
|
1069 | prevsrc = targets.get(abstarget) | |
1070 | if prevsrc is not None: |
|
1070 | if prevsrc is not None: | |
1071 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
|
1071 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % | |
1072 | (reltarget, abssrc, prevsrc)) |
|
1072 | (reltarget, abssrc, prevsrc)) | |
1073 | return |
|
1073 | return | |
1074 | if (not opts['after'] and os.path.exists(reltarget) or |
|
1074 | if (not opts['after'] and os.path.exists(reltarget) or | |
1075 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): |
|
1075 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): | |
1076 | if not opts['force']: |
|
1076 | if not opts['force']: | |
1077 | ui.warn(_('%s: not overwriting - file exists\n') % |
|
1077 | ui.warn(_('%s: not overwriting - file exists\n') % | |
1078 | reltarget) |
|
1078 | reltarget) | |
1079 | return |
|
1079 | return | |
1080 | if not opts['after']: |
|
1080 | if not opts['after']: | |
1081 | os.unlink(reltarget) |
|
1081 | os.unlink(reltarget) | |
1082 | if opts['after']: |
|
1082 | if opts['after']: | |
1083 | if not os.path.exists(reltarget): |
|
1083 | if not os.path.exists(reltarget): | |
1084 | return |
|
1084 | return | |
1085 | else: |
|
1085 | else: | |
1086 | targetdir = os.path.dirname(reltarget) or '.' |
|
1086 | targetdir = os.path.dirname(reltarget) or '.' | |
1087 | if not os.path.isdir(targetdir): |
|
1087 | if not os.path.isdir(targetdir): | |
1088 | os.makedirs(targetdir) |
|
1088 | os.makedirs(targetdir) | |
1089 | try: |
|
1089 | try: | |
1090 | restore = repo.dirstate.state(abstarget) == 'r' |
|
1090 | restore = repo.dirstate.state(abstarget) == 'r' | |
1091 | if restore: |
|
1091 | if restore: | |
1092 | repo.undelete([abstarget], wlock) |
|
1092 | repo.undelete([abstarget], wlock) | |
1093 | try: |
|
1093 | try: | |
1094 | shutil.copyfile(relsrc, reltarget) |
|
1094 | shutil.copyfile(relsrc, reltarget) | |
1095 | shutil.copymode(relsrc, reltarget) |
|
1095 | shutil.copymode(relsrc, reltarget) | |
1096 | restore = False |
|
1096 | restore = False | |
1097 | finally: |
|
1097 | finally: | |
1098 | if restore: |
|
1098 | if restore: | |
1099 | repo.remove([abstarget], wlock) |
|
1099 | repo.remove([abstarget], wlock) | |
1100 | except shutil.Error, inst: |
|
1100 | except shutil.Error, inst: | |
1101 | raise util.Abort(str(inst)) |
|
1101 | raise util.Abort(str(inst)) | |
1102 | except IOError, inst: |
|
1102 | except IOError, inst: | |
1103 | if inst.errno == errno.ENOENT: |
|
1103 | if inst.errno == errno.ENOENT: | |
1104 | ui.warn(_('%s: deleted in working copy\n') % relsrc) |
|
1104 | ui.warn(_('%s: deleted in working copy\n') % relsrc) | |
1105 | else: |
|
1105 | else: | |
1106 | ui.warn(_('%s: cannot copy - %s\n') % |
|
1106 | ui.warn(_('%s: cannot copy - %s\n') % | |
1107 | (relsrc, inst.strerror)) |
|
1107 | (relsrc, inst.strerror)) | |
1108 | errors += 1 |
|
1108 | errors += 1 | |
1109 | return |
|
1109 | return | |
1110 | if ui.verbose or not exact: |
|
1110 | if ui.verbose or not exact: | |
1111 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
|
1111 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) | |
1112 | targets[abstarget] = abssrc |
|
1112 | targets[abstarget] = abssrc | |
1113 | if abstarget != origsrc: |
|
1113 | if abstarget != origsrc: | |
1114 | repo.copy(origsrc, abstarget, wlock) |
|
1114 | repo.copy(origsrc, abstarget, wlock) | |
1115 | copied.append((abssrc, relsrc, exact)) |
|
1115 | copied.append((abssrc, relsrc, exact)) | |
1116 |
|
1116 | |||
1117 | def targetpathfn(pat, dest, srcs): |
|
1117 | def targetpathfn(pat, dest, srcs): | |
1118 | if os.path.isdir(pat): |
|
1118 | if os.path.isdir(pat): | |
1119 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
1119 | abspfx = util.canonpath(repo.root, cwd, pat) | |
1120 | if destdirexists: |
|
1120 | if destdirexists: | |
1121 | striplen = len(os.path.split(abspfx)[0]) |
|
1121 | striplen = len(os.path.split(abspfx)[0]) | |
1122 | else: |
|
1122 | else: | |
1123 | striplen = len(abspfx) |
|
1123 | striplen = len(abspfx) | |
1124 | if striplen: |
|
1124 | if striplen: | |
1125 | striplen += len(os.sep) |
|
1125 | striplen += len(os.sep) | |
1126 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
1126 | res = lambda p: os.path.join(dest, p[striplen:]) | |
1127 | elif destdirexists: |
|
1127 | elif destdirexists: | |
1128 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1128 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1129 | else: |
|
1129 | else: | |
1130 | res = lambda p: dest |
|
1130 | res = lambda p: dest | |
1131 | return res |
|
1131 | return res | |
1132 |
|
1132 | |||
1133 | def targetpathafterfn(pat, dest, srcs): |
|
1133 | def targetpathafterfn(pat, dest, srcs): | |
1134 | if util.patkind(pat, None)[0]: |
|
1134 | if util.patkind(pat, None)[0]: | |
1135 | # a mercurial pattern |
|
1135 | # a mercurial pattern | |
1136 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1136 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1137 | else: |
|
1137 | else: | |
1138 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
1138 | abspfx = util.canonpath(repo.root, cwd, pat) | |
1139 | if len(abspfx) < len(srcs[0][0]): |
|
1139 | if len(abspfx) < len(srcs[0][0]): | |
1140 | # A directory. Either the target path contains the last |
|
1140 | # A directory. Either the target path contains the last | |
1141 | # component of the source path or it does not. |
|
1141 | # component of the source path or it does not. | |
1142 | def evalpath(striplen): |
|
1142 | def evalpath(striplen): | |
1143 | score = 0 |
|
1143 | score = 0 | |
1144 | for s in srcs: |
|
1144 | for s in srcs: | |
1145 | t = os.path.join(dest, s[0][striplen:]) |
|
1145 | t = os.path.join(dest, s[0][striplen:]) | |
1146 | if os.path.exists(t): |
|
1146 | if os.path.exists(t): | |
1147 | score += 1 |
|
1147 | score += 1 | |
1148 | return score |
|
1148 | return score | |
1149 |
|
1149 | |||
1150 | striplen = len(abspfx) |
|
1150 | striplen = len(abspfx) | |
1151 | if striplen: |
|
1151 | if striplen: | |
1152 | striplen += len(os.sep) |
|
1152 | striplen += len(os.sep) | |
1153 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
|
1153 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): | |
1154 | score = evalpath(striplen) |
|
1154 | score = evalpath(striplen) | |
1155 | striplen1 = len(os.path.split(abspfx)[0]) |
|
1155 | striplen1 = len(os.path.split(abspfx)[0]) | |
1156 | if striplen1: |
|
1156 | if striplen1: | |
1157 | striplen1 += len(os.sep) |
|
1157 | striplen1 += len(os.sep) | |
1158 | if evalpath(striplen1) > score: |
|
1158 | if evalpath(striplen1) > score: | |
1159 | striplen = striplen1 |
|
1159 | striplen = striplen1 | |
1160 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
1160 | res = lambda p: os.path.join(dest, p[striplen:]) | |
1161 | else: |
|
1161 | else: | |
1162 | # a file |
|
1162 | # a file | |
1163 | if destdirexists: |
|
1163 | if destdirexists: | |
1164 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1164 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1165 | else: |
|
1165 | else: | |
1166 | res = lambda p: dest |
|
1166 | res = lambda p: dest | |
1167 | return res |
|
1167 | return res | |
1168 |
|
1168 | |||
1169 |
|
1169 | |||
1170 | pats = list(pats) |
|
1170 | pats = list(pats) | |
1171 | if not pats: |
|
1171 | if not pats: | |
1172 | raise util.Abort(_('no source or destination specified')) |
|
1172 | raise util.Abort(_('no source or destination specified')) | |
1173 | if len(pats) == 1: |
|
1173 | if len(pats) == 1: | |
1174 | raise util.Abort(_('no destination specified')) |
|
1174 | raise util.Abort(_('no destination specified')) | |
1175 | dest = pats.pop() |
|
1175 | dest = pats.pop() | |
1176 | destdirexists = os.path.isdir(dest) |
|
1176 | destdirexists = os.path.isdir(dest) | |
1177 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: |
|
1177 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: | |
1178 | raise util.Abort(_('with multiple sources, destination must be an ' |
|
1178 | raise util.Abort(_('with multiple sources, destination must be an ' | |
1179 | 'existing directory')) |
|
1179 | 'existing directory')) | |
1180 | if opts['after']: |
|
1180 | if opts['after']: | |
1181 | tfn = targetpathafterfn |
|
1181 | tfn = targetpathafterfn | |
1182 | else: |
|
1182 | else: | |
1183 | tfn = targetpathfn |
|
1183 | tfn = targetpathfn | |
1184 | copylist = [] |
|
1184 | copylist = [] | |
1185 | for pat in pats: |
|
1185 | for pat in pats: | |
1186 | srcs = [] |
|
1186 | srcs = [] | |
1187 | for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): |
|
1187 | for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): | |
1188 | origsrc = okaytocopy(abssrc, relsrc, exact) |
|
1188 | origsrc = okaytocopy(abssrc, relsrc, exact) | |
1189 | if origsrc: |
|
1189 | if origsrc: | |
1190 | srcs.append((origsrc, abssrc, relsrc, exact)) |
|
1190 | srcs.append((origsrc, abssrc, relsrc, exact)) | |
1191 | if not srcs: |
|
1191 | if not srcs: | |
1192 | continue |
|
1192 | continue | |
1193 | copylist.append((tfn(pat, dest, srcs), srcs)) |
|
1193 | copylist.append((tfn(pat, dest, srcs), srcs)) | |
1194 | if not copylist: |
|
1194 | if not copylist: | |
1195 | raise util.Abort(_('no files to copy')) |
|
1195 | raise util.Abort(_('no files to copy')) | |
1196 |
|
1196 | |||
1197 | for targetpath, srcs in copylist: |
|
1197 | for targetpath, srcs in copylist: | |
1198 | for origsrc, abssrc, relsrc, exact in srcs: |
|
1198 | for origsrc, abssrc, relsrc, exact in srcs: | |
1199 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) |
|
1199 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) | |
1200 |
|
1200 | |||
1201 | if errors: |
|
1201 | if errors: | |
1202 | ui.warn(_('(consider using --after)\n')) |
|
1202 | ui.warn(_('(consider using --after)\n')) | |
1203 | return errors, copied |
|
1203 | return errors, copied | |
1204 |
|
1204 | |||
1205 | def copy(ui, repo, *pats, **opts): |
|
1205 | def copy(ui, repo, *pats, **opts): | |
1206 | """mark files as copied for the next commit |
|
1206 | """mark files as copied for the next commit | |
1207 |
|
1207 | |||
1208 | Mark dest as having copies of source files. If dest is a |
|
1208 | Mark dest as having copies of source files. If dest is a | |
1209 | directory, copies are put in that directory. If dest is a file, |
|
1209 | directory, copies are put in that directory. If dest is a file, | |
1210 | there can only be one source. |
|
1210 | there can only be one source. | |
1211 |
|
1211 | |||
1212 | By default, this command copies the contents of files as they |
|
1212 | By default, this command copies the contents of files as they | |
1213 | stand in the working directory. If invoked with --after, the |
|
1213 | stand in the working directory. If invoked with --after, the | |
1214 | operation is recorded, but no copying is performed. |
|
1214 | operation is recorded, but no copying is performed. | |
1215 |
|
1215 | |||
1216 | This command takes effect in the next commit. |
|
1216 | This command takes effect in the next commit. | |
1217 |
|
1217 | |||
1218 | NOTE: This command should be treated as experimental. While it |
|
1218 | NOTE: This command should be treated as experimental. While it | |
1219 | should properly record copied files, this information is not yet |
|
1219 | should properly record copied files, this information is not yet | |
1220 | fully used by merge, nor fully reported by log. |
|
1220 | fully used by merge, nor fully reported by log. | |
1221 | """ |
|
1221 | """ | |
1222 | try: |
|
1222 | try: | |
1223 | wlock = repo.wlock(0) |
|
1223 | wlock = repo.wlock(0) | |
1224 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
1224 | errs, copied = docopy(ui, repo, pats, opts, wlock) | |
1225 | except lock.LockHeld, inst: |
|
1225 | except lock.LockHeld, inst: | |
1226 | ui.warn(_("repository lock held by %s\n") % inst.args[0]) |
|
1226 | ui.warn(_("repository lock held by %s\n") % inst.args[0]) | |
1227 | errs = 1 |
|
1227 | errs = 1 | |
1228 | return errs |
|
1228 | return errs | |
1229 |
|
1229 | |||
1230 | def debugancestor(ui, index, rev1, rev2): |
|
1230 | def debugancestor(ui, index, rev1, rev2): | |
1231 | """find the ancestor revision of two revisions in a given index""" |
|
1231 | """find the ancestor revision of two revisions in a given index""" | |
1232 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "") |
|
1232 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "") | |
1233 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) |
|
1233 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) | |
1234 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
1234 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) | |
1235 |
|
1235 | |||
1236 | def debugcomplete(ui, cmd): |
|
1236 | def debugcomplete(ui, cmd): | |
1237 | """returns the completion list associated with the given command""" |
|
1237 | """returns the completion list associated with the given command""" | |
1238 | clist = findpossible(cmd).keys() |
|
1238 | clist = findpossible(cmd).keys() | |
1239 | clist.sort() |
|
1239 | clist.sort() | |
1240 | ui.write("%s\n" % " ".join(clist)) |
|
1240 | ui.write("%s\n" % " ".join(clist)) | |
1241 |
|
1241 | |||
1242 | def debugrebuildstate(ui, repo, rev=None): |
|
1242 | def debugrebuildstate(ui, repo, rev=None): | |
1243 | """rebuild the dirstate as it would look like for the given revision""" |
|
1243 | """rebuild the dirstate as it would look like for the given revision""" | |
1244 | if not rev: |
|
1244 | if not rev: | |
1245 | rev = repo.changelog.tip() |
|
1245 | rev = repo.changelog.tip() | |
1246 | else: |
|
1246 | else: | |
1247 | rev = repo.lookup(rev) |
|
1247 | rev = repo.lookup(rev) | |
1248 | change = repo.changelog.read(rev) |
|
1248 | change = repo.changelog.read(rev) | |
1249 | n = change[0] |
|
1249 | n = change[0] | |
1250 | files = repo.manifest.readflags(n) |
|
1250 | files = repo.manifest.readflags(n) | |
1251 | wlock = repo.wlock() |
|
1251 | wlock = repo.wlock() | |
1252 | repo.dirstate.rebuild(rev, files.iteritems()) |
|
1252 | repo.dirstate.rebuild(rev, files.iteritems()) | |
1253 |
|
1253 | |||
1254 | def debugcheckstate(ui, repo): |
|
1254 | def debugcheckstate(ui, repo): | |
1255 | """validate the correctness of the current dirstate""" |
|
1255 | """validate the correctness of the current dirstate""" | |
1256 | parent1, parent2 = repo.dirstate.parents() |
|
1256 | parent1, parent2 = repo.dirstate.parents() | |
1257 | repo.dirstate.read() |
|
1257 | repo.dirstate.read() | |
1258 | dc = repo.dirstate.map |
|
1258 | dc = repo.dirstate.map | |
1259 | keys = dc.keys() |
|
1259 | keys = dc.keys() | |
1260 | keys.sort() |
|
1260 | keys.sort() | |
1261 | m1n = repo.changelog.read(parent1)[0] |
|
1261 | m1n = repo.changelog.read(parent1)[0] | |
1262 | m2n = repo.changelog.read(parent2)[0] |
|
1262 | m2n = repo.changelog.read(parent2)[0] | |
1263 | m1 = repo.manifest.read(m1n) |
|
1263 | m1 = repo.manifest.read(m1n) | |
1264 | m2 = repo.manifest.read(m2n) |
|
1264 | m2 = repo.manifest.read(m2n) | |
1265 | errors = 0 |
|
1265 | errors = 0 | |
1266 | for f in dc: |
|
1266 | for f in dc: | |
1267 | state = repo.dirstate.state(f) |
|
1267 | state = repo.dirstate.state(f) | |
1268 | if state in "nr" and f not in m1: |
|
1268 | if state in "nr" and f not in m1: | |
1269 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
1269 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) | |
1270 | errors += 1 |
|
1270 | errors += 1 | |
1271 | if state in "a" and f in m1: |
|
1271 | if state in "a" and f in m1: | |
1272 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
1272 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) | |
1273 | errors += 1 |
|
1273 | errors += 1 | |
1274 | if state in "m" and f not in m1 and f not in m2: |
|
1274 | if state in "m" and f not in m1 and f not in m2: | |
1275 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
1275 | ui.warn(_("%s in state %s, but not in either manifest\n") % | |
1276 | (f, state)) |
|
1276 | (f, state)) | |
1277 | errors += 1 |
|
1277 | errors += 1 | |
1278 | for f in m1: |
|
1278 | for f in m1: | |
1279 | state = repo.dirstate.state(f) |
|
1279 | state = repo.dirstate.state(f) | |
1280 | if state not in "nrm": |
|
1280 | if state not in "nrm": | |
1281 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
1281 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) | |
1282 | errors += 1 |
|
1282 | errors += 1 | |
1283 | if errors: |
|
1283 | if errors: | |
1284 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
1284 | error = _(".hg/dirstate inconsistent with current parent's manifest") | |
1285 | raise util.Abort(error) |
|
1285 | raise util.Abort(error) | |
1286 |
|
1286 | |||
1287 | def debugconfig(ui, repo): |
|
1287 | def debugconfig(ui, repo): | |
1288 | """show combined config settings from all hgrc files""" |
|
1288 | """show combined config settings from all hgrc files""" | |
1289 | for section, name, value in ui.walkconfig(): |
|
1289 | for section, name, value in ui.walkconfig(): | |
1290 | ui.write('%s.%s=%s\n' % (section, name, value)) |
|
1290 | ui.write('%s.%s=%s\n' % (section, name, value)) | |
1291 |
|
1291 | |||
1292 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
1292 | def debugsetparents(ui, repo, rev1, rev2=None): | |
1293 | """manually set the parents of the current working directory |
|
1293 | """manually set the parents of the current working directory | |
1294 |
|
1294 | |||
1295 | This is useful for writing repository conversion tools, but should |
|
1295 | This is useful for writing repository conversion tools, but should | |
1296 | be used with care. |
|
1296 | be used with care. | |
1297 | """ |
|
1297 | """ | |
1298 |
|
1298 | |||
1299 | if not rev2: |
|
1299 | if not rev2: | |
1300 | rev2 = hex(nullid) |
|
1300 | rev2 = hex(nullid) | |
1301 |
|
1301 | |||
1302 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) |
|
1302 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) | |
1303 |
|
1303 | |||
1304 | def debugstate(ui, repo): |
|
1304 | def debugstate(ui, repo): | |
1305 | """show the contents of the current dirstate""" |
|
1305 | """show the contents of the current dirstate""" | |
1306 | repo.dirstate.read() |
|
1306 | repo.dirstate.read() | |
1307 | dc = repo.dirstate.map |
|
1307 | dc = repo.dirstate.map | |
1308 | keys = dc.keys() |
|
1308 | keys = dc.keys() | |
1309 | keys.sort() |
|
1309 | keys.sort() | |
1310 | for file_ in keys: |
|
1310 | for file_ in keys: | |
1311 | ui.write("%c %3o %10d %s %s\n" |
|
1311 | ui.write("%c %3o %10d %s %s\n" | |
1312 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], |
|
1312 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], | |
1313 | time.strftime("%x %X", |
|
1313 | time.strftime("%x %X", | |
1314 | time.localtime(dc[file_][3])), file_)) |
|
1314 | time.localtime(dc[file_][3])), file_)) | |
1315 | for f in repo.dirstate.copies: |
|
1315 | for f in repo.dirstate.copies: | |
1316 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) |
|
1316 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) | |
1317 |
|
1317 | |||
1318 | def debugdata(ui, file_, rev): |
|
1318 | def debugdata(ui, file_, rev): | |
1319 | """dump the contents of an data file revision""" |
|
1319 | """dump the contents of an data file revision""" | |
1320 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), |
|
1320 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), | |
1321 | file_[:-2] + ".i", file_) |
|
1321 | file_[:-2] + ".i", file_) | |
1322 | try: |
|
1322 | try: | |
1323 | ui.write(r.revision(r.lookup(rev))) |
|
1323 | ui.write(r.revision(r.lookup(rev))) | |
1324 | except KeyError: |
|
1324 | except KeyError: | |
1325 | raise util.Abort(_('invalid revision identifier %s'), rev) |
|
1325 | raise util.Abort(_('invalid revision identifier %s'), rev) | |
1326 |
|
1326 | |||
1327 | def debugindex(ui, file_): |
|
1327 | def debugindex(ui, file_): | |
1328 | """dump the contents of an index file""" |
|
1328 | """dump the contents of an index file""" | |
1329 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") |
|
1329 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") | |
1330 | ui.write(" rev offset length base linkrev" + |
|
1330 | ui.write(" rev offset length base linkrev" + | |
1331 | " nodeid p1 p2\n") |
|
1331 | " nodeid p1 p2\n") | |
1332 | for i in range(r.count()): |
|
1332 | for i in range(r.count()): | |
1333 | e = r.index[i] |
|
1333 | e = r.index[i] | |
1334 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
1334 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( | |
1335 | i, e[0], e[1], e[2], e[3], |
|
1335 | i, e[0], e[1], e[2], e[3], | |
1336 | short(e[6]), short(e[4]), short(e[5]))) |
|
1336 | short(e[6]), short(e[4]), short(e[5]))) | |
1337 |
|
1337 | |||
1338 | def debugindexdot(ui, file_): |
|
1338 | def debugindexdot(ui, file_): | |
1339 | """dump an index DAG as a .dot file""" |
|
1339 | """dump an index DAG as a .dot file""" | |
1340 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") |
|
1340 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") | |
1341 | ui.write("digraph G {\n") |
|
1341 | ui.write("digraph G {\n") | |
1342 | for i in range(r.count()): |
|
1342 | for i in range(r.count()): | |
1343 | e = r.index[i] |
|
1343 | e = r.index[i] | |
1344 | ui.write("\t%d -> %d\n" % (r.rev(e[4]), i)) |
|
1344 | ui.write("\t%d -> %d\n" % (r.rev(e[4]), i)) | |
1345 | if e[5] != nullid: |
|
1345 | if e[5] != nullid: | |
1346 | ui.write("\t%d -> %d\n" % (r.rev(e[5]), i)) |
|
1346 | ui.write("\t%d -> %d\n" % (r.rev(e[5]), i)) | |
1347 | ui.write("}\n") |
|
1347 | ui.write("}\n") | |
1348 |
|
1348 | |||
1349 | def debugrename(ui, repo, file, rev=None): |
|
1349 | def debugrename(ui, repo, file, rev=None): | |
1350 | """dump rename information""" |
|
1350 | """dump rename information""" | |
1351 | r = repo.file(relpath(repo, [file])[0]) |
|
1351 | r = repo.file(relpath(repo, [file])[0]) | |
1352 | if rev: |
|
1352 | if rev: | |
1353 | try: |
|
1353 | try: | |
1354 | # assume all revision numbers are for changesets |
|
1354 | # assume all revision numbers are for changesets | |
1355 | n = repo.lookup(rev) |
|
1355 | n = repo.lookup(rev) | |
1356 | change = repo.changelog.read(n) |
|
1356 | change = repo.changelog.read(n) | |
1357 | m = repo.manifest.read(change[0]) |
|
1357 | m = repo.manifest.read(change[0]) | |
1358 | n = m[relpath(repo, [file])[0]] |
|
1358 | n = m[relpath(repo, [file])[0]] | |
1359 | except (hg.RepoError, KeyError): |
|
1359 | except (hg.RepoError, KeyError): | |
1360 | n = r.lookup(rev) |
|
1360 | n = r.lookup(rev) | |
1361 | else: |
|
1361 | else: | |
1362 | n = r.tip() |
|
1362 | n = r.tip() | |
1363 | m = r.renamed(n) |
|
1363 | m = r.renamed(n) | |
1364 | if m: |
|
1364 | if m: | |
1365 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) |
|
1365 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) | |
1366 | else: |
|
1366 | else: | |
1367 | ui.write(_("not renamed\n")) |
|
1367 | ui.write(_("not renamed\n")) | |
1368 |
|
1368 | |||
1369 | def debugwalk(ui, repo, *pats, **opts): |
|
1369 | def debugwalk(ui, repo, *pats, **opts): | |
1370 | """show how files match on given patterns""" |
|
1370 | """show how files match on given patterns""" | |
1371 | items = list(walk(repo, pats, opts)) |
|
1371 | items = list(walk(repo, pats, opts)) | |
1372 | if not items: |
|
1372 | if not items: | |
1373 | return |
|
1373 | return | |
1374 | fmt = '%%s %%-%ds %%-%ds %%s' % ( |
|
1374 | fmt = '%%s %%-%ds %%-%ds %%s' % ( | |
1375 | max([len(abs) for (src, abs, rel, exact) in items]), |
|
1375 | max([len(abs) for (src, abs, rel, exact) in items]), | |
1376 | max([len(rel) for (src, abs, rel, exact) in items])) |
|
1376 | max([len(rel) for (src, abs, rel, exact) in items])) | |
1377 | for src, abs, rel, exact in items: |
|
1377 | for src, abs, rel, exact in items: | |
1378 | line = fmt % (src, abs, rel, exact and 'exact' or '') |
|
1378 | line = fmt % (src, abs, rel, exact and 'exact' or '') | |
1379 | ui.write("%s\n" % line.rstrip()) |
|
1379 | ui.write("%s\n" % line.rstrip()) | |
1380 |
|
1380 | |||
1381 | def diff(ui, repo, *pats, **opts): |
|
1381 | def diff(ui, repo, *pats, **opts): | |
1382 | """diff repository (or selected files) |
|
1382 | """diff repository (or selected files) | |
1383 |
|
1383 | |||
1384 | Show differences between revisions for the specified files. |
|
1384 | Show differences between revisions for the specified files. | |
1385 |
|
1385 | |||
1386 | Differences between files are shown using the unified diff format. |
|
1386 | Differences between files are shown using the unified diff format. | |
1387 |
|
1387 | |||
1388 | When two revision arguments are given, then changes are shown |
|
1388 | When two revision arguments are given, then changes are shown | |
1389 | between those revisions. If only one revision is specified then |
|
1389 | between those revisions. If only one revision is specified then | |
1390 | that revision is compared to the working directory, and, when no |
|
1390 | that revision is compared to the working directory, and, when no | |
1391 | revisions are specified, the working directory files are compared |
|
1391 | revisions are specified, the working directory files are compared | |
1392 | to its parent. |
|
1392 | to its parent. | |
1393 |
|
1393 | |||
1394 | Without the -a option, diff will avoid generating diffs of files |
|
1394 | Without the -a option, diff will avoid generating diffs of files | |
1395 | it detects as binary. With -a, diff will generate a diff anyway, |
|
1395 | it detects as binary. With -a, diff will generate a diff anyway, | |
1396 | probably with undesirable results. |
|
1396 | probably with undesirable results. | |
1397 | """ |
|
1397 | """ | |
1398 | node1, node2 = None, None |
|
1398 | node1, node2 = None, None | |
1399 | revs = [repo.lookup(x) for x in opts['rev']] |
|
1399 | revs = [repo.lookup(x) for x in opts['rev']] | |
1400 |
|
1400 | |||
1401 | if len(revs) > 0: |
|
1401 | if len(revs) > 0: | |
1402 | node1 = revs[0] |
|
1402 | node1 = revs[0] | |
1403 | if len(revs) > 1: |
|
1403 | if len(revs) > 1: | |
1404 | node2 = revs[1] |
|
1404 | node2 = revs[1] | |
1405 | if len(revs) > 2: |
|
1405 | if len(revs) > 2: | |
1406 | raise util.Abort(_("too many revisions to diff")) |
|
1406 | raise util.Abort(_("too many revisions to diff")) | |
1407 |
|
1407 | |||
1408 | fns, matchfn, anypats = matchpats(repo, pats, opts) |
|
1408 | fns, matchfn, anypats = matchpats(repo, pats, opts) | |
1409 |
|
1409 | |||
1410 | dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, |
|
1410 | dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, | |
1411 | text=opts['text'], opts=opts) |
|
1411 | text=opts['text'], opts=opts) | |
1412 |
|
1412 | |||
1413 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): |
|
1413 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): | |
1414 | node = repo.lookup(changeset) |
|
1414 | node = repo.lookup(changeset) | |
1415 | parents = [p for p in repo.changelog.parents(node) if p != nullid] |
|
1415 | parents = [p for p in repo.changelog.parents(node) if p != nullid] | |
1416 | if opts['switch_parent']: |
|
1416 | if opts['switch_parent']: | |
1417 | parents.reverse() |
|
1417 | parents.reverse() | |
1418 | prev = (parents and parents[0]) or nullid |
|
1418 | prev = (parents and parents[0]) or nullid | |
1419 | change = repo.changelog.read(node) |
|
1419 | change = repo.changelog.read(node) | |
1420 |
|
1420 | |||
1421 | fp = make_file(repo, repo.changelog, opts['output'], |
|
1421 | fp = make_file(repo, repo.changelog, opts['output'], | |
1422 | node=node, total=total, seqno=seqno, |
|
1422 | node=node, total=total, seqno=seqno, | |
1423 | revwidth=revwidth) |
|
1423 | revwidth=revwidth) | |
1424 | if fp != sys.stdout: |
|
1424 | if fp != sys.stdout: | |
1425 | ui.note("%s\n" % fp.name) |
|
1425 | ui.note("%s\n" % fp.name) | |
1426 |
|
1426 | |||
1427 | fp.write("# HG changeset patch\n") |
|
1427 | fp.write("# HG changeset patch\n") | |
1428 | fp.write("# User %s\n" % change[1]) |
|
1428 | fp.write("# User %s\n" % change[1]) | |
1429 | fp.write("# Node ID %s\n" % hex(node)) |
|
1429 | fp.write("# Node ID %s\n" % hex(node)) | |
1430 | fp.write("# Parent %s\n" % hex(prev)) |
|
1430 | fp.write("# Parent %s\n" % hex(prev)) | |
1431 | if len(parents) > 1: |
|
1431 | if len(parents) > 1: | |
1432 | fp.write("# Parent %s\n" % hex(parents[1])) |
|
1432 | fp.write("# Parent %s\n" % hex(parents[1])) | |
1433 | fp.write(change[4].rstrip()) |
|
1433 | fp.write(change[4].rstrip()) | |
1434 | fp.write("\n\n") |
|
1434 | fp.write("\n\n") | |
1435 |
|
1435 | |||
1436 | dodiff(fp, ui, repo, prev, node, text=opts['text']) |
|
1436 | dodiff(fp, ui, repo, prev, node, text=opts['text']) | |
1437 | if fp != sys.stdout: |
|
1437 | if fp != sys.stdout: | |
1438 | fp.close() |
|
1438 | fp.close() | |
1439 |
|
1439 | |||
1440 | def export(ui, repo, *changesets, **opts): |
|
1440 | def export(ui, repo, *changesets, **opts): | |
1441 | """dump the header and diffs for one or more changesets |
|
1441 | """dump the header and diffs for one or more changesets | |
1442 |
|
1442 | |||
1443 | Print the changeset header and diffs for one or more revisions. |
|
1443 | Print the changeset header and diffs for one or more revisions. | |
1444 |
|
1444 | |||
1445 | The information shown in the changeset header is: author, |
|
1445 | The information shown in the changeset header is: author, | |
1446 | changeset hash, parent and commit comment. |
|
1446 | changeset hash, parent and commit comment. | |
1447 |
|
1447 | |||
1448 | Output may be to a file, in which case the name of the file is |
|
1448 | Output may be to a file, in which case the name of the file is | |
1449 | given using a format string. The formatting rules are as follows: |
|
1449 | given using a format string. The formatting rules are as follows: | |
1450 |
|
1450 | |||
1451 | %% literal "%" character |
|
1451 | %% literal "%" character | |
1452 | %H changeset hash (40 bytes of hexadecimal) |
|
1452 | %H changeset hash (40 bytes of hexadecimal) | |
1453 | %N number of patches being generated |
|
1453 | %N number of patches being generated | |
1454 | %R changeset revision number |
|
1454 | %R changeset revision number | |
1455 | %b basename of the exporting repository |
|
1455 | %b basename of the exporting repository | |
1456 | %h short-form changeset hash (12 bytes of hexadecimal) |
|
1456 | %h short-form changeset hash (12 bytes of hexadecimal) | |
1457 | %n zero-padded sequence number, starting at 1 |
|
1457 | %n zero-padded sequence number, starting at 1 | |
1458 | %r zero-padded changeset revision number |
|
1458 | %r zero-padded changeset revision number | |
1459 |
|
1459 | |||
1460 | Without the -a option, export will avoid generating diffs of files |
|
1460 | Without the -a option, export will avoid generating diffs of files | |
1461 | it detects as binary. With -a, export will generate a diff anyway, |
|
1461 | it detects as binary. With -a, export will generate a diff anyway, | |
1462 | probably with undesirable results. |
|
1462 | probably with undesirable results. | |
1463 |
|
1463 | |||
1464 | With the --switch-parent option, the diff will be against the second |
|
1464 | With the --switch-parent option, the diff will be against the second | |
1465 | parent. It can be useful to review a merge. |
|
1465 | parent. It can be useful to review a merge. | |
1466 | """ |
|
1466 | """ | |
1467 | if not changesets: |
|
1467 | if not changesets: | |
1468 | raise util.Abort(_("export requires at least one changeset")) |
|
1468 | raise util.Abort(_("export requires at least one changeset")) | |
1469 | seqno = 0 |
|
1469 | seqno = 0 | |
1470 | revs = list(revrange(ui, repo, changesets)) |
|
1470 | revs = list(revrange(ui, repo, changesets)) | |
1471 | total = len(revs) |
|
1471 | total = len(revs) | |
1472 | revwidth = max(map(len, revs)) |
|
1472 | revwidth = max(map(len, revs)) | |
1473 | msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n") |
|
1473 | msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n") | |
1474 | ui.note(msg) |
|
1474 | ui.note(msg) | |
1475 | for cset in revs: |
|
1475 | for cset in revs: | |
1476 | seqno += 1 |
|
1476 | seqno += 1 | |
1477 | doexport(ui, repo, cset, seqno, total, revwidth, opts) |
|
1477 | doexport(ui, repo, cset, seqno, total, revwidth, opts) | |
1478 |
|
1478 | |||
1479 | def forget(ui, repo, *pats, **opts): |
|
1479 | def forget(ui, repo, *pats, **opts): | |
1480 | """don't add the specified files on the next commit |
|
1480 | """don't add the specified files on the next commit | |
1481 |
|
1481 | |||
1482 | Undo an 'hg add' scheduled for the next commit. |
|
1482 | Undo an 'hg add' scheduled for the next commit. | |
1483 | """ |
|
1483 | """ | |
1484 | forget = [] |
|
1484 | forget = [] | |
1485 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
1485 | for src, abs, rel, exact in walk(repo, pats, opts): | |
1486 | if repo.dirstate.state(abs) == 'a': |
|
1486 | if repo.dirstate.state(abs) == 'a': | |
1487 | forget.append(abs) |
|
1487 | forget.append(abs) | |
1488 | if ui.verbose or not exact: |
|
1488 | if ui.verbose or not exact: | |
1489 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) |
|
1489 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) | |
1490 | repo.forget(forget) |
|
1490 | repo.forget(forget) | |
1491 |
|
1491 | |||
1492 | def grep(ui, repo, pattern, *pats, **opts): |
|
1492 | def grep(ui, repo, pattern, *pats, **opts): | |
1493 | """search for a pattern in specified files and revisions |
|
1493 | """search for a pattern in specified files and revisions | |
1494 |
|
1494 | |||
1495 | Search revisions of files for a regular expression. |
|
1495 | Search revisions of files for a regular expression. | |
1496 |
|
1496 | |||
1497 | This command behaves differently than Unix grep. It only accepts |
|
1497 | This command behaves differently than Unix grep. It only accepts | |
1498 | Python/Perl regexps. It searches repository history, not the |
|
1498 | Python/Perl regexps. It searches repository history, not the | |
1499 | working directory. It always prints the revision number in which |
|
1499 | working directory. It always prints the revision number in which | |
1500 | a match appears. |
|
1500 | a match appears. | |
1501 |
|
1501 | |||
1502 | By default, grep only prints output for the first revision of a |
|
1502 | By default, grep only prints output for the first revision of a | |
1503 | file in which it finds a match. To get it to print every revision |
|
1503 | file in which it finds a match. To get it to print every revision | |
1504 | that contains a change in match status ("-" for a match that |
|
1504 | that contains a change in match status ("-" for a match that | |
1505 | becomes a non-match, or "+" for a non-match that becomes a match), |
|
1505 | becomes a non-match, or "+" for a non-match that becomes a match), | |
1506 | use the --all flag. |
|
1506 | use the --all flag. | |
1507 | """ |
|
1507 | """ | |
1508 | reflags = 0 |
|
1508 | reflags = 0 | |
1509 | if opts['ignore_case']: |
|
1509 | if opts['ignore_case']: | |
1510 | reflags |= re.I |
|
1510 | reflags |= re.I | |
1511 | regexp = re.compile(pattern, reflags) |
|
1511 | regexp = re.compile(pattern, reflags) | |
1512 | sep, eol = ':', '\n' |
|
1512 | sep, eol = ':', '\n' | |
1513 | if opts['print0']: |
|
1513 | if opts['print0']: | |
1514 | sep = eol = '\0' |
|
1514 | sep = eol = '\0' | |
1515 |
|
1515 | |||
1516 | fcache = {} |
|
1516 | fcache = {} | |
1517 | def getfile(fn): |
|
1517 | def getfile(fn): | |
1518 | if fn not in fcache: |
|
1518 | if fn not in fcache: | |
1519 | fcache[fn] = repo.file(fn) |
|
1519 | fcache[fn] = repo.file(fn) | |
1520 | return fcache[fn] |
|
1520 | return fcache[fn] | |
1521 |
|
1521 | |||
1522 | def matchlines(body): |
|
1522 | def matchlines(body): | |
1523 | begin = 0 |
|
1523 | begin = 0 | |
1524 | linenum = 0 |
|
1524 | linenum = 0 | |
1525 | while True: |
|
1525 | while True: | |
1526 | match = regexp.search(body, begin) |
|
1526 | match = regexp.search(body, begin) | |
1527 | if not match: |
|
1527 | if not match: | |
1528 | break |
|
1528 | break | |
1529 | mstart, mend = match.span() |
|
1529 | mstart, mend = match.span() | |
1530 | linenum += body.count('\n', begin, mstart) + 1 |
|
1530 | linenum += body.count('\n', begin, mstart) + 1 | |
1531 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
1531 | lstart = body.rfind('\n', begin, mstart) + 1 or begin | |
1532 | lend = body.find('\n', mend) |
|
1532 | lend = body.find('\n', mend) | |
1533 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
1533 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] | |
1534 | begin = lend + 1 |
|
1534 | begin = lend + 1 | |
1535 |
|
1535 | |||
1536 | class linestate(object): |
|
1536 | class linestate(object): | |
1537 | def __init__(self, line, linenum, colstart, colend): |
|
1537 | def __init__(self, line, linenum, colstart, colend): | |
1538 | self.line = line |
|
1538 | self.line = line | |
1539 | self.linenum = linenum |
|
1539 | self.linenum = linenum | |
1540 | self.colstart = colstart |
|
1540 | self.colstart = colstart | |
1541 | self.colend = colend |
|
1541 | self.colend = colend | |
1542 | def __eq__(self, other): |
|
1542 | def __eq__(self, other): | |
1543 | return self.line == other.line |
|
1543 | return self.line == other.line | |
1544 | def __hash__(self): |
|
1544 | def __hash__(self): | |
1545 | return hash(self.line) |
|
1545 | return hash(self.line) | |
1546 |
|
1546 | |||
1547 | matches = {} |
|
1547 | matches = {} | |
1548 | def grepbody(fn, rev, body): |
|
1548 | def grepbody(fn, rev, body): | |
1549 | matches[rev].setdefault(fn, {}) |
|
1549 | matches[rev].setdefault(fn, {}) | |
1550 | m = matches[rev][fn] |
|
1550 | m = matches[rev][fn] | |
1551 | for lnum, cstart, cend, line in matchlines(body): |
|
1551 | for lnum, cstart, cend, line in matchlines(body): | |
1552 | s = linestate(line, lnum, cstart, cend) |
|
1552 | s = linestate(line, lnum, cstart, cend) | |
1553 | m[s] = s |
|
1553 | m[s] = s | |
1554 |
|
1554 | |||
1555 | # FIXME: prev isn't used, why ? |
|
1555 | # FIXME: prev isn't used, why ? | |
1556 | prev = {} |
|
1556 | prev = {} | |
1557 | ucache = {} |
|
1557 | ucache = {} | |
1558 | def display(fn, rev, states, prevstates): |
|
1558 | def display(fn, rev, states, prevstates): | |
1559 | diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates))) |
|
1559 | diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates))) | |
1560 | diff.sort(lambda x, y: cmp(x.linenum, y.linenum)) |
|
1560 | diff.sort(lambda x, y: cmp(x.linenum, y.linenum)) | |
1561 | counts = {'-': 0, '+': 0} |
|
1561 | counts = {'-': 0, '+': 0} | |
1562 | filerevmatches = {} |
|
1562 | filerevmatches = {} | |
1563 | for l in diff: |
|
1563 | for l in diff: | |
1564 | if incrementing or not opts['all']: |
|
1564 | if incrementing or not opts['all']: | |
1565 | change = ((l in prevstates) and '-') or '+' |
|
1565 | change = ((l in prevstates) and '-') or '+' | |
1566 | r = rev |
|
1566 | r = rev | |
1567 | else: |
|
1567 | else: | |
1568 | change = ((l in states) and '-') or '+' |
|
1568 | change = ((l in states) and '-') or '+' | |
1569 | r = prev[fn] |
|
1569 | r = prev[fn] | |
1570 | cols = [fn, str(rev)] |
|
1570 | cols = [fn, str(rev)] | |
1571 | if opts['line_number']: |
|
1571 | if opts['line_number']: | |
1572 | cols.append(str(l.linenum)) |
|
1572 | cols.append(str(l.linenum)) | |
1573 | if opts['all']: |
|
1573 | if opts['all']: | |
1574 | cols.append(change) |
|
1574 | cols.append(change) | |
1575 | if opts['user']: |
|
1575 | if opts['user']: | |
1576 | cols.append(trimuser(ui, getchange(rev)[1], rev, |
|
1576 | cols.append(trimuser(ui, getchange(rev)[1], rev, | |
1577 | ucache)) |
|
1577 | ucache)) | |
1578 | if opts['files_with_matches']: |
|
1578 | if opts['files_with_matches']: | |
1579 | c = (fn, rev) |
|
1579 | c = (fn, rev) | |
1580 | if c in filerevmatches: |
|
1580 | if c in filerevmatches: | |
1581 | continue |
|
1581 | continue | |
1582 | filerevmatches[c] = 1 |
|
1582 | filerevmatches[c] = 1 | |
1583 | else: |
|
1583 | else: | |
1584 | cols.append(l.line) |
|
1584 | cols.append(l.line) | |
1585 | ui.write(sep.join(cols), eol) |
|
1585 | ui.write(sep.join(cols), eol) | |
1586 | counts[change] += 1 |
|
1586 | counts[change] += 1 | |
1587 | return counts['+'], counts['-'] |
|
1587 | return counts['+'], counts['-'] | |
1588 |
|
1588 | |||
1589 | fstate = {} |
|
1589 | fstate = {} | |
1590 | skip = {} |
|
1590 | skip = {} | |
1591 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1591 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | |
1592 | count = 0 |
|
1592 | count = 0 | |
1593 | incrementing = False |
|
1593 | incrementing = False | |
1594 | for st, rev, fns in changeiter: |
|
1594 | for st, rev, fns in changeiter: | |
1595 | if st == 'window': |
|
1595 | if st == 'window': | |
1596 | incrementing = rev |
|
1596 | incrementing = rev | |
1597 | matches.clear() |
|
1597 | matches.clear() | |
1598 | elif st == 'add': |
|
1598 | elif st == 'add': | |
1599 | change = repo.changelog.read(repo.lookup(str(rev))) |
|
1599 | change = repo.changelog.read(repo.lookup(str(rev))) | |
1600 | mf = repo.manifest.read(change[0]) |
|
1600 | mf = repo.manifest.read(change[0]) | |
1601 | matches[rev] = {} |
|
1601 | matches[rev] = {} | |
1602 | for fn in fns: |
|
1602 | for fn in fns: | |
1603 | if fn in skip: |
|
1603 | if fn in skip: | |
1604 | continue |
|
1604 | continue | |
1605 | fstate.setdefault(fn, {}) |
|
1605 | fstate.setdefault(fn, {}) | |
1606 | try: |
|
1606 | try: | |
1607 | grepbody(fn, rev, getfile(fn).read(mf[fn])) |
|
1607 | grepbody(fn, rev, getfile(fn).read(mf[fn])) | |
1608 | except KeyError: |
|
1608 | except KeyError: | |
1609 | pass |
|
1609 | pass | |
1610 | elif st == 'iter': |
|
1610 | elif st == 'iter': | |
1611 | states = matches[rev].items() |
|
1611 | states = matches[rev].items() | |
1612 | states.sort() |
|
1612 | states.sort() | |
1613 | for fn, m in states: |
|
1613 | for fn, m in states: | |
1614 | if fn in skip: |
|
1614 | if fn in skip: | |
1615 | continue |
|
1615 | continue | |
1616 | if incrementing or not opts['all'] or fstate[fn]: |
|
1616 | if incrementing or not opts['all'] or fstate[fn]: | |
1617 | pos, neg = display(fn, rev, m, fstate[fn]) |
|
1617 | pos, neg = display(fn, rev, m, fstate[fn]) | |
1618 | count += pos + neg |
|
1618 | count += pos + neg | |
1619 | if pos and not opts['all']: |
|
1619 | if pos and not opts['all']: | |
1620 | skip[fn] = True |
|
1620 | skip[fn] = True | |
1621 | fstate[fn] = m |
|
1621 | fstate[fn] = m | |
1622 | prev[fn] = rev |
|
1622 | prev[fn] = rev | |
1623 |
|
1623 | |||
1624 | if not incrementing: |
|
1624 | if not incrementing: | |
1625 | fstate = fstate.items() |
|
1625 | fstate = fstate.items() | |
1626 | fstate.sort() |
|
1626 | fstate.sort() | |
1627 | for fn, state in fstate: |
|
1627 | for fn, state in fstate: | |
1628 | if fn in skip: |
|
1628 | if fn in skip: | |
1629 | continue |
|
1629 | continue | |
1630 | display(fn, rev, {}, state) |
|
1630 | display(fn, rev, {}, state) | |
1631 | return (count == 0 and 1) or 0 |
|
1631 | return (count == 0 and 1) or 0 | |
1632 |
|
1632 | |||
1633 | def heads(ui, repo, **opts): |
|
1633 | def heads(ui, repo, **opts): | |
1634 | """show current repository heads |
|
1634 | """show current repository heads | |
1635 |
|
1635 | |||
1636 | Show all repository head changesets. |
|
1636 | Show all repository head changesets. | |
1637 |
|
1637 | |||
1638 | Repository "heads" are changesets that don't have children |
|
1638 | Repository "heads" are changesets that don't have children | |
1639 | changesets. They are where development generally takes place and |
|
1639 | changesets. They are where development generally takes place and | |
1640 | are the usual targets for update and merge operations. |
|
1640 | are the usual targets for update and merge operations. | |
1641 | """ |
|
1641 | """ | |
1642 | if opts['rev']: |
|
1642 | if opts['rev']: | |
1643 | heads = repo.heads(repo.lookup(opts['rev'])) |
|
1643 | heads = repo.heads(repo.lookup(opts['rev'])) | |
1644 | else: |
|
1644 | else: | |
1645 | heads = repo.heads() |
|
1645 | heads = repo.heads() | |
1646 | br = None |
|
1646 | br = None | |
1647 | if opts['branches']: |
|
1647 | if opts['branches']: | |
1648 | br = repo.branchlookup(heads) |
|
1648 | br = repo.branchlookup(heads) | |
1649 | displayer = show_changeset(ui, repo, opts) |
|
1649 | displayer = show_changeset(ui, repo, opts) | |
1650 | for n in heads: |
|
1650 | for n in heads: | |
1651 | displayer.show(changenode=n, brinfo=br) |
|
1651 | displayer.show(changenode=n, brinfo=br) | |
1652 |
|
1652 | |||
1653 | def identify(ui, repo): |
|
1653 | def identify(ui, repo): | |
1654 | """print information about the working copy |
|
1654 | """print information about the working copy | |
1655 |
|
1655 | |||
1656 | Print a short summary of the current state of the repo. |
|
1656 | Print a short summary of the current state of the repo. | |
1657 |
|
1657 | |||
1658 | This summary identifies the repository state using one or two parent |
|
1658 | This summary identifies the repository state using one or two parent | |
1659 | hash identifiers, followed by a "+" if there are uncommitted changes |
|
1659 | hash identifiers, followed by a "+" if there are uncommitted changes | |
1660 | in the working directory, followed by a list of tags for this revision. |
|
1660 | in the working directory, followed by a list of tags for this revision. | |
1661 | """ |
|
1661 | """ | |
1662 | parents = [p for p in repo.dirstate.parents() if p != nullid] |
|
1662 | parents = [p for p in repo.dirstate.parents() if p != nullid] | |
1663 | if not parents: |
|
1663 | if not parents: | |
1664 | ui.write(_("unknown\n")) |
|
1664 | ui.write(_("unknown\n")) | |
1665 | return |
|
1665 | return | |
1666 |
|
1666 | |||
1667 | hexfunc = ui.verbose and hex or short |
|
1667 | hexfunc = ui.verbose and hex or short | |
1668 | modified, added, removed, deleted, unknown = repo.changes() |
|
1668 | modified, added, removed, deleted, unknown = repo.changes() | |
1669 | output = ["%s%s" % |
|
1669 | output = ["%s%s" % | |
1670 | ('+'.join([hexfunc(parent) for parent in parents]), |
|
1670 | ('+'.join([hexfunc(parent) for parent in parents]), | |
1671 | (modified or added or removed or deleted) and "+" or "")] |
|
1671 | (modified or added or removed or deleted) and "+" or "")] | |
1672 |
|
1672 | |||
1673 | if not ui.quiet: |
|
1673 | if not ui.quiet: | |
1674 | # multiple tags for a single parent separated by '/' |
|
1674 | # multiple tags for a single parent separated by '/' | |
1675 | parenttags = ['/'.join(tags) |
|
1675 | parenttags = ['/'.join(tags) | |
1676 | for tags in map(repo.nodetags, parents) if tags] |
|
1676 | for tags in map(repo.nodetags, parents) if tags] | |
1677 | # tags for multiple parents separated by ' + ' |
|
1677 | # tags for multiple parents separated by ' + ' | |
1678 | if parenttags: |
|
1678 | if parenttags: | |
1679 | output.append(' + '.join(parenttags)) |
|
1679 | output.append(' + '.join(parenttags)) | |
1680 |
|
1680 | |||
1681 | ui.write("%s\n" % ' '.join(output)) |
|
1681 | ui.write("%s\n" % ' '.join(output)) | |
1682 |
|
1682 | |||
1683 | def import_(ui, repo, patch1, *patches, **opts): |
|
1683 | def import_(ui, repo, patch1, *patches, **opts): | |
1684 | """import an ordered set of patches |
|
1684 | """import an ordered set of patches | |
1685 |
|
1685 | |||
1686 | Import a list of patches and commit them individually. |
|
1686 | Import a list of patches and commit them individually. | |
1687 |
|
1687 | |||
1688 | If there are outstanding changes in the working directory, import |
|
1688 | If there are outstanding changes in the working directory, import | |
1689 | will abort unless given the -f flag. |
|
1689 | will abort unless given the -f flag. | |
1690 |
|
1690 | |||
1691 | If a patch looks like a mail message (its first line starts with |
|
1691 | If a patch looks like a mail message (its first line starts with | |
1692 | "From " or looks like an RFC822 header), it will not be applied |
|
1692 | "From " or looks like an RFC822 header), it will not be applied | |
1693 | unless the -f option is used. The importer neither parses nor |
|
1693 | unless the -f option is used. The importer neither parses nor | |
1694 | discards mail headers, so use -f only to override the "mailness" |
|
1694 | discards mail headers, so use -f only to override the "mailness" | |
1695 | safety check, not to import a real mail message. |
|
1695 | safety check, not to import a real mail message. | |
1696 | """ |
|
1696 | """ | |
1697 | patches = (patch1,) + patches |
|
1697 | patches = (patch1,) + patches | |
1698 |
|
1698 | |||
1699 | if not opts['force']: |
|
1699 | if not opts['force']: | |
1700 | modified, added, removed, deleted, unknown = repo.changes() |
|
1700 | modified, added, removed, deleted, unknown = repo.changes() | |
1701 | if modified or added or removed or deleted: |
|
1701 | if modified or added or removed or deleted: | |
1702 | raise util.Abort(_("outstanding uncommitted changes")) |
|
1702 | raise util.Abort(_("outstanding uncommitted changes")) | |
1703 |
|
1703 | |||
1704 | d = opts["base"] |
|
1704 | d = opts["base"] | |
1705 | strip = opts["strip"] |
|
1705 | strip = opts["strip"] | |
1706 |
|
1706 | |||
1707 | mailre = re.compile(r'(?:From |[\w-]+:)') |
|
1707 | mailre = re.compile(r'(?:From |[\w-]+:)') | |
1708 |
|
1708 | |||
1709 | # attempt to detect the start of a patch |
|
1709 | # attempt to detect the start of a patch | |
1710 | # (this heuristic is borrowed from quilt) |
|
1710 | # (this heuristic is borrowed from quilt) | |
1711 | diffre = re.compile(r'(?:Index:[ \t]|diff[ \t]|RCS file: |' + |
|
1711 | diffre = re.compile(r'(?:Index:[ \t]|diff[ \t]|RCS file: |' + | |
1712 | 'retrieving revision [0-9]+(\.[0-9]+)*$|' + |
|
1712 | 'retrieving revision [0-9]+(\.[0-9]+)*$|' + | |
1713 | '(---|\*\*\*)[ \t])') |
|
1713 | '(---|\*\*\*)[ \t])') | |
1714 |
|
1714 | |||
1715 | for patch in patches: |
|
1715 | for patch in patches: | |
1716 | ui.status(_("applying %s\n") % patch) |
|
1716 | ui.status(_("applying %s\n") % patch) | |
1717 | pf = os.path.join(d, patch) |
|
1717 | pf = os.path.join(d, patch) | |
1718 |
|
1718 | |||
1719 | message = [] |
|
1719 | message = [] | |
1720 | user = None |
|
1720 | user = None | |
1721 | hgpatch = False |
|
1721 | hgpatch = False | |
1722 | for line in file(pf): |
|
1722 | for line in file(pf): | |
1723 | line = line.rstrip() |
|
1723 | line = line.rstrip() | |
1724 | if (not message and not hgpatch and |
|
1724 | if (not message and not hgpatch and | |
1725 | mailre.match(line) and not opts['force']): |
|
1725 | mailre.match(line) and not opts['force']): | |
1726 | if len(line) > 35: |
|
1726 | if len(line) > 35: | |
1727 | line = line[:32] + '...' |
|
1727 | line = line[:32] + '...' | |
1728 | raise util.Abort(_('first line looks like a ' |
|
1728 | raise util.Abort(_('first line looks like a ' | |
1729 | 'mail header: ') + line) |
|
1729 | 'mail header: ') + line) | |
1730 | if diffre.match(line): |
|
1730 | if diffre.match(line): | |
1731 | break |
|
1731 | break | |
1732 | elif hgpatch: |
|
1732 | elif hgpatch: | |
1733 | # parse values when importing the result of an hg export |
|
1733 | # parse values when importing the result of an hg export | |
1734 | if line.startswith("# User "): |
|
1734 | if line.startswith("# User "): | |
1735 | user = line[7:] |
|
1735 | user = line[7:] | |
1736 | ui.debug(_('User: %s\n') % user) |
|
1736 | ui.debug(_('User: %s\n') % user) | |
1737 | elif not line.startswith("# ") and line: |
|
1737 | elif not line.startswith("# ") and line: | |
1738 | message.append(line) |
|
1738 | message.append(line) | |
1739 | hgpatch = False |
|
1739 | hgpatch = False | |
1740 | elif line == '# HG changeset patch': |
|
1740 | elif line == '# HG changeset patch': | |
1741 | hgpatch = True |
|
1741 | hgpatch = True | |
1742 | message = [] # We may have collected garbage |
|
1742 | message = [] # We may have collected garbage | |
1743 | else: |
|
1743 | else: | |
1744 | message.append(line) |
|
1744 | message.append(line) | |
1745 |
|
1745 | |||
1746 | # make sure message isn't empty |
|
1746 | # make sure message isn't empty | |
1747 | if not message: |
|
1747 | if not message: | |
1748 | message = _("imported patch %s\n") % patch |
|
1748 | message = _("imported patch %s\n") % patch | |
1749 | else: |
|
1749 | else: | |
1750 | message = "%s\n" % '\n'.join(message) |
|
1750 | message = "%s\n" % '\n'.join(message) | |
1751 | ui.debug(_('message:\n%s\n') % message) |
|
1751 | ui.debug(_('message:\n%s\n') % message) | |
1752 |
|
1752 | |||
1753 | files = util.patch(strip, pf, ui) |
|
1753 | files = util.patch(strip, pf, ui) | |
1754 |
|
1754 | |||
1755 | if len(files) > 0: |
|
1755 | if len(files) > 0: | |
1756 | addremove(ui, repo, *files) |
|
1756 | addremove(ui, repo, *files) | |
1757 | repo.commit(files, message, user) |
|
1757 | repo.commit(files, message, user) | |
1758 |
|
1758 | |||
1759 | def incoming(ui, repo, source="default", **opts): |
|
1759 | def incoming(ui, repo, source="default", **opts): | |
1760 | """show new changesets found in source |
|
1760 | """show new changesets found in source | |
1761 |
|
1761 | |||
1762 | Show new changesets found in the specified repo or the default |
|
1762 | Show new changesets found in the specified repo or the default | |
1763 | pull repo. These are the changesets that would be pulled if a pull |
|
1763 | pull repo. These are the changesets that would be pulled if a pull | |
1764 | was requested. |
|
1764 | was requested. | |
1765 |
|
1765 | |||
1766 | For remote repository, using --bundle avoids downloading the changesets |
|
1766 | For remote repository, using --bundle avoids downloading the changesets | |
1767 | twice if the incoming is followed by a pull. |
|
1767 | twice if the incoming is followed by a pull. | |
1768 | """ |
|
1768 | """ | |
1769 | source = ui.expandpath(source) |
|
1769 | source = ui.expandpath(source) | |
1770 | if opts['ssh']: |
|
1770 | if opts['ssh']: | |
1771 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
1771 | ui.setconfig("ui", "ssh", opts['ssh']) | |
1772 | if opts['remotecmd']: |
|
1772 | if opts['remotecmd']: | |
1773 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
1773 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
1774 |
|
1774 | |||
1775 | other = hg.repository(ui, source) |
|
1775 | other = hg.repository(ui, source) | |
1776 | incoming = repo.findincoming(other, force=opts["force"]) |
|
1776 | incoming = repo.findincoming(other, force=opts["force"]) | |
1777 | if not incoming: |
|
1777 | if not incoming: | |
1778 | return |
|
1778 | return | |
1779 |
|
1779 | |||
1780 | cleanup = None |
|
1780 | cleanup = None | |
1781 | if not other.local() or opts["bundle"]: |
|
1781 | if not other.local() or opts["bundle"]: | |
1782 | # create an uncompressed bundle |
|
1782 | # create an uncompressed bundle | |
1783 | if not opts["bundle"]: |
|
1783 | if not opts["bundle"]: | |
1784 | # create a temporary bundle |
|
1784 | # create a temporary bundle | |
1785 | fd, fname = tempfile.mkstemp(suffix=".hg", |
|
1785 | fd, fname = tempfile.mkstemp(suffix=".hg", | |
1786 | prefix="tmp-hg-incoming") |
|
1786 | prefix="tmp-hg-incoming") | |
1787 | f = os.fdopen(fd, "wb") |
|
1787 | f = os.fdopen(fd, "wb") | |
1788 | cleanup = fname |
|
1788 | cleanup = fname | |
1789 | else: |
|
1789 | else: | |
1790 | fname = opts["bundle"] |
|
1790 | fname = opts["bundle"] | |
1791 | f = open(fname, "wb") |
|
1791 | f = open(fname, "wb") | |
1792 |
|
1792 | |||
1793 | cg = other.changegroup(incoming, "incoming") |
|
1793 | cg = other.changegroup(incoming, "incoming") | |
1794 | write_bundle(cg, fname, compress=other.local(), fh=f) |
|
1794 | write_bundle(cg, fname, compress=other.local(), fh=f) | |
1795 | if not other.local(): |
|
1795 | if not other.local(): | |
1796 | # use a bundlerepo |
|
1796 | # use a bundlerepo | |
1797 | other = bundlerepo.bundlerepository(ui, repo.root, fname) |
|
1797 | other = bundlerepo.bundlerepository(ui, repo.root, fname) | |
1798 |
|
1798 | |||
1799 | o = other.changelog.nodesbetween(incoming)[0] |
|
1799 | o = other.changelog.nodesbetween(incoming)[0] | |
1800 | if opts['newest_first']: |
|
1800 | if opts['newest_first']: | |
1801 | o.reverse() |
|
1801 | o.reverse() | |
1802 | displayer = show_changeset(ui, other, opts) |
|
1802 | displayer = show_changeset(ui, other, opts) | |
1803 | for n in o: |
|
1803 | for n in o: | |
1804 | parents = [p for p in other.changelog.parents(n) if p != nullid] |
|
1804 | parents = [p for p in other.changelog.parents(n) if p != nullid] | |
1805 | if opts['no_merges'] and len(parents) == 2: |
|
1805 | if opts['no_merges'] and len(parents) == 2: | |
1806 | continue |
|
1806 | continue | |
1807 | displayer.show(changenode=n) |
|
1807 | displayer.show(changenode=n) | |
1808 | if opts['patch']: |
|
1808 | if opts['patch']: | |
1809 | prev = (parents and parents[0]) or nullid |
|
1809 | prev = (parents and parents[0]) or nullid | |
1810 | dodiff(ui, ui, other, prev, n) |
|
1810 | dodiff(ui, ui, other, prev, n) | |
1811 | ui.write("\n") |
|
1811 | ui.write("\n") | |
1812 |
|
1812 | |||
1813 | if cleanup: |
|
1813 | if cleanup: | |
1814 | os.close(fd) |
|
1814 | other.close() # explicit close for unlink | |
1815 | os.unlink(cleanup) |
|
1815 | os.unlink(cleanup) | |
1816 |
|
1816 | |||
1817 | def init(ui, dest="."): |
|
1817 | def init(ui, dest="."): | |
1818 | """create a new repository in the given directory |
|
1818 | """create a new repository in the given directory | |
1819 |
|
1819 | |||
1820 | Initialize a new repository in the given directory. If the given |
|
1820 | Initialize a new repository in the given directory. If the given | |
1821 | directory does not exist, it is created. |
|
1821 | directory does not exist, it is created. | |
1822 |
|
1822 | |||
1823 | If no directory is given, the current directory is used. |
|
1823 | If no directory is given, the current directory is used. | |
1824 | """ |
|
1824 | """ | |
1825 | if not os.path.exists(dest): |
|
1825 | if not os.path.exists(dest): | |
1826 | os.mkdir(dest) |
|
1826 | os.mkdir(dest) | |
1827 | hg.repository(ui, dest, create=1) |
|
1827 | hg.repository(ui, dest, create=1) | |
1828 |
|
1828 | |||
1829 | def locate(ui, repo, *pats, **opts): |
|
1829 | def locate(ui, repo, *pats, **opts): | |
1830 | """locate files matching specific patterns |
|
1830 | """locate files matching specific patterns | |
1831 |
|
1831 | |||
1832 | Print all files under Mercurial control whose names match the |
|
1832 | Print all files under Mercurial control whose names match the | |
1833 | given patterns. |
|
1833 | given patterns. | |
1834 |
|
1834 | |||
1835 | This command searches the current directory and its |
|
1835 | This command searches the current directory and its | |
1836 | subdirectories. To search an entire repository, move to the root |
|
1836 | subdirectories. To search an entire repository, move to the root | |
1837 | of the repository. |
|
1837 | of the repository. | |
1838 |
|
1838 | |||
1839 | If no patterns are given to match, this command prints all file |
|
1839 | If no patterns are given to match, this command prints all file | |
1840 | names. |
|
1840 | names. | |
1841 |
|
1841 | |||
1842 | If you want to feed the output of this command into the "xargs" |
|
1842 | If you want to feed the output of this command into the "xargs" | |
1843 | command, use the "-0" option to both this command and "xargs". |
|
1843 | command, use the "-0" option to both this command and "xargs". | |
1844 | This will avoid the problem of "xargs" treating single filenames |
|
1844 | This will avoid the problem of "xargs" treating single filenames | |
1845 | that contain white space as multiple filenames. |
|
1845 | that contain white space as multiple filenames. | |
1846 | """ |
|
1846 | """ | |
1847 | end = opts['print0'] and '\0' or '\n' |
|
1847 | end = opts['print0'] and '\0' or '\n' | |
1848 | rev = opts['rev'] |
|
1848 | rev = opts['rev'] | |
1849 | if rev: |
|
1849 | if rev: | |
1850 | node = repo.lookup(rev) |
|
1850 | node = repo.lookup(rev) | |
1851 | else: |
|
1851 | else: | |
1852 | node = None |
|
1852 | node = None | |
1853 |
|
1853 | |||
1854 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, |
|
1854 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, | |
1855 | head='(?:.*/|)'): |
|
1855 | head='(?:.*/|)'): | |
1856 | if not node and repo.dirstate.state(abs) == '?': |
|
1856 | if not node and repo.dirstate.state(abs) == '?': | |
1857 | continue |
|
1857 | continue | |
1858 | if opts['fullpath']: |
|
1858 | if opts['fullpath']: | |
1859 | ui.write(os.path.join(repo.root, abs), end) |
|
1859 | ui.write(os.path.join(repo.root, abs), end) | |
1860 | else: |
|
1860 | else: | |
1861 | ui.write(((pats and rel) or abs), end) |
|
1861 | ui.write(((pats and rel) or abs), end) | |
1862 |
|
1862 | |||
1863 | def log(ui, repo, *pats, **opts): |
|
1863 | def log(ui, repo, *pats, **opts): | |
1864 | """show revision history of entire repository or files |
|
1864 | """show revision history of entire repository or files | |
1865 |
|
1865 | |||
1866 | Print the revision history of the specified files or the entire project. |
|
1866 | Print the revision history of the specified files or the entire project. | |
1867 |
|
1867 | |||
1868 | By default this command outputs: changeset id and hash, tags, |
|
1868 | By default this command outputs: changeset id and hash, tags, | |
1869 | non-trivial parents, user, date and time, and a summary for each |
|
1869 | non-trivial parents, user, date and time, and a summary for each | |
1870 | commit. When the -v/--verbose switch is used, the list of changed |
|
1870 | commit. When the -v/--verbose switch is used, the list of changed | |
1871 | files and full commit message is shown. |
|
1871 | files and full commit message is shown. | |
1872 | """ |
|
1872 | """ | |
1873 | class dui(object): |
|
1873 | class dui(object): | |
1874 | # Implement and delegate some ui protocol. Save hunks of |
|
1874 | # Implement and delegate some ui protocol. Save hunks of | |
1875 | # output for later display in the desired order. |
|
1875 | # output for later display in the desired order. | |
1876 | def __init__(self, ui): |
|
1876 | def __init__(self, ui): | |
1877 | self.ui = ui |
|
1877 | self.ui = ui | |
1878 | self.hunk = {} |
|
1878 | self.hunk = {} | |
1879 | def bump(self, rev): |
|
1879 | def bump(self, rev): | |
1880 | self.rev = rev |
|
1880 | self.rev = rev | |
1881 | self.hunk[rev] = [] |
|
1881 | self.hunk[rev] = [] | |
1882 | def note(self, *args): |
|
1882 | def note(self, *args): | |
1883 | if self.verbose: |
|
1883 | if self.verbose: | |
1884 | self.write(*args) |
|
1884 | self.write(*args) | |
1885 | def status(self, *args): |
|
1885 | def status(self, *args): | |
1886 | if not self.quiet: |
|
1886 | if not self.quiet: | |
1887 | self.write(*args) |
|
1887 | self.write(*args) | |
1888 | def write(self, *args): |
|
1888 | def write(self, *args): | |
1889 | self.hunk[self.rev].append(args) |
|
1889 | self.hunk[self.rev].append(args) | |
1890 | def debug(self, *args): |
|
1890 | def debug(self, *args): | |
1891 | if self.debugflag: |
|
1891 | if self.debugflag: | |
1892 | self.write(*args) |
|
1892 | self.write(*args) | |
1893 | def __getattr__(self, key): |
|
1893 | def __getattr__(self, key): | |
1894 | return getattr(self.ui, key) |
|
1894 | return getattr(self.ui, key) | |
1895 |
|
1895 | |||
1896 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1896 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | |
1897 |
|
1897 | |||
1898 | if opts['limit']: |
|
1898 | if opts['limit']: | |
1899 | try: |
|
1899 | try: | |
1900 | limit = int(opts['limit']) |
|
1900 | limit = int(opts['limit']) | |
1901 | except ValueError: |
|
1901 | except ValueError: | |
1902 | raise util.Abort(_('limit must be a positive integer')) |
|
1902 | raise util.Abort(_('limit must be a positive integer')) | |
1903 | if limit <= 0: raise util.Abort(_('limit must be positive')) |
|
1903 | if limit <= 0: raise util.Abort(_('limit must be positive')) | |
1904 | else: |
|
1904 | else: | |
1905 | limit = sys.maxint |
|
1905 | limit = sys.maxint | |
1906 | count = 0 |
|
1906 | count = 0 | |
1907 |
|
1907 | |||
1908 | displayer = show_changeset(ui, repo, opts) |
|
1908 | displayer = show_changeset(ui, repo, opts) | |
1909 | for st, rev, fns in changeiter: |
|
1909 | for st, rev, fns in changeiter: | |
1910 | if st == 'window': |
|
1910 | if st == 'window': | |
1911 | du = dui(ui) |
|
1911 | du = dui(ui) | |
1912 | displayer.ui = du |
|
1912 | displayer.ui = du | |
1913 | elif st == 'add': |
|
1913 | elif st == 'add': | |
1914 | du.bump(rev) |
|
1914 | du.bump(rev) | |
1915 | changenode = repo.changelog.node(rev) |
|
1915 | changenode = repo.changelog.node(rev) | |
1916 | parents = [p for p in repo.changelog.parents(changenode) |
|
1916 | parents = [p for p in repo.changelog.parents(changenode) | |
1917 | if p != nullid] |
|
1917 | if p != nullid] | |
1918 | if opts['no_merges'] and len(parents) == 2: |
|
1918 | if opts['no_merges'] and len(parents) == 2: | |
1919 | continue |
|
1919 | continue | |
1920 | if opts['only_merges'] and len(parents) != 2: |
|
1920 | if opts['only_merges'] and len(parents) != 2: | |
1921 | continue |
|
1921 | continue | |
1922 |
|
1922 | |||
1923 | if opts['keyword']: |
|
1923 | if opts['keyword']: | |
1924 | changes = getchange(rev) |
|
1924 | changes = getchange(rev) | |
1925 | miss = 0 |
|
1925 | miss = 0 | |
1926 | for k in [kw.lower() for kw in opts['keyword']]: |
|
1926 | for k in [kw.lower() for kw in opts['keyword']]: | |
1927 | if not (k in changes[1].lower() or |
|
1927 | if not (k in changes[1].lower() or | |
1928 | k in changes[4].lower() or |
|
1928 | k in changes[4].lower() or | |
1929 | k in " ".join(changes[3][:20]).lower()): |
|
1929 | k in " ".join(changes[3][:20]).lower()): | |
1930 | miss = 1 |
|
1930 | miss = 1 | |
1931 | break |
|
1931 | break | |
1932 | if miss: |
|
1932 | if miss: | |
1933 | continue |
|
1933 | continue | |
1934 |
|
1934 | |||
1935 | br = None |
|
1935 | br = None | |
1936 | if opts['branches']: |
|
1936 | if opts['branches']: | |
1937 | br = repo.branchlookup([repo.changelog.node(rev)]) |
|
1937 | br = repo.branchlookup([repo.changelog.node(rev)]) | |
1938 |
|
1938 | |||
1939 | displayer.show(rev, brinfo=br) |
|
1939 | displayer.show(rev, brinfo=br) | |
1940 | if opts['patch']: |
|
1940 | if opts['patch']: | |
1941 | prev = (parents and parents[0]) or nullid |
|
1941 | prev = (parents and parents[0]) or nullid | |
1942 | dodiff(du, du, repo, prev, changenode, match=matchfn) |
|
1942 | dodiff(du, du, repo, prev, changenode, match=matchfn) | |
1943 | du.write("\n\n") |
|
1943 | du.write("\n\n") | |
1944 | elif st == 'iter': |
|
1944 | elif st == 'iter': | |
1945 | if count == limit: break |
|
1945 | if count == limit: break | |
1946 | if du.hunk[rev]: |
|
1946 | if du.hunk[rev]: | |
1947 | count += 1 |
|
1947 | count += 1 | |
1948 | for args in du.hunk[rev]: |
|
1948 | for args in du.hunk[rev]: | |
1949 | ui.write(*args) |
|
1949 | ui.write(*args) | |
1950 |
|
1950 | |||
1951 | def manifest(ui, repo, rev=None): |
|
1951 | def manifest(ui, repo, rev=None): | |
1952 | """output the latest or given revision of the project manifest |
|
1952 | """output the latest or given revision of the project manifest | |
1953 |
|
1953 | |||
1954 | Print a list of version controlled files for the given revision. |
|
1954 | Print a list of version controlled files for the given revision. | |
1955 |
|
1955 | |||
1956 | The manifest is the list of files being version controlled. If no revision |
|
1956 | The manifest is the list of files being version controlled. If no revision | |
1957 | is given then the tip is used. |
|
1957 | is given then the tip is used. | |
1958 | """ |
|
1958 | """ | |
1959 | if rev: |
|
1959 | if rev: | |
1960 | try: |
|
1960 | try: | |
1961 | # assume all revision numbers are for changesets |
|
1961 | # assume all revision numbers are for changesets | |
1962 | n = repo.lookup(rev) |
|
1962 | n = repo.lookup(rev) | |
1963 | change = repo.changelog.read(n) |
|
1963 | change = repo.changelog.read(n) | |
1964 | n = change[0] |
|
1964 | n = change[0] | |
1965 | except hg.RepoError: |
|
1965 | except hg.RepoError: | |
1966 | n = repo.manifest.lookup(rev) |
|
1966 | n = repo.manifest.lookup(rev) | |
1967 | else: |
|
1967 | else: | |
1968 | n = repo.manifest.tip() |
|
1968 | n = repo.manifest.tip() | |
1969 | m = repo.manifest.read(n) |
|
1969 | m = repo.manifest.read(n) | |
1970 | mf = repo.manifest.readflags(n) |
|
1970 | mf = repo.manifest.readflags(n) | |
1971 | files = m.keys() |
|
1971 | files = m.keys() | |
1972 | files.sort() |
|
1972 | files.sort() | |
1973 |
|
1973 | |||
1974 | for f in files: |
|
1974 | for f in files: | |
1975 | ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) |
|
1975 | ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) | |
1976 |
|
1976 | |||
1977 | def outgoing(ui, repo, dest="default-push", **opts): |
|
1977 | def outgoing(ui, repo, dest="default-push", **opts): | |
1978 | """show changesets not found in destination |
|
1978 | """show changesets not found in destination | |
1979 |
|
1979 | |||
1980 | Show changesets not found in the specified destination repo or the |
|
1980 | Show changesets not found in the specified destination repo or the | |
1981 | default push repo. These are the changesets that would be pushed |
|
1981 | default push repo. These are the changesets that would be pushed | |
1982 | if a push was requested. |
|
1982 | if a push was requested. | |
1983 |
|
1983 | |||
1984 | See pull for valid source format details. |
|
1984 | See pull for valid source format details. | |
1985 | """ |
|
1985 | """ | |
1986 | dest = ui.expandpath(dest) |
|
1986 | dest = ui.expandpath(dest) | |
1987 | if opts['ssh']: |
|
1987 | if opts['ssh']: | |
1988 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
1988 | ui.setconfig("ui", "ssh", opts['ssh']) | |
1989 | if opts['remotecmd']: |
|
1989 | if opts['remotecmd']: | |
1990 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
1990 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
1991 |
|
1991 | |||
1992 | other = hg.repository(ui, dest) |
|
1992 | other = hg.repository(ui, dest) | |
1993 | o = repo.findoutgoing(other, force=opts['force']) |
|
1993 | o = repo.findoutgoing(other, force=opts['force']) | |
1994 | o = repo.changelog.nodesbetween(o)[0] |
|
1994 | o = repo.changelog.nodesbetween(o)[0] | |
1995 | if opts['newest_first']: |
|
1995 | if opts['newest_first']: | |
1996 | o.reverse() |
|
1996 | o.reverse() | |
1997 | displayer = show_changeset(ui, repo, opts) |
|
1997 | displayer = show_changeset(ui, repo, opts) | |
1998 | for n in o: |
|
1998 | for n in o: | |
1999 | parents = [p for p in repo.changelog.parents(n) if p != nullid] |
|
1999 | parents = [p for p in repo.changelog.parents(n) if p != nullid] | |
2000 | if opts['no_merges'] and len(parents) == 2: |
|
2000 | if opts['no_merges'] and len(parents) == 2: | |
2001 | continue |
|
2001 | continue | |
2002 | displayer.show(changenode=n) |
|
2002 | displayer.show(changenode=n) | |
2003 | if opts['patch']: |
|
2003 | if opts['patch']: | |
2004 | prev = (parents and parents[0]) or nullid |
|
2004 | prev = (parents and parents[0]) or nullid | |
2005 | dodiff(ui, ui, repo, prev, n) |
|
2005 | dodiff(ui, ui, repo, prev, n) | |
2006 | ui.write("\n") |
|
2006 | ui.write("\n") | |
2007 |
|
2007 | |||
2008 | def parents(ui, repo, rev=None, branches=None, **opts): |
|
2008 | def parents(ui, repo, rev=None, branches=None, **opts): | |
2009 | """show the parents of the working dir or revision |
|
2009 | """show the parents of the working dir or revision | |
2010 |
|
2010 | |||
2011 | Print the working directory's parent revisions. |
|
2011 | Print the working directory's parent revisions. | |
2012 | """ |
|
2012 | """ | |
2013 | if rev: |
|
2013 | if rev: | |
2014 | p = repo.changelog.parents(repo.lookup(rev)) |
|
2014 | p = repo.changelog.parents(repo.lookup(rev)) | |
2015 | else: |
|
2015 | else: | |
2016 | p = repo.dirstate.parents() |
|
2016 | p = repo.dirstate.parents() | |
2017 |
|
2017 | |||
2018 | br = None |
|
2018 | br = None | |
2019 | if branches is not None: |
|
2019 | if branches is not None: | |
2020 | br = repo.branchlookup(p) |
|
2020 | br = repo.branchlookup(p) | |
2021 | displayer = show_changeset(ui, repo, opts) |
|
2021 | displayer = show_changeset(ui, repo, opts) | |
2022 | for n in p: |
|
2022 | for n in p: | |
2023 | if n != nullid: |
|
2023 | if n != nullid: | |
2024 | displayer.show(changenode=n, brinfo=br) |
|
2024 | displayer.show(changenode=n, brinfo=br) | |
2025 |
|
2025 | |||
2026 | def paths(ui, repo, search=None): |
|
2026 | def paths(ui, repo, search=None): | |
2027 | """show definition of symbolic path names |
|
2027 | """show definition of symbolic path names | |
2028 |
|
2028 | |||
2029 | Show definition of symbolic path name NAME. If no name is given, show |
|
2029 | Show definition of symbolic path name NAME. If no name is given, show | |
2030 | definition of available names. |
|
2030 | definition of available names. | |
2031 |
|
2031 | |||
2032 | Path names are defined in the [paths] section of /etc/mercurial/hgrc |
|
2032 | Path names are defined in the [paths] section of /etc/mercurial/hgrc | |
2033 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. |
|
2033 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. | |
2034 | """ |
|
2034 | """ | |
2035 | if search: |
|
2035 | if search: | |
2036 | for name, path in ui.configitems("paths"): |
|
2036 | for name, path in ui.configitems("paths"): | |
2037 | if name == search: |
|
2037 | if name == search: | |
2038 | ui.write("%s\n" % path) |
|
2038 | ui.write("%s\n" % path) | |
2039 | return |
|
2039 | return | |
2040 | ui.warn(_("not found!\n")) |
|
2040 | ui.warn(_("not found!\n")) | |
2041 | return 1 |
|
2041 | return 1 | |
2042 | else: |
|
2042 | else: | |
2043 | for name, path in ui.configitems("paths"): |
|
2043 | for name, path in ui.configitems("paths"): | |
2044 | ui.write("%s = %s\n" % (name, path)) |
|
2044 | ui.write("%s = %s\n" % (name, path)) | |
2045 |
|
2045 | |||
2046 | def pull(ui, repo, source="default", **opts): |
|
2046 | def pull(ui, repo, source="default", **opts): | |
2047 | """pull changes from the specified source |
|
2047 | """pull changes from the specified source | |
2048 |
|
2048 | |||
2049 | Pull changes from a remote repository to a local one. |
|
2049 | Pull changes from a remote repository to a local one. | |
2050 |
|
2050 | |||
2051 | This finds all changes from the repository at the specified path |
|
2051 | This finds all changes from the repository at the specified path | |
2052 | or URL and adds them to the local repository. By default, this |
|
2052 | or URL and adds them to the local repository. By default, this | |
2053 | does not update the copy of the project in the working directory. |
|
2053 | does not update the copy of the project in the working directory. | |
2054 |
|
2054 | |||
2055 | Valid URLs are of the form: |
|
2055 | Valid URLs are of the form: | |
2056 |
|
2056 | |||
2057 | local/filesystem/path |
|
2057 | local/filesystem/path | |
2058 | http://[user@]host[:port][/path] |
|
2058 | http://[user@]host[:port][/path] | |
2059 | https://[user@]host[:port][/path] |
|
2059 | https://[user@]host[:port][/path] | |
2060 | ssh://[user@]host[:port][/path] |
|
2060 | ssh://[user@]host[:port][/path] | |
2061 |
|
2061 | |||
2062 | SSH requires an accessible shell account on the destination machine |
|
2062 | SSH requires an accessible shell account on the destination machine | |
2063 | and a copy of hg in the remote path. With SSH, paths are relative |
|
2063 | and a copy of hg in the remote path. With SSH, paths are relative | |
2064 | to the remote user's home directory by default; use two slashes at |
|
2064 | to the remote user's home directory by default; use two slashes at | |
2065 | the start of a path to specify it as relative to the filesystem root. |
|
2065 | the start of a path to specify it as relative to the filesystem root. | |
2066 | """ |
|
2066 | """ | |
2067 | source = ui.expandpath(source) |
|
2067 | source = ui.expandpath(source) | |
2068 | ui.status(_('pulling from %s\n') % (source)) |
|
2068 | ui.status(_('pulling from %s\n') % (source)) | |
2069 |
|
2069 | |||
2070 | if opts['ssh']: |
|
2070 | if opts['ssh']: | |
2071 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
2071 | ui.setconfig("ui", "ssh", opts['ssh']) | |
2072 | if opts['remotecmd']: |
|
2072 | if opts['remotecmd']: | |
2073 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
2073 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
2074 |
|
2074 | |||
2075 | other = hg.repository(ui, source) |
|
2075 | other = hg.repository(ui, source) | |
2076 | revs = None |
|
2076 | revs = None | |
2077 | if opts['rev'] and not other.local(): |
|
2077 | if opts['rev'] and not other.local(): | |
2078 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) |
|
2078 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) | |
2079 | elif opts['rev']: |
|
2079 | elif opts['rev']: | |
2080 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
2080 | revs = [other.lookup(rev) for rev in opts['rev']] | |
2081 | r = repo.pull(other, heads=revs, force=opts['force']) |
|
2081 | r = repo.pull(other, heads=revs, force=opts['force']) | |
2082 | if not r: |
|
2082 | if not r: | |
2083 | if opts['update']: |
|
2083 | if opts['update']: | |
2084 | return update(ui, repo) |
|
2084 | return update(ui, repo) | |
2085 | else: |
|
2085 | else: | |
2086 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
2086 | ui.status(_("(run 'hg update' to get a working copy)\n")) | |
2087 |
|
2087 | |||
2088 | return r |
|
2088 | return r | |
2089 |
|
2089 | |||
2090 | def push(ui, repo, dest="default-push", **opts): |
|
2090 | def push(ui, repo, dest="default-push", **opts): | |
2091 | """push changes to the specified destination |
|
2091 | """push changes to the specified destination | |
2092 |
|
2092 | |||
2093 | Push changes from the local repository to the given destination. |
|
2093 | Push changes from the local repository to the given destination. | |
2094 |
|
2094 | |||
2095 | This is the symmetrical operation for pull. It helps to move |
|
2095 | This is the symmetrical operation for pull. It helps to move | |
2096 | changes from the current repository to a different one. If the |
|
2096 | changes from the current repository to a different one. If the | |
2097 | destination is local this is identical to a pull in that directory |
|
2097 | destination is local this is identical to a pull in that directory | |
2098 | from the current one. |
|
2098 | from the current one. | |
2099 |
|
2099 | |||
2100 | By default, push will refuse to run if it detects the result would |
|
2100 | By default, push will refuse to run if it detects the result would | |
2101 | increase the number of remote heads. This generally indicates the |
|
2101 | increase the number of remote heads. This generally indicates the | |
2102 | the client has forgotten to sync and merge before pushing. |
|
2102 | the client has forgotten to sync and merge before pushing. | |
2103 |
|
2103 | |||
2104 | Valid URLs are of the form: |
|
2104 | Valid URLs are of the form: | |
2105 |
|
2105 | |||
2106 | local/filesystem/path |
|
2106 | local/filesystem/path | |
2107 | ssh://[user@]host[:port][/path] |
|
2107 | ssh://[user@]host[:port][/path] | |
2108 |
|
2108 | |||
2109 | SSH requires an accessible shell account on the destination |
|
2109 | SSH requires an accessible shell account on the destination | |
2110 | machine and a copy of hg in the remote path. |
|
2110 | machine and a copy of hg in the remote path. | |
2111 | """ |
|
2111 | """ | |
2112 | dest = ui.expandpath(dest) |
|
2112 | dest = ui.expandpath(dest) | |
2113 | ui.status('pushing to %s\n' % (dest)) |
|
2113 | ui.status('pushing to %s\n' % (dest)) | |
2114 |
|
2114 | |||
2115 | if opts['ssh']: |
|
2115 | if opts['ssh']: | |
2116 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
2116 | ui.setconfig("ui", "ssh", opts['ssh']) | |
2117 | if opts['remotecmd']: |
|
2117 | if opts['remotecmd']: | |
2118 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
2118 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
2119 |
|
2119 | |||
2120 | other = hg.repository(ui, dest) |
|
2120 | other = hg.repository(ui, dest) | |
2121 | revs = None |
|
2121 | revs = None | |
2122 | if opts['rev']: |
|
2122 | if opts['rev']: | |
2123 | revs = [repo.lookup(rev) for rev in opts['rev']] |
|
2123 | revs = [repo.lookup(rev) for rev in opts['rev']] | |
2124 | r = repo.push(other, opts['force'], revs=revs) |
|
2124 | r = repo.push(other, opts['force'], revs=revs) | |
2125 | return r |
|
2125 | return r | |
2126 |
|
2126 | |||
2127 | def rawcommit(ui, repo, *flist, **rc): |
|
2127 | def rawcommit(ui, repo, *flist, **rc): | |
2128 | """raw commit interface (DEPRECATED) |
|
2128 | """raw commit interface (DEPRECATED) | |
2129 |
|
2129 | |||
2130 | (DEPRECATED) |
|
2130 | (DEPRECATED) | |
2131 | Lowlevel commit, for use in helper scripts. |
|
2131 | Lowlevel commit, for use in helper scripts. | |
2132 |
|
2132 | |||
2133 | This command is not intended to be used by normal users, as it is |
|
2133 | This command is not intended to be used by normal users, as it is | |
2134 | primarily useful for importing from other SCMs. |
|
2134 | primarily useful for importing from other SCMs. | |
2135 |
|
2135 | |||
2136 | This command is now deprecated and will be removed in a future |
|
2136 | This command is now deprecated and will be removed in a future | |
2137 | release, please use debugsetparents and commit instead. |
|
2137 | release, please use debugsetparents and commit instead. | |
2138 | """ |
|
2138 | """ | |
2139 |
|
2139 | |||
2140 | ui.warn(_("(the rawcommit command is deprecated)\n")) |
|
2140 | ui.warn(_("(the rawcommit command is deprecated)\n")) | |
2141 |
|
2141 | |||
2142 | message = rc['message'] |
|
2142 | message = rc['message'] | |
2143 | if not message and rc['logfile']: |
|
2143 | if not message and rc['logfile']: | |
2144 | try: |
|
2144 | try: | |
2145 | message = open(rc['logfile']).read() |
|
2145 | message = open(rc['logfile']).read() | |
2146 | except IOError: |
|
2146 | except IOError: | |
2147 | pass |
|
2147 | pass | |
2148 | if not message and not rc['logfile']: |
|
2148 | if not message and not rc['logfile']: | |
2149 | raise util.Abort(_("missing commit message")) |
|
2149 | raise util.Abort(_("missing commit message")) | |
2150 |
|
2150 | |||
2151 | files = relpath(repo, list(flist)) |
|
2151 | files = relpath(repo, list(flist)) | |
2152 | if rc['files']: |
|
2152 | if rc['files']: | |
2153 | files += open(rc['files']).read().splitlines() |
|
2153 | files += open(rc['files']).read().splitlines() | |
2154 |
|
2154 | |||
2155 | rc['parent'] = map(repo.lookup, rc['parent']) |
|
2155 | rc['parent'] = map(repo.lookup, rc['parent']) | |
2156 |
|
2156 | |||
2157 | try: |
|
2157 | try: | |
2158 | repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) |
|
2158 | repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) | |
2159 | except ValueError, inst: |
|
2159 | except ValueError, inst: | |
2160 | raise util.Abort(str(inst)) |
|
2160 | raise util.Abort(str(inst)) | |
2161 |
|
2161 | |||
2162 | def recover(ui, repo): |
|
2162 | def recover(ui, repo): | |
2163 | """roll back an interrupted transaction |
|
2163 | """roll back an interrupted transaction | |
2164 |
|
2164 | |||
2165 | Recover from an interrupted commit or pull. |
|
2165 | Recover from an interrupted commit or pull. | |
2166 |
|
2166 | |||
2167 | This command tries to fix the repository status after an interrupted |
|
2167 | This command tries to fix the repository status after an interrupted | |
2168 | operation. It should only be necessary when Mercurial suggests it. |
|
2168 | operation. It should only be necessary when Mercurial suggests it. | |
2169 | """ |
|
2169 | """ | |
2170 | if repo.recover(): |
|
2170 | if repo.recover(): | |
2171 | return repo.verify() |
|
2171 | return repo.verify() | |
2172 | return False |
|
2172 | return False | |
2173 |
|
2173 | |||
2174 | def remove(ui, repo, pat, *pats, **opts): |
|
2174 | def remove(ui, repo, pat, *pats, **opts): | |
2175 | """remove the specified files on the next commit |
|
2175 | """remove the specified files on the next commit | |
2176 |
|
2176 | |||
2177 | Schedule the indicated files for removal from the repository. |
|
2177 | Schedule the indicated files for removal from the repository. | |
2178 |
|
2178 | |||
2179 | This command schedules the files to be removed at the next commit. |
|
2179 | This command schedules the files to be removed at the next commit. | |
2180 | This only removes files from the current branch, not from the |
|
2180 | This only removes files from the current branch, not from the | |
2181 | entire project history. If the files still exist in the working |
|
2181 | entire project history. If the files still exist in the working | |
2182 | directory, they will be deleted from it. |
|
2182 | directory, they will be deleted from it. | |
2183 | """ |
|
2183 | """ | |
2184 | names = [] |
|
2184 | names = [] | |
2185 | def okaytoremove(abs, rel, exact): |
|
2185 | def okaytoremove(abs, rel, exact): | |
2186 | modified, added, removed, deleted, unknown = repo.changes(files=[abs]) |
|
2186 | modified, added, removed, deleted, unknown = repo.changes(files=[abs]) | |
2187 | reason = None |
|
2187 | reason = None | |
2188 | if modified and not opts['force']: |
|
2188 | if modified and not opts['force']: | |
2189 | reason = _('is modified') |
|
2189 | reason = _('is modified') | |
2190 | elif added: |
|
2190 | elif added: | |
2191 | reason = _('has been marked for add') |
|
2191 | reason = _('has been marked for add') | |
2192 | elif unknown: |
|
2192 | elif unknown: | |
2193 | reason = _('is not managed') |
|
2193 | reason = _('is not managed') | |
2194 | if reason: |
|
2194 | if reason: | |
2195 | if exact: |
|
2195 | if exact: | |
2196 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) |
|
2196 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) | |
2197 | else: |
|
2197 | else: | |
2198 | return True |
|
2198 | return True | |
2199 | for src, abs, rel, exact in walk(repo, (pat,) + pats, opts): |
|
2199 | for src, abs, rel, exact in walk(repo, (pat,) + pats, opts): | |
2200 | if okaytoremove(abs, rel, exact): |
|
2200 | if okaytoremove(abs, rel, exact): | |
2201 | if ui.verbose or not exact: |
|
2201 | if ui.verbose or not exact: | |
2202 | ui.status(_('removing %s\n') % rel) |
|
2202 | ui.status(_('removing %s\n') % rel) | |
2203 | names.append(abs) |
|
2203 | names.append(abs) | |
2204 | repo.remove(names, unlink=True) |
|
2204 | repo.remove(names, unlink=True) | |
2205 |
|
2205 | |||
2206 | def rename(ui, repo, *pats, **opts): |
|
2206 | def rename(ui, repo, *pats, **opts): | |
2207 | """rename files; equivalent of copy + remove |
|
2207 | """rename files; equivalent of copy + remove | |
2208 |
|
2208 | |||
2209 | Mark dest as copies of sources; mark sources for deletion. If |
|
2209 | Mark dest as copies of sources; mark sources for deletion. If | |
2210 | dest is a directory, copies are put in that directory. If dest is |
|
2210 | dest is a directory, copies are put in that directory. If dest is | |
2211 | a file, there can only be one source. |
|
2211 | a file, there can only be one source. | |
2212 |
|
2212 | |||
2213 | By default, this command copies the contents of files as they |
|
2213 | By default, this command copies the contents of files as they | |
2214 | stand in the working directory. If invoked with --after, the |
|
2214 | stand in the working directory. If invoked with --after, the | |
2215 | operation is recorded, but no copying is performed. |
|
2215 | operation is recorded, but no copying is performed. | |
2216 |
|
2216 | |||
2217 | This command takes effect in the next commit. |
|
2217 | This command takes effect in the next commit. | |
2218 |
|
2218 | |||
2219 | NOTE: This command should be treated as experimental. While it |
|
2219 | NOTE: This command should be treated as experimental. While it | |
2220 | should properly record rename files, this information is not yet |
|
2220 | should properly record rename files, this information is not yet | |
2221 | fully used by merge, nor fully reported by log. |
|
2221 | fully used by merge, nor fully reported by log. | |
2222 | """ |
|
2222 | """ | |
2223 | try: |
|
2223 | try: | |
2224 | wlock = repo.wlock(0) |
|
2224 | wlock = repo.wlock(0) | |
2225 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
2225 | errs, copied = docopy(ui, repo, pats, opts, wlock) | |
2226 | names = [] |
|
2226 | names = [] | |
2227 | for abs, rel, exact in copied: |
|
2227 | for abs, rel, exact in copied: | |
2228 | if ui.verbose or not exact: |
|
2228 | if ui.verbose or not exact: | |
2229 | ui.status(_('removing %s\n') % rel) |
|
2229 | ui.status(_('removing %s\n') % rel) | |
2230 | names.append(abs) |
|
2230 | names.append(abs) | |
2231 | repo.remove(names, True, wlock) |
|
2231 | repo.remove(names, True, wlock) | |
2232 | except lock.LockHeld, inst: |
|
2232 | except lock.LockHeld, inst: | |
2233 | ui.warn(_("repository lock held by %s\n") % inst.args[0]) |
|
2233 | ui.warn(_("repository lock held by %s\n") % inst.args[0]) | |
2234 | errs = 1 |
|
2234 | errs = 1 | |
2235 | return errs |
|
2235 | return errs | |
2236 |
|
2236 | |||
2237 | def revert(ui, repo, *pats, **opts): |
|
2237 | def revert(ui, repo, *pats, **opts): | |
2238 | """revert modified files or dirs back to their unmodified states |
|
2238 | """revert modified files or dirs back to their unmodified states | |
2239 |
|
2239 | |||
2240 | In its default mode, it reverts any uncommitted modifications made |
|
2240 | In its default mode, it reverts any uncommitted modifications made | |
2241 | to the named files or directories. This restores the contents of |
|
2241 | to the named files or directories. This restores the contents of | |
2242 | the affected files to an unmodified state. |
|
2242 | the affected files to an unmodified state. | |
2243 |
|
2243 | |||
2244 | Using the -r option, it reverts the given files or directories to |
|
2244 | Using the -r option, it reverts the given files or directories to | |
2245 | their state as of an earlier revision. This can be helpful to "roll |
|
2245 | their state as of an earlier revision. This can be helpful to "roll | |
2246 | back" some or all of a change that should not have been committed. |
|
2246 | back" some or all of a change that should not have been committed. | |
2247 |
|
2247 | |||
2248 | Revert modifies the working directory. It does not commit any |
|
2248 | Revert modifies the working directory. It does not commit any | |
2249 | changes, or change the parent of the current working directory. |
|
2249 | changes, or change the parent of the current working directory. | |
2250 |
|
2250 | |||
2251 | If a file has been deleted, it is recreated. If the executable |
|
2251 | If a file has been deleted, it is recreated. If the executable | |
2252 | mode of a file was changed, it is reset. |
|
2252 | mode of a file was changed, it is reset. | |
2253 |
|
2253 | |||
2254 | If names are given, all files matching the names are reverted. |
|
2254 | If names are given, all files matching the names are reverted. | |
2255 |
|
2255 | |||
2256 | If no arguments are given, all files in the repository are reverted. |
|
2256 | If no arguments are given, all files in the repository are reverted. | |
2257 | """ |
|
2257 | """ | |
2258 | node = opts['rev'] and repo.lookup(opts['rev']) or \ |
|
2258 | node = opts['rev'] and repo.lookup(opts['rev']) or \ | |
2259 | repo.dirstate.parents()[0] |
|
2259 | repo.dirstate.parents()[0] | |
2260 |
|
2260 | |||
2261 | files, choose, anypats = matchpats(repo, pats, opts) |
|
2261 | files, choose, anypats = matchpats(repo, pats, opts) | |
2262 | modified, added, removed, deleted, unknown = repo.changes(match=choose) |
|
2262 | modified, added, removed, deleted, unknown = repo.changes(match=choose) | |
2263 | repo.forget(added) |
|
2263 | repo.forget(added) | |
2264 | repo.undelete(removed) |
|
2264 | repo.undelete(removed) | |
2265 |
|
2265 | |||
2266 | return repo.update(node, False, True, choose, False) |
|
2266 | return repo.update(node, False, True, choose, False) | |
2267 |
|
2267 | |||
2268 | def root(ui, repo): |
|
2268 | def root(ui, repo): | |
2269 | """print the root (top) of the current working dir |
|
2269 | """print the root (top) of the current working dir | |
2270 |
|
2270 | |||
2271 | Print the root directory of the current repository. |
|
2271 | Print the root directory of the current repository. | |
2272 | """ |
|
2272 | """ | |
2273 | ui.write(repo.root + "\n") |
|
2273 | ui.write(repo.root + "\n") | |
2274 |
|
2274 | |||
2275 | def serve(ui, repo, **opts): |
|
2275 | def serve(ui, repo, **opts): | |
2276 | """export the repository via HTTP |
|
2276 | """export the repository via HTTP | |
2277 |
|
2277 | |||
2278 | Start a local HTTP repository browser and pull server. |
|
2278 | Start a local HTTP repository browser and pull server. | |
2279 |
|
2279 | |||
2280 | By default, the server logs accesses to stdout and errors to |
|
2280 | By default, the server logs accesses to stdout and errors to | |
2281 | stderr. Use the "-A" and "-E" options to log to files. |
|
2281 | stderr. Use the "-A" and "-E" options to log to files. | |
2282 | """ |
|
2282 | """ | |
2283 |
|
2283 | |||
2284 | if opts["stdio"]: |
|
2284 | if opts["stdio"]: | |
2285 | fin, fout = sys.stdin, sys.stdout |
|
2285 | fin, fout = sys.stdin, sys.stdout | |
2286 | sys.stdout = sys.stderr |
|
2286 | sys.stdout = sys.stderr | |
2287 |
|
2287 | |||
2288 | # Prevent insertion/deletion of CRs |
|
2288 | # Prevent insertion/deletion of CRs | |
2289 | util.set_binary(fin) |
|
2289 | util.set_binary(fin) | |
2290 | util.set_binary(fout) |
|
2290 | util.set_binary(fout) | |
2291 |
|
2291 | |||
2292 | def getarg(): |
|
2292 | def getarg(): | |
2293 | argline = fin.readline()[:-1] |
|
2293 | argline = fin.readline()[:-1] | |
2294 | arg, l = argline.split() |
|
2294 | arg, l = argline.split() | |
2295 | val = fin.read(int(l)) |
|
2295 | val = fin.read(int(l)) | |
2296 | return arg, val |
|
2296 | return arg, val | |
2297 | def respond(v): |
|
2297 | def respond(v): | |
2298 | fout.write("%d\n" % len(v)) |
|
2298 | fout.write("%d\n" % len(v)) | |
2299 | fout.write(v) |
|
2299 | fout.write(v) | |
2300 | fout.flush() |
|
2300 | fout.flush() | |
2301 |
|
2301 | |||
2302 | lock = None |
|
2302 | lock = None | |
2303 |
|
2303 | |||
2304 | while 1: |
|
2304 | while 1: | |
2305 | cmd = fin.readline()[:-1] |
|
2305 | cmd = fin.readline()[:-1] | |
2306 | if cmd == '': |
|
2306 | if cmd == '': | |
2307 | return |
|
2307 | return | |
2308 | if cmd == "heads": |
|
2308 | if cmd == "heads": | |
2309 | h = repo.heads() |
|
2309 | h = repo.heads() | |
2310 | respond(" ".join(map(hex, h)) + "\n") |
|
2310 | respond(" ".join(map(hex, h)) + "\n") | |
2311 | if cmd == "lock": |
|
2311 | if cmd == "lock": | |
2312 | lock = repo.lock() |
|
2312 | lock = repo.lock() | |
2313 | respond("") |
|
2313 | respond("") | |
2314 | if cmd == "unlock": |
|
2314 | if cmd == "unlock": | |
2315 | if lock: |
|
2315 | if lock: | |
2316 | lock.release() |
|
2316 | lock.release() | |
2317 | lock = None |
|
2317 | lock = None | |
2318 | respond("") |
|
2318 | respond("") | |
2319 | elif cmd == "branches": |
|
2319 | elif cmd == "branches": | |
2320 | arg, nodes = getarg() |
|
2320 | arg, nodes = getarg() | |
2321 | nodes = map(bin, nodes.split(" ")) |
|
2321 | nodes = map(bin, nodes.split(" ")) | |
2322 | r = [] |
|
2322 | r = [] | |
2323 | for b in repo.branches(nodes): |
|
2323 | for b in repo.branches(nodes): | |
2324 | r.append(" ".join(map(hex, b)) + "\n") |
|
2324 | r.append(" ".join(map(hex, b)) + "\n") | |
2325 | respond("".join(r)) |
|
2325 | respond("".join(r)) | |
2326 | elif cmd == "between": |
|
2326 | elif cmd == "between": | |
2327 | arg, pairs = getarg() |
|
2327 | arg, pairs = getarg() | |
2328 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] |
|
2328 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] | |
2329 | r = [] |
|
2329 | r = [] | |
2330 | for b in repo.between(pairs): |
|
2330 | for b in repo.between(pairs): | |
2331 | r.append(" ".join(map(hex, b)) + "\n") |
|
2331 | r.append(" ".join(map(hex, b)) + "\n") | |
2332 | respond("".join(r)) |
|
2332 | respond("".join(r)) | |
2333 | elif cmd == "changegroup": |
|
2333 | elif cmd == "changegroup": | |
2334 | nodes = [] |
|
2334 | nodes = [] | |
2335 | arg, roots = getarg() |
|
2335 | arg, roots = getarg() | |
2336 | nodes = map(bin, roots.split(" ")) |
|
2336 | nodes = map(bin, roots.split(" ")) | |
2337 |
|
2337 | |||
2338 | cg = repo.changegroup(nodes, 'serve') |
|
2338 | cg = repo.changegroup(nodes, 'serve') | |
2339 | while 1: |
|
2339 | while 1: | |
2340 | d = cg.read(4096) |
|
2340 | d = cg.read(4096) | |
2341 | if not d: |
|
2341 | if not d: | |
2342 | break |
|
2342 | break | |
2343 | fout.write(d) |
|
2343 | fout.write(d) | |
2344 |
|
2344 | |||
2345 | fout.flush() |
|
2345 | fout.flush() | |
2346 |
|
2346 | |||
2347 | elif cmd == "addchangegroup": |
|
2347 | elif cmd == "addchangegroup": | |
2348 | if not lock: |
|
2348 | if not lock: | |
2349 | respond("not locked") |
|
2349 | respond("not locked") | |
2350 | continue |
|
2350 | continue | |
2351 | respond("") |
|
2351 | respond("") | |
2352 |
|
2352 | |||
2353 | r = repo.addchangegroup(fin) |
|
2353 | r = repo.addchangegroup(fin) | |
2354 | respond("") |
|
2354 | respond("") | |
2355 |
|
2355 | |||
2356 | optlist = "name templates style address port ipv6 accesslog errorlog" |
|
2356 | optlist = "name templates style address port ipv6 accesslog errorlog" | |
2357 | for o in optlist.split(): |
|
2357 | for o in optlist.split(): | |
2358 | if opts[o]: |
|
2358 | if opts[o]: | |
2359 | ui.setconfig("web", o, opts[o]) |
|
2359 | ui.setconfig("web", o, opts[o]) | |
2360 |
|
2360 | |||
2361 | if opts['daemon'] and not opts['daemon_pipefds']: |
|
2361 | if opts['daemon'] and not opts['daemon_pipefds']: | |
2362 | rfd, wfd = os.pipe() |
|
2362 | rfd, wfd = os.pipe() | |
2363 | args = sys.argv[:] |
|
2363 | args = sys.argv[:] | |
2364 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) |
|
2364 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) | |
2365 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), |
|
2365 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), | |
2366 | args[0], args) |
|
2366 | args[0], args) | |
2367 | os.close(wfd) |
|
2367 | os.close(wfd) | |
2368 | os.read(rfd, 1) |
|
2368 | os.read(rfd, 1) | |
2369 | os._exit(0) |
|
2369 | os._exit(0) | |
2370 |
|
2370 | |||
2371 | try: |
|
2371 | try: | |
2372 | httpd = hgweb.create_server(repo) |
|
2372 | httpd = hgweb.create_server(repo) | |
2373 | except socket.error, inst: |
|
2373 | except socket.error, inst: | |
2374 | raise util.Abort(_('cannot start server: ') + inst.args[1]) |
|
2374 | raise util.Abort(_('cannot start server: ') + inst.args[1]) | |
2375 |
|
2375 | |||
2376 | if ui.verbose: |
|
2376 | if ui.verbose: | |
2377 | addr, port = httpd.socket.getsockname() |
|
2377 | addr, port = httpd.socket.getsockname() | |
2378 | if addr == '0.0.0.0': |
|
2378 | if addr == '0.0.0.0': | |
2379 | addr = socket.gethostname() |
|
2379 | addr = socket.gethostname() | |
2380 | else: |
|
2380 | else: | |
2381 | try: |
|
2381 | try: | |
2382 | addr = socket.gethostbyaddr(addr)[0] |
|
2382 | addr = socket.gethostbyaddr(addr)[0] | |
2383 | except socket.error: |
|
2383 | except socket.error: | |
2384 | pass |
|
2384 | pass | |
2385 | if port != 80: |
|
2385 | if port != 80: | |
2386 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) |
|
2386 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) | |
2387 | else: |
|
2387 | else: | |
2388 | ui.status(_('listening at http://%s/\n') % addr) |
|
2388 | ui.status(_('listening at http://%s/\n') % addr) | |
2389 |
|
2389 | |||
2390 | if opts['pid_file']: |
|
2390 | if opts['pid_file']: | |
2391 | fp = open(opts['pid_file'], 'w') |
|
2391 | fp = open(opts['pid_file'], 'w') | |
2392 | fp.write(str(os.getpid())) |
|
2392 | fp.write(str(os.getpid())) | |
2393 | fp.close() |
|
2393 | fp.close() | |
2394 |
|
2394 | |||
2395 | if opts['daemon_pipefds']: |
|
2395 | if opts['daemon_pipefds']: | |
2396 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] |
|
2396 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] | |
2397 | os.close(rfd) |
|
2397 | os.close(rfd) | |
2398 | os.write(wfd, 'y') |
|
2398 | os.write(wfd, 'y') | |
2399 | os.close(wfd) |
|
2399 | os.close(wfd) | |
2400 | sys.stdout.flush() |
|
2400 | sys.stdout.flush() | |
2401 | sys.stderr.flush() |
|
2401 | sys.stderr.flush() | |
2402 | fd = os.open(util.nulldev, os.O_RDWR) |
|
2402 | fd = os.open(util.nulldev, os.O_RDWR) | |
2403 | if fd != 0: os.dup2(fd, 0) |
|
2403 | if fd != 0: os.dup2(fd, 0) | |
2404 | if fd != 1: os.dup2(fd, 1) |
|
2404 | if fd != 1: os.dup2(fd, 1) | |
2405 | if fd != 2: os.dup2(fd, 2) |
|
2405 | if fd != 2: os.dup2(fd, 2) | |
2406 | if fd not in (0, 1, 2): os.close(fd) |
|
2406 | if fd not in (0, 1, 2): os.close(fd) | |
2407 |
|
2407 | |||
2408 | httpd.serve_forever() |
|
2408 | httpd.serve_forever() | |
2409 |
|
2409 | |||
2410 | def status(ui, repo, *pats, **opts): |
|
2410 | def status(ui, repo, *pats, **opts): | |
2411 | """show changed files in the working directory |
|
2411 | """show changed files in the working directory | |
2412 |
|
2412 | |||
2413 | Show changed files in the repository. If names are |
|
2413 | Show changed files in the repository. If names are | |
2414 | given, only files that match are shown. |
|
2414 | given, only files that match are shown. | |
2415 |
|
2415 | |||
2416 | The codes used to show the status of files are: |
|
2416 | The codes used to show the status of files are: | |
2417 | M = modified |
|
2417 | M = modified | |
2418 | A = added |
|
2418 | A = added | |
2419 | R = removed |
|
2419 | R = removed | |
2420 | ! = deleted, but still tracked |
|
2420 | ! = deleted, but still tracked | |
2421 | ? = not tracked |
|
2421 | ? = not tracked | |
2422 | """ |
|
2422 | """ | |
2423 |
|
2423 | |||
2424 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
2424 | files, matchfn, anypats = matchpats(repo, pats, opts) | |
2425 | cwd = (pats and repo.getcwd()) or '' |
|
2425 | cwd = (pats and repo.getcwd()) or '' | |
2426 | modified, added, removed, deleted, unknown = [ |
|
2426 | modified, added, removed, deleted, unknown = [ | |
2427 | [util.pathto(cwd, x) for x in n] |
|
2427 | [util.pathto(cwd, x) for x in n] | |
2428 | for n in repo.changes(files=files, match=matchfn)] |
|
2428 | for n in repo.changes(files=files, match=matchfn)] | |
2429 |
|
2429 | |||
2430 | changetypes = [('modified', 'M', modified), |
|
2430 | changetypes = [('modified', 'M', modified), | |
2431 | ('added', 'A', added), |
|
2431 | ('added', 'A', added), | |
2432 | ('removed', 'R', removed), |
|
2432 | ('removed', 'R', removed), | |
2433 | ('deleted', '!', deleted), |
|
2433 | ('deleted', '!', deleted), | |
2434 | ('unknown', '?', unknown)] |
|
2434 | ('unknown', '?', unknown)] | |
2435 |
|
2435 | |||
2436 | end = opts['print0'] and '\0' or '\n' |
|
2436 | end = opts['print0'] and '\0' or '\n' | |
2437 |
|
2437 | |||
2438 | for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]] |
|
2438 | for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]] | |
2439 | or changetypes): |
|
2439 | or changetypes): | |
2440 | if opts['no_status']: |
|
2440 | if opts['no_status']: | |
2441 | format = "%%s%s" % end |
|
2441 | format = "%%s%s" % end | |
2442 | else: |
|
2442 | else: | |
2443 | format = "%s %%s%s" % (char, end) |
|
2443 | format = "%s %%s%s" % (char, end) | |
2444 |
|
2444 | |||
2445 | for f in changes: |
|
2445 | for f in changes: | |
2446 | ui.write(format % f) |
|
2446 | ui.write(format % f) | |
2447 |
|
2447 | |||
2448 | def tag(ui, repo, name, rev_=None, **opts): |
|
2448 | def tag(ui, repo, name, rev_=None, **opts): | |
2449 | """add a tag for the current tip or a given revision |
|
2449 | """add a tag for the current tip or a given revision | |
2450 |
|
2450 | |||
2451 | Name a particular revision using <name>. |
|
2451 | Name a particular revision using <name>. | |
2452 |
|
2452 | |||
2453 | Tags are used to name particular revisions of the repository and are |
|
2453 | Tags are used to name particular revisions of the repository and are | |
2454 | very useful to compare different revision, to go back to significant |
|
2454 | very useful to compare different revision, to go back to significant | |
2455 | earlier versions or to mark branch points as releases, etc. |
|
2455 | earlier versions or to mark branch points as releases, etc. | |
2456 |
|
2456 | |||
2457 | If no revision is given, the tip is used. |
|
2457 | If no revision is given, the tip is used. | |
2458 |
|
2458 | |||
2459 | To facilitate version control, distribution, and merging of tags, |
|
2459 | To facilitate version control, distribution, and merging of tags, | |
2460 | they are stored as a file named ".hgtags" which is managed |
|
2460 | they are stored as a file named ".hgtags" which is managed | |
2461 | similarly to other project files and can be hand-edited if |
|
2461 | similarly to other project files and can be hand-edited if | |
2462 | necessary. The file '.hg/localtags' is used for local tags (not |
|
2462 | necessary. The file '.hg/localtags' is used for local tags (not | |
2463 | shared among repositories). |
|
2463 | shared among repositories). | |
2464 | """ |
|
2464 | """ | |
2465 | if name == "tip": |
|
2465 | if name == "tip": | |
2466 | raise util.Abort(_("the name 'tip' is reserved")) |
|
2466 | raise util.Abort(_("the name 'tip' is reserved")) | |
2467 | if rev_ is not None: |
|
2467 | if rev_ is not None: | |
2468 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " |
|
2468 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " | |
2469 | "please use 'hg tag [-r REV] NAME' instead\n")) |
|
2469 | "please use 'hg tag [-r REV] NAME' instead\n")) | |
2470 | if opts['rev']: |
|
2470 | if opts['rev']: | |
2471 | raise util.Abort(_("use only one form to specify the revision")) |
|
2471 | raise util.Abort(_("use only one form to specify the revision")) | |
2472 | if opts['rev']: |
|
2472 | if opts['rev']: | |
2473 | rev_ = opts['rev'] |
|
2473 | rev_ = opts['rev'] | |
2474 | if rev_: |
|
2474 | if rev_: | |
2475 | r = hex(repo.lookup(rev_)) |
|
2475 | r = hex(repo.lookup(rev_)) | |
2476 | else: |
|
2476 | else: | |
2477 | r = hex(repo.changelog.tip()) |
|
2477 | r = hex(repo.changelog.tip()) | |
2478 |
|
2478 | |||
2479 | disallowed = (revrangesep, '\r', '\n') |
|
2479 | disallowed = (revrangesep, '\r', '\n') | |
2480 | for c in disallowed: |
|
2480 | for c in disallowed: | |
2481 | if name.find(c) >= 0: |
|
2481 | if name.find(c) >= 0: | |
2482 | raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) |
|
2482 | raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) | |
2483 |
|
2483 | |||
2484 | repo.hook('pretag', throw=True, node=r, tag=name, |
|
2484 | repo.hook('pretag', throw=True, node=r, tag=name, | |
2485 | local=int(not not opts['local'])) |
|
2485 | local=int(not not opts['local'])) | |
2486 |
|
2486 | |||
2487 | if opts['local']: |
|
2487 | if opts['local']: | |
2488 | repo.opener("localtags", "a").write("%s %s\n" % (r, name)) |
|
2488 | repo.opener("localtags", "a").write("%s %s\n" % (r, name)) | |
2489 | repo.hook('tag', node=r, tag=name, local=1) |
|
2489 | repo.hook('tag', node=r, tag=name, local=1) | |
2490 | return |
|
2490 | return | |
2491 |
|
2491 | |||
2492 | for x in repo.changes(): |
|
2492 | for x in repo.changes(): | |
2493 | if ".hgtags" in x: |
|
2493 | if ".hgtags" in x: | |
2494 | raise util.Abort(_("working copy of .hgtags is changed " |
|
2494 | raise util.Abort(_("working copy of .hgtags is changed " | |
2495 | "(please commit .hgtags manually)")) |
|
2495 | "(please commit .hgtags manually)")) | |
2496 |
|
2496 | |||
2497 | repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name)) |
|
2497 | repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name)) | |
2498 | if repo.dirstate.state(".hgtags") == '?': |
|
2498 | if repo.dirstate.state(".hgtags") == '?': | |
2499 | repo.add([".hgtags"]) |
|
2499 | repo.add([".hgtags"]) | |
2500 |
|
2500 | |||
2501 | message = (opts['message'] or |
|
2501 | message = (opts['message'] or | |
2502 | _("Added tag %s for changeset %s") % (name, r)) |
|
2502 | _("Added tag %s for changeset %s") % (name, r)) | |
2503 | try: |
|
2503 | try: | |
2504 | repo.commit([".hgtags"], message, opts['user'], opts['date']) |
|
2504 | repo.commit([".hgtags"], message, opts['user'], opts['date']) | |
2505 | repo.hook('tag', node=r, tag=name, local=0) |
|
2505 | repo.hook('tag', node=r, tag=name, local=0) | |
2506 | except ValueError, inst: |
|
2506 | except ValueError, inst: | |
2507 | raise util.Abort(str(inst)) |
|
2507 | raise util.Abort(str(inst)) | |
2508 |
|
2508 | |||
2509 | def tags(ui, repo): |
|
2509 | def tags(ui, repo): | |
2510 | """list repository tags |
|
2510 | """list repository tags | |
2511 |
|
2511 | |||
2512 | List the repository tags. |
|
2512 | List the repository tags. | |
2513 |
|
2513 | |||
2514 | This lists both regular and local tags. |
|
2514 | This lists both regular and local tags. | |
2515 | """ |
|
2515 | """ | |
2516 |
|
2516 | |||
2517 | l = repo.tagslist() |
|
2517 | l = repo.tagslist() | |
2518 | l.reverse() |
|
2518 | l.reverse() | |
2519 | for t, n in l: |
|
2519 | for t, n in l: | |
2520 | try: |
|
2520 | try: | |
2521 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) |
|
2521 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) | |
2522 | except KeyError: |
|
2522 | except KeyError: | |
2523 | r = " ?:?" |
|
2523 | r = " ?:?" | |
2524 | ui.write("%-30s %s\n" % (t, r)) |
|
2524 | ui.write("%-30s %s\n" % (t, r)) | |
2525 |
|
2525 | |||
2526 | def tip(ui, repo, **opts): |
|
2526 | def tip(ui, repo, **opts): | |
2527 | """show the tip revision |
|
2527 | """show the tip revision | |
2528 |
|
2528 | |||
2529 | Show the tip revision. |
|
2529 | Show the tip revision. | |
2530 | """ |
|
2530 | """ | |
2531 | n = repo.changelog.tip() |
|
2531 | n = repo.changelog.tip() | |
2532 | br = None |
|
2532 | br = None | |
2533 | if opts['branches']: |
|
2533 | if opts['branches']: | |
2534 | br = repo.branchlookup([n]) |
|
2534 | br = repo.branchlookup([n]) | |
2535 | show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) |
|
2535 | show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) | |
2536 | if opts['patch']: |
|
2536 | if opts['patch']: | |
2537 | dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n) |
|
2537 | dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n) | |
2538 |
|
2538 | |||
2539 | def unbundle(ui, repo, fname, **opts): |
|
2539 | def unbundle(ui, repo, fname, **opts): | |
2540 | """apply a changegroup file |
|
2540 | """apply a changegroup file | |
2541 |
|
2541 | |||
2542 | Apply a compressed changegroup file generated by the bundle |
|
2542 | Apply a compressed changegroup file generated by the bundle | |
2543 | command. |
|
2543 | command. | |
2544 | """ |
|
2544 | """ | |
2545 | f = urllib.urlopen(fname) |
|
2545 | f = urllib.urlopen(fname) | |
2546 |
|
2546 | |||
2547 | header = f.read(4) |
|
2547 | header = f.read(4) | |
2548 | if header == "HG10": |
|
2548 | if header == "HG10": | |
2549 | def generator(f): |
|
2549 | def generator(f): | |
2550 | zd = bz2.BZ2Decompressor() |
|
2550 | zd = bz2.BZ2Decompressor() | |
2551 | for chunk in f: |
|
2551 | for chunk in f: | |
2552 | yield zd.decompress(chunk) |
|
2552 | yield zd.decompress(chunk) | |
2553 | elif header == "HG11": |
|
2553 | elif header == "HG11": | |
2554 | def generator(f): |
|
2554 | def generator(f): | |
2555 | for chunk in f: |
|
2555 | for chunk in f: | |
2556 | yield chunk |
|
2556 | yield chunk | |
2557 | else: |
|
2557 | else: | |
2558 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) |
|
2558 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) | |
2559 | gen = generator(util.filechunkiter(f, 4096)) |
|
2559 | gen = generator(util.filechunkiter(f, 4096)) | |
2560 | if repo.addchangegroup(util.chunkbuffer(gen)): |
|
2560 | if repo.addchangegroup(util.chunkbuffer(gen)): | |
2561 | return 1 |
|
2561 | return 1 | |
2562 |
|
2562 | |||
2563 | if opts['update']: |
|
2563 | if opts['update']: | |
2564 | return update(ui, repo) |
|
2564 | return update(ui, repo) | |
2565 | else: |
|
2565 | else: | |
2566 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
2566 | ui.status(_("(run 'hg update' to get a working copy)\n")) | |
2567 |
|
2567 | |||
2568 | def undo(ui, repo): |
|
2568 | def undo(ui, repo): | |
2569 | """undo the last commit or pull |
|
2569 | """undo the last commit or pull | |
2570 |
|
2570 | |||
2571 | Roll back the last pull or commit transaction on the |
|
2571 | Roll back the last pull or commit transaction on the | |
2572 | repository, restoring the project to its earlier state. |
|
2572 | repository, restoring the project to its earlier state. | |
2573 |
|
2573 | |||
2574 | This command should be used with care. There is only one level of |
|
2574 | This command should be used with care. There is only one level of | |
2575 | undo and there is no redo. |
|
2575 | undo and there is no redo. | |
2576 |
|
2576 | |||
2577 | This command is not intended for use on public repositories. Once |
|
2577 | This command is not intended for use on public repositories. Once | |
2578 | a change is visible for pull by other users, undoing it locally is |
|
2578 | a change is visible for pull by other users, undoing it locally is | |
2579 | ineffective. |
|
2579 | ineffective. | |
2580 | """ |
|
2580 | """ | |
2581 | repo.undo() |
|
2581 | repo.undo() | |
2582 |
|
2582 | |||
2583 | def update(ui, repo, node=None, merge=False, clean=False, force=None, |
|
2583 | def update(ui, repo, node=None, merge=False, clean=False, force=None, | |
2584 | branch=None, **opts): |
|
2584 | branch=None, **opts): | |
2585 | """update or merge working directory |
|
2585 | """update or merge working directory | |
2586 |
|
2586 | |||
2587 | Update the working directory to the specified revision. |
|
2587 | Update the working directory to the specified revision. | |
2588 |
|
2588 | |||
2589 | If there are no outstanding changes in the working directory and |
|
2589 | If there are no outstanding changes in the working directory and | |
2590 | there is a linear relationship between the current version and the |
|
2590 | there is a linear relationship between the current version and the | |
2591 | requested version, the result is the requested version. |
|
2591 | requested version, the result is the requested version. | |
2592 |
|
2592 | |||
2593 | Otherwise the result is a merge between the contents of the |
|
2593 | Otherwise the result is a merge between the contents of the | |
2594 | current working directory and the requested version. Files that |
|
2594 | current working directory and the requested version. Files that | |
2595 | changed between either parent are marked as changed for the next |
|
2595 | changed between either parent are marked as changed for the next | |
2596 | commit and a commit must be performed before any further updates |
|
2596 | commit and a commit must be performed before any further updates | |
2597 | are allowed. |
|
2597 | are allowed. | |
2598 |
|
2598 | |||
2599 | By default, update will refuse to run if doing so would require |
|
2599 | By default, update will refuse to run if doing so would require | |
2600 | merging or discarding local changes. |
|
2600 | merging or discarding local changes. | |
2601 | """ |
|
2601 | """ | |
2602 | if branch: |
|
2602 | if branch: | |
2603 | br = repo.branchlookup(branch=branch) |
|
2603 | br = repo.branchlookup(branch=branch) | |
2604 | found = [] |
|
2604 | found = [] | |
2605 | for x in br: |
|
2605 | for x in br: | |
2606 | if branch in br[x]: |
|
2606 | if branch in br[x]: | |
2607 | found.append(x) |
|
2607 | found.append(x) | |
2608 | if len(found) > 1: |
|
2608 | if len(found) > 1: | |
2609 | ui.warn(_("Found multiple heads for %s\n") % branch) |
|
2609 | ui.warn(_("Found multiple heads for %s\n") % branch) | |
2610 | for x in found: |
|
2610 | for x in found: | |
2611 | show_changeset(ui, repo, opts).show(changenode=x, brinfo=br) |
|
2611 | show_changeset(ui, repo, opts).show(changenode=x, brinfo=br) | |
2612 | return 1 |
|
2612 | return 1 | |
2613 | if len(found) == 1: |
|
2613 | if len(found) == 1: | |
2614 | node = found[0] |
|
2614 | node = found[0] | |
2615 | ui.warn(_("Using head %s for branch %s\n") % (short(node), branch)) |
|
2615 | ui.warn(_("Using head %s for branch %s\n") % (short(node), branch)) | |
2616 | else: |
|
2616 | else: | |
2617 | ui.warn(_("branch %s not found\n") % (branch)) |
|
2617 | ui.warn(_("branch %s not found\n") % (branch)) | |
2618 | return 1 |
|
2618 | return 1 | |
2619 | else: |
|
2619 | else: | |
2620 | node = node and repo.lookup(node) or repo.changelog.tip() |
|
2620 | node = node and repo.lookup(node) or repo.changelog.tip() | |
2621 | return repo.update(node, allow=merge, force=clean, forcemerge=force) |
|
2621 | return repo.update(node, allow=merge, force=clean, forcemerge=force) | |
2622 |
|
2622 | |||
2623 | def verify(ui, repo): |
|
2623 | def verify(ui, repo): | |
2624 | """verify the integrity of the repository |
|
2624 | """verify the integrity of the repository | |
2625 |
|
2625 | |||
2626 | Verify the integrity of the current repository. |
|
2626 | Verify the integrity of the current repository. | |
2627 |
|
2627 | |||
2628 | This will perform an extensive check of the repository's |
|
2628 | This will perform an extensive check of the repository's | |
2629 | integrity, validating the hashes and checksums of each entry in |
|
2629 | integrity, validating the hashes and checksums of each entry in | |
2630 | the changelog, manifest, and tracked files, as well as the |
|
2630 | the changelog, manifest, and tracked files, as well as the | |
2631 | integrity of their crosslinks and indices. |
|
2631 | integrity of their crosslinks and indices. | |
2632 | """ |
|
2632 | """ | |
2633 | return repo.verify() |
|
2633 | return repo.verify() | |
2634 |
|
2634 | |||
2635 | # Command options and aliases are listed here, alphabetically |
|
2635 | # Command options and aliases are listed here, alphabetically | |
2636 |
|
2636 | |||
2637 | table = { |
|
2637 | table = { | |
2638 | "^add": |
|
2638 | "^add": | |
2639 | (add, |
|
2639 | (add, | |
2640 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2640 | [('I', 'include', [], _('include names matching the given patterns')), | |
2641 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2641 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2642 | _('hg add [OPTION]... [FILE]...')), |
|
2642 | _('hg add [OPTION]... [FILE]...')), | |
2643 | "addremove": |
|
2643 | "addremove": | |
2644 | (addremove, |
|
2644 | (addremove, | |
2645 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2645 | [('I', 'include', [], _('include names matching the given patterns')), | |
2646 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2646 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2647 | _('hg addremove [OPTION]... [FILE]...')), |
|
2647 | _('hg addremove [OPTION]... [FILE]...')), | |
2648 | "^annotate": |
|
2648 | "^annotate": | |
2649 | (annotate, |
|
2649 | (annotate, | |
2650 | [('r', 'rev', '', _('annotate the specified revision')), |
|
2650 | [('r', 'rev', '', _('annotate the specified revision')), | |
2651 | ('a', 'text', None, _('treat all files as text')), |
|
2651 | ('a', 'text', None, _('treat all files as text')), | |
2652 | ('u', 'user', None, _('list the author')), |
|
2652 | ('u', 'user', None, _('list the author')), | |
2653 | ('d', 'date', None, _('list the date')), |
|
2653 | ('d', 'date', None, _('list the date')), | |
2654 | ('n', 'number', None, _('list the revision number (default)')), |
|
2654 | ('n', 'number', None, _('list the revision number (default)')), | |
2655 | ('c', 'changeset', None, _('list the changeset')), |
|
2655 | ('c', 'changeset', None, _('list the changeset')), | |
2656 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2656 | ('I', 'include', [], _('include names matching the given patterns')), | |
2657 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2657 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2658 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), |
|
2658 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), | |
2659 | "bundle": |
|
2659 | "bundle": | |
2660 | (bundle, |
|
2660 | (bundle, | |
2661 | [('f', 'force', None, |
|
2661 | [('f', 'force', None, | |
2662 | _('run even when remote repository is unrelated'))], |
|
2662 | _('run even when remote repository is unrelated'))], | |
2663 | _('hg bundle FILE DEST')), |
|
2663 | _('hg bundle FILE DEST')), | |
2664 | "cat": |
|
2664 | "cat": | |
2665 | (cat, |
|
2665 | (cat, | |
2666 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2666 | [('o', 'output', '', _('print output to file with formatted name')), | |
2667 | ('r', 'rev', '', _('print the given revision')), |
|
2667 | ('r', 'rev', '', _('print the given revision')), | |
2668 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2668 | ('I', 'include', [], _('include names matching the given patterns')), | |
2669 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2669 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2670 | _('hg cat [OPTION]... FILE...')), |
|
2670 | _('hg cat [OPTION]... FILE...')), | |
2671 | "^clone": |
|
2671 | "^clone": | |
2672 | (clone, |
|
2672 | (clone, | |
2673 | [('U', 'noupdate', None, _('do not update the new working directory')), |
|
2673 | [('U', 'noupdate', None, _('do not update the new working directory')), | |
2674 | ('r', 'rev', [], |
|
2674 | ('r', 'rev', [], | |
2675 | _('a changeset you would like to have after cloning')), |
|
2675 | _('a changeset you would like to have after cloning')), | |
2676 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
2676 | ('', 'pull', None, _('use pull protocol to copy metadata')), | |
2677 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2677 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2678 | ('', 'remotecmd', '', |
|
2678 | ('', 'remotecmd', '', | |
2679 | _('specify hg command to run on the remote side'))], |
|
2679 | _('specify hg command to run on the remote side'))], | |
2680 | _('hg clone [OPTION]... SOURCE [DEST]')), |
|
2680 | _('hg clone [OPTION]... SOURCE [DEST]')), | |
2681 | "^commit|ci": |
|
2681 | "^commit|ci": | |
2682 | (commit, |
|
2682 | (commit, | |
2683 | [('A', 'addremove', None, _('run addremove during commit')), |
|
2683 | [('A', 'addremove', None, _('run addremove during commit')), | |
2684 | ('m', 'message', '', _('use <text> as commit message')), |
|
2684 | ('m', 'message', '', _('use <text> as commit message')), | |
2685 | ('l', 'logfile', '', _('read the commit message from <file>')), |
|
2685 | ('l', 'logfile', '', _('read the commit message from <file>')), | |
2686 | ('d', 'date', '', _('record datecode as commit date')), |
|
2686 | ('d', 'date', '', _('record datecode as commit date')), | |
2687 | ('u', 'user', '', _('record user as commiter')), |
|
2687 | ('u', 'user', '', _('record user as commiter')), | |
2688 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2688 | ('I', 'include', [], _('include names matching the given patterns')), | |
2689 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2689 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2690 | _('hg commit [OPTION]... [FILE]...')), |
|
2690 | _('hg commit [OPTION]... [FILE]...')), | |
2691 | "copy|cp": |
|
2691 | "copy|cp": | |
2692 | (copy, |
|
2692 | (copy, | |
2693 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
2693 | [('A', 'after', None, _('record a copy that has already occurred')), | |
2694 | ('f', 'force', None, |
|
2694 | ('f', 'force', None, | |
2695 | _('forcibly copy over an existing managed file')), |
|
2695 | _('forcibly copy over an existing managed file')), | |
2696 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2696 | ('I', 'include', [], _('include names matching the given patterns')), | |
2697 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2697 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2698 | _('hg copy [OPTION]... [SOURCE]... DEST')), |
|
2698 | _('hg copy [OPTION]... [SOURCE]... DEST')), | |
2699 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), |
|
2699 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), | |
2700 | "debugcomplete": (debugcomplete, [], _('debugcomplete CMD')), |
|
2700 | "debugcomplete": (debugcomplete, [], _('debugcomplete CMD')), | |
2701 | "debugrebuildstate": |
|
2701 | "debugrebuildstate": | |
2702 | (debugrebuildstate, |
|
2702 | (debugrebuildstate, | |
2703 | [('r', 'rev', '', _('revision to rebuild to'))], |
|
2703 | [('r', 'rev', '', _('revision to rebuild to'))], | |
2704 | _('debugrebuildstate [-r REV] [REV]')), |
|
2704 | _('debugrebuildstate [-r REV] [REV]')), | |
2705 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), |
|
2705 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), | |
2706 | "debugconfig": (debugconfig, [], _('debugconfig')), |
|
2706 | "debugconfig": (debugconfig, [], _('debugconfig')), | |
2707 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), |
|
2707 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), | |
2708 | "debugstate": (debugstate, [], _('debugstate')), |
|
2708 | "debugstate": (debugstate, [], _('debugstate')), | |
2709 | "debugdata": (debugdata, [], _('debugdata FILE REV')), |
|
2709 | "debugdata": (debugdata, [], _('debugdata FILE REV')), | |
2710 | "debugindex": (debugindex, [], _('debugindex FILE')), |
|
2710 | "debugindex": (debugindex, [], _('debugindex FILE')), | |
2711 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), |
|
2711 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), | |
2712 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), |
|
2712 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), | |
2713 | "debugwalk": |
|
2713 | "debugwalk": | |
2714 | (debugwalk, |
|
2714 | (debugwalk, | |
2715 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2715 | [('I', 'include', [], _('include names matching the given patterns')), | |
2716 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2716 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2717 | _('debugwalk [OPTION]... [FILE]...')), |
|
2717 | _('debugwalk [OPTION]... [FILE]...')), | |
2718 | "^diff": |
|
2718 | "^diff": | |
2719 | (diff, |
|
2719 | (diff, | |
2720 | [('r', 'rev', [], _('revision')), |
|
2720 | [('r', 'rev', [], _('revision')), | |
2721 | ('a', 'text', None, _('treat all files as text')), |
|
2721 | ('a', 'text', None, _('treat all files as text')), | |
2722 | ('p', 'show-function', None, |
|
2722 | ('p', 'show-function', None, | |
2723 | _('show which function each change is in')), |
|
2723 | _('show which function each change is in')), | |
2724 | ('w', 'ignore-all-space', None, |
|
2724 | ('w', 'ignore-all-space', None, | |
2725 | _('ignore white space when comparing lines')), |
|
2725 | _('ignore white space when comparing lines')), | |
2726 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2726 | ('I', 'include', [], _('include names matching the given patterns')), | |
2727 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2727 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2728 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), |
|
2728 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), | |
2729 | "^export": |
|
2729 | "^export": | |
2730 | (export, |
|
2730 | (export, | |
2731 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2731 | [('o', 'output', '', _('print output to file with formatted name')), | |
2732 | ('a', 'text', None, _('treat all files as text')), |
|
2732 | ('a', 'text', None, _('treat all files as text')), | |
2733 | ('', 'switch-parent', None, _('diff against the second parent'))], |
|
2733 | ('', 'switch-parent', None, _('diff against the second parent'))], | |
2734 | _('hg export [-a] [-o OUTFILESPEC] REV...')), |
|
2734 | _('hg export [-a] [-o OUTFILESPEC] REV...')), | |
2735 | "forget": |
|
2735 | "forget": | |
2736 | (forget, |
|
2736 | (forget, | |
2737 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2737 | [('I', 'include', [], _('include names matching the given patterns')), | |
2738 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2738 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2739 | _('hg forget [OPTION]... FILE...')), |
|
2739 | _('hg forget [OPTION]... FILE...')), | |
2740 | "grep": |
|
2740 | "grep": | |
2741 | (grep, |
|
2741 | (grep, | |
2742 | [('0', 'print0', None, _('end fields with NUL')), |
|
2742 | [('0', 'print0', None, _('end fields with NUL')), | |
2743 | ('', 'all', None, _('print all revisions that match')), |
|
2743 | ('', 'all', None, _('print all revisions that match')), | |
2744 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
2744 | ('i', 'ignore-case', None, _('ignore case when matching')), | |
2745 | ('l', 'files-with-matches', None, |
|
2745 | ('l', 'files-with-matches', None, | |
2746 | _('print only filenames and revs that match')), |
|
2746 | _('print only filenames and revs that match')), | |
2747 | ('n', 'line-number', None, _('print matching line numbers')), |
|
2747 | ('n', 'line-number', None, _('print matching line numbers')), | |
2748 | ('r', 'rev', [], _('search in given revision range')), |
|
2748 | ('r', 'rev', [], _('search in given revision range')), | |
2749 | ('u', 'user', None, _('print user who committed change')), |
|
2749 | ('u', 'user', None, _('print user who committed change')), | |
2750 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2750 | ('I', 'include', [], _('include names matching the given patterns')), | |
2751 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2751 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2752 | _('hg grep [OPTION]... PATTERN [FILE]...')), |
|
2752 | _('hg grep [OPTION]... PATTERN [FILE]...')), | |
2753 | "heads": |
|
2753 | "heads": | |
2754 | (heads, |
|
2754 | (heads, | |
2755 | [('b', 'branches', None, _('show branches')), |
|
2755 | [('b', 'branches', None, _('show branches')), | |
2756 | ('', 'style', '', _('display using template map file')), |
|
2756 | ('', 'style', '', _('display using template map file')), | |
2757 | ('r', 'rev', '', _('show only heads which are descendants of rev')), |
|
2757 | ('r', 'rev', '', _('show only heads which are descendants of rev')), | |
2758 | ('', 'template', '', _('display with template'))], |
|
2758 | ('', 'template', '', _('display with template'))], | |
2759 | _('hg heads [-b] [-r <rev>]')), |
|
2759 | _('hg heads [-b] [-r <rev>]')), | |
2760 | "help": (help_, [], _('hg help [COMMAND]')), |
|
2760 | "help": (help_, [], _('hg help [COMMAND]')), | |
2761 | "identify|id": (identify, [], _('hg identify')), |
|
2761 | "identify|id": (identify, [], _('hg identify')), | |
2762 | "import|patch": |
|
2762 | "import|patch": | |
2763 | (import_, |
|
2763 | (import_, | |
2764 | [('p', 'strip', 1, |
|
2764 | [('p', 'strip', 1, | |
2765 | _('directory strip option for patch. This has the same\n') + |
|
2765 | _('directory strip option for patch. This has the same\n') + | |
2766 | _('meaning as the corresponding patch option')), |
|
2766 | _('meaning as the corresponding patch option')), | |
2767 | ('b', 'base', '', _('base path')), |
|
2767 | ('b', 'base', '', _('base path')), | |
2768 | ('f', 'force', None, |
|
2768 | ('f', 'force', None, | |
2769 | _('skip check for outstanding uncommitted changes'))], |
|
2769 | _('skip check for outstanding uncommitted changes'))], | |
2770 | _('hg import [-p NUM] [-b BASE] [-f] PATCH...')), |
|
2770 | _('hg import [-p NUM] [-b BASE] [-f] PATCH...')), | |
2771 | "incoming|in": (incoming, |
|
2771 | "incoming|in": (incoming, | |
2772 | [('M', 'no-merges', None, _('do not show merges')), |
|
2772 | [('M', 'no-merges', None, _('do not show merges')), | |
2773 | ('f', 'force', None, |
|
2773 | ('f', 'force', None, | |
2774 | _('run even when remote repository is unrelated')), |
|
2774 | _('run even when remote repository is unrelated')), | |
2775 | ('', 'style', '', _('display using template map file')), |
|
2775 | ('', 'style', '', _('display using template map file')), | |
2776 | ('n', 'newest-first', None, _('show newest record first')), |
|
2776 | ('n', 'newest-first', None, _('show newest record first')), | |
2777 | ('', 'bundle', '', _('file to store the bundles into')), |
|
2777 | ('', 'bundle', '', _('file to store the bundles into')), | |
2778 | ('p', 'patch', None, _('show patch')), |
|
2778 | ('p', 'patch', None, _('show patch')), | |
2779 | ('', 'template', '', _('display with template')), |
|
2779 | ('', 'template', '', _('display with template')), | |
2780 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2780 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2781 | ('', 'remotecmd', '', |
|
2781 | ('', 'remotecmd', '', | |
2782 | _('specify hg command to run on the remote side'))], |
|
2782 | _('specify hg command to run on the remote side'))], | |
2783 | _('hg incoming [-p] [-n] [-M] [--bundle FILENAME] [SOURCE]')), |
|
2783 | _('hg incoming [-p] [-n] [-M] [--bundle FILENAME] [SOURCE]')), | |
2784 | "^init": (init, [], _('hg init [DEST]')), |
|
2784 | "^init": (init, [], _('hg init [DEST]')), | |
2785 | "locate": |
|
2785 | "locate": | |
2786 | (locate, |
|
2786 | (locate, | |
2787 | [('r', 'rev', '', _('search the repository as it stood at rev')), |
|
2787 | [('r', 'rev', '', _('search the repository as it stood at rev')), | |
2788 | ('0', 'print0', None, |
|
2788 | ('0', 'print0', None, | |
2789 | _('end filenames with NUL, for use with xargs')), |
|
2789 | _('end filenames with NUL, for use with xargs')), | |
2790 | ('f', 'fullpath', None, |
|
2790 | ('f', 'fullpath', None, | |
2791 | _('print complete paths from the filesystem root')), |
|
2791 | _('print complete paths from the filesystem root')), | |
2792 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2792 | ('I', 'include', [], _('include names matching the given patterns')), | |
2793 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2793 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2794 | _('hg locate [OPTION]... [PATTERN]...')), |
|
2794 | _('hg locate [OPTION]... [PATTERN]...')), | |
2795 | "^log|history": |
|
2795 | "^log|history": | |
2796 | (log, |
|
2796 | (log, | |
2797 | [('b', 'branches', None, _('show branches')), |
|
2797 | [('b', 'branches', None, _('show branches')), | |
2798 | ('k', 'keyword', [], _('search for a keyword')), |
|
2798 | ('k', 'keyword', [], _('search for a keyword')), | |
2799 | ('l', 'limit', '', _('limit number of changes displayed')), |
|
2799 | ('l', 'limit', '', _('limit number of changes displayed')), | |
2800 | ('r', 'rev', [], _('show the specified revision or range')), |
|
2800 | ('r', 'rev', [], _('show the specified revision or range')), | |
2801 | ('M', 'no-merges', None, _('do not show merges')), |
|
2801 | ('M', 'no-merges', None, _('do not show merges')), | |
2802 | ('', 'style', '', _('display using template map file')), |
|
2802 | ('', 'style', '', _('display using template map file')), | |
2803 | ('m', 'only-merges', None, _('show only merges')), |
|
2803 | ('m', 'only-merges', None, _('show only merges')), | |
2804 | ('p', 'patch', None, _('show patch')), |
|
2804 | ('p', 'patch', None, _('show patch')), | |
2805 | ('', 'template', '', _('display with template')), |
|
2805 | ('', 'template', '', _('display with template')), | |
2806 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2806 | ('I', 'include', [], _('include names matching the given patterns')), | |
2807 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2807 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2808 | _('hg log [OPTION]... [FILE]')), |
|
2808 | _('hg log [OPTION]... [FILE]')), | |
2809 | "manifest": (manifest, [], _('hg manifest [REV]')), |
|
2809 | "manifest": (manifest, [], _('hg manifest [REV]')), | |
2810 | "outgoing|out": (outgoing, |
|
2810 | "outgoing|out": (outgoing, | |
2811 | [('M', 'no-merges', None, _('do not show merges')), |
|
2811 | [('M', 'no-merges', None, _('do not show merges')), | |
2812 | ('f', 'force', None, |
|
2812 | ('f', 'force', None, | |
2813 | _('run even when remote repository is unrelated')), |
|
2813 | _('run even when remote repository is unrelated')), | |
2814 | ('p', 'patch', None, _('show patch')), |
|
2814 | ('p', 'patch', None, _('show patch')), | |
2815 | ('', 'style', '', _('display using template map file')), |
|
2815 | ('', 'style', '', _('display using template map file')), | |
2816 | ('n', 'newest-first', None, _('show newest record first')), |
|
2816 | ('n', 'newest-first', None, _('show newest record first')), | |
2817 | ('', 'template', '', _('display with template')), |
|
2817 | ('', 'template', '', _('display with template')), | |
2818 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2818 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2819 | ('', 'remotecmd', '', |
|
2819 | ('', 'remotecmd', '', | |
2820 | _('specify hg command to run on the remote side'))], |
|
2820 | _('specify hg command to run on the remote side'))], | |
2821 | _('hg outgoing [-M] [-p] [-n] [DEST]')), |
|
2821 | _('hg outgoing [-M] [-p] [-n] [DEST]')), | |
2822 | "^parents": |
|
2822 | "^parents": | |
2823 | (parents, |
|
2823 | (parents, | |
2824 | [('b', 'branches', None, _('show branches')), |
|
2824 | [('b', 'branches', None, _('show branches')), | |
2825 | ('', 'style', '', _('display using template map file')), |
|
2825 | ('', 'style', '', _('display using template map file')), | |
2826 | ('', 'template', '', _('display with template'))], |
|
2826 | ('', 'template', '', _('display with template'))], | |
2827 | _('hg parents [-b] [REV]')), |
|
2827 | _('hg parents [-b] [REV]')), | |
2828 | "paths": (paths, [], _('hg paths [NAME]')), |
|
2828 | "paths": (paths, [], _('hg paths [NAME]')), | |
2829 | "^pull": |
|
2829 | "^pull": | |
2830 | (pull, |
|
2830 | (pull, | |
2831 | [('u', 'update', None, |
|
2831 | [('u', 'update', None, | |
2832 | _('update the working directory to tip after pull')), |
|
2832 | _('update the working directory to tip after pull')), | |
2833 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2833 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2834 | ('f', 'force', None, |
|
2834 | ('f', 'force', None, | |
2835 | _('run even when remote repository is unrelated')), |
|
2835 | _('run even when remote repository is unrelated')), | |
2836 | ('r', 'rev', [], _('a specific revision you would like to pull')), |
|
2836 | ('r', 'rev', [], _('a specific revision you would like to pull')), | |
2837 | ('', 'remotecmd', '', |
|
2837 | ('', 'remotecmd', '', | |
2838 | _('specify hg command to run on the remote side'))], |
|
2838 | _('specify hg command to run on the remote side'))], | |
2839 | _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')), |
|
2839 | _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')), | |
2840 | "^push": |
|
2840 | "^push": | |
2841 | (push, |
|
2841 | (push, | |
2842 | [('f', 'force', None, _('force push')), |
|
2842 | [('f', 'force', None, _('force push')), | |
2843 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2843 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2844 | ('r', 'rev', [], _('a specific revision you would like to push')), |
|
2844 | ('r', 'rev', [], _('a specific revision you would like to push')), | |
2845 | ('', 'remotecmd', '', |
|
2845 | ('', 'remotecmd', '', | |
2846 | _('specify hg command to run on the remote side'))], |
|
2846 | _('specify hg command to run on the remote side'))], | |
2847 | _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')), |
|
2847 | _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')), | |
2848 | "debugrawcommit|rawcommit": |
|
2848 | "debugrawcommit|rawcommit": | |
2849 | (rawcommit, |
|
2849 | (rawcommit, | |
2850 | [('p', 'parent', [], _('parent')), |
|
2850 | [('p', 'parent', [], _('parent')), | |
2851 | ('d', 'date', '', _('date code')), |
|
2851 | ('d', 'date', '', _('date code')), | |
2852 | ('u', 'user', '', _('user')), |
|
2852 | ('u', 'user', '', _('user')), | |
2853 | ('F', 'files', '', _('file list')), |
|
2853 | ('F', 'files', '', _('file list')), | |
2854 | ('m', 'message', '', _('commit message')), |
|
2854 | ('m', 'message', '', _('commit message')), | |
2855 | ('l', 'logfile', '', _('commit message file'))], |
|
2855 | ('l', 'logfile', '', _('commit message file'))], | |
2856 | _('hg debugrawcommit [OPTION]... [FILE]...')), |
|
2856 | _('hg debugrawcommit [OPTION]... [FILE]...')), | |
2857 | "recover": (recover, [], _('hg recover')), |
|
2857 | "recover": (recover, [], _('hg recover')), | |
2858 | "^remove|rm": |
|
2858 | "^remove|rm": | |
2859 | (remove, |
|
2859 | (remove, | |
2860 | [('f', 'force', None, _('remove file even if modified')), |
|
2860 | [('f', 'force', None, _('remove file even if modified')), | |
2861 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2861 | ('I', 'include', [], _('include names matching the given patterns')), | |
2862 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2862 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2863 | _('hg remove [OPTION]... FILE...')), |
|
2863 | _('hg remove [OPTION]... FILE...')), | |
2864 | "rename|mv": |
|
2864 | "rename|mv": | |
2865 | (rename, |
|
2865 | (rename, | |
2866 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
2866 | [('A', 'after', None, _('record a rename that has already occurred')), | |
2867 | ('f', 'force', None, |
|
2867 | ('f', 'force', None, | |
2868 | _('forcibly copy over an existing managed file')), |
|
2868 | _('forcibly copy over an existing managed file')), | |
2869 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2869 | ('I', 'include', [], _('include names matching the given patterns')), | |
2870 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2870 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2871 | _('hg rename [OPTION]... SOURCE... DEST')), |
|
2871 | _('hg rename [OPTION]... SOURCE... DEST')), | |
2872 | "^revert": |
|
2872 | "^revert": | |
2873 | (revert, |
|
2873 | (revert, | |
2874 | [('r', 'rev', '', _('revision to revert to')), |
|
2874 | [('r', 'rev', '', _('revision to revert to')), | |
2875 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2875 | ('I', 'include', [], _('include names matching the given patterns')), | |
2876 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2876 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2877 | _('hg revert [-r REV] [NAME]...')), |
|
2877 | _('hg revert [-r REV] [NAME]...')), | |
2878 | "root": (root, [], _('hg root')), |
|
2878 | "root": (root, [], _('hg root')), | |
2879 | "^serve": |
|
2879 | "^serve": | |
2880 | (serve, |
|
2880 | (serve, | |
2881 | [('A', 'accesslog', '', _('name of access log file to write to')), |
|
2881 | [('A', 'accesslog', '', _('name of access log file to write to')), | |
2882 | ('d', 'daemon', None, _('run server in background')), |
|
2882 | ('d', 'daemon', None, _('run server in background')), | |
2883 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
2883 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | |
2884 | ('E', 'errorlog', '', _('name of error log file to write to')), |
|
2884 | ('E', 'errorlog', '', _('name of error log file to write to')), | |
2885 | ('p', 'port', 0, _('port to use (default: 8000)')), |
|
2885 | ('p', 'port', 0, _('port to use (default: 8000)')), | |
2886 | ('a', 'address', '', _('address to use')), |
|
2886 | ('a', 'address', '', _('address to use')), | |
2887 | ('n', 'name', '', |
|
2887 | ('n', 'name', '', | |
2888 | _('name to show in web pages (default: working dir)')), |
|
2888 | _('name to show in web pages (default: working dir)')), | |
2889 | ('', 'pid-file', '', _('name of file to write process ID to')), |
|
2889 | ('', 'pid-file', '', _('name of file to write process ID to')), | |
2890 | ('', 'stdio', None, _('for remote clients')), |
|
2890 | ('', 'stdio', None, _('for remote clients')), | |
2891 | ('t', 'templates', '', _('web templates to use')), |
|
2891 | ('t', 'templates', '', _('web templates to use')), | |
2892 | ('', 'style', '', _('template style to use')), |
|
2892 | ('', 'style', '', _('template style to use')), | |
2893 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], |
|
2893 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], | |
2894 | _('hg serve [OPTION]...')), |
|
2894 | _('hg serve [OPTION]...')), | |
2895 | "^status|st": |
|
2895 | "^status|st": | |
2896 | (status, |
|
2896 | (status, | |
2897 | [('m', 'modified', None, _('show only modified files')), |
|
2897 | [('m', 'modified', None, _('show only modified files')), | |
2898 | ('a', 'added', None, _('show only added files')), |
|
2898 | ('a', 'added', None, _('show only added files')), | |
2899 | ('r', 'removed', None, _('show only removed files')), |
|
2899 | ('r', 'removed', None, _('show only removed files')), | |
2900 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
2900 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), | |
2901 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
2901 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), | |
2902 | ('n', 'no-status', None, _('hide status prefix')), |
|
2902 | ('n', 'no-status', None, _('hide status prefix')), | |
2903 | ('0', 'print0', None, |
|
2903 | ('0', 'print0', None, | |
2904 | _('end filenames with NUL, for use with xargs')), |
|
2904 | _('end filenames with NUL, for use with xargs')), | |
2905 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2905 | ('I', 'include', [], _('include names matching the given patterns')), | |
2906 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2906 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2907 | _('hg status [OPTION]... [FILE]...')), |
|
2907 | _('hg status [OPTION]... [FILE]...')), | |
2908 | "tag": |
|
2908 | "tag": | |
2909 | (tag, |
|
2909 | (tag, | |
2910 | [('l', 'local', None, _('make the tag local')), |
|
2910 | [('l', 'local', None, _('make the tag local')), | |
2911 | ('m', 'message', '', _('message for tag commit log entry')), |
|
2911 | ('m', 'message', '', _('message for tag commit log entry')), | |
2912 | ('d', 'date', '', _('record datecode as commit date')), |
|
2912 | ('d', 'date', '', _('record datecode as commit date')), | |
2913 | ('u', 'user', '', _('record user as commiter')), |
|
2913 | ('u', 'user', '', _('record user as commiter')), | |
2914 | ('r', 'rev', '', _('revision to tag'))], |
|
2914 | ('r', 'rev', '', _('revision to tag'))], | |
2915 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), |
|
2915 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), | |
2916 | "tags": (tags, [], _('hg tags')), |
|
2916 | "tags": (tags, [], _('hg tags')), | |
2917 | "tip": |
|
2917 | "tip": | |
2918 | (tip, |
|
2918 | (tip, | |
2919 | [('b', 'branches', None, _('show branches')), |
|
2919 | [('b', 'branches', None, _('show branches')), | |
2920 | ('', 'style', '', _('display using template map file')), |
|
2920 | ('', 'style', '', _('display using template map file')), | |
2921 | ('p', 'patch', None, _('show patch')), |
|
2921 | ('p', 'patch', None, _('show patch')), | |
2922 | ('', 'template', '', _('display with template'))], |
|
2922 | ('', 'template', '', _('display with template'))], | |
2923 | _('hg tip [-b] [-p]')), |
|
2923 | _('hg tip [-b] [-p]')), | |
2924 | "unbundle": |
|
2924 | "unbundle": | |
2925 | (unbundle, |
|
2925 | (unbundle, | |
2926 | [('u', 'update', None, |
|
2926 | [('u', 'update', None, | |
2927 | _('update the working directory to tip after unbundle'))], |
|
2927 | _('update the working directory to tip after unbundle'))], | |
2928 | _('hg unbundle [-u] FILE')), |
|
2928 | _('hg unbundle [-u] FILE')), | |
2929 | "undo": (undo, [], _('hg undo')), |
|
2929 | "undo": (undo, [], _('hg undo')), | |
2930 | "^update|up|checkout|co": |
|
2930 | "^update|up|checkout|co": | |
2931 | (update, |
|
2931 | (update, | |
2932 | [('b', 'branch', '', _('checkout the head of a specific branch')), |
|
2932 | [('b', 'branch', '', _('checkout the head of a specific branch')), | |
2933 | ('', 'style', '', _('display using template map file')), |
|
2933 | ('', 'style', '', _('display using template map file')), | |
2934 | ('m', 'merge', None, _('allow merging of branches')), |
|
2934 | ('m', 'merge', None, _('allow merging of branches')), | |
2935 | ('C', 'clean', None, _('overwrite locally modified files')), |
|
2935 | ('C', 'clean', None, _('overwrite locally modified files')), | |
2936 | ('f', 'force', None, _('force a merge with outstanding changes')), |
|
2936 | ('f', 'force', None, _('force a merge with outstanding changes')), | |
2937 | ('', 'template', '', _('display with template'))], |
|
2937 | ('', 'template', '', _('display with template'))], | |
2938 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), |
|
2938 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), | |
2939 | "verify": (verify, [], _('hg verify')), |
|
2939 | "verify": (verify, [], _('hg verify')), | |
2940 | "version": (show_version, [], _('hg version')), |
|
2940 | "version": (show_version, [], _('hg version')), | |
2941 | } |
|
2941 | } | |
2942 |
|
2942 | |||
2943 | globalopts = [ |
|
2943 | globalopts = [ | |
2944 | ('R', 'repository', '', |
|
2944 | ('R', 'repository', '', | |
2945 | _('repository root directory or symbolic path name')), |
|
2945 | _('repository root directory or symbolic path name')), | |
2946 | ('', 'cwd', '', _('change working directory')), |
|
2946 | ('', 'cwd', '', _('change working directory')), | |
2947 | ('y', 'noninteractive', None, |
|
2947 | ('y', 'noninteractive', None, | |
2948 | _('do not prompt, assume \'yes\' for any required answers')), |
|
2948 | _('do not prompt, assume \'yes\' for any required answers')), | |
2949 | ('q', 'quiet', None, _('suppress output')), |
|
2949 | ('q', 'quiet', None, _('suppress output')), | |
2950 | ('v', 'verbose', None, _('enable additional output')), |
|
2950 | ('v', 'verbose', None, _('enable additional output')), | |
2951 | ('', 'debug', None, _('enable debugging output')), |
|
2951 | ('', 'debug', None, _('enable debugging output')), | |
2952 | ('', 'debugger', None, _('start debugger')), |
|
2952 | ('', 'debugger', None, _('start debugger')), | |
2953 | ('', 'traceback', None, _('print traceback on exception')), |
|
2953 | ('', 'traceback', None, _('print traceback on exception')), | |
2954 | ('', 'time', None, _('time how long the command takes')), |
|
2954 | ('', 'time', None, _('time how long the command takes')), | |
2955 | ('', 'profile', None, _('print command execution profile')), |
|
2955 | ('', 'profile', None, _('print command execution profile')), | |
2956 | ('', 'version', None, _('output version information and exit')), |
|
2956 | ('', 'version', None, _('output version information and exit')), | |
2957 | ('h', 'help', None, _('display help and exit')), |
|
2957 | ('h', 'help', None, _('display help and exit')), | |
2958 | ] |
|
2958 | ] | |
2959 |
|
2959 | |||
2960 | norepo = ("clone init version help debugancestor debugcomplete debugdata" |
|
2960 | norepo = ("clone init version help debugancestor debugcomplete debugdata" | |
2961 | " debugindex debugindexdot") |
|
2961 | " debugindex debugindexdot") | |
2962 | optionalrepo = ("paths debugconfig") |
|
2962 | optionalrepo = ("paths debugconfig") | |
2963 |
|
2963 | |||
2964 | def findpossible(cmd): |
|
2964 | def findpossible(cmd): | |
2965 | """ |
|
2965 | """ | |
2966 | Return cmd -> (aliases, command table entry) |
|
2966 | Return cmd -> (aliases, command table entry) | |
2967 | for each matching command |
|
2967 | for each matching command | |
2968 | """ |
|
2968 | """ | |
2969 | choice = {} |
|
2969 | choice = {} | |
2970 | debugchoice = {} |
|
2970 | debugchoice = {} | |
2971 | for e in table.keys(): |
|
2971 | for e in table.keys(): | |
2972 | aliases = e.lstrip("^").split("|") |
|
2972 | aliases = e.lstrip("^").split("|") | |
2973 | if cmd in aliases: |
|
2973 | if cmd in aliases: | |
2974 | choice[cmd] = (aliases, table[e]) |
|
2974 | choice[cmd] = (aliases, table[e]) | |
2975 | continue |
|
2975 | continue | |
2976 | for a in aliases: |
|
2976 | for a in aliases: | |
2977 | if a.startswith(cmd): |
|
2977 | if a.startswith(cmd): | |
2978 | if aliases[0].startswith("debug"): |
|
2978 | if aliases[0].startswith("debug"): | |
2979 | debugchoice[a] = (aliases, table[e]) |
|
2979 | debugchoice[a] = (aliases, table[e]) | |
2980 | else: |
|
2980 | else: | |
2981 | choice[a] = (aliases, table[e]) |
|
2981 | choice[a] = (aliases, table[e]) | |
2982 | break |
|
2982 | break | |
2983 |
|
2983 | |||
2984 | if not choice and debugchoice: |
|
2984 | if not choice and debugchoice: | |
2985 | choice = debugchoice |
|
2985 | choice = debugchoice | |
2986 |
|
2986 | |||
2987 | return choice |
|
2987 | return choice | |
2988 |
|
2988 | |||
2989 | def find(cmd): |
|
2989 | def find(cmd): | |
2990 | """Return (aliases, command table entry) for command string.""" |
|
2990 | """Return (aliases, command table entry) for command string.""" | |
2991 | choice = findpossible(cmd) |
|
2991 | choice = findpossible(cmd) | |
2992 |
|
2992 | |||
2993 | if choice.has_key(cmd): |
|
2993 | if choice.has_key(cmd): | |
2994 | return choice[cmd] |
|
2994 | return choice[cmd] | |
2995 |
|
2995 | |||
2996 | if len(choice) > 1: |
|
2996 | if len(choice) > 1: | |
2997 | clist = choice.keys() |
|
2997 | clist = choice.keys() | |
2998 | clist.sort() |
|
2998 | clist.sort() | |
2999 | raise AmbiguousCommand(cmd, clist) |
|
2999 | raise AmbiguousCommand(cmd, clist) | |
3000 |
|
3000 | |||
3001 | if choice: |
|
3001 | if choice: | |
3002 | return choice.values()[0] |
|
3002 | return choice.values()[0] | |
3003 |
|
3003 | |||
3004 | raise UnknownCommand(cmd) |
|
3004 | raise UnknownCommand(cmd) | |
3005 |
|
3005 | |||
3006 | class SignalInterrupt(Exception): |
|
3006 | class SignalInterrupt(Exception): | |
3007 | """Exception raised on SIGTERM and SIGHUP.""" |
|
3007 | """Exception raised on SIGTERM and SIGHUP.""" | |
3008 |
|
3008 | |||
3009 | def catchterm(*args): |
|
3009 | def catchterm(*args): | |
3010 | raise SignalInterrupt |
|
3010 | raise SignalInterrupt | |
3011 |
|
3011 | |||
3012 | def run(): |
|
3012 | def run(): | |
3013 | sys.exit(dispatch(sys.argv[1:])) |
|
3013 | sys.exit(dispatch(sys.argv[1:])) | |
3014 |
|
3014 | |||
3015 | class ParseError(Exception): |
|
3015 | class ParseError(Exception): | |
3016 | """Exception raised on errors in parsing the command line.""" |
|
3016 | """Exception raised on errors in parsing the command line.""" | |
3017 |
|
3017 | |||
3018 | def parse(ui, args): |
|
3018 | def parse(ui, args): | |
3019 | options = {} |
|
3019 | options = {} | |
3020 | cmdoptions = {} |
|
3020 | cmdoptions = {} | |
3021 |
|
3021 | |||
3022 | try: |
|
3022 | try: | |
3023 | args = fancyopts.fancyopts(args, globalopts, options) |
|
3023 | args = fancyopts.fancyopts(args, globalopts, options) | |
3024 | except fancyopts.getopt.GetoptError, inst: |
|
3024 | except fancyopts.getopt.GetoptError, inst: | |
3025 | raise ParseError(None, inst) |
|
3025 | raise ParseError(None, inst) | |
3026 |
|
3026 | |||
3027 | if args: |
|
3027 | if args: | |
3028 | cmd, args = args[0], args[1:] |
|
3028 | cmd, args = args[0], args[1:] | |
3029 | aliases, i = find(cmd) |
|
3029 | aliases, i = find(cmd) | |
3030 | cmd = aliases[0] |
|
3030 | cmd = aliases[0] | |
3031 | defaults = ui.config("defaults", cmd) |
|
3031 | defaults = ui.config("defaults", cmd) | |
3032 | if defaults: |
|
3032 | if defaults: | |
3033 | args = defaults.split() + args |
|
3033 | args = defaults.split() + args | |
3034 | c = list(i[1]) |
|
3034 | c = list(i[1]) | |
3035 | else: |
|
3035 | else: | |
3036 | cmd = None |
|
3036 | cmd = None | |
3037 | c = [] |
|
3037 | c = [] | |
3038 |
|
3038 | |||
3039 | # combine global options into local |
|
3039 | # combine global options into local | |
3040 | for o in globalopts: |
|
3040 | for o in globalopts: | |
3041 | c.append((o[0], o[1], options[o[1]], o[3])) |
|
3041 | c.append((o[0], o[1], options[o[1]], o[3])) | |
3042 |
|
3042 | |||
3043 | try: |
|
3043 | try: | |
3044 | args = fancyopts.fancyopts(args, c, cmdoptions) |
|
3044 | args = fancyopts.fancyopts(args, c, cmdoptions) | |
3045 | except fancyopts.getopt.GetoptError, inst: |
|
3045 | except fancyopts.getopt.GetoptError, inst: | |
3046 | raise ParseError(cmd, inst) |
|
3046 | raise ParseError(cmd, inst) | |
3047 |
|
3047 | |||
3048 | # separate global options back out |
|
3048 | # separate global options back out | |
3049 | for o in globalopts: |
|
3049 | for o in globalopts: | |
3050 | n = o[1] |
|
3050 | n = o[1] | |
3051 | options[n] = cmdoptions[n] |
|
3051 | options[n] = cmdoptions[n] | |
3052 | del cmdoptions[n] |
|
3052 | del cmdoptions[n] | |
3053 |
|
3053 | |||
3054 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) |
|
3054 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) | |
3055 |
|
3055 | |||
3056 | def dispatch(args): |
|
3056 | def dispatch(args): | |
3057 | signal.signal(signal.SIGTERM, catchterm) |
|
3057 | signal.signal(signal.SIGTERM, catchterm) | |
3058 | try: |
|
3058 | try: | |
3059 | signal.signal(signal.SIGHUP, catchterm) |
|
3059 | signal.signal(signal.SIGHUP, catchterm) | |
3060 | except AttributeError: |
|
3060 | except AttributeError: | |
3061 | pass |
|
3061 | pass | |
3062 |
|
3062 | |||
3063 | try: |
|
3063 | try: | |
3064 | u = ui.ui() |
|
3064 | u = ui.ui() | |
3065 | except util.Abort, inst: |
|
3065 | except util.Abort, inst: | |
3066 | sys.stderr.write(_("abort: %s\n") % inst) |
|
3066 | sys.stderr.write(_("abort: %s\n") % inst) | |
3067 | sys.exit(1) |
|
3067 | sys.exit(1) | |
3068 |
|
3068 | |||
3069 | external = [] |
|
3069 | external = [] | |
3070 | for x in u.extensions(): |
|
3070 | for x in u.extensions(): | |
3071 | def on_exception(exc, inst): |
|
3071 | def on_exception(exc, inst): | |
3072 | u.warn(_("*** failed to import extension %s\n") % x[1]) |
|
3072 | u.warn(_("*** failed to import extension %s\n") % x[1]) | |
3073 | u.warn("%s\n" % inst) |
|
3073 | u.warn("%s\n" % inst) | |
3074 | if "--traceback" in sys.argv[1:]: |
|
3074 | if "--traceback" in sys.argv[1:]: | |
3075 | traceback.print_exc() |
|
3075 | traceback.print_exc() | |
3076 | if x[1]: |
|
3076 | if x[1]: | |
3077 | try: |
|
3077 | try: | |
3078 | mod = imp.load_source(x[0], x[1]) |
|
3078 | mod = imp.load_source(x[0], x[1]) | |
3079 | except Exception, inst: |
|
3079 | except Exception, inst: | |
3080 | on_exception(Exception, inst) |
|
3080 | on_exception(Exception, inst) | |
3081 | continue |
|
3081 | continue | |
3082 | else: |
|
3082 | else: | |
3083 | def importh(name): |
|
3083 | def importh(name): | |
3084 | mod = __import__(name) |
|
3084 | mod = __import__(name) | |
3085 | components = name.split('.') |
|
3085 | components = name.split('.') | |
3086 | for comp in components[1:]: |
|
3086 | for comp in components[1:]: | |
3087 | mod = getattr(mod, comp) |
|
3087 | mod = getattr(mod, comp) | |
3088 | return mod |
|
3088 | return mod | |
3089 | try: |
|
3089 | try: | |
3090 | try: |
|
3090 | try: | |
3091 | mod = importh("hgext." + x[0]) |
|
3091 | mod = importh("hgext." + x[0]) | |
3092 | except ImportError: |
|
3092 | except ImportError: | |
3093 | mod = importh(x[0]) |
|
3093 | mod = importh(x[0]) | |
3094 | except Exception, inst: |
|
3094 | except Exception, inst: | |
3095 | on_exception(Exception, inst) |
|
3095 | on_exception(Exception, inst) | |
3096 | continue |
|
3096 | continue | |
3097 |
|
3097 | |||
3098 | external.append(mod) |
|
3098 | external.append(mod) | |
3099 | for x in external: |
|
3099 | for x in external: | |
3100 | cmdtable = getattr(x, 'cmdtable', {}) |
|
3100 | cmdtable = getattr(x, 'cmdtable', {}) | |
3101 | for t in cmdtable: |
|
3101 | for t in cmdtable: | |
3102 | if t in table: |
|
3102 | if t in table: | |
3103 | u.warn(_("module %s overrides %s\n") % (x.__name__, t)) |
|
3103 | u.warn(_("module %s overrides %s\n") % (x.__name__, t)) | |
3104 | table.update(cmdtable) |
|
3104 | table.update(cmdtable) | |
3105 |
|
3105 | |||
3106 | try: |
|
3106 | try: | |
3107 | cmd, func, args, options, cmdoptions = parse(u, args) |
|
3107 | cmd, func, args, options, cmdoptions = parse(u, args) | |
3108 | if options["time"]: |
|
3108 | if options["time"]: | |
3109 | def get_times(): |
|
3109 | def get_times(): | |
3110 | t = os.times() |
|
3110 | t = os.times() | |
3111 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() |
|
3111 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() | |
3112 | t = (t[0], t[1], t[2], t[3], time.clock()) |
|
3112 | t = (t[0], t[1], t[2], t[3], time.clock()) | |
3113 | return t |
|
3113 | return t | |
3114 | s = get_times() |
|
3114 | s = get_times() | |
3115 | def print_time(): |
|
3115 | def print_time(): | |
3116 | t = get_times() |
|
3116 | t = get_times() | |
3117 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % |
|
3117 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % | |
3118 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) |
|
3118 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) | |
3119 | atexit.register(print_time) |
|
3119 | atexit.register(print_time) | |
3120 |
|
3120 | |||
3121 | u.updateopts(options["verbose"], options["debug"], options["quiet"], |
|
3121 | u.updateopts(options["verbose"], options["debug"], options["quiet"], | |
3122 | not options["noninteractive"]) |
|
3122 | not options["noninteractive"]) | |
3123 |
|
3123 | |||
3124 | # enter the debugger before command execution |
|
3124 | # enter the debugger before command execution | |
3125 | if options['debugger']: |
|
3125 | if options['debugger']: | |
3126 | pdb.set_trace() |
|
3126 | pdb.set_trace() | |
3127 |
|
3127 | |||
3128 | try: |
|
3128 | try: | |
3129 | if options['cwd']: |
|
3129 | if options['cwd']: | |
3130 | try: |
|
3130 | try: | |
3131 | os.chdir(options['cwd']) |
|
3131 | os.chdir(options['cwd']) | |
3132 | except OSError, inst: |
|
3132 | except OSError, inst: | |
3133 | raise util.Abort('%s: %s' % |
|
3133 | raise util.Abort('%s: %s' % | |
3134 | (options['cwd'], inst.strerror)) |
|
3134 | (options['cwd'], inst.strerror)) | |
3135 |
|
3135 | |||
3136 | path = u.expandpath(options["repository"]) or "" |
|
3136 | path = u.expandpath(options["repository"]) or "" | |
3137 | repo = path and hg.repository(u, path=path) or None |
|
3137 | repo = path and hg.repository(u, path=path) or None | |
3138 |
|
3138 | |||
3139 | if options['help']: |
|
3139 | if options['help']: | |
3140 | help_(u, cmd, options['version']) |
|
3140 | help_(u, cmd, options['version']) | |
3141 | sys.exit(0) |
|
3141 | sys.exit(0) | |
3142 | elif options['version']: |
|
3142 | elif options['version']: | |
3143 | show_version(u) |
|
3143 | show_version(u) | |
3144 | sys.exit(0) |
|
3144 | sys.exit(0) | |
3145 | elif not cmd: |
|
3145 | elif not cmd: | |
3146 | help_(u, 'shortlist') |
|
3146 | help_(u, 'shortlist') | |
3147 | sys.exit(0) |
|
3147 | sys.exit(0) | |
3148 |
|
3148 | |||
3149 | if cmd not in norepo.split(): |
|
3149 | if cmd not in norepo.split(): | |
3150 | try: |
|
3150 | try: | |
3151 | if not repo: |
|
3151 | if not repo: | |
3152 | repo = hg.repository(u, path=path) |
|
3152 | repo = hg.repository(u, path=path) | |
3153 | u = repo.ui |
|
3153 | u = repo.ui | |
3154 | for x in external: |
|
3154 | for x in external: | |
3155 | if hasattr(x, 'reposetup'): |
|
3155 | if hasattr(x, 'reposetup'): | |
3156 | x.reposetup(u, repo) |
|
3156 | x.reposetup(u, repo) | |
3157 | except hg.RepoError: |
|
3157 | except hg.RepoError: | |
3158 | if cmd not in optionalrepo.split(): |
|
3158 | if cmd not in optionalrepo.split(): | |
3159 | raise |
|
3159 | raise | |
3160 | d = lambda: func(u, repo, *args, **cmdoptions) |
|
3160 | d = lambda: func(u, repo, *args, **cmdoptions) | |
3161 | else: |
|
3161 | else: | |
3162 | d = lambda: func(u, *args, **cmdoptions) |
|
3162 | d = lambda: func(u, *args, **cmdoptions) | |
3163 |
|
3163 | |||
3164 | try: |
|
3164 | try: | |
3165 | if options['profile']: |
|
3165 | if options['profile']: | |
3166 | import hotshot, hotshot.stats |
|
3166 | import hotshot, hotshot.stats | |
3167 | prof = hotshot.Profile("hg.prof") |
|
3167 | prof = hotshot.Profile("hg.prof") | |
3168 | try: |
|
3168 | try: | |
3169 | try: |
|
3169 | try: | |
3170 | return prof.runcall(d) |
|
3170 | return prof.runcall(d) | |
3171 | except: |
|
3171 | except: | |
3172 | try: |
|
3172 | try: | |
3173 | u.warn(_('exception raised - generating ' |
|
3173 | u.warn(_('exception raised - generating ' | |
3174 | 'profile anyway\n')) |
|
3174 | 'profile anyway\n')) | |
3175 | except: |
|
3175 | except: | |
3176 | pass |
|
3176 | pass | |
3177 | raise |
|
3177 | raise | |
3178 | finally: |
|
3178 | finally: | |
3179 | prof.close() |
|
3179 | prof.close() | |
3180 | stats = hotshot.stats.load("hg.prof") |
|
3180 | stats = hotshot.stats.load("hg.prof") | |
3181 | stats.strip_dirs() |
|
3181 | stats.strip_dirs() | |
3182 | stats.sort_stats('time', 'calls') |
|
3182 | stats.sort_stats('time', 'calls') | |
3183 | stats.print_stats(40) |
|
3183 | stats.print_stats(40) | |
3184 | else: |
|
3184 | else: | |
3185 | return d() |
|
3185 | return d() | |
3186 | finally: |
|
3186 | finally: | |
3187 | u.flush() |
|
3187 | u.flush() | |
3188 | except: |
|
3188 | except: | |
3189 | # enter the debugger when we hit an exception |
|
3189 | # enter the debugger when we hit an exception | |
3190 | if options['debugger']: |
|
3190 | if options['debugger']: | |
3191 | pdb.post_mortem(sys.exc_info()[2]) |
|
3191 | pdb.post_mortem(sys.exc_info()[2]) | |
3192 | if options['traceback']: |
|
3192 | if options['traceback']: | |
3193 | traceback.print_exc() |
|
3193 | traceback.print_exc() | |
3194 | raise |
|
3194 | raise | |
3195 | except ParseError, inst: |
|
3195 | except ParseError, inst: | |
3196 | if inst.args[0]: |
|
3196 | if inst.args[0]: | |
3197 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
|
3197 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) | |
3198 | help_(u, inst.args[0]) |
|
3198 | help_(u, inst.args[0]) | |
3199 | else: |
|
3199 | else: | |
3200 | u.warn(_("hg: %s\n") % inst.args[1]) |
|
3200 | u.warn(_("hg: %s\n") % inst.args[1]) | |
3201 | help_(u, 'shortlist') |
|
3201 | help_(u, 'shortlist') | |
3202 | sys.exit(-1) |
|
3202 | sys.exit(-1) | |
3203 | except AmbiguousCommand, inst: |
|
3203 | except AmbiguousCommand, inst: | |
3204 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
|
3204 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | |
3205 | (inst.args[0], " ".join(inst.args[1]))) |
|
3205 | (inst.args[0], " ".join(inst.args[1]))) | |
3206 | sys.exit(1) |
|
3206 | sys.exit(1) | |
3207 | except UnknownCommand, inst: |
|
3207 | except UnknownCommand, inst: | |
3208 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
|
3208 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | |
3209 | help_(u, 'shortlist') |
|
3209 | help_(u, 'shortlist') | |
3210 | sys.exit(1) |
|
3210 | sys.exit(1) | |
3211 | except hg.RepoError, inst: |
|
3211 | except hg.RepoError, inst: | |
3212 | u.warn(_("abort: "), inst, "!\n") |
|
3212 | u.warn(_("abort: "), inst, "!\n") | |
3213 | except revlog.RevlogError, inst: |
|
3213 | except revlog.RevlogError, inst: | |
3214 | u.warn(_("abort: "), inst, "!\n") |
|
3214 | u.warn(_("abort: "), inst, "!\n") | |
3215 | except SignalInterrupt: |
|
3215 | except SignalInterrupt: | |
3216 | u.warn(_("killed!\n")) |
|
3216 | u.warn(_("killed!\n")) | |
3217 | except KeyboardInterrupt: |
|
3217 | except KeyboardInterrupt: | |
3218 | try: |
|
3218 | try: | |
3219 | u.warn(_("interrupted!\n")) |
|
3219 | u.warn(_("interrupted!\n")) | |
3220 | except IOError, inst: |
|
3220 | except IOError, inst: | |
3221 | if inst.errno == errno.EPIPE: |
|
3221 | if inst.errno == errno.EPIPE: | |
3222 | if u.debugflag: |
|
3222 | if u.debugflag: | |
3223 | u.warn(_("\nbroken pipe\n")) |
|
3223 | u.warn(_("\nbroken pipe\n")) | |
3224 | else: |
|
3224 | else: | |
3225 | raise |
|
3225 | raise | |
3226 | except IOError, inst: |
|
3226 | except IOError, inst: | |
3227 | if hasattr(inst, "code"): |
|
3227 | if hasattr(inst, "code"): | |
3228 | u.warn(_("abort: %s\n") % inst) |
|
3228 | u.warn(_("abort: %s\n") % inst) | |
3229 | elif hasattr(inst, "reason"): |
|
3229 | elif hasattr(inst, "reason"): | |
3230 | u.warn(_("abort: error: %s\n") % inst.reason[1]) |
|
3230 | u.warn(_("abort: error: %s\n") % inst.reason[1]) | |
3231 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: |
|
3231 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: | |
3232 | if u.debugflag: |
|
3232 | if u.debugflag: | |
3233 | u.warn(_("broken pipe\n")) |
|
3233 | u.warn(_("broken pipe\n")) | |
3234 | elif getattr(inst, "strerror", None): |
|
3234 | elif getattr(inst, "strerror", None): | |
3235 | if getattr(inst, "filename", None): |
|
3235 | if getattr(inst, "filename", None): | |
3236 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) |
|
3236 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) | |
3237 | else: |
|
3237 | else: | |
3238 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3238 | u.warn(_("abort: %s\n") % inst.strerror) | |
3239 | else: |
|
3239 | else: | |
3240 | raise |
|
3240 | raise | |
3241 | except OSError, inst: |
|
3241 | except OSError, inst: | |
3242 | if hasattr(inst, "filename"): |
|
3242 | if hasattr(inst, "filename"): | |
3243 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
|
3243 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) | |
3244 | else: |
|
3244 | else: | |
3245 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3245 | u.warn(_("abort: %s\n") % inst.strerror) | |
3246 | except util.Abort, inst: |
|
3246 | except util.Abort, inst: | |
3247 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') |
|
3247 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') | |
3248 | sys.exit(1) |
|
3248 | sys.exit(1) | |
3249 | except TypeError, inst: |
|
3249 | except TypeError, inst: | |
3250 | # was this an argument error? |
|
3250 | # was this an argument error? | |
3251 | tb = traceback.extract_tb(sys.exc_info()[2]) |
|
3251 | tb = traceback.extract_tb(sys.exc_info()[2]) | |
3252 | if len(tb) > 2: # no |
|
3252 | if len(tb) > 2: # no | |
3253 | raise |
|
3253 | raise | |
3254 | u.debug(inst, "\n") |
|
3254 | u.debug(inst, "\n") | |
3255 | u.warn(_("%s: invalid arguments\n") % cmd) |
|
3255 | u.warn(_("%s: invalid arguments\n") % cmd) | |
3256 | help_(u, cmd) |
|
3256 | help_(u, cmd) | |
3257 | except SystemExit: |
|
3257 | except SystemExit: | |
3258 | # don't catch this in the catch-all below |
|
3258 | # don't catch this in the catch-all below | |
3259 | raise |
|
3259 | raise | |
3260 | except: |
|
3260 | except: | |
3261 | u.warn(_("** unknown exception encountered, details follow\n")) |
|
3261 | u.warn(_("** unknown exception encountered, details follow\n")) | |
3262 | u.warn(_("** report bug details to mercurial@selenic.com\n")) |
|
3262 | u.warn(_("** report bug details to mercurial@selenic.com\n")) | |
3263 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") |
|
3263 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") | |
3264 | % version.get_version()) |
|
3264 | % version.get_version()) | |
3265 | raise |
|
3265 | raise | |
3266 |
|
3266 | |||
3267 | sys.exit(-1) |
|
3267 | sys.exit(-1) |
General Comments 0
You need to be logged in to leave comments.
Login now