Show More
@@ -1,289 +1,289 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # |
|
2 | # | |
3 | # This is a generalized framework for converting between SCM |
|
3 | # This is a generalized framework for converting between SCM | |
4 | # repository formats. |
|
4 | # repository formats. | |
5 | # |
|
5 | # | |
6 | # In its current form, it's hardcoded to convert incrementally between |
|
6 | # In its current form, it's hardcoded to convert incrementally between | |
7 | # git and Mercurial. |
|
7 | # git and Mercurial. | |
8 | # |
|
8 | # | |
9 | # To use, you must first import the first git version into Mercurial, |
|
9 | # To use, you must first import the first git version into Mercurial, | |
10 | # and establish a mapping between the git commit hash and the hash in |
|
10 | # and establish a mapping between the git commit hash and the hash in | |
11 | # Mercurial for that version. This mapping is kept in a simple text |
|
11 | # Mercurial for that version. This mapping is kept in a simple text | |
12 | # file with lines like so: |
|
12 | # file with lines like so: | |
13 | # |
|
13 | # | |
14 | # <git hash> <mercurial hash> |
|
14 | # <git hash> <mercurial hash> | |
15 | # |
|
15 | # | |
16 | # To convert the rest of the repo, run: |
|
16 | # To convert the rest of the repo, run: | |
17 | # |
|
17 | # | |
18 | # convert-repo <git-dir> <hg-dir> <mapfile> |
|
18 | # convert-repo <git-dir> <hg-dir> <mapfile> | |
19 | # |
|
19 | # | |
20 | # This updates the mapfile on each commit copied, so it can be |
|
20 | # This updates the mapfile on each commit copied, so it can be | |
21 | # interrupted and can be run repeatedly to copy new commits. |
|
21 | # interrupted and can be run repeatedly to copy new commits. | |
22 |
|
22 | |||
23 | import sys, os, zlib, sha, time |
|
23 | import sys, os, zlib, sha, time | |
24 | from mercurial import hg, ui, util |
|
24 | from mercurial import hg, ui, util | |
25 |
|
25 | |||
26 | class convert_git: |
|
26 | class convert_git: | |
27 | def __init__(self, path): |
|
27 | def __init__(self, path): | |
28 | self.path = path |
|
28 | self.path = path | |
29 |
|
29 | |||
30 | def getheads(self): |
|
30 | def getheads(self): | |
31 | return [file(self.path + "/HEAD").read()[:-1]] |
|
31 | return [file(self.path + "/HEAD").read()[:-1]] | |
32 |
|
32 | |||
33 | def catfile(self, rev, type): |
|
33 | def catfile(self, rev, type): | |
34 | if rev == "0" * 40: raise IOError() |
|
34 | if rev == "0" * 40: raise IOError() | |
35 | fh = os.popen("GIT_DIR=%s git-cat-file %s %s 2>/dev/null" % (self.path, type, rev)) |
|
35 | fh = os.popen("GIT_DIR=%s git-cat-file %s %s 2>/dev/null" % (self.path, type, rev)) | |
36 | return fh.read() |
|
36 | return fh.read() | |
37 |
|
37 | |||
38 | def getfile(self, name, rev): |
|
38 | def getfile(self, name, rev): | |
39 | return self.catfile(rev, "blob") |
|
39 | return self.catfile(rev, "blob") | |
40 |
|
40 | |||
41 | def getchanges(self, version): |
|
41 | def getchanges(self, version): | |
42 | fh = os.popen("GIT_DIR=%s git-diff-tree --root -m -r %s" % (self.path, version)) |
|
42 | fh = os.popen("GIT_DIR=%s git-diff-tree --root -m -r %s" % (self.path, version)) | |
43 | changes = [] |
|
43 | changes = [] | |
44 | for l in fh: |
|
44 | for l in fh: | |
45 | if "\t" not in l: continue |
|
45 | if "\t" not in l: continue | |
46 | m, f = l[:-1].split("\t") |
|
46 | m, f = l[:-1].split("\t") | |
47 | m = m.split() |
|
47 | m = m.split() | |
48 | h = m[3] |
|
48 | h = m[3] | |
49 | p = (m[1] == "100755") |
|
49 | p = (m[1] == "100755") | |
50 | changes.append((f, h, p)) |
|
50 | changes.append((f, h, p)) | |
51 | return changes |
|
51 | return changes | |
52 |
|
52 | |||
53 | def getcommit(self, version): |
|
53 | def getcommit(self, version): | |
54 | c = self.catfile(version, "commit") # read the commit hash |
|
54 | c = self.catfile(version, "commit") # read the commit hash | |
55 | end = c.find("\n\n") |
|
55 | end = c.find("\n\n") | |
56 | message = c[end+2:] |
|
56 | message = c[end+2:] | |
57 | l = c[:end].splitlines() |
|
57 | l = c[:end].splitlines() | |
58 | manifest = l[0].split()[1] |
|
58 | manifest = l[0].split()[1] | |
59 | parents = [] |
|
59 | parents = [] | |
60 | for e in l[1:]: |
|
60 | for e in l[1:]: | |
61 | n,v = e.split(" ", 1) |
|
61 | n,v = e.split(" ", 1) | |
62 | if n == "author": |
|
62 | if n == "author": | |
63 | p = v.split() |
|
63 | p = v.split() | |
64 | tm, tz = p[-2:] |
|
64 | tm, tz = p[-2:] | |
65 | author = " ".join(p[:-2]) |
|
65 | author = " ".join(p[:-2]) | |
66 | if author[0] == "<": author = author[1:-1] |
|
66 | if author[0] == "<": author = author[1:-1] | |
67 | if n == "committer": |
|
67 | if n == "committer": | |
68 | p = v.split() |
|
68 | p = v.split() | |
69 | tm, tz = p[-2:] |
|
69 | tm, tz = p[-2:] | |
70 | committer = " ".join(p[:-2]) |
|
70 | committer = " ".join(p[:-2]) | |
71 | if committer[0] == "<": committer = committer[1:-1] |
|
71 | if committer[0] == "<": committer = committer[1:-1] | |
72 | message += "\ncommitter: %s\n" % v |
|
72 | message += "\ncommitter: %s\n" % v | |
73 | if n == "parent": parents.append(v) |
|
73 | if n == "parent": parents.append(v) | |
74 |
|
74 | |||
75 | tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:] |
|
75 | tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:] | |
76 | tz = int(tzs) * (int(tzh) * 3600 + int(tzm)) |
|
76 | tz = -int(tzs) * (int(tzh) * 3600 + int(tzm)) | |
77 | date = tm + " " + str(tz) |
|
77 | date = tm + " " + str(tz) | |
78 | return (parents, author, date, message) |
|
78 | return (parents, author, date, message) | |
79 |
|
79 | |||
80 | def gettags(self): |
|
80 | def gettags(self): | |
81 | tags = {} |
|
81 | tags = {} | |
82 | for f in os.listdir(self.path + "/refs/tags"): |
|
82 | for f in os.listdir(self.path + "/refs/tags"): | |
83 | try: |
|
83 | try: | |
84 | h = file(self.path + "/refs/tags/" + f).read().strip() |
|
84 | h = file(self.path + "/refs/tags/" + f).read().strip() | |
85 | c = self.catfile(h, "tag") # read the commit hash |
|
85 | c = self.catfile(h, "tag") # read the commit hash | |
86 | h = c.splitlines()[0].split()[1] |
|
86 | h = c.splitlines()[0].split()[1] | |
87 | tags[f] = h |
|
87 | tags[f] = h | |
88 | except: |
|
88 | except: | |
89 | pass |
|
89 | pass | |
90 | return tags |
|
90 | return tags | |
91 |
|
91 | |||
92 | class convert_mercurial: |
|
92 | class convert_mercurial: | |
93 | def __init__(self, path): |
|
93 | def __init__(self, path): | |
94 | self.path = path |
|
94 | self.path = path | |
95 | u = ui.ui() |
|
95 | u = ui.ui() | |
96 | self.repo = hg.repository(u, path) |
|
96 | self.repo = hg.repository(u, path) | |
97 |
|
97 | |||
98 | def getheads(self): |
|
98 | def getheads(self): | |
99 | h = self.repo.changelog.heads() |
|
99 | h = self.repo.changelog.heads() | |
100 | return [ hg.hex(x) for x in h ] |
|
100 | return [ hg.hex(x) for x in h ] | |
101 |
|
101 | |||
102 | def putfile(self, f, e, data): |
|
102 | def putfile(self, f, e, data): | |
103 | self.repo.wfile(f, "w").write(data) |
|
103 | self.repo.wfile(f, "w").write(data) | |
104 | if self.repo.dirstate.state(f) == '?': |
|
104 | if self.repo.dirstate.state(f) == '?': | |
105 | self.repo.dirstate.update([f], "a") |
|
105 | self.repo.dirstate.update([f], "a") | |
106 |
|
106 | |||
107 | util.set_exec(self.repo.wjoin(f), e) |
|
107 | util.set_exec(self.repo.wjoin(f), e) | |
108 |
|
108 | |||
109 | def delfile(self, f): |
|
109 | def delfile(self, f): | |
110 | try: |
|
110 | try: | |
111 | os.unlink(self.repo.wjoin(f)) |
|
111 | os.unlink(self.repo.wjoin(f)) | |
112 | #self.repo.remove([f]) |
|
112 | #self.repo.remove([f]) | |
113 | except: |
|
113 | except: | |
114 | pass |
|
114 | pass | |
115 |
|
115 | |||
116 | def putcommit(self, files, parents, author, dest, text): |
|
116 | def putcommit(self, files, parents, author, dest, text): | |
117 | seen = {} |
|
117 | seen = {} | |
118 | pl = [] |
|
118 | pl = [] | |
119 | for p in parents: |
|
119 | for p in parents: | |
120 | if p not in seen: |
|
120 | if p not in seen: | |
121 | pl.append(p) |
|
121 | pl.append(p) | |
122 | seen[p] = 1 |
|
122 | seen[p] = 1 | |
123 | parents = pl |
|
123 | parents = pl | |
124 |
|
124 | |||
125 | if len(parents) < 2: parents.append("0" * 40) |
|
125 | if len(parents) < 2: parents.append("0" * 40) | |
126 | if len(parents) < 2: parents.append("0" * 40) |
|
126 | if len(parents) < 2: parents.append("0" * 40) | |
127 | p2 = parents.pop(0) |
|
127 | p2 = parents.pop(0) | |
128 |
|
128 | |||
129 | while parents: |
|
129 | while parents: | |
130 | p1 = p2 |
|
130 | p1 = p2 | |
131 | p2 = parents.pop(0) |
|
131 | p2 = parents.pop(0) | |
132 | self.repo.rawcommit(files, text, author, dest, |
|
132 | self.repo.rawcommit(files, text, author, dest, | |
133 | hg.bin(p1), hg.bin(p2)) |
|
133 | hg.bin(p1), hg.bin(p2)) | |
134 | text = "(octopus merge fixup)\n" |
|
134 | text = "(octopus merge fixup)\n" | |
135 | p2 = hg.hex(self.repo.changelog.tip()) |
|
135 | p2 = hg.hex(self.repo.changelog.tip()) | |
136 |
|
136 | |||
137 | return p2 |
|
137 | return p2 | |
138 |
|
138 | |||
139 | def puttags(self, tags): |
|
139 | def puttags(self, tags): | |
140 | try: |
|
140 | try: | |
141 | old = self.repo.wfile(".hgtags").read() |
|
141 | old = self.repo.wfile(".hgtags").read() | |
142 | oldlines = old.splitlines(1) |
|
142 | oldlines = old.splitlines(1) | |
143 | oldlines.sort() |
|
143 | oldlines.sort() | |
144 | except: |
|
144 | except: | |
145 | oldlines = [] |
|
145 | oldlines = [] | |
146 |
|
146 | |||
147 | k = tags.keys() |
|
147 | k = tags.keys() | |
148 | k.sort() |
|
148 | k.sort() | |
149 | newlines = [] |
|
149 | newlines = [] | |
150 | for tag in k: |
|
150 | for tag in k: | |
151 | newlines.append("%s %s\n" % (tags[tag], tag)) |
|
151 | newlines.append("%s %s\n" % (tags[tag], tag)) | |
152 |
|
152 | |||
153 | newlines.sort() |
|
153 | newlines.sort() | |
154 |
|
154 | |||
155 | if newlines != oldlines: |
|
155 | if newlines != oldlines: | |
156 | #print "updating tags" |
|
156 | #print "updating tags" | |
157 | f = self.repo.wfile(".hgtags", "w") |
|
157 | f = self.repo.wfile(".hgtags", "w") | |
158 | f.write("".join(newlines)) |
|
158 | f.write("".join(newlines)) | |
159 | f.close() |
|
159 | f.close() | |
160 | if not oldlines: self.repo.add([".hgtags"]) |
|
160 | if not oldlines: self.repo.add([".hgtags"]) | |
161 | date = "%s 0" % int(time.mktime(time.gmtime())) |
|
161 | date = "%s 0" % int(time.mktime(time.gmtime())) | |
162 | self.repo.rawcommit([".hgtags"], "update tags", "convert-repo", |
|
162 | self.repo.rawcommit([".hgtags"], "update tags", "convert-repo", | |
163 | date, self.repo.changelog.tip(), hg.nullid) |
|
163 | date, self.repo.changelog.tip(), hg.nullid) | |
164 | return hg.hex(self.repo.changelog.tip()) |
|
164 | return hg.hex(self.repo.changelog.tip()) | |
165 |
|
165 | |||
166 | class convert: |
|
166 | class convert: | |
167 | def __init__(self, source, dest, mapfile): |
|
167 | def __init__(self, source, dest, mapfile): | |
168 | self.source = source |
|
168 | self.source = source | |
169 | self.dest = dest |
|
169 | self.dest = dest | |
170 | self.mapfile = mapfile |
|
170 | self.mapfile = mapfile | |
171 | self.commitcache = {} |
|
171 | self.commitcache = {} | |
172 |
|
172 | |||
173 | self.map = {} |
|
173 | self.map = {} | |
174 | try: |
|
174 | try: | |
175 | for l in file(self.mapfile): |
|
175 | for l in file(self.mapfile): | |
176 | sv, dv = l[:-1].split() |
|
176 | sv, dv = l[:-1].split() | |
177 | self.map[sv] = dv |
|
177 | self.map[sv] = dv | |
178 | except IOError: |
|
178 | except IOError: | |
179 | pass |
|
179 | pass | |
180 |
|
180 | |||
181 | def walktree(self, heads): |
|
181 | def walktree(self, heads): | |
182 | visit = heads |
|
182 | visit = heads | |
183 | known = {} |
|
183 | known = {} | |
184 | parents = {} |
|
184 | parents = {} | |
185 | while visit: |
|
185 | while visit: | |
186 | n = visit.pop(0) |
|
186 | n = visit.pop(0) | |
187 | if n in known or n in self.map: continue |
|
187 | if n in known or n in self.map: continue | |
188 | known[n] = 1 |
|
188 | known[n] = 1 | |
189 | self.commitcache[n] = self.source.getcommit(n) |
|
189 | self.commitcache[n] = self.source.getcommit(n) | |
190 | cp = self.commitcache[n][0] |
|
190 | cp = self.commitcache[n][0] | |
191 | for p in cp: |
|
191 | for p in cp: | |
192 | parents.setdefault(n, []).append(p) |
|
192 | parents.setdefault(n, []).append(p) | |
193 | visit.append(p) |
|
193 | visit.append(p) | |
194 |
|
194 | |||
195 | return parents |
|
195 | return parents | |
196 |
|
196 | |||
197 | def toposort(self, parents): |
|
197 | def toposort(self, parents): | |
198 | visit = parents.keys() |
|
198 | visit = parents.keys() | |
199 | seen = {} |
|
199 | seen = {} | |
200 | children = {} |
|
200 | children = {} | |
201 |
|
201 | |||
202 | while visit: |
|
202 | while visit: | |
203 | n = visit.pop(0) |
|
203 | n = visit.pop(0) | |
204 | if n in seen: continue |
|
204 | if n in seen: continue | |
205 | seen[n] = 1 |
|
205 | seen[n] = 1 | |
206 | pc = 0 |
|
206 | pc = 0 | |
207 | if n in parents: |
|
207 | if n in parents: | |
208 | for p in parents[n]: |
|
208 | for p in parents[n]: | |
209 | if p not in self.map: pc += 1 |
|
209 | if p not in self.map: pc += 1 | |
210 | visit.append(p) |
|
210 | visit.append(p) | |
211 | children.setdefault(p, []).append(n) |
|
211 | children.setdefault(p, []).append(n) | |
212 | if not pc: root = n |
|
212 | if not pc: root = n | |
213 |
|
213 | |||
214 | s = [] |
|
214 | s = [] | |
215 | removed = {} |
|
215 | removed = {} | |
216 | visit = children.keys() |
|
216 | visit = children.keys() | |
217 | while visit: |
|
217 | while visit: | |
218 | n = visit.pop(0) |
|
218 | n = visit.pop(0) | |
219 | if n in removed: continue |
|
219 | if n in removed: continue | |
220 | dep = 0 |
|
220 | dep = 0 | |
221 | if n in parents: |
|
221 | if n in parents: | |
222 | for p in parents[n]: |
|
222 | for p in parents[n]: | |
223 | if p in self.map: continue |
|
223 | if p in self.map: continue | |
224 | if p not in removed: |
|
224 | if p not in removed: | |
225 | # we're still dependent |
|
225 | # we're still dependent | |
226 | visit.append(n) |
|
226 | visit.append(n) | |
227 | dep = 1 |
|
227 | dep = 1 | |
228 | break |
|
228 | break | |
229 |
|
229 | |||
230 | if not dep: |
|
230 | if not dep: | |
231 | # all n's parents are in the list |
|
231 | # all n's parents are in the list | |
232 | removed[n] = 1 |
|
232 | removed[n] = 1 | |
233 | s.append(n) |
|
233 | s.append(n) | |
234 | if n in children: |
|
234 | if n in children: | |
235 | for c in children[n]: |
|
235 | for c in children[n]: | |
236 | visit.insert(0, c) |
|
236 | visit.insert(0, c) | |
237 |
|
237 | |||
238 | return s |
|
238 | return s | |
239 |
|
239 | |||
240 | def copy(self, rev): |
|
240 | def copy(self, rev): | |
241 | p, a, d, t = self.commitcache[rev] |
|
241 | p, a, d, t = self.commitcache[rev] | |
242 | files = self.source.getchanges(rev) |
|
242 | files = self.source.getchanges(rev) | |
243 |
|
243 | |||
244 | for f,v,e in files: |
|
244 | for f,v,e in files: | |
245 | try: |
|
245 | try: | |
246 | data = self.source.getfile(f, v) |
|
246 | data = self.source.getfile(f, v) | |
247 | except IOError, inst: |
|
247 | except IOError, inst: | |
248 | self.dest.delfile(f) |
|
248 | self.dest.delfile(f) | |
249 | else: |
|
249 | else: | |
250 | self.dest.putfile(f, e, data) |
|
250 | self.dest.putfile(f, e, data) | |
251 |
|
251 | |||
252 | r = [self.map[v] for v in p] |
|
252 | r = [self.map[v] for v in p] | |
253 | f = [f for f,v,e in files] |
|
253 | f = [f for f,v,e in files] | |
254 | self.map[rev] = self.dest.putcommit(f, r, a, d, t) |
|
254 | self.map[rev] = self.dest.putcommit(f, r, a, d, t) | |
255 | file(self.mapfile, "a").write("%s %s\n" % (rev, self.map[rev])) |
|
255 | file(self.mapfile, "a").write("%s %s\n" % (rev, self.map[rev])) | |
256 |
|
256 | |||
257 | def convert(self): |
|
257 | def convert(self): | |
258 | heads = self.source.getheads() |
|
258 | heads = self.source.getheads() | |
259 | parents = self.walktree(heads) |
|
259 | parents = self.walktree(heads) | |
260 | t = self.toposort(parents) |
|
260 | t = self.toposort(parents) | |
261 | t = [n for n in t if n not in self.map] |
|
261 | t = [n for n in t if n not in self.map] | |
262 | num = len(t) |
|
262 | num = len(t) | |
263 | c = None |
|
263 | c = None | |
264 |
|
264 | |||
265 | for c in t: |
|
265 | for c in t: | |
266 | num -= 1 |
|
266 | num -= 1 | |
267 | desc = self.commitcache[c][3].splitlines()[0] |
|
267 | desc = self.commitcache[c][3].splitlines()[0] | |
268 | #print num, desc |
|
268 | #print num, desc | |
269 | self.copy(c) |
|
269 | self.copy(c) | |
270 |
|
270 | |||
271 | tags = self.source.gettags() |
|
271 | tags = self.source.gettags() | |
272 | ctags = {} |
|
272 | ctags = {} | |
273 | for k in tags: |
|
273 | for k in tags: | |
274 | v = tags[k] |
|
274 | v = tags[k] | |
275 | if v in self.map: |
|
275 | if v in self.map: | |
276 | ctags[k] = self.map[v] |
|
276 | ctags[k] = self.map[v] | |
277 |
|
277 | |||
278 | if c and ctags: |
|
278 | if c and ctags: | |
279 | nrev = self.dest.puttags(ctags) |
|
279 | nrev = self.dest.puttags(ctags) | |
280 | # write another hash correspondence to override the previous |
|
280 | # write another hash correspondence to override the previous | |
281 | # one so we don't end up with extra tag heads |
|
281 | # one so we don't end up with extra tag heads | |
282 | file(self.mapfile, "a").write("%s %s\n" % (c, nrev)) |
|
282 | file(self.mapfile, "a").write("%s %s\n" % (c, nrev)) | |
283 |
|
283 | |||
284 | gitpath, hgpath, mapfile = sys.argv[1:] |
|
284 | gitpath, hgpath, mapfile = sys.argv[1:] | |
285 | if os.path.isdir(gitpath + "/.git"): |
|
285 | if os.path.isdir(gitpath + "/.git"): | |
286 | gitpath += "/.git" |
|
286 | gitpath += "/.git" | |
287 |
|
287 | |||
288 | c = convert(convert_git(gitpath), convert_mercurial(hgpath), mapfile) |
|
288 | c = convert(convert_git(gitpath), convert_mercurial(hgpath), mapfile) | |
289 | c.convert() |
|
289 | c.convert() |
@@ -1,1310 +1,1311 b'' | |||||
1 | # queue.py - patch queues for mercurial |
|
1 | # queue.py - patch queues for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005 Chris Mason <mason@suse.com> |
|
3 | # Copyright 2005 Chris Mason <mason@suse.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 mercurial.demandload import * |
|
8 | from mercurial.demandload import * | |
9 | demandload(globals(), "os sys re struct traceback errno bz2") |
|
9 | demandload(globals(), "os sys re struct traceback errno bz2") | |
10 | from mercurial.i18n import gettext as _ |
|
10 | from mercurial.i18n import gettext as _ | |
11 | from mercurial import ui, hg, revlog, commands, util |
|
11 | from mercurial import ui, hg, revlog, commands, util | |
12 |
|
12 | |||
13 | versionstr = "0.45" |
|
13 | versionstr = "0.45" | |
14 |
|
14 | |||
15 | repomap = {} |
|
15 | repomap = {} | |
16 |
|
16 | |||
17 | commands.norepo += " qversion" |
|
17 | commands.norepo += " qversion" | |
18 | class queue: |
|
18 | class queue: | |
19 | def __init__(self, ui, path, patchdir=None): |
|
19 | def __init__(self, ui, path, patchdir=None): | |
20 | self.basepath = path |
|
20 | self.basepath = path | |
21 | if patchdir: |
|
21 | if patchdir: | |
22 | self.path = patchdir |
|
22 | self.path = patchdir | |
23 | else: |
|
23 | else: | |
24 | self.path = os.path.join(path, "patches") |
|
24 | self.path = os.path.join(path, "patches") | |
25 | self.opener = util.opener(self.path) |
|
25 | self.opener = util.opener(self.path) | |
26 | self.ui = ui |
|
26 | self.ui = ui | |
27 | self.applied = [] |
|
27 | self.applied = [] | |
28 | self.full_series = [] |
|
28 | self.full_series = [] | |
29 | self.applied_dirty = 0 |
|
29 | self.applied_dirty = 0 | |
30 | self.series_dirty = 0 |
|
30 | self.series_dirty = 0 | |
31 | self.series_path = "series" |
|
31 | self.series_path = "series" | |
32 | self.status_path = "status" |
|
32 | self.status_path = "status" | |
33 |
|
33 | |||
34 | if os.path.exists(os.path.join(self.path, self.series_path)): |
|
34 | if os.path.exists(os.path.join(self.path, self.series_path)): | |
35 | self.full_series = self.opener(self.series_path).read().splitlines() |
|
35 | self.full_series = self.opener(self.series_path).read().splitlines() | |
36 | self.read_series(self.full_series) |
|
36 | self.read_series(self.full_series) | |
37 |
|
37 | |||
38 | if os.path.exists(os.path.join(self.path, self.status_path)): |
|
38 | if os.path.exists(os.path.join(self.path, self.status_path)): | |
39 | self.applied = self.opener(self.status_path).read().splitlines() |
|
39 | self.applied = self.opener(self.status_path).read().splitlines() | |
40 |
|
40 | |||
41 | def find_series(self, patch): |
|
41 | def find_series(self, patch): | |
42 | pre = re.compile("(\s*)([^#]+)") |
|
42 | pre = re.compile("(\s*)([^#]+)") | |
43 | index = 0 |
|
43 | index = 0 | |
44 | for l in self.full_series: |
|
44 | for l in self.full_series: | |
45 | m = pre.match(l) |
|
45 | m = pre.match(l) | |
46 | if m: |
|
46 | if m: | |
47 | s = m.group(2) |
|
47 | s = m.group(2) | |
48 | s = s.rstrip() |
|
48 | s = s.rstrip() | |
49 | if s == patch: |
|
49 | if s == patch: | |
50 | return index |
|
50 | return index | |
51 | index += 1 |
|
51 | index += 1 | |
52 | return None |
|
52 | return None | |
53 |
|
53 | |||
54 | def read_series(self, list): |
|
54 | def read_series(self, list): | |
55 | def matcher(list): |
|
55 | def matcher(list): | |
56 | pre = re.compile("(\s*)([^#]+)") |
|
56 | pre = re.compile("(\s*)([^#]+)") | |
57 | for l in list: |
|
57 | for l in list: | |
58 | m = pre.match(l) |
|
58 | m = pre.match(l) | |
59 | if m: |
|
59 | if m: | |
60 | s = m.group(2) |
|
60 | s = m.group(2) | |
61 | s = s.rstrip() |
|
61 | s = s.rstrip() | |
62 | if len(s) > 0: |
|
62 | if len(s) > 0: | |
63 | yield s |
|
63 | yield s | |
64 | self.series = [] |
|
64 | self.series = [] | |
65 | self.series = [ x for x in matcher(list) ] |
|
65 | self.series = [ x for x in matcher(list) ] | |
66 |
|
66 | |||
67 | def save_dirty(self): |
|
67 | def save_dirty(self): | |
68 | if self.applied_dirty: |
|
68 | if self.applied_dirty: | |
69 | if len(self.applied) > 0: |
|
69 | if len(self.applied) > 0: | |
70 | nl = "\n" |
|
70 | nl = "\n" | |
71 | else: |
|
71 | else: | |
72 | nl = "" |
|
72 | nl = "" | |
73 | f = self.opener(self.status_path, "w") |
|
73 | f = self.opener(self.status_path, "w") | |
74 | f.write("\n".join(self.applied) + nl) |
|
74 | f.write("\n".join(self.applied) + nl) | |
75 | if self.series_dirty: |
|
75 | if self.series_dirty: | |
76 | if len(self.full_series) > 0: |
|
76 | if len(self.full_series) > 0: | |
77 | nl = "\n" |
|
77 | nl = "\n" | |
78 | else: |
|
78 | else: | |
79 | nl = "" |
|
79 | nl = "" | |
80 | f = self.opener(self.series_path, "w") |
|
80 | f = self.opener(self.series_path, "w") | |
81 | f.write("\n".join(self.full_series) + nl) |
|
81 | f.write("\n".join(self.full_series) + nl) | |
82 |
|
82 | |||
83 | def readheaders(self, patch): |
|
83 | def readheaders(self, patch): | |
84 | def eatdiff(lines): |
|
84 | def eatdiff(lines): | |
85 | while lines: |
|
85 | while lines: | |
86 | l = lines[-1] |
|
86 | l = lines[-1] | |
87 | if (l.startswith("diff -") or |
|
87 | if (l.startswith("diff -") or | |
88 | l.startswith("Index:") or |
|
88 | l.startswith("Index:") or | |
89 | l.startswith("===========")): |
|
89 | l.startswith("===========")): | |
90 | del lines[-1] |
|
90 | del lines[-1] | |
91 | else: |
|
91 | else: | |
92 | break |
|
92 | break | |
93 | def eatempty(lines): |
|
93 | def eatempty(lines): | |
94 | while lines: |
|
94 | while lines: | |
95 | l = lines[-1] |
|
95 | l = lines[-1] | |
96 | if re.match('\s*$', l): |
|
96 | if re.match('\s*$', l): | |
97 | del lines[-1] |
|
97 | del lines[-1] | |
98 | else: |
|
98 | else: | |
99 | break |
|
99 | break | |
100 |
|
100 | |||
101 | pf = os.path.join(self.path, patch) |
|
101 | pf = os.path.join(self.path, patch) | |
102 | message = [] |
|
102 | message = [] | |
103 | comments = [] |
|
103 | comments = [] | |
104 | user = None |
|
104 | user = None | |
105 | format = None |
|
105 | format = None | |
106 | subject = None |
|
106 | subject = None | |
107 | diffstart = 0 |
|
107 | diffstart = 0 | |
108 |
|
108 | |||
109 | for line in file(pf): |
|
109 | for line in file(pf): | |
110 | line = line.rstrip() |
|
110 | line = line.rstrip() | |
111 | if diffstart: |
|
111 | if diffstart: | |
112 | if line.startswith('+++ '): |
|
112 | if line.startswith('+++ '): | |
113 | diffstart = 2 |
|
113 | diffstart = 2 | |
114 | break |
|
114 | break | |
115 | if line.startswith("--- "): |
|
115 | if line.startswith("--- "): | |
116 | diffstart = 1 |
|
116 | diffstart = 1 | |
117 | continue |
|
117 | continue | |
118 | elif format == "hgpatch": |
|
118 | elif format == "hgpatch": | |
119 | # parse values when importing the result of an hg export |
|
119 | # parse values when importing the result of an hg export | |
120 | if line.startswith("# User "): |
|
120 | if line.startswith("# User "): | |
121 | user = line[7:] |
|
121 | user = line[7:] | |
122 | elif not line.startswith("# ") and line: |
|
122 | elif not line.startswith("# ") and line: | |
123 | message.append(line) |
|
123 | message.append(line) | |
124 | format = None |
|
124 | format = None | |
125 | elif line == '# HG changeset patch': |
|
125 | elif line == '# HG changeset patch': | |
126 | format = "hgpatch" |
|
126 | format = "hgpatch" | |
127 | elif (format != "tagdone" and (line.startswith("Subject: ") or |
|
127 | elif (format != "tagdone" and (line.startswith("Subject: ") or | |
128 | line.startswith("subject: "))): |
|
128 | line.startswith("subject: "))): | |
129 | subject = line[9:] |
|
129 | subject = line[9:] | |
130 | format = "tag" |
|
130 | format = "tag" | |
131 | elif (format != "tagdone" and (line.startswith("From: ") or |
|
131 | elif (format != "tagdone" and (line.startswith("From: ") or | |
132 | line.startswith("from: "))): |
|
132 | line.startswith("from: "))): | |
133 | user = line[6:] |
|
133 | user = line[6:] | |
134 | format = "tag" |
|
134 | format = "tag" | |
135 | elif format == "tag" and line == "": |
|
135 | elif format == "tag" and line == "": | |
136 | # when looking for tags (subject: from: etc) they |
|
136 | # when looking for tags (subject: from: etc) they | |
137 | # end once you find a blank line in the source |
|
137 | # end once you find a blank line in the source | |
138 | format = "tagdone" |
|
138 | format = "tagdone" | |
139 | else: |
|
139 | else: | |
140 | message.append(line) |
|
140 | message.append(line) | |
141 | comments.append(line) |
|
141 | comments.append(line) | |
142 |
|
142 | |||
143 | eatdiff(message) |
|
143 | eatdiff(message) | |
144 | eatdiff(comments) |
|
144 | eatdiff(comments) | |
145 | eatempty(message) |
|
145 | eatempty(message) | |
146 | eatempty(comments) |
|
146 | eatempty(comments) | |
147 |
|
147 | |||
148 | # make sure message isn't empty |
|
148 | # make sure message isn't empty | |
149 | if format and format.startswith("tag") and subject: |
|
149 | if format and format.startswith("tag") and subject: | |
150 | message.insert(0, "") |
|
150 | message.insert(0, "") | |
151 | message.insert(0, subject) |
|
151 | message.insert(0, subject) | |
152 | return (message, comments, user, diffstart > 1) |
|
152 | return (message, comments, user, diffstart > 1) | |
153 |
|
153 | |||
154 | def mergeone(self, repo, mergeq, head, patch, rev, wlock): |
|
154 | def mergeone(self, repo, mergeq, head, patch, rev, wlock): | |
155 | # first try just applying the patch |
|
155 | # first try just applying the patch | |
156 | (err, n) = self.apply(repo, [ patch ], update_status=False, |
|
156 | (err, n) = self.apply(repo, [ patch ], update_status=False, | |
157 | strict=True, merge=rev, wlock=wlock) |
|
157 | strict=True, merge=rev, wlock=wlock) | |
158 |
|
158 | |||
159 | if err == 0: |
|
159 | if err == 0: | |
160 | return (err, n) |
|
160 | return (err, n) | |
161 |
|
161 | |||
162 | if n is None: |
|
162 | if n is None: | |
163 | self.ui.warn("apply failed for patch %s\n" % patch) |
|
163 | self.ui.warn("apply failed for patch %s\n" % patch) | |
164 | sys.exit(1) |
|
164 | sys.exit(1) | |
165 |
|
165 | |||
166 | self.ui.warn("patch didn't work out, merging %s\n" % patch) |
|
166 | self.ui.warn("patch didn't work out, merging %s\n" % patch) | |
167 |
|
167 | |||
168 | # apply failed, strip away that rev and merge. |
|
168 | # apply failed, strip away that rev and merge. | |
169 | repo.update(head, allow=False, force=True, wlock=wlock) |
|
169 | repo.update(head, allow=False, force=True, wlock=wlock) | |
170 | self.strip(repo, n, update=False, backup='strip', wlock=wlock) |
|
170 | self.strip(repo, n, update=False, backup='strip', wlock=wlock) | |
171 |
|
171 | |||
172 | c = repo.changelog.read(rev) |
|
172 | c = repo.changelog.read(rev) | |
173 | ret = repo.update(rev, allow=True, wlock=wlock) |
|
173 | ret = repo.update(rev, allow=True, wlock=wlock) | |
174 | if ret: |
|
174 | if ret: | |
175 | self.ui.warn("update returned %d\n" % ret) |
|
175 | self.ui.warn("update returned %d\n" % ret) | |
176 | sys.exit(1) |
|
176 | sys.exit(1) | |
177 | n = repo.commit(None, c[4], c[1], force=1, wlock=wlock) |
|
177 | n = repo.commit(None, c[4], c[1], force=1, wlock=wlock) | |
178 | if n == None: |
|
178 | if n == None: | |
179 | self.ui.warn("repo commit failed\n") |
|
179 | self.ui.warn("repo commit failed\n") | |
180 | sys.exit(1) |
|
180 | sys.exit(1) | |
181 | try: |
|
181 | try: | |
182 | message, comments, user, patchfound = mergeq.readheaders(patch) |
|
182 | message, comments, user, patchfound = mergeq.readheaders(patch) | |
183 | except: |
|
183 | except: | |
184 | self.ui.warn("Unable to read %s\n" % patch) |
|
184 | self.ui.warn("Unable to read %s\n" % patch) | |
185 | sys.exit(1) |
|
185 | sys.exit(1) | |
186 |
|
186 | |||
187 | patchf = self.opener(patch, "w") |
|
187 | patchf = self.opener(patch, "w") | |
188 | if comments: |
|
188 | if comments: | |
189 | comments = "\n".join(comments) + '\n\n' |
|
189 | comments = "\n".join(comments) + '\n\n' | |
190 | patchf.write(comments) |
|
190 | patchf.write(comments) | |
191 | commands.dodiff(patchf, self.ui, repo, head, n) |
|
191 | commands.dodiff(patchf, self.ui, repo, head, n) | |
192 | patchf.close() |
|
192 | patchf.close() | |
193 | return (0, n) |
|
193 | return (0, n) | |
194 |
|
194 | |||
195 | def qparents(self, repo, rev=None): |
|
195 | def qparents(self, repo, rev=None): | |
196 | if rev is None: |
|
196 | if rev is None: | |
197 | (p1, p2) = repo.dirstate.parents() |
|
197 | (p1, p2) = repo.dirstate.parents() | |
198 | if p2 == revlog.nullid: |
|
198 | if p2 == revlog.nullid: | |
199 | return p1 |
|
199 | return p1 | |
200 | if len(self.applied) == 0: |
|
200 | if len(self.applied) == 0: | |
201 | return None |
|
201 | return None | |
202 | (top, patch) = self.applied[-1].split(':') |
|
202 | (top, patch) = self.applied[-1].split(':') | |
203 | top = revlog.bin(top) |
|
203 | top = revlog.bin(top) | |
204 | return top |
|
204 | return top | |
205 | pp = repo.changelog.parents(rev) |
|
205 | pp = repo.changelog.parents(rev) | |
206 | if pp[1] != revlog.nullid: |
|
206 | if pp[1] != revlog.nullid: | |
207 | arevs = [ x.split(':')[0] for x in self.applied ] |
|
207 | arevs = [ x.split(':')[0] for x in self.applied ] | |
208 | p0 = revlog.hex(pp[0]) |
|
208 | p0 = revlog.hex(pp[0]) | |
209 | p1 = revlog.hex(pp[1]) |
|
209 | p1 = revlog.hex(pp[1]) | |
210 | if p0 in arevs: |
|
210 | if p0 in arevs: | |
211 | return pp[0] |
|
211 | return pp[0] | |
212 | if p1 in arevs: |
|
212 | if p1 in arevs: | |
213 | return pp[1] |
|
213 | return pp[1] | |
214 | return None |
|
214 | return None | |
215 | return pp[0] |
|
215 | return pp[0] | |
216 |
|
216 | |||
217 | def mergepatch(self, repo, mergeq, series, wlock): |
|
217 | def mergepatch(self, repo, mergeq, series, wlock): | |
218 | if len(self.applied) == 0: |
|
218 | if len(self.applied) == 0: | |
219 | # each of the patches merged in will have two parents. This |
|
219 | # each of the patches merged in will have two parents. This | |
220 | # can confuse the qrefresh, qdiff, and strip code because it |
|
220 | # can confuse the qrefresh, qdiff, and strip code because it | |
221 | # needs to know which parent is actually in the patch queue. |
|
221 | # needs to know which parent is actually in the patch queue. | |
222 | # so, we insert a merge marker with only one parent. This way |
|
222 | # so, we insert a merge marker with only one parent. This way | |
223 | # the first patch in the queue is never a merge patch |
|
223 | # the first patch in the queue is never a merge patch | |
224 | # |
|
224 | # | |
225 | pname = ".hg.patches.merge.marker" |
|
225 | pname = ".hg.patches.merge.marker" | |
226 | n = repo.commit(None, '[mq]: merge marker', user=None, force=1, |
|
226 | n = repo.commit(None, '[mq]: merge marker', user=None, force=1, | |
227 | wlock=wlock) |
|
227 | wlock=wlock) | |
228 | self.applied.append(revlog.hex(n) + ":" + pname) |
|
228 | self.applied.append(revlog.hex(n) + ":" + pname) | |
229 | self.applied_dirty = 1 |
|
229 | self.applied_dirty = 1 | |
230 |
|
230 | |||
231 | head = self.qparents(repo) |
|
231 | head = self.qparents(repo) | |
232 |
|
232 | |||
233 | for patch in series: |
|
233 | for patch in series: | |
234 | patch = mergeq.lookup(patch) |
|
234 | patch = mergeq.lookup(patch) | |
235 | if not patch: |
|
235 | if not patch: | |
236 | self.ui.warn("patch %s does not exist\n" % patch) |
|
236 | self.ui.warn("patch %s does not exist\n" % patch) | |
237 | return (1, None) |
|
237 | return (1, None) | |
238 |
|
238 | |||
239 | info = mergeq.isapplied(patch) |
|
239 | info = mergeq.isapplied(patch) | |
240 | if not info: |
|
240 | if not info: | |
241 | self.ui.warn("patch %s is not applied\n" % patch) |
|
241 | self.ui.warn("patch %s is not applied\n" % patch) | |
242 | return (1, None) |
|
242 | return (1, None) | |
243 | rev = revlog.bin(info[1]) |
|
243 | rev = revlog.bin(info[1]) | |
244 | (err, head) = self.mergeone(repo, mergeq, head, patch, rev, wlock) |
|
244 | (err, head) = self.mergeone(repo, mergeq, head, patch, rev, wlock) | |
245 | if head: |
|
245 | if head: | |
246 | self.applied.append(revlog.hex(head) + ":" + patch) |
|
246 | self.applied.append(revlog.hex(head) + ":" + patch) | |
247 | self.applied_dirty = 1 |
|
247 | self.applied_dirty = 1 | |
248 | if err: |
|
248 | if err: | |
249 | return (err, head) |
|
249 | return (err, head) | |
250 | return (0, head) |
|
250 | return (0, head) | |
251 |
|
251 | |||
252 | def apply(self, repo, series, list=False, update_status=True, |
|
252 | def apply(self, repo, series, list=False, update_status=True, | |
253 | strict=False, patchdir=None, merge=None, wlock=None): |
|
253 | strict=False, patchdir=None, merge=None, wlock=None): | |
254 | # TODO unify with commands.py |
|
254 | # TODO unify with commands.py | |
255 | if not patchdir: |
|
255 | if not patchdir: | |
256 | patchdir = self.path |
|
256 | patchdir = self.path | |
257 | pwd = os.getcwd() |
|
257 | pwd = os.getcwd() | |
258 | os.chdir(repo.root) |
|
258 | os.chdir(repo.root) | |
259 | err = 0 |
|
259 | err = 0 | |
260 | if not wlock: |
|
260 | if not wlock: | |
261 | wlock = repo.wlock() |
|
261 | wlock = repo.wlock() | |
262 | lock = repo.lock() |
|
262 | lock = repo.lock() | |
263 | tr = repo.transaction() |
|
263 | tr = repo.transaction() | |
264 | n = None |
|
264 | n = None | |
265 | for patch in series: |
|
265 | for patch in series: | |
266 | self.ui.warn("applying %s\n" % patch) |
|
266 | self.ui.warn("applying %s\n" % patch) | |
267 | pf = os.path.join(patchdir, patch) |
|
267 | pf = os.path.join(patchdir, patch) | |
268 |
|
268 | |||
269 | try: |
|
269 | try: | |
270 | message, comments, user, patchfound = self.readheaders(patch) |
|
270 | message, comments, user, patchfound = self.readheaders(patch) | |
271 | except: |
|
271 | except: | |
272 | self.ui.warn("Unable to read %s\n" % pf) |
|
272 | self.ui.warn("Unable to read %s\n" % pf) | |
273 | err = 1 |
|
273 | err = 1 | |
274 | break |
|
274 | break | |
275 |
|
275 | |||
276 | if not message: |
|
276 | if not message: | |
277 | message = "imported patch %s\n" % patch |
|
277 | message = "imported patch %s\n" % patch | |
278 | else: |
|
278 | else: | |
279 | if list: |
|
279 | if list: | |
280 | message.append("\nimported patch %s" % patch) |
|
280 | message.append("\nimported patch %s" % patch) | |
281 | message = '\n'.join(message) |
|
281 | message = '\n'.join(message) | |
282 |
|
282 | |||
283 | try: |
|
283 | try: | |
284 | f = os.popen("patch -p1 --no-backup-if-mismatch < '%s'" % (pf)) |
|
284 | f = os.popen("patch -p1 --no-backup-if-mismatch < '%s'" % (pf)) | |
285 | except: |
|
285 | except: | |
286 | self.ui.warn("patch failed, unable to continue (try -v)\n") |
|
286 | self.ui.warn("patch failed, unable to continue (try -v)\n") | |
287 | err = 1 |
|
287 | err = 1 | |
288 | break |
|
288 | break | |
289 | files = [] |
|
289 | files = [] | |
290 | fuzz = False |
|
290 | fuzz = False | |
291 | for l in f: |
|
291 | for l in f: | |
292 | l = l.rstrip('\r\n'); |
|
292 | l = l.rstrip('\r\n'); | |
293 | if self.ui.verbose: |
|
293 | if self.ui.verbose: | |
294 | self.ui.warn(l + "\n") |
|
294 | self.ui.warn(l + "\n") | |
295 | if l[:14] == 'patching file ': |
|
295 | if l[:14] == 'patching file ': | |
296 | pf = os.path.normpath(l[14:]) |
|
296 | pf = os.path.normpath(l[14:]) | |
297 | # when patch finds a space in the file name, it puts |
|
297 | # when patch finds a space in the file name, it puts | |
298 | # single quotes around the filename. strip them off |
|
298 | # single quotes around the filename. strip them off | |
299 | if pf[0] == "'" and pf[-1] == "'": |
|
299 | if pf[0] == "'" and pf[-1] == "'": | |
300 | pf = pf[1:-1] |
|
300 | pf = pf[1:-1] | |
301 | if pf not in files: |
|
301 | if pf not in files: | |
302 | files.append(pf) |
|
302 | files.append(pf) | |
303 | printed_file = False |
|
303 | printed_file = False | |
304 | file_str = l |
|
304 | file_str = l | |
305 | elif l.find('with fuzz') >= 0: |
|
305 | elif l.find('with fuzz') >= 0: | |
306 | if not printed_file: |
|
306 | if not printed_file: | |
307 | self.ui.warn(file_str + '\n') |
|
307 | self.ui.warn(file_str + '\n') | |
308 | printed_file = True |
|
308 | printed_file = True | |
309 | self.ui.warn(l + '\n') |
|
309 | self.ui.warn(l + '\n') | |
310 | fuzz = True |
|
310 | fuzz = True | |
311 | elif l.find('saving rejects to file') >= 0: |
|
311 | elif l.find('saving rejects to file') >= 0: | |
312 | self.ui.warn(l + '\n') |
|
312 | self.ui.warn(l + '\n') | |
313 | elif l.find('FAILED') >= 0: |
|
313 | elif l.find('FAILED') >= 0: | |
314 | if not printed_file: |
|
314 | if not printed_file: | |
315 | self.ui.warn(file_str + '\n') |
|
315 | self.ui.warn(file_str + '\n') | |
316 | printed_file = True |
|
316 | printed_file = True | |
317 | self.ui.warn(l + '\n') |
|
317 | self.ui.warn(l + '\n') | |
318 | patcherr = f.close() |
|
318 | patcherr = f.close() | |
319 |
|
319 | |||
320 | if merge and len(files) > 0: |
|
320 | if merge and len(files) > 0: | |
321 | # Mark as merged and update dirstate parent info |
|
321 | # Mark as merged and update dirstate parent info | |
322 | repo.dirstate.update(repo.dirstate.filterfiles(files), 'm') |
|
322 | repo.dirstate.update(repo.dirstate.filterfiles(files), 'm') | |
323 | p1, p2 = repo.dirstate.parents() |
|
323 | p1, p2 = repo.dirstate.parents() | |
324 | repo.dirstate.setparents(p1, merge) |
|
324 | repo.dirstate.setparents(p1, merge) | |
325 | if len(files) > 0: |
|
325 | if len(files) > 0: | |
326 | commands.addremove_lock(self.ui, repo, files, |
|
326 | commands.addremove_lock(self.ui, repo, files, | |
327 | opts={}, wlock=wlock) |
|
327 | opts={}, wlock=wlock) | |
328 | n = repo.commit(files, message, user, force=1, lock=lock, |
|
328 | n = repo.commit(files, message, user, force=1, lock=lock, | |
329 | wlock=wlock) |
|
329 | wlock=wlock) | |
330 |
|
330 | |||
331 | if n == None: |
|
331 | if n == None: | |
332 | self.ui.warn("repo commit failed\n") |
|
332 | self.ui.warn("repo commit failed\n") | |
333 | sys.exit(1) |
|
333 | sys.exit(1) | |
334 |
|
334 | |||
335 | if update_status: |
|
335 | if update_status: | |
336 | self.applied.append(revlog.hex(n) + ":" + patch) |
|
336 | self.applied.append(revlog.hex(n) + ":" + patch) | |
337 |
|
337 | |||
338 | if patcherr: |
|
338 | if patcherr: | |
339 | if not patchfound: |
|
339 | if not patchfound: | |
340 | self.ui.warn("patch %s is empty\n" % patch) |
|
340 | self.ui.warn("patch %s is empty\n" % patch) | |
341 | err = 0 |
|
341 | err = 0 | |
342 | else: |
|
342 | else: | |
343 | self.ui.warn("patch failed, rejects left in working dir\n") |
|
343 | self.ui.warn("patch failed, rejects left in working dir\n") | |
344 | err = 1 |
|
344 | err = 1 | |
345 | break |
|
345 | break | |
346 |
|
346 | |||
347 | if fuzz and strict: |
|
347 | if fuzz and strict: | |
348 | self.ui.warn("fuzz found when applying patch, stopping\n") |
|
348 | self.ui.warn("fuzz found when applying patch, stopping\n") | |
349 | err = 1 |
|
349 | err = 1 | |
350 | break |
|
350 | break | |
351 | tr.close() |
|
351 | tr.close() | |
352 | os.chdir(pwd) |
|
352 | os.chdir(pwd) | |
353 | return (err, n) |
|
353 | return (err, n) | |
354 |
|
354 | |||
355 | def delete(self, repo, patch): |
|
355 | def delete(self, repo, patch): | |
356 | patch = self.lookup(patch) |
|
356 | patch = self.lookup(patch) | |
357 | info = self.isapplied(patch) |
|
357 | info = self.isapplied(patch) | |
358 | if info: |
|
358 | if info: | |
359 | self.ui.warn("cannot delete applied patch %s\n" % patch) |
|
359 | self.ui.warn("cannot delete applied patch %s\n" % patch) | |
360 | sys.exit(1) |
|
360 | sys.exit(1) | |
361 | if patch not in self.series: |
|
361 | if patch not in self.series: | |
362 | self.ui.warn("patch %s not in series file\n" % patch) |
|
362 | self.ui.warn("patch %s not in series file\n" % patch) | |
363 | sys.exit(1) |
|
363 | sys.exit(1) | |
364 | i = self.find_series(patch) |
|
364 | i = self.find_series(patch) | |
365 | del self.full_series[i] |
|
365 | del self.full_series[i] | |
366 | self.read_series(self.full_series) |
|
366 | self.read_series(self.full_series) | |
367 | self.series_dirty = 1 |
|
367 | self.series_dirty = 1 | |
368 |
|
368 | |||
369 | def check_toppatch(self, repo): |
|
369 | def check_toppatch(self, repo): | |
370 | if len(self.applied) > 0: |
|
370 | if len(self.applied) > 0: | |
371 | (top, patch) = self.applied[-1].split(':') |
|
371 | (top, patch) = self.applied[-1].split(':') | |
372 | top = revlog.bin(top) |
|
372 | top = revlog.bin(top) | |
373 | pp = repo.dirstate.parents() |
|
373 | pp = repo.dirstate.parents() | |
374 | if top not in pp: |
|
374 | if top not in pp: | |
375 | self.ui.warn("queue top not at dirstate parents. top %s dirstate %s %s\n" %( revlog.short(top), revlog.short(pp[0]), revlog.short(pp[1]))) |
|
375 | self.ui.warn("queue top not at dirstate parents. top %s dirstate %s %s\n" %( revlog.short(top), revlog.short(pp[0]), revlog.short(pp[1]))) | |
376 | sys.exit(1) |
|
376 | sys.exit(1) | |
377 | return top |
|
377 | return top | |
378 | return None |
|
378 | return None | |
379 | def check_localchanges(self, repo): |
|
379 | def check_localchanges(self, repo): | |
380 | (c, a, r, d, u) = repo.changes(None, None) |
|
380 | (c, a, r, d, u) = repo.changes(None, None) | |
381 | if c or a or d or r: |
|
381 | if c or a or d or r: | |
382 | self.ui.write("Local changes found, refresh first\n") |
|
382 | self.ui.write("Local changes found, refresh first\n") | |
383 | sys.exit(1) |
|
383 | sys.exit(1) | |
384 | def new(self, repo, patch, msg=None, force=None): |
|
384 | def new(self, repo, patch, msg=None, force=None): | |
385 | if not force: |
|
385 | if not force: | |
386 | self.check_localchanges(repo) |
|
386 | self.check_localchanges(repo) | |
387 | self.check_toppatch(repo) |
|
387 | self.check_toppatch(repo) | |
388 | wlock = repo.wlock() |
|
388 | wlock = repo.wlock() | |
389 | insert = self.series_end() |
|
389 | insert = self.series_end() | |
390 | if msg: |
|
390 | if msg: | |
391 | n = repo.commit([], "[mq]: %s" % msg, force=True, wlock=wlock) |
|
391 | n = repo.commit([], "[mq]: %s" % msg, force=True, wlock=wlock) | |
392 | else: |
|
392 | else: | |
393 | n = repo.commit([], |
|
393 | n = repo.commit([], | |
394 | "New patch: %s" % patch, force=True, wlock=wlock) |
|
394 | "New patch: %s" % patch, force=True, wlock=wlock) | |
395 | if n == None: |
|
395 | if n == None: | |
396 | self.ui.warn("repo commit failed\n") |
|
396 | self.ui.warn("repo commit failed\n") | |
397 | sys.exit(1) |
|
397 | sys.exit(1) | |
398 | self.full_series[insert:insert] = [patch] |
|
398 | self.full_series[insert:insert] = [patch] | |
399 | self.applied.append(revlog.hex(n) + ":" + patch) |
|
399 | self.applied.append(revlog.hex(n) + ":" + patch) | |
400 | self.read_series(self.full_series) |
|
400 | self.read_series(self.full_series) | |
401 | self.series_dirty = 1 |
|
401 | self.series_dirty = 1 | |
402 | self.applied_dirty = 1 |
|
402 | self.applied_dirty = 1 | |
403 | p = self.opener(patch, "w") |
|
403 | p = self.opener(patch, "w") | |
404 | if msg: |
|
404 | if msg: | |
405 | msg = msg + "\n" |
|
405 | msg = msg + "\n" | |
406 | p.write(msg) |
|
406 | p.write(msg) | |
407 | p.close() |
|
407 | p.close() | |
408 | wlock = None |
|
408 | wlock = None | |
409 | r = self.qrepo() |
|
409 | r = self.qrepo() | |
410 | if r: r.add([patch]) |
|
410 | if r: r.add([patch]) | |
411 |
|
411 | |||
412 | def strip(self, repo, rev, update=True, backup="all", wlock=None): |
|
412 | def strip(self, repo, rev, update=True, backup="all", wlock=None): | |
413 | def limitheads(chlog, stop): |
|
413 | def limitheads(chlog, stop): | |
414 | """return the list of all nodes that have no children""" |
|
414 | """return the list of all nodes that have no children""" | |
415 | p = {} |
|
415 | p = {} | |
416 | h = [] |
|
416 | h = [] | |
417 | stoprev = 0 |
|
417 | stoprev = 0 | |
418 | if stop in chlog.nodemap: |
|
418 | if stop in chlog.nodemap: | |
419 | stoprev = chlog.rev(stop) |
|
419 | stoprev = chlog.rev(stop) | |
420 |
|
420 | |||
421 | for r in range(chlog.count() - 1, -1, -1): |
|
421 | for r in range(chlog.count() - 1, -1, -1): | |
422 | n = chlog.node(r) |
|
422 | n = chlog.node(r) | |
423 | if n not in p: |
|
423 | if n not in p: | |
424 | h.append(n) |
|
424 | h.append(n) | |
425 | if n == stop: |
|
425 | if n == stop: | |
426 | break |
|
426 | break | |
427 | if r < stoprev: |
|
427 | if r < stoprev: | |
428 | break |
|
428 | break | |
429 | for pn in chlog.parents(n): |
|
429 | for pn in chlog.parents(n): | |
430 | p[pn] = 1 |
|
430 | p[pn] = 1 | |
431 | return h |
|
431 | return h | |
432 |
|
432 | |||
433 | def bundle(cg): |
|
433 | def bundle(cg): | |
434 | backupdir = repo.join("strip-backup") |
|
434 | backupdir = repo.join("strip-backup") | |
435 | if not os.path.isdir(backupdir): |
|
435 | if not os.path.isdir(backupdir): | |
436 | os.mkdir(backupdir) |
|
436 | os.mkdir(backupdir) | |
437 | name = os.path.join(backupdir, "%s" % revlog.short(rev)) |
|
437 | name = os.path.join(backupdir, "%s" % revlog.short(rev)) | |
438 | name = savename(name) |
|
438 | name = savename(name) | |
439 | self.ui.warn("saving bundle to %s\n" % name) |
|
439 | self.ui.warn("saving bundle to %s\n" % name) | |
440 | # TODO, exclusive open |
|
440 | # TODO, exclusive open | |
441 | f = open(name, "wb") |
|
441 | f = open(name, "wb") | |
442 | try: |
|
442 | try: | |
443 | f.write("HG10") |
|
443 | f.write("HG10") | |
444 | z = bz2.BZ2Compressor(9) |
|
444 | z = bz2.BZ2Compressor(9) | |
445 | while 1: |
|
445 | while 1: | |
446 | chunk = cg.read(4096) |
|
446 | chunk = cg.read(4096) | |
447 | if not chunk: |
|
447 | if not chunk: | |
448 | break |
|
448 | break | |
449 | f.write(z.compress(chunk)) |
|
449 | f.write(z.compress(chunk)) | |
450 | f.write(z.flush()) |
|
450 | f.write(z.flush()) | |
451 | except: |
|
451 | except: | |
452 | os.unlink(name) |
|
452 | os.unlink(name) | |
453 | raise |
|
453 | raise | |
454 | f.close() |
|
454 | f.close() | |
455 | return name |
|
455 | return name | |
456 |
|
456 | |||
457 | def stripall(rev, revnum): |
|
457 | def stripall(rev, revnum): | |
458 | cl = repo.changelog |
|
458 | cl = repo.changelog | |
459 | c = cl.read(rev) |
|
459 | c = cl.read(rev) | |
460 | mm = repo.manifest.read(c[0]) |
|
460 | mm = repo.manifest.read(c[0]) | |
461 | seen = {} |
|
461 | seen = {} | |
462 |
|
462 | |||
463 | for x in xrange(revnum, cl.count()): |
|
463 | for x in xrange(revnum, cl.count()): | |
464 | c = cl.read(cl.node(x)) |
|
464 | c = cl.read(cl.node(x)) | |
465 | for f in c[3]: |
|
465 | for f in c[3]: | |
466 | if f in seen: |
|
466 | if f in seen: | |
467 | continue |
|
467 | continue | |
468 | seen[f] = 1 |
|
468 | seen[f] = 1 | |
469 | if f in mm: |
|
469 | if f in mm: | |
470 | filerev = mm[f] |
|
470 | filerev = mm[f] | |
471 | else: |
|
471 | else: | |
472 | filerev = 0 |
|
472 | filerev = 0 | |
473 | seen[f] = filerev |
|
473 | seen[f] = filerev | |
474 | # we go in two steps here so the strip loop happens in a |
|
474 | # we go in two steps here so the strip loop happens in a | |
475 | # sensible order. When stripping many files, this helps keep |
|
475 | # sensible order. When stripping many files, this helps keep | |
476 | # our disk access patterns under control. |
|
476 | # our disk access patterns under control. | |
477 | list = seen.keys() |
|
477 | list = seen.keys() | |
478 | list.sort() |
|
478 | list.sort() | |
479 | for f in list: |
|
479 | for f in list: | |
480 | ff = repo.file(f) |
|
480 | ff = repo.file(f) | |
481 | filerev = seen[f] |
|
481 | filerev = seen[f] | |
482 | if filerev != 0: |
|
482 | if filerev != 0: | |
483 | if filerev in ff.nodemap: |
|
483 | if filerev in ff.nodemap: | |
484 | filerev = ff.rev(filerev) |
|
484 | filerev = ff.rev(filerev) | |
485 | else: |
|
485 | else: | |
486 | filerev = 0 |
|
486 | filerev = 0 | |
487 | ff.strip(filerev, revnum) |
|
487 | ff.strip(filerev, revnum) | |
488 |
|
488 | |||
489 | if not wlock: |
|
489 | if not wlock: | |
490 | wlock = repo.wlock() |
|
490 | wlock = repo.wlock() | |
491 | lock = repo.lock() |
|
491 | lock = repo.lock() | |
492 | chlog = repo.changelog |
|
492 | chlog = repo.changelog | |
493 | # TODO delete the undo files, and handle undo of merge sets |
|
493 | # TODO delete the undo files, and handle undo of merge sets | |
494 | pp = chlog.parents(rev) |
|
494 | pp = chlog.parents(rev) | |
495 | revnum = chlog.rev(rev) |
|
495 | revnum = chlog.rev(rev) | |
496 |
|
496 | |||
497 | if update: |
|
497 | if update: | |
498 | urev = self.qparents(repo, rev) |
|
498 | urev = self.qparents(repo, rev) | |
499 | repo.update(urev, allow=False, force=True, wlock=wlock) |
|
499 | repo.update(urev, allow=False, force=True, wlock=wlock) | |
500 | repo.dirstate.write() |
|
500 | repo.dirstate.write() | |
501 |
|
501 | |||
502 | # save is a list of all the branches we are truncating away |
|
502 | # save is a list of all the branches we are truncating away | |
503 | # that we actually want to keep. changegroup will be used |
|
503 | # that we actually want to keep. changegroup will be used | |
504 | # to preserve them and add them back after the truncate |
|
504 | # to preserve them and add them back after the truncate | |
505 | saveheads = [] |
|
505 | saveheads = [] | |
506 | savebases = {} |
|
506 | savebases = {} | |
507 |
|
507 | |||
508 | tip = chlog.tip() |
|
508 | tip = chlog.tip() | |
509 | heads = limitheads(chlog, rev) |
|
509 | heads = limitheads(chlog, rev) | |
510 | seen = {} |
|
510 | seen = {} | |
511 |
|
511 | |||
512 | # search through all the heads, finding those where the revision |
|
512 | # search through all the heads, finding those where the revision | |
513 | # we want to strip away is an ancestor. Also look for merges |
|
513 | # we want to strip away is an ancestor. Also look for merges | |
514 | # that might be turned into new heads by the strip. |
|
514 | # that might be turned into new heads by the strip. | |
515 | while heads: |
|
515 | while heads: | |
516 | h = heads.pop() |
|
516 | h = heads.pop() | |
517 | n = h |
|
517 | n = h | |
518 | while True: |
|
518 | while True: | |
519 | seen[n] = 1 |
|
519 | seen[n] = 1 | |
520 | pp = chlog.parents(n) |
|
520 | pp = chlog.parents(n) | |
521 | if pp[1] != revlog.nullid and chlog.rev(pp[1]) > revnum: |
|
521 | if pp[1] != revlog.nullid and chlog.rev(pp[1]) > revnum: | |
522 | if pp[1] not in seen: |
|
522 | if pp[1] not in seen: | |
523 | heads.append(pp[1]) |
|
523 | heads.append(pp[1]) | |
524 | if pp[0] == revlog.nullid: |
|
524 | if pp[0] == revlog.nullid: | |
525 | break |
|
525 | break | |
526 | if chlog.rev(pp[0]) < revnum: |
|
526 | if chlog.rev(pp[0]) < revnum: | |
527 | break |
|
527 | break | |
528 | n = pp[0] |
|
528 | n = pp[0] | |
529 | if n == rev: |
|
529 | if n == rev: | |
530 | break |
|
530 | break | |
531 | r = chlog.reachable(h, rev) |
|
531 | r = chlog.reachable(h, rev) | |
532 | if rev not in r: |
|
532 | if rev not in r: | |
533 | saveheads.append(h) |
|
533 | saveheads.append(h) | |
534 | for x in r: |
|
534 | for x in r: | |
535 | if chlog.rev(x) > revnum: |
|
535 | if chlog.rev(x) > revnum: | |
536 | savebases[x] = 1 |
|
536 | savebases[x] = 1 | |
537 |
|
537 | |||
538 | # create a changegroup for all the branches we need to keep |
|
538 | # create a changegroup for all the branches we need to keep | |
539 | if backup is "all": |
|
539 | if backup is "all": | |
540 | backupch = repo.changegroupsubset([rev], chlog.heads(), 'strip') |
|
540 | backupch = repo.changegroupsubset([rev], chlog.heads(), 'strip') | |
541 | bundle(backupch) |
|
541 | bundle(backupch) | |
542 | if saveheads: |
|
542 | if saveheads: | |
543 | backupch = repo.changegroupsubset(savebases.keys(), saveheads, 'strip') |
|
543 | backupch = repo.changegroupsubset(savebases.keys(), saveheads, 'strip') | |
544 | chgrpfile = bundle(backupch) |
|
544 | chgrpfile = bundle(backupch) | |
545 |
|
545 | |||
546 | stripall(rev, revnum) |
|
546 | stripall(rev, revnum) | |
547 |
|
547 | |||
548 | change = chlog.read(rev) |
|
548 | change = chlog.read(rev) | |
549 | repo.manifest.strip(repo.manifest.rev(change[0]), revnum) |
|
549 | repo.manifest.strip(repo.manifest.rev(change[0]), revnum) | |
550 | chlog.strip(revnum, revnum) |
|
550 | chlog.strip(revnum, revnum) | |
551 | if saveheads: |
|
551 | if saveheads: | |
552 | self.ui.status("adding branch\n") |
|
552 | self.ui.status("adding branch\n") | |
553 | commands.unbundle(self.ui, repo, chgrpfile, update=False) |
|
553 | commands.unbundle(self.ui, repo, chgrpfile, update=False) | |
554 | if backup is not "strip": |
|
554 | if backup is not "strip": | |
555 | os.unlink(chgrpfile) |
|
555 | os.unlink(chgrpfile) | |
556 |
|
556 | |||
557 | def isapplied(self, patch): |
|
557 | def isapplied(self, patch): | |
558 | """returns (index, rev, patch)""" |
|
558 | """returns (index, rev, patch)""" | |
559 | for i in xrange(len(self.applied)): |
|
559 | for i in xrange(len(self.applied)): | |
560 | p = self.applied[i] |
|
560 | p = self.applied[i] | |
561 | a = p.split(':') |
|
561 | a = p.split(':') | |
562 | if a[1] == patch: |
|
562 | if a[1] == patch: | |
563 | return (i, a[0], a[1]) |
|
563 | return (i, a[0], a[1]) | |
564 | return None |
|
564 | return None | |
565 |
|
565 | |||
566 | def lookup(self, patch): |
|
566 | def lookup(self, patch): | |
567 | if patch == None: |
|
567 | if patch == None: | |
568 | return None |
|
568 | return None | |
569 | if patch in self.series: |
|
569 | if patch in self.series: | |
570 | return patch |
|
570 | return patch | |
571 | if not os.path.isfile(os.path.join(self.path, patch)): |
|
571 | if not os.path.isfile(os.path.join(self.path, patch)): | |
572 | try: |
|
572 | try: | |
573 | sno = int(patch) |
|
573 | sno = int(patch) | |
574 | except(ValueError, OverflowError): |
|
574 | except(ValueError, OverflowError): | |
575 | self.ui.warn("patch %s not in series\n" % patch) |
|
575 | self.ui.warn("patch %s not in series\n" % patch) | |
576 | sys.exit(1) |
|
576 | sys.exit(1) | |
577 | if sno >= len(self.series): |
|
577 | if sno >= len(self.series): | |
578 | self.ui.warn("patch number %d is out of range\n" % sno) |
|
578 | self.ui.warn("patch number %d is out of range\n" % sno) | |
579 | sys.exit(1) |
|
579 | sys.exit(1) | |
580 | patch = self.series[sno] |
|
580 | patch = self.series[sno] | |
581 | else: |
|
581 | else: | |
582 | self.ui.warn("patch %s not in series\n" % patch) |
|
582 | self.ui.warn("patch %s not in series\n" % patch) | |
583 | sys.exit(1) |
|
583 | sys.exit(1) | |
584 | return patch |
|
584 | return patch | |
585 |
|
585 | |||
586 | def push(self, repo, patch=None, force=False, list=False, |
|
586 | def push(self, repo, patch=None, force=False, list=False, | |
587 | mergeq=None, wlock=None): |
|
587 | mergeq=None, wlock=None): | |
588 | if not wlock: |
|
588 | if not wlock: | |
589 | wlock = repo.wlock() |
|
589 | wlock = repo.wlock() | |
590 | patch = self.lookup(patch) |
|
590 | patch = self.lookup(patch) | |
591 | if patch and self.isapplied(patch): |
|
591 | if patch and self.isapplied(patch): | |
592 | self.ui.warn("patch %s is already applied\n" % patch) |
|
592 | self.ui.warn("patch %s is already applied\n" % patch) | |
593 | sys.exit(1) |
|
593 | sys.exit(1) | |
594 | if self.series_end() == len(self.series): |
|
594 | if self.series_end() == len(self.series): | |
595 | self.ui.warn("File series fully applied\n") |
|
595 | self.ui.warn("File series fully applied\n") | |
596 | sys.exit(1) |
|
596 | sys.exit(1) | |
597 | if not force: |
|
597 | if not force: | |
598 | self.check_localchanges(repo) |
|
598 | self.check_localchanges(repo) | |
599 |
|
599 | |||
600 | self.applied_dirty = 1; |
|
600 | self.applied_dirty = 1; | |
601 | start = self.series_end() |
|
601 | start = self.series_end() | |
602 | if start > 0: |
|
602 | if start > 0: | |
603 | self.check_toppatch(repo) |
|
603 | self.check_toppatch(repo) | |
604 | if not patch: |
|
604 | if not patch: | |
605 | patch = self.series[start] |
|
605 | patch = self.series[start] | |
606 | end = start + 1 |
|
606 | end = start + 1 | |
607 | else: |
|
607 | else: | |
608 | end = self.series.index(patch, start) + 1 |
|
608 | end = self.series.index(patch, start) + 1 | |
609 | s = self.series[start:end] |
|
609 | s = self.series[start:end] | |
610 | if mergeq: |
|
610 | if mergeq: | |
611 | ret = self.mergepatch(repo, mergeq, s, wlock) |
|
611 | ret = self.mergepatch(repo, mergeq, s, wlock) | |
612 | else: |
|
612 | else: | |
613 | ret = self.apply(repo, s, list, wlock=wlock) |
|
613 | ret = self.apply(repo, s, list, wlock=wlock) | |
614 | top = self.applied[-1].split(':')[1] |
|
614 | top = self.applied[-1].split(':')[1] | |
615 | if ret[0]: |
|
615 | if ret[0]: | |
616 | self.ui.write("Errors during apply, please fix and refresh %s\n" % |
|
616 | self.ui.write("Errors during apply, please fix and refresh %s\n" % | |
617 | top) |
|
617 | top) | |
618 | else: |
|
618 | else: | |
619 | self.ui.write("Now at: %s\n" % top) |
|
619 | self.ui.write("Now at: %s\n" % top) | |
620 | return ret[0] |
|
620 | return ret[0] | |
621 |
|
621 | |||
622 | def pop(self, repo, patch=None, force=False, update=True, wlock=None): |
|
622 | def pop(self, repo, patch=None, force=False, update=True, wlock=None): | |
623 | def getfile(f, rev): |
|
623 | def getfile(f, rev): | |
624 | t = repo.file(f).read(rev) |
|
624 | t = repo.file(f).read(rev) | |
625 | try: |
|
625 | try: | |
626 | repo.wfile(f, "w").write(t) |
|
626 | repo.wfile(f, "w").write(t) | |
627 | except IOError: |
|
627 | except IOError: | |
628 | try: |
|
628 | try: | |
629 | os.makedirs(os.path.dirname(repo.wjoin(f))) |
|
629 | os.makedirs(os.path.dirname(repo.wjoin(f))) | |
630 | except OSError, err: |
|
630 | except OSError, err: | |
631 | if err.errno != errno.EEXIST: raise |
|
631 | if err.errno != errno.EEXIST: raise | |
632 | repo.wfile(f, "w").write(t) |
|
632 | repo.wfile(f, "w").write(t) | |
633 |
|
633 | |||
634 | if not wlock: |
|
634 | if not wlock: | |
635 | wlock = repo.wlock() |
|
635 | wlock = repo.wlock() | |
636 | if patch: |
|
636 | if patch: | |
637 | # index, rev, patch |
|
637 | # index, rev, patch | |
638 | info = self.isapplied(patch) |
|
638 | info = self.isapplied(patch) | |
639 | if not info: |
|
639 | if not info: | |
640 | patch = self.lookup(patch) |
|
640 | patch = self.lookup(patch) | |
641 | info = self.isapplied(patch) |
|
641 | info = self.isapplied(patch) | |
642 | if not info: |
|
642 | if not info: | |
643 | self.ui.warn("patch %s is not applied\n" % patch) |
|
643 | self.ui.warn("patch %s is not applied\n" % patch) | |
644 | sys.exit(1) |
|
644 | sys.exit(1) | |
645 | if len(self.applied) == 0: |
|
645 | if len(self.applied) == 0: | |
646 | self.ui.warn("No patches applied\n") |
|
646 | self.ui.warn("No patches applied\n") | |
647 | sys.exit(1) |
|
647 | sys.exit(1) | |
648 |
|
648 | |||
649 | if not update: |
|
649 | if not update: | |
650 | parents = repo.dirstate.parents() |
|
650 | parents = repo.dirstate.parents() | |
651 | rr = [ revlog.bin(x.split(':')[0]) for x in self.applied ] |
|
651 | rr = [ revlog.bin(x.split(':')[0]) for x in self.applied ] | |
652 | for p in parents: |
|
652 | for p in parents: | |
653 | if p in rr: |
|
653 | if p in rr: | |
654 | self.ui.warn("qpop: forcing dirstate update\n") |
|
654 | self.ui.warn("qpop: forcing dirstate update\n") | |
655 | update = True |
|
655 | update = True | |
656 |
|
656 | |||
657 | if not force and update: |
|
657 | if not force and update: | |
658 | self.check_localchanges(repo) |
|
658 | self.check_localchanges(repo) | |
659 |
|
659 | |||
660 | self.applied_dirty = 1; |
|
660 | self.applied_dirty = 1; | |
661 | end = len(self.applied) |
|
661 | end = len(self.applied) | |
662 | if not patch: |
|
662 | if not patch: | |
663 | info = [len(self.applied) - 1] + self.applied[-1].split(':') |
|
663 | info = [len(self.applied) - 1] + self.applied[-1].split(':') | |
664 | start = info[0] |
|
664 | start = info[0] | |
665 | rev = revlog.bin(info[1]) |
|
665 | rev = revlog.bin(info[1]) | |
666 |
|
666 | |||
667 | # we know there are no local changes, so we can make a simplified |
|
667 | # we know there are no local changes, so we can make a simplified | |
668 | # form of hg.update. |
|
668 | # form of hg.update. | |
669 | if update: |
|
669 | if update: | |
670 | top = self.check_toppatch(repo) |
|
670 | top = self.check_toppatch(repo) | |
671 | qp = self.qparents(repo, rev) |
|
671 | qp = self.qparents(repo, rev) | |
672 | changes = repo.changelog.read(qp) |
|
672 | changes = repo.changelog.read(qp) | |
673 | mf1 = repo.manifest.readflags(changes[0]) |
|
673 | mf1 = repo.manifest.readflags(changes[0]) | |
674 | mmap = repo.manifest.read(changes[0]) |
|
674 | mmap = repo.manifest.read(changes[0]) | |
675 | (c, a, r, d, u) = repo.changes(qp, top) |
|
675 | (c, a, r, d, u) = repo.changes(qp, top) | |
676 | if d: |
|
676 | if d: | |
677 | raise util.Abort("deletions found between repo revs") |
|
677 | raise util.Abort("deletions found between repo revs") | |
678 | for f in c: |
|
678 | for f in c: | |
679 | getfile(f, mmap[f]) |
|
679 | getfile(f, mmap[f]) | |
680 | for f in r: |
|
680 | for f in r: | |
681 | getfile(f, mmap[f]) |
|
681 | getfile(f, mmap[f]) | |
682 | util.set_exec(repo.wjoin(f), mf1[f]) |
|
682 | util.set_exec(repo.wjoin(f), mf1[f]) | |
683 | repo.dirstate.update(c + r, 'n') |
|
683 | repo.dirstate.update(c + r, 'n') | |
684 | for f in a: |
|
684 | for f in a: | |
685 | try: os.unlink(repo.wjoin(f)) |
|
685 | try: os.unlink(repo.wjoin(f)) | |
686 | except: raise |
|
686 | except: raise | |
687 | try: os.removedirs(os.path.dirname(repo.wjoin(f))) |
|
687 | try: os.removedirs(os.path.dirname(repo.wjoin(f))) | |
688 | except: pass |
|
688 | except: pass | |
689 | if a: |
|
689 | if a: | |
690 | repo.dirstate.forget(a) |
|
690 | repo.dirstate.forget(a) | |
691 | repo.dirstate.setparents(qp, revlog.nullid) |
|
691 | repo.dirstate.setparents(qp, revlog.nullid) | |
692 | self.strip(repo, rev, update=False, backup='strip', wlock=wlock) |
|
692 | self.strip(repo, rev, update=False, backup='strip', wlock=wlock) | |
693 | del self.applied[start:end] |
|
693 | del self.applied[start:end] | |
694 | if len(self.applied): |
|
694 | if len(self.applied): | |
695 | self.ui.write("Now at: %s\n" % self.applied[-1].split(':')[1]) |
|
695 | self.ui.write("Now at: %s\n" % self.applied[-1].split(':')[1]) | |
696 | else: |
|
696 | else: | |
697 | self.ui.write("Patch queue now empty\n") |
|
697 | self.ui.write("Patch queue now empty\n") | |
698 |
|
698 | |||
699 | def diff(self, repo, files): |
|
699 | def diff(self, repo, files): | |
700 | top = self.check_toppatch(repo) |
|
700 | top = self.check_toppatch(repo) | |
701 | if not top: |
|
701 | if not top: | |
702 | self.ui.write("No patches applied\n") |
|
702 | self.ui.write("No patches applied\n") | |
703 | return |
|
703 | return | |
704 | qp = self.qparents(repo, top) |
|
704 | qp = self.qparents(repo, top) | |
705 | commands.dodiff(sys.stdout, self.ui, repo, qp, None, files) |
|
705 | commands.dodiff(sys.stdout, self.ui, repo, qp, None, files) | |
706 |
|
706 | |||
707 | def refresh(self, repo, short=False): |
|
707 | def refresh(self, repo, short=False): | |
708 | if len(self.applied) == 0: |
|
708 | if len(self.applied) == 0: | |
709 | self.ui.write("No patches applied\n") |
|
709 | self.ui.write("No patches applied\n") | |
710 | return |
|
710 | return | |
711 | wlock = repo.wlock() |
|
711 | wlock = repo.wlock() | |
712 | self.check_toppatch(repo) |
|
712 | self.check_toppatch(repo) | |
713 | qp = self.qparents(repo) |
|
713 | qp = self.qparents(repo) | |
714 | (top, patch) = self.applied[-1].split(':') |
|
714 | (top, patch) = self.applied[-1].split(':') | |
715 | top = revlog.bin(top) |
|
715 | top = revlog.bin(top) | |
716 | cparents = repo.changelog.parents(top) |
|
716 | cparents = repo.changelog.parents(top) | |
717 | patchparent = self.qparents(repo, top) |
|
717 | patchparent = self.qparents(repo, top) | |
718 | message, comments, user, patchfound = self.readheaders(patch) |
|
718 | message, comments, user, patchfound = self.readheaders(patch) | |
719 |
|
719 | |||
720 | patchf = self.opener(patch, "w") |
|
720 | patchf = self.opener(patch, "w") | |
721 | if comments: |
|
721 | if comments: | |
722 | comments = "\n".join(comments) + '\n\n' |
|
722 | comments = "\n".join(comments) + '\n\n' | |
723 | patchf.write(comments) |
|
723 | patchf.write(comments) | |
724 |
|
724 | |||
725 | tip = repo.changelog.tip() |
|
725 | tip = repo.changelog.tip() | |
726 | if top == tip: |
|
726 | if top == tip: | |
727 | # if the top of our patch queue is also the tip, there is an |
|
727 | # if the top of our patch queue is also the tip, there is an | |
728 | # optimization here. We update the dirstate in place and strip |
|
728 | # optimization here. We update the dirstate in place and strip | |
729 | # off the tip commit. Then just commit the current directory |
|
729 | # off the tip commit. Then just commit the current directory | |
730 | # tree. We can also send repo.commit the list of files |
|
730 | # tree. We can also send repo.commit the list of files | |
731 | # changed to speed up the diff |
|
731 | # changed to speed up the diff | |
732 | # |
|
732 | # | |
733 | # in short mode, we only diff the files included in the |
|
733 | # in short mode, we only diff the files included in the | |
734 | # patch already |
|
734 | # patch already | |
735 | # |
|
735 | # | |
736 | # this should really read: |
|
736 | # this should really read: | |
737 | #(cc, dd, aa, aa2, uu) = repo.changes(tip, patchparent) |
|
737 | #(cc, dd, aa, aa2, uu) = repo.changes(tip, patchparent) | |
738 | # but we do it backwards to take advantage of manifest/chlog |
|
738 | # but we do it backwards to take advantage of manifest/chlog | |
739 | # caching against the next repo.changes call |
|
739 | # caching against the next repo.changes call | |
740 | # |
|
740 | # | |
741 | (cc, aa, dd, aa2, uu) = repo.changes(patchparent, tip) |
|
741 | (cc, aa, dd, aa2, uu) = repo.changes(patchparent, tip) | |
742 | if short: |
|
742 | if short: | |
743 | filelist = cc + aa + dd |
|
743 | filelist = cc + aa + dd | |
744 | else: |
|
744 | else: | |
745 | filelist = None |
|
745 | filelist = None | |
746 | (c, a, r, d, u) = repo.changes(None, None, filelist) |
|
746 | (c, a, r, d, u) = repo.changes(None, None, filelist) | |
747 |
|
747 | |||
748 | # we might end up with files that were added between tip and |
|
748 | # we might end up with files that were added between tip and | |
749 | # the dirstate parent, but then changed in the local dirstate. |
|
749 | # the dirstate parent, but then changed in the local dirstate. | |
750 | # in this case, we want them to only show up in the added section |
|
750 | # in this case, we want them to only show up in the added section | |
751 | for x in c: |
|
751 | for x in c: | |
752 | if x not in aa: |
|
752 | if x not in aa: | |
753 | cc.append(x) |
|
753 | cc.append(x) | |
754 | # we might end up with files added by the local dirstate that |
|
754 | # we might end up with files added by the local dirstate that | |
755 | # were deleted by the patch. In this case, they should only |
|
755 | # were deleted by the patch. In this case, they should only | |
756 | # show up in the changed section. |
|
756 | # show up in the changed section. | |
757 | for x in a: |
|
757 | for x in a: | |
758 | if x in dd: |
|
758 | if x in dd: | |
759 | del dd[dd.index(x)] |
|
759 | del dd[dd.index(x)] | |
760 | cc.append(x) |
|
760 | cc.append(x) | |
761 | else: |
|
761 | else: | |
762 | aa.append(x) |
|
762 | aa.append(x) | |
763 | # make sure any files deleted in the local dirstate |
|
763 | # make sure any files deleted in the local dirstate | |
764 | # are not in the add or change column of the patch |
|
764 | # are not in the add or change column of the patch | |
765 | forget = [] |
|
765 | forget = [] | |
766 | for x in d + r: |
|
766 | for x in d + r: | |
767 | if x in aa: |
|
767 | if x in aa: | |
768 | del aa[aa.index(x)] |
|
768 | del aa[aa.index(x)] | |
769 | forget.append(x) |
|
769 | forget.append(x) | |
770 | continue |
|
770 | continue | |
771 | elif x in cc: |
|
771 | elif x in cc: | |
772 | del cc[cc.index(x)] |
|
772 | del cc[cc.index(x)] | |
773 | dd.append(x) |
|
773 | dd.append(x) | |
774 |
|
774 | |||
775 | c = list(util.unique(cc)) |
|
775 | c = list(util.unique(cc)) | |
776 | r = list(util.unique(dd)) |
|
776 | r = list(util.unique(dd)) | |
777 | a = list(util.unique(aa)) |
|
777 | a = list(util.unique(aa)) | |
778 | filelist = list(util.unique(c + r + a )) |
|
778 | filelist = list(util.unique(c + r + a )) | |
779 | commands.dodiff(patchf, self.ui, repo, patchparent, None, |
|
779 | commands.dodiff(patchf, self.ui, repo, patchparent, None, | |
780 | filelist, changes=(c, a, r, [], u)) |
|
780 | filelist, changes=(c, a, r, [], u)) | |
781 | patchf.close() |
|
781 | patchf.close() | |
782 |
|
782 | |||
783 | changes = repo.changelog.read(tip) |
|
783 | changes = repo.changelog.read(tip) | |
784 | repo.dirstate.setparents(*cparents) |
|
784 | repo.dirstate.setparents(*cparents) | |
785 | repo.dirstate.update(a, 'a') |
|
785 | repo.dirstate.update(a, 'a') | |
786 | repo.dirstate.update(r, 'r') |
|
786 | repo.dirstate.update(r, 'r') | |
787 | repo.dirstate.update(c, 'n') |
|
787 | repo.dirstate.update(c, 'n') | |
788 | repo.dirstate.forget(forget) |
|
788 | repo.dirstate.forget(forget) | |
789 |
|
789 | |||
790 | if not message: |
|
790 | if not message: | |
791 | message = "patch queue: %s\n" % patch |
|
791 | message = "patch queue: %s\n" % patch | |
792 | else: |
|
792 | else: | |
793 | message = "\n".join(message) |
|
793 | message = "\n".join(message) | |
794 | self.strip(repo, top, update=False, backup='strip', wlock=wlock) |
|
794 | self.strip(repo, top, update=False, backup='strip', wlock=wlock) | |
795 | n = repo.commit(filelist, message, changes[1], force=1, wlock=wlock) |
|
795 | n = repo.commit(filelist, message, changes[1], force=1, wlock=wlock) | |
796 | self.applied[-1] = revlog.hex(n) + ':' + patch |
|
796 | self.applied[-1] = revlog.hex(n) + ':' + patch | |
797 | self.applied_dirty = 1 |
|
797 | self.applied_dirty = 1 | |
798 | else: |
|
798 | else: | |
799 | commands.dodiff(patchf, self.ui, repo, patchparent, None) |
|
799 | commands.dodiff(patchf, self.ui, repo, patchparent, None) | |
800 | patchf.close() |
|
800 | patchf.close() | |
801 | self.pop(repo, force=True, wlock=wlock) |
|
801 | self.pop(repo, force=True, wlock=wlock) | |
802 | self.push(repo, force=True, wlock=wlock) |
|
802 | self.push(repo, force=True, wlock=wlock) | |
803 |
|
803 | |||
804 | def init(self, repo, create=False): |
|
804 | def init(self, repo, create=False): | |
805 | if os.path.isdir(self.path): |
|
805 | if os.path.isdir(self.path): | |
806 | raise util.Abort("patch queue directory already exists") |
|
806 | raise util.Abort("patch queue directory already exists") | |
807 | os.mkdir(self.path) |
|
807 | os.mkdir(self.path) | |
808 | if create: |
|
808 | if create: | |
809 | return self.qrepo(create=True) |
|
809 | return self.qrepo(create=True) | |
810 |
|
810 | |||
811 | def unapplied(self, repo, patch=None): |
|
811 | def unapplied(self, repo, patch=None): | |
812 | if patch and patch not in self.series: |
|
812 | if patch and patch not in self.series: | |
813 | self.ui.warn("%s not in the series file\n" % patch) |
|
813 | self.ui.warn("%s not in the series file\n" % patch) | |
814 | sys.exit(1) |
|
814 | sys.exit(1) | |
815 | if not patch: |
|
815 | if not patch: | |
816 | start = self.series_end() |
|
816 | start = self.series_end() | |
817 | else: |
|
817 | else: | |
818 | start = self.series.index(patch) + 1 |
|
818 | start = self.series.index(patch) + 1 | |
819 | for p in self.series[start:]: |
|
819 | for p in self.series[start:]: | |
820 | self.ui.write("%s\n" % p) |
|
820 | self.ui.write("%s\n" % p) | |
821 |
|
821 | |||
822 | def qseries(self, repo, missing=None): |
|
822 | def qseries(self, repo, missing=None): | |
823 | start = self.series_end() |
|
823 | start = self.series_end() | |
824 | if not missing: |
|
824 | if not missing: | |
825 | for p in self.series[:start]: |
|
825 | for p in self.series[:start]: | |
826 | if self.ui.verbose: |
|
826 | if self.ui.verbose: | |
827 | self.ui.write("%d A " % self.series.index(p)) |
|
827 | self.ui.write("%d A " % self.series.index(p)) | |
828 | self.ui.write("%s\n" % p) |
|
828 | self.ui.write("%s\n" % p) | |
829 | for p in self.series[start:]: |
|
829 | for p in self.series[start:]: | |
830 | if self.ui.verbose: |
|
830 | if self.ui.verbose: | |
831 | self.ui.write("%d U " % self.series.index(p)) |
|
831 | self.ui.write("%d U " % self.series.index(p)) | |
832 | self.ui.write("%s\n" % p) |
|
832 | self.ui.write("%s\n" % p) | |
833 | else: |
|
833 | else: | |
834 | list = [] |
|
834 | list = [] | |
835 | for root, dirs, files in os.walk(self.path): |
|
835 | for root, dirs, files in os.walk(self.path): | |
836 | d = root[len(self.path) + 1:] |
|
836 | d = root[len(self.path) + 1:] | |
837 | for f in files: |
|
837 | for f in files: | |
838 | fl = os.path.join(d, f) |
|
838 | fl = os.path.join(d, f) | |
839 | if (fl not in self.series and |
|
839 | if (fl not in self.series and | |
840 | fl not in (self.status_path, self.series_path) |
|
840 | fl not in (self.status_path, self.series_path) | |
841 | and not fl.startswith('.')): |
|
841 | and not fl.startswith('.')): | |
842 | list.append(fl) |
|
842 | list.append(fl) | |
843 | list.sort() |
|
843 | list.sort() | |
844 | if list: |
|
844 | if list: | |
845 | for x in list: |
|
845 | for x in list: | |
846 | if self.ui.verbose: |
|
846 | if self.ui.verbose: | |
847 | self.ui.write("D ") |
|
847 | self.ui.write("D ") | |
848 | self.ui.write("%s\n" % x) |
|
848 | self.ui.write("%s\n" % x) | |
849 |
|
849 | |||
850 | def issaveline(self, l): |
|
850 | def issaveline(self, l): | |
851 | name = l.split(':')[1] |
|
851 | name = l.split(':')[1] | |
852 | if name == '.hg.patches.save.line': |
|
852 | if name == '.hg.patches.save.line': | |
853 | return True |
|
853 | return True | |
854 |
|
854 | |||
855 | def qrepo(self, create=False): |
|
855 | def qrepo(self, create=False): | |
856 | if create or os.path.isdir(os.path.join(self.path, ".hg")): |
|
856 | if create or os.path.isdir(os.path.join(self.path, ".hg")): | |
857 | return hg.repository(self.ui, path=self.path, create=create) |
|
857 | return hg.repository(self.ui, path=self.path, create=create) | |
858 |
|
858 | |||
859 | def restore(self, repo, rev, delete=None, qupdate=None): |
|
859 | def restore(self, repo, rev, delete=None, qupdate=None): | |
860 | c = repo.changelog.read(rev) |
|
860 | c = repo.changelog.read(rev) | |
861 | desc = c[4].strip() |
|
861 | desc = c[4].strip() | |
862 | lines = desc.splitlines() |
|
862 | lines = desc.splitlines() | |
863 | i = 0 |
|
863 | i = 0 | |
864 | datastart = None |
|
864 | datastart = None | |
865 | series = [] |
|
865 | series = [] | |
866 | applied = [] |
|
866 | applied = [] | |
867 | qpp = None |
|
867 | qpp = None | |
868 | for i in xrange(0, len(lines)): |
|
868 | for i in xrange(0, len(lines)): | |
869 | if lines[i] == 'Patch Data:': |
|
869 | if lines[i] == 'Patch Data:': | |
870 | datastart = i + 1 |
|
870 | datastart = i + 1 | |
871 | elif lines[i].startswith('Dirstate:'): |
|
871 | elif lines[i].startswith('Dirstate:'): | |
872 | l = lines[i].rstrip() |
|
872 | l = lines[i].rstrip() | |
873 | l = l[10:].split(' ') |
|
873 | l = l[10:].split(' ') | |
874 | qpp = [ hg.bin(x) for x in l ] |
|
874 | qpp = [ hg.bin(x) for x in l ] | |
875 | elif datastart != None: |
|
875 | elif datastart != None: | |
876 | l = lines[i].rstrip() |
|
876 | l = lines[i].rstrip() | |
877 | index = l.index(':') |
|
877 | index = l.index(':') | |
878 | id = l[:index] |
|
878 | id = l[:index] | |
879 | file = l[index + 1:] |
|
879 | file = l[index + 1:] | |
880 | if id: |
|
880 | if id: | |
881 | applied.append(l) |
|
881 | applied.append(l) | |
882 | series.append(file) |
|
882 | series.append(file) | |
883 | if datastart == None: |
|
883 | if datastart == None: | |
884 | self.ui.warn("No saved patch data found\n") |
|
884 | self.ui.warn("No saved patch data found\n") | |
885 | return 1 |
|
885 | return 1 | |
886 | self.ui.warn("restoring status: %s\n" % lines[0]) |
|
886 | self.ui.warn("restoring status: %s\n" % lines[0]) | |
887 | self.full_series = series |
|
887 | self.full_series = series | |
888 | self.applied = applied |
|
888 | self.applied = applied | |
889 | self.read_series(self.full_series) |
|
889 | self.read_series(self.full_series) | |
890 | self.series_dirty = 1 |
|
890 | self.series_dirty = 1 | |
891 | self.applied_dirty = 1 |
|
891 | self.applied_dirty = 1 | |
892 | heads = repo.changelog.heads() |
|
892 | heads = repo.changelog.heads() | |
893 | if delete: |
|
893 | if delete: | |
894 | if rev not in heads: |
|
894 | if rev not in heads: | |
895 | self.ui.warn("save entry has children, leaving it alone\n") |
|
895 | self.ui.warn("save entry has children, leaving it alone\n") | |
896 | else: |
|
896 | else: | |
897 | self.ui.warn("removing save entry %s\n" % hg.short(rev)) |
|
897 | self.ui.warn("removing save entry %s\n" % hg.short(rev)) | |
898 | pp = repo.dirstate.parents() |
|
898 | pp = repo.dirstate.parents() | |
899 | if rev in pp: |
|
899 | if rev in pp: | |
900 | update = True |
|
900 | update = True | |
901 | else: |
|
901 | else: | |
902 | update = False |
|
902 | update = False | |
903 | self.strip(repo, rev, update=update, backup='strip') |
|
903 | self.strip(repo, rev, update=update, backup='strip') | |
904 | if qpp: |
|
904 | if qpp: | |
905 | self.ui.warn("saved queue repository parents: %s %s\n" % |
|
905 | self.ui.warn("saved queue repository parents: %s %s\n" % | |
906 | (hg.short(qpp[0]), hg.short(qpp[1]))) |
|
906 | (hg.short(qpp[0]), hg.short(qpp[1]))) | |
907 | if qupdate: |
|
907 | if qupdate: | |
908 | print "queue directory updating" |
|
908 | print "queue directory updating" | |
909 | r = self.qrepo() |
|
909 | r = self.qrepo() | |
910 | if not r: |
|
910 | if not r: | |
911 | self.ui.warn("Unable to load queue repository\n") |
|
911 | self.ui.warn("Unable to load queue repository\n") | |
912 | return 1 |
|
912 | return 1 | |
913 | r.update(qpp[0], allow=False, force=True) |
|
913 | r.update(qpp[0], allow=False, force=True) | |
914 |
|
914 | |||
915 | def save(self, repo, msg=None): |
|
915 | def save(self, repo, msg=None): | |
916 | if len(self.applied) == 0: |
|
916 | if len(self.applied) == 0: | |
917 | self.ui.warn("save: no patches applied, exiting\n") |
|
917 | self.ui.warn("save: no patches applied, exiting\n") | |
918 | return 1 |
|
918 | return 1 | |
919 | if self.issaveline(self.applied[-1]): |
|
919 | if self.issaveline(self.applied[-1]): | |
920 | self.ui.warn("status is already saved\n") |
|
920 | self.ui.warn("status is already saved\n") | |
921 | return 1 |
|
921 | return 1 | |
922 |
|
922 | |||
923 | ar = [ ':' + x for x in self.full_series ] |
|
923 | ar = [ ':' + x for x in self.full_series ] | |
924 | if not msg: |
|
924 | if not msg: | |
925 | msg = "hg patches saved state" |
|
925 | msg = "hg patches saved state" | |
926 | else: |
|
926 | else: | |
927 | msg = "hg patches: " + msg.rstrip('\r\n') |
|
927 | msg = "hg patches: " + msg.rstrip('\r\n') | |
928 | r = self.qrepo() |
|
928 | r = self.qrepo() | |
929 | if r: |
|
929 | if r: | |
930 | pp = r.dirstate.parents() |
|
930 | pp = r.dirstate.parents() | |
931 | msg += "\nDirstate: %s %s" % (hg.hex(pp[0]), hg.hex(pp[1])) |
|
931 | msg += "\nDirstate: %s %s" % (hg.hex(pp[0]), hg.hex(pp[1])) | |
932 | msg += "\n\nPatch Data:\n" |
|
932 | msg += "\n\nPatch Data:\n" | |
933 | text = msg + "\n".join(self.applied) + '\n' + (ar and "\n".join(ar) |
|
933 | text = msg + "\n".join(self.applied) + '\n' + (ar and "\n".join(ar) | |
934 | + '\n' or "") |
|
934 | + '\n' or "") | |
935 | n = repo.commit(None, text, user=None, force=1) |
|
935 | n = repo.commit(None, text, user=None, force=1) | |
936 | if not n: |
|
936 | if not n: | |
937 | self.ui.warn("repo commit failed\n") |
|
937 | self.ui.warn("repo commit failed\n") | |
938 | return 1 |
|
938 | return 1 | |
939 | self.applied.append(revlog.hex(n) + ":" + '.hg.patches.save.line') |
|
939 | self.applied.append(revlog.hex(n) + ":" + '.hg.patches.save.line') | |
940 | self.applied_dirty = 1 |
|
940 | self.applied_dirty = 1 | |
941 |
|
941 | |||
942 | def series_end(self): |
|
942 | def series_end(self): | |
943 | end = 0 |
|
943 | end = 0 | |
944 | if len(self.applied) > 0: |
|
944 | if len(self.applied) > 0: | |
945 | (top, p) = self.applied[-1].split(':') |
|
945 | (top, p) = self.applied[-1].split(':') | |
946 | try: |
|
946 | try: | |
947 | end = self.series.index(p) |
|
947 | end = self.series.index(p) | |
948 | except ValueError: |
|
948 | except ValueError: | |
949 | return 0 |
|
949 | return 0 | |
950 | return end + 1 |
|
950 | return end + 1 | |
951 | return end |
|
951 | return end | |
952 |
|
952 | |||
953 | def qapplied(self, repo, patch=None): |
|
953 | def qapplied(self, repo, patch=None): | |
954 | if patch and patch not in self.series: |
|
954 | if patch and patch not in self.series: | |
955 | self.ui.warn("%s not in the series file\n" % patch) |
|
955 | self.ui.warn("%s not in the series file\n" % patch) | |
956 | sys.exit(1) |
|
956 | sys.exit(1) | |
957 | if not patch: |
|
957 | if not patch: | |
958 | end = len(self.applied) |
|
958 | end = len(self.applied) | |
959 | else: |
|
959 | else: | |
960 | end = self.series.index(patch) + 1 |
|
960 | end = self.series.index(patch) + 1 | |
961 | for x in xrange(end): |
|
961 | for x in xrange(end): | |
962 | p = self.appliedname(x) |
|
962 | p = self.appliedname(x) | |
963 | self.ui.write("%s\n" % p) |
|
963 | self.ui.write("%s\n" % p) | |
964 |
|
964 | |||
965 | def appliedname(self, index): |
|
965 | def appliedname(self, index): | |
966 | p = self.applied[index] |
|
966 | p = self.applied[index] | |
967 | if not self.ui.verbose: |
|
967 | if not self.ui.verbose: | |
968 | p = p.split(':')[1] |
|
968 | p = p.split(':')[1] | |
969 | return p |
|
969 | return p | |
970 |
|
970 | |||
971 | def top(self, repo): |
|
971 | def top(self, repo): | |
972 | if len(self.applied): |
|
972 | if len(self.applied): | |
973 | p = self.appliedname(-1) |
|
973 | p = self.appliedname(-1) | |
974 | self.ui.write(p + '\n') |
|
974 | self.ui.write(p + '\n') | |
975 | else: |
|
975 | else: | |
976 | self.ui.write("No patches applied\n") |
|
976 | self.ui.write("No patches applied\n") | |
977 |
|
977 | |||
978 | def next(self, repo): |
|
978 | def next(self, repo): | |
979 | end = self.series_end() |
|
979 | end = self.series_end() | |
980 | if end == len(self.series): |
|
980 | if end == len(self.series): | |
981 | self.ui.write("All patches applied\n") |
|
981 | self.ui.write("All patches applied\n") | |
982 | else: |
|
982 | else: | |
983 | self.ui.write(self.series[end] + '\n') |
|
983 | self.ui.write(self.series[end] + '\n') | |
984 |
|
984 | |||
985 | def prev(self, repo): |
|
985 | def prev(self, repo): | |
986 | if len(self.applied) > 1: |
|
986 | if len(self.applied) > 1: | |
987 | p = self.appliedname(-2) |
|
987 | p = self.appliedname(-2) | |
988 | self.ui.write(p + '\n') |
|
988 | self.ui.write(p + '\n') | |
989 | elif len(self.applied) == 1: |
|
989 | elif len(self.applied) == 1: | |
990 | self.ui.write("Only one patch applied\n") |
|
990 | self.ui.write("Only one patch applied\n") | |
991 | else: |
|
991 | else: | |
992 | self.ui.write("No patches applied\n") |
|
992 | self.ui.write("No patches applied\n") | |
993 |
|
993 | |||
994 | def qimport(self, repo, files, patch=None, existing=None, force=None): |
|
994 | def qimport(self, repo, files, patch=None, existing=None, force=None): | |
995 | if len(files) > 1 and patch: |
|
995 | if len(files) > 1 and patch: | |
996 | self.ui.warn("-n option not valid when importing multiple files\n") |
|
996 | self.ui.warn("-n option not valid when importing multiple files\n") | |
997 | sys.exit(1) |
|
997 | sys.exit(1) | |
998 | i = 0 |
|
998 | i = 0 | |
999 | for filename in files: |
|
999 | for filename in files: | |
1000 | if existing: |
|
1000 | if existing: | |
1001 | if not patch: |
|
1001 | if not patch: | |
1002 | patch = filename |
|
1002 | patch = filename | |
1003 | if not os.path.isfile(os.path.join(self.path, patch)): |
|
1003 | if not os.path.isfile(os.path.join(self.path, patch)): | |
1004 | self.ui.warn("patch %s does not exist\n" % patch) |
|
1004 | self.ui.warn("patch %s does not exist\n" % patch) | |
1005 | sys.exit(1) |
|
1005 | sys.exit(1) | |
1006 | else: |
|
1006 | else: | |
1007 | try: |
|
1007 | try: | |
1008 | text = file(filename).read() |
|
1008 | text = file(filename).read() | |
1009 | except IOError: |
|
1009 | except IOError: | |
1010 | self.ui.warn("Unable to read %s\n" % patch) |
|
1010 | self.ui.warn("Unable to read %s\n" % patch) | |
1011 | sys.exit(1) |
|
1011 | sys.exit(1) | |
1012 | if not patch: |
|
1012 | if not patch: | |
1013 | patch = os.path.split(filename)[1] |
|
1013 | patch = os.path.split(filename)[1] | |
1014 | if not force and os.path.isfile(os.path.join(self.path, patch)): |
|
1014 | if not force and os.path.isfile(os.path.join(self.path, patch)): | |
1015 | self.ui.warn("patch %s already exists\n" % patch) |
|
1015 | self.ui.warn("patch %s already exists\n" % patch) | |
1016 | sys.exit(1) |
|
1016 | sys.exit(1) | |
1017 | patchf = self.opener(patch, "w") |
|
1017 | patchf = self.opener(patch, "w") | |
1018 | patchf.write(text) |
|
1018 | patchf.write(text) | |
1019 | if patch in self.series: |
|
1019 | if patch in self.series: | |
1020 | self.ui.warn("patch %s is already in the series file\n" % patch) |
|
1020 | self.ui.warn("patch %s is already in the series file\n" % patch) | |
1021 | sys.exit(1) |
|
1021 | sys.exit(1) | |
1022 | index = self.series_end() + i |
|
1022 | index = self.series_end() + i | |
1023 | self.full_series[index:index] = [patch] |
|
1023 | self.full_series[index:index] = [patch] | |
1024 | self.read_series(self.full_series) |
|
1024 | self.read_series(self.full_series) | |
1025 | self.ui.warn("adding %s to series file\n" % patch) |
|
1025 | self.ui.warn("adding %s to series file\n" % patch) | |
1026 | i += 1 |
|
1026 | i += 1 | |
1027 | patch = None |
|
1027 | patch = None | |
1028 | self.series_dirty = 1 |
|
1028 | self.series_dirty = 1 | |
1029 |
|
1029 | |||
1030 | def delete(ui, repo, patch, **opts): |
|
1030 | def delete(ui, repo, patch, **opts): | |
1031 | """remove a patch from the series file""" |
|
1031 | """remove a patch from the series file""" | |
1032 | q = repomap[repo] |
|
1032 | q = repomap[repo] | |
1033 | q.delete(repo, patch) |
|
1033 | q.delete(repo, patch) | |
1034 | q.save_dirty() |
|
1034 | q.save_dirty() | |
1035 | return 0 |
|
1035 | return 0 | |
1036 |
|
1036 | |||
1037 | def applied(ui, repo, patch=None, **opts): |
|
1037 | def applied(ui, repo, patch=None, **opts): | |
1038 | """print the patches already applied""" |
|
1038 | """print the patches already applied""" | |
1039 | repomap[repo].qapplied(repo, patch) |
|
1039 | repomap[repo].qapplied(repo, patch) | |
1040 | return 0 |
|
1040 | return 0 | |
1041 |
|
1041 | |||
1042 | def unapplied(ui, repo, patch=None, **opts): |
|
1042 | def unapplied(ui, repo, patch=None, **opts): | |
1043 | """print the patches not yet applied""" |
|
1043 | """print the patches not yet applied""" | |
1044 | repomap[repo].unapplied(repo, patch) |
|
1044 | repomap[repo].unapplied(repo, patch) | |
1045 | return 0 |
|
1045 | return 0 | |
1046 |
|
1046 | |||
1047 | def qimport(ui, repo, *filename, **opts): |
|
1047 | def qimport(ui, repo, *filename, **opts): | |
1048 | """import a patch""" |
|
1048 | """import a patch""" | |
1049 | q = repomap[repo] |
|
1049 | q = repomap[repo] | |
1050 | q.qimport(repo, filename, patch=opts['name'], |
|
1050 | q.qimport(repo, filename, patch=opts['name'], | |
1051 | existing=opts['existing'], force=opts['force']) |
|
1051 | existing=opts['existing'], force=opts['force']) | |
1052 | q.save_dirty() |
|
1052 | q.save_dirty() | |
1053 | return 0 |
|
1053 | return 0 | |
1054 |
|
1054 | |||
1055 | def init(ui, repo, **opts): |
|
1055 | def init(ui, repo, **opts): | |
1056 | """init a new queue repository""" |
|
1056 | """init a new queue repository""" | |
1057 | q = repomap[repo] |
|
1057 | q = repomap[repo] | |
1058 | r = q.init(repo, create=opts['create_repo']) |
|
1058 | r = q.init(repo, create=opts['create_repo']) | |
1059 | q.save_dirty() |
|
1059 | q.save_dirty() | |
1060 | if r: |
|
1060 | if r: | |
1061 | fp = r.wopener('.hgignore', 'w') |
|
1061 | fp = r.wopener('.hgignore', 'w') | |
1062 | print >> fp, 'syntax: glob' |
|
1062 | print >> fp, 'syntax: glob' | |
1063 | print >> fp, 'status' |
|
1063 | print >> fp, 'status' | |
1064 | fp.close() |
|
1064 | fp.close() | |
1065 | r.wopener('series', 'w').close() |
|
1065 | r.wopener('series', 'w').close() | |
1066 | r.add(['.hgignore', 'series']) |
|
1066 | r.add(['.hgignore', 'series']) | |
1067 | return 0 |
|
1067 | return 0 | |
1068 |
|
1068 | |||
1069 | def commit(ui, repo, *pats, **opts): |
|
1069 | def commit(ui, repo, *pats, **opts): | |
1070 | q = repomap[repo] |
|
1070 | q = repomap[repo] | |
1071 | r = q.qrepo() |
|
1071 | r = q.qrepo() | |
1072 | if not r: raise util.Abort('no queue repository') |
|
1072 | if not r: raise util.Abort('no queue repository') | |
1073 | commands.commit(r.ui, r, *pats, **opts) |
|
1073 | commands.commit(r.ui, r, *pats, **opts) | |
1074 |
|
1074 | |||
1075 | def series(ui, repo, **opts): |
|
1075 | def series(ui, repo, **opts): | |
1076 | """print the entire series file""" |
|
1076 | """print the entire series file""" | |
1077 | repomap[repo].qseries(repo, missing=opts['missing']) |
|
1077 | repomap[repo].qseries(repo, missing=opts['missing']) | |
1078 | return 0 |
|
1078 | return 0 | |
1079 |
|
1079 | |||
1080 | def top(ui, repo, **opts): |
|
1080 | def top(ui, repo, **opts): | |
1081 | """print the name of the current patch""" |
|
1081 | """print the name of the current patch""" | |
1082 | repomap[repo].top(repo) |
|
1082 | repomap[repo].top(repo) | |
1083 | return 0 |
|
1083 | return 0 | |
1084 |
|
1084 | |||
1085 | def next(ui, repo, **opts): |
|
1085 | def next(ui, repo, **opts): | |
1086 | """print the name of the next patch""" |
|
1086 | """print the name of the next patch""" | |
1087 | repomap[repo].next(repo) |
|
1087 | repomap[repo].next(repo) | |
1088 | return 0 |
|
1088 | return 0 | |
1089 |
|
1089 | |||
1090 | def prev(ui, repo, **opts): |
|
1090 | def prev(ui, repo, **opts): | |
1091 | """print the name of the previous patch""" |
|
1091 | """print the name of the previous patch""" | |
1092 | repomap[repo].prev(repo) |
|
1092 | repomap[repo].prev(repo) | |
1093 | return 0 |
|
1093 | return 0 | |
1094 |
|
1094 | |||
1095 | def new(ui, repo, patch, **opts): |
|
1095 | def new(ui, repo, patch, **opts): | |
1096 | """create a new patch""" |
|
1096 | """create a new patch""" | |
1097 | q = repomap[repo] |
|
1097 | q = repomap[repo] | |
1098 | q.new(repo, patch, msg=opts['message'], force=opts['force']) |
|
1098 | q.new(repo, patch, msg=opts['message'], force=opts['force']) | |
1099 | q.save_dirty() |
|
1099 | q.save_dirty() | |
1100 | return 0 |
|
1100 | return 0 | |
1101 |
|
1101 | |||
1102 | def refresh(ui, repo, **opts): |
|
1102 | def refresh(ui, repo, **opts): | |
1103 | """update the current patch""" |
|
1103 | """update the current patch""" | |
1104 | q = repomap[repo] |
|
1104 | q = repomap[repo] | |
1105 | q.refresh(repo, short=opts['short']) |
|
1105 | q.refresh(repo, short=opts['short']) | |
1106 | q.save_dirty() |
|
1106 | q.save_dirty() | |
1107 | return 0 |
|
1107 | return 0 | |
1108 |
|
1108 | |||
1109 | def diff(ui, repo, *files, **opts): |
|
1109 | def diff(ui, repo, *files, **opts): | |
1110 | """diff of the current patch""" |
|
1110 | """diff of the current patch""" | |
1111 | repomap[repo].diff(repo, files) |
|
1111 | # deep in the dirstate code, the walkhelper method wants a list, not a tuple | |
|
1112 | repomap[repo].diff(repo, list(files)) | |||
1112 | return 0 |
|
1113 | return 0 | |
1113 |
|
1114 | |||
1114 | def lastsavename(path): |
|
1115 | def lastsavename(path): | |
1115 | (dir, base) = os.path.split(path) |
|
1116 | (dir, base) = os.path.split(path) | |
1116 | names = os.listdir(dir) |
|
1117 | names = os.listdir(dir) | |
1117 | namere = re.compile("%s.([0-9]+)" % base) |
|
1118 | namere = re.compile("%s.([0-9]+)" % base) | |
1118 | max = None |
|
1119 | max = None | |
1119 | maxname = None |
|
1120 | maxname = None | |
1120 | for f in names: |
|
1121 | for f in names: | |
1121 | m = namere.match(f) |
|
1122 | m = namere.match(f) | |
1122 | if m: |
|
1123 | if m: | |
1123 | index = int(m.group(1)) |
|
1124 | index = int(m.group(1)) | |
1124 | if max == None or index > max: |
|
1125 | if max == None or index > max: | |
1125 | max = index |
|
1126 | max = index | |
1126 | maxname = f |
|
1127 | maxname = f | |
1127 | if maxname: |
|
1128 | if maxname: | |
1128 | return (os.path.join(dir, maxname), max) |
|
1129 | return (os.path.join(dir, maxname), max) | |
1129 | return (None, None) |
|
1130 | return (None, None) | |
1130 |
|
1131 | |||
1131 | def savename(path): |
|
1132 | def savename(path): | |
1132 | (last, index) = lastsavename(path) |
|
1133 | (last, index) = lastsavename(path) | |
1133 | if last is None: |
|
1134 | if last is None: | |
1134 | index = 0 |
|
1135 | index = 0 | |
1135 | newpath = path + ".%d" % (index + 1) |
|
1136 | newpath = path + ".%d" % (index + 1) | |
1136 | return newpath |
|
1137 | return newpath | |
1137 |
|
1138 | |||
1138 | def push(ui, repo, patch=None, **opts): |
|
1139 | def push(ui, repo, patch=None, **opts): | |
1139 | """push the next patch onto the stack""" |
|
1140 | """push the next patch onto the stack""" | |
1140 | q = repomap[repo] |
|
1141 | q = repomap[repo] | |
1141 | mergeq = None |
|
1142 | mergeq = None | |
1142 |
|
1143 | |||
1143 | if opts['all']: |
|
1144 | if opts['all']: | |
1144 | patch = q.series[-1] |
|
1145 | patch = q.series[-1] | |
1145 | if opts['merge']: |
|
1146 | if opts['merge']: | |
1146 | if opts['name']: |
|
1147 | if opts['name']: | |
1147 | newpath = opts['name'] |
|
1148 | newpath = opts['name'] | |
1148 | else: |
|
1149 | else: | |
1149 | newpath, i = lastsavename(q.path) |
|
1150 | newpath, i = lastsavename(q.path) | |
1150 | if not newpath: |
|
1151 | if not newpath: | |
1151 | ui.warn("no saved queues found, please use -n\n") |
|
1152 | ui.warn("no saved queues found, please use -n\n") | |
1152 | return 1 |
|
1153 | return 1 | |
1153 | mergeq = queue(ui, repo.join(""), newpath) |
|
1154 | mergeq = queue(ui, repo.join(""), newpath) | |
1154 | ui.warn("merging with queue at: %s\n" % mergeq.path) |
|
1155 | ui.warn("merging with queue at: %s\n" % mergeq.path) | |
1155 | ret = q.push(repo, patch, force=opts['force'], list=opts['list'], |
|
1156 | ret = q.push(repo, patch, force=opts['force'], list=opts['list'], | |
1156 | mergeq=mergeq) |
|
1157 | mergeq=mergeq) | |
1157 | q.save_dirty() |
|
1158 | q.save_dirty() | |
1158 | return ret |
|
1159 | return ret | |
1159 |
|
1160 | |||
1160 | def pop(ui, repo, patch=None, **opts): |
|
1161 | def pop(ui, repo, patch=None, **opts): | |
1161 | """pop the current patch off the stack""" |
|
1162 | """pop the current patch off the stack""" | |
1162 | localupdate = True |
|
1163 | localupdate = True | |
1163 | if opts['name']: |
|
1164 | if opts['name']: | |
1164 | q = queue(ui, repo.join(""), repo.join(opts['name'])) |
|
1165 | q = queue(ui, repo.join(""), repo.join(opts['name'])) | |
1165 | ui.warn('using patch queue: %s\n' % q.path) |
|
1166 | ui.warn('using patch queue: %s\n' % q.path) | |
1166 | localupdate = False |
|
1167 | localupdate = False | |
1167 | else: |
|
1168 | else: | |
1168 | q = repomap[repo] |
|
1169 | q = repomap[repo] | |
1169 | if opts['all'] and len(q.applied) > 0: |
|
1170 | if opts['all'] and len(q.applied) > 0: | |
1170 | patch = q.applied[0].split(':')[1] |
|
1171 | patch = q.applied[0].split(':')[1] | |
1171 | q.pop(repo, patch, force=opts['force'], update=localupdate) |
|
1172 | q.pop(repo, patch, force=opts['force'], update=localupdate) | |
1172 | q.save_dirty() |
|
1173 | q.save_dirty() | |
1173 | return 0 |
|
1174 | return 0 | |
1174 |
|
1175 | |||
1175 | def restore(ui, repo, rev, **opts): |
|
1176 | def restore(ui, repo, rev, **opts): | |
1176 | """restore the queue state saved by a rev""" |
|
1177 | """restore the queue state saved by a rev""" | |
1177 | rev = repo.lookup(rev) |
|
1178 | rev = repo.lookup(rev) | |
1178 | q = repomap[repo] |
|
1179 | q = repomap[repo] | |
1179 | q.restore(repo, rev, delete=opts['delete'], |
|
1180 | q.restore(repo, rev, delete=opts['delete'], | |
1180 | qupdate=opts['update']) |
|
1181 | qupdate=opts['update']) | |
1181 | q.save_dirty() |
|
1182 | q.save_dirty() | |
1182 | return 0 |
|
1183 | return 0 | |
1183 |
|
1184 | |||
1184 | def save(ui, repo, **opts): |
|
1185 | def save(ui, repo, **opts): | |
1185 | """save current queue state""" |
|
1186 | """save current queue state""" | |
1186 | q = repomap[repo] |
|
1187 | q = repomap[repo] | |
1187 | ret = q.save(repo, msg=opts['message']) |
|
1188 | ret = q.save(repo, msg=opts['message']) | |
1188 | if ret: |
|
1189 | if ret: | |
1189 | return ret |
|
1190 | return ret | |
1190 | q.save_dirty() |
|
1191 | q.save_dirty() | |
1191 | if opts['copy']: |
|
1192 | if opts['copy']: | |
1192 | path = q.path |
|
1193 | path = q.path | |
1193 | if opts['name']: |
|
1194 | if opts['name']: | |
1194 | newpath = os.path.join(q.basepath, opts['name']) |
|
1195 | newpath = os.path.join(q.basepath, opts['name']) | |
1195 | if os.path.exists(newpath): |
|
1196 | if os.path.exists(newpath): | |
1196 | if not os.path.isdir(newpath): |
|
1197 | if not os.path.isdir(newpath): | |
1197 | ui.warn("destination %s exists and is not a directory\n" % |
|
1198 | ui.warn("destination %s exists and is not a directory\n" % | |
1198 | newpath) |
|
1199 | newpath) | |
1199 | sys.exit(1) |
|
1200 | sys.exit(1) | |
1200 | if not opts['force']: |
|
1201 | if not opts['force']: | |
1201 | ui.warn("destination %s exists, use -f to force\n" % |
|
1202 | ui.warn("destination %s exists, use -f to force\n" % | |
1202 | newpath) |
|
1203 | newpath) | |
1203 | sys.exit(1) |
|
1204 | sys.exit(1) | |
1204 | else: |
|
1205 | else: | |
1205 | newpath = savename(path) |
|
1206 | newpath = savename(path) | |
1206 | ui.warn("copy %s to %s\n" % (path, newpath)) |
|
1207 | ui.warn("copy %s to %s\n" % (path, newpath)) | |
1207 | util.copyfiles(path, newpath) |
|
1208 | util.copyfiles(path, newpath) | |
1208 | if opts['empty']: |
|
1209 | if opts['empty']: | |
1209 | try: |
|
1210 | try: | |
1210 | os.unlink(os.path.join(q.path, q.status_path)) |
|
1211 | os.unlink(os.path.join(q.path, q.status_path)) | |
1211 | except: |
|
1212 | except: | |
1212 | pass |
|
1213 | pass | |
1213 | return 0 |
|
1214 | return 0 | |
1214 |
|
1215 | |||
1215 | def strip(ui, repo, rev, **opts): |
|
1216 | def strip(ui, repo, rev, **opts): | |
1216 | """strip a revision and all later revs on the same branch""" |
|
1217 | """strip a revision and all later revs on the same branch""" | |
1217 | rev = repo.lookup(rev) |
|
1218 | rev = repo.lookup(rev) | |
1218 | backup = 'all' |
|
1219 | backup = 'all' | |
1219 | if opts['backup']: |
|
1220 | if opts['backup']: | |
1220 | backup = 'strip' |
|
1221 | backup = 'strip' | |
1221 | elif opts['nobackup']: |
|
1222 | elif opts['nobackup']: | |
1222 | backup = 'none' |
|
1223 | backup = 'none' | |
1223 | repomap[repo].strip(repo, rev, backup=backup) |
|
1224 | repomap[repo].strip(repo, rev, backup=backup) | |
1224 | return 0 |
|
1225 | return 0 | |
1225 |
|
1226 | |||
1226 | def version(ui, q=None): |
|
1227 | def version(ui, q=None): | |
1227 | """print the version number""" |
|
1228 | """print the version number""" | |
1228 | ui.write("mq version %s\n" % versionstr) |
|
1229 | ui.write("mq version %s\n" % versionstr) | |
1229 | return 0 |
|
1230 | return 0 | |
1230 |
|
1231 | |||
1231 | def reposetup(ui, repo): |
|
1232 | def reposetup(ui, repo): | |
1232 | repomap[repo] = queue(ui, repo.join("")) |
|
1233 | repomap[repo] = queue(ui, repo.join("")) | |
1233 |
|
1234 | |||
1234 | cmdtable = { |
|
1235 | cmdtable = { | |
1235 | "qapplied": (applied, [], 'hg qapplied [patch]'), |
|
1236 | "qapplied": (applied, [], 'hg qapplied [patch]'), | |
1236 | "qcommit|qci": |
|
1237 | "qcommit|qci": | |
1237 | (commit, |
|
1238 | (commit, | |
1238 | [('A', 'addremove', None, _('run addremove during commit')), |
|
1239 | [('A', 'addremove', None, _('run addremove during commit')), | |
1239 | ('I', 'include', [], _('include names matching the given patterns')), |
|
1240 | ('I', 'include', [], _('include names matching the given patterns')), | |
1240 | ('X', 'exclude', [], _('exclude names matching the given patterns')), |
|
1241 | ('X', 'exclude', [], _('exclude names matching the given patterns')), | |
1241 | ('m', 'message', '', _('use <text> as commit message')), |
|
1242 | ('m', 'message', '', _('use <text> as commit message')), | |
1242 | ('l', 'logfile', '', _('read the commit message from <file>')), |
|
1243 | ('l', 'logfile', '', _('read the commit message from <file>')), | |
1243 | ('d', 'date', '', _('record datecode as commit date')), |
|
1244 | ('d', 'date', '', _('record datecode as commit date')), | |
1244 | ('u', 'user', '', _('record user as commiter'))], |
|
1245 | ('u', 'user', '', _('record user as commiter'))], | |
1245 | 'hg qcommit [options] [files]'), |
|
1246 | 'hg qcommit [options] [files]'), | |
1246 | "^qdiff": (diff, [], 'hg qdiff [files]'), |
|
1247 | "^qdiff": (diff, [], 'hg qdiff [files]'), | |
1247 | "qdelete": (delete, [], 'hg qdelete [patch]'), |
|
1248 | "qdelete": (delete, [], 'hg qdelete [patch]'), | |
1248 | "^qimport": |
|
1249 | "^qimport": | |
1249 | (qimport, |
|
1250 | (qimport, | |
1250 | [('e', 'existing', None, 'import file in patch dir'), |
|
1251 | [('e', 'existing', None, 'import file in patch dir'), | |
1251 | ('n', 'name', '', 'patch file name'), |
|
1252 | ('n', 'name', '', 'patch file name'), | |
1252 | ('f', 'force', None, 'overwrite existing files')], |
|
1253 | ('f', 'force', None, 'overwrite existing files')], | |
1253 | 'hg qimport'), |
|
1254 | 'hg qimport'), | |
1254 | "^qinit": |
|
1255 | "^qinit": | |
1255 | (init, |
|
1256 | (init, | |
1256 | [('c', 'create-repo', None, 'create patch repository')], |
|
1257 | [('c', 'create-repo', None, 'create patch repository')], | |
1257 | 'hg [-c] qinit'), |
|
1258 | 'hg [-c] qinit'), | |
1258 | "qnew": |
|
1259 | "qnew": | |
1259 | (new, |
|
1260 | (new, | |
1260 | [('m', 'message', '', 'commit message'), |
|
1261 | [('m', 'message', '', 'commit message'), | |
1261 | ('f', 'force', None, 'force')], |
|
1262 | ('f', 'force', None, 'force')], | |
1262 | 'hg qnew [-m message ] patch'), |
|
1263 | 'hg qnew [-m message ] patch'), | |
1263 | "qnext": (next, [], 'hg qnext'), |
|
1264 | "qnext": (next, [], 'hg qnext'), | |
1264 | "qprev": (prev, [], 'hg qprev'), |
|
1265 | "qprev": (prev, [], 'hg qprev'), | |
1265 | "^qpop": |
|
1266 | "^qpop": | |
1266 | (pop, |
|
1267 | (pop, | |
1267 | [('a', 'all', None, 'pop all patches'), |
|
1268 | [('a', 'all', None, 'pop all patches'), | |
1268 | ('n', 'name', '', 'queue name to pop'), |
|
1269 | ('n', 'name', '', 'queue name to pop'), | |
1269 | ('f', 'force', None, 'forget any local changes')], |
|
1270 | ('f', 'force', None, 'forget any local changes')], | |
1270 | 'hg qpop [options] [patch/index]'), |
|
1271 | 'hg qpop [options] [patch/index]'), | |
1271 | "^qpush": |
|
1272 | "^qpush": | |
1272 | (push, |
|
1273 | (push, | |
1273 | [('f', 'force', None, 'apply if the patch has rejects'), |
|
1274 | [('f', 'force', None, 'apply if the patch has rejects'), | |
1274 | ('l', 'list', None, 'list patch name in commit text'), |
|
1275 | ('l', 'list', None, 'list patch name in commit text'), | |
1275 | ('a', 'all', None, 'apply all patches'), |
|
1276 | ('a', 'all', None, 'apply all patches'), | |
1276 | ('m', 'merge', None, 'merge from another queue'), |
|
1277 | ('m', 'merge', None, 'merge from another queue'), | |
1277 | ('n', 'name', '', 'merge queue name')], |
|
1278 | ('n', 'name', '', 'merge queue name')], | |
1278 | 'hg qpush [options] [patch/index]'), |
|
1279 | 'hg qpush [options] [patch/index]'), | |
1279 | "^qrefresh": |
|
1280 | "^qrefresh": | |
1280 | (refresh, |
|
1281 | (refresh, | |
1281 | [('s', 'short', None, 'short refresh')], |
|
1282 | [('s', 'short', None, 'short refresh')], | |
1282 | 'hg qrefresh'), |
|
1283 | 'hg qrefresh'), | |
1283 | "qrestore": |
|
1284 | "qrestore": | |
1284 | (restore, |
|
1285 | (restore, | |
1285 | [('d', 'delete', None, 'delete save entry'), |
|
1286 | [('d', 'delete', None, 'delete save entry'), | |
1286 | ('u', 'update', None, 'update queue working dir')], |
|
1287 | ('u', 'update', None, 'update queue working dir')], | |
1287 | 'hg qrestore rev'), |
|
1288 | 'hg qrestore rev'), | |
1288 | "qsave": |
|
1289 | "qsave": | |
1289 | (save, |
|
1290 | (save, | |
1290 | [('m', 'message', '', 'commit message'), |
|
1291 | [('m', 'message', '', 'commit message'), | |
1291 | ('c', 'copy', None, 'copy patch directory'), |
|
1292 | ('c', 'copy', None, 'copy patch directory'), | |
1292 | ('n', 'name', '', 'copy directory name'), |
|
1293 | ('n', 'name', '', 'copy directory name'), | |
1293 | ('e', 'empty', None, 'clear queue status file'), |
|
1294 | ('e', 'empty', None, 'clear queue status file'), | |
1294 | ('f', 'force', None, 'force copy')], |
|
1295 | ('f', 'force', None, 'force copy')], | |
1295 | 'hg qsave'), |
|
1296 | 'hg qsave'), | |
1296 | "qseries": |
|
1297 | "qseries": | |
1297 | (series, |
|
1298 | (series, | |
1298 | [('m', 'missing', None, 'print patches not in series')], |
|
1299 | [('m', 'missing', None, 'print patches not in series')], | |
1299 | 'hg qseries'), |
|
1300 | 'hg qseries'), | |
1300 | "^strip": |
|
1301 | "^strip": | |
1301 | (strip, |
|
1302 | (strip, | |
1302 | [('f', 'force', None, 'force multi-head removal'), |
|
1303 | [('f', 'force', None, 'force multi-head removal'), | |
1303 | ('b', 'backup', None, 'bundle unrelated changesets'), |
|
1304 | ('b', 'backup', None, 'bundle unrelated changesets'), | |
1304 | ('n', 'nobackup', None, 'no backups')], |
|
1305 | ('n', 'nobackup', None, 'no backups')], | |
1305 | 'hg strip rev'), |
|
1306 | 'hg strip rev'), | |
1306 | "qtop": (top, [], 'hg qtop'), |
|
1307 | "qtop": (top, [], 'hg qtop'), | |
1307 | "qunapplied": (unapplied, [], 'hg qunapplied [patch]'), |
|
1308 | "qunapplied": (unapplied, [], 'hg qunapplied [patch]'), | |
1308 | "qversion": (version, [], 'hg qversion') |
|
1309 | "qversion": (version, [], 'hg qversion') | |
1309 | } |
|
1310 | } | |
1310 |
|
1311 |
@@ -1,3459 +1,3457 b'' | |||||
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 | demandload(globals(), "changegroup") |
|
15 | demandload(globals(), "changegroup") | |
16 |
|
16 | |||
17 | class UnknownCommand(Exception): |
|
17 | class UnknownCommand(Exception): | |
18 | """Exception raised if command is not in the command table.""" |
|
18 | """Exception raised if command is not in the command table.""" | |
19 | class AmbiguousCommand(Exception): |
|
19 | class AmbiguousCommand(Exception): | |
20 | """Exception raised if command shortcut matches more than one command.""" |
|
20 | """Exception raised if command shortcut matches more than one command.""" | |
21 |
|
21 | |||
22 | def filterfiles(filters, files): |
|
22 | def filterfiles(filters, files): | |
23 | l = [x for x in files if x in filters] |
|
23 | l = [x for x in files if x in filters] | |
24 |
|
24 | |||
25 | for t in filters: |
|
25 | for t in filters: | |
26 | if t and t[-1] != "/": |
|
26 | if t and t[-1] != "/": | |
27 | t += "/" |
|
27 | t += "/" | |
28 | l += [x for x in files if x.startswith(t)] |
|
28 | l += [x for x in files if x.startswith(t)] | |
29 | return l |
|
29 | return l | |
30 |
|
30 | |||
31 | def relpath(repo, args): |
|
31 | def relpath(repo, args): | |
32 | cwd = repo.getcwd() |
|
32 | cwd = repo.getcwd() | |
33 | if cwd: |
|
33 | if cwd: | |
34 | return [util.normpath(os.path.join(cwd, x)) for x in args] |
|
34 | return [util.normpath(os.path.join(cwd, x)) for x in args] | |
35 | return args |
|
35 | return args | |
36 |
|
36 | |||
37 | def matchpats(repo, pats=[], opts={}, head=''): |
|
37 | def matchpats(repo, pats=[], opts={}, head=''): | |
38 | cwd = repo.getcwd() |
|
38 | cwd = repo.getcwd() | |
39 | if not pats and cwd: |
|
39 | if not pats and cwd: | |
40 | opts['include'] = [os.path.join(cwd, i) for i in opts['include']] |
|
40 | opts['include'] = [os.path.join(cwd, i) for i in opts['include']] | |
41 | opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] |
|
41 | opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] | |
42 | cwd = '' |
|
42 | cwd = '' | |
43 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), |
|
43 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), | |
44 | opts.get('exclude'), head) |
|
44 | opts.get('exclude'), head) | |
45 |
|
45 | |||
46 | def makewalk(repo, pats, opts, node=None, head='', badmatch=None): |
|
46 | def makewalk(repo, pats, opts, node=None, head='', badmatch=None): | |
47 | files, matchfn, anypats = matchpats(repo, pats, opts, head) |
|
47 | files, matchfn, anypats = matchpats(repo, pats, opts, head) | |
48 | exact = dict(zip(files, files)) |
|
48 | exact = dict(zip(files, files)) | |
49 | def walk(): |
|
49 | def walk(): | |
50 | for src, fn in repo.walk(node=node, files=files, match=matchfn, |
|
50 | for src, fn in repo.walk(node=node, files=files, match=matchfn, | |
51 | badmatch=badmatch): |
|
51 | badmatch=badmatch): | |
52 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact |
|
52 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact | |
53 | return files, matchfn, walk() |
|
53 | return files, matchfn, walk() | |
54 |
|
54 | |||
55 | def walk(repo, pats, opts, node=None, head='', badmatch=None): |
|
55 | def walk(repo, pats, opts, node=None, head='', badmatch=None): | |
56 | files, matchfn, results = makewalk(repo, pats, opts, node, head, badmatch) |
|
56 | files, matchfn, results = makewalk(repo, pats, opts, node, head, badmatch) | |
57 | for r in results: |
|
57 | for r in results: | |
58 | yield r |
|
58 | yield r | |
59 |
|
59 | |||
60 | def walkchangerevs(ui, repo, pats, opts): |
|
60 | def walkchangerevs(ui, repo, pats, opts): | |
61 | '''Iterate over files and the revs they changed in. |
|
61 | '''Iterate over files and the revs they changed in. | |
62 |
|
62 | |||
63 | Callers most commonly need to iterate backwards over the history |
|
63 | Callers most commonly need to iterate backwards over the history | |
64 | it is interested in. Doing so has awful (quadratic-looking) |
|
64 | it is interested in. Doing so has awful (quadratic-looking) | |
65 | performance, so we use iterators in a "windowed" way. |
|
65 | performance, so we use iterators in a "windowed" way. | |
66 |
|
66 | |||
67 | We walk a window of revisions in the desired order. Within the |
|
67 | We walk a window of revisions in the desired order. Within the | |
68 | window, we first walk forwards to gather data, then in the desired |
|
68 | window, we first walk forwards to gather data, then in the desired | |
69 | order (usually backwards) to display it. |
|
69 | order (usually backwards) to display it. | |
70 |
|
70 | |||
71 | This function returns an (iterator, getchange, matchfn) tuple. The |
|
71 | This function returns an (iterator, getchange, matchfn) tuple. The | |
72 | getchange function returns the changelog entry for a numeric |
|
72 | getchange function returns the changelog entry for a numeric | |
73 | revision. The iterator yields 3-tuples. They will be of one of |
|
73 | revision. The iterator yields 3-tuples. They will be of one of | |
74 | the following forms: |
|
74 | the following forms: | |
75 |
|
75 | |||
76 | "window", incrementing, lastrev: stepping through a window, |
|
76 | "window", incrementing, lastrev: stepping through a window, | |
77 | positive if walking forwards through revs, last rev in the |
|
77 | positive if walking forwards through revs, last rev in the | |
78 | sequence iterated over - use to reset state for the current window |
|
78 | sequence iterated over - use to reset state for the current window | |
79 |
|
79 | |||
80 | "add", rev, fns: out-of-order traversal of the given file names |
|
80 | "add", rev, fns: out-of-order traversal of the given file names | |
81 | fns, which changed during revision rev - use to gather data for |
|
81 | fns, which changed during revision rev - use to gather data for | |
82 | possible display |
|
82 | possible display | |
83 |
|
83 | |||
84 | "iter", rev, None: in-order traversal of the revs earlier iterated |
|
84 | "iter", rev, None: in-order traversal of the revs earlier iterated | |
85 | over with "add" - use to display data''' |
|
85 | over with "add" - use to display data''' | |
86 |
|
86 | |||
87 | def increasing_windows(start, end, windowsize=8, sizelimit=512): |
|
87 | def increasing_windows(start, end, windowsize=8, sizelimit=512): | |
88 | if start < end: |
|
88 | if start < end: | |
89 | while start < end: |
|
89 | while start < end: | |
90 | yield start, min(windowsize, end-start) |
|
90 | yield start, min(windowsize, end-start) | |
91 | start += windowsize |
|
91 | start += windowsize | |
92 | if windowsize < sizelimit: |
|
92 | if windowsize < sizelimit: | |
93 | windowsize *= 2 |
|
93 | windowsize *= 2 | |
94 | else: |
|
94 | else: | |
95 | while start > end: |
|
95 | while start > end: | |
96 | yield start, min(windowsize, start-end-1) |
|
96 | yield start, min(windowsize, start-end-1) | |
97 | start -= windowsize |
|
97 | start -= windowsize | |
98 | if windowsize < sizelimit: |
|
98 | if windowsize < sizelimit: | |
99 | windowsize *= 2 |
|
99 | windowsize *= 2 | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
102 | files, matchfn, anypats = matchpats(repo, pats, opts) | |
103 |
|
103 | |||
104 | if repo.changelog.count() == 0: |
|
104 | if repo.changelog.count() == 0: | |
105 | return [], False, matchfn |
|
105 | return [], False, matchfn | |
106 |
|
106 | |||
107 | revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) |
|
107 | revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) | |
108 | wanted = {} |
|
108 | wanted = {} | |
109 | slowpath = anypats |
|
109 | slowpath = anypats | |
110 | fncache = {} |
|
110 | fncache = {} | |
111 |
|
111 | |||
112 | chcache = {} |
|
112 | chcache = {} | |
113 | def getchange(rev): |
|
113 | def getchange(rev): | |
114 | ch = chcache.get(rev) |
|
114 | ch = chcache.get(rev) | |
115 | if ch is None: |
|
115 | if ch is None: | |
116 | chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) |
|
116 | chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) | |
117 | return ch |
|
117 | return ch | |
118 |
|
118 | |||
119 | if not slowpath and not files: |
|
119 | if not slowpath and not files: | |
120 | # No files, no patterns. Display all revs. |
|
120 | # No files, no patterns. Display all revs. | |
121 | wanted = dict(zip(revs, revs)) |
|
121 | wanted = dict(zip(revs, revs)) | |
122 | if not slowpath: |
|
122 | if not slowpath: | |
123 | # Only files, no patterns. Check the history of each file. |
|
123 | # Only files, no patterns. Check the history of each file. | |
124 | def filerevgen(filelog): |
|
124 | def filerevgen(filelog): | |
125 | for i, window in increasing_windows(filelog.count()-1, -1): |
|
125 | for i, window in increasing_windows(filelog.count()-1, -1): | |
126 | revs = [] |
|
126 | revs = [] | |
127 | for j in xrange(i - window, i + 1): |
|
127 | for j in xrange(i - window, i + 1): | |
128 | revs.append(filelog.linkrev(filelog.node(j))) |
|
128 | revs.append(filelog.linkrev(filelog.node(j))) | |
129 | revs.reverse() |
|
129 | revs.reverse() | |
130 | for rev in revs: |
|
130 | for rev in revs: | |
131 | yield rev |
|
131 | yield rev | |
132 |
|
132 | |||
133 | minrev, maxrev = min(revs), max(revs) |
|
133 | minrev, maxrev = min(revs), max(revs) | |
134 | for file_ in files: |
|
134 | for file_ in files: | |
135 | filelog = repo.file(file_) |
|
135 | filelog = repo.file(file_) | |
136 | # A zero count may be a directory or deleted file, so |
|
136 | # A zero count may be a directory or deleted file, so | |
137 | # try to find matching entries on the slow path. |
|
137 | # try to find matching entries on the slow path. | |
138 | if filelog.count() == 0: |
|
138 | if filelog.count() == 0: | |
139 | slowpath = True |
|
139 | slowpath = True | |
140 | break |
|
140 | break | |
141 | for rev in filerevgen(filelog): |
|
141 | for rev in filerevgen(filelog): | |
142 | if rev <= maxrev: |
|
142 | if rev <= maxrev: | |
143 | if rev < minrev: |
|
143 | if rev < minrev: | |
144 | break |
|
144 | break | |
145 | fncache.setdefault(rev, []) |
|
145 | fncache.setdefault(rev, []) | |
146 | fncache[rev].append(file_) |
|
146 | fncache[rev].append(file_) | |
147 | wanted[rev] = 1 |
|
147 | wanted[rev] = 1 | |
148 | if slowpath: |
|
148 | if slowpath: | |
149 | # The slow path checks files modified in every changeset. |
|
149 | # The slow path checks files modified in every changeset. | |
150 | def changerevgen(): |
|
150 | def changerevgen(): | |
151 | for i, window in increasing_windows(repo.changelog.count()-1, -1): |
|
151 | for i, window in increasing_windows(repo.changelog.count()-1, -1): | |
152 | for j in xrange(i - window, i + 1): |
|
152 | for j in xrange(i - window, i + 1): | |
153 | yield j, getchange(j)[3] |
|
153 | yield j, getchange(j)[3] | |
154 |
|
154 | |||
155 | for rev, changefiles in changerevgen(): |
|
155 | for rev, changefiles in changerevgen(): | |
156 | matches = filter(matchfn, changefiles) |
|
156 | matches = filter(matchfn, changefiles) | |
157 | if matches: |
|
157 | if matches: | |
158 | fncache[rev] = matches |
|
158 | fncache[rev] = matches | |
159 | wanted[rev] = 1 |
|
159 | wanted[rev] = 1 | |
160 |
|
160 | |||
161 | def iterate(): |
|
161 | def iterate(): | |
162 | for i, window in increasing_windows(0, len(revs)): |
|
162 | for i, window in increasing_windows(0, len(revs)): | |
163 | yield 'window', revs[0] < revs[-1], revs[-1] |
|
163 | yield 'window', revs[0] < revs[-1], revs[-1] | |
164 | nrevs = [rev for rev in revs[i:i+window] |
|
164 | nrevs = [rev for rev in revs[i:i+window] | |
165 | if rev in wanted] |
|
165 | if rev in wanted] | |
166 | srevs = list(nrevs) |
|
166 | srevs = list(nrevs) | |
167 | srevs.sort() |
|
167 | srevs.sort() | |
168 | for rev in srevs: |
|
168 | for rev in srevs: | |
169 | fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) |
|
169 | fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) | |
170 | yield 'add', rev, fns |
|
170 | yield 'add', rev, fns | |
171 | for rev in nrevs: |
|
171 | for rev in nrevs: | |
172 | yield 'iter', rev, None |
|
172 | yield 'iter', rev, None | |
173 | return iterate(), getchange, matchfn |
|
173 | return iterate(), getchange, matchfn | |
174 |
|
174 | |||
175 | revrangesep = ':' |
|
175 | revrangesep = ':' | |
176 |
|
176 | |||
177 | def revrange(ui, repo, revs, revlog=None): |
|
177 | def revrange(ui, repo, revs, revlog=None): | |
178 | """Yield revision as strings from a list of revision specifications.""" |
|
178 | """Yield revision as strings from a list of revision specifications.""" | |
179 | if revlog is None: |
|
179 | if revlog is None: | |
180 | revlog = repo.changelog |
|
180 | revlog = repo.changelog | |
181 | revcount = revlog.count() |
|
181 | revcount = revlog.count() | |
182 | def fix(val, defval): |
|
182 | def fix(val, defval): | |
183 | if not val: |
|
183 | if not val: | |
184 | return defval |
|
184 | return defval | |
185 | try: |
|
185 | try: | |
186 | num = int(val) |
|
186 | num = int(val) | |
187 | if str(num) != val: |
|
187 | if str(num) != val: | |
188 | raise ValueError |
|
188 | raise ValueError | |
189 | if num < 0: |
|
189 | if num < 0: | |
190 | num += revcount |
|
190 | num += revcount | |
191 | if num < 0: |
|
191 | if num < 0: | |
192 | num = 0 |
|
192 | num = 0 | |
193 | elif num >= revcount: |
|
193 | elif num >= revcount: | |
194 | raise ValueError |
|
194 | raise ValueError | |
195 | except ValueError: |
|
195 | except ValueError: | |
196 | try: |
|
196 | try: | |
197 | num = repo.changelog.rev(repo.lookup(val)) |
|
197 | num = repo.changelog.rev(repo.lookup(val)) | |
198 | except KeyError: |
|
198 | except KeyError: | |
199 | try: |
|
199 | try: | |
200 | num = revlog.rev(revlog.lookup(val)) |
|
200 | num = revlog.rev(revlog.lookup(val)) | |
201 | except KeyError: |
|
201 | except KeyError: | |
202 | raise util.Abort(_('invalid revision identifier %s'), val) |
|
202 | raise util.Abort(_('invalid revision identifier %s'), val) | |
203 | return num |
|
203 | return num | |
204 | seen = {} |
|
204 | seen = {} | |
205 | for spec in revs: |
|
205 | for spec in revs: | |
206 | if spec.find(revrangesep) >= 0: |
|
206 | if spec.find(revrangesep) >= 0: | |
207 | start, end = spec.split(revrangesep, 1) |
|
207 | start, end = spec.split(revrangesep, 1) | |
208 | start = fix(start, 0) |
|
208 | start = fix(start, 0) | |
209 | end = fix(end, revcount - 1) |
|
209 | end = fix(end, revcount - 1) | |
210 | step = start > end and -1 or 1 |
|
210 | step = start > end and -1 or 1 | |
211 | for rev in xrange(start, end+step, step): |
|
211 | for rev in xrange(start, end+step, step): | |
212 | if rev in seen: |
|
212 | if rev in seen: | |
213 | continue |
|
213 | continue | |
214 | seen[rev] = 1 |
|
214 | seen[rev] = 1 | |
215 | yield str(rev) |
|
215 | yield str(rev) | |
216 | else: |
|
216 | else: | |
217 | rev = fix(spec, None) |
|
217 | rev = fix(spec, None) | |
218 | if rev in seen: |
|
218 | if rev in seen: | |
219 | continue |
|
219 | continue | |
220 | seen[rev] = 1 |
|
220 | seen[rev] = 1 | |
221 | yield str(rev) |
|
221 | yield str(rev) | |
222 |
|
222 | |||
223 | def make_filename(repo, r, pat, node=None, |
|
223 | def make_filename(repo, r, pat, node=None, | |
224 | total=None, seqno=None, revwidth=None, pathname=None): |
|
224 | total=None, seqno=None, revwidth=None, pathname=None): | |
225 | node_expander = { |
|
225 | node_expander = { | |
226 | 'H': lambda: hex(node), |
|
226 | 'H': lambda: hex(node), | |
227 | 'R': lambda: str(r.rev(node)), |
|
227 | 'R': lambda: str(r.rev(node)), | |
228 | 'h': lambda: short(node), |
|
228 | 'h': lambda: short(node), | |
229 | } |
|
229 | } | |
230 | expander = { |
|
230 | expander = { | |
231 | '%': lambda: '%', |
|
231 | '%': lambda: '%', | |
232 | 'b': lambda: os.path.basename(repo.root), |
|
232 | 'b': lambda: os.path.basename(repo.root), | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | try: |
|
235 | try: | |
236 | if node: |
|
236 | if node: | |
237 | expander.update(node_expander) |
|
237 | expander.update(node_expander) | |
238 | if node and revwidth is not None: |
|
238 | if node and revwidth is not None: | |
239 | expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) |
|
239 | expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) | |
240 | if total is not None: |
|
240 | if total is not None: | |
241 | expander['N'] = lambda: str(total) |
|
241 | expander['N'] = lambda: str(total) | |
242 | if seqno is not None: |
|
242 | if seqno is not None: | |
243 | expander['n'] = lambda: str(seqno) |
|
243 | expander['n'] = lambda: str(seqno) | |
244 | if total is not None and seqno is not None: |
|
244 | if total is not None and seqno is not None: | |
245 | expander['n'] = lambda:str(seqno).zfill(len(str(total))) |
|
245 | expander['n'] = lambda:str(seqno).zfill(len(str(total))) | |
246 | if pathname is not None: |
|
246 | if pathname is not None: | |
247 | expander['s'] = lambda: os.path.basename(pathname) |
|
247 | expander['s'] = lambda: os.path.basename(pathname) | |
248 | expander['d'] = lambda: os.path.dirname(pathname) or '.' |
|
248 | expander['d'] = lambda: os.path.dirname(pathname) or '.' | |
249 | expander['p'] = lambda: pathname |
|
249 | expander['p'] = lambda: pathname | |
250 |
|
250 | |||
251 | newname = [] |
|
251 | newname = [] | |
252 | patlen = len(pat) |
|
252 | patlen = len(pat) | |
253 | i = 0 |
|
253 | i = 0 | |
254 | while i < patlen: |
|
254 | while i < patlen: | |
255 | c = pat[i] |
|
255 | c = pat[i] | |
256 | if c == '%': |
|
256 | if c == '%': | |
257 | i += 1 |
|
257 | i += 1 | |
258 | c = pat[i] |
|
258 | c = pat[i] | |
259 | c = expander[c]() |
|
259 | c = expander[c]() | |
260 | newname.append(c) |
|
260 | newname.append(c) | |
261 | i += 1 |
|
261 | i += 1 | |
262 | return ''.join(newname) |
|
262 | return ''.join(newname) | |
263 | except KeyError, inst: |
|
263 | except KeyError, inst: | |
264 | raise util.Abort(_("invalid format spec '%%%s' in output file name"), |
|
264 | raise util.Abort(_("invalid format spec '%%%s' in output file name"), | |
265 | inst.args[0]) |
|
265 | inst.args[0]) | |
266 |
|
266 | |||
267 | def make_file(repo, r, pat, node=None, |
|
267 | def make_file(repo, r, pat, node=None, | |
268 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): |
|
268 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): | |
269 | if not pat or pat == '-': |
|
269 | if not pat or pat == '-': | |
270 | return 'w' in mode and sys.stdout or sys.stdin |
|
270 | return 'w' in mode and sys.stdout or sys.stdin | |
271 | if hasattr(pat, 'write') and 'w' in mode: |
|
271 | if hasattr(pat, 'write') and 'w' in mode: | |
272 | return pat |
|
272 | return pat | |
273 | if hasattr(pat, 'read') and 'r' in mode: |
|
273 | if hasattr(pat, 'read') and 'r' in mode: | |
274 | return pat |
|
274 | return pat | |
275 | return open(make_filename(repo, r, pat, node, total, seqno, revwidth, |
|
275 | return open(make_filename(repo, r, pat, node, total, seqno, revwidth, | |
276 | pathname), |
|
276 | pathname), | |
277 | mode) |
|
277 | mode) | |
278 |
|
278 | |||
279 | def write_bundle(cg, filename=None, compress=True): |
|
279 | def write_bundle(cg, filename=None, compress=True): | |
280 | """Write a bundle file and return its filename. |
|
280 | """Write a bundle file and return its filename. | |
281 |
|
281 | |||
282 | Existing files will not be overwritten. |
|
282 | Existing files will not be overwritten. | |
283 | If no filename is specified, a temporary file is created. |
|
283 | If no filename is specified, a temporary file is created. | |
284 | bz2 compression can be turned off. |
|
284 | bz2 compression can be turned off. | |
285 | The bundle file will be deleted in case of errors. |
|
285 | The bundle file will be deleted in case of errors. | |
286 | """ |
|
286 | """ | |
287 | class nocompress(object): |
|
287 | class nocompress(object): | |
288 | def compress(self, x): |
|
288 | def compress(self, x): | |
289 | return x |
|
289 | return x | |
290 | def flush(self): |
|
290 | def flush(self): | |
291 | return "" |
|
291 | return "" | |
292 |
|
292 | |||
293 | fh = None |
|
293 | fh = None | |
294 | cleanup = None |
|
294 | cleanup = None | |
295 | try: |
|
295 | try: | |
296 | if filename: |
|
296 | if filename: | |
297 | if os.path.exists(filename): |
|
297 | if os.path.exists(filename): | |
298 | raise util.Abort(_("file '%s' already exists"), filename) |
|
298 | raise util.Abort(_("file '%s' already exists"), filename) | |
299 | fh = open(filename, "wb") |
|
299 | fh = open(filename, "wb") | |
300 | else: |
|
300 | else: | |
301 | fd, filename = tempfile.mkstemp(suffix=".hg", prefix="hg-bundle-") |
|
301 | fd, filename = tempfile.mkstemp(suffix=".hg", prefix="hg-bundle-") | |
302 | fh = os.fdopen(fd, "wb") |
|
302 | fh = os.fdopen(fd, "wb") | |
303 | cleanup = filename |
|
303 | cleanup = filename | |
304 |
|
304 | |||
305 | if compress: |
|
305 | if compress: | |
306 | fh.write("HG10") |
|
306 | fh.write("HG10") | |
307 | z = bz2.BZ2Compressor(9) |
|
307 | z = bz2.BZ2Compressor(9) | |
308 | else: |
|
308 | else: | |
309 | fh.write("HG10UN") |
|
309 | fh.write("HG10UN") | |
310 | z = nocompress() |
|
310 | z = nocompress() | |
311 | # parse the changegroup data, otherwise we will block |
|
311 | # parse the changegroup data, otherwise we will block | |
312 | # in case of sshrepo because we don't know the end of the stream |
|
312 | # in case of sshrepo because we don't know the end of the stream | |
313 |
|
313 | |||
314 | # an empty chunkiter is the end of the changegroup |
|
314 | # an empty chunkiter is the end of the changegroup | |
315 | empty = False |
|
315 | empty = False | |
316 | while not empty: |
|
316 | while not empty: | |
317 | empty = True |
|
317 | empty = True | |
318 | for chunk in changegroup.chunkiter(cg): |
|
318 | for chunk in changegroup.chunkiter(cg): | |
319 | empty = False |
|
319 | empty = False | |
320 | fh.write(z.compress(changegroup.genchunk(chunk))) |
|
320 | fh.write(z.compress(changegroup.genchunk(chunk))) | |
321 | fh.write(z.compress(changegroup.closechunk())) |
|
321 | fh.write(z.compress(changegroup.closechunk())) | |
322 | fh.write(z.flush()) |
|
322 | fh.write(z.flush()) | |
323 | cleanup = None |
|
323 | cleanup = None | |
324 | return filename |
|
324 | return filename | |
325 | finally: |
|
325 | finally: | |
326 | if fh is not None: |
|
326 | if fh is not None: | |
327 | fh.close() |
|
327 | fh.close() | |
328 | if cleanup is not None: |
|
328 | if cleanup is not None: | |
329 | os.unlink(cleanup) |
|
329 | os.unlink(cleanup) | |
330 |
|
330 | |||
331 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, |
|
331 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, | |
332 | changes=None, text=False, opts={}): |
|
332 | changes=None, text=False, opts={}): | |
333 | if not node1: |
|
333 | if not node1: | |
334 | node1 = repo.dirstate.parents()[0] |
|
334 | node1 = repo.dirstate.parents()[0] | |
335 | # reading the data for node1 early allows it to play nicely |
|
335 | # reading the data for node1 early allows it to play nicely | |
336 | # with repo.changes and the revlog cache. |
|
336 | # with repo.changes and the revlog cache. | |
337 | change = repo.changelog.read(node1) |
|
337 | change = repo.changelog.read(node1) | |
338 | mmap = repo.manifest.read(change[0]) |
|
338 | mmap = repo.manifest.read(change[0]) | |
339 | date1 = util.datestr(change[2]) |
|
339 | date1 = util.datestr(change[2]) | |
340 |
|
340 | |||
341 | if not changes: |
|
341 | if not changes: | |
342 | changes = repo.changes(node1, node2, files, match=match) |
|
342 | changes = repo.changes(node1, node2, files, match=match) | |
343 | modified, added, removed, deleted, unknown = changes |
|
343 | modified, added, removed, deleted, unknown = changes | |
344 | if files: |
|
344 | if files: | |
345 | modified, added, removed = map(lambda x: filterfiles(files, x), |
|
345 | modified, added, removed = map(lambda x: filterfiles(files, x), | |
346 | (modified, added, removed)) |
|
346 | (modified, added, removed)) | |
347 |
|
347 | |||
348 | if not modified and not added and not removed: |
|
348 | if not modified and not added and not removed: | |
349 | return |
|
349 | return | |
350 |
|
350 | |||
351 | if node2: |
|
351 | if node2: | |
352 | change = repo.changelog.read(node2) |
|
352 | change = repo.changelog.read(node2) | |
353 | mmap2 = repo.manifest.read(change[0]) |
|
353 | mmap2 = repo.manifest.read(change[0]) | |
354 | date2 = util.datestr(change[2]) |
|
354 | date2 = util.datestr(change[2]) | |
355 | def read(f): |
|
355 | def read(f): | |
356 | return repo.file(f).read(mmap2[f]) |
|
356 | return repo.file(f).read(mmap2[f]) | |
357 | else: |
|
357 | else: | |
358 | date2 = util.datestr() |
|
358 | date2 = util.datestr() | |
359 | def read(f): |
|
359 | def read(f): | |
360 | return repo.wread(f) |
|
360 | return repo.wread(f) | |
361 |
|
361 | |||
362 | if ui.quiet: |
|
362 | if ui.quiet: | |
363 | r = None |
|
363 | r = None | |
364 | else: |
|
364 | else: | |
365 | hexfunc = ui.verbose and hex or short |
|
365 | hexfunc = ui.verbose and hex or short | |
366 | r = [hexfunc(node) for node in [node1, node2] if node] |
|
366 | r = [hexfunc(node) for node in [node1, node2] if node] | |
367 |
|
367 | |||
368 | diffopts = ui.diffopts() |
|
368 | diffopts = ui.diffopts() | |
369 | showfunc = opts.get('show_function') or diffopts['showfunc'] |
|
369 | showfunc = opts.get('show_function') or diffopts['showfunc'] | |
370 | ignorews = opts.get('ignore_all_space') or diffopts['ignorews'] |
|
370 | ignorews = opts.get('ignore_all_space') or diffopts['ignorews'] | |
371 | for f in modified: |
|
371 | for f in modified: | |
372 | to = None |
|
372 | to = None | |
373 | if f in mmap: |
|
373 | if f in mmap: | |
374 | to = repo.file(f).read(mmap[f]) |
|
374 | to = repo.file(f).read(mmap[f]) | |
375 | tn = read(f) |
|
375 | tn = read(f) | |
376 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
376 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
377 | showfunc=showfunc, ignorews=ignorews)) |
|
377 | showfunc=showfunc, ignorews=ignorews)) | |
378 | for f in added: |
|
378 | for f in added: | |
379 | to = None |
|
379 | to = None | |
380 | tn = read(f) |
|
380 | tn = read(f) | |
381 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
381 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
382 | showfunc=showfunc, ignorews=ignorews)) |
|
382 | showfunc=showfunc, ignorews=ignorews)) | |
383 | for f in removed: |
|
383 | for f in removed: | |
384 | to = repo.file(f).read(mmap[f]) |
|
384 | to = repo.file(f).read(mmap[f]) | |
385 | tn = None |
|
385 | tn = None | |
386 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
386 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
387 | showfunc=showfunc, ignorews=ignorews)) |
|
387 | showfunc=showfunc, ignorews=ignorews)) | |
388 |
|
388 | |||
389 | def trimuser(ui, name, rev, revcache): |
|
389 | def trimuser(ui, name, rev, revcache): | |
390 | """trim the name of the user who committed a change""" |
|
390 | """trim the name of the user who committed a change""" | |
391 | user = revcache.get(rev) |
|
391 | user = revcache.get(rev) | |
392 | if user is None: |
|
392 | if user is None: | |
393 | user = revcache[rev] = ui.shortuser(name) |
|
393 | user = revcache[rev] = ui.shortuser(name) | |
394 | return user |
|
394 | return user | |
395 |
|
395 | |||
396 | class changeset_templater(object): |
|
396 | class changeset_templater(object): | |
397 | '''use templater module to format changeset information.''' |
|
397 | '''use templater module to format changeset information.''' | |
398 |
|
398 | |||
399 | def __init__(self, ui, repo, mapfile): |
|
399 | def __init__(self, ui, repo, mapfile): | |
400 | self.t = templater.templater(mapfile, templater.common_filters, |
|
400 | self.t = templater.templater(mapfile, templater.common_filters, | |
401 | cache={'parent': '{rev}:{node|short} ', |
|
401 | cache={'parent': '{rev}:{node|short} ', | |
402 | 'manifest': '{rev}:{node|short}'}) |
|
402 | 'manifest': '{rev}:{node|short}'}) | |
403 | self.ui = ui |
|
403 | self.ui = ui | |
404 | self.repo = repo |
|
404 | self.repo = repo | |
405 |
|
405 | |||
406 | def use_template(self, t): |
|
406 | def use_template(self, t): | |
407 | '''set template string to use''' |
|
407 | '''set template string to use''' | |
408 | self.t.cache['changeset'] = t |
|
408 | self.t.cache['changeset'] = t | |
409 |
|
409 | |||
410 | def write(self, thing, header=False): |
|
410 | def write(self, thing, header=False): | |
411 | '''write expanded template. |
|
411 | '''write expanded template. | |
412 | uses in-order recursive traverse of iterators.''' |
|
412 | uses in-order recursive traverse of iterators.''' | |
413 | for t in thing: |
|
413 | for t in thing: | |
414 | if hasattr(t, '__iter__'): |
|
414 | if hasattr(t, '__iter__'): | |
415 | self.write(t, header=header) |
|
415 | self.write(t, header=header) | |
416 | elif header: |
|
416 | elif header: | |
417 | self.ui.write_header(t) |
|
417 | self.ui.write_header(t) | |
418 | else: |
|
418 | else: | |
419 | self.ui.write(t) |
|
419 | self.ui.write(t) | |
420 |
|
420 | |||
421 | def write_header(self, thing): |
|
421 | def write_header(self, thing): | |
422 | self.write(thing, header=True) |
|
422 | self.write(thing, header=True) | |
423 |
|
423 | |||
424 | def show(self, rev=0, changenode=None, brinfo=None): |
|
424 | def show(self, rev=0, changenode=None, brinfo=None): | |
425 | '''show a single changeset or file revision''' |
|
425 | '''show a single changeset or file revision''' | |
426 | log = self.repo.changelog |
|
426 | log = self.repo.changelog | |
427 | if changenode is None: |
|
427 | if changenode is None: | |
428 | changenode = log.node(rev) |
|
428 | changenode = log.node(rev) | |
429 | elif not rev: |
|
429 | elif not rev: | |
430 | rev = log.rev(changenode) |
|
430 | rev = log.rev(changenode) | |
431 |
|
431 | |||
432 | changes = log.read(changenode) |
|
432 | changes = log.read(changenode) | |
433 |
|
433 | |||
434 | def showlist(name, values, plural=None, **args): |
|
434 | def showlist(name, values, plural=None, **args): | |
435 | '''expand set of values. |
|
435 | '''expand set of values. | |
436 | name is name of key in template map. |
|
436 | name is name of key in template map. | |
437 | values is list of strings or dicts. |
|
437 | values is list of strings or dicts. | |
438 | plural is plural of name, if not simply name + 's'. |
|
438 | plural is plural of name, if not simply name + 's'. | |
439 |
|
439 | |||
440 | expansion works like this, given name 'foo'. |
|
440 | expansion works like this, given name 'foo'. | |
441 |
|
441 | |||
442 | if values is empty, expand 'no_foos'. |
|
442 | if values is empty, expand 'no_foos'. | |
443 |
|
443 | |||
444 | if 'foo' not in template map, return values as a string, |
|
444 | if 'foo' not in template map, return values as a string, | |
445 | joined by space. |
|
445 | joined by space. | |
446 |
|
446 | |||
447 | expand 'start_foos'. |
|
447 | expand 'start_foos'. | |
448 |
|
448 | |||
449 | for each value, expand 'foo'. if 'last_foo' in template |
|
449 | for each value, expand 'foo'. if 'last_foo' in template | |
450 | map, expand it instead of 'foo' for last key. |
|
450 | map, expand it instead of 'foo' for last key. | |
451 |
|
451 | |||
452 | expand 'end_foos'. |
|
452 | expand 'end_foos'. | |
453 | ''' |
|
453 | ''' | |
454 | if plural: names = plural |
|
454 | if plural: names = plural | |
455 | else: names = name + 's' |
|
455 | else: names = name + 's' | |
456 | if not values: |
|
456 | if not values: | |
457 | noname = 'no_' + names |
|
457 | noname = 'no_' + names | |
458 | if noname in self.t: |
|
458 | if noname in self.t: | |
459 | yield self.t(noname, **args) |
|
459 | yield self.t(noname, **args) | |
460 | return |
|
460 | return | |
461 | if name not in self.t: |
|
461 | if name not in self.t: | |
462 | if isinstance(values[0], str): |
|
462 | if isinstance(values[0], str): | |
463 | yield ' '.join(values) |
|
463 | yield ' '.join(values) | |
464 | else: |
|
464 | else: | |
465 | for v in values: |
|
465 | for v in values: | |
466 | yield dict(v, **args) |
|
466 | yield dict(v, **args) | |
467 | return |
|
467 | return | |
468 | startname = 'start_' + names |
|
468 | startname = 'start_' + names | |
469 | if startname in self.t: |
|
469 | if startname in self.t: | |
470 | yield self.t(startname, **args) |
|
470 | yield self.t(startname, **args) | |
471 | vargs = args.copy() |
|
471 | vargs = args.copy() | |
472 | def one(v, tag=name): |
|
472 | def one(v, tag=name): | |
473 | try: |
|
473 | try: | |
474 | vargs.update(v) |
|
474 | vargs.update(v) | |
475 | except (AttributeError, ValueError): |
|
475 | except (AttributeError, ValueError): | |
476 | try: |
|
476 | try: | |
477 | for a, b in v: |
|
477 | for a, b in v: | |
478 | vargs[a] = b |
|
478 | vargs[a] = b | |
479 | except ValueError: |
|
479 | except ValueError: | |
480 | vargs[name] = v |
|
480 | vargs[name] = v | |
481 | return self.t(tag, **vargs) |
|
481 | return self.t(tag, **vargs) | |
482 | lastname = 'last_' + name |
|
482 | lastname = 'last_' + name | |
483 | if lastname in self.t: |
|
483 | if lastname in self.t: | |
484 | last = values.pop() |
|
484 | last = values.pop() | |
485 | else: |
|
485 | else: | |
486 | last = None |
|
486 | last = None | |
487 | for v in values: |
|
487 | for v in values: | |
488 | yield one(v) |
|
488 | yield one(v) | |
489 | if last is not None: |
|
489 | if last is not None: | |
490 | yield one(last, tag=lastname) |
|
490 | yield one(last, tag=lastname) | |
491 | endname = 'end_' + names |
|
491 | endname = 'end_' + names | |
492 | if endname in self.t: |
|
492 | if endname in self.t: | |
493 | yield self.t(endname, **args) |
|
493 | yield self.t(endname, **args) | |
494 |
|
494 | |||
495 | if brinfo: |
|
495 | if brinfo: | |
496 | def showbranches(**args): |
|
496 | def showbranches(**args): | |
497 | if changenode in brinfo: |
|
497 | if changenode in brinfo: | |
498 | for x in showlist('branch', brinfo[changenode], |
|
498 | for x in showlist('branch', brinfo[changenode], | |
499 | plural='branches', **args): |
|
499 | plural='branches', **args): | |
500 | yield x |
|
500 | yield x | |
501 | else: |
|
501 | else: | |
502 | showbranches = '' |
|
502 | showbranches = '' | |
503 |
|
503 | |||
504 | if self.ui.debugflag: |
|
504 | if self.ui.debugflag: | |
505 | def showmanifest(**args): |
|
505 | def showmanifest(**args): | |
506 | args = args.copy() |
|
506 | args = args.copy() | |
507 | args.update(dict(rev=self.repo.manifest.rev(changes[0]), |
|
507 | args.update(dict(rev=self.repo.manifest.rev(changes[0]), | |
508 | node=hex(changes[0]))) |
|
508 | node=hex(changes[0]))) | |
509 | yield self.t('manifest', **args) |
|
509 | yield self.t('manifest', **args) | |
510 | else: |
|
510 | else: | |
511 | showmanifest = '' |
|
511 | showmanifest = '' | |
512 |
|
512 | |||
513 | def showparents(**args): |
|
513 | def showparents(**args): | |
514 | parents = [[('rev', log.rev(p)), ('node', hex(p))] |
|
514 | parents = [[('rev', log.rev(p)), ('node', hex(p))] | |
515 | for p in log.parents(changenode) |
|
515 | for p in log.parents(changenode) | |
516 | if self.ui.debugflag or p != nullid] |
|
516 | if self.ui.debugflag or p != nullid] | |
517 | if (not self.ui.debugflag and len(parents) == 1 and |
|
517 | if (not self.ui.debugflag and len(parents) == 1 and | |
518 | parents[0][0][1] == rev - 1): |
|
518 | parents[0][0][1] == rev - 1): | |
519 | return |
|
519 | return | |
520 | for x in showlist('parent', parents, **args): |
|
520 | for x in showlist('parent', parents, **args): | |
521 | yield x |
|
521 | yield x | |
522 |
|
522 | |||
523 | def showtags(**args): |
|
523 | def showtags(**args): | |
524 | for x in showlist('tag', self.repo.nodetags(changenode), **args): |
|
524 | for x in showlist('tag', self.repo.nodetags(changenode), **args): | |
525 | yield x |
|
525 | yield x | |
526 |
|
526 | |||
527 | if self.ui.debugflag: |
|
527 | if self.ui.debugflag: | |
528 | files = self.repo.changes(log.parents(changenode)[0], changenode) |
|
528 | files = self.repo.changes(log.parents(changenode)[0], changenode) | |
529 | def showfiles(**args): |
|
529 | def showfiles(**args): | |
530 | for x in showlist('file', files[0], **args): yield x |
|
530 | for x in showlist('file', files[0], **args): yield x | |
531 | def showadds(**args): |
|
531 | def showadds(**args): | |
532 | for x in showlist('file_add', files[1], **args): yield x |
|
532 | for x in showlist('file_add', files[1], **args): yield x | |
533 | def showdels(**args): |
|
533 | def showdels(**args): | |
534 | for x in showlist('file_del', files[2], **args): yield x |
|
534 | for x in showlist('file_del', files[2], **args): yield x | |
535 | else: |
|
535 | else: | |
536 | def showfiles(**args): |
|
536 | def showfiles(**args): | |
537 | for x in showlist('file', changes[3], **args): yield x |
|
537 | for x in showlist('file', changes[3], **args): yield x | |
538 | showadds = '' |
|
538 | showadds = '' | |
539 | showdels = '' |
|
539 | showdels = '' | |
540 |
|
540 | |||
541 | props = { |
|
541 | props = { | |
542 | 'author': changes[1], |
|
542 | 'author': changes[1], | |
543 | 'branches': showbranches, |
|
543 | 'branches': showbranches, | |
544 | 'date': changes[2], |
|
544 | 'date': changes[2], | |
545 | 'desc': changes[4], |
|
545 | 'desc': changes[4], | |
546 | 'file_adds': showadds, |
|
546 | 'file_adds': showadds, | |
547 | 'file_dels': showdels, |
|
547 | 'file_dels': showdels, | |
548 | 'files': showfiles, |
|
548 | 'files': showfiles, | |
549 | 'manifest': showmanifest, |
|
549 | 'manifest': showmanifest, | |
550 | 'node': hex(changenode), |
|
550 | 'node': hex(changenode), | |
551 | 'parents': showparents, |
|
551 | 'parents': showparents, | |
552 | 'rev': rev, |
|
552 | 'rev': rev, | |
553 | 'tags': showtags, |
|
553 | 'tags': showtags, | |
554 | } |
|
554 | } | |
555 |
|
555 | |||
556 | try: |
|
556 | try: | |
557 | if self.ui.debugflag and 'header_debug' in self.t: |
|
557 | if self.ui.debugflag and 'header_debug' in self.t: | |
558 | key = 'header_debug' |
|
558 | key = 'header_debug' | |
559 | elif self.ui.quiet and 'header_quiet' in self.t: |
|
559 | elif self.ui.quiet and 'header_quiet' in self.t: | |
560 | key = 'header_quiet' |
|
560 | key = 'header_quiet' | |
561 | elif self.ui.verbose and 'header_verbose' in self.t: |
|
561 | elif self.ui.verbose and 'header_verbose' in self.t: | |
562 | key = 'header_verbose' |
|
562 | key = 'header_verbose' | |
563 | elif 'header' in self.t: |
|
563 | elif 'header' in self.t: | |
564 | key = 'header' |
|
564 | key = 'header' | |
565 | else: |
|
565 | else: | |
566 | key = '' |
|
566 | key = '' | |
567 | if key: |
|
567 | if key: | |
568 | self.write_header(self.t(key, **props)) |
|
568 | self.write_header(self.t(key, **props)) | |
569 | if self.ui.debugflag and 'changeset_debug' in self.t: |
|
569 | if self.ui.debugflag and 'changeset_debug' in self.t: | |
570 | key = 'changeset_debug' |
|
570 | key = 'changeset_debug' | |
571 | elif self.ui.quiet and 'changeset_quiet' in self.t: |
|
571 | elif self.ui.quiet and 'changeset_quiet' in self.t: | |
572 | key = 'changeset_quiet' |
|
572 | key = 'changeset_quiet' | |
573 | elif self.ui.verbose and 'changeset_verbose' in self.t: |
|
573 | elif self.ui.verbose and 'changeset_verbose' in self.t: | |
574 | key = 'changeset_verbose' |
|
574 | key = 'changeset_verbose' | |
575 | else: |
|
575 | else: | |
576 | key = 'changeset' |
|
576 | key = 'changeset' | |
577 | self.write(self.t(key, **props)) |
|
577 | self.write(self.t(key, **props)) | |
578 | except KeyError, inst: |
|
578 | except KeyError, inst: | |
579 | raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile, |
|
579 | raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile, | |
580 | inst.args[0])) |
|
580 | inst.args[0])) | |
581 | except SyntaxError, inst: |
|
581 | except SyntaxError, inst: | |
582 | raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0])) |
|
582 | raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0])) | |
583 |
|
583 | |||
584 | class changeset_printer(object): |
|
584 | class changeset_printer(object): | |
585 | '''show changeset information when templating not requested.''' |
|
585 | '''show changeset information when templating not requested.''' | |
586 |
|
586 | |||
587 | def __init__(self, ui, repo): |
|
587 | def __init__(self, ui, repo): | |
588 | self.ui = ui |
|
588 | self.ui = ui | |
589 | self.repo = repo |
|
589 | self.repo = repo | |
590 |
|
590 | |||
591 | def show(self, rev=0, changenode=None, brinfo=None): |
|
591 | def show(self, rev=0, changenode=None, brinfo=None): | |
592 | '''show a single changeset or file revision''' |
|
592 | '''show a single changeset or file revision''' | |
593 | log = self.repo.changelog |
|
593 | log = self.repo.changelog | |
594 | if changenode is None: |
|
594 | if changenode is None: | |
595 | changenode = log.node(rev) |
|
595 | changenode = log.node(rev) | |
596 | elif not rev: |
|
596 | elif not rev: | |
597 | rev = log.rev(changenode) |
|
597 | rev = log.rev(changenode) | |
598 |
|
598 | |||
599 | if self.ui.quiet: |
|
599 | if self.ui.quiet: | |
600 | self.ui.write("%d:%s\n" % (rev, short(changenode))) |
|
600 | self.ui.write("%d:%s\n" % (rev, short(changenode))) | |
601 | return |
|
601 | return | |
602 |
|
602 | |||
603 | changes = log.read(changenode) |
|
603 | changes = log.read(changenode) | |
604 | date = util.datestr(changes[2]) |
|
604 | date = util.datestr(changes[2]) | |
605 |
|
605 | |||
606 | parents = [(log.rev(p), self.ui.verbose and hex(p) or short(p)) |
|
606 | parents = [(log.rev(p), self.ui.verbose and hex(p) or short(p)) | |
607 | for p in log.parents(changenode) |
|
607 | for p in log.parents(changenode) | |
608 | if self.ui.debugflag or p != nullid] |
|
608 | if self.ui.debugflag or p != nullid] | |
609 | if (not self.ui.debugflag and len(parents) == 1 and |
|
609 | if (not self.ui.debugflag and len(parents) == 1 and | |
610 | parents[0][0] == rev-1): |
|
610 | parents[0][0] == rev-1): | |
611 | parents = [] |
|
611 | parents = [] | |
612 |
|
612 | |||
613 | if self.ui.verbose: |
|
613 | if self.ui.verbose: | |
614 | self.ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) |
|
614 | self.ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) | |
615 | else: |
|
615 | else: | |
616 | self.ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) |
|
616 | self.ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) | |
617 |
|
617 | |||
618 | for tag in self.repo.nodetags(changenode): |
|
618 | for tag in self.repo.nodetags(changenode): | |
619 | self.ui.status(_("tag: %s\n") % tag) |
|
619 | self.ui.status(_("tag: %s\n") % tag) | |
620 | for parent in parents: |
|
620 | for parent in parents: | |
621 | self.ui.write(_("parent: %d:%s\n") % parent) |
|
621 | self.ui.write(_("parent: %d:%s\n") % parent) | |
622 |
|
622 | |||
623 | if brinfo and changenode in brinfo: |
|
623 | if brinfo and changenode in brinfo: | |
624 | br = brinfo[changenode] |
|
624 | br = brinfo[changenode] | |
625 | self.ui.write(_("branch: %s\n") % " ".join(br)) |
|
625 | self.ui.write(_("branch: %s\n") % " ".join(br)) | |
626 |
|
626 | |||
627 | self.ui.debug(_("manifest: %d:%s\n") % |
|
627 | self.ui.debug(_("manifest: %d:%s\n") % | |
628 | (self.repo.manifest.rev(changes[0]), hex(changes[0]))) |
|
628 | (self.repo.manifest.rev(changes[0]), hex(changes[0]))) | |
629 | self.ui.status(_("user: %s\n") % changes[1]) |
|
629 | self.ui.status(_("user: %s\n") % changes[1]) | |
630 | self.ui.status(_("date: %s\n") % date) |
|
630 | self.ui.status(_("date: %s\n") % date) | |
631 |
|
631 | |||
632 | if self.ui.debugflag: |
|
632 | if self.ui.debugflag: | |
633 | files = self.repo.changes(log.parents(changenode)[0], changenode) |
|
633 | files = self.repo.changes(log.parents(changenode)[0], changenode) | |
634 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], |
|
634 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], | |
635 | files): |
|
635 | files): | |
636 | if value: |
|
636 | if value: | |
637 | self.ui.note("%-12s %s\n" % (key, " ".join(value))) |
|
637 | self.ui.note("%-12s %s\n" % (key, " ".join(value))) | |
638 | else: |
|
638 | else: | |
639 | self.ui.note(_("files: %s\n") % " ".join(changes[3])) |
|
639 | self.ui.note(_("files: %s\n") % " ".join(changes[3])) | |
640 |
|
640 | |||
641 | description = changes[4].strip() |
|
641 | description = changes[4].strip() | |
642 | if description: |
|
642 | if description: | |
643 | if self.ui.verbose: |
|
643 | if self.ui.verbose: | |
644 | self.ui.status(_("description:\n")) |
|
644 | self.ui.status(_("description:\n")) | |
645 | self.ui.status(description) |
|
645 | self.ui.status(description) | |
646 | self.ui.status("\n\n") |
|
646 | self.ui.status("\n\n") | |
647 | else: |
|
647 | else: | |
648 | self.ui.status(_("summary: %s\n") % |
|
648 | self.ui.status(_("summary: %s\n") % | |
649 | description.splitlines()[0]) |
|
649 | description.splitlines()[0]) | |
650 | self.ui.status("\n") |
|
650 | self.ui.status("\n") | |
651 |
|
651 | |||
652 | def show_changeset(ui, repo, opts): |
|
652 | def show_changeset(ui, repo, opts): | |
653 | '''show one changeset. uses template or regular display. caller |
|
653 | '''show one changeset. uses template or regular display. caller | |
654 | can pass in 'style' and 'template' options in opts.''' |
|
654 | can pass in 'style' and 'template' options in opts.''' | |
655 |
|
655 | |||
656 | tmpl = opts.get('template') |
|
656 | tmpl = opts.get('template') | |
657 | if tmpl: |
|
657 | if tmpl: | |
658 | tmpl = templater.parsestring(tmpl, quoted=False) |
|
658 | tmpl = templater.parsestring(tmpl, quoted=False) | |
659 | else: |
|
659 | else: | |
660 | tmpl = ui.config('ui', 'logtemplate') |
|
660 | tmpl = ui.config('ui', 'logtemplate') | |
661 | if tmpl: tmpl = templater.parsestring(tmpl) |
|
661 | if tmpl: tmpl = templater.parsestring(tmpl) | |
662 | mapfile = opts.get('style') or ui.config('ui', 'style') |
|
662 | mapfile = opts.get('style') or ui.config('ui', 'style') | |
663 | if tmpl or mapfile: |
|
663 | if tmpl or mapfile: | |
664 | if mapfile: |
|
664 | if mapfile: | |
665 | if not os.path.isfile(mapfile): |
|
665 | if not os.path.isfile(mapfile): | |
666 | mapname = templater.templatepath('map-cmdline.' + mapfile) |
|
666 | mapname = templater.templatepath('map-cmdline.' + mapfile) | |
667 | if not mapname: mapname = templater.templatepath(mapfile) |
|
667 | if not mapname: mapname = templater.templatepath(mapfile) | |
668 | if mapname: mapfile = mapname |
|
668 | if mapname: mapfile = mapname | |
669 | try: |
|
669 | try: | |
670 | t = changeset_templater(ui, repo, mapfile) |
|
670 | t = changeset_templater(ui, repo, mapfile) | |
671 | except SyntaxError, inst: |
|
671 | except SyntaxError, inst: | |
672 | raise util.Abort(inst.args[0]) |
|
672 | raise util.Abort(inst.args[0]) | |
673 | if tmpl: t.use_template(tmpl) |
|
673 | if tmpl: t.use_template(tmpl) | |
674 | return t |
|
674 | return t | |
675 | return changeset_printer(ui, repo) |
|
675 | return changeset_printer(ui, repo) | |
676 |
|
676 | |||
677 | def show_version(ui): |
|
677 | def show_version(ui): | |
678 | """output version and copyright information""" |
|
678 | """output version and copyright information""" | |
679 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
679 | ui.write(_("Mercurial Distributed SCM (version %s)\n") | |
680 | % version.get_version()) |
|
680 | % version.get_version()) | |
681 | ui.status(_( |
|
681 | ui.status(_( | |
682 | "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" |
|
682 | "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" | |
683 | "This is free software; see the source for copying conditions. " |
|
683 | "This is free software; see the source for copying conditions. " | |
684 | "There is NO\nwarranty; " |
|
684 | "There is NO\nwarranty; " | |
685 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
685 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | |
686 | )) |
|
686 | )) | |
687 |
|
687 | |||
688 | def help_(ui, cmd=None, with_version=False): |
|
688 | def help_(ui, cmd=None, with_version=False): | |
689 | """show help for a given command or all commands""" |
|
689 | """show help for a given command or all commands""" | |
690 | option_lists = [] |
|
690 | option_lists = [] | |
691 | if cmd and cmd != 'shortlist': |
|
691 | if cmd and cmd != 'shortlist': | |
692 | if with_version: |
|
692 | if with_version: | |
693 | show_version(ui) |
|
693 | show_version(ui) | |
694 | ui.write('\n') |
|
694 | ui.write('\n') | |
695 | aliases, i = find(cmd) |
|
695 | aliases, i = find(cmd) | |
696 | # synopsis |
|
696 | # synopsis | |
697 | ui.write("%s\n\n" % i[2]) |
|
697 | ui.write("%s\n\n" % i[2]) | |
698 |
|
698 | |||
699 | # description |
|
699 | # description | |
700 | doc = i[0].__doc__ |
|
700 | doc = i[0].__doc__ | |
701 | if not doc: |
|
701 | if not doc: | |
702 | doc = _("(No help text available)") |
|
702 | doc = _("(No help text available)") | |
703 | if ui.quiet: |
|
703 | if ui.quiet: | |
704 | doc = doc.splitlines(0)[0] |
|
704 | doc = doc.splitlines(0)[0] | |
705 | ui.write("%s\n" % doc.rstrip()) |
|
705 | ui.write("%s\n" % doc.rstrip()) | |
706 |
|
706 | |||
707 | if not ui.quiet: |
|
707 | if not ui.quiet: | |
708 | # aliases |
|
708 | # aliases | |
709 | if len(aliases) > 1: |
|
709 | if len(aliases) > 1: | |
710 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) |
|
710 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) | |
711 |
|
711 | |||
712 | # options |
|
712 | # options | |
713 | if i[1]: |
|
713 | if i[1]: | |
714 | option_lists.append(("options", i[1])) |
|
714 | option_lists.append(("options", i[1])) | |
715 |
|
715 | |||
716 | else: |
|
716 | else: | |
717 | # program name |
|
717 | # program name | |
718 | if ui.verbose or with_version: |
|
718 | if ui.verbose or with_version: | |
719 | show_version(ui) |
|
719 | show_version(ui) | |
720 | else: |
|
720 | else: | |
721 | ui.status(_("Mercurial Distributed SCM\n")) |
|
721 | ui.status(_("Mercurial Distributed SCM\n")) | |
722 | ui.status('\n') |
|
722 | ui.status('\n') | |
723 |
|
723 | |||
724 | # list of commands |
|
724 | # list of commands | |
725 | if cmd == "shortlist": |
|
725 | if cmd == "shortlist": | |
726 | ui.status(_('basic commands (use "hg help" ' |
|
726 | ui.status(_('basic commands (use "hg help" ' | |
727 | 'for the full list or option "-v" for details):\n\n')) |
|
727 | 'for the full list or option "-v" for details):\n\n')) | |
728 | elif ui.verbose: |
|
728 | elif ui.verbose: | |
729 | ui.status(_('list of commands:\n\n')) |
|
729 | ui.status(_('list of commands:\n\n')) | |
730 | else: |
|
730 | else: | |
731 | ui.status(_('list of commands (use "hg help -v" ' |
|
731 | ui.status(_('list of commands (use "hg help -v" ' | |
732 | 'to show aliases and global options):\n\n')) |
|
732 | 'to show aliases and global options):\n\n')) | |
733 |
|
733 | |||
734 | h = {} |
|
734 | h = {} | |
735 | cmds = {} |
|
735 | cmds = {} | |
736 | for c, e in table.items(): |
|
736 | for c, e in table.items(): | |
737 | f = c.split("|")[0] |
|
737 | f = c.split("|")[0] | |
738 | if cmd == "shortlist" and not f.startswith("^"): |
|
738 | if cmd == "shortlist" and not f.startswith("^"): | |
739 | continue |
|
739 | continue | |
740 | f = f.lstrip("^") |
|
740 | f = f.lstrip("^") | |
741 | if not ui.debugflag and f.startswith("debug"): |
|
741 | if not ui.debugflag and f.startswith("debug"): | |
742 | continue |
|
742 | continue | |
743 | doc = e[0].__doc__ |
|
743 | doc = e[0].__doc__ | |
744 | if not doc: |
|
744 | if not doc: | |
745 | doc = _("(No help text available)") |
|
745 | doc = _("(No help text available)") | |
746 | h[f] = doc.splitlines(0)[0].rstrip() |
|
746 | h[f] = doc.splitlines(0)[0].rstrip() | |
747 | cmds[f] = c.lstrip("^") |
|
747 | cmds[f] = c.lstrip("^") | |
748 |
|
748 | |||
749 | fns = h.keys() |
|
749 | fns = h.keys() | |
750 | fns.sort() |
|
750 | fns.sort() | |
751 | m = max(map(len, fns)) |
|
751 | m = max(map(len, fns)) | |
752 | for f in fns: |
|
752 | for f in fns: | |
753 | if ui.verbose: |
|
753 | if ui.verbose: | |
754 | commands = cmds[f].replace("|",", ") |
|
754 | commands = cmds[f].replace("|",", ") | |
755 | ui.write(" %s:\n %s\n"%(commands, h[f])) |
|
755 | ui.write(" %s:\n %s\n"%(commands, h[f])) | |
756 | else: |
|
756 | else: | |
757 | ui.write(' %-*s %s\n' % (m, f, h[f])) |
|
757 | ui.write(' %-*s %s\n' % (m, f, h[f])) | |
758 |
|
758 | |||
759 | # global options |
|
759 | # global options | |
760 | if ui.verbose: |
|
760 | if ui.verbose: | |
761 | option_lists.append(("global options", globalopts)) |
|
761 | option_lists.append(("global options", globalopts)) | |
762 |
|
762 | |||
763 | # list all option lists |
|
763 | # list all option lists | |
764 | opt_output = [] |
|
764 | opt_output = [] | |
765 | for title, options in option_lists: |
|
765 | for title, options in option_lists: | |
766 | opt_output.append(("\n%s:\n" % title, None)) |
|
766 | opt_output.append(("\n%s:\n" % title, None)) | |
767 | for shortopt, longopt, default, desc in options: |
|
767 | for shortopt, longopt, default, desc in options: | |
768 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, |
|
768 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, | |
769 | longopt and " --%s" % longopt), |
|
769 | longopt and " --%s" % longopt), | |
770 | "%s%s" % (desc, |
|
770 | "%s%s" % (desc, | |
771 | default |
|
771 | default | |
772 | and _(" (default: %s)") % default |
|
772 | and _(" (default: %s)") % default | |
773 | or ""))) |
|
773 | or ""))) | |
774 |
|
774 | |||
775 | if opt_output: |
|
775 | if opt_output: | |
776 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) |
|
776 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) | |
777 | for first, second in opt_output: |
|
777 | for first, second in opt_output: | |
778 | if second: |
|
778 | if second: | |
779 | ui.write(" %-*s %s\n" % (opts_len, first, second)) |
|
779 | ui.write(" %-*s %s\n" % (opts_len, first, second)) | |
780 | else: |
|
780 | else: | |
781 | ui.write("%s\n" % first) |
|
781 | ui.write("%s\n" % first) | |
782 |
|
782 | |||
783 | # Commands start here, listed alphabetically |
|
783 | # Commands start here, listed alphabetically | |
784 |
|
784 | |||
785 | def add(ui, repo, *pats, **opts): |
|
785 | def add(ui, repo, *pats, **opts): | |
786 | """add the specified files on the next commit |
|
786 | """add the specified files on the next commit | |
787 |
|
787 | |||
788 | Schedule files to be version controlled and added to the repository. |
|
788 | Schedule files to be version controlled and added to the repository. | |
789 |
|
789 | |||
790 | The files will be added to the repository at the next commit. |
|
790 | The files will be added to the repository at the next commit. | |
791 |
|
791 | |||
792 | If no names are given, add all files in the repository. |
|
792 | If no names are given, add all files in the repository. | |
793 | """ |
|
793 | """ | |
794 |
|
794 | |||
795 | names = [] |
|
795 | names = [] | |
796 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
796 | for src, abs, rel, exact in walk(repo, pats, opts): | |
797 | if exact: |
|
797 | if exact: | |
798 | if ui.verbose: |
|
798 | if ui.verbose: | |
799 | ui.status(_('adding %s\n') % rel) |
|
799 | ui.status(_('adding %s\n') % rel) | |
800 | names.append(abs) |
|
800 | names.append(abs) | |
801 | elif repo.dirstate.state(abs) == '?': |
|
801 | elif repo.dirstate.state(abs) == '?': | |
802 | ui.status(_('adding %s\n') % rel) |
|
802 | ui.status(_('adding %s\n') % rel) | |
803 | names.append(abs) |
|
803 | names.append(abs) | |
804 | repo.add(names) |
|
804 | repo.add(names) | |
805 |
|
805 | |||
806 | def addremove(ui, repo, *pats, **opts): |
|
806 | def addremove(ui, repo, *pats, **opts): | |
807 | """add all new files, delete all missing files |
|
807 | """add all new files, delete all missing files | |
808 |
|
808 | |||
809 | Add all new files and remove all missing files from the repository. |
|
809 | Add all new files and remove all missing files from the repository. | |
810 |
|
810 | |||
811 | New files are ignored if they match any of the patterns in .hgignore. As |
|
811 | New files are ignored if they match any of the patterns in .hgignore. As | |
812 | with add, these changes take effect at the next commit. |
|
812 | with add, these changes take effect at the next commit. | |
813 | """ |
|
813 | """ | |
814 | return addremove_lock(ui, repo, pats, opts) |
|
814 | return addremove_lock(ui, repo, pats, opts) | |
815 |
|
815 | |||
816 | def addremove_lock(ui, repo, pats, opts, wlock=None): |
|
816 | def addremove_lock(ui, repo, pats, opts, wlock=None): | |
817 | add, remove = [], [] |
|
817 | add, remove = [], [] | |
818 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
818 | for src, abs, rel, exact in walk(repo, pats, opts): | |
819 | if src == 'f' and repo.dirstate.state(abs) == '?': |
|
819 | if src == 'f' and repo.dirstate.state(abs) == '?': | |
820 | add.append(abs) |
|
820 | add.append(abs) | |
821 | if ui.verbose or not exact: |
|
821 | if ui.verbose or not exact: | |
822 | ui.status(_('adding %s\n') % ((pats and rel) or abs)) |
|
822 | ui.status(_('adding %s\n') % ((pats and rel) or abs)) | |
823 | if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): |
|
823 | if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): | |
824 | remove.append(abs) |
|
824 | remove.append(abs) | |
825 | if ui.verbose or not exact: |
|
825 | if ui.verbose or not exact: | |
826 | ui.status(_('removing %s\n') % ((pats and rel) or abs)) |
|
826 | ui.status(_('removing %s\n') % ((pats and rel) or abs)) | |
827 | repo.add(add, wlock=wlock) |
|
827 | repo.add(add, wlock=wlock) | |
828 | repo.remove(remove, wlock=wlock) |
|
828 | repo.remove(remove, wlock=wlock) | |
829 |
|
829 | |||
830 | def annotate(ui, repo, *pats, **opts): |
|
830 | def annotate(ui, repo, *pats, **opts): | |
831 | """show changeset information per file line |
|
831 | """show changeset information per file line | |
832 |
|
832 | |||
833 | List changes in files, showing the revision id responsible for each line |
|
833 | List changes in files, showing the revision id responsible for each line | |
834 |
|
834 | |||
835 | This command is useful to discover who did a change or when a change took |
|
835 | This command is useful to discover who did a change or when a change took | |
836 | place. |
|
836 | place. | |
837 |
|
837 | |||
838 | Without the -a option, annotate will avoid processing files it |
|
838 | Without the -a option, annotate will avoid processing files it | |
839 | detects as binary. With -a, annotate will generate an annotation |
|
839 | detects as binary. With -a, annotate will generate an annotation | |
840 | anyway, probably with undesirable results. |
|
840 | anyway, probably with undesirable results. | |
841 | """ |
|
841 | """ | |
842 | def getnode(rev): |
|
842 | def getnode(rev): | |
843 | return short(repo.changelog.node(rev)) |
|
843 | return short(repo.changelog.node(rev)) | |
844 |
|
844 | |||
845 | ucache = {} |
|
845 | ucache = {} | |
846 | def getname(rev): |
|
846 | def getname(rev): | |
847 | cl = repo.changelog.read(repo.changelog.node(rev)) |
|
847 | cl = repo.changelog.read(repo.changelog.node(rev)) | |
848 | return trimuser(ui, cl[1], rev, ucache) |
|
848 | return trimuser(ui, cl[1], rev, ucache) | |
849 |
|
849 | |||
850 | dcache = {} |
|
850 | dcache = {} | |
851 | def getdate(rev): |
|
851 | def getdate(rev): | |
852 | datestr = dcache.get(rev) |
|
852 | datestr = dcache.get(rev) | |
853 | if datestr is None: |
|
853 | if datestr is None: | |
854 | cl = repo.changelog.read(repo.changelog.node(rev)) |
|
854 | cl = repo.changelog.read(repo.changelog.node(rev)) | |
855 | datestr = dcache[rev] = util.datestr(cl[2]) |
|
855 | datestr = dcache[rev] = util.datestr(cl[2]) | |
856 | return datestr |
|
856 | return datestr | |
857 |
|
857 | |||
858 | if not pats: |
|
858 | if not pats: | |
859 | raise util.Abort(_('at least one file name or pattern required')) |
|
859 | raise util.Abort(_('at least one file name or pattern required')) | |
860 |
|
860 | |||
861 | opmap = [['user', getname], ['number', str], ['changeset', getnode], |
|
861 | opmap = [['user', getname], ['number', str], ['changeset', getnode], | |
862 | ['date', getdate]] |
|
862 | ['date', getdate]] | |
863 | if not opts['user'] and not opts['changeset'] and not opts['date']: |
|
863 | if not opts['user'] and not opts['changeset'] and not opts['date']: | |
864 | opts['number'] = 1 |
|
864 | opts['number'] = 1 | |
865 |
|
865 | |||
866 | if opts['rev']: |
|
866 | if opts['rev']: | |
867 | node = repo.changelog.lookup(opts['rev']) |
|
867 | node = repo.changelog.lookup(opts['rev']) | |
868 | else: |
|
868 | else: | |
869 | node = repo.dirstate.parents()[0] |
|
869 | node = repo.dirstate.parents()[0] | |
870 | change = repo.changelog.read(node) |
|
870 | change = repo.changelog.read(node) | |
871 | mmap = repo.manifest.read(change[0]) |
|
871 | mmap = repo.manifest.read(change[0]) | |
872 |
|
872 | |||
873 | for src, abs, rel, exact in walk(repo, pats, opts, node=node): |
|
873 | for src, abs, rel, exact in walk(repo, pats, opts, node=node): | |
874 | f = repo.file(abs) |
|
874 | f = repo.file(abs) | |
875 | if not opts['text'] and util.binary(f.read(mmap[abs])): |
|
875 | if not opts['text'] and util.binary(f.read(mmap[abs])): | |
876 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) |
|
876 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) | |
877 | continue |
|
877 | continue | |
878 |
|
878 | |||
879 | lines = f.annotate(mmap[abs]) |
|
879 | lines = f.annotate(mmap[abs]) | |
880 | pieces = [] |
|
880 | pieces = [] | |
881 |
|
881 | |||
882 | for o, f in opmap: |
|
882 | for o, f in opmap: | |
883 | if opts[o]: |
|
883 | if opts[o]: | |
884 | l = [f(n) for n, dummy in lines] |
|
884 | l = [f(n) for n, dummy in lines] | |
885 | if l: |
|
885 | if l: | |
886 | m = max(map(len, l)) |
|
886 | m = max(map(len, l)) | |
887 | pieces.append(["%*s" % (m, x) for x in l]) |
|
887 | pieces.append(["%*s" % (m, x) for x in l]) | |
888 |
|
888 | |||
889 | if pieces: |
|
889 | if pieces: | |
890 | for p, l in zip(zip(*pieces), lines): |
|
890 | for p, l in zip(zip(*pieces), lines): | |
891 | ui.write("%s: %s" % (" ".join(p), l[1])) |
|
891 | ui.write("%s: %s" % (" ".join(p), l[1])) | |
892 |
|
892 | |||
893 | def bundle(ui, repo, fname, dest="default-push", **opts): |
|
893 | def bundle(ui, repo, fname, dest="default-push", **opts): | |
894 | """create a changegroup file |
|
894 | """create a changegroup file | |
895 |
|
895 | |||
896 | Generate a compressed changegroup file collecting all changesets |
|
896 | Generate a compressed changegroup file collecting all changesets | |
897 | not found in the other repository. |
|
897 | not found in the other repository. | |
898 |
|
898 | |||
899 | This file can then be transferred using conventional means and |
|
899 | This file can then be transferred using conventional means and | |
900 | applied to another repository with the unbundle command. This is |
|
900 | applied to another repository with the unbundle command. This is | |
901 | useful when native push and pull are not available or when |
|
901 | useful when native push and pull are not available or when | |
902 | exporting an entire repository is undesirable. The standard file |
|
902 | exporting an entire repository is undesirable. The standard file | |
903 | extension is ".hg". |
|
903 | extension is ".hg". | |
904 |
|
904 | |||
905 | Unlike import/export, this exactly preserves all changeset |
|
905 | Unlike import/export, this exactly preserves all changeset | |
906 | contents including permissions, rename data, and revision history. |
|
906 | contents including permissions, rename data, and revision history. | |
907 | """ |
|
907 | """ | |
908 | dest = ui.expandpath(dest) |
|
908 | dest = ui.expandpath(dest) | |
909 | other = hg.repository(ui, dest) |
|
909 | other = hg.repository(ui, dest) | |
910 | o = repo.findoutgoing(other, force=opts['force']) |
|
910 | o = repo.findoutgoing(other, force=opts['force']) | |
911 | cg = repo.changegroup(o, 'bundle') |
|
911 | cg = repo.changegroup(o, 'bundle') | |
912 | write_bundle(cg, fname) |
|
912 | write_bundle(cg, fname) | |
913 |
|
913 | |||
914 | def cat(ui, repo, file1, *pats, **opts): |
|
914 | def cat(ui, repo, file1, *pats, **opts): | |
915 | """output the latest or given revisions of files |
|
915 | """output the latest or given revisions of files | |
916 |
|
916 | |||
917 | Print the specified files as they were at the given revision. |
|
917 | Print the specified files as they were at the given revision. | |
918 | If no revision is given then the tip is used. |
|
918 | If no revision is given then the tip is used. | |
919 |
|
919 | |||
920 | Output may be to a file, in which case the name of the file is |
|
920 | Output may be to a file, in which case the name of the file is | |
921 | given using a format string. The formatting rules are the same as |
|
921 | given using a format string. The formatting rules are the same as | |
922 | for the export command, with the following additions: |
|
922 | for the export command, with the following additions: | |
923 |
|
923 | |||
924 | %s basename of file being printed |
|
924 | %s basename of file being printed | |
925 | %d dirname of file being printed, or '.' if in repo root |
|
925 | %d dirname of file being printed, or '.' if in repo root | |
926 | %p root-relative path name of file being printed |
|
926 | %p root-relative path name of file being printed | |
927 | """ |
|
927 | """ | |
928 | mf = {} |
|
928 | mf = {} | |
929 | rev = opts['rev'] |
|
929 | rev = opts['rev'] | |
930 | if rev: |
|
930 | if rev: | |
931 | node = repo.lookup(rev) |
|
931 | node = repo.lookup(rev) | |
932 | else: |
|
932 | else: | |
933 | node = repo.changelog.tip() |
|
933 | node = repo.changelog.tip() | |
934 | change = repo.changelog.read(node) |
|
934 | change = repo.changelog.read(node) | |
935 | mf = repo.manifest.read(change[0]) |
|
935 | mf = repo.manifest.read(change[0]) | |
936 | for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): |
|
936 | for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): | |
937 | r = repo.file(abs) |
|
937 | r = repo.file(abs) | |
938 | n = mf[abs] |
|
938 | n = mf[abs] | |
939 | fp = make_file(repo, r, opts['output'], node=n, pathname=abs) |
|
939 | fp = make_file(repo, r, opts['output'], node=n, pathname=abs) | |
940 | fp.write(r.read(n)) |
|
940 | fp.write(r.read(n)) | |
941 |
|
941 | |||
942 | def clone(ui, source, dest=None, **opts): |
|
942 | def clone(ui, source, dest=None, **opts): | |
943 | """make a copy of an existing repository |
|
943 | """make a copy of an existing repository | |
944 |
|
944 | |||
945 | Create a copy of an existing repository in a new directory. |
|
945 | Create a copy of an existing repository in a new directory. | |
946 |
|
946 | |||
947 | If no destination directory name is specified, it defaults to the |
|
947 | If no destination directory name is specified, it defaults to the | |
948 | basename of the source. |
|
948 | basename of the source. | |
949 |
|
949 | |||
950 | The location of the source is added to the new repository's |
|
950 | The location of the source is added to the new repository's | |
951 | .hg/hgrc file, as the default to be used for future pulls. |
|
951 | .hg/hgrc file, as the default to be used for future pulls. | |
952 |
|
952 | |||
953 | For efficiency, hardlinks are used for cloning whenever the source |
|
953 | For efficiency, hardlinks are used for cloning whenever the source | |
954 | and destination are on the same filesystem. Some filesystems, |
|
954 | and destination are on the same filesystem. Some filesystems, | |
955 | such as AFS, implement hardlinking incorrectly, but do not report |
|
955 | such as AFS, implement hardlinking incorrectly, but do not report | |
956 | errors. In these cases, use the --pull option to avoid |
|
956 | errors. In these cases, use the --pull option to avoid | |
957 | hardlinking. |
|
957 | hardlinking. | |
958 |
|
958 | |||
959 | See pull for valid source format details. |
|
959 | See pull for valid source format details. | |
960 | """ |
|
960 | """ | |
961 | if dest is None: |
|
961 | if dest is None: | |
962 | dest = os.path.basename(os.path.normpath(source)) |
|
962 | dest = os.path.basename(os.path.normpath(source)) | |
963 |
|
963 | |||
964 | if os.path.exists(dest): |
|
964 | if os.path.exists(dest): | |
965 | raise util.Abort(_("destination '%s' already exists"), dest) |
|
965 | raise util.Abort(_("destination '%s' already exists"), dest) | |
966 |
|
966 | |||
967 | dest = os.path.realpath(dest) |
|
967 | dest = os.path.realpath(dest) | |
968 |
|
968 | |||
969 | class Dircleanup(object): |
|
969 | class Dircleanup(object): | |
970 | def __init__(self, dir_): |
|
970 | def __init__(self, dir_): | |
971 | self.rmtree = shutil.rmtree |
|
971 | self.rmtree = shutil.rmtree | |
972 | self.dir_ = dir_ |
|
972 | self.dir_ = dir_ | |
973 | os.mkdir(dir_) |
|
973 | os.mkdir(dir_) | |
974 | def close(self): |
|
974 | def close(self): | |
975 | self.dir_ = None |
|
975 | self.dir_ = None | |
976 | def __del__(self): |
|
976 | def __del__(self): | |
977 | if self.dir_: |
|
977 | if self.dir_: | |
978 | self.rmtree(self.dir_, True) |
|
978 | self.rmtree(self.dir_, True) | |
979 |
|
979 | |||
980 | if opts['ssh']: |
|
980 | if opts['ssh']: | |
981 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
981 | ui.setconfig("ui", "ssh", opts['ssh']) | |
982 | if opts['remotecmd']: |
|
982 | if opts['remotecmd']: | |
983 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
983 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
984 |
|
984 | |||
985 | source = ui.expandpath(source) |
|
985 | source = ui.expandpath(source) | |
986 |
|
986 | |||
987 | d = Dircleanup(dest) |
|
987 | d = Dircleanup(dest) | |
988 | abspath = source |
|
988 | abspath = source | |
989 | other = hg.repository(ui, source) |
|
989 | other = hg.repository(ui, source) | |
990 |
|
990 | |||
991 | copy = False |
|
991 | copy = False | |
992 | if other.dev() != -1: |
|
992 | if other.dev() != -1: | |
993 | abspath = os.path.abspath(source) |
|
993 | abspath = os.path.abspath(source) | |
994 | if not opts['pull'] and not opts['rev']: |
|
994 | if not opts['pull'] and not opts['rev']: | |
995 | copy = True |
|
995 | copy = True | |
996 |
|
996 | |||
997 | if copy: |
|
997 | if copy: | |
998 | try: |
|
998 | try: | |
999 | # we use a lock here because if we race with commit, we |
|
999 | # we use a lock here because if we race with commit, we | |
1000 | # can end up with extra data in the cloned revlogs that's |
|
1000 | # can end up with extra data in the cloned revlogs that's | |
1001 | # not pointed to by changesets, thus causing verify to |
|
1001 | # not pointed to by changesets, thus causing verify to | |
1002 | # fail |
|
1002 | # fail | |
1003 | l1 = other.lock() |
|
1003 | l1 = other.lock() | |
1004 | except lock.LockException: |
|
1004 | except lock.LockException: | |
1005 | copy = False |
|
1005 | copy = False | |
1006 |
|
1006 | |||
1007 | if copy: |
|
1007 | if copy: | |
1008 | # we lock here to avoid premature writing to the target |
|
1008 | # we lock here to avoid premature writing to the target | |
1009 | os.mkdir(os.path.join(dest, ".hg")) |
|
1009 | os.mkdir(os.path.join(dest, ".hg")) | |
1010 | l2 = lock.lock(os.path.join(dest, ".hg", "lock")) |
|
1010 | l2 = lock.lock(os.path.join(dest, ".hg", "lock")) | |
1011 |
|
1011 | |||
1012 | files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" |
|
1012 | files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" | |
1013 | for f in files.split(): |
|
1013 | for f in files.split(): | |
1014 | src = os.path.join(source, ".hg", f) |
|
1014 | src = os.path.join(source, ".hg", f) | |
1015 | dst = os.path.join(dest, ".hg", f) |
|
1015 | dst = os.path.join(dest, ".hg", f) | |
1016 | try: |
|
1016 | try: | |
1017 | util.copyfiles(src, dst) |
|
1017 | util.copyfiles(src, dst) | |
1018 | except OSError, inst: |
|
1018 | except OSError, inst: | |
1019 | if inst.errno != errno.ENOENT: |
|
1019 | if inst.errno != errno.ENOENT: | |
1020 | raise |
|
1020 | raise | |
1021 |
|
1021 | |||
1022 | repo = hg.repository(ui, dest) |
|
1022 | repo = hg.repository(ui, dest) | |
1023 |
|
1023 | |||
1024 | else: |
|
1024 | else: | |
1025 | revs = None |
|
1025 | revs = None | |
1026 | if opts['rev']: |
|
1026 | if opts['rev']: | |
1027 | if not other.local(): |
|
1027 | if not other.local(): | |
1028 | error = _("clone -r not supported yet for remote repositories.") |
|
1028 | error = _("clone -r not supported yet for remote repositories.") | |
1029 | raise util.Abort(error) |
|
1029 | raise util.Abort(error) | |
1030 | else: |
|
1030 | else: | |
1031 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
1031 | revs = [other.lookup(rev) for rev in opts['rev']] | |
1032 | repo = hg.repository(ui, dest, create=1) |
|
1032 | repo = hg.repository(ui, dest, create=1) | |
1033 | repo.pull(other, heads = revs) |
|
1033 | repo.pull(other, heads = revs) | |
1034 |
|
1034 | |||
1035 | f = repo.opener("hgrc", "w", text=True) |
|
1035 | f = repo.opener("hgrc", "w", text=True) | |
1036 | f.write("[paths]\n") |
|
1036 | f.write("[paths]\n") | |
1037 | f.write("default = %s\n" % abspath) |
|
1037 | f.write("default = %s\n" % abspath) | |
1038 | f.close() |
|
1038 | f.close() | |
1039 |
|
1039 | |||
1040 | if not opts['noupdate']: |
|
1040 | if not opts['noupdate']: | |
1041 | update(repo.ui, repo) |
|
1041 | update(repo.ui, repo) | |
1042 |
|
1042 | |||
1043 | d.close() |
|
1043 | d.close() | |
1044 |
|
1044 | |||
1045 | def commit(ui, repo, *pats, **opts): |
|
1045 | def commit(ui, repo, *pats, **opts): | |
1046 | """commit the specified files or all outstanding changes |
|
1046 | """commit the specified files or all outstanding changes | |
1047 |
|
1047 | |||
1048 | Commit changes to the given files into the repository. |
|
1048 | Commit changes to the given files into the repository. | |
1049 |
|
1049 | |||
1050 | If a list of files is omitted, all changes reported by "hg status" |
|
1050 | If a list of files is omitted, all changes reported by "hg status" | |
1051 | will be committed. |
|
1051 | will be committed. | |
1052 |
|
1052 | |||
1053 | If no commit message is specified, the editor configured in your hgrc |
|
1053 | If no commit message is specified, the editor configured in your hgrc | |
1054 | or in the EDITOR environment variable is started to enter a message. |
|
1054 | or in the EDITOR environment variable is started to enter a message. | |
1055 | """ |
|
1055 | """ | |
1056 | message = opts['message'] |
|
1056 | message = opts['message'] | |
1057 | logfile = opts['logfile'] |
|
1057 | logfile = opts['logfile'] | |
1058 |
|
1058 | |||
1059 | if message and logfile: |
|
1059 | if message and logfile: | |
1060 | raise util.Abort(_('options --message and --logfile are mutually ' |
|
1060 | raise util.Abort(_('options --message and --logfile are mutually ' | |
1061 | 'exclusive')) |
|
1061 | 'exclusive')) | |
1062 | if not message and logfile: |
|
1062 | if not message and logfile: | |
1063 | try: |
|
1063 | try: | |
1064 | if logfile == '-': |
|
1064 | if logfile == '-': | |
1065 | message = sys.stdin.read() |
|
1065 | message = sys.stdin.read() | |
1066 | else: |
|
1066 | else: | |
1067 | message = open(logfile).read() |
|
1067 | message = open(logfile).read() | |
1068 | except IOError, inst: |
|
1068 | except IOError, inst: | |
1069 | raise util.Abort(_("can't read commit message '%s': %s") % |
|
1069 | raise util.Abort(_("can't read commit message '%s': %s") % | |
1070 | (logfile, inst.strerror)) |
|
1070 | (logfile, inst.strerror)) | |
1071 |
|
1071 | |||
1072 | if opts['addremove']: |
|
1072 | if opts['addremove']: | |
1073 | addremove(ui, repo, *pats, **opts) |
|
1073 | addremove(ui, repo, *pats, **opts) | |
1074 | fns, match, anypats = matchpats(repo, pats, opts) |
|
1074 | fns, match, anypats = matchpats(repo, pats, opts) | |
1075 | if pats: |
|
1075 | if pats: | |
1076 | modified, added, removed, deleted, unknown = ( |
|
1076 | modified, added, removed, deleted, unknown = ( | |
1077 | repo.changes(files=fns, match=match)) |
|
1077 | repo.changes(files=fns, match=match)) | |
1078 | files = modified + added + removed |
|
1078 | files = modified + added + removed | |
1079 | else: |
|
1079 | else: | |
1080 | files = [] |
|
1080 | files = [] | |
1081 | try: |
|
1081 | try: | |
1082 | repo.commit(files, message, opts['user'], opts['date'], match) |
|
1082 | repo.commit(files, message, opts['user'], opts['date'], match) | |
1083 | except ValueError, inst: |
|
1083 | except ValueError, inst: | |
1084 | raise util.Abort(str(inst)) |
|
1084 | raise util.Abort(str(inst)) | |
1085 |
|
1085 | |||
1086 | def docopy(ui, repo, pats, opts, wlock): |
|
1086 | def docopy(ui, repo, pats, opts, wlock): | |
1087 | # called with the repo lock held |
|
1087 | # called with the repo lock held | |
1088 | cwd = repo.getcwd() |
|
1088 | cwd = repo.getcwd() | |
1089 | errors = 0 |
|
1089 | errors = 0 | |
1090 | copied = [] |
|
1090 | copied = [] | |
1091 | targets = {} |
|
1091 | targets = {} | |
1092 |
|
1092 | |||
1093 | def okaytocopy(abs, rel, exact): |
|
1093 | def okaytocopy(abs, rel, exact): | |
1094 | reasons = {'?': _('is not managed'), |
|
1094 | reasons = {'?': _('is not managed'), | |
1095 | 'a': _('has been marked for add'), |
|
1095 | 'a': _('has been marked for add'), | |
1096 | 'r': _('has been marked for remove')} |
|
1096 | 'r': _('has been marked for remove')} | |
1097 | state = repo.dirstate.state(abs) |
|
1097 | state = repo.dirstate.state(abs) | |
1098 | reason = reasons.get(state) |
|
1098 | reason = reasons.get(state) | |
1099 | if reason: |
|
1099 | if reason: | |
1100 | if state == 'a': |
|
1100 | if state == 'a': | |
1101 | origsrc = repo.dirstate.copied(abs) |
|
1101 | origsrc = repo.dirstate.copied(abs) | |
1102 | if origsrc is not None: |
|
1102 | if origsrc is not None: | |
1103 | return origsrc |
|
1103 | return origsrc | |
1104 | if exact: |
|
1104 | if exact: | |
1105 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) |
|
1105 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) | |
1106 | else: |
|
1106 | else: | |
1107 | return abs |
|
1107 | return abs | |
1108 |
|
1108 | |||
1109 | def copy(origsrc, abssrc, relsrc, target, exact): |
|
1109 | def copy(origsrc, abssrc, relsrc, target, exact): | |
1110 | abstarget = util.canonpath(repo.root, cwd, target) |
|
1110 | abstarget = util.canonpath(repo.root, cwd, target) | |
1111 | reltarget = util.pathto(cwd, abstarget) |
|
1111 | reltarget = util.pathto(cwd, abstarget) | |
1112 | prevsrc = targets.get(abstarget) |
|
1112 | prevsrc = targets.get(abstarget) | |
1113 | if prevsrc is not None: |
|
1113 | if prevsrc is not None: | |
1114 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
|
1114 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % | |
1115 | (reltarget, abssrc, prevsrc)) |
|
1115 | (reltarget, abssrc, prevsrc)) | |
1116 | return |
|
1116 | return | |
1117 | if (not opts['after'] and os.path.exists(reltarget) or |
|
1117 | if (not opts['after'] and os.path.exists(reltarget) or | |
1118 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): |
|
1118 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): | |
1119 | if not opts['force']: |
|
1119 | if not opts['force']: | |
1120 | ui.warn(_('%s: not overwriting - file exists\n') % |
|
1120 | ui.warn(_('%s: not overwriting - file exists\n') % | |
1121 | reltarget) |
|
1121 | reltarget) | |
1122 | return |
|
1122 | return | |
1123 | if not opts['after']: |
|
1123 | if not opts['after']: | |
1124 | os.unlink(reltarget) |
|
1124 | os.unlink(reltarget) | |
1125 | if opts['after']: |
|
1125 | if opts['after']: | |
1126 | if not os.path.exists(reltarget): |
|
1126 | if not os.path.exists(reltarget): | |
1127 | return |
|
1127 | return | |
1128 | else: |
|
1128 | else: | |
1129 | targetdir = os.path.dirname(reltarget) or '.' |
|
1129 | targetdir = os.path.dirname(reltarget) or '.' | |
1130 | if not os.path.isdir(targetdir): |
|
1130 | if not os.path.isdir(targetdir): | |
1131 | os.makedirs(targetdir) |
|
1131 | os.makedirs(targetdir) | |
1132 | try: |
|
1132 | try: | |
1133 | restore = repo.dirstate.state(abstarget) == 'r' |
|
1133 | restore = repo.dirstate.state(abstarget) == 'r' | |
1134 | if restore: |
|
1134 | if restore: | |
1135 | repo.undelete([abstarget], wlock) |
|
1135 | repo.undelete([abstarget], wlock) | |
1136 | try: |
|
1136 | try: | |
1137 | shutil.copyfile(relsrc, reltarget) |
|
1137 | shutil.copyfile(relsrc, reltarget) | |
1138 | shutil.copymode(relsrc, reltarget) |
|
1138 | shutil.copymode(relsrc, reltarget) | |
1139 | restore = False |
|
1139 | restore = False | |
1140 | finally: |
|
1140 | finally: | |
1141 | if restore: |
|
1141 | if restore: | |
1142 | repo.remove([abstarget], wlock) |
|
1142 | repo.remove([abstarget], wlock) | |
1143 | except shutil.Error, inst: |
|
1143 | except shutil.Error, inst: | |
1144 | raise util.Abort(str(inst)) |
|
1144 | raise util.Abort(str(inst)) | |
1145 | except IOError, inst: |
|
1145 | except IOError, inst: | |
1146 | if inst.errno == errno.ENOENT: |
|
1146 | if inst.errno == errno.ENOENT: | |
1147 | ui.warn(_('%s: deleted in working copy\n') % relsrc) |
|
1147 | ui.warn(_('%s: deleted in working copy\n') % relsrc) | |
1148 | else: |
|
1148 | else: | |
1149 | ui.warn(_('%s: cannot copy - %s\n') % |
|
1149 | ui.warn(_('%s: cannot copy - %s\n') % | |
1150 | (relsrc, inst.strerror)) |
|
1150 | (relsrc, inst.strerror)) | |
1151 | errors += 1 |
|
1151 | errors += 1 | |
1152 | return |
|
1152 | return | |
1153 | if ui.verbose or not exact: |
|
1153 | if ui.verbose or not exact: | |
1154 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
|
1154 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) | |
1155 | targets[abstarget] = abssrc |
|
1155 | targets[abstarget] = abssrc | |
1156 | if abstarget != origsrc: |
|
1156 | if abstarget != origsrc: | |
1157 | repo.copy(origsrc, abstarget, wlock) |
|
1157 | repo.copy(origsrc, abstarget, wlock) | |
1158 | copied.append((abssrc, relsrc, exact)) |
|
1158 | copied.append((abssrc, relsrc, exact)) | |
1159 |
|
1159 | |||
1160 | def targetpathfn(pat, dest, srcs): |
|
1160 | def targetpathfn(pat, dest, srcs): | |
1161 | if os.path.isdir(pat): |
|
1161 | if os.path.isdir(pat): | |
1162 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
1162 | abspfx = util.canonpath(repo.root, cwd, pat) | |
1163 | if destdirexists: |
|
1163 | if destdirexists: | |
1164 | striplen = len(os.path.split(abspfx)[0]) |
|
1164 | striplen = len(os.path.split(abspfx)[0]) | |
1165 | else: |
|
1165 | else: | |
1166 | striplen = len(abspfx) |
|
1166 | striplen = len(abspfx) | |
1167 | if striplen: |
|
1167 | if striplen: | |
1168 | striplen += len(os.sep) |
|
1168 | striplen += len(os.sep) | |
1169 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
1169 | res = lambda p: os.path.join(dest, p[striplen:]) | |
1170 | elif destdirexists: |
|
1170 | elif destdirexists: | |
1171 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1171 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1172 | else: |
|
1172 | else: | |
1173 | res = lambda p: dest |
|
1173 | res = lambda p: dest | |
1174 | return res |
|
1174 | return res | |
1175 |
|
1175 | |||
1176 | def targetpathafterfn(pat, dest, srcs): |
|
1176 | def targetpathafterfn(pat, dest, srcs): | |
1177 | if util.patkind(pat, None)[0]: |
|
1177 | if util.patkind(pat, None)[0]: | |
1178 | # a mercurial pattern |
|
1178 | # a mercurial pattern | |
1179 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1179 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1180 | else: |
|
1180 | else: | |
1181 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
1181 | abspfx = util.canonpath(repo.root, cwd, pat) | |
1182 | if len(abspfx) < len(srcs[0][0]): |
|
1182 | if len(abspfx) < len(srcs[0][0]): | |
1183 | # A directory. Either the target path contains the last |
|
1183 | # A directory. Either the target path contains the last | |
1184 | # component of the source path or it does not. |
|
1184 | # component of the source path or it does not. | |
1185 | def evalpath(striplen): |
|
1185 | def evalpath(striplen): | |
1186 | score = 0 |
|
1186 | score = 0 | |
1187 | for s in srcs: |
|
1187 | for s in srcs: | |
1188 | t = os.path.join(dest, s[0][striplen:]) |
|
1188 | t = os.path.join(dest, s[0][striplen:]) | |
1189 | if os.path.exists(t): |
|
1189 | if os.path.exists(t): | |
1190 | score += 1 |
|
1190 | score += 1 | |
1191 | return score |
|
1191 | return score | |
1192 |
|
1192 | |||
1193 | striplen = len(abspfx) |
|
1193 | striplen = len(abspfx) | |
1194 | if striplen: |
|
1194 | if striplen: | |
1195 | striplen += len(os.sep) |
|
1195 | striplen += len(os.sep) | |
1196 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
|
1196 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): | |
1197 | score = evalpath(striplen) |
|
1197 | score = evalpath(striplen) | |
1198 | striplen1 = len(os.path.split(abspfx)[0]) |
|
1198 | striplen1 = len(os.path.split(abspfx)[0]) | |
1199 | if striplen1: |
|
1199 | if striplen1: | |
1200 | striplen1 += len(os.sep) |
|
1200 | striplen1 += len(os.sep) | |
1201 | if evalpath(striplen1) > score: |
|
1201 | if evalpath(striplen1) > score: | |
1202 | striplen = striplen1 |
|
1202 | striplen = striplen1 | |
1203 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
1203 | res = lambda p: os.path.join(dest, p[striplen:]) | |
1204 | else: |
|
1204 | else: | |
1205 | # a file |
|
1205 | # a file | |
1206 | if destdirexists: |
|
1206 | if destdirexists: | |
1207 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1207 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1208 | else: |
|
1208 | else: | |
1209 | res = lambda p: dest |
|
1209 | res = lambda p: dest | |
1210 | return res |
|
1210 | return res | |
1211 |
|
1211 | |||
1212 |
|
1212 | |||
1213 | pats = list(pats) |
|
1213 | pats = list(pats) | |
1214 | if not pats: |
|
1214 | if not pats: | |
1215 | raise util.Abort(_('no source or destination specified')) |
|
1215 | raise util.Abort(_('no source or destination specified')) | |
1216 | if len(pats) == 1: |
|
1216 | if len(pats) == 1: | |
1217 | raise util.Abort(_('no destination specified')) |
|
1217 | raise util.Abort(_('no destination specified')) | |
1218 | dest = pats.pop() |
|
1218 | dest = pats.pop() | |
1219 | destdirexists = os.path.isdir(dest) |
|
1219 | destdirexists = os.path.isdir(dest) | |
1220 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: |
|
1220 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: | |
1221 | raise util.Abort(_('with multiple sources, destination must be an ' |
|
1221 | raise util.Abort(_('with multiple sources, destination must be an ' | |
1222 | 'existing directory')) |
|
1222 | 'existing directory')) | |
1223 | if opts['after']: |
|
1223 | if opts['after']: | |
1224 | tfn = targetpathafterfn |
|
1224 | tfn = targetpathafterfn | |
1225 | else: |
|
1225 | else: | |
1226 | tfn = targetpathfn |
|
1226 | tfn = targetpathfn | |
1227 | copylist = [] |
|
1227 | copylist = [] | |
1228 | for pat in pats: |
|
1228 | for pat in pats: | |
1229 | srcs = [] |
|
1229 | srcs = [] | |
1230 | for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): |
|
1230 | for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): | |
1231 | origsrc = okaytocopy(abssrc, relsrc, exact) |
|
1231 | origsrc = okaytocopy(abssrc, relsrc, exact) | |
1232 | if origsrc: |
|
1232 | if origsrc: | |
1233 | srcs.append((origsrc, abssrc, relsrc, exact)) |
|
1233 | srcs.append((origsrc, abssrc, relsrc, exact)) | |
1234 | if not srcs: |
|
1234 | if not srcs: | |
1235 | continue |
|
1235 | continue | |
1236 | copylist.append((tfn(pat, dest, srcs), srcs)) |
|
1236 | copylist.append((tfn(pat, dest, srcs), srcs)) | |
1237 | if not copylist: |
|
1237 | if not copylist: | |
1238 | raise util.Abort(_('no files to copy')) |
|
1238 | raise util.Abort(_('no files to copy')) | |
1239 |
|
1239 | |||
1240 | for targetpath, srcs in copylist: |
|
1240 | for targetpath, srcs in copylist: | |
1241 | for origsrc, abssrc, relsrc, exact in srcs: |
|
1241 | for origsrc, abssrc, relsrc, exact in srcs: | |
1242 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) |
|
1242 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) | |
1243 |
|
1243 | |||
1244 | if errors: |
|
1244 | if errors: | |
1245 | ui.warn(_('(consider using --after)\n')) |
|
1245 | ui.warn(_('(consider using --after)\n')) | |
1246 | return errors, copied |
|
1246 | return errors, copied | |
1247 |
|
1247 | |||
1248 | def copy(ui, repo, *pats, **opts): |
|
1248 | def copy(ui, repo, *pats, **opts): | |
1249 | """mark files as copied for the next commit |
|
1249 | """mark files as copied for the next commit | |
1250 |
|
1250 | |||
1251 | Mark dest as having copies of source files. If dest is a |
|
1251 | Mark dest as having copies of source files. If dest is a | |
1252 | directory, copies are put in that directory. If dest is a file, |
|
1252 | directory, copies are put in that directory. If dest is a file, | |
1253 | there can only be one source. |
|
1253 | there can only be one source. | |
1254 |
|
1254 | |||
1255 | By default, this command copies the contents of files as they |
|
1255 | By default, this command copies the contents of files as they | |
1256 | stand in the working directory. If invoked with --after, the |
|
1256 | stand in the working directory. If invoked with --after, the | |
1257 | operation is recorded, but no copying is performed. |
|
1257 | operation is recorded, but no copying is performed. | |
1258 |
|
1258 | |||
1259 | This command takes effect in the next commit. |
|
1259 | This command takes effect in the next commit. | |
1260 |
|
1260 | |||
1261 | NOTE: This command should be treated as experimental. While it |
|
1261 | NOTE: This command should be treated as experimental. While it | |
1262 | should properly record copied files, this information is not yet |
|
1262 | should properly record copied files, this information is not yet | |
1263 | fully used by merge, nor fully reported by log. |
|
1263 | fully used by merge, nor fully reported by log. | |
1264 | """ |
|
1264 | """ | |
1265 | wlock = repo.wlock(0) |
|
1265 | wlock = repo.wlock(0) | |
1266 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
1266 | errs, copied = docopy(ui, repo, pats, opts, wlock) | |
1267 | return errs |
|
1267 | return errs | |
1268 |
|
1268 | |||
1269 | def debugancestor(ui, index, rev1, rev2): |
|
1269 | def debugancestor(ui, index, rev1, rev2): | |
1270 | """find the ancestor revision of two revisions in a given index""" |
|
1270 | """find the ancestor revision of two revisions in a given index""" | |
1271 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "", 0) |
|
1271 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "", 0) | |
1272 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) |
|
1272 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) | |
1273 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
1273 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) | |
1274 |
|
1274 | |||
1275 | def debugcomplete(ui, cmd='', **opts): |
|
1275 | def debugcomplete(ui, cmd='', **opts): | |
1276 | """returns the completion list associated with the given command""" |
|
1276 | """returns the completion list associated with the given command""" | |
1277 |
|
1277 | |||
1278 | if opts['options']: |
|
1278 | if opts['options']: | |
1279 | options = [] |
|
1279 | options = [] | |
1280 | otables = [globalopts] |
|
1280 | otables = [globalopts] | |
1281 | if cmd: |
|
1281 | if cmd: | |
1282 | aliases, entry = find(cmd) |
|
1282 | aliases, entry = find(cmd) | |
1283 | otables.append(entry[1]) |
|
1283 | otables.append(entry[1]) | |
1284 | for t in otables: |
|
1284 | for t in otables: | |
1285 | for o in t: |
|
1285 | for o in t: | |
1286 | if o[0]: |
|
1286 | if o[0]: | |
1287 | options.append('-%s' % o[0]) |
|
1287 | options.append('-%s' % o[0]) | |
1288 | options.append('--%s' % o[1]) |
|
1288 | options.append('--%s' % o[1]) | |
1289 | ui.write("%s\n" % "\n".join(options)) |
|
1289 | ui.write("%s\n" % "\n".join(options)) | |
1290 | return |
|
1290 | return | |
1291 |
|
1291 | |||
1292 | clist = findpossible(cmd).keys() |
|
1292 | clist = findpossible(cmd).keys() | |
1293 | clist.sort() |
|
1293 | clist.sort() | |
1294 | ui.write("%s\n" % "\n".join(clist)) |
|
1294 | ui.write("%s\n" % "\n".join(clist)) | |
1295 |
|
1295 | |||
1296 | def debugrebuildstate(ui, repo, rev=None): |
|
1296 | def debugrebuildstate(ui, repo, rev=None): | |
1297 | """rebuild the dirstate as it would look like for the given revision""" |
|
1297 | """rebuild the dirstate as it would look like for the given revision""" | |
1298 | if not rev: |
|
1298 | if not rev: | |
1299 | rev = repo.changelog.tip() |
|
1299 | rev = repo.changelog.tip() | |
1300 | else: |
|
1300 | else: | |
1301 | rev = repo.lookup(rev) |
|
1301 | rev = repo.lookup(rev) | |
1302 | change = repo.changelog.read(rev) |
|
1302 | change = repo.changelog.read(rev) | |
1303 | n = change[0] |
|
1303 | n = change[0] | |
1304 | files = repo.manifest.readflags(n) |
|
1304 | files = repo.manifest.readflags(n) | |
1305 | wlock = repo.wlock() |
|
1305 | wlock = repo.wlock() | |
1306 | repo.dirstate.rebuild(rev, files.iteritems()) |
|
1306 | repo.dirstate.rebuild(rev, files.iteritems()) | |
1307 |
|
1307 | |||
1308 | def debugcheckstate(ui, repo): |
|
1308 | def debugcheckstate(ui, repo): | |
1309 | """validate the correctness of the current dirstate""" |
|
1309 | """validate the correctness of the current dirstate""" | |
1310 | parent1, parent2 = repo.dirstate.parents() |
|
1310 | parent1, parent2 = repo.dirstate.parents() | |
1311 | repo.dirstate.read() |
|
1311 | repo.dirstate.read() | |
1312 | dc = repo.dirstate.map |
|
1312 | dc = repo.dirstate.map | |
1313 | keys = dc.keys() |
|
1313 | keys = dc.keys() | |
1314 | keys.sort() |
|
1314 | keys.sort() | |
1315 | m1n = repo.changelog.read(parent1)[0] |
|
1315 | m1n = repo.changelog.read(parent1)[0] | |
1316 | m2n = repo.changelog.read(parent2)[0] |
|
1316 | m2n = repo.changelog.read(parent2)[0] | |
1317 | m1 = repo.manifest.read(m1n) |
|
1317 | m1 = repo.manifest.read(m1n) | |
1318 | m2 = repo.manifest.read(m2n) |
|
1318 | m2 = repo.manifest.read(m2n) | |
1319 | errors = 0 |
|
1319 | errors = 0 | |
1320 | for f in dc: |
|
1320 | for f in dc: | |
1321 | state = repo.dirstate.state(f) |
|
1321 | state = repo.dirstate.state(f) | |
1322 | if state in "nr" and f not in m1: |
|
1322 | if state in "nr" and f not in m1: | |
1323 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
1323 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) | |
1324 | errors += 1 |
|
1324 | errors += 1 | |
1325 | if state in "a" and f in m1: |
|
1325 | if state in "a" and f in m1: | |
1326 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
1326 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) | |
1327 | errors += 1 |
|
1327 | errors += 1 | |
1328 | if state in "m" and f not in m1 and f not in m2: |
|
1328 | if state in "m" and f not in m1 and f not in m2: | |
1329 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
1329 | ui.warn(_("%s in state %s, but not in either manifest\n") % | |
1330 | (f, state)) |
|
1330 | (f, state)) | |
1331 | errors += 1 |
|
1331 | errors += 1 | |
1332 | for f in m1: |
|
1332 | for f in m1: | |
1333 | state = repo.dirstate.state(f) |
|
1333 | state = repo.dirstate.state(f) | |
1334 | if state not in "nrm": |
|
1334 | if state not in "nrm": | |
1335 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
1335 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) | |
1336 | errors += 1 |
|
1336 | errors += 1 | |
1337 | if errors: |
|
1337 | if errors: | |
1338 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
1338 | error = _(".hg/dirstate inconsistent with current parent's manifest") | |
1339 | raise util.Abort(error) |
|
1339 | raise util.Abort(error) | |
1340 |
|
1340 | |||
1341 | def debugconfig(ui, repo): |
|
1341 | def debugconfig(ui, repo): | |
1342 | """show combined config settings from all hgrc files""" |
|
1342 | """show combined config settings from all hgrc files""" | |
1343 | for section, name, value in ui.walkconfig(): |
|
1343 | for section, name, value in ui.walkconfig(): | |
1344 | ui.write('%s.%s=%s\n' % (section, name, value)) |
|
1344 | ui.write('%s.%s=%s\n' % (section, name, value)) | |
1345 |
|
1345 | |||
1346 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
1346 | def debugsetparents(ui, repo, rev1, rev2=None): | |
1347 | """manually set the parents of the current working directory |
|
1347 | """manually set the parents of the current working directory | |
1348 |
|
1348 | |||
1349 | This is useful for writing repository conversion tools, but should |
|
1349 | This is useful for writing repository conversion tools, but should | |
1350 | be used with care. |
|
1350 | be used with care. | |
1351 | """ |
|
1351 | """ | |
1352 |
|
1352 | |||
1353 | if not rev2: |
|
1353 | if not rev2: | |
1354 | rev2 = hex(nullid) |
|
1354 | rev2 = hex(nullid) | |
1355 |
|
1355 | |||
1356 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) |
|
1356 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) | |
1357 |
|
1357 | |||
1358 | def debugstate(ui, repo): |
|
1358 | def debugstate(ui, repo): | |
1359 | """show the contents of the current dirstate""" |
|
1359 | """show the contents of the current dirstate""" | |
1360 | repo.dirstate.read() |
|
1360 | repo.dirstate.read() | |
1361 | dc = repo.dirstate.map |
|
1361 | dc = repo.dirstate.map | |
1362 | keys = dc.keys() |
|
1362 | keys = dc.keys() | |
1363 | keys.sort() |
|
1363 | keys.sort() | |
1364 | for file_ in keys: |
|
1364 | for file_ in keys: | |
1365 | ui.write("%c %3o %10d %s %s\n" |
|
1365 | ui.write("%c %3o %10d %s %s\n" | |
1366 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], |
|
1366 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], | |
1367 | time.strftime("%x %X", |
|
1367 | time.strftime("%x %X", | |
1368 | time.localtime(dc[file_][3])), file_)) |
|
1368 | time.localtime(dc[file_][3])), file_)) | |
1369 | for f in repo.dirstate.copies: |
|
1369 | for f in repo.dirstate.copies: | |
1370 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) |
|
1370 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) | |
1371 |
|
1371 | |||
1372 | def debugdata(ui, file_, rev): |
|
1372 | def debugdata(ui, file_, rev): | |
1373 | """dump the contents of an data file revision""" |
|
1373 | """dump the contents of an data file revision""" | |
1374 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), |
|
1374 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), | |
1375 | file_[:-2] + ".i", file_, 0) |
|
1375 | file_[:-2] + ".i", file_, 0) | |
1376 | try: |
|
1376 | try: | |
1377 | ui.write(r.revision(r.lookup(rev))) |
|
1377 | ui.write(r.revision(r.lookup(rev))) | |
1378 | except KeyError: |
|
1378 | except KeyError: | |
1379 | raise util.Abort(_('invalid revision identifier %s'), rev) |
|
1379 | raise util.Abort(_('invalid revision identifier %s'), rev) | |
1380 |
|
1380 | |||
1381 | def debugindex(ui, file_): |
|
1381 | def debugindex(ui, file_): | |
1382 | """dump the contents of an index file""" |
|
1382 | """dump the contents of an index file""" | |
1383 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) |
|
1383 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) | |
1384 | ui.write(" rev offset length base linkrev" + |
|
1384 | ui.write(" rev offset length base linkrev" + | |
1385 | " nodeid p1 p2\n") |
|
1385 | " nodeid p1 p2\n") | |
1386 | for i in range(r.count()): |
|
1386 | for i in range(r.count()): | |
1387 | node = r.node(i) |
|
1387 | node = r.node(i) | |
1388 | pp = r.parents(node) |
|
1388 | pp = r.parents(node) | |
1389 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
1389 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( | |
1390 | i, r.start(i), r.length(i), r.base(i), r.linkrev(node), |
|
1390 | i, r.start(i), r.length(i), r.base(i), r.linkrev(node), | |
1391 | short(node), short(pp[0]), short(pp[1]))) |
|
1391 | short(node), short(pp[0]), short(pp[1]))) | |
1392 |
|
1392 | |||
1393 | def debugindexdot(ui, file_): |
|
1393 | def debugindexdot(ui, file_): | |
1394 | """dump an index DAG as a .dot file""" |
|
1394 | """dump an index DAG as a .dot file""" | |
1395 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) |
|
1395 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) | |
1396 | ui.write("digraph G {\n") |
|
1396 | ui.write("digraph G {\n") | |
1397 | for i in range(r.count()): |
|
1397 | for i in range(r.count()): | |
1398 | e = r.index[i] |
|
1398 | e = r.index[i] | |
1399 | ui.write("\t%d -> %d\n" % (r.rev(e[4]), i)) |
|
1399 | ui.write("\t%d -> %d\n" % (r.rev(e[4]), i)) | |
1400 | if e[5] != nullid: |
|
1400 | if e[5] != nullid: | |
1401 | ui.write("\t%d -> %d\n" % (r.rev(e[5]), i)) |
|
1401 | ui.write("\t%d -> %d\n" % (r.rev(e[5]), i)) | |
1402 | ui.write("}\n") |
|
1402 | ui.write("}\n") | |
1403 |
|
1403 | |||
1404 | def debugrename(ui, repo, file, rev=None): |
|
1404 | def debugrename(ui, repo, file, rev=None): | |
1405 | """dump rename information""" |
|
1405 | """dump rename information""" | |
1406 | r = repo.file(relpath(repo, [file])[0]) |
|
1406 | r = repo.file(relpath(repo, [file])[0]) | |
1407 | if rev: |
|
1407 | if rev: | |
1408 | try: |
|
1408 | try: | |
1409 | # assume all revision numbers are for changesets |
|
1409 | # assume all revision numbers are for changesets | |
1410 | n = repo.lookup(rev) |
|
1410 | n = repo.lookup(rev) | |
1411 | change = repo.changelog.read(n) |
|
1411 | change = repo.changelog.read(n) | |
1412 | m = repo.manifest.read(change[0]) |
|
1412 | m = repo.manifest.read(change[0]) | |
1413 | n = m[relpath(repo, [file])[0]] |
|
1413 | n = m[relpath(repo, [file])[0]] | |
1414 | except (hg.RepoError, KeyError): |
|
1414 | except (hg.RepoError, KeyError): | |
1415 | n = r.lookup(rev) |
|
1415 | n = r.lookup(rev) | |
1416 | else: |
|
1416 | else: | |
1417 | n = r.tip() |
|
1417 | n = r.tip() | |
1418 | m = r.renamed(n) |
|
1418 | m = r.renamed(n) | |
1419 | if m: |
|
1419 | if m: | |
1420 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) |
|
1420 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) | |
1421 | else: |
|
1421 | else: | |
1422 | ui.write(_("not renamed\n")) |
|
1422 | ui.write(_("not renamed\n")) | |
1423 |
|
1423 | |||
1424 | def debugwalk(ui, repo, *pats, **opts): |
|
1424 | def debugwalk(ui, repo, *pats, **opts): | |
1425 | """show how files match on given patterns""" |
|
1425 | """show how files match on given patterns""" | |
1426 | items = list(walk(repo, pats, opts)) |
|
1426 | items = list(walk(repo, pats, opts)) | |
1427 | if not items: |
|
1427 | if not items: | |
1428 | return |
|
1428 | return | |
1429 | fmt = '%%s %%-%ds %%-%ds %%s' % ( |
|
1429 | fmt = '%%s %%-%ds %%-%ds %%s' % ( | |
1430 | max([len(abs) for (src, abs, rel, exact) in items]), |
|
1430 | max([len(abs) for (src, abs, rel, exact) in items]), | |
1431 | max([len(rel) for (src, abs, rel, exact) in items])) |
|
1431 | max([len(rel) for (src, abs, rel, exact) in items])) | |
1432 | for src, abs, rel, exact in items: |
|
1432 | for src, abs, rel, exact in items: | |
1433 | line = fmt % (src, abs, rel, exact and 'exact' or '') |
|
1433 | line = fmt % (src, abs, rel, exact and 'exact' or '') | |
1434 | ui.write("%s\n" % line.rstrip()) |
|
1434 | ui.write("%s\n" % line.rstrip()) | |
1435 |
|
1435 | |||
1436 | def diff(ui, repo, *pats, **opts): |
|
1436 | def diff(ui, repo, *pats, **opts): | |
1437 | """diff repository (or selected files) |
|
1437 | """diff repository (or selected files) | |
1438 |
|
1438 | |||
1439 | Show differences between revisions for the specified files. |
|
1439 | Show differences between revisions for the specified files. | |
1440 |
|
1440 | |||
1441 | Differences between files are shown using the unified diff format. |
|
1441 | Differences between files are shown using the unified diff format. | |
1442 |
|
1442 | |||
1443 | When two revision arguments are given, then changes are shown |
|
1443 | When two revision arguments are given, then changes are shown | |
1444 | between those revisions. If only one revision is specified then |
|
1444 | between those revisions. If only one revision is specified then | |
1445 | that revision is compared to the working directory, and, when no |
|
1445 | that revision is compared to the working directory, and, when no | |
1446 | revisions are specified, the working directory files are compared |
|
1446 | revisions are specified, the working directory files are compared | |
1447 | to its parent. |
|
1447 | to its parent. | |
1448 |
|
1448 | |||
1449 | Without the -a option, diff will avoid generating diffs of files |
|
1449 | Without the -a option, diff will avoid generating diffs of files | |
1450 | it detects as binary. With -a, diff will generate a diff anyway, |
|
1450 | it detects as binary. With -a, diff will generate a diff anyway, | |
1451 | probably with undesirable results. |
|
1451 | probably with undesirable results. | |
1452 | """ |
|
1452 | """ | |
1453 | node1, node2 = None, None |
|
1453 | node1, node2 = None, None | |
1454 | revs = [repo.lookup(x) for x in opts['rev']] |
|
1454 | revs = [repo.lookup(x) for x in opts['rev']] | |
1455 |
|
1455 | |||
1456 | if len(revs) > 0: |
|
1456 | if len(revs) > 0: | |
1457 | node1 = revs[0] |
|
1457 | node1 = revs[0] | |
1458 | if len(revs) > 1: |
|
1458 | if len(revs) > 1: | |
1459 | node2 = revs[1] |
|
1459 | node2 = revs[1] | |
1460 | if len(revs) > 2: |
|
1460 | if len(revs) > 2: | |
1461 | raise util.Abort(_("too many revisions to diff")) |
|
1461 | raise util.Abort(_("too many revisions to diff")) | |
1462 |
|
1462 | |||
1463 | fns, matchfn, anypats = matchpats(repo, pats, opts) |
|
1463 | fns, matchfn, anypats = matchpats(repo, pats, opts) | |
1464 |
|
1464 | |||
1465 | dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, |
|
1465 | dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, | |
1466 | text=opts['text'], opts=opts) |
|
1466 | text=opts['text'], opts=opts) | |
1467 |
|
1467 | |||
1468 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): |
|
1468 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): | |
1469 | node = repo.lookup(changeset) |
|
1469 | node = repo.lookup(changeset) | |
1470 | parents = [p for p in repo.changelog.parents(node) if p != nullid] |
|
1470 | parents = [p for p in repo.changelog.parents(node) if p != nullid] | |
1471 | if opts['switch_parent']: |
|
1471 | if opts['switch_parent']: | |
1472 | parents.reverse() |
|
1472 | parents.reverse() | |
1473 | prev = (parents and parents[0]) or nullid |
|
1473 | prev = (parents and parents[0]) or nullid | |
1474 | change = repo.changelog.read(node) |
|
1474 | change = repo.changelog.read(node) | |
1475 |
|
1475 | |||
1476 | fp = make_file(repo, repo.changelog, opts['output'], |
|
1476 | fp = make_file(repo, repo.changelog, opts['output'], | |
1477 | node=node, total=total, seqno=seqno, |
|
1477 | node=node, total=total, seqno=seqno, | |
1478 | revwidth=revwidth) |
|
1478 | revwidth=revwidth) | |
1479 | if fp != sys.stdout: |
|
1479 | if fp != sys.stdout: | |
1480 | ui.note("%s\n" % fp.name) |
|
1480 | ui.note("%s\n" % fp.name) | |
1481 |
|
1481 | |||
1482 | fp.write("# HG changeset patch\n") |
|
1482 | fp.write("# HG changeset patch\n") | |
1483 | fp.write("# User %s\n" % change[1]) |
|
1483 | fp.write("# User %s\n" % change[1]) | |
1484 | fp.write("# Node ID %s\n" % hex(node)) |
|
1484 | fp.write("# Node ID %s\n" % hex(node)) | |
1485 | fp.write("# Parent %s\n" % hex(prev)) |
|
1485 | fp.write("# Parent %s\n" % hex(prev)) | |
1486 | if len(parents) > 1: |
|
1486 | if len(parents) > 1: | |
1487 | fp.write("# Parent %s\n" % hex(parents[1])) |
|
1487 | fp.write("# Parent %s\n" % hex(parents[1])) | |
1488 | fp.write(change[4].rstrip()) |
|
1488 | fp.write(change[4].rstrip()) | |
1489 | fp.write("\n\n") |
|
1489 | fp.write("\n\n") | |
1490 |
|
1490 | |||
1491 | dodiff(fp, ui, repo, prev, node, text=opts['text']) |
|
1491 | dodiff(fp, ui, repo, prev, node, text=opts['text']) | |
1492 | if fp != sys.stdout: |
|
1492 | if fp != sys.stdout: | |
1493 | fp.close() |
|
1493 | fp.close() | |
1494 |
|
1494 | |||
1495 | def export(ui, repo, *changesets, **opts): |
|
1495 | def export(ui, repo, *changesets, **opts): | |
1496 | """dump the header and diffs for one or more changesets |
|
1496 | """dump the header and diffs for one or more changesets | |
1497 |
|
1497 | |||
1498 | Print the changeset header and diffs for one or more revisions. |
|
1498 | Print the changeset header and diffs for one or more revisions. | |
1499 |
|
1499 | |||
1500 | The information shown in the changeset header is: author, |
|
1500 | The information shown in the changeset header is: author, | |
1501 | changeset hash, parent and commit comment. |
|
1501 | changeset hash, parent and commit comment. | |
1502 |
|
1502 | |||
1503 | Output may be to a file, in which case the name of the file is |
|
1503 | Output may be to a file, in which case the name of the file is | |
1504 | given using a format string. The formatting rules are as follows: |
|
1504 | given using a format string. The formatting rules are as follows: | |
1505 |
|
1505 | |||
1506 | %% literal "%" character |
|
1506 | %% literal "%" character | |
1507 | %H changeset hash (40 bytes of hexadecimal) |
|
1507 | %H changeset hash (40 bytes of hexadecimal) | |
1508 | %N number of patches being generated |
|
1508 | %N number of patches being generated | |
1509 | %R changeset revision number |
|
1509 | %R changeset revision number | |
1510 | %b basename of the exporting repository |
|
1510 | %b basename of the exporting repository | |
1511 | %h short-form changeset hash (12 bytes of hexadecimal) |
|
1511 | %h short-form changeset hash (12 bytes of hexadecimal) | |
1512 | %n zero-padded sequence number, starting at 1 |
|
1512 | %n zero-padded sequence number, starting at 1 | |
1513 | %r zero-padded changeset revision number |
|
1513 | %r zero-padded changeset revision number | |
1514 |
|
1514 | |||
1515 | Without the -a option, export will avoid generating diffs of files |
|
1515 | Without the -a option, export will avoid generating diffs of files | |
1516 | it detects as binary. With -a, export will generate a diff anyway, |
|
1516 | it detects as binary. With -a, export will generate a diff anyway, | |
1517 | probably with undesirable results. |
|
1517 | probably with undesirable results. | |
1518 |
|
1518 | |||
1519 | With the --switch-parent option, the diff will be against the second |
|
1519 | With the --switch-parent option, the diff will be against the second | |
1520 | parent. It can be useful to review a merge. |
|
1520 | parent. It can be useful to review a merge. | |
1521 | """ |
|
1521 | """ | |
1522 | if not changesets: |
|
1522 | if not changesets: | |
1523 | raise util.Abort(_("export requires at least one changeset")) |
|
1523 | raise util.Abort(_("export requires at least one changeset")) | |
1524 | seqno = 0 |
|
1524 | seqno = 0 | |
1525 | revs = list(revrange(ui, repo, changesets)) |
|
1525 | revs = list(revrange(ui, repo, changesets)) | |
1526 | total = len(revs) |
|
1526 | total = len(revs) | |
1527 | revwidth = max(map(len, revs)) |
|
1527 | revwidth = max(map(len, revs)) | |
1528 | msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n") |
|
1528 | msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n") | |
1529 | ui.note(msg) |
|
1529 | ui.note(msg) | |
1530 | for cset in revs: |
|
1530 | for cset in revs: | |
1531 | seqno += 1 |
|
1531 | seqno += 1 | |
1532 | doexport(ui, repo, cset, seqno, total, revwidth, opts) |
|
1532 | doexport(ui, repo, cset, seqno, total, revwidth, opts) | |
1533 |
|
1533 | |||
1534 | def forget(ui, repo, *pats, **opts): |
|
1534 | def forget(ui, repo, *pats, **opts): | |
1535 | """don't add the specified files on the next commit |
|
1535 | """don't add the specified files on the next commit | |
1536 |
|
1536 | |||
1537 | Undo an 'hg add' scheduled for the next commit. |
|
1537 | Undo an 'hg add' scheduled for the next commit. | |
1538 | """ |
|
1538 | """ | |
1539 | forget = [] |
|
1539 | forget = [] | |
1540 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
1540 | for src, abs, rel, exact in walk(repo, pats, opts): | |
1541 | if repo.dirstate.state(abs) == 'a': |
|
1541 | if repo.dirstate.state(abs) == 'a': | |
1542 | forget.append(abs) |
|
1542 | forget.append(abs) | |
1543 | if ui.verbose or not exact: |
|
1543 | if ui.verbose or not exact: | |
1544 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) |
|
1544 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) | |
1545 | repo.forget(forget) |
|
1545 | repo.forget(forget) | |
1546 |
|
1546 | |||
1547 | def grep(ui, repo, pattern, *pats, **opts): |
|
1547 | def grep(ui, repo, pattern, *pats, **opts): | |
1548 | """search for a pattern in specified files and revisions |
|
1548 | """search for a pattern in specified files and revisions | |
1549 |
|
1549 | |||
1550 | Search revisions of files for a regular expression. |
|
1550 | Search revisions of files for a regular expression. | |
1551 |
|
1551 | |||
1552 | This command behaves differently than Unix grep. It only accepts |
|
1552 | This command behaves differently than Unix grep. It only accepts | |
1553 | Python/Perl regexps. It searches repository history, not the |
|
1553 | Python/Perl regexps. It searches repository history, not the | |
1554 | working directory. It always prints the revision number in which |
|
1554 | working directory. It always prints the revision number in which | |
1555 | a match appears. |
|
1555 | a match appears. | |
1556 |
|
1556 | |||
1557 | By default, grep only prints output for the first revision of a |
|
1557 | By default, grep only prints output for the first revision of a | |
1558 | file in which it finds a match. To get it to print every revision |
|
1558 | file in which it finds a match. To get it to print every revision | |
1559 | that contains a change in match status ("-" for a match that |
|
1559 | that contains a change in match status ("-" for a match that | |
1560 | becomes a non-match, or "+" for a non-match that becomes a match), |
|
1560 | becomes a non-match, or "+" for a non-match that becomes a match), | |
1561 | use the --all flag. |
|
1561 | use the --all flag. | |
1562 | """ |
|
1562 | """ | |
1563 | reflags = 0 |
|
1563 | reflags = 0 | |
1564 | if opts['ignore_case']: |
|
1564 | if opts['ignore_case']: | |
1565 | reflags |= re.I |
|
1565 | reflags |= re.I | |
1566 | regexp = re.compile(pattern, reflags) |
|
1566 | regexp = re.compile(pattern, reflags) | |
1567 | sep, eol = ':', '\n' |
|
1567 | sep, eol = ':', '\n' | |
1568 | if opts['print0']: |
|
1568 | if opts['print0']: | |
1569 | sep = eol = '\0' |
|
1569 | sep = eol = '\0' | |
1570 |
|
1570 | |||
1571 | fcache = {} |
|
1571 | fcache = {} | |
1572 | def getfile(fn): |
|
1572 | def getfile(fn): | |
1573 | if fn not in fcache: |
|
1573 | if fn not in fcache: | |
1574 | fcache[fn] = repo.file(fn) |
|
1574 | fcache[fn] = repo.file(fn) | |
1575 | return fcache[fn] |
|
1575 | return fcache[fn] | |
1576 |
|
1576 | |||
1577 | def matchlines(body): |
|
1577 | def matchlines(body): | |
1578 | begin = 0 |
|
1578 | begin = 0 | |
1579 | linenum = 0 |
|
1579 | linenum = 0 | |
1580 | while True: |
|
1580 | while True: | |
1581 | match = regexp.search(body, begin) |
|
1581 | match = regexp.search(body, begin) | |
1582 | if not match: |
|
1582 | if not match: | |
1583 | break |
|
1583 | break | |
1584 | mstart, mend = match.span() |
|
1584 | mstart, mend = match.span() | |
1585 | linenum += body.count('\n', begin, mstart) + 1 |
|
1585 | linenum += body.count('\n', begin, mstart) + 1 | |
1586 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
1586 | lstart = body.rfind('\n', begin, mstart) + 1 or begin | |
1587 | lend = body.find('\n', mend) |
|
1587 | lend = body.find('\n', mend) | |
1588 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
1588 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] | |
1589 | begin = lend + 1 |
|
1589 | begin = lend + 1 | |
1590 |
|
1590 | |||
1591 | class linestate(object): |
|
1591 | class linestate(object): | |
1592 | def __init__(self, line, linenum, colstart, colend): |
|
1592 | def __init__(self, line, linenum, colstart, colend): | |
1593 | self.line = line |
|
1593 | self.line = line | |
1594 | self.linenum = linenum |
|
1594 | self.linenum = linenum | |
1595 | self.colstart = colstart |
|
1595 | self.colstart = colstart | |
1596 | self.colend = colend |
|
1596 | self.colend = colend | |
1597 | def __eq__(self, other): |
|
1597 | def __eq__(self, other): | |
1598 | return self.line == other.line |
|
1598 | return self.line == other.line | |
1599 | def __hash__(self): |
|
1599 | def __hash__(self): | |
1600 | return hash(self.line) |
|
1600 | return hash(self.line) | |
1601 |
|
1601 | |||
1602 | matches = {} |
|
1602 | matches = {} | |
1603 | def grepbody(fn, rev, body): |
|
1603 | def grepbody(fn, rev, body): | |
1604 | matches[rev].setdefault(fn, {}) |
|
1604 | matches[rev].setdefault(fn, {}) | |
1605 | m = matches[rev][fn] |
|
1605 | m = matches[rev][fn] | |
1606 | for lnum, cstart, cend, line in matchlines(body): |
|
1606 | for lnum, cstart, cend, line in matchlines(body): | |
1607 | s = linestate(line, lnum, cstart, cend) |
|
1607 | s = linestate(line, lnum, cstart, cend) | |
1608 | m[s] = s |
|
1608 | m[s] = s | |
1609 |
|
1609 | |||
1610 | # FIXME: prev isn't used, why ? |
|
1610 | # FIXME: prev isn't used, why ? | |
1611 | prev = {} |
|
1611 | prev = {} | |
1612 | ucache = {} |
|
1612 | ucache = {} | |
1613 | def display(fn, rev, states, prevstates): |
|
1613 | def display(fn, rev, states, prevstates): | |
1614 | diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates))) |
|
1614 | diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates))) | |
1615 | diff.sort(lambda x, y: cmp(x.linenum, y.linenum)) |
|
1615 | diff.sort(lambda x, y: cmp(x.linenum, y.linenum)) | |
1616 | counts = {'-': 0, '+': 0} |
|
1616 | counts = {'-': 0, '+': 0} | |
1617 | filerevmatches = {} |
|
1617 | filerevmatches = {} | |
1618 | for l in diff: |
|
1618 | for l in diff: | |
1619 | if incrementing or not opts['all']: |
|
1619 | if incrementing or not opts['all']: | |
1620 | change = ((l in prevstates) and '-') or '+' |
|
1620 | change = ((l in prevstates) and '-') or '+' | |
1621 | r = rev |
|
1621 | r = rev | |
1622 | else: |
|
1622 | else: | |
1623 | change = ((l in states) and '-') or '+' |
|
1623 | change = ((l in states) and '-') or '+' | |
1624 | r = prev[fn] |
|
1624 | r = prev[fn] | |
1625 | cols = [fn, str(rev)] |
|
1625 | cols = [fn, str(rev)] | |
1626 | if opts['line_number']: |
|
1626 | if opts['line_number']: | |
1627 | cols.append(str(l.linenum)) |
|
1627 | cols.append(str(l.linenum)) | |
1628 | if opts['all']: |
|
1628 | if opts['all']: | |
1629 | cols.append(change) |
|
1629 | cols.append(change) | |
1630 | if opts['user']: |
|
1630 | if opts['user']: | |
1631 | cols.append(trimuser(ui, getchange(rev)[1], rev, |
|
1631 | cols.append(trimuser(ui, getchange(rev)[1], rev, | |
1632 | ucache)) |
|
1632 | ucache)) | |
1633 | if opts['files_with_matches']: |
|
1633 | if opts['files_with_matches']: | |
1634 | c = (fn, rev) |
|
1634 | c = (fn, rev) | |
1635 | if c in filerevmatches: |
|
1635 | if c in filerevmatches: | |
1636 | continue |
|
1636 | continue | |
1637 | filerevmatches[c] = 1 |
|
1637 | filerevmatches[c] = 1 | |
1638 | else: |
|
1638 | else: | |
1639 | cols.append(l.line) |
|
1639 | cols.append(l.line) | |
1640 | ui.write(sep.join(cols), eol) |
|
1640 | ui.write(sep.join(cols), eol) | |
1641 | counts[change] += 1 |
|
1641 | counts[change] += 1 | |
1642 | return counts['+'], counts['-'] |
|
1642 | return counts['+'], counts['-'] | |
1643 |
|
1643 | |||
1644 | fstate = {} |
|
1644 | fstate = {} | |
1645 | skip = {} |
|
1645 | skip = {} | |
1646 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1646 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | |
1647 | count = 0 |
|
1647 | count = 0 | |
1648 | incrementing = False |
|
1648 | incrementing = False | |
1649 | for st, rev, fns in changeiter: |
|
1649 | for st, rev, fns in changeiter: | |
1650 | if st == 'window': |
|
1650 | if st == 'window': | |
1651 | incrementing = rev |
|
1651 | incrementing = rev | |
1652 | matches.clear() |
|
1652 | matches.clear() | |
1653 | elif st == 'add': |
|
1653 | elif st == 'add': | |
1654 | change = repo.changelog.read(repo.lookup(str(rev))) |
|
1654 | change = repo.changelog.read(repo.lookup(str(rev))) | |
1655 | mf = repo.manifest.read(change[0]) |
|
1655 | mf = repo.manifest.read(change[0]) | |
1656 | matches[rev] = {} |
|
1656 | matches[rev] = {} | |
1657 | for fn in fns: |
|
1657 | for fn in fns: | |
1658 | if fn in skip: |
|
1658 | if fn in skip: | |
1659 | continue |
|
1659 | continue | |
1660 | fstate.setdefault(fn, {}) |
|
1660 | fstate.setdefault(fn, {}) | |
1661 | try: |
|
1661 | try: | |
1662 | grepbody(fn, rev, getfile(fn).read(mf[fn])) |
|
1662 | grepbody(fn, rev, getfile(fn).read(mf[fn])) | |
1663 | except KeyError: |
|
1663 | except KeyError: | |
1664 | pass |
|
1664 | pass | |
1665 | elif st == 'iter': |
|
1665 | elif st == 'iter': | |
1666 | states = matches[rev].items() |
|
1666 | states = matches[rev].items() | |
1667 | states.sort() |
|
1667 | states.sort() | |
1668 | for fn, m in states: |
|
1668 | for fn, m in states: | |
1669 | if fn in skip: |
|
1669 | if fn in skip: | |
1670 | continue |
|
1670 | continue | |
1671 | if incrementing or not opts['all'] or fstate[fn]: |
|
1671 | if incrementing or not opts['all'] or fstate[fn]: | |
1672 | pos, neg = display(fn, rev, m, fstate[fn]) |
|
1672 | pos, neg = display(fn, rev, m, fstate[fn]) | |
1673 | count += pos + neg |
|
1673 | count += pos + neg | |
1674 | if pos and not opts['all']: |
|
1674 | if pos and not opts['all']: | |
1675 | skip[fn] = True |
|
1675 | skip[fn] = True | |
1676 | fstate[fn] = m |
|
1676 | fstate[fn] = m | |
1677 | prev[fn] = rev |
|
1677 | prev[fn] = rev | |
1678 |
|
1678 | |||
1679 | if not incrementing: |
|
1679 | if not incrementing: | |
1680 | fstate = fstate.items() |
|
1680 | fstate = fstate.items() | |
1681 | fstate.sort() |
|
1681 | fstate.sort() | |
1682 | for fn, state in fstate: |
|
1682 | for fn, state in fstate: | |
1683 | if fn in skip: |
|
1683 | if fn in skip: | |
1684 | continue |
|
1684 | continue | |
1685 | display(fn, rev, {}, state) |
|
1685 | display(fn, rev, {}, state) | |
1686 | return (count == 0 and 1) or 0 |
|
1686 | return (count == 0 and 1) or 0 | |
1687 |
|
1687 | |||
1688 | def heads(ui, repo, **opts): |
|
1688 | def heads(ui, repo, **opts): | |
1689 | """show current repository heads |
|
1689 | """show current repository heads | |
1690 |
|
1690 | |||
1691 | Show all repository head changesets. |
|
1691 | Show all repository head changesets. | |
1692 |
|
1692 | |||
1693 | Repository "heads" are changesets that don't have children |
|
1693 | Repository "heads" are changesets that don't have children | |
1694 | changesets. They are where development generally takes place and |
|
1694 | changesets. They are where development generally takes place and | |
1695 | are the usual targets for update and merge operations. |
|
1695 | are the usual targets for update and merge operations. | |
1696 | """ |
|
1696 | """ | |
1697 | if opts['rev']: |
|
1697 | if opts['rev']: | |
1698 | heads = repo.heads(repo.lookup(opts['rev'])) |
|
1698 | heads = repo.heads(repo.lookup(opts['rev'])) | |
1699 | else: |
|
1699 | else: | |
1700 | heads = repo.heads() |
|
1700 | heads = repo.heads() | |
1701 | br = None |
|
1701 | br = None | |
1702 | if opts['branches']: |
|
1702 | if opts['branches']: | |
1703 | br = repo.branchlookup(heads) |
|
1703 | br = repo.branchlookup(heads) | |
1704 | displayer = show_changeset(ui, repo, opts) |
|
1704 | displayer = show_changeset(ui, repo, opts) | |
1705 | for n in heads: |
|
1705 | for n in heads: | |
1706 | displayer.show(changenode=n, brinfo=br) |
|
1706 | displayer.show(changenode=n, brinfo=br) | |
1707 |
|
1707 | |||
1708 | def identify(ui, repo): |
|
1708 | def identify(ui, repo): | |
1709 | """print information about the working copy |
|
1709 | """print information about the working copy | |
1710 |
|
1710 | |||
1711 | Print a short summary of the current state of the repo. |
|
1711 | Print a short summary of the current state of the repo. | |
1712 |
|
1712 | |||
1713 | This summary identifies the repository state using one or two parent |
|
1713 | This summary identifies the repository state using one or two parent | |
1714 | hash identifiers, followed by a "+" if there are uncommitted changes |
|
1714 | hash identifiers, followed by a "+" if there are uncommitted changes | |
1715 | in the working directory, followed by a list of tags for this revision. |
|
1715 | in the working directory, followed by a list of tags for this revision. | |
1716 | """ |
|
1716 | """ | |
1717 | parents = [p for p in repo.dirstate.parents() if p != nullid] |
|
1717 | parents = [p for p in repo.dirstate.parents() if p != nullid] | |
1718 | if not parents: |
|
1718 | if not parents: | |
1719 | ui.write(_("unknown\n")) |
|
1719 | ui.write(_("unknown\n")) | |
1720 | return |
|
1720 | return | |
1721 |
|
1721 | |||
1722 | hexfunc = ui.verbose and hex or short |
|
1722 | hexfunc = ui.verbose and hex or short | |
1723 | modified, added, removed, deleted, unknown = repo.changes() |
|
1723 | modified, added, removed, deleted, unknown = repo.changes() | |
1724 | output = ["%s%s" % |
|
1724 | output = ["%s%s" % | |
1725 | ('+'.join([hexfunc(parent) for parent in parents]), |
|
1725 | ('+'.join([hexfunc(parent) for parent in parents]), | |
1726 | (modified or added or removed or deleted) and "+" or "")] |
|
1726 | (modified or added or removed or deleted) and "+" or "")] | |
1727 |
|
1727 | |||
1728 | if not ui.quiet: |
|
1728 | if not ui.quiet: | |
1729 | # multiple tags for a single parent separated by '/' |
|
1729 | # multiple tags for a single parent separated by '/' | |
1730 | parenttags = ['/'.join(tags) |
|
1730 | parenttags = ['/'.join(tags) | |
1731 | for tags in map(repo.nodetags, parents) if tags] |
|
1731 | for tags in map(repo.nodetags, parents) if tags] | |
1732 | # tags for multiple parents separated by ' + ' |
|
1732 | # tags for multiple parents separated by ' + ' | |
1733 | if parenttags: |
|
1733 | if parenttags: | |
1734 | output.append(' + '.join(parenttags)) |
|
1734 | output.append(' + '.join(parenttags)) | |
1735 |
|
1735 | |||
1736 | ui.write("%s\n" % ' '.join(output)) |
|
1736 | ui.write("%s\n" % ' '.join(output)) | |
1737 |
|
1737 | |||
1738 | def import_(ui, repo, patch1, *patches, **opts): |
|
1738 | def import_(ui, repo, patch1, *patches, **opts): | |
1739 | """import an ordered set of patches |
|
1739 | """import an ordered set of patches | |
1740 |
|
1740 | |||
1741 | Import a list of patches and commit them individually. |
|
1741 | Import a list of patches and commit them individually. | |
1742 |
|
1742 | |||
1743 | If there are outstanding changes in the working directory, import |
|
1743 | If there are outstanding changes in the working directory, import | |
1744 | will abort unless given the -f flag. |
|
1744 | will abort unless given the -f flag. | |
1745 |
|
1745 | |||
1746 | If a patch looks like a mail message (its first line starts with |
|
1746 | If a patch looks like a mail message (its first line starts with | |
1747 | "From " or looks like an RFC822 header), it will not be applied |
|
1747 | "From " or looks like an RFC822 header), it will not be applied | |
1748 | unless the -f option is used. The importer neither parses nor |
|
1748 | unless the -f option is used. The importer neither parses nor | |
1749 | discards mail headers, so use -f only to override the "mailness" |
|
1749 | discards mail headers, so use -f only to override the "mailness" | |
1750 | safety check, not to import a real mail message. |
|
1750 | safety check, not to import a real mail message. | |
1751 | """ |
|
1751 | """ | |
1752 | patches = (patch1,) + patches |
|
1752 | patches = (patch1,) + patches | |
1753 |
|
1753 | |||
1754 | if not opts['force']: |
|
1754 | if not opts['force']: | |
1755 | modified, added, removed, deleted, unknown = repo.changes() |
|
1755 | modified, added, removed, deleted, unknown = repo.changes() | |
1756 | if modified or added or removed or deleted: |
|
1756 | if modified or added or removed or deleted: | |
1757 | raise util.Abort(_("outstanding uncommitted changes")) |
|
1757 | raise util.Abort(_("outstanding uncommitted changes")) | |
1758 |
|
1758 | |||
1759 | d = opts["base"] |
|
1759 | d = opts["base"] | |
1760 | strip = opts["strip"] |
|
1760 | strip = opts["strip"] | |
1761 |
|
1761 | |||
1762 | mailre = re.compile(r'(?:From |[\w-]+:)') |
|
1762 | mailre = re.compile(r'(?:From |[\w-]+:)') | |
1763 |
|
1763 | |||
1764 | # attempt to detect the start of a patch |
|
1764 | # attempt to detect the start of a patch | |
1765 | # (this heuristic is borrowed from quilt) |
|
1765 | # (this heuristic is borrowed from quilt) | |
1766 | diffre = re.compile(r'(?:Index:[ \t]|diff[ \t]|RCS file: |' + |
|
1766 | diffre = re.compile(r'(?:Index:[ \t]|diff[ \t]|RCS file: |' + | |
1767 | 'retrieving revision [0-9]+(\.[0-9]+)*$|' + |
|
1767 | 'retrieving revision [0-9]+(\.[0-9]+)*$|' + | |
1768 | '(---|\*\*\*)[ \t])') |
|
1768 | '(---|\*\*\*)[ \t])') | |
1769 |
|
1769 | |||
1770 | for patch in patches: |
|
1770 | for patch in patches: | |
1771 | ui.status(_("applying %s\n") % patch) |
|
1771 | ui.status(_("applying %s\n") % patch) | |
1772 | pf = os.path.join(d, patch) |
|
1772 | pf = os.path.join(d, patch) | |
1773 |
|
1773 | |||
1774 | message = [] |
|
1774 | message = [] | |
1775 | user = None |
|
1775 | user = None | |
1776 | hgpatch = False |
|
1776 | hgpatch = False | |
1777 | for line in file(pf): |
|
1777 | for line in file(pf): | |
1778 | line = line.rstrip() |
|
1778 | line = line.rstrip() | |
1779 | if (not message and not hgpatch and |
|
1779 | if (not message and not hgpatch and | |
1780 | mailre.match(line) and not opts['force']): |
|
1780 | mailre.match(line) and not opts['force']): | |
1781 | if len(line) > 35: |
|
1781 | if len(line) > 35: | |
1782 | line = line[:32] + '...' |
|
1782 | line = line[:32] + '...' | |
1783 | raise util.Abort(_('first line looks like a ' |
|
1783 | raise util.Abort(_('first line looks like a ' | |
1784 | 'mail header: ') + line) |
|
1784 | 'mail header: ') + line) | |
1785 | if diffre.match(line): |
|
1785 | if diffre.match(line): | |
1786 | break |
|
1786 | break | |
1787 | elif hgpatch: |
|
1787 | elif hgpatch: | |
1788 | # parse values when importing the result of an hg export |
|
1788 | # parse values when importing the result of an hg export | |
1789 | if line.startswith("# User "): |
|
1789 | if line.startswith("# User "): | |
1790 | user = line[7:] |
|
1790 | user = line[7:] | |
1791 | ui.debug(_('User: %s\n') % user) |
|
1791 | ui.debug(_('User: %s\n') % user) | |
1792 | elif not line.startswith("# ") and line: |
|
1792 | elif not line.startswith("# ") and line: | |
1793 | message.append(line) |
|
1793 | message.append(line) | |
1794 | hgpatch = False |
|
1794 | hgpatch = False | |
1795 | elif line == '# HG changeset patch': |
|
1795 | elif line == '# HG changeset patch': | |
1796 | hgpatch = True |
|
1796 | hgpatch = True | |
1797 | message = [] # We may have collected garbage |
|
1797 | message = [] # We may have collected garbage | |
1798 | else: |
|
1798 | else: | |
1799 | message.append(line) |
|
1799 | message.append(line) | |
1800 |
|
1800 | |||
1801 | # make sure message isn't empty |
|
1801 | # make sure message isn't empty | |
1802 | if not message: |
|
1802 | if not message: | |
1803 | message = _("imported patch %s\n") % patch |
|
1803 | message = _("imported patch %s\n") % patch | |
1804 | else: |
|
1804 | else: | |
1805 | message = "%s\n" % '\n'.join(message) |
|
1805 | message = "%s\n" % '\n'.join(message) | |
1806 | ui.debug(_('message:\n%s\n') % message) |
|
1806 | ui.debug(_('message:\n%s\n') % message) | |
1807 |
|
1807 | |||
1808 | files = util.patch(strip, pf, ui) |
|
1808 | files = util.patch(strip, pf, ui) | |
1809 |
|
1809 | |||
1810 | if len(files) > 0: |
|
1810 | if len(files) > 0: | |
1811 | addremove(ui, repo, *files) |
|
1811 | addremove(ui, repo, *files) | |
1812 | repo.commit(files, message, user) |
|
1812 | repo.commit(files, message, user) | |
1813 |
|
1813 | |||
1814 | def incoming(ui, repo, source="default", **opts): |
|
1814 | def incoming(ui, repo, source="default", **opts): | |
1815 | """show new changesets found in source |
|
1815 | """show new changesets found in source | |
1816 |
|
1816 | |||
1817 | Show new changesets found in the specified path/URL or the default |
|
1817 | Show new changesets found in the specified path/URL or the default | |
1818 | pull location. These are the changesets that would be pulled if a pull |
|
1818 | pull location. These are the changesets that would be pulled if a pull | |
1819 | was requested. |
|
1819 | was requested. | |
1820 |
|
1820 | |||
1821 | For remote repository, using --bundle avoids downloading the changesets |
|
1821 | For remote repository, using --bundle avoids downloading the changesets | |
1822 | twice if the incoming is followed by a pull. |
|
1822 | twice if the incoming is followed by a pull. | |
1823 |
|
1823 | |||
1824 | See pull for valid source format details. |
|
1824 | See pull for valid source format details. | |
1825 | """ |
|
1825 | """ | |
1826 | source = ui.expandpath(source) |
|
1826 | source = ui.expandpath(source) | |
1827 | if opts['ssh']: |
|
1827 | if opts['ssh']: | |
1828 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
1828 | ui.setconfig("ui", "ssh", opts['ssh']) | |
1829 | if opts['remotecmd']: |
|
1829 | if opts['remotecmd']: | |
1830 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
1830 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
1831 |
|
1831 | |||
1832 | other = hg.repository(ui, source) |
|
1832 | other = hg.repository(ui, source) | |
1833 | incoming = repo.findincoming(other, force=opts["force"]) |
|
1833 | incoming = repo.findincoming(other, force=opts["force"]) | |
1834 | if not incoming: |
|
1834 | if not incoming: | |
1835 | ui.status(_("no changes found\n")) |
|
1835 | ui.status(_("no changes found\n")) | |
1836 | return |
|
1836 | return | |
1837 |
|
1837 | |||
1838 | cleanup = None |
|
1838 | cleanup = None | |
1839 | try: |
|
1839 | try: | |
1840 | fname = opts["bundle"] |
|
1840 | fname = opts["bundle"] | |
1841 | if fname or not other.local(): |
|
1841 | if fname or not other.local(): | |
1842 | # create a bundle (uncompressed if other repo is not local) |
|
1842 | # create a bundle (uncompressed if other repo is not local) | |
1843 | cg = other.changegroup(incoming, "incoming") |
|
1843 | cg = other.changegroup(incoming, "incoming") | |
1844 | fname = cleanup = write_bundle(cg, fname, compress=other.local()) |
|
1844 | fname = cleanup = write_bundle(cg, fname, compress=other.local()) | |
1845 | # keep written bundle? |
|
1845 | # keep written bundle? | |
1846 | if opts["bundle"]: |
|
1846 | if opts["bundle"]: | |
1847 | cleanup = None |
|
1847 | cleanup = None | |
1848 | if not other.local(): |
|
1848 | if not other.local(): | |
1849 | # use the created uncompressed bundlerepo |
|
1849 | # use the created uncompressed bundlerepo | |
1850 | other = bundlerepo.bundlerepository(ui, repo.root, fname) |
|
1850 | other = bundlerepo.bundlerepository(ui, repo.root, fname) | |
1851 |
|
1851 | |||
1852 | o = other.changelog.nodesbetween(incoming)[0] |
|
1852 | o = other.changelog.nodesbetween(incoming)[0] | |
1853 | if opts['newest_first']: |
|
1853 | if opts['newest_first']: | |
1854 | o.reverse() |
|
1854 | o.reverse() | |
1855 | displayer = show_changeset(ui, other, opts) |
|
1855 | displayer = show_changeset(ui, other, opts) | |
1856 | for n in o: |
|
1856 | for n in o: | |
1857 | parents = [p for p in other.changelog.parents(n) if p != nullid] |
|
1857 | parents = [p for p in other.changelog.parents(n) if p != nullid] | |
1858 | if opts['no_merges'] and len(parents) == 2: |
|
1858 | if opts['no_merges'] and len(parents) == 2: | |
1859 | continue |
|
1859 | continue | |
1860 | displayer.show(changenode=n) |
|
1860 | displayer.show(changenode=n) | |
1861 | if opts['patch']: |
|
1861 | if opts['patch']: | |
1862 | prev = (parents and parents[0]) or nullid |
|
1862 | prev = (parents and parents[0]) or nullid | |
1863 | dodiff(ui, ui, other, prev, n) |
|
1863 | dodiff(ui, ui, other, prev, n) | |
1864 | ui.write("\n") |
|
1864 | ui.write("\n") | |
1865 | finally: |
|
1865 | finally: | |
1866 | if hasattr(other, 'close'): |
|
1866 | if hasattr(other, 'close'): | |
1867 | other.close() |
|
1867 | other.close() | |
1868 | if cleanup: |
|
1868 | if cleanup: | |
1869 | os.unlink(cleanup) |
|
1869 | os.unlink(cleanup) | |
1870 |
|
1870 | |||
1871 | def init(ui, dest="."): |
|
1871 | def init(ui, dest="."): | |
1872 | """create a new repository in the given directory |
|
1872 | """create a new repository in the given directory | |
1873 |
|
1873 | |||
1874 | Initialize a new repository in the given directory. If the given |
|
1874 | Initialize a new repository in the given directory. If the given | |
1875 | directory does not exist, it is created. |
|
1875 | directory does not exist, it is created. | |
1876 |
|
1876 | |||
1877 | If no directory is given, the current directory is used. |
|
1877 | If no directory is given, the current directory is used. | |
1878 | """ |
|
1878 | """ | |
1879 | if not os.path.exists(dest): |
|
1879 | if not os.path.exists(dest): | |
1880 | os.mkdir(dest) |
|
1880 | os.mkdir(dest) | |
1881 | hg.repository(ui, dest, create=1) |
|
1881 | hg.repository(ui, dest, create=1) | |
1882 |
|
1882 | |||
1883 | def locate(ui, repo, *pats, **opts): |
|
1883 | def locate(ui, repo, *pats, **opts): | |
1884 | """locate files matching specific patterns |
|
1884 | """locate files matching specific patterns | |
1885 |
|
1885 | |||
1886 | Print all files under Mercurial control whose names match the |
|
1886 | Print all files under Mercurial control whose names match the | |
1887 | given patterns. |
|
1887 | given patterns. | |
1888 |
|
1888 | |||
1889 | This command searches the current directory and its |
|
1889 | This command searches the current directory and its | |
1890 | subdirectories. To search an entire repository, move to the root |
|
1890 | subdirectories. To search an entire repository, move to the root | |
1891 | of the repository. |
|
1891 | of the repository. | |
1892 |
|
1892 | |||
1893 | If no patterns are given to match, this command prints all file |
|
1893 | If no patterns are given to match, this command prints all file | |
1894 | names. |
|
1894 | names. | |
1895 |
|
1895 | |||
1896 | If you want to feed the output of this command into the "xargs" |
|
1896 | If you want to feed the output of this command into the "xargs" | |
1897 | command, use the "-0" option to both this command and "xargs". |
|
1897 | command, use the "-0" option to both this command and "xargs". | |
1898 | This will avoid the problem of "xargs" treating single filenames |
|
1898 | This will avoid the problem of "xargs" treating single filenames | |
1899 | that contain white space as multiple filenames. |
|
1899 | that contain white space as multiple filenames. | |
1900 | """ |
|
1900 | """ | |
1901 | end = opts['print0'] and '\0' or '\n' |
|
1901 | end = opts['print0'] and '\0' or '\n' | |
1902 | rev = opts['rev'] |
|
1902 | rev = opts['rev'] | |
1903 | if rev: |
|
1903 | if rev: | |
1904 | node = repo.lookup(rev) |
|
1904 | node = repo.lookup(rev) | |
1905 | else: |
|
1905 | else: | |
1906 | node = None |
|
1906 | node = None | |
1907 |
|
1907 | |||
1908 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, |
|
1908 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, | |
1909 | head='(?:.*/|)'): |
|
1909 | head='(?:.*/|)'): | |
1910 | if not node and repo.dirstate.state(abs) == '?': |
|
1910 | if not node and repo.dirstate.state(abs) == '?': | |
1911 | continue |
|
1911 | continue | |
1912 | if opts['fullpath']: |
|
1912 | if opts['fullpath']: | |
1913 | ui.write(os.path.join(repo.root, abs), end) |
|
1913 | ui.write(os.path.join(repo.root, abs), end) | |
1914 | else: |
|
1914 | else: | |
1915 | ui.write(((pats and rel) or abs), end) |
|
1915 | ui.write(((pats and rel) or abs), end) | |
1916 |
|
1916 | |||
1917 | def log(ui, repo, *pats, **opts): |
|
1917 | def log(ui, repo, *pats, **opts): | |
1918 | """show revision history of entire repository or files |
|
1918 | """show revision history of entire repository or files | |
1919 |
|
1919 | |||
1920 | Print the revision history of the specified files or the entire project. |
|
1920 | Print the revision history of the specified files or the entire project. | |
1921 |
|
1921 | |||
1922 | By default this command outputs: changeset id and hash, tags, |
|
1922 | By default this command outputs: changeset id and hash, tags, | |
1923 | non-trivial parents, user, date and time, and a summary for each |
|
1923 | non-trivial parents, user, date and time, and a summary for each | |
1924 | commit. When the -v/--verbose switch is used, the list of changed |
|
1924 | commit. When the -v/--verbose switch is used, the list of changed | |
1925 | files and full commit message is shown. |
|
1925 | files and full commit message is shown. | |
1926 | """ |
|
1926 | """ | |
1927 | class dui(object): |
|
1927 | class dui(object): | |
1928 | # Implement and delegate some ui protocol. Save hunks of |
|
1928 | # Implement and delegate some ui protocol. Save hunks of | |
1929 | # output for later display in the desired order. |
|
1929 | # output for later display in the desired order. | |
1930 | def __init__(self, ui): |
|
1930 | def __init__(self, ui): | |
1931 | self.ui = ui |
|
1931 | self.ui = ui | |
1932 | self.hunk = {} |
|
1932 | self.hunk = {} | |
1933 | self.header = {} |
|
1933 | self.header = {} | |
1934 | def bump(self, rev): |
|
1934 | def bump(self, rev): | |
1935 | self.rev = rev |
|
1935 | self.rev = rev | |
1936 | self.hunk[rev] = [] |
|
1936 | self.hunk[rev] = [] | |
1937 | self.header[rev] = [] |
|
1937 | self.header[rev] = [] | |
1938 | def note(self, *args): |
|
1938 | def note(self, *args): | |
1939 | if self.verbose: |
|
1939 | if self.verbose: | |
1940 | self.write(*args) |
|
1940 | self.write(*args) | |
1941 | def status(self, *args): |
|
1941 | def status(self, *args): | |
1942 | if not self.quiet: |
|
1942 | if not self.quiet: | |
1943 | self.write(*args) |
|
1943 | self.write(*args) | |
1944 | def write(self, *args): |
|
1944 | def write(self, *args): | |
1945 | self.hunk[self.rev].append(args) |
|
1945 | self.hunk[self.rev].append(args) | |
1946 | def write_header(self, *args): |
|
1946 | def write_header(self, *args): | |
1947 | self.header[self.rev].append(args) |
|
1947 | self.header[self.rev].append(args) | |
1948 | def debug(self, *args): |
|
1948 | def debug(self, *args): | |
1949 | if self.debugflag: |
|
1949 | if self.debugflag: | |
1950 | self.write(*args) |
|
1950 | self.write(*args) | |
1951 | def __getattr__(self, key): |
|
1951 | def __getattr__(self, key): | |
1952 | return getattr(self.ui, key) |
|
1952 | return getattr(self.ui, key) | |
1953 |
|
1953 | |||
1954 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1954 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | |
1955 |
|
1955 | |||
1956 | if opts['limit']: |
|
1956 | if opts['limit']: | |
1957 | try: |
|
1957 | try: | |
1958 | limit = int(opts['limit']) |
|
1958 | limit = int(opts['limit']) | |
1959 | except ValueError: |
|
1959 | except ValueError: | |
1960 | raise util.Abort(_('limit must be a positive integer')) |
|
1960 | raise util.Abort(_('limit must be a positive integer')) | |
1961 | if limit <= 0: raise util.Abort(_('limit must be positive')) |
|
1961 | if limit <= 0: raise util.Abort(_('limit must be positive')) | |
1962 | else: |
|
1962 | else: | |
1963 | limit = sys.maxint |
|
1963 | limit = sys.maxint | |
1964 | count = 0 |
|
1964 | count = 0 | |
1965 |
|
1965 | |||
1966 | displayer = show_changeset(ui, repo, opts) |
|
1966 | displayer = show_changeset(ui, repo, opts) | |
1967 | for st, rev, fns in changeiter: |
|
1967 | for st, rev, fns in changeiter: | |
1968 | if st == 'window': |
|
1968 | if st == 'window': | |
1969 | du = dui(ui) |
|
1969 | du = dui(ui) | |
1970 | displayer.ui = du |
|
1970 | displayer.ui = du | |
1971 | elif st == 'add': |
|
1971 | elif st == 'add': | |
1972 | du.bump(rev) |
|
1972 | du.bump(rev) | |
1973 | changenode = repo.changelog.node(rev) |
|
1973 | changenode = repo.changelog.node(rev) | |
1974 | parents = [p for p in repo.changelog.parents(changenode) |
|
1974 | parents = [p for p in repo.changelog.parents(changenode) | |
1975 | if p != nullid] |
|
1975 | if p != nullid] | |
1976 | if opts['no_merges'] and len(parents) == 2: |
|
1976 | if opts['no_merges'] and len(parents) == 2: | |
1977 | continue |
|
1977 | continue | |
1978 | if opts['only_merges'] and len(parents) != 2: |
|
1978 | if opts['only_merges'] and len(parents) != 2: | |
1979 | continue |
|
1979 | continue | |
1980 |
|
1980 | |||
1981 | if opts['keyword']: |
|
1981 | if opts['keyword']: | |
1982 | changes = getchange(rev) |
|
1982 | changes = getchange(rev) | |
1983 | miss = 0 |
|
1983 | miss = 0 | |
1984 | for k in [kw.lower() for kw in opts['keyword']]: |
|
1984 | for k in [kw.lower() for kw in opts['keyword']]: | |
1985 | if not (k in changes[1].lower() or |
|
1985 | if not (k in changes[1].lower() or | |
1986 | k in changes[4].lower() or |
|
1986 | k in changes[4].lower() or | |
1987 | k in " ".join(changes[3][:20]).lower()): |
|
1987 | k in " ".join(changes[3][:20]).lower()): | |
1988 | miss = 1 |
|
1988 | miss = 1 | |
1989 | break |
|
1989 | break | |
1990 | if miss: |
|
1990 | if miss: | |
1991 | continue |
|
1991 | continue | |
1992 |
|
1992 | |||
1993 | br = None |
|
1993 | br = None | |
1994 | if opts['branches']: |
|
1994 | if opts['branches']: | |
1995 | br = repo.branchlookup([repo.changelog.node(rev)]) |
|
1995 | br = repo.branchlookup([repo.changelog.node(rev)]) | |
1996 |
|
1996 | |||
1997 | displayer.show(rev, brinfo=br) |
|
1997 | displayer.show(rev, brinfo=br) | |
1998 | if opts['patch']: |
|
1998 | if opts['patch']: | |
1999 | prev = (parents and parents[0]) or nullid |
|
1999 | prev = (parents and parents[0]) or nullid | |
2000 | dodiff(du, du, repo, prev, changenode, match=matchfn) |
|
2000 | dodiff(du, du, repo, prev, changenode, match=matchfn) | |
2001 | du.write("\n\n") |
|
2001 | du.write("\n\n") | |
2002 | elif st == 'iter': |
|
2002 | elif st == 'iter': | |
2003 | if count == limit: break |
|
2003 | if count == limit: break | |
2004 | if du.header[rev]: |
|
2004 | if du.header[rev]: | |
2005 | for args in du.header[rev]: |
|
2005 | for args in du.header[rev]: | |
2006 | ui.write_header(*args) |
|
2006 | ui.write_header(*args) | |
2007 | if du.hunk[rev]: |
|
2007 | if du.hunk[rev]: | |
2008 | count += 1 |
|
2008 | count += 1 | |
2009 | for args in du.hunk[rev]: |
|
2009 | for args in du.hunk[rev]: | |
2010 | ui.write(*args) |
|
2010 | ui.write(*args) | |
2011 |
|
2011 | |||
2012 | def manifest(ui, repo, rev=None): |
|
2012 | def manifest(ui, repo, rev=None): | |
2013 | """output the latest or given revision of the project manifest |
|
2013 | """output the latest or given revision of the project manifest | |
2014 |
|
2014 | |||
2015 | Print a list of version controlled files for the given revision. |
|
2015 | Print a list of version controlled files for the given revision. | |
2016 |
|
2016 | |||
2017 | The manifest is the list of files being version controlled. If no revision |
|
2017 | The manifest is the list of files being version controlled. If no revision | |
2018 | is given then the tip is used. |
|
2018 | is given then the tip is used. | |
2019 | """ |
|
2019 | """ | |
2020 | if rev: |
|
2020 | if rev: | |
2021 | try: |
|
2021 | try: | |
2022 | # assume all revision numbers are for changesets |
|
2022 | # assume all revision numbers are for changesets | |
2023 | n = repo.lookup(rev) |
|
2023 | n = repo.lookup(rev) | |
2024 | change = repo.changelog.read(n) |
|
2024 | change = repo.changelog.read(n) | |
2025 | n = change[0] |
|
2025 | n = change[0] | |
2026 | except hg.RepoError: |
|
2026 | except hg.RepoError: | |
2027 | n = repo.manifest.lookup(rev) |
|
2027 | n = repo.manifest.lookup(rev) | |
2028 | else: |
|
2028 | else: | |
2029 | n = repo.manifest.tip() |
|
2029 | n = repo.manifest.tip() | |
2030 | m = repo.manifest.read(n) |
|
2030 | m = repo.manifest.read(n) | |
2031 | mf = repo.manifest.readflags(n) |
|
2031 | mf = repo.manifest.readflags(n) | |
2032 | files = m.keys() |
|
2032 | files = m.keys() | |
2033 | files.sort() |
|
2033 | files.sort() | |
2034 |
|
2034 | |||
2035 | for f in files: |
|
2035 | for f in files: | |
2036 | ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) |
|
2036 | ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) | |
2037 |
|
2037 | |||
2038 | def merge(ui, repo, node=None, **opts): |
|
2038 | def merge(ui, repo, node=None, **opts): | |
2039 | """Merge working directory with another revision |
|
2039 | """Merge working directory with another revision | |
2040 |
|
2040 | |||
2041 | Merge the contents of the current working directory and the |
|
2041 | Merge the contents of the current working directory and the | |
2042 | requested revision. Files that changed between either parent are |
|
2042 | requested revision. Files that changed between either parent are | |
2043 | marked as changed for the next commit and a commit must be |
|
2043 | marked as changed for the next commit and a commit must be | |
2044 | performed before any further updates are allowed. |
|
2044 | performed before any further updates are allowed. | |
2045 | """ |
|
2045 | """ | |
2046 | return update(ui, repo, node=node, merge=True, **opts) |
|
2046 | return update(ui, repo, node=node, merge=True, **opts) | |
2047 |
|
2047 | |||
2048 | def outgoing(ui, repo, dest="default-push", **opts): |
|
2048 | def outgoing(ui, repo, dest="default-push", **opts): | |
2049 | """show changesets not found in destination |
|
2049 | """show changesets not found in destination | |
2050 |
|
2050 | |||
2051 | Show changesets not found in the specified destination repository or |
|
2051 | Show changesets not found in the specified destination repository or | |
2052 | the default push location. These are the changesets that would be pushed |
|
2052 | the default push location. These are the changesets that would be pushed | |
2053 | if a push was requested. |
|
2053 | if a push was requested. | |
2054 |
|
2054 | |||
2055 | See pull for valid destination format details. |
|
2055 | See pull for valid destination format details. | |
2056 | """ |
|
2056 | """ | |
2057 | dest = ui.expandpath(dest) |
|
2057 | dest = ui.expandpath(dest) | |
2058 | if opts['ssh']: |
|
2058 | if opts['ssh']: | |
2059 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
2059 | ui.setconfig("ui", "ssh", opts['ssh']) | |
2060 | if opts['remotecmd']: |
|
2060 | if opts['remotecmd']: | |
2061 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
2061 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
2062 |
|
2062 | |||
2063 | other = hg.repository(ui, dest) |
|
2063 | other = hg.repository(ui, dest) | |
2064 | o = repo.findoutgoing(other, force=opts['force']) |
|
2064 | o = repo.findoutgoing(other, force=opts['force']) | |
2065 | if not o: |
|
2065 | if not o: | |
2066 | ui.status(_("no changes found\n")) |
|
2066 | ui.status(_("no changes found\n")) | |
2067 | return |
|
2067 | return | |
2068 | o = repo.changelog.nodesbetween(o)[0] |
|
2068 | o = repo.changelog.nodesbetween(o)[0] | |
2069 | if opts['newest_first']: |
|
2069 | if opts['newest_first']: | |
2070 | o.reverse() |
|
2070 | o.reverse() | |
2071 | displayer = show_changeset(ui, repo, opts) |
|
2071 | displayer = show_changeset(ui, repo, opts) | |
2072 | for n in o: |
|
2072 | for n in o: | |
2073 | parents = [p for p in repo.changelog.parents(n) if p != nullid] |
|
2073 | parents = [p for p in repo.changelog.parents(n) if p != nullid] | |
2074 | if opts['no_merges'] and len(parents) == 2: |
|
2074 | if opts['no_merges'] and len(parents) == 2: | |
2075 | continue |
|
2075 | continue | |
2076 | displayer.show(changenode=n) |
|
2076 | displayer.show(changenode=n) | |
2077 | if opts['patch']: |
|
2077 | if opts['patch']: | |
2078 | prev = (parents and parents[0]) or nullid |
|
2078 | prev = (parents and parents[0]) or nullid | |
2079 | dodiff(ui, ui, repo, prev, n) |
|
2079 | dodiff(ui, ui, repo, prev, n) | |
2080 | ui.write("\n") |
|
2080 | ui.write("\n") | |
2081 |
|
2081 | |||
2082 | def parents(ui, repo, rev=None, branches=None, **opts): |
|
2082 | def parents(ui, repo, rev=None, branches=None, **opts): | |
2083 | """show the parents of the working dir or revision |
|
2083 | """show the parents of the working dir or revision | |
2084 |
|
2084 | |||
2085 | Print the working directory's parent revisions. |
|
2085 | Print the working directory's parent revisions. | |
2086 | """ |
|
2086 | """ | |
2087 | if rev: |
|
2087 | if rev: | |
2088 | p = repo.changelog.parents(repo.lookup(rev)) |
|
2088 | p = repo.changelog.parents(repo.lookup(rev)) | |
2089 | else: |
|
2089 | else: | |
2090 | p = repo.dirstate.parents() |
|
2090 | p = repo.dirstate.parents() | |
2091 |
|
2091 | |||
2092 | br = None |
|
2092 | br = None | |
2093 | if branches is not None: |
|
2093 | if branches is not None: | |
2094 | br = repo.branchlookup(p) |
|
2094 | br = repo.branchlookup(p) | |
2095 | displayer = show_changeset(ui, repo, opts) |
|
2095 | displayer = show_changeset(ui, repo, opts) | |
2096 | for n in p: |
|
2096 | for n in p: | |
2097 | if n != nullid: |
|
2097 | if n != nullid: | |
2098 | displayer.show(changenode=n, brinfo=br) |
|
2098 | displayer.show(changenode=n, brinfo=br) | |
2099 |
|
2099 | |||
2100 | def paths(ui, repo, search=None): |
|
2100 | def paths(ui, repo, search=None): | |
2101 | """show definition of symbolic path names |
|
2101 | """show definition of symbolic path names | |
2102 |
|
2102 | |||
2103 | Show definition of symbolic path name NAME. If no name is given, show |
|
2103 | Show definition of symbolic path name NAME. If no name is given, show | |
2104 | definition of available names. |
|
2104 | definition of available names. | |
2105 |
|
2105 | |||
2106 | Path names are defined in the [paths] section of /etc/mercurial/hgrc |
|
2106 | Path names are defined in the [paths] section of /etc/mercurial/hgrc | |
2107 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. |
|
2107 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. | |
2108 | """ |
|
2108 | """ | |
2109 | if search: |
|
2109 | if search: | |
2110 | for name, path in ui.configitems("paths"): |
|
2110 | for name, path in ui.configitems("paths"): | |
2111 | if name == search: |
|
2111 | if name == search: | |
2112 | ui.write("%s\n" % path) |
|
2112 | ui.write("%s\n" % path) | |
2113 | return |
|
2113 | return | |
2114 | ui.warn(_("not found!\n")) |
|
2114 | ui.warn(_("not found!\n")) | |
2115 | return 1 |
|
2115 | return 1 | |
2116 | else: |
|
2116 | else: | |
2117 | for name, path in ui.configitems("paths"): |
|
2117 | for name, path in ui.configitems("paths"): | |
2118 | ui.write("%s = %s\n" % (name, path)) |
|
2118 | ui.write("%s = %s\n" % (name, path)) | |
2119 |
|
2119 | |||
2120 | def postincoming(ui, repo, modheads, optupdate): |
|
2120 | def postincoming(ui, repo, modheads, optupdate): | |
2121 | if modheads == 0: |
|
2121 | if modheads == 0: | |
2122 | return |
|
2122 | return | |
2123 | if optupdate: |
|
2123 | if optupdate: | |
2124 | if modheads == 1: |
|
2124 | if modheads == 1: | |
2125 | return update(ui, repo) |
|
2125 | return update(ui, repo) | |
2126 | else: |
|
2126 | else: | |
2127 | ui.status(_("not updating, since new heads added\n")) |
|
2127 | ui.status(_("not updating, since new heads added\n")) | |
2128 | if modheads > 1: |
|
2128 | if modheads > 1: | |
2129 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
2129 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) | |
2130 | else: |
|
2130 | else: | |
2131 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
2131 | ui.status(_("(run 'hg update' to get a working copy)\n")) | |
2132 |
|
2132 | |||
2133 | def pull(ui, repo, source="default", **opts): |
|
2133 | def pull(ui, repo, source="default", **opts): | |
2134 | """pull changes from the specified source |
|
2134 | """pull changes from the specified source | |
2135 |
|
2135 | |||
2136 | Pull changes from a remote repository to a local one. |
|
2136 | Pull changes from a remote repository to a local one. | |
2137 |
|
2137 | |||
2138 | This finds all changes from the repository at the specified path |
|
2138 | This finds all changes from the repository at the specified path | |
2139 | or URL and adds them to the local repository. By default, this |
|
2139 | or URL and adds them to the local repository. By default, this | |
2140 | does not update the copy of the project in the working directory. |
|
2140 | does not update the copy of the project in the working directory. | |
2141 |
|
2141 | |||
2142 | Valid URLs are of the form: |
|
2142 | Valid URLs are of the form: | |
2143 |
|
2143 | |||
2144 | local/filesystem/path |
|
2144 | local/filesystem/path | |
2145 | http://[user@]host[:port][/path] |
|
2145 | http://[user@]host[:port][/path] | |
2146 | https://[user@]host[:port][/path] |
|
2146 | https://[user@]host[:port][/path] | |
2147 | ssh://[user@]host[:port][/path] |
|
2147 | ssh://[user@]host[:port][/path] | |
2148 |
|
2148 | |||
2149 | Some notes about using SSH with Mercurial: |
|
2149 | Some notes about using SSH with Mercurial: | |
2150 | - SSH requires an accessible shell account on the destination machine |
|
2150 | - SSH requires an accessible shell account on the destination machine | |
2151 | and a copy of hg in the remote path or specified with as remotecmd. |
|
2151 | and a copy of hg in the remote path or specified with as remotecmd. | |
2152 | - /path is relative to the remote user's home directory by default. |
|
2152 | - /path is relative to the remote user's home directory by default. | |
2153 | Use two slashes at the start of a path to specify an absolute path. |
|
2153 | Use two slashes at the start of a path to specify an absolute path. | |
2154 | - Mercurial doesn't use its own compression via SSH; the right thing |
|
2154 | - Mercurial doesn't use its own compression via SSH; the right thing | |
2155 | to do is to configure it in your ~/.ssh/ssh_config, e.g.: |
|
2155 | to do is to configure it in your ~/.ssh/ssh_config, e.g.: | |
2156 | Host *.mylocalnetwork.example.com |
|
2156 | Host *.mylocalnetwork.example.com | |
2157 | Compression off |
|
2157 | Compression off | |
2158 | Host * |
|
2158 | Host * | |
2159 | Compression on |
|
2159 | Compression on | |
2160 | Alternatively specify "ssh -C" as your ssh command in your hgrc or |
|
2160 | Alternatively specify "ssh -C" as your ssh command in your hgrc or | |
2161 | with the --ssh command line option. |
|
2161 | with the --ssh command line option. | |
2162 | """ |
|
2162 | """ | |
2163 | source = ui.expandpath(source) |
|
2163 | source = ui.expandpath(source) | |
2164 | ui.status(_('pulling from %s\n') % (source)) |
|
2164 | ui.status(_('pulling from %s\n') % (source)) | |
2165 |
|
2165 | |||
2166 | if opts['ssh']: |
|
2166 | if opts['ssh']: | |
2167 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
2167 | ui.setconfig("ui", "ssh", opts['ssh']) | |
2168 | if opts['remotecmd']: |
|
2168 | if opts['remotecmd']: | |
2169 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
2169 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
2170 |
|
2170 | |||
2171 | other = hg.repository(ui, source) |
|
2171 | other = hg.repository(ui, source) | |
2172 | revs = None |
|
2172 | revs = None | |
2173 | if opts['rev'] and not other.local(): |
|
2173 | if opts['rev'] and not other.local(): | |
2174 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) |
|
2174 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) | |
2175 | elif opts['rev']: |
|
2175 | elif opts['rev']: | |
2176 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
2176 | revs = [other.lookup(rev) for rev in opts['rev']] | |
2177 | modheads = repo.pull(other, heads=revs, force=opts['force']) |
|
2177 | modheads = repo.pull(other, heads=revs, force=opts['force']) | |
2178 | return postincoming(ui, repo, modheads, opts['update']) |
|
2178 | return postincoming(ui, repo, modheads, opts['update']) | |
2179 |
|
2179 | |||
2180 | def push(ui, repo, dest="default-push", **opts): |
|
2180 | def push(ui, repo, dest="default-push", **opts): | |
2181 | """push changes to the specified destination |
|
2181 | """push changes to the specified destination | |
2182 |
|
2182 | |||
2183 | Push changes from the local repository to the given destination. |
|
2183 | Push changes from the local repository to the given destination. | |
2184 |
|
2184 | |||
2185 | This is the symmetrical operation for pull. It helps to move |
|
2185 | This is the symmetrical operation for pull. It helps to move | |
2186 | changes from the current repository to a different one. If the |
|
2186 | changes from the current repository to a different one. If the | |
2187 | destination is local this is identical to a pull in that directory |
|
2187 | destination is local this is identical to a pull in that directory | |
2188 | from the current one. |
|
2188 | from the current one. | |
2189 |
|
2189 | |||
2190 | By default, push will refuse to run if it detects the result would |
|
2190 | By default, push will refuse to run if it detects the result would | |
2191 | increase the number of remote heads. This generally indicates the |
|
2191 | increase the number of remote heads. This generally indicates the | |
2192 | the client has forgotten to sync and merge before pushing. |
|
2192 | the client has forgotten to sync and merge before pushing. | |
2193 |
|
2193 | |||
2194 | Valid URLs are of the form: |
|
2194 | Valid URLs are of the form: | |
2195 |
|
2195 | |||
2196 | local/filesystem/path |
|
2196 | local/filesystem/path | |
2197 | ssh://[user@]host[:port][/path] |
|
2197 | ssh://[user@]host[:port][/path] | |
2198 |
|
2198 | |||
2199 | Look at the help text for the pull command for important details |
|
2199 | Look at the help text for the pull command for important details | |
2200 | about ssh:// URLs. |
|
2200 | about ssh:// URLs. | |
2201 | """ |
|
2201 | """ | |
2202 | dest = ui.expandpath(dest) |
|
2202 | dest = ui.expandpath(dest) | |
2203 | ui.status('pushing to %s\n' % (dest)) |
|
2203 | ui.status('pushing to %s\n' % (dest)) | |
2204 |
|
2204 | |||
2205 | if opts['ssh']: |
|
2205 | if opts['ssh']: | |
2206 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
2206 | ui.setconfig("ui", "ssh", opts['ssh']) | |
2207 | if opts['remotecmd']: |
|
2207 | if opts['remotecmd']: | |
2208 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
2208 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
2209 |
|
2209 | |||
2210 | other = hg.repository(ui, dest) |
|
2210 | other = hg.repository(ui, dest) | |
2211 | revs = None |
|
2211 | revs = None | |
2212 | if opts['rev']: |
|
2212 | if opts['rev']: | |
2213 | revs = [repo.lookup(rev) for rev in opts['rev']] |
|
2213 | revs = [repo.lookup(rev) for rev in opts['rev']] | |
2214 | r = repo.push(other, opts['force'], revs=revs) |
|
2214 | r = repo.push(other, opts['force'], revs=revs) | |
2215 | return r == 0 |
|
2215 | return r == 0 | |
2216 |
|
2216 | |||
2217 | def rawcommit(ui, repo, *flist, **rc): |
|
2217 | def rawcommit(ui, repo, *flist, **rc): | |
2218 | """raw commit interface (DEPRECATED) |
|
2218 | """raw commit interface (DEPRECATED) | |
2219 |
|
2219 | |||
2220 | (DEPRECATED) |
|
2220 | (DEPRECATED) | |
2221 | Lowlevel commit, for use in helper scripts. |
|
2221 | Lowlevel commit, for use in helper scripts. | |
2222 |
|
2222 | |||
2223 | This command is not intended to be used by normal users, as it is |
|
2223 | This command is not intended to be used by normal users, as it is | |
2224 | primarily useful for importing from other SCMs. |
|
2224 | primarily useful for importing from other SCMs. | |
2225 |
|
2225 | |||
2226 | This command is now deprecated and will be removed in a future |
|
2226 | This command is now deprecated and will be removed in a future | |
2227 | release, please use debugsetparents and commit instead. |
|
2227 | release, please use debugsetparents and commit instead. | |
2228 | """ |
|
2228 | """ | |
2229 |
|
2229 | |||
2230 | ui.warn(_("(the rawcommit command is deprecated)\n")) |
|
2230 | ui.warn(_("(the rawcommit command is deprecated)\n")) | |
2231 |
|
2231 | |||
2232 | message = rc['message'] |
|
2232 | message = rc['message'] | |
2233 | if not message and rc['logfile']: |
|
2233 | if not message and rc['logfile']: | |
2234 | try: |
|
2234 | try: | |
2235 | message = open(rc['logfile']).read() |
|
2235 | message = open(rc['logfile']).read() | |
2236 | except IOError: |
|
2236 | except IOError: | |
2237 | pass |
|
2237 | pass | |
2238 | if not message and not rc['logfile']: |
|
2238 | if not message and not rc['logfile']: | |
2239 | raise util.Abort(_("missing commit message")) |
|
2239 | raise util.Abort(_("missing commit message")) | |
2240 |
|
2240 | |||
2241 | files = relpath(repo, list(flist)) |
|
2241 | files = relpath(repo, list(flist)) | |
2242 | if rc['files']: |
|
2242 | if rc['files']: | |
2243 | files += open(rc['files']).read().splitlines() |
|
2243 | files += open(rc['files']).read().splitlines() | |
2244 |
|
2244 | |||
2245 | rc['parent'] = map(repo.lookup, rc['parent']) |
|
2245 | rc['parent'] = map(repo.lookup, rc['parent']) | |
2246 |
|
2246 | |||
2247 | try: |
|
2247 | try: | |
2248 | repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) |
|
2248 | repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) | |
2249 | except ValueError, inst: |
|
2249 | except ValueError, inst: | |
2250 | raise util.Abort(str(inst)) |
|
2250 | raise util.Abort(str(inst)) | |
2251 |
|
2251 | |||
2252 | def recover(ui, repo): |
|
2252 | def recover(ui, repo): | |
2253 | """roll back an interrupted transaction |
|
2253 | """roll back an interrupted transaction | |
2254 |
|
2254 | |||
2255 | Recover from an interrupted commit or pull. |
|
2255 | Recover from an interrupted commit or pull. | |
2256 |
|
2256 | |||
2257 | This command tries to fix the repository status after an interrupted |
|
2257 | This command tries to fix the repository status after an interrupted | |
2258 | operation. It should only be necessary when Mercurial suggests it. |
|
2258 | operation. It should only be necessary when Mercurial suggests it. | |
2259 | """ |
|
2259 | """ | |
2260 | if repo.recover(): |
|
2260 | if repo.recover(): | |
2261 | return repo.verify() |
|
2261 | return repo.verify() | |
2262 | return 1 |
|
2262 | return 1 | |
2263 |
|
2263 | |||
2264 | def remove(ui, repo, pat, *pats, **opts): |
|
2264 | def remove(ui, repo, pat, *pats, **opts): | |
2265 | """remove the specified files on the next commit |
|
2265 | """remove the specified files on the next commit | |
2266 |
|
2266 | |||
2267 | Schedule the indicated files for removal from the repository. |
|
2267 | Schedule the indicated files for removal from the repository. | |
2268 |
|
2268 | |||
2269 | This command schedules the files to be removed at the next commit. |
|
2269 | This command schedules the files to be removed at the next commit. | |
2270 | This only removes files from the current branch, not from the |
|
2270 | This only removes files from the current branch, not from the | |
2271 | entire project history. If the files still exist in the working |
|
2271 | entire project history. If the files still exist in the working | |
2272 | directory, they will be deleted from it. |
|
2272 | directory, they will be deleted from it. | |
2273 | """ |
|
2273 | """ | |
2274 | names = [] |
|
2274 | names = [] | |
2275 | def okaytoremove(abs, rel, exact): |
|
2275 | def okaytoremove(abs, rel, exact): | |
2276 | modified, added, removed, deleted, unknown = repo.changes(files=[abs]) |
|
2276 | modified, added, removed, deleted, unknown = repo.changes(files=[abs]) | |
2277 | reason = None |
|
2277 | reason = None | |
2278 | if modified and not opts['force']: |
|
2278 | if modified and not opts['force']: | |
2279 | reason = _('is modified') |
|
2279 | reason = _('is modified') | |
2280 | elif added: |
|
2280 | elif added: | |
2281 | reason = _('has been marked for add') |
|
2281 | reason = _('has been marked for add') | |
2282 | elif unknown: |
|
2282 | elif unknown: | |
2283 | reason = _('is not managed') |
|
2283 | reason = _('is not managed') | |
2284 | if reason: |
|
2284 | if reason: | |
2285 | if exact: |
|
2285 | if exact: | |
2286 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) |
|
2286 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) | |
2287 | else: |
|
2287 | else: | |
2288 | return True |
|
2288 | return True | |
2289 | for src, abs, rel, exact in walk(repo, (pat,) + pats, opts): |
|
2289 | for src, abs, rel, exact in walk(repo, (pat,) + pats, opts): | |
2290 | if okaytoremove(abs, rel, exact): |
|
2290 | if okaytoremove(abs, rel, exact): | |
2291 | if ui.verbose or not exact: |
|
2291 | if ui.verbose or not exact: | |
2292 | ui.status(_('removing %s\n') % rel) |
|
2292 | ui.status(_('removing %s\n') % rel) | |
2293 | names.append(abs) |
|
2293 | names.append(abs) | |
2294 | repo.remove(names, unlink=True) |
|
2294 | repo.remove(names, unlink=True) | |
2295 |
|
2295 | |||
2296 | def rename(ui, repo, *pats, **opts): |
|
2296 | def rename(ui, repo, *pats, **opts): | |
2297 | """rename files; equivalent of copy + remove |
|
2297 | """rename files; equivalent of copy + remove | |
2298 |
|
2298 | |||
2299 | Mark dest as copies of sources; mark sources for deletion. If |
|
2299 | Mark dest as copies of sources; mark sources for deletion. If | |
2300 | dest is a directory, copies are put in that directory. If dest is |
|
2300 | dest is a directory, copies are put in that directory. If dest is | |
2301 | a file, there can only be one source. |
|
2301 | a file, there can only be one source. | |
2302 |
|
2302 | |||
2303 | By default, this command copies the contents of files as they |
|
2303 | By default, this command copies the contents of files as they | |
2304 | stand in the working directory. If invoked with --after, the |
|
2304 | stand in the working directory. If invoked with --after, the | |
2305 | operation is recorded, but no copying is performed. |
|
2305 | operation is recorded, but no copying is performed. | |
2306 |
|
2306 | |||
2307 | This command takes effect in the next commit. |
|
2307 | This command takes effect in the next commit. | |
2308 |
|
2308 | |||
2309 | NOTE: This command should be treated as experimental. While it |
|
2309 | NOTE: This command should be treated as experimental. While it | |
2310 | should properly record rename files, this information is not yet |
|
2310 | should properly record rename files, this information is not yet | |
2311 | fully used by merge, nor fully reported by log. |
|
2311 | fully used by merge, nor fully reported by log. | |
2312 | """ |
|
2312 | """ | |
2313 | wlock = repo.wlock(0) |
|
2313 | wlock = repo.wlock(0) | |
2314 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
2314 | errs, copied = docopy(ui, repo, pats, opts, wlock) | |
2315 | names = [] |
|
2315 | names = [] | |
2316 | for abs, rel, exact in copied: |
|
2316 | for abs, rel, exact in copied: | |
2317 | if ui.verbose or not exact: |
|
2317 | if ui.verbose or not exact: | |
2318 | ui.status(_('removing %s\n') % rel) |
|
2318 | ui.status(_('removing %s\n') % rel) | |
2319 | names.append(abs) |
|
2319 | names.append(abs) | |
2320 | repo.remove(names, True, wlock) |
|
2320 | repo.remove(names, True, wlock) | |
2321 | return errs |
|
2321 | return errs | |
2322 |
|
2322 | |||
2323 | def revert(ui, repo, *pats, **opts): |
|
2323 | def revert(ui, repo, *pats, **opts): | |
2324 | """revert modified files or dirs back to their unmodified states |
|
2324 | """revert modified files or dirs back to their unmodified states | |
2325 |
|
2325 | |||
2326 | In its default mode, it reverts any uncommitted modifications made |
|
2326 | In its default mode, it reverts any uncommitted modifications made | |
2327 | to the named files or directories. This restores the contents of |
|
2327 | to the named files or directories. This restores the contents of | |
2328 | the affected files to an unmodified state. |
|
2328 | the affected files to an unmodified state. | |
2329 |
|
2329 | |||
2330 | Modified files are saved with a .orig suffix before reverting. |
|
2330 | Modified files are saved with a .orig suffix before reverting. | |
2331 | To disable these backups, use --no-backup. |
|
2331 | To disable these backups, use --no-backup. | |
2332 |
|
2332 | |||
2333 | Using the -r option, it reverts the given files or directories to |
|
2333 | Using the -r option, it reverts the given files or directories to | |
2334 | their state as of an earlier revision. This can be helpful to "roll |
|
2334 | their state as of an earlier revision. This can be helpful to "roll | |
2335 | back" some or all of a change that should not have been committed. |
|
2335 | back" some or all of a change that should not have been committed. | |
2336 |
|
2336 | |||
2337 | Revert modifies the working directory. It does not commit any |
|
2337 | Revert modifies the working directory. It does not commit any | |
2338 | changes, or change the parent of the current working directory. |
|
2338 | changes, or change the parent of the current working directory. | |
2339 |
|
2339 | |||
2340 | If a file has been deleted, it is recreated. If the executable |
|
2340 | If a file has been deleted, it is recreated. If the executable | |
2341 | mode of a file was changed, it is reset. |
|
2341 | mode of a file was changed, it is reset. | |
2342 |
|
2342 | |||
2343 | If names are given, all files matching the names are reverted. |
|
2343 | If names are given, all files matching the names are reverted. | |
2344 |
|
2344 | |||
2345 | If no arguments are given, all files in the repository are reverted. |
|
2345 | If no arguments are given, all files in the repository are reverted. | |
2346 | """ |
|
2346 | """ | |
2347 | parent = repo.dirstate.parents()[0] |
|
2347 | parent = repo.dirstate.parents()[0] | |
2348 | node = opts['rev'] and repo.lookup(opts['rev']) or parent |
|
2348 | node = opts['rev'] and repo.lookup(opts['rev']) or parent | |
2349 | mf = repo.manifest.read(repo.changelog.read(node)[0]) |
|
2349 | mf = repo.manifest.read(repo.changelog.read(node)[0]) | |
2350 |
|
2350 | |||
2351 | wlock = repo.wlock() |
|
2351 | wlock = repo.wlock() | |
2352 |
|
2352 | |||
2353 | # need all matching names in dirstate and manifest of target rev, |
|
2353 | # need all matching names in dirstate and manifest of target rev, | |
2354 | # so have to walk both. do not print errors if files exist in one |
|
2354 | # so have to walk both. do not print errors if files exist in one | |
2355 | # but not other. |
|
2355 | # but not other. | |
2356 |
|
2356 | |||
2357 | names = {} |
|
2357 | names = {} | |
2358 | target_only = {} |
|
2358 | target_only = {} | |
2359 |
|
2359 | |||
2360 | # walk dirstate. |
|
2360 | # walk dirstate. | |
2361 |
|
2361 | |||
2362 | for src, abs, rel, exact in walk(repo, pats, opts, badmatch=mf.has_key): |
|
2362 | for src, abs, rel, exact in walk(repo, pats, opts, badmatch=mf.has_key): | |
2363 | names[abs] = (rel, exact) |
|
2363 | names[abs] = (rel, exact) | |
2364 | if src == 'b': |
|
2364 | if src == 'b': | |
2365 | target_only[abs] = True |
|
2365 | target_only[abs] = True | |
2366 |
|
2366 | |||
2367 | # walk target manifest. |
|
2367 | # walk target manifest. | |
2368 |
|
2368 | |||
2369 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, |
|
2369 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, | |
2370 | badmatch=names.has_key): |
|
2370 | badmatch=names.has_key): | |
2371 | if abs in names: continue |
|
2371 | if abs in names: continue | |
2372 | names[abs] = (rel, exact) |
|
2372 | names[abs] = (rel, exact) | |
2373 | target_only[abs] = True |
|
2373 | target_only[abs] = True | |
2374 |
|
2374 | |||
2375 | changes = repo.changes(match=names.has_key, wlock=wlock) |
|
2375 | changes = repo.changes(match=names.has_key, wlock=wlock) | |
2376 | modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) |
|
2376 | modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) | |
2377 |
|
2377 | |||
2378 | revert = ([], _('reverting %s\n')) |
|
2378 | revert = ([], _('reverting %s\n')) | |
2379 | add = ([], _('adding %s\n')) |
|
2379 | add = ([], _('adding %s\n')) | |
2380 | remove = ([], _('removing %s\n')) |
|
2380 | remove = ([], _('removing %s\n')) | |
2381 | forget = ([], _('forgetting %s\n')) |
|
2381 | forget = ([], _('forgetting %s\n')) | |
2382 | undelete = ([], _('undeleting %s\n')) |
|
2382 | undelete = ([], _('undeleting %s\n')) | |
2383 | update = {} |
|
2383 | update = {} | |
2384 |
|
2384 | |||
2385 | disptable = ( |
|
2385 | disptable = ( | |
2386 | # dispatch table: |
|
2386 | # dispatch table: | |
2387 | # file state |
|
2387 | # file state | |
2388 | # action if in target manifest |
|
2388 | # action if in target manifest | |
2389 | # action if not in target manifest |
|
2389 | # action if not in target manifest | |
2390 | # make backup if in target manifest |
|
2390 | # make backup if in target manifest | |
2391 | # make backup if not in target manifest |
|
2391 | # make backup if not in target manifest | |
2392 | (modified, revert, remove, True, True), |
|
2392 | (modified, revert, remove, True, True), | |
2393 | (added, revert, forget, True, False), |
|
2393 | (added, revert, forget, True, False), | |
2394 | (removed, undelete, None, False, False), |
|
2394 | (removed, undelete, None, False, False), | |
2395 | (deleted, revert, remove, False, False), |
|
2395 | (deleted, revert, remove, False, False), | |
2396 | (unknown, add, None, True, False), |
|
2396 | (unknown, add, None, True, False), | |
2397 | (target_only, add, None, False, False), |
|
2397 | (target_only, add, None, False, False), | |
2398 | ) |
|
2398 | ) | |
2399 |
|
2399 | |||
2400 | entries = names.items() |
|
2400 | entries = names.items() | |
2401 | entries.sort() |
|
2401 | entries.sort() | |
2402 |
|
2402 | |||
2403 | for abs, (rel, exact) in entries: |
|
2403 | for abs, (rel, exact) in entries: | |
2404 | in_mf = abs in mf |
|
2404 | in_mf = abs in mf | |
2405 | def handle(xlist, dobackup): |
|
2405 | def handle(xlist, dobackup): | |
2406 | xlist[0].append(abs) |
|
2406 | xlist[0].append(abs) | |
2407 | if dobackup and not opts['no_backup'] and os.path.exists(rel): |
|
2407 | if dobackup and not opts['no_backup'] and os.path.exists(rel): | |
2408 | bakname = "%s.orig" % rel |
|
2408 | bakname = "%s.orig" % rel | |
2409 | ui.note(_('saving current version of %s as %s\n') % |
|
2409 | ui.note(_('saving current version of %s as %s\n') % | |
2410 | (rel, bakname)) |
|
2410 | (rel, bakname)) | |
2411 | shutil.copyfile(rel, bakname) |
|
2411 | shutil.copyfile(rel, bakname) | |
2412 | shutil.copymode(rel, bakname) |
|
2412 | shutil.copymode(rel, bakname) | |
2413 | if ui.verbose or not exact: |
|
2413 | if ui.verbose or not exact: | |
2414 | ui.status(xlist[1] % rel) |
|
2414 | ui.status(xlist[1] % rel) | |
2415 | for table, hitlist, misslist, backuphit, backupmiss in disptable: |
|
2415 | for table, hitlist, misslist, backuphit, backupmiss in disptable: | |
2416 | if abs not in table: continue |
|
2416 | if abs not in table: continue | |
2417 | # file has changed in dirstate |
|
2417 | # file has changed in dirstate | |
2418 | if in_mf: |
|
2418 | if in_mf: | |
2419 | handle(hitlist, backuphit) |
|
2419 | handle(hitlist, backuphit) | |
2420 | elif misslist is not None: |
|
2420 | elif misslist is not None: | |
2421 | handle(misslist, backupmiss) |
|
2421 | handle(misslist, backupmiss) | |
2422 | else: |
|
2422 | else: | |
2423 | if exact: ui.warn(_('file not managed: %s\n' % rel)) |
|
2423 | if exact: ui.warn(_('file not managed: %s\n' % rel)) | |
2424 | break |
|
2424 | break | |
2425 | else: |
|
2425 | else: | |
2426 | # file has not changed in dirstate |
|
2426 | # file has not changed in dirstate | |
2427 | if node == parent: |
|
2427 | if node == parent: | |
2428 | if exact: ui.warn(_('no changes needed to %s\n' % rel)) |
|
2428 | if exact: ui.warn(_('no changes needed to %s\n' % rel)) | |
2429 | continue |
|
2429 | continue | |
2430 | if not in_mf: |
|
2430 | if not in_mf: | |
2431 | handle(remove, False) |
|
2431 | handle(remove, False) | |
2432 | update[abs] = True |
|
2432 | update[abs] = True | |
2433 |
|
2433 | |||
2434 | repo.dirstate.forget(forget[0]) |
|
2434 | repo.dirstate.forget(forget[0]) | |
2435 | r = repo.update(node, False, True, update.has_key, False, wlock=wlock) |
|
2435 | r = repo.update(node, False, True, update.has_key, False, wlock=wlock) | |
2436 | repo.dirstate.update(add[0], 'a') |
|
2436 | repo.dirstate.update(add[0], 'a') | |
2437 | repo.dirstate.update(undelete[0], 'n') |
|
2437 | repo.dirstate.update(undelete[0], 'n') | |
2438 | repo.dirstate.update(remove[0], 'r') |
|
2438 | repo.dirstate.update(remove[0], 'r') | |
2439 | return r |
|
2439 | return r | |
2440 |
|
2440 | |||
2441 | def root(ui, repo): |
|
2441 | def root(ui, repo): | |
2442 | """print the root (top) of the current working dir |
|
2442 | """print the root (top) of the current working dir | |
2443 |
|
2443 | |||
2444 | Print the root directory of the current repository. |
|
2444 | Print the root directory of the current repository. | |
2445 | """ |
|
2445 | """ | |
2446 | ui.write(repo.root + "\n") |
|
2446 | ui.write(repo.root + "\n") | |
2447 |
|
2447 | |||
2448 | def serve(ui, repo, **opts): |
|
2448 | def serve(ui, repo, **opts): | |
2449 | """export the repository via HTTP |
|
2449 | """export the repository via HTTP | |
2450 |
|
2450 | |||
2451 | Start a local HTTP repository browser and pull server. |
|
2451 | Start a local HTTP repository browser and pull server. | |
2452 |
|
2452 | |||
2453 | By default, the server logs accesses to stdout and errors to |
|
2453 | By default, the server logs accesses to stdout and errors to | |
2454 | stderr. Use the "-A" and "-E" options to log to files. |
|
2454 | stderr. Use the "-A" and "-E" options to log to files. | |
2455 | """ |
|
2455 | """ | |
2456 |
|
2456 | |||
2457 | if opts["stdio"]: |
|
2457 | if opts["stdio"]: | |
2458 | fin, fout = sys.stdin, sys.stdout |
|
2458 | fin, fout = sys.stdin, sys.stdout | |
2459 | sys.stdout = sys.stderr |
|
2459 | sys.stdout = sys.stderr | |
2460 |
|
2460 | |||
2461 | # Prevent insertion/deletion of CRs |
|
2461 | # Prevent insertion/deletion of CRs | |
2462 | util.set_binary(fin) |
|
2462 | util.set_binary(fin) | |
2463 | util.set_binary(fout) |
|
2463 | util.set_binary(fout) | |
2464 |
|
2464 | |||
2465 | def getarg(): |
|
2465 | def getarg(): | |
2466 | argline = fin.readline()[:-1] |
|
2466 | argline = fin.readline()[:-1] | |
2467 | arg, l = argline.split() |
|
2467 | arg, l = argline.split() | |
2468 | val = fin.read(int(l)) |
|
2468 | val = fin.read(int(l)) | |
2469 | return arg, val |
|
2469 | return arg, val | |
2470 | def respond(v): |
|
2470 | def respond(v): | |
2471 | fout.write("%d\n" % len(v)) |
|
2471 | fout.write("%d\n" % len(v)) | |
2472 | fout.write(v) |
|
2472 | fout.write(v) | |
2473 | fout.flush() |
|
2473 | fout.flush() | |
2474 |
|
2474 | |||
2475 | lock = None |
|
2475 | lock = None | |
2476 |
|
2476 | |||
2477 | while 1: |
|
2477 | while 1: | |
2478 | cmd = fin.readline()[:-1] |
|
2478 | cmd = fin.readline()[:-1] | |
2479 | if cmd == '': |
|
2479 | if cmd == '': | |
2480 | return |
|
2480 | return | |
2481 | if cmd == "heads": |
|
2481 | if cmd == "heads": | |
2482 | h = repo.heads() |
|
2482 | h = repo.heads() | |
2483 | respond(" ".join(map(hex, h)) + "\n") |
|
2483 | respond(" ".join(map(hex, h)) + "\n") | |
2484 | if cmd == "lock": |
|
2484 | if cmd == "lock": | |
2485 | lock = repo.lock() |
|
2485 | lock = repo.lock() | |
2486 | respond("") |
|
2486 | respond("") | |
2487 | if cmd == "unlock": |
|
2487 | if cmd == "unlock": | |
2488 | if lock: |
|
2488 | if lock: | |
2489 | lock.release() |
|
2489 | lock.release() | |
2490 | lock = None |
|
2490 | lock = None | |
2491 | respond("") |
|
2491 | respond("") | |
2492 | elif cmd == "branches": |
|
2492 | elif cmd == "branches": | |
2493 | arg, nodes = getarg() |
|
2493 | arg, nodes = getarg() | |
2494 | nodes = map(bin, nodes.split(" ")) |
|
2494 | nodes = map(bin, nodes.split(" ")) | |
2495 | r = [] |
|
2495 | r = [] | |
2496 | for b in repo.branches(nodes): |
|
2496 | for b in repo.branches(nodes): | |
2497 | r.append(" ".join(map(hex, b)) + "\n") |
|
2497 | r.append(" ".join(map(hex, b)) + "\n") | |
2498 | respond("".join(r)) |
|
2498 | respond("".join(r)) | |
2499 | elif cmd == "between": |
|
2499 | elif cmd == "between": | |
2500 | arg, pairs = getarg() |
|
2500 | arg, pairs = getarg() | |
2501 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] |
|
2501 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] | |
2502 | r = [] |
|
2502 | r = [] | |
2503 | for b in repo.between(pairs): |
|
2503 | for b in repo.between(pairs): | |
2504 | r.append(" ".join(map(hex, b)) + "\n") |
|
2504 | r.append(" ".join(map(hex, b)) + "\n") | |
2505 | respond("".join(r)) |
|
2505 | respond("".join(r)) | |
2506 | elif cmd == "changegroup": |
|
2506 | elif cmd == "changegroup": | |
2507 | nodes = [] |
|
2507 | nodes = [] | |
2508 | arg, roots = getarg() |
|
2508 | arg, roots = getarg() | |
2509 | nodes = map(bin, roots.split(" ")) |
|
2509 | nodes = map(bin, roots.split(" ")) | |
2510 |
|
2510 | |||
2511 | cg = repo.changegroup(nodes, 'serve') |
|
2511 | cg = repo.changegroup(nodes, 'serve') | |
2512 | while 1: |
|
2512 | while 1: | |
2513 | d = cg.read(4096) |
|
2513 | d = cg.read(4096) | |
2514 | if not d: |
|
2514 | if not d: | |
2515 | break |
|
2515 | break | |
2516 | fout.write(d) |
|
2516 | fout.write(d) | |
2517 |
|
2517 | |||
2518 | fout.flush() |
|
2518 | fout.flush() | |
2519 |
|
2519 | |||
2520 | elif cmd == "addchangegroup": |
|
2520 | elif cmd == "addchangegroup": | |
2521 | if not lock: |
|
2521 | if not lock: | |
2522 | respond("not locked") |
|
2522 | respond("not locked") | |
2523 | continue |
|
2523 | continue | |
2524 | respond("") |
|
2524 | respond("") | |
2525 |
|
2525 | |||
2526 | r = repo.addchangegroup(fin) |
|
2526 | r = repo.addchangegroup(fin) | |
2527 | respond(str(r)) |
|
2527 | respond(str(r)) | |
2528 |
|
2528 | |||
2529 | optlist = "name templates style address port ipv6 accesslog errorlog" |
|
2529 | optlist = "name templates style address port ipv6 accesslog errorlog" | |
2530 | for o in optlist.split(): |
|
2530 | for o in optlist.split(): | |
2531 | if opts[o]: |
|
2531 | if opts[o]: | |
2532 | ui.setconfig("web", o, opts[o]) |
|
2532 | ui.setconfig("web", o, opts[o]) | |
2533 |
|
2533 | |||
2534 | if opts['daemon'] and not opts['daemon_pipefds']: |
|
2534 | if opts['daemon'] and not opts['daemon_pipefds']: | |
2535 | rfd, wfd = os.pipe() |
|
2535 | rfd, wfd = os.pipe() | |
2536 | args = sys.argv[:] |
|
2536 | args = sys.argv[:] | |
2537 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) |
|
2537 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) | |
2538 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), |
|
2538 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), | |
2539 | args[0], args) |
|
2539 | args[0], args) | |
2540 | os.close(wfd) |
|
2540 | os.close(wfd) | |
2541 | os.read(rfd, 1) |
|
2541 | os.read(rfd, 1) | |
2542 | os._exit(0) |
|
2542 | os._exit(0) | |
2543 |
|
2543 | |||
2544 | try: |
|
2544 | try: | |
2545 | httpd = hgweb.create_server(repo) |
|
2545 | httpd = hgweb.create_server(repo) | |
2546 | except socket.error, inst: |
|
2546 | except socket.error, inst: | |
2547 | raise util.Abort(_('cannot start server: ') + inst.args[1]) |
|
2547 | raise util.Abort(_('cannot start server: ') + inst.args[1]) | |
2548 |
|
2548 | |||
2549 | if ui.verbose: |
|
2549 | if ui.verbose: | |
2550 | addr, port = httpd.socket.getsockname() |
|
2550 | addr, port = httpd.socket.getsockname() | |
2551 | if addr == '0.0.0.0': |
|
2551 | if addr == '0.0.0.0': | |
2552 | addr = socket.gethostname() |
|
2552 | addr = socket.gethostname() | |
2553 | else: |
|
2553 | else: | |
2554 | try: |
|
2554 | try: | |
2555 | addr = socket.gethostbyaddr(addr)[0] |
|
2555 | addr = socket.gethostbyaddr(addr)[0] | |
2556 | except socket.error: |
|
2556 | except socket.error: | |
2557 | pass |
|
2557 | pass | |
2558 | if port != 80: |
|
2558 | if port != 80: | |
2559 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) |
|
2559 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) | |
2560 | else: |
|
2560 | else: | |
2561 | ui.status(_('listening at http://%s/\n') % addr) |
|
2561 | ui.status(_('listening at http://%s/\n') % addr) | |
2562 |
|
2562 | |||
2563 | if opts['pid_file']: |
|
2563 | if opts['pid_file']: | |
2564 | fp = open(opts['pid_file'], 'w') |
|
2564 | fp = open(opts['pid_file'], 'w') | |
2565 | fp.write(str(os.getpid())) |
|
2565 | fp.write(str(os.getpid())) | |
2566 | fp.close() |
|
2566 | fp.close() | |
2567 |
|
2567 | |||
2568 | if opts['daemon_pipefds']: |
|
2568 | if opts['daemon_pipefds']: | |
2569 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] |
|
2569 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] | |
2570 | os.close(rfd) |
|
2570 | os.close(rfd) | |
2571 | os.write(wfd, 'y') |
|
2571 | os.write(wfd, 'y') | |
2572 | os.close(wfd) |
|
2572 | os.close(wfd) | |
2573 | sys.stdout.flush() |
|
2573 | sys.stdout.flush() | |
2574 | sys.stderr.flush() |
|
2574 | sys.stderr.flush() | |
2575 | fd = os.open(util.nulldev, os.O_RDWR) |
|
2575 | fd = os.open(util.nulldev, os.O_RDWR) | |
2576 | if fd != 0: os.dup2(fd, 0) |
|
2576 | if fd != 0: os.dup2(fd, 0) | |
2577 | if fd != 1: os.dup2(fd, 1) |
|
2577 | if fd != 1: os.dup2(fd, 1) | |
2578 | if fd != 2: os.dup2(fd, 2) |
|
2578 | if fd != 2: os.dup2(fd, 2) | |
2579 | if fd not in (0, 1, 2): os.close(fd) |
|
2579 | if fd not in (0, 1, 2): os.close(fd) | |
2580 |
|
2580 | |||
2581 | httpd.serve_forever() |
|
2581 | httpd.serve_forever() | |
2582 |
|
2582 | |||
2583 | def status(ui, repo, *pats, **opts): |
|
2583 | def status(ui, repo, *pats, **opts): | |
2584 | """show changed files in the working directory |
|
2584 | """show changed files in the working directory | |
2585 |
|
2585 | |||
2586 | Show changed files in the repository. If names are |
|
2586 | Show changed files in the repository. If names are | |
2587 | given, only files that match are shown. |
|
2587 | given, only files that match are shown. | |
2588 |
|
2588 | |||
2589 | The codes used to show the status of files are: |
|
2589 | The codes used to show the status of files are: | |
2590 | M = modified |
|
2590 | M = modified | |
2591 | A = added |
|
2591 | A = added | |
2592 | R = removed |
|
2592 | R = removed | |
2593 | ! = deleted, but still tracked |
|
2593 | ! = deleted, but still tracked | |
2594 | ? = not tracked |
|
2594 | ? = not tracked | |
2595 | I = ignored (not shown by default) |
|
2595 | I = ignored (not shown by default) | |
2596 | """ |
|
2596 | """ | |
2597 |
|
2597 | |||
2598 | show_ignored = opts['ignored'] and True or False |
|
2598 | show_ignored = opts['ignored'] and True or False | |
2599 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
2599 | files, matchfn, anypats = matchpats(repo, pats, opts) | |
2600 | cwd = (pats and repo.getcwd()) or '' |
|
2600 | cwd = (pats and repo.getcwd()) or '' | |
2601 | modified, added, removed, deleted, unknown, ignored = [ |
|
2601 | modified, added, removed, deleted, unknown, ignored = [ | |
2602 | [util.pathto(cwd, x) for x in n] |
|
2602 | [util.pathto(cwd, x) for x in n] | |
2603 | for n in repo.changes(files=files, match=matchfn, |
|
2603 | for n in repo.changes(files=files, match=matchfn, | |
2604 | show_ignored=show_ignored)] |
|
2604 | show_ignored=show_ignored)] | |
2605 |
|
2605 | |||
2606 | changetypes = [('modified', 'M', modified), |
|
2606 | changetypes = [('modified', 'M', modified), | |
2607 | ('added', 'A', added), |
|
2607 | ('added', 'A', added), | |
2608 | ('removed', 'R', removed), |
|
2608 | ('removed', 'R', removed), | |
2609 | ('deleted', '!', deleted), |
|
2609 | ('deleted', '!', deleted), | |
2610 | ('unknown', '?', unknown), |
|
2610 | ('unknown', '?', unknown), | |
2611 | ('ignored', 'I', ignored)] |
|
2611 | ('ignored', 'I', ignored)] | |
2612 |
|
2612 | |||
2613 | end = opts['print0'] and '\0' or '\n' |
|
2613 | end = opts['print0'] and '\0' or '\n' | |
2614 |
|
2614 | |||
2615 | for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]] |
|
2615 | for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]] | |
2616 | or changetypes): |
|
2616 | or changetypes): | |
2617 | if opts['no_status']: |
|
2617 | if opts['no_status']: | |
2618 | format = "%%s%s" % end |
|
2618 | format = "%%s%s" % end | |
2619 | else: |
|
2619 | else: | |
2620 | format = "%s %%s%s" % (char, end) |
|
2620 | format = "%s %%s%s" % (char, end) | |
2621 |
|
2621 | |||
2622 | for f in changes: |
|
2622 | for f in changes: | |
2623 | ui.write(format % f) |
|
2623 | ui.write(format % f) | |
2624 |
|
2624 | |||
2625 | def tag(ui, repo, name, rev_=None, **opts): |
|
2625 | def tag(ui, repo, name, rev_=None, **opts): | |
2626 | """add a tag for the current tip or a given revision |
|
2626 | """add a tag for the current tip or a given revision | |
2627 |
|
2627 | |||
2628 | Name a particular revision using <name>. |
|
2628 | Name a particular revision using <name>. | |
2629 |
|
2629 | |||
2630 | Tags are used to name particular revisions of the repository and are |
|
2630 | Tags are used to name particular revisions of the repository and are | |
2631 | very useful to compare different revision, to go back to significant |
|
2631 | very useful to compare different revision, to go back to significant | |
2632 | earlier versions or to mark branch points as releases, etc. |
|
2632 | earlier versions or to mark branch points as releases, etc. | |
2633 |
|
2633 | |||
2634 | If no revision is given, the tip is used. |
|
2634 | If no revision is given, the tip is used. | |
2635 |
|
2635 | |||
2636 | To facilitate version control, distribution, and merging of tags, |
|
2636 | To facilitate version control, distribution, and merging of tags, | |
2637 | they are stored as a file named ".hgtags" which is managed |
|
2637 | they are stored as a file named ".hgtags" which is managed | |
2638 | similarly to other project files and can be hand-edited if |
|
2638 | similarly to other project files and can be hand-edited if | |
2639 | necessary. The file '.hg/localtags' is used for local tags (not |
|
2639 | necessary. The file '.hg/localtags' is used for local tags (not | |
2640 | shared among repositories). |
|
2640 | shared among repositories). | |
2641 | """ |
|
2641 | """ | |
2642 | if name == "tip": |
|
2642 | if name == "tip": | |
2643 | raise util.Abort(_("the name 'tip' is reserved")) |
|
2643 | raise util.Abort(_("the name 'tip' is reserved")) | |
2644 | if rev_ is not None: |
|
2644 | if rev_ is not None: | |
2645 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " |
|
2645 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " | |
2646 | "please use 'hg tag [-r REV] NAME' instead\n")) |
|
2646 | "please use 'hg tag [-r REV] NAME' instead\n")) | |
2647 | if opts['rev']: |
|
2647 | if opts['rev']: | |
2648 | raise util.Abort(_("use only one form to specify the revision")) |
|
2648 | raise util.Abort(_("use only one form to specify the revision")) | |
2649 | if opts['rev']: |
|
2649 | if opts['rev']: | |
2650 | rev_ = opts['rev'] |
|
2650 | rev_ = opts['rev'] | |
2651 | if rev_: |
|
2651 | if rev_: | |
2652 | r = hex(repo.lookup(rev_)) |
|
2652 | r = hex(repo.lookup(rev_)) | |
2653 | else: |
|
2653 | else: | |
2654 | r = hex(repo.changelog.tip()) |
|
2654 | r = hex(repo.changelog.tip()) | |
2655 |
|
2655 | |||
2656 | disallowed = (revrangesep, '\r', '\n') |
|
2656 | disallowed = (revrangesep, '\r', '\n') | |
2657 | for c in disallowed: |
|
2657 | for c in disallowed: | |
2658 | if name.find(c) >= 0: |
|
2658 | if name.find(c) >= 0: | |
2659 | raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) |
|
2659 | raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) | |
2660 |
|
2660 | |||
2661 | repo.hook('pretag', throw=True, node=r, tag=name, |
|
2661 | repo.hook('pretag', throw=True, node=r, tag=name, | |
2662 | local=int(not not opts['local'])) |
|
2662 | local=int(not not opts['local'])) | |
2663 |
|
2663 | |||
2664 | if opts['local']: |
|
2664 | if opts['local']: | |
2665 | repo.opener("localtags", "a").write("%s %s\n" % (r, name)) |
|
2665 | repo.opener("localtags", "a").write("%s %s\n" % (r, name)) | |
2666 | repo.hook('tag', node=r, tag=name, local=1) |
|
2666 | repo.hook('tag', node=r, tag=name, local=1) | |
2667 | return |
|
2667 | return | |
2668 |
|
2668 | |||
2669 | for x in repo.changes(): |
|
2669 | for x in repo.changes(): | |
2670 | if ".hgtags" in x: |
|
2670 | if ".hgtags" in x: | |
2671 | raise util.Abort(_("working copy of .hgtags is changed " |
|
2671 | raise util.Abort(_("working copy of .hgtags is changed " | |
2672 | "(please commit .hgtags manually)")) |
|
2672 | "(please commit .hgtags manually)")) | |
2673 |
|
2673 | |||
2674 | repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name)) |
|
2674 | repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name)) | |
2675 | if repo.dirstate.state(".hgtags") == '?': |
|
2675 | if repo.dirstate.state(".hgtags") == '?': | |
2676 | repo.add([".hgtags"]) |
|
2676 | repo.add([".hgtags"]) | |
2677 |
|
2677 | |||
2678 | message = (opts['message'] or |
|
2678 | message = (opts['message'] or | |
2679 | _("Added tag %s for changeset %s") % (name, r)) |
|
2679 | _("Added tag %s for changeset %s") % (name, r)) | |
2680 | try: |
|
2680 | try: | |
2681 | repo.commit([".hgtags"], message, opts['user'], opts['date']) |
|
2681 | repo.commit([".hgtags"], message, opts['user'], opts['date']) | |
2682 | repo.hook('tag', node=r, tag=name, local=0) |
|
2682 | repo.hook('tag', node=r, tag=name, local=0) | |
2683 | except ValueError, inst: |
|
2683 | except ValueError, inst: | |
2684 | raise util.Abort(str(inst)) |
|
2684 | raise util.Abort(str(inst)) | |
2685 |
|
2685 | |||
2686 | def tags(ui, repo): |
|
2686 | def tags(ui, repo): | |
2687 | """list repository tags |
|
2687 | """list repository tags | |
2688 |
|
2688 | |||
2689 | List the repository tags. |
|
2689 | List the repository tags. | |
2690 |
|
2690 | |||
2691 | This lists both regular and local tags. |
|
2691 | This lists both regular and local tags. | |
2692 | """ |
|
2692 | """ | |
2693 |
|
2693 | |||
2694 | l = repo.tagslist() |
|
2694 | l = repo.tagslist() | |
2695 | l.reverse() |
|
2695 | l.reverse() | |
2696 | for t, n in l: |
|
2696 | for t, n in l: | |
2697 | try: |
|
2697 | try: | |
2698 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) |
|
2698 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) | |
2699 | except KeyError: |
|
2699 | except KeyError: | |
2700 | r = " ?:?" |
|
2700 | r = " ?:?" | |
2701 | if ui.quiet: |
|
2701 | if ui.quiet: | |
2702 | ui.write("%s\n" % t) |
|
2702 | ui.write("%s\n" % t) | |
2703 | else: |
|
2703 | else: | |
2704 | ui.write("%-30s %s\n" % (t, r)) |
|
2704 | ui.write("%-30s %s\n" % (t, r)) | |
2705 |
|
2705 | |||
2706 | def tip(ui, repo, **opts): |
|
2706 | def tip(ui, repo, **opts): | |
2707 | """show the tip revision |
|
2707 | """show the tip revision | |
2708 |
|
2708 | |||
2709 | Show the tip revision. |
|
2709 | Show the tip revision. | |
2710 | """ |
|
2710 | """ | |
2711 | n = repo.changelog.tip() |
|
2711 | n = repo.changelog.tip() | |
2712 | br = None |
|
2712 | br = None | |
2713 | if opts['branches']: |
|
2713 | if opts['branches']: | |
2714 | br = repo.branchlookup([n]) |
|
2714 | br = repo.branchlookup([n]) | |
2715 | show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) |
|
2715 | show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) | |
2716 | if opts['patch']: |
|
2716 | if opts['patch']: | |
2717 | dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n) |
|
2717 | dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n) | |
2718 |
|
2718 | |||
2719 | def unbundle(ui, repo, fname, **opts): |
|
2719 | def unbundle(ui, repo, fname, **opts): | |
2720 | """apply a changegroup file |
|
2720 | """apply a changegroup file | |
2721 |
|
2721 | |||
2722 | Apply a compressed changegroup file generated by the bundle |
|
2722 | Apply a compressed changegroup file generated by the bundle | |
2723 | command. |
|
2723 | command. | |
2724 | """ |
|
2724 | """ | |
2725 | f = urllib.urlopen(fname) |
|
2725 | f = urllib.urlopen(fname) | |
2726 |
|
2726 | |||
2727 | header = f.read(6) |
|
2727 | header = f.read(6) | |
2728 | if not header.startswith("HG"): |
|
2728 | if not header.startswith("HG"): | |
2729 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) |
|
2729 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) | |
2730 | elif not header.startswith("HG10"): |
|
2730 | elif not header.startswith("HG10"): | |
2731 | raise util.Abort(_("%s: unknown bundle version") % fname) |
|
2731 | raise util.Abort(_("%s: unknown bundle version") % fname) | |
2732 | elif header == "HG10BZ": |
|
2732 | elif header == "HG10BZ": | |
2733 | def generator(f): |
|
2733 | def generator(f): | |
2734 | zd = bz2.BZ2Decompressor() |
|
2734 | zd = bz2.BZ2Decompressor() | |
2735 | zd.decompress("BZ") |
|
2735 | zd.decompress("BZ") | |
2736 | for chunk in f: |
|
2736 | for chunk in f: | |
2737 | yield zd.decompress(chunk) |
|
2737 | yield zd.decompress(chunk) | |
2738 | elif header == "HG10UN": |
|
2738 | elif header == "HG10UN": | |
2739 | def generator(f): |
|
2739 | def generator(f): | |
2740 | for chunk in f: |
|
2740 | for chunk in f: | |
2741 | yield chunk |
|
2741 | yield chunk | |
2742 | else: |
|
2742 | else: | |
2743 | raise util.Abort(_("%s: unknown bundle compression type") |
|
2743 | raise util.Abort(_("%s: unknown bundle compression type") | |
2744 | % fname) |
|
2744 | % fname) | |
2745 | gen = generator(util.filechunkiter(f, 4096)) |
|
2745 | gen = generator(util.filechunkiter(f, 4096)) | |
2746 | modheads = repo.addchangegroup(util.chunkbuffer(gen)) |
|
2746 | modheads = repo.addchangegroup(util.chunkbuffer(gen)) | |
2747 | return postincoming(ui, repo, modheads, opts['update']) |
|
2747 | return postincoming(ui, repo, modheads, opts['update']) | |
2748 |
|
2748 | |||
2749 | def undo(ui, repo): |
|
2749 | def undo(ui, repo): | |
2750 | """undo the last commit or pull |
|
2750 | """undo the last commit or pull | |
2751 |
|
2751 | |||
2752 | Roll back the last pull or commit transaction on the |
|
2752 | Roll back the last pull or commit transaction on the | |
2753 | repository, restoring the project to its earlier state. |
|
2753 | repository, restoring the project to its earlier state. | |
2754 |
|
2754 | |||
2755 | This command should be used with care. There is only one level of |
|
2755 | This command should be used with care. There is only one level of | |
2756 | undo and there is no redo. |
|
2756 | undo and there is no redo. | |
2757 |
|
2757 | |||
2758 | This command is not intended for use on public repositories. Once |
|
2758 | This command is not intended for use on public repositories. Once | |
2759 | a change is visible for pull by other users, undoing it locally is |
|
2759 | a change is visible for pull by other users, undoing it locally is | |
2760 | ineffective. Furthemore a race is possible with readers of the |
|
2760 | ineffective. Furthemore a race is possible with readers of the | |
2761 | repository, for example an ongoing pull from the repository will |
|
2761 | repository, for example an ongoing pull from the repository will | |
2762 | fail and rollback. |
|
2762 | fail and rollback. | |
2763 | """ |
|
2763 | """ | |
2764 | repo.undo() |
|
2764 | repo.undo() | |
2765 |
|
2765 | |||
2766 | def update(ui, repo, node=None, merge=False, clean=False, force=None, |
|
2766 | def update(ui, repo, node=None, merge=False, clean=False, force=None, | |
2767 | branch=None, **opts): |
|
2767 | branch=None, **opts): | |
2768 | """update or merge working directory |
|
2768 | """update or merge working directory | |
2769 |
|
2769 | |||
2770 | Update the working directory to the specified revision. |
|
2770 | Update the working directory to the specified revision. | |
2771 |
|
2771 | |||
2772 | If there are no outstanding changes in the working directory and |
|
2772 | If there are no outstanding changes in the working directory and | |
2773 | there is a linear relationship between the current version and the |
|
2773 | there is a linear relationship between the current version and the | |
2774 | requested version, the result is the requested version. |
|
2774 | requested version, the result is the requested version. | |
2775 |
|
2775 | |||
2776 | Otherwise the result is a merge between the contents of the |
|
2776 | Otherwise the result is a merge between the contents of the | |
2777 | current working directory and the requested version. Files that |
|
2777 | current working directory and the requested version. Files that | |
2778 | changed between either parent are marked as changed for the next |
|
2778 | changed between either parent are marked as changed for the next | |
2779 | commit and a commit must be performed before any further updates |
|
2779 | commit and a commit must be performed before any further updates | |
2780 | are allowed. |
|
2780 | are allowed. | |
2781 |
|
2781 | |||
2782 | By default, update will refuse to run if doing so would require |
|
2782 | By default, update will refuse to run if doing so would require | |
2783 | merging or discarding local changes. |
|
2783 | merging or discarding local changes. | |
2784 | """ |
|
2784 | """ | |
2785 | if branch: |
|
2785 | if branch: | |
2786 | br = repo.branchlookup(branch=branch) |
|
2786 | br = repo.branchlookup(branch=branch) | |
2787 | found = [] |
|
2787 | found = [] | |
2788 | for x in br: |
|
2788 | for x in br: | |
2789 | if branch in br[x]: |
|
2789 | if branch in br[x]: | |
2790 | found.append(x) |
|
2790 | found.append(x) | |
2791 | if len(found) > 1: |
|
2791 | if len(found) > 1: | |
2792 | ui.warn(_("Found multiple heads for %s\n") % branch) |
|
2792 | ui.warn(_("Found multiple heads for %s\n") % branch) | |
2793 | for x in found: |
|
2793 | for x in found: | |
2794 | show_changeset(ui, repo, opts).show(changenode=x, brinfo=br) |
|
2794 | show_changeset(ui, repo, opts).show(changenode=x, brinfo=br) | |
2795 | return 1 |
|
2795 | return 1 | |
2796 | if len(found) == 1: |
|
2796 | if len(found) == 1: | |
2797 | node = found[0] |
|
2797 | node = found[0] | |
2798 | ui.warn(_("Using head %s for branch %s\n") % (short(node), branch)) |
|
2798 | ui.warn(_("Using head %s for branch %s\n") % (short(node), branch)) | |
2799 | else: |
|
2799 | else: | |
2800 | ui.warn(_("branch %s not found\n") % (branch)) |
|
2800 | ui.warn(_("branch %s not found\n") % (branch)) | |
2801 | return 1 |
|
2801 | return 1 | |
2802 | else: |
|
2802 | else: | |
2803 | node = node and repo.lookup(node) or repo.changelog.tip() |
|
2803 | node = node and repo.lookup(node) or repo.changelog.tip() | |
2804 | return repo.update(node, allow=merge, force=clean, forcemerge=force) |
|
2804 | return repo.update(node, allow=merge, force=clean, forcemerge=force) | |
2805 |
|
2805 | |||
2806 | def verify(ui, repo): |
|
2806 | def verify(ui, repo): | |
2807 | """verify the integrity of the repository |
|
2807 | """verify the integrity of the repository | |
2808 |
|
2808 | |||
2809 | Verify the integrity of the current repository. |
|
2809 | Verify the integrity of the current repository. | |
2810 |
|
2810 | |||
2811 | This will perform an extensive check of the repository's |
|
2811 | This will perform an extensive check of the repository's | |
2812 | integrity, validating the hashes and checksums of each entry in |
|
2812 | integrity, validating the hashes and checksums of each entry in | |
2813 | the changelog, manifest, and tracked files, as well as the |
|
2813 | the changelog, manifest, and tracked files, as well as the | |
2814 | integrity of their crosslinks and indices. |
|
2814 | integrity of their crosslinks and indices. | |
2815 | """ |
|
2815 | """ | |
2816 | return repo.verify() |
|
2816 | return repo.verify() | |
2817 |
|
2817 | |||
2818 | # Command options and aliases are listed here, alphabetically |
|
2818 | # Command options and aliases are listed here, alphabetically | |
2819 |
|
2819 | |||
2820 | table = { |
|
2820 | table = { | |
2821 | "^add": |
|
2821 | "^add": | |
2822 | (add, |
|
2822 | (add, | |
2823 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2823 | [('I', 'include', [], _('include names matching the given patterns')), | |
2824 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2824 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2825 | _('hg add [OPTION]... [FILE]...')), |
|
2825 | _('hg add [OPTION]... [FILE]...')), | |
2826 | "addremove": |
|
2826 | "addremove": | |
2827 | (addremove, |
|
2827 | (addremove, | |
2828 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2828 | [('I', 'include', [], _('include names matching the given patterns')), | |
2829 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2829 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2830 | _('hg addremove [OPTION]... [FILE]...')), |
|
2830 | _('hg addremove [OPTION]... [FILE]...')), | |
2831 | "^annotate": |
|
2831 | "^annotate": | |
2832 | (annotate, |
|
2832 | (annotate, | |
2833 | [('r', 'rev', '', _('annotate the specified revision')), |
|
2833 | [('r', 'rev', '', _('annotate the specified revision')), | |
2834 | ('a', 'text', None, _('treat all files as text')), |
|
2834 | ('a', 'text', None, _('treat all files as text')), | |
2835 | ('u', 'user', None, _('list the author')), |
|
2835 | ('u', 'user', None, _('list the author')), | |
2836 | ('d', 'date', None, _('list the date')), |
|
2836 | ('d', 'date', None, _('list the date')), | |
2837 | ('n', 'number', None, _('list the revision number (default)')), |
|
2837 | ('n', 'number', None, _('list the revision number (default)')), | |
2838 | ('c', 'changeset', None, _('list the changeset')), |
|
2838 | ('c', 'changeset', None, _('list the changeset')), | |
2839 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2839 | ('I', 'include', [], _('include names matching the given patterns')), | |
2840 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2840 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2841 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), |
|
2841 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), | |
2842 | "bundle": |
|
2842 | "bundle": | |
2843 | (bundle, |
|
2843 | (bundle, | |
2844 | [('f', 'force', None, |
|
2844 | [('f', 'force', None, | |
2845 | _('run even when remote repository is unrelated'))], |
|
2845 | _('run even when remote repository is unrelated'))], | |
2846 | _('hg bundle FILE DEST')), |
|
2846 | _('hg bundle FILE DEST')), | |
2847 | "cat": |
|
2847 | "cat": | |
2848 | (cat, |
|
2848 | (cat, | |
2849 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2849 | [('o', 'output', '', _('print output to file with formatted name')), | |
2850 | ('r', 'rev', '', _('print the given revision')), |
|
2850 | ('r', 'rev', '', _('print the given revision')), | |
2851 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2851 | ('I', 'include', [], _('include names matching the given patterns')), | |
2852 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2852 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2853 | _('hg cat [OPTION]... FILE...')), |
|
2853 | _('hg cat [OPTION]... FILE...')), | |
2854 | "^clone": |
|
2854 | "^clone": | |
2855 | (clone, |
|
2855 | (clone, | |
2856 | [('U', 'noupdate', None, _('do not update the new working directory')), |
|
2856 | [('U', 'noupdate', None, _('do not update the new working directory')), | |
2857 | ('r', 'rev', [], |
|
2857 | ('r', 'rev', [], | |
2858 | _('a changeset you would like to have after cloning')), |
|
2858 | _('a changeset you would like to have after cloning')), | |
2859 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
2859 | ('', 'pull', None, _('use pull protocol to copy metadata')), | |
2860 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2860 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2861 | ('', 'remotecmd', '', |
|
2861 | ('', 'remotecmd', '', | |
2862 | _('specify hg command to run on the remote side'))], |
|
2862 | _('specify hg command to run on the remote side'))], | |
2863 | _('hg clone [OPTION]... SOURCE [DEST]')), |
|
2863 | _('hg clone [OPTION]... SOURCE [DEST]')), | |
2864 | "^commit|ci": |
|
2864 | "^commit|ci": | |
2865 | (commit, |
|
2865 | (commit, | |
2866 | [('A', 'addremove', None, _('run addremove during commit')), |
|
2866 | [('A', 'addremove', None, _('run addremove during commit')), | |
2867 | ('m', 'message', '', _('use <text> as commit message')), |
|
2867 | ('m', 'message', '', _('use <text> as commit message')), | |
2868 | ('l', 'logfile', '', _('read the commit message from <file>')), |
|
2868 | ('l', 'logfile', '', _('read the commit message from <file>')), | |
2869 | ('d', 'date', '', _('record datecode as commit date')), |
|
2869 | ('d', 'date', '', _('record datecode as commit date')), | |
2870 | ('u', 'user', '', _('record user as commiter')), |
|
2870 | ('u', 'user', '', _('record user as commiter')), | |
2871 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2871 | ('I', 'include', [], _('include names matching the given patterns')), | |
2872 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2872 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2873 | _('hg commit [OPTION]... [FILE]...')), |
|
2873 | _('hg commit [OPTION]... [FILE]...')), | |
2874 | "copy|cp": |
|
2874 | "copy|cp": | |
2875 | (copy, |
|
2875 | (copy, | |
2876 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
2876 | [('A', 'after', None, _('record a copy that has already occurred')), | |
2877 | ('f', 'force', None, |
|
2877 | ('f', 'force', None, | |
2878 | _('forcibly copy over an existing managed file')), |
|
2878 | _('forcibly copy over an existing managed file')), | |
2879 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2879 | ('I', 'include', [], _('include names matching the given patterns')), | |
2880 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2880 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2881 | _('hg copy [OPTION]... [SOURCE]... DEST')), |
|
2881 | _('hg copy [OPTION]... [SOURCE]... DEST')), | |
2882 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), |
|
2882 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), | |
2883 | "debugcomplete": |
|
2883 | "debugcomplete": | |
2884 | (debugcomplete, |
|
2884 | (debugcomplete, | |
2885 | [('o', 'options', None, _('show the command options'))], |
|
2885 | [('o', 'options', None, _('show the command options'))], | |
2886 | _('debugcomplete [-o] CMD')), |
|
2886 | _('debugcomplete [-o] CMD')), | |
2887 | "debugrebuildstate": |
|
2887 | "debugrebuildstate": | |
2888 | (debugrebuildstate, |
|
2888 | (debugrebuildstate, | |
2889 | [('r', 'rev', '', _('revision to rebuild to'))], |
|
2889 | [('r', 'rev', '', _('revision to rebuild to'))], | |
2890 | _('debugrebuildstate [-r REV] [REV]')), |
|
2890 | _('debugrebuildstate [-r REV] [REV]')), | |
2891 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), |
|
2891 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), | |
2892 | "debugconfig": (debugconfig, [], _('debugconfig')), |
|
2892 | "debugconfig": (debugconfig, [], _('debugconfig')), | |
2893 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), |
|
2893 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), | |
2894 | "debugstate": (debugstate, [], _('debugstate')), |
|
2894 | "debugstate": (debugstate, [], _('debugstate')), | |
2895 | "debugdata": (debugdata, [], _('debugdata FILE REV')), |
|
2895 | "debugdata": (debugdata, [], _('debugdata FILE REV')), | |
2896 | "debugindex": (debugindex, [], _('debugindex FILE')), |
|
2896 | "debugindex": (debugindex, [], _('debugindex FILE')), | |
2897 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), |
|
2897 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), | |
2898 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), |
|
2898 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), | |
2899 | "debugwalk": |
|
2899 | "debugwalk": | |
2900 | (debugwalk, |
|
2900 | (debugwalk, | |
2901 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2901 | [('I', 'include', [], _('include names matching the given patterns')), | |
2902 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2902 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2903 | _('debugwalk [OPTION]... [FILE]...')), |
|
2903 | _('debugwalk [OPTION]... [FILE]...')), | |
2904 | "^diff": |
|
2904 | "^diff": | |
2905 | (diff, |
|
2905 | (diff, | |
2906 | [('r', 'rev', [], _('revision')), |
|
2906 | [('r', 'rev', [], _('revision')), | |
2907 | ('a', 'text', None, _('treat all files as text')), |
|
2907 | ('a', 'text', None, _('treat all files as text')), | |
2908 | ('p', 'show-function', None, |
|
2908 | ('p', 'show-function', None, | |
2909 | _('show which function each change is in')), |
|
2909 | _('show which function each change is in')), | |
2910 | ('w', 'ignore-all-space', None, |
|
2910 | ('w', 'ignore-all-space', None, | |
2911 | _('ignore white space when comparing lines')), |
|
2911 | _('ignore white space when comparing lines')), | |
2912 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2912 | ('I', 'include', [], _('include names matching the given patterns')), | |
2913 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2913 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2914 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), |
|
2914 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), | |
2915 | "^export": |
|
2915 | "^export": | |
2916 | (export, |
|
2916 | (export, | |
2917 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2917 | [('o', 'output', '', _('print output to file with formatted name')), | |
2918 | ('a', 'text', None, _('treat all files as text')), |
|
2918 | ('a', 'text', None, _('treat all files as text')), | |
2919 | ('', 'switch-parent', None, _('diff against the second parent'))], |
|
2919 | ('', 'switch-parent', None, _('diff against the second parent'))], | |
2920 | _('hg export [-a] [-o OUTFILESPEC] REV...')), |
|
2920 | _('hg export [-a] [-o OUTFILESPEC] REV...')), | |
2921 | "forget": |
|
2921 | "forget": | |
2922 | (forget, |
|
2922 | (forget, | |
2923 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2923 | [('I', 'include', [], _('include names matching the given patterns')), | |
2924 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2924 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2925 | _('hg forget [OPTION]... FILE...')), |
|
2925 | _('hg forget [OPTION]... FILE...')), | |
2926 | "grep": |
|
2926 | "grep": | |
2927 | (grep, |
|
2927 | (grep, | |
2928 | [('0', 'print0', None, _('end fields with NUL')), |
|
2928 | [('0', 'print0', None, _('end fields with NUL')), | |
2929 | ('', 'all', None, _('print all revisions that match')), |
|
2929 | ('', 'all', None, _('print all revisions that match')), | |
2930 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
2930 | ('i', 'ignore-case', None, _('ignore case when matching')), | |
2931 | ('l', 'files-with-matches', None, |
|
2931 | ('l', 'files-with-matches', None, | |
2932 | _('print only filenames and revs that match')), |
|
2932 | _('print only filenames and revs that match')), | |
2933 | ('n', 'line-number', None, _('print matching line numbers')), |
|
2933 | ('n', 'line-number', None, _('print matching line numbers')), | |
2934 | ('r', 'rev', [], _('search in given revision range')), |
|
2934 | ('r', 'rev', [], _('search in given revision range')), | |
2935 | ('u', 'user', None, _('print user who committed change')), |
|
2935 | ('u', 'user', None, _('print user who committed change')), | |
2936 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2936 | ('I', 'include', [], _('include names matching the given patterns')), | |
2937 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2937 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2938 | _('hg grep [OPTION]... PATTERN [FILE]...')), |
|
2938 | _('hg grep [OPTION]... PATTERN [FILE]...')), | |
2939 | "heads": |
|
2939 | "heads": | |
2940 | (heads, |
|
2940 | (heads, | |
2941 | [('b', 'branches', None, _('show branches')), |
|
2941 | [('b', 'branches', None, _('show branches')), | |
2942 | ('', 'style', '', _('display using template map file')), |
|
2942 | ('', 'style', '', _('display using template map file')), | |
2943 | ('r', 'rev', '', _('show only heads which are descendants of rev')), |
|
2943 | ('r', 'rev', '', _('show only heads which are descendants of rev')), | |
2944 | ('', 'template', '', _('display with template'))], |
|
2944 | ('', 'template', '', _('display with template'))], | |
2945 | _('hg heads [-b] [-r <rev>]')), |
|
2945 | _('hg heads [-b] [-r <rev>]')), | |
2946 | "help": (help_, [], _('hg help [COMMAND]')), |
|
2946 | "help": (help_, [], _('hg help [COMMAND]')), | |
2947 | "identify|id": (identify, [], _('hg identify')), |
|
2947 | "identify|id": (identify, [], _('hg identify')), | |
2948 | "import|patch": |
|
2948 | "import|patch": | |
2949 | (import_, |
|
2949 | (import_, | |
2950 | [('p', 'strip', 1, |
|
2950 | [('p', 'strip', 1, | |
2951 | _('directory strip option for patch. This has the same\n') + |
|
2951 | _('directory strip option for patch. This has the same\n') + | |
2952 | _('meaning as the corresponding patch option')), |
|
2952 | _('meaning as the corresponding patch option')), | |
2953 | ('b', 'base', '', _('base path')), |
|
2953 | ('b', 'base', '', _('base path')), | |
2954 | ('f', 'force', None, |
|
2954 | ('f', 'force', None, | |
2955 | _('skip check for outstanding uncommitted changes'))], |
|
2955 | _('skip check for outstanding uncommitted changes'))], | |
2956 | _('hg import [-p NUM] [-b BASE] [-f] PATCH...')), |
|
2956 | _('hg import [-p NUM] [-b BASE] [-f] PATCH...')), | |
2957 | "incoming|in": (incoming, |
|
2957 | "incoming|in": (incoming, | |
2958 | [('M', 'no-merges', None, _('do not show merges')), |
|
2958 | [('M', 'no-merges', None, _('do not show merges')), | |
2959 | ('f', 'force', None, |
|
2959 | ('f', 'force', None, | |
2960 | _('run even when remote repository is unrelated')), |
|
2960 | _('run even when remote repository is unrelated')), | |
2961 | ('', 'style', '', _('display using template map file')), |
|
2961 | ('', 'style', '', _('display using template map file')), | |
2962 | ('n', 'newest-first', None, _('show newest record first')), |
|
2962 | ('n', 'newest-first', None, _('show newest record first')), | |
2963 | ('', 'bundle', '', _('file to store the bundles into')), |
|
2963 | ('', 'bundle', '', _('file to store the bundles into')), | |
2964 | ('p', 'patch', None, _('show patch')), |
|
2964 | ('p', 'patch', None, _('show patch')), | |
2965 | ('', 'template', '', _('display with template')), |
|
2965 | ('', 'template', '', _('display with template')), | |
2966 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2966 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2967 | ('', 'remotecmd', '', |
|
2967 | ('', 'remotecmd', '', | |
2968 | _('specify hg command to run on the remote side'))], |
|
2968 | _('specify hg command to run on the remote side'))], | |
2969 | _('hg incoming [-p] [-n] [-M] [--bundle FILENAME] [SOURCE]')), |
|
2969 | _('hg incoming [-p] [-n] [-M] [--bundle FILENAME] [SOURCE]')), | |
2970 | "^init": (init, [], _('hg init [DEST]')), |
|
2970 | "^init": (init, [], _('hg init [DEST]')), | |
2971 | "locate": |
|
2971 | "locate": | |
2972 | (locate, |
|
2972 | (locate, | |
2973 | [('r', 'rev', '', _('search the repository as it stood at rev')), |
|
2973 | [('r', 'rev', '', _('search the repository as it stood at rev')), | |
2974 | ('0', 'print0', None, |
|
2974 | ('0', 'print0', None, | |
2975 | _('end filenames with NUL, for use with xargs')), |
|
2975 | _('end filenames with NUL, for use with xargs')), | |
2976 | ('f', 'fullpath', None, |
|
2976 | ('f', 'fullpath', None, | |
2977 | _('print complete paths from the filesystem root')), |
|
2977 | _('print complete paths from the filesystem root')), | |
2978 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2978 | ('I', 'include', [], _('include names matching the given patterns')), | |
2979 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2979 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2980 | _('hg locate [OPTION]... [PATTERN]...')), |
|
2980 | _('hg locate [OPTION]... [PATTERN]...')), | |
2981 | "^log|history": |
|
2981 | "^log|history": | |
2982 | (log, |
|
2982 | (log, | |
2983 | [('b', 'branches', None, _('show branches')), |
|
2983 | [('b', 'branches', None, _('show branches')), | |
2984 | ('k', 'keyword', [], _('search for a keyword')), |
|
2984 | ('k', 'keyword', [], _('search for a keyword')), | |
2985 | ('l', 'limit', '', _('limit number of changes displayed')), |
|
2985 | ('l', 'limit', '', _('limit number of changes displayed')), | |
2986 | ('r', 'rev', [], _('show the specified revision or range')), |
|
2986 | ('r', 'rev', [], _('show the specified revision or range')), | |
2987 | ('M', 'no-merges', None, _('do not show merges')), |
|
2987 | ('M', 'no-merges', None, _('do not show merges')), | |
2988 | ('', 'style', '', _('display using template map file')), |
|
2988 | ('', 'style', '', _('display using template map file')), | |
2989 | ('m', 'only-merges', None, _('show only merges')), |
|
2989 | ('m', 'only-merges', None, _('show only merges')), | |
2990 | ('p', 'patch', None, _('show patch')), |
|
2990 | ('p', 'patch', None, _('show patch')), | |
2991 | ('', 'template', '', _('display with template')), |
|
2991 | ('', 'template', '', _('display with template')), | |
2992 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2992 | ('I', 'include', [], _('include names matching the given patterns')), | |
2993 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2993 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2994 | _('hg log [OPTION]... [FILE]')), |
|
2994 | _('hg log [OPTION]... [FILE]')), | |
2995 | "manifest": (manifest, [], _('hg manifest [REV]')), |
|
2995 | "manifest": (manifest, [], _('hg manifest [REV]')), | |
2996 | "merge": |
|
2996 | "merge": | |
2997 | (merge, |
|
2997 | (merge, | |
2998 | [('b', 'branch', '', _('merge with head of a specific branch')), |
|
2998 | [('b', 'branch', '', _('merge with head of a specific branch')), | |
2999 | ('f', 'force', None, _('force a merge with outstanding changes'))], |
|
2999 | ('f', 'force', None, _('force a merge with outstanding changes'))], | |
3000 | _('hg merge [-b TAG] [-f] [REV]')), |
|
3000 | _('hg merge [-b TAG] [-f] [REV]')), | |
3001 | "outgoing|out": (outgoing, |
|
3001 | "outgoing|out": (outgoing, | |
3002 | [('M', 'no-merges', None, _('do not show merges')), |
|
3002 | [('M', 'no-merges', None, _('do not show merges')), | |
3003 | ('f', 'force', None, |
|
3003 | ('f', 'force', None, | |
3004 | _('run even when remote repository is unrelated')), |
|
3004 | _('run even when remote repository is unrelated')), | |
3005 | ('p', 'patch', None, _('show patch')), |
|
3005 | ('p', 'patch', None, _('show patch')), | |
3006 | ('', 'style', '', _('display using template map file')), |
|
3006 | ('', 'style', '', _('display using template map file')), | |
3007 | ('n', 'newest-first', None, _('show newest record first')), |
|
3007 | ('n', 'newest-first', None, _('show newest record first')), | |
3008 | ('', 'template', '', _('display with template')), |
|
3008 | ('', 'template', '', _('display with template')), | |
3009 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3009 | ('e', 'ssh', '', _('specify ssh command to use')), | |
3010 | ('', 'remotecmd', '', |
|
3010 | ('', 'remotecmd', '', | |
3011 | _('specify hg command to run on the remote side'))], |
|
3011 | _('specify hg command to run on the remote side'))], | |
3012 | _('hg outgoing [-M] [-p] [-n] [DEST]')), |
|
3012 | _('hg outgoing [-M] [-p] [-n] [DEST]')), | |
3013 | "^parents": |
|
3013 | "^parents": | |
3014 | (parents, |
|
3014 | (parents, | |
3015 | [('b', 'branches', None, _('show branches')), |
|
3015 | [('b', 'branches', None, _('show branches')), | |
3016 | ('', 'style', '', _('display using template map file')), |
|
3016 | ('', 'style', '', _('display using template map file')), | |
3017 | ('', 'template', '', _('display with template'))], |
|
3017 | ('', 'template', '', _('display with template'))], | |
3018 | _('hg parents [-b] [REV]')), |
|
3018 | _('hg parents [-b] [REV]')), | |
3019 | "paths": (paths, [], _('hg paths [NAME]')), |
|
3019 | "paths": (paths, [], _('hg paths [NAME]')), | |
3020 | "^pull": |
|
3020 | "^pull": | |
3021 | (pull, |
|
3021 | (pull, | |
3022 | [('u', 'update', None, |
|
3022 | [('u', 'update', None, | |
3023 | _('update the working directory to tip after pull')), |
|
3023 | _('update the working directory to tip after pull')), | |
3024 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3024 | ('e', 'ssh', '', _('specify ssh command to use')), | |
3025 | ('f', 'force', None, |
|
3025 | ('f', 'force', None, | |
3026 | _('run even when remote repository is unrelated')), |
|
3026 | _('run even when remote repository is unrelated')), | |
3027 | ('r', 'rev', [], _('a specific revision you would like to pull')), |
|
3027 | ('r', 'rev', [], _('a specific revision you would like to pull')), | |
3028 | ('', 'remotecmd', '', |
|
3028 | ('', 'remotecmd', '', | |
3029 | _('specify hg command to run on the remote side'))], |
|
3029 | _('specify hg command to run on the remote side'))], | |
3030 | _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')), |
|
3030 | _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')), | |
3031 | "^push": |
|
3031 | "^push": | |
3032 | (push, |
|
3032 | (push, | |
3033 | [('f', 'force', None, _('force push')), |
|
3033 | [('f', 'force', None, _('force push')), | |
3034 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3034 | ('e', 'ssh', '', _('specify ssh command to use')), | |
3035 | ('r', 'rev', [], _('a specific revision you would like to push')), |
|
3035 | ('r', 'rev', [], _('a specific revision you would like to push')), | |
3036 | ('', 'remotecmd', '', |
|
3036 | ('', 'remotecmd', '', | |
3037 | _('specify hg command to run on the remote side'))], |
|
3037 | _('specify hg command to run on the remote side'))], | |
3038 | _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')), |
|
3038 | _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')), | |
3039 | "debugrawcommit|rawcommit": |
|
3039 | "debugrawcommit|rawcommit": | |
3040 | (rawcommit, |
|
3040 | (rawcommit, | |
3041 | [('p', 'parent', [], _('parent')), |
|
3041 | [('p', 'parent', [], _('parent')), | |
3042 | ('d', 'date', '', _('date code')), |
|
3042 | ('d', 'date', '', _('date code')), | |
3043 | ('u', 'user', '', _('user')), |
|
3043 | ('u', 'user', '', _('user')), | |
3044 | ('F', 'files', '', _('file list')), |
|
3044 | ('F', 'files', '', _('file list')), | |
3045 | ('m', 'message', '', _('commit message')), |
|
3045 | ('m', 'message', '', _('commit message')), | |
3046 | ('l', 'logfile', '', _('commit message file'))], |
|
3046 | ('l', 'logfile', '', _('commit message file'))], | |
3047 | _('hg debugrawcommit [OPTION]... [FILE]...')), |
|
3047 | _('hg debugrawcommit [OPTION]... [FILE]...')), | |
3048 | "recover": (recover, [], _('hg recover')), |
|
3048 | "recover": (recover, [], _('hg recover')), | |
3049 | "^remove|rm": |
|
3049 | "^remove|rm": | |
3050 | (remove, |
|
3050 | (remove, | |
3051 | [('f', 'force', None, _('remove file even if modified')), |
|
3051 | [('f', 'force', None, _('remove file even if modified')), | |
3052 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3052 | ('I', 'include', [], _('include names matching the given patterns')), | |
3053 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3053 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
3054 | _('hg remove [OPTION]... FILE...')), |
|
3054 | _('hg remove [OPTION]... FILE...')), | |
3055 | "rename|mv": |
|
3055 | "rename|mv": | |
3056 | (rename, |
|
3056 | (rename, | |
3057 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
3057 | [('A', 'after', None, _('record a rename that has already occurred')), | |
3058 | ('f', 'force', None, |
|
3058 | ('f', 'force', None, | |
3059 | _('forcibly copy over an existing managed file')), |
|
3059 | _('forcibly copy over an existing managed file')), | |
3060 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3060 | ('I', 'include', [], _('include names matching the given patterns')), | |
3061 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3061 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
3062 | _('hg rename [OPTION]... SOURCE... DEST')), |
|
3062 | _('hg rename [OPTION]... SOURCE... DEST')), | |
3063 | "^revert": |
|
3063 | "^revert": | |
3064 | (revert, |
|
3064 | (revert, | |
3065 | [('r', 'rev', '', _('revision to revert to')), |
|
3065 | [('r', 'rev', '', _('revision to revert to')), | |
3066 | ('', 'no-backup', None, _('do not save backup copies of files')), |
|
3066 | ('', 'no-backup', None, _('do not save backup copies of files')), | |
3067 | ('I', 'include', [], _('include names matching given patterns')), |
|
3067 | ('I', 'include', [], _('include names matching given patterns')), | |
3068 | ('X', 'exclude', [], _('exclude names matching given patterns'))], |
|
3068 | ('X', 'exclude', [], _('exclude names matching given patterns'))], | |
3069 | _('hg revert [-r REV] [NAME]...')), |
|
3069 | _('hg revert [-r REV] [NAME]...')), | |
3070 | "root": (root, [], _('hg root')), |
|
3070 | "root": (root, [], _('hg root')), | |
3071 | "^serve": |
|
3071 | "^serve": | |
3072 | (serve, |
|
3072 | (serve, | |
3073 | [('A', 'accesslog', '', _('name of access log file to write to')), |
|
3073 | [('A', 'accesslog', '', _('name of access log file to write to')), | |
3074 | ('d', 'daemon', None, _('run server in background')), |
|
3074 | ('d', 'daemon', None, _('run server in background')), | |
3075 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
3075 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | |
3076 | ('E', 'errorlog', '', _('name of error log file to write to')), |
|
3076 | ('E', 'errorlog', '', _('name of error log file to write to')), | |
3077 | ('p', 'port', 0, _('port to use (default: 8000)')), |
|
3077 | ('p', 'port', 0, _('port to use (default: 8000)')), | |
3078 | ('a', 'address', '', _('address to use')), |
|
3078 | ('a', 'address', '', _('address to use')), | |
3079 | ('n', 'name', '', |
|
3079 | ('n', 'name', '', | |
3080 | _('name to show in web pages (default: working dir)')), |
|
3080 | _('name to show in web pages (default: working dir)')), | |
3081 | ('', 'pid-file', '', _('name of file to write process ID to')), |
|
3081 | ('', 'pid-file', '', _('name of file to write process ID to')), | |
3082 | ('', 'stdio', None, _('for remote clients')), |
|
3082 | ('', 'stdio', None, _('for remote clients')), | |
3083 | ('t', 'templates', '', _('web templates to use')), |
|
3083 | ('t', 'templates', '', _('web templates to use')), | |
3084 | ('', 'style', '', _('template style to use')), |
|
3084 | ('', 'style', '', _('template style to use')), | |
3085 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], |
|
3085 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], | |
3086 | _('hg serve [OPTION]...')), |
|
3086 | _('hg serve [OPTION]...')), | |
3087 | "^status|st": |
|
3087 | "^status|st": | |
3088 | (status, |
|
3088 | (status, | |
3089 | [('m', 'modified', None, _('show only modified files')), |
|
3089 | [('m', 'modified', None, _('show only modified files')), | |
3090 | ('a', 'added', None, _('show only added files')), |
|
3090 | ('a', 'added', None, _('show only added files')), | |
3091 | ('r', 'removed', None, _('show only removed files')), |
|
3091 | ('r', 'removed', None, _('show only removed files')), | |
3092 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
3092 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), | |
3093 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
3093 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), | |
3094 | ('i', 'ignored', None, _('show ignored files')), |
|
3094 | ('i', 'ignored', None, _('show ignored files')), | |
3095 | ('n', 'no-status', None, _('hide status prefix')), |
|
3095 | ('n', 'no-status', None, _('hide status prefix')), | |
3096 | ('0', 'print0', None, |
|
3096 | ('0', 'print0', None, | |
3097 | _('end filenames with NUL, for use with xargs')), |
|
3097 | _('end filenames with NUL, for use with xargs')), | |
3098 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3098 | ('I', 'include', [], _('include names matching the given patterns')), | |
3099 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3099 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
3100 | _('hg status [OPTION]... [FILE]...')), |
|
3100 | _('hg status [OPTION]... [FILE]...')), | |
3101 | "tag": |
|
3101 | "tag": | |
3102 | (tag, |
|
3102 | (tag, | |
3103 | [('l', 'local', None, _('make the tag local')), |
|
3103 | [('l', 'local', None, _('make the tag local')), | |
3104 | ('m', 'message', '', _('message for tag commit log entry')), |
|
3104 | ('m', 'message', '', _('message for tag commit log entry')), | |
3105 | ('d', 'date', '', _('record datecode as commit date')), |
|
3105 | ('d', 'date', '', _('record datecode as commit date')), | |
3106 | ('u', 'user', '', _('record user as commiter')), |
|
3106 | ('u', 'user', '', _('record user as commiter')), | |
3107 | ('r', 'rev', '', _('revision to tag'))], |
|
3107 | ('r', 'rev', '', _('revision to tag'))], | |
3108 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), |
|
3108 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), | |
3109 | "tags": (tags, [], _('hg tags')), |
|
3109 | "tags": (tags, [], _('hg tags')), | |
3110 | "tip": |
|
3110 | "tip": | |
3111 | (tip, |
|
3111 | (tip, | |
3112 | [('b', 'branches', None, _('show branches')), |
|
3112 | [('b', 'branches', None, _('show branches')), | |
3113 | ('', 'style', '', _('display using template map file')), |
|
3113 | ('', 'style', '', _('display using template map file')), | |
3114 | ('p', 'patch', None, _('show patch')), |
|
3114 | ('p', 'patch', None, _('show patch')), | |
3115 | ('', 'template', '', _('display with template'))], |
|
3115 | ('', 'template', '', _('display with template'))], | |
3116 | _('hg tip [-b] [-p]')), |
|
3116 | _('hg tip [-b] [-p]')), | |
3117 | "unbundle": |
|
3117 | "unbundle": | |
3118 | (unbundle, |
|
3118 | (unbundle, | |
3119 | [('u', 'update', None, |
|
3119 | [('u', 'update', None, | |
3120 | _('update the working directory to tip after unbundle'))], |
|
3120 | _('update the working directory to tip after unbundle'))], | |
3121 | _('hg unbundle [-u] FILE')), |
|
3121 | _('hg unbundle [-u] FILE')), | |
3122 | "undo": (undo, [], _('hg undo')), |
|
3122 | "undo": (undo, [], _('hg undo')), | |
3123 | "^update|up|checkout|co": |
|
3123 | "^update|up|checkout|co": | |
3124 | (update, |
|
3124 | (update, | |
3125 | [('b', 'branch', '', _('checkout the head of a specific branch')), |
|
3125 | [('b', 'branch', '', _('checkout the head of a specific branch')), | |
3126 | ('m', 'merge', None, _('allow merging of branches')), |
|
3126 | ('m', 'merge', None, _('allow merging of branches')), | |
3127 | ('C', 'clean', None, _('overwrite locally modified files')), |
|
3127 | ('C', 'clean', None, _('overwrite locally modified files')), | |
3128 | ('f', 'force', None, _('force a merge with outstanding changes'))], |
|
3128 | ('f', 'force', None, _('force a merge with outstanding changes'))], | |
3129 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), |
|
3129 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), | |
3130 | "verify": (verify, [], _('hg verify')), |
|
3130 | "verify": (verify, [], _('hg verify')), | |
3131 | "version": (show_version, [], _('hg version')), |
|
3131 | "version": (show_version, [], _('hg version')), | |
3132 | } |
|
3132 | } | |
3133 |
|
3133 | |||
3134 | globalopts = [ |
|
3134 | globalopts = [ | |
3135 | ('R', 'repository', '', |
|
3135 | ('R', 'repository', '', | |
3136 | _('repository root directory or symbolic path name')), |
|
3136 | _('repository root directory or symbolic path name')), | |
3137 | ('', 'cwd', '', _('change working directory')), |
|
3137 | ('', 'cwd', '', _('change working directory')), | |
3138 | ('y', 'noninteractive', None, |
|
3138 | ('y', 'noninteractive', None, | |
3139 | _('do not prompt, assume \'yes\' for any required answers')), |
|
3139 | _('do not prompt, assume \'yes\' for any required answers')), | |
3140 | ('q', 'quiet', None, _('suppress output')), |
|
3140 | ('q', 'quiet', None, _('suppress output')), | |
3141 | ('v', 'verbose', None, _('enable additional output')), |
|
3141 | ('v', 'verbose', None, _('enable additional output')), | |
3142 | ('', 'debug', None, _('enable debugging output')), |
|
3142 | ('', 'debug', None, _('enable debugging output')), | |
3143 | ('', 'debugger', None, _('start debugger')), |
|
3143 | ('', 'debugger', None, _('start debugger')), | |
3144 | ('', 'traceback', None, _('print traceback on exception')), |
|
3144 | ('', 'traceback', None, _('print traceback on exception')), | |
3145 | ('', 'time', None, _('time how long the command takes')), |
|
3145 | ('', 'time', None, _('time how long the command takes')), | |
3146 | ('', 'profile', None, _('print command execution profile')), |
|
3146 | ('', 'profile', None, _('print command execution profile')), | |
3147 | ('', 'version', None, _('output version information and exit')), |
|
3147 | ('', 'version', None, _('output version information and exit')), | |
3148 | ('h', 'help', None, _('display help and exit')), |
|
3148 | ('h', 'help', None, _('display help and exit')), | |
3149 | ] |
|
3149 | ] | |
3150 |
|
3150 | |||
3151 | norepo = ("clone init version help debugancestor debugcomplete debugdata" |
|
3151 | norepo = ("clone init version help debugancestor debugcomplete debugdata" | |
3152 | " debugindex debugindexdot") |
|
3152 | " debugindex debugindexdot") | |
3153 | optionalrepo = ("paths debugconfig") |
|
3153 | optionalrepo = ("paths debugconfig") | |
3154 |
|
3154 | |||
3155 | def findpossible(cmd): |
|
3155 | def findpossible(cmd): | |
3156 | """ |
|
3156 | """ | |
3157 | Return cmd -> (aliases, command table entry) |
|
3157 | Return cmd -> (aliases, command table entry) | |
3158 | for each matching command. |
|
3158 | for each matching command. | |
3159 | Return debug commands (or their aliases) only if no normal command matches. |
|
3159 | Return debug commands (or their aliases) only if no normal command matches. | |
3160 | """ |
|
3160 | """ | |
3161 | choice = {} |
|
3161 | choice = {} | |
3162 | debugchoice = {} |
|
3162 | debugchoice = {} | |
3163 | for e in table.keys(): |
|
3163 | for e in table.keys(): | |
3164 | aliases = e.lstrip("^").split("|") |
|
3164 | aliases = e.lstrip("^").split("|") | |
3165 | found = None |
|
3165 | found = None | |
3166 | if cmd in aliases: |
|
3166 | if cmd in aliases: | |
3167 | found = cmd |
|
3167 | found = cmd | |
3168 | else: |
|
3168 | else: | |
3169 | for a in aliases: |
|
3169 | for a in aliases: | |
3170 | if a.startswith(cmd): |
|
3170 | if a.startswith(cmd): | |
3171 | found = a |
|
3171 | found = a | |
3172 | break |
|
3172 | break | |
3173 | if found is not None: |
|
3173 | if found is not None: | |
3174 | if aliases[0].startswith("debug"): |
|
3174 | if aliases[0].startswith("debug"): | |
3175 | debugchoice[found] = (aliases, table[e]) |
|
3175 | debugchoice[found] = (aliases, table[e]) | |
3176 | else: |
|
3176 | else: | |
3177 | choice[found] = (aliases, table[e]) |
|
3177 | choice[found] = (aliases, table[e]) | |
3178 |
|
3178 | |||
3179 | if not choice and debugchoice: |
|
3179 | if not choice and debugchoice: | |
3180 | choice = debugchoice |
|
3180 | choice = debugchoice | |
3181 |
|
3181 | |||
3182 | return choice |
|
3182 | return choice | |
3183 |
|
3183 | |||
3184 | def find(cmd): |
|
3184 | def find(cmd): | |
3185 | """Return (aliases, command table entry) for command string.""" |
|
3185 | """Return (aliases, command table entry) for command string.""" | |
3186 | choice = findpossible(cmd) |
|
3186 | choice = findpossible(cmd) | |
3187 |
|
3187 | |||
3188 | if choice.has_key(cmd): |
|
3188 | if choice.has_key(cmd): | |
3189 | return choice[cmd] |
|
3189 | return choice[cmd] | |
3190 |
|
3190 | |||
3191 | if len(choice) > 1: |
|
3191 | if len(choice) > 1: | |
3192 | clist = choice.keys() |
|
3192 | clist = choice.keys() | |
3193 | clist.sort() |
|
3193 | clist.sort() | |
3194 | raise AmbiguousCommand(cmd, clist) |
|
3194 | raise AmbiguousCommand(cmd, clist) | |
3195 |
|
3195 | |||
3196 | if choice: |
|
3196 | if choice: | |
3197 | return choice.values()[0] |
|
3197 | return choice.values()[0] | |
3198 |
|
3198 | |||
3199 | raise UnknownCommand(cmd) |
|
3199 | raise UnknownCommand(cmd) | |
3200 |
|
3200 | |||
3201 | class SignalInterrupt(Exception): |
|
3201 | class SignalInterrupt(Exception): | |
3202 | """Exception raised on SIGTERM and SIGHUP.""" |
|
3202 | """Exception raised on SIGTERM and SIGHUP.""" | |
3203 |
|
3203 | |||
3204 | def catchterm(*args): |
|
3204 | def catchterm(*args): | |
3205 | raise SignalInterrupt |
|
3205 | raise SignalInterrupt | |
3206 |
|
3206 | |||
3207 | def run(): |
|
3207 | def run(): | |
3208 | sys.exit(dispatch(sys.argv[1:])) |
|
3208 | sys.exit(dispatch(sys.argv[1:])) | |
3209 |
|
3209 | |||
3210 | class ParseError(Exception): |
|
3210 | class ParseError(Exception): | |
3211 | """Exception raised on errors in parsing the command line.""" |
|
3211 | """Exception raised on errors in parsing the command line.""" | |
3212 |
|
3212 | |||
3213 | def parse(ui, args): |
|
3213 | def parse(ui, args): | |
3214 | options = {} |
|
3214 | options = {} | |
3215 | cmdoptions = {} |
|
3215 | cmdoptions = {} | |
3216 |
|
3216 | |||
3217 | try: |
|
3217 | try: | |
3218 | args = fancyopts.fancyopts(args, globalopts, options) |
|
3218 | args = fancyopts.fancyopts(args, globalopts, options) | |
3219 | except fancyopts.getopt.GetoptError, inst: |
|
3219 | except fancyopts.getopt.GetoptError, inst: | |
3220 | raise ParseError(None, inst) |
|
3220 | raise ParseError(None, inst) | |
3221 |
|
3221 | |||
3222 | if args: |
|
3222 | if args: | |
3223 | cmd, args = args[0], args[1:] |
|
3223 | cmd, args = args[0], args[1:] | |
3224 | aliases, i = find(cmd) |
|
3224 | aliases, i = find(cmd) | |
3225 | cmd = aliases[0] |
|
3225 | cmd = aliases[0] | |
3226 | defaults = ui.config("defaults", cmd) |
|
3226 | defaults = ui.config("defaults", cmd) | |
3227 | if defaults: |
|
3227 | if defaults: | |
3228 | args = defaults.split() + args |
|
3228 | args = defaults.split() + args | |
3229 | c = list(i[1]) |
|
3229 | c = list(i[1]) | |
3230 | else: |
|
3230 | else: | |
3231 | cmd = None |
|
3231 | cmd = None | |
3232 | c = [] |
|
3232 | c = [] | |
3233 |
|
3233 | |||
3234 | # combine global options into local |
|
3234 | # combine global options into local | |
3235 | for o in globalopts: |
|
3235 | for o in globalopts: | |
3236 | c.append((o[0], o[1], options[o[1]], o[3])) |
|
3236 | c.append((o[0], o[1], options[o[1]], o[3])) | |
3237 |
|
3237 | |||
3238 | try: |
|
3238 | try: | |
3239 | args = fancyopts.fancyopts(args, c, cmdoptions) |
|
3239 | args = fancyopts.fancyopts(args, c, cmdoptions) | |
3240 | except fancyopts.getopt.GetoptError, inst: |
|
3240 | except fancyopts.getopt.GetoptError, inst: | |
3241 | raise ParseError(cmd, inst) |
|
3241 | raise ParseError(cmd, inst) | |
3242 |
|
3242 | |||
3243 | # separate global options back out |
|
3243 | # separate global options back out | |
3244 | for o in globalopts: |
|
3244 | for o in globalopts: | |
3245 | n = o[1] |
|
3245 | n = o[1] | |
3246 | options[n] = cmdoptions[n] |
|
3246 | options[n] = cmdoptions[n] | |
3247 | del cmdoptions[n] |
|
3247 | del cmdoptions[n] | |
3248 |
|
3248 | |||
3249 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) |
|
3249 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) | |
3250 |
|
3250 | |||
3251 | def dispatch(args): |
|
3251 | def dispatch(args): | |
3252 | signal.signal(signal.SIGTERM, catchterm) |
|
3252 | for name in 'SIGTERM', 'SIGHUP', 'SIGBREAK': | |
3253 | try: |
|
3253 | num = getattr(signal, name, None) | |
3254 |
signal.signal( |
|
3254 | if num: signal.signal(num, catchterm) | |
3255 | except AttributeError: |
|
|||
3256 | pass |
|
|||
3257 |
|
3255 | |||
3258 | try: |
|
3256 | try: | |
3259 | u = ui.ui() |
|
3257 | u = ui.ui() | |
3260 | except util.Abort, inst: |
|
3258 | except util.Abort, inst: | |
3261 | sys.stderr.write(_("abort: %s\n") % inst) |
|
3259 | sys.stderr.write(_("abort: %s\n") % inst) | |
3262 | return -1 |
|
3260 | return -1 | |
3263 |
|
3261 | |||
3264 | external = [] |
|
3262 | external = [] | |
3265 | for x in u.extensions(): |
|
3263 | for x in u.extensions(): | |
3266 | try: |
|
3264 | try: | |
3267 | if x[1]: |
|
3265 | if x[1]: | |
3268 | mod = imp.load_source(x[0], x[1]) |
|
3266 | mod = imp.load_source(x[0], x[1]) | |
3269 | else: |
|
3267 | else: | |
3270 | def importh(name): |
|
3268 | def importh(name): | |
3271 | mod = __import__(name) |
|
3269 | mod = __import__(name) | |
3272 | components = name.split('.') |
|
3270 | components = name.split('.') | |
3273 | for comp in components[1:]: |
|
3271 | for comp in components[1:]: | |
3274 | mod = getattr(mod, comp) |
|
3272 | mod = getattr(mod, comp) | |
3275 | return mod |
|
3273 | return mod | |
3276 | try: |
|
3274 | try: | |
3277 | mod = importh("hgext." + x[0]) |
|
3275 | mod = importh("hgext." + x[0]) | |
3278 | except ImportError: |
|
3276 | except ImportError: | |
3279 | mod = importh(x[0]) |
|
3277 | mod = importh(x[0]) | |
3280 | external.append(mod) |
|
3278 | external.append(mod) | |
3281 | except Exception, inst: |
|
3279 | except Exception, inst: | |
3282 | u.warn(_("*** failed to import extension %s: %s\n") % (x[0], inst)) |
|
3280 | u.warn(_("*** failed to import extension %s: %s\n") % (x[0], inst)) | |
3283 | if "--traceback" in sys.argv[1:]: |
|
3281 | if "--traceback" in sys.argv[1:]: | |
3284 | traceback.print_exc() |
|
3282 | traceback.print_exc() | |
3285 | return 1 |
|
3283 | return 1 | |
3286 | continue |
|
3284 | continue | |
3287 |
|
3285 | |||
3288 | for x in external: |
|
3286 | for x in external: | |
3289 | cmdtable = getattr(x, 'cmdtable', {}) |
|
3287 | cmdtable = getattr(x, 'cmdtable', {}) | |
3290 | for t in cmdtable: |
|
3288 | for t in cmdtable: | |
3291 | if t in table: |
|
3289 | if t in table: | |
3292 | u.warn(_("module %s overrides %s\n") % (x.__name__, t)) |
|
3290 | u.warn(_("module %s overrides %s\n") % (x.__name__, t)) | |
3293 | table.update(cmdtable) |
|
3291 | table.update(cmdtable) | |
3294 |
|
3292 | |||
3295 | try: |
|
3293 | try: | |
3296 | cmd, func, args, options, cmdoptions = parse(u, args) |
|
3294 | cmd, func, args, options, cmdoptions = parse(u, args) | |
3297 | if options["time"]: |
|
3295 | if options["time"]: | |
3298 | def get_times(): |
|
3296 | def get_times(): | |
3299 | t = os.times() |
|
3297 | t = os.times() | |
3300 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() |
|
3298 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() | |
3301 | t = (t[0], t[1], t[2], t[3], time.clock()) |
|
3299 | t = (t[0], t[1], t[2], t[3], time.clock()) | |
3302 | return t |
|
3300 | return t | |
3303 | s = get_times() |
|
3301 | s = get_times() | |
3304 | def print_time(): |
|
3302 | def print_time(): | |
3305 | t = get_times() |
|
3303 | t = get_times() | |
3306 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % |
|
3304 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % | |
3307 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) |
|
3305 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) | |
3308 | atexit.register(print_time) |
|
3306 | atexit.register(print_time) | |
3309 |
|
3307 | |||
3310 | u.updateopts(options["verbose"], options["debug"], options["quiet"], |
|
3308 | u.updateopts(options["verbose"], options["debug"], options["quiet"], | |
3311 | not options["noninteractive"]) |
|
3309 | not options["noninteractive"]) | |
3312 |
|
3310 | |||
3313 | # enter the debugger before command execution |
|
3311 | # enter the debugger before command execution | |
3314 | if options['debugger']: |
|
3312 | if options['debugger']: | |
3315 | pdb.set_trace() |
|
3313 | pdb.set_trace() | |
3316 |
|
3314 | |||
3317 | try: |
|
3315 | try: | |
3318 | if options['cwd']: |
|
3316 | if options['cwd']: | |
3319 | try: |
|
3317 | try: | |
3320 | os.chdir(options['cwd']) |
|
3318 | os.chdir(options['cwd']) | |
3321 | except OSError, inst: |
|
3319 | except OSError, inst: | |
3322 | raise util.Abort('%s: %s' % |
|
3320 | raise util.Abort('%s: %s' % | |
3323 | (options['cwd'], inst.strerror)) |
|
3321 | (options['cwd'], inst.strerror)) | |
3324 |
|
3322 | |||
3325 | path = u.expandpath(options["repository"]) or "" |
|
3323 | path = u.expandpath(options["repository"]) or "" | |
3326 | repo = path and hg.repository(u, path=path) or None |
|
3324 | repo = path and hg.repository(u, path=path) or None | |
3327 |
|
3325 | |||
3328 | if options['help']: |
|
3326 | if options['help']: | |
3329 | return help_(u, cmd, options['version']) |
|
3327 | return help_(u, cmd, options['version']) | |
3330 | elif options['version']: |
|
3328 | elif options['version']: | |
3331 | return show_version(u) |
|
3329 | return show_version(u) | |
3332 | elif not cmd: |
|
3330 | elif not cmd: | |
3333 | return help_(u, 'shortlist') |
|
3331 | return help_(u, 'shortlist') | |
3334 |
|
3332 | |||
3335 | if cmd not in norepo.split(): |
|
3333 | if cmd not in norepo.split(): | |
3336 | try: |
|
3334 | try: | |
3337 | if not repo: |
|
3335 | if not repo: | |
3338 | repo = hg.repository(u, path=path) |
|
3336 | repo = hg.repository(u, path=path) | |
3339 | u = repo.ui |
|
3337 | u = repo.ui | |
3340 | for x in external: |
|
3338 | for x in external: | |
3341 | if hasattr(x, 'reposetup'): |
|
3339 | if hasattr(x, 'reposetup'): | |
3342 | x.reposetup(u, repo) |
|
3340 | x.reposetup(u, repo) | |
3343 | except hg.RepoError: |
|
3341 | except hg.RepoError: | |
3344 | if cmd not in optionalrepo.split(): |
|
3342 | if cmd not in optionalrepo.split(): | |
3345 | raise |
|
3343 | raise | |
3346 | d = lambda: func(u, repo, *args, **cmdoptions) |
|
3344 | d = lambda: func(u, repo, *args, **cmdoptions) | |
3347 | else: |
|
3345 | else: | |
3348 | d = lambda: func(u, *args, **cmdoptions) |
|
3346 | d = lambda: func(u, *args, **cmdoptions) | |
3349 |
|
3347 | |||
3350 | try: |
|
3348 | try: | |
3351 | if options['profile']: |
|
3349 | if options['profile']: | |
3352 | import hotshot, hotshot.stats |
|
3350 | import hotshot, hotshot.stats | |
3353 | prof = hotshot.Profile("hg.prof") |
|
3351 | prof = hotshot.Profile("hg.prof") | |
3354 | try: |
|
3352 | try: | |
3355 | try: |
|
3353 | try: | |
3356 | return prof.runcall(d) |
|
3354 | return prof.runcall(d) | |
3357 | except: |
|
3355 | except: | |
3358 | try: |
|
3356 | try: | |
3359 | u.warn(_('exception raised - generating ' |
|
3357 | u.warn(_('exception raised - generating ' | |
3360 | 'profile anyway\n')) |
|
3358 | 'profile anyway\n')) | |
3361 | except: |
|
3359 | except: | |
3362 | pass |
|
3360 | pass | |
3363 | raise |
|
3361 | raise | |
3364 | finally: |
|
3362 | finally: | |
3365 | prof.close() |
|
3363 | prof.close() | |
3366 | stats = hotshot.stats.load("hg.prof") |
|
3364 | stats = hotshot.stats.load("hg.prof") | |
3367 | stats.strip_dirs() |
|
3365 | stats.strip_dirs() | |
3368 | stats.sort_stats('time', 'calls') |
|
3366 | stats.sort_stats('time', 'calls') | |
3369 | stats.print_stats(40) |
|
3367 | stats.print_stats(40) | |
3370 | else: |
|
3368 | else: | |
3371 | return d() |
|
3369 | return d() | |
3372 | finally: |
|
3370 | finally: | |
3373 | u.flush() |
|
3371 | u.flush() | |
3374 | except: |
|
3372 | except: | |
3375 | # enter the debugger when we hit an exception |
|
3373 | # enter the debugger when we hit an exception | |
3376 | if options['debugger']: |
|
3374 | if options['debugger']: | |
3377 | pdb.post_mortem(sys.exc_info()[2]) |
|
3375 | pdb.post_mortem(sys.exc_info()[2]) | |
3378 | if options['traceback']: |
|
3376 | if options['traceback']: | |
3379 | traceback.print_exc() |
|
3377 | traceback.print_exc() | |
3380 | raise |
|
3378 | raise | |
3381 | except ParseError, inst: |
|
3379 | except ParseError, inst: | |
3382 | if inst.args[0]: |
|
3380 | if inst.args[0]: | |
3383 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
|
3381 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) | |
3384 | help_(u, inst.args[0]) |
|
3382 | help_(u, inst.args[0]) | |
3385 | else: |
|
3383 | else: | |
3386 | u.warn(_("hg: %s\n") % inst.args[1]) |
|
3384 | u.warn(_("hg: %s\n") % inst.args[1]) | |
3387 | help_(u, 'shortlist') |
|
3385 | help_(u, 'shortlist') | |
3388 | except AmbiguousCommand, inst: |
|
3386 | except AmbiguousCommand, inst: | |
3389 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
|
3387 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | |
3390 | (inst.args[0], " ".join(inst.args[1]))) |
|
3388 | (inst.args[0], " ".join(inst.args[1]))) | |
3391 | except UnknownCommand, inst: |
|
3389 | except UnknownCommand, inst: | |
3392 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
|
3390 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | |
3393 | help_(u, 'shortlist') |
|
3391 | help_(u, 'shortlist') | |
3394 | except hg.RepoError, inst: |
|
3392 | except hg.RepoError, inst: | |
3395 | u.warn(_("abort: "), inst, "!\n") |
|
3393 | u.warn(_("abort: "), inst, "!\n") | |
3396 | except lock.LockHeld, inst: |
|
3394 | except lock.LockHeld, inst: | |
3397 | if inst.errno == errno.ETIMEDOUT: |
|
3395 | if inst.errno == errno.ETIMEDOUT: | |
3398 | reason = _('timed out waiting for lock held by %s') % inst.locker |
|
3396 | reason = _('timed out waiting for lock held by %s') % inst.locker | |
3399 | else: |
|
3397 | else: | |
3400 | reason = _('lock held by %s') % inst.locker |
|
3398 | reason = _('lock held by %s') % inst.locker | |
3401 | u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) |
|
3399 | u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) | |
3402 | except lock.LockUnavailable, inst: |
|
3400 | except lock.LockUnavailable, inst: | |
3403 | u.warn(_("abort: could not lock %s: %s\n") % |
|
3401 | u.warn(_("abort: could not lock %s: %s\n") % | |
3404 | (inst.desc or inst.filename, inst.strerror)) |
|
3402 | (inst.desc or inst.filename, inst.strerror)) | |
3405 | except revlog.RevlogError, inst: |
|
3403 | except revlog.RevlogError, inst: | |
3406 | u.warn(_("abort: "), inst, "!\n") |
|
3404 | u.warn(_("abort: "), inst, "!\n") | |
3407 | except SignalInterrupt: |
|
3405 | except SignalInterrupt: | |
3408 | u.warn(_("killed!\n")) |
|
3406 | u.warn(_("killed!\n")) | |
3409 | except KeyboardInterrupt: |
|
3407 | except KeyboardInterrupt: | |
3410 | try: |
|
3408 | try: | |
3411 | u.warn(_("interrupted!\n")) |
|
3409 | u.warn(_("interrupted!\n")) | |
3412 | except IOError, inst: |
|
3410 | except IOError, inst: | |
3413 | if inst.errno == errno.EPIPE: |
|
3411 | if inst.errno == errno.EPIPE: | |
3414 | if u.debugflag: |
|
3412 | if u.debugflag: | |
3415 | u.warn(_("\nbroken pipe\n")) |
|
3413 | u.warn(_("\nbroken pipe\n")) | |
3416 | else: |
|
3414 | else: | |
3417 | raise |
|
3415 | raise | |
3418 | except IOError, inst: |
|
3416 | except IOError, inst: | |
3419 | if hasattr(inst, "code"): |
|
3417 | if hasattr(inst, "code"): | |
3420 | u.warn(_("abort: %s\n") % inst) |
|
3418 | u.warn(_("abort: %s\n") % inst) | |
3421 | elif hasattr(inst, "reason"): |
|
3419 | elif hasattr(inst, "reason"): | |
3422 | u.warn(_("abort: error: %s\n") % inst.reason[1]) |
|
3420 | u.warn(_("abort: error: %s\n") % inst.reason[1]) | |
3423 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: |
|
3421 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: | |
3424 | if u.debugflag: |
|
3422 | if u.debugflag: | |
3425 | u.warn(_("broken pipe\n")) |
|
3423 | u.warn(_("broken pipe\n")) | |
3426 | elif getattr(inst, "strerror", None): |
|
3424 | elif getattr(inst, "strerror", None): | |
3427 | if getattr(inst, "filename", None): |
|
3425 | if getattr(inst, "filename", None): | |
3428 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) |
|
3426 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) | |
3429 | else: |
|
3427 | else: | |
3430 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3428 | u.warn(_("abort: %s\n") % inst.strerror) | |
3431 | else: |
|
3429 | else: | |
3432 | raise |
|
3430 | raise | |
3433 | except OSError, inst: |
|
3431 | except OSError, inst: | |
3434 | if hasattr(inst, "filename"): |
|
3432 | if hasattr(inst, "filename"): | |
3435 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
|
3433 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) | |
3436 | else: |
|
3434 | else: | |
3437 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3435 | u.warn(_("abort: %s\n") % inst.strerror) | |
3438 | except util.Abort, inst: |
|
3436 | except util.Abort, inst: | |
3439 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') |
|
3437 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') | |
3440 | except TypeError, inst: |
|
3438 | except TypeError, inst: | |
3441 | # was this an argument error? |
|
3439 | # was this an argument error? | |
3442 | tb = traceback.extract_tb(sys.exc_info()[2]) |
|
3440 | tb = traceback.extract_tb(sys.exc_info()[2]) | |
3443 | if len(tb) > 2: # no |
|
3441 | if len(tb) > 2: # no | |
3444 | raise |
|
3442 | raise | |
3445 | u.debug(inst, "\n") |
|
3443 | u.debug(inst, "\n") | |
3446 | u.warn(_("%s: invalid arguments\n") % cmd) |
|
3444 | u.warn(_("%s: invalid arguments\n") % cmd) | |
3447 | help_(u, cmd) |
|
3445 | help_(u, cmd) | |
3448 | except SystemExit, inst: |
|
3446 | except SystemExit, inst: | |
3449 | # Commands shouldn't sys.exit directly, but give a return code. |
|
3447 | # Commands shouldn't sys.exit directly, but give a return code. | |
3450 | # Just in case catch this and and pass exit code to caller. |
|
3448 | # Just in case catch this and and pass exit code to caller. | |
3451 | return inst.code |
|
3449 | return inst.code | |
3452 | except: |
|
3450 | except: | |
3453 | u.warn(_("** unknown exception encountered, details follow\n")) |
|
3451 | u.warn(_("** unknown exception encountered, details follow\n")) | |
3454 | u.warn(_("** report bug details to mercurial@selenic.com\n")) |
|
3452 | u.warn(_("** report bug details to mercurial@selenic.com\n")) | |
3455 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") |
|
3453 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") | |
3456 | % version.get_version()) |
|
3454 | % version.get_version()) | |
3457 | raise |
|
3455 | raise | |
3458 |
|
3456 | |||
3459 | return -1 |
|
3457 | return -1 |
@@ -1,1085 +1,1086 b'' | |||||
1 | # hgweb.py - web interface to a mercurial repository |
|
1 | # hgweb.py - web interface to a mercurial repository | |
2 | # |
|
2 | # | |
3 | # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
|
3 | # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> | |
4 | # Copyright 2005 Matt Mackall <mpm@selenic.com> |
|
4 | # Copyright 2005 Matt Mackall <mpm@selenic.com> | |
5 | # |
|
5 | # | |
6 | # This software may be used and distributed according to the terms |
|
6 | # This software may be used and distributed according to the terms | |
7 | # of the GNU General Public License, incorporated herein by reference. |
|
7 | # of the GNU General Public License, incorporated herein by reference. | |
8 |
|
8 | |||
9 | import os, cgi, sys |
|
9 | import os, cgi, sys | |
10 | import mimetypes |
|
10 | import mimetypes | |
11 | from demandload import demandload |
|
11 | from demandload import demandload | |
12 | demandload(globals(), "mdiff time re socket zlib errno ui hg ConfigParser") |
|
12 | demandload(globals(), "mdiff time re socket zlib errno ui hg ConfigParser") | |
13 | demandload(globals(), "zipfile tempfile StringIO tarfile BaseHTTPServer util") |
|
13 | demandload(globals(), "zipfile tempfile StringIO tarfile BaseHTTPServer util") | |
14 | demandload(globals(), "mimetypes templater") |
|
14 | demandload(globals(), "mimetypes templater") | |
15 | from node import * |
|
15 | from node import * | |
16 | from i18n import gettext as _ |
|
16 | from i18n import gettext as _ | |
17 |
|
17 | |||
18 | def up(p): |
|
18 | def up(p): | |
19 | if p[0] != "/": |
|
19 | if p[0] != "/": | |
20 | p = "/" + p |
|
20 | p = "/" + p | |
21 | if p[-1] == "/": |
|
21 | if p[-1] == "/": | |
22 | p = p[:-1] |
|
22 | p = p[:-1] | |
23 | up = os.path.dirname(p) |
|
23 | up = os.path.dirname(p) | |
24 | if up == "/": |
|
24 | if up == "/": | |
25 | return "/" |
|
25 | return "/" | |
26 | return up + "/" |
|
26 | return up + "/" | |
27 |
|
27 | |||
28 | def get_mtime(repo_path): |
|
28 | def get_mtime(repo_path): | |
29 | hg_path = os.path.join(repo_path, ".hg") |
|
29 | hg_path = os.path.join(repo_path, ".hg") | |
30 | cl_path = os.path.join(hg_path, "00changelog.i") |
|
30 | cl_path = os.path.join(hg_path, "00changelog.i") | |
31 | if os.path.exists(os.path.join(cl_path)): |
|
31 | if os.path.exists(os.path.join(cl_path)): | |
32 | return os.stat(cl_path).st_mtime |
|
32 | return os.stat(cl_path).st_mtime | |
33 | else: |
|
33 | else: | |
34 | return os.stat(hg_path).st_mtime |
|
34 | return os.stat(hg_path).st_mtime | |
35 |
|
35 | |||
36 | def staticfile(directory, fname): |
|
36 | def staticfile(directory, fname): | |
37 | """return a file inside directory with guessed content-type header |
|
37 | """return a file inside directory with guessed content-type header | |
38 |
|
38 | |||
39 | fname always uses '/' as directory separator and isn't allowed to |
|
39 | fname always uses '/' as directory separator and isn't allowed to | |
40 | contain unusual path components. |
|
40 | contain unusual path components. | |
41 | Content-type is guessed using the mimetypes module. |
|
41 | Content-type is guessed using the mimetypes module. | |
42 | Return an empty string if fname is illegal or file not found. |
|
42 | Return an empty string if fname is illegal or file not found. | |
43 |
|
43 | |||
44 | """ |
|
44 | """ | |
45 | parts = fname.split('/') |
|
45 | parts = fname.split('/') | |
46 | path = directory |
|
46 | path = directory | |
47 | for part in parts: |
|
47 | for part in parts: | |
48 | if (part in ('', os.curdir, os.pardir) or |
|
48 | if (part in ('', os.curdir, os.pardir) or | |
49 | os.sep in part or os.altsep is not None and os.altsep in part): |
|
49 | os.sep in part or os.altsep is not None and os.altsep in part): | |
50 | return "" |
|
50 | return "" | |
51 | path = os.path.join(path, part) |
|
51 | path = os.path.join(path, part) | |
52 | try: |
|
52 | try: | |
53 | os.stat(path) |
|
53 | os.stat(path) | |
54 | ct = mimetypes.guess_type(path)[0] or "text/plain" |
|
54 | ct = mimetypes.guess_type(path)[0] or "text/plain" | |
55 | return "Content-type: %s\n\n%s" % (ct, file(path).read()) |
|
55 | return "Content-type: %s\n\n%s" % (ct, file(path).read()) | |
56 | except (TypeError, OSError): |
|
56 | except (TypeError, OSError): | |
57 | # illegal fname or unreadable file |
|
57 | # illegal fname or unreadable file | |
58 | return "" |
|
58 | return "" | |
59 |
|
59 | |||
60 | class hgrequest(object): |
|
60 | class hgrequest(object): | |
61 | def __init__(self, inp=None, out=None, env=None): |
|
61 | def __init__(self, inp=None, out=None, env=None): | |
62 | self.inp = inp or sys.stdin |
|
62 | self.inp = inp or sys.stdin | |
63 | self.out = out or sys.stdout |
|
63 | self.out = out or sys.stdout | |
64 | self.env = env or os.environ |
|
64 | self.env = env or os.environ | |
65 | self.form = cgi.parse(self.inp, self.env, keep_blank_values=1) |
|
65 | self.form = cgi.parse(self.inp, self.env, keep_blank_values=1) | |
66 |
|
66 | |||
67 | def write(self, *things): |
|
67 | def write(self, *things): | |
68 | for thing in things: |
|
68 | for thing in things: | |
69 | if hasattr(thing, "__iter__"): |
|
69 | if hasattr(thing, "__iter__"): | |
70 | for part in thing: |
|
70 | for part in thing: | |
71 | self.write(part) |
|
71 | self.write(part) | |
72 | else: |
|
72 | else: | |
73 | try: |
|
73 | try: | |
74 | self.out.write(str(thing)) |
|
74 | self.out.write(str(thing)) | |
75 | except socket.error, inst: |
|
75 | except socket.error, inst: | |
76 | if inst[0] != errno.ECONNRESET: |
|
76 | if inst[0] != errno.ECONNRESET: | |
77 | raise |
|
77 | raise | |
78 |
|
78 | |||
79 | def header(self, headers=[('Content-type','text/html')]): |
|
79 | def header(self, headers=[('Content-type','text/html')]): | |
80 | for header in headers: |
|
80 | for header in headers: | |
81 | self.out.write("%s: %s\r\n" % header) |
|
81 | self.out.write("%s: %s\r\n" % header) | |
82 | self.out.write("\r\n") |
|
82 | self.out.write("\r\n") | |
83 |
|
83 | |||
84 | def httphdr(self, type, file="", size=0): |
|
84 | def httphdr(self, type, file="", size=0): | |
85 |
|
85 | |||
86 | headers = [('Content-type', type)] |
|
86 | headers = [('Content-type', type)] | |
87 | if file: |
|
87 | if file: | |
88 | headers.append(('Content-disposition', 'attachment; filename=%s' % file)) |
|
88 | headers.append(('Content-disposition', 'attachment; filename=%s' % file)) | |
89 | if size > 0: |
|
89 | if size > 0: | |
90 | headers.append(('Content-length', str(size))) |
|
90 | headers.append(('Content-length', str(size))) | |
91 | self.header(headers) |
|
91 | self.header(headers) | |
92 |
|
92 | |||
93 | class hgweb(object): |
|
93 | class hgweb(object): | |
94 | def __init__(self, repo, name=None): |
|
94 | def __init__(self, repo, name=None): | |
95 | if type(repo) == type(""): |
|
95 | if type(repo) == type(""): | |
96 | self.repo = hg.repository(ui.ui(), repo) |
|
96 | self.repo = hg.repository(ui.ui(), repo) | |
97 | else: |
|
97 | else: | |
98 | self.repo = repo |
|
98 | self.repo = repo | |
99 |
|
99 | |||
100 | self.mtime = -1 |
|
100 | self.mtime = -1 | |
101 | self.reponame = name |
|
101 | self.reponame = name | |
102 | self.archives = 'zip', 'gz', 'bz2' |
|
102 | self.archives = 'zip', 'gz', 'bz2' | |
103 |
|
103 | |||
104 | def refresh(self): |
|
104 | def refresh(self): | |
105 | mtime = get_mtime(self.repo.root) |
|
105 | mtime = get_mtime(self.repo.root) | |
106 | if mtime != self.mtime: |
|
106 | if mtime != self.mtime: | |
107 | self.mtime = mtime |
|
107 | self.mtime = mtime | |
108 | self.repo = hg.repository(self.repo.ui, self.repo.root) |
|
108 | self.repo = hg.repository(self.repo.ui, self.repo.root) | |
109 | self.maxchanges = int(self.repo.ui.config("web", "maxchanges", 10)) |
|
109 | self.maxchanges = int(self.repo.ui.config("web", "maxchanges", 10)) | |
110 | self.maxfiles = int(self.repo.ui.config("web", "maxfiles", 10)) |
|
110 | self.maxfiles = int(self.repo.ui.config("web", "maxfiles", 10)) | |
111 | self.allowpull = self.repo.ui.configbool("web", "allowpull", True) |
|
111 | self.allowpull = self.repo.ui.configbool("web", "allowpull", True) | |
112 |
|
112 | |||
113 | def archivelist(self, nodeid): |
|
113 | def archivelist(self, nodeid): | |
114 | for i in self.archives: |
|
114 | for i in self.archives: | |
115 | if self.repo.ui.configbool("web", "allow" + i, False): |
|
115 | if self.repo.ui.configbool("web", "allow" + i, False): | |
116 | yield {"type" : i, "node" : nodeid} |
|
116 | yield {"type" : i, "node" : nodeid} | |
117 |
|
117 | |||
118 | def listfiles(self, files, mf): |
|
118 | def listfiles(self, files, mf): | |
119 | for f in files[:self.maxfiles]: |
|
119 | for f in files[:self.maxfiles]: | |
120 | yield self.t("filenodelink", node=hex(mf[f]), file=f) |
|
120 | yield self.t("filenodelink", node=hex(mf[f]), file=f) | |
121 | if len(files) > self.maxfiles: |
|
121 | if len(files) > self.maxfiles: | |
122 | yield self.t("fileellipses") |
|
122 | yield self.t("fileellipses") | |
123 |
|
123 | |||
124 | def listfilediffs(self, files, changeset): |
|
124 | def listfilediffs(self, files, changeset): | |
125 | for f in files[:self.maxfiles]: |
|
125 | for f in files[:self.maxfiles]: | |
126 | yield self.t("filedifflink", node=hex(changeset), file=f) |
|
126 | yield self.t("filedifflink", node=hex(changeset), file=f) | |
127 | if len(files) > self.maxfiles: |
|
127 | if len(files) > self.maxfiles: | |
128 | yield self.t("fileellipses") |
|
128 | yield self.t("fileellipses") | |
129 |
|
129 | |||
130 | def siblings(self, siblings=[], rev=None, hiderev=None, **args): |
|
130 | def siblings(self, siblings=[], rev=None, hiderev=None, **args): | |
131 | if not rev: |
|
131 | if not rev: | |
132 | rev = lambda x: "" |
|
132 | rev = lambda x: "" | |
133 | siblings = [s for s in siblings if s != nullid] |
|
133 | siblings = [s for s in siblings if s != nullid] | |
134 | if len(siblings) == 1 and rev(siblings[0]) == hiderev: |
|
134 | if len(siblings) == 1 and rev(siblings[0]) == hiderev: | |
135 | return |
|
135 | return | |
136 | for s in siblings: |
|
136 | for s in siblings: | |
137 | yield dict(node=hex(s), rev=rev(s), **args) |
|
137 | yield dict(node=hex(s), rev=rev(s), **args) | |
138 |
|
138 | |||
139 | def renamelink(self, fl, node): |
|
139 | def renamelink(self, fl, node): | |
140 | r = fl.renamed(node) |
|
140 | r = fl.renamed(node) | |
141 | if r: |
|
141 | if r: | |
142 | return [dict(file=r[0], node=hex(r[1]))] |
|
142 | return [dict(file=r[0], node=hex(r[1]))] | |
143 | return [] |
|
143 | return [] | |
144 |
|
144 | |||
145 | def showtag(self, t1, node=nullid, **args): |
|
145 | def showtag(self, t1, node=nullid, **args): | |
146 | for t in self.repo.nodetags(node): |
|
146 | for t in self.repo.nodetags(node): | |
147 | yield self.t(t1, tag=t, **args) |
|
147 | yield self.t(t1, tag=t, **args) | |
148 |
|
148 | |||
149 | def diff(self, node1, node2, files): |
|
149 | def diff(self, node1, node2, files): | |
150 | def filterfiles(filters, files): |
|
150 | def filterfiles(filters, files): | |
151 | l = [x for x in files if x in filters] |
|
151 | l = [x for x in files if x in filters] | |
152 |
|
152 | |||
153 | for t in filters: |
|
153 | for t in filters: | |
154 | if t and t[-1] != os.sep: |
|
154 | if t and t[-1] != os.sep: | |
155 | t += os.sep |
|
155 | t += os.sep | |
156 | l += [x for x in files if x.startswith(t)] |
|
156 | l += [x for x in files if x.startswith(t)] | |
157 | return l |
|
157 | return l | |
158 |
|
158 | |||
159 | parity = [0] |
|
159 | parity = [0] | |
160 | def diffblock(diff, f, fn): |
|
160 | def diffblock(diff, f, fn): | |
161 | yield self.t("diffblock", |
|
161 | yield self.t("diffblock", | |
162 | lines=prettyprintlines(diff), |
|
162 | lines=prettyprintlines(diff), | |
163 | parity=parity[0], |
|
163 | parity=parity[0], | |
164 | file=f, |
|
164 | file=f, | |
165 | filenode=hex(fn or nullid)) |
|
165 | filenode=hex(fn or nullid)) | |
166 | parity[0] = 1 - parity[0] |
|
166 | parity[0] = 1 - parity[0] | |
167 |
|
167 | |||
168 | def prettyprintlines(diff): |
|
168 | def prettyprintlines(diff): | |
169 | for l in diff.splitlines(1): |
|
169 | for l in diff.splitlines(1): | |
170 | if l.startswith('+'): |
|
170 | if l.startswith('+'): | |
171 | yield self.t("difflineplus", line=l) |
|
171 | yield self.t("difflineplus", line=l) | |
172 | elif l.startswith('-'): |
|
172 | elif l.startswith('-'): | |
173 | yield self.t("difflineminus", line=l) |
|
173 | yield self.t("difflineminus", line=l) | |
174 | elif l.startswith('@'): |
|
174 | elif l.startswith('@'): | |
175 | yield self.t("difflineat", line=l) |
|
175 | yield self.t("difflineat", line=l) | |
176 | else: |
|
176 | else: | |
177 | yield self.t("diffline", line=l) |
|
177 | yield self.t("diffline", line=l) | |
178 |
|
178 | |||
179 | r = self.repo |
|
179 | r = self.repo | |
180 | cl = r.changelog |
|
180 | cl = r.changelog | |
181 | mf = r.manifest |
|
181 | mf = r.manifest | |
182 | change1 = cl.read(node1) |
|
182 | change1 = cl.read(node1) | |
183 | change2 = cl.read(node2) |
|
183 | change2 = cl.read(node2) | |
184 | mmap1 = mf.read(change1[0]) |
|
184 | mmap1 = mf.read(change1[0]) | |
185 | mmap2 = mf.read(change2[0]) |
|
185 | mmap2 = mf.read(change2[0]) | |
186 | date1 = util.datestr(change1[2]) |
|
186 | date1 = util.datestr(change1[2]) | |
187 | date2 = util.datestr(change2[2]) |
|
187 | date2 = util.datestr(change2[2]) | |
188 |
|
188 | |||
189 | modified, added, removed, deleted, unknown = r.changes(node1, node2) |
|
189 | modified, added, removed, deleted, unknown = r.changes(node1, node2) | |
190 | if files: |
|
190 | if files: | |
191 | modified, added, removed = map(lambda x: filterfiles(files, x), |
|
191 | modified, added, removed = map(lambda x: filterfiles(files, x), | |
192 | (modified, added, removed)) |
|
192 | (modified, added, removed)) | |
193 |
|
193 | |||
194 | diffopts = self.repo.ui.diffopts() |
|
194 | diffopts = self.repo.ui.diffopts() | |
195 | showfunc = diffopts['showfunc'] |
|
195 | showfunc = diffopts['showfunc'] | |
196 | ignorews = diffopts['ignorews'] |
|
196 | ignorews = diffopts['ignorews'] | |
197 | for f in modified: |
|
197 | for f in modified: | |
198 | to = r.file(f).read(mmap1[f]) |
|
198 | to = r.file(f).read(mmap1[f]) | |
199 | tn = r.file(f).read(mmap2[f]) |
|
199 | tn = r.file(f).read(mmap2[f]) | |
200 | yield diffblock(mdiff.unidiff(to, date1, tn, date2, f, |
|
200 | yield diffblock(mdiff.unidiff(to, date1, tn, date2, f, | |
201 | showfunc=showfunc, ignorews=ignorews), f, tn) |
|
201 | showfunc=showfunc, ignorews=ignorews), f, tn) | |
202 | for f in added: |
|
202 | for f in added: | |
203 | to = None |
|
203 | to = None | |
204 | tn = r.file(f).read(mmap2[f]) |
|
204 | tn = r.file(f).read(mmap2[f]) | |
205 | yield diffblock(mdiff.unidiff(to, date1, tn, date2, f, |
|
205 | yield diffblock(mdiff.unidiff(to, date1, tn, date2, f, | |
206 | showfunc=showfunc, ignorews=ignorews), f, tn) |
|
206 | showfunc=showfunc, ignorews=ignorews), f, tn) | |
207 | for f in removed: |
|
207 | for f in removed: | |
208 | to = r.file(f).read(mmap1[f]) |
|
208 | to = r.file(f).read(mmap1[f]) | |
209 | tn = None |
|
209 | tn = None | |
210 | yield diffblock(mdiff.unidiff(to, date1, tn, date2, f, |
|
210 | yield diffblock(mdiff.unidiff(to, date1, tn, date2, f, | |
211 | showfunc=showfunc, ignorews=ignorews), f, tn) |
|
211 | showfunc=showfunc, ignorews=ignorews), f, tn) | |
212 |
|
212 | |||
213 | def changelog(self, pos): |
|
213 | def changelog(self, pos): | |
214 | def changenav(**map): |
|
214 | def changenav(**map): | |
215 | def seq(factor, maxchanges=None): |
|
215 | def seq(factor, maxchanges=None): | |
216 | if maxchanges: |
|
216 | if maxchanges: | |
217 | yield maxchanges |
|
217 | yield maxchanges | |
218 | if maxchanges >= 20 and maxchanges <= 40: |
|
218 | if maxchanges >= 20 and maxchanges <= 40: | |
219 | yield 50 |
|
219 | yield 50 | |
220 | else: |
|
220 | else: | |
221 | yield 1 * factor |
|
221 | yield 1 * factor | |
222 | yield 3 * factor |
|
222 | yield 3 * factor | |
223 | for f in seq(factor * 10): |
|
223 | for f in seq(factor * 10): | |
224 | yield f |
|
224 | yield f | |
225 |
|
225 | |||
226 | l = [] |
|
226 | l = [] | |
227 | last = 0 |
|
227 | last = 0 | |
228 | for f in seq(1, self.maxchanges): |
|
228 | for f in seq(1, self.maxchanges): | |
229 | if f < self.maxchanges or f <= last: |
|
229 | if f < self.maxchanges or f <= last: | |
230 | continue |
|
230 | continue | |
231 | if f > count: |
|
231 | if f > count: | |
232 | break |
|
232 | break | |
233 | last = f |
|
233 | last = f | |
234 | r = "%d" % f |
|
234 | r = "%d" % f | |
235 | if pos + f < count: |
|
235 | if pos + f < count: | |
236 | l.append(("+" + r, pos + f)) |
|
236 | l.append(("+" + r, pos + f)) | |
237 | if pos - f >= 0: |
|
237 | if pos - f >= 0: | |
238 | l.insert(0, ("-" + r, pos - f)) |
|
238 | l.insert(0, ("-" + r, pos - f)) | |
239 |
|
239 | |||
240 | yield {"rev": 0, "label": "(0)"} |
|
240 | yield {"rev": 0, "label": "(0)"} | |
241 |
|
241 | |||
242 | for label, rev in l: |
|
242 | for label, rev in l: | |
243 | yield {"label": label, "rev": rev} |
|
243 | yield {"label": label, "rev": rev} | |
244 |
|
244 | |||
245 | yield {"label": "tip", "rev": "tip"} |
|
245 | yield {"label": "tip", "rev": "tip"} | |
246 |
|
246 | |||
247 | def changelist(**map): |
|
247 | def changelist(**map): | |
248 | parity = (start - end) & 1 |
|
248 | parity = (start - end) & 1 | |
249 | cl = self.repo.changelog |
|
249 | cl = self.repo.changelog | |
250 | l = [] # build a list in forward order for efficiency |
|
250 | l = [] # build a list in forward order for efficiency | |
251 | for i in range(start, end): |
|
251 | for i in range(start, end): | |
252 | n = cl.node(i) |
|
252 | n = cl.node(i) | |
253 | changes = cl.read(n) |
|
253 | changes = cl.read(n) | |
254 | hn = hex(n) |
|
254 | hn = hex(n) | |
255 |
|
255 | |||
256 | l.insert(0, {"parity": parity, |
|
256 | l.insert(0, {"parity": parity, | |
257 | "author": changes[1], |
|
257 | "author": changes[1], | |
258 | "parent": self.siblings(cl.parents(n), cl.rev, |
|
258 | "parent": self.siblings(cl.parents(n), cl.rev, | |
259 | cl.rev(n) - 1), |
|
259 | cl.rev(n) - 1), | |
260 | "child": self.siblings(cl.children(n), cl.rev, |
|
260 | "child": self.siblings(cl.children(n), cl.rev, | |
261 | cl.rev(n) + 1), |
|
261 | cl.rev(n) + 1), | |
262 | "changelogtag": self.showtag("changelogtag",n), |
|
262 | "changelogtag": self.showtag("changelogtag",n), | |
263 | "manifest": hex(changes[0]), |
|
263 | "manifest": hex(changes[0]), | |
264 | "desc": changes[4], |
|
264 | "desc": changes[4], | |
265 | "date": changes[2], |
|
265 | "date": changes[2], | |
266 | "files": self.listfilediffs(changes[3], n), |
|
266 | "files": self.listfilediffs(changes[3], n), | |
267 | "rev": i, |
|
267 | "rev": i, | |
268 | "node": hn}) |
|
268 | "node": hn}) | |
269 | parity = 1 - parity |
|
269 | parity = 1 - parity | |
270 |
|
270 | |||
271 | for e in l: |
|
271 | for e in l: | |
272 | yield e |
|
272 | yield e | |
273 |
|
273 | |||
274 | cl = self.repo.changelog |
|
274 | cl = self.repo.changelog | |
275 | mf = cl.read(cl.tip())[0] |
|
275 | mf = cl.read(cl.tip())[0] | |
276 | count = cl.count() |
|
276 | count = cl.count() | |
277 | start = max(0, pos - self.maxchanges + 1) |
|
277 | start = max(0, pos - self.maxchanges + 1) | |
278 | end = min(count, start + self.maxchanges) |
|
278 | end = min(count, start + self.maxchanges) | |
279 | pos = end - 1 |
|
279 | pos = end - 1 | |
280 |
|
280 | |||
281 | yield self.t('changelog', |
|
281 | yield self.t('changelog', | |
282 | changenav=changenav, |
|
282 | changenav=changenav, | |
283 | manifest=hex(mf), |
|
283 | manifest=hex(mf), | |
284 | rev=pos, changesets=count, entries=changelist) |
|
284 | rev=pos, changesets=count, entries=changelist) | |
285 |
|
285 | |||
286 | def search(self, query): |
|
286 | def search(self, query): | |
287 |
|
287 | |||
288 | def changelist(**map): |
|
288 | def changelist(**map): | |
289 | cl = self.repo.changelog |
|
289 | cl = self.repo.changelog | |
290 | count = 0 |
|
290 | count = 0 | |
291 | qw = query.lower().split() |
|
291 | qw = query.lower().split() | |
292 |
|
292 | |||
293 | def revgen(): |
|
293 | def revgen(): | |
294 | for i in range(cl.count() - 1, 0, -100): |
|
294 | for i in range(cl.count() - 1, 0, -100): | |
295 | l = [] |
|
295 | l = [] | |
296 | for j in range(max(0, i - 100), i): |
|
296 | for j in range(max(0, i - 100), i): | |
297 | n = cl.node(j) |
|
297 | n = cl.node(j) | |
298 | changes = cl.read(n) |
|
298 | changes = cl.read(n) | |
299 | l.append((n, j, changes)) |
|
299 | l.append((n, j, changes)) | |
300 | l.reverse() |
|
300 | l.reverse() | |
301 | for e in l: |
|
301 | for e in l: | |
302 | yield e |
|
302 | yield e | |
303 |
|
303 | |||
304 | for n, i, changes in revgen(): |
|
304 | for n, i, changes in revgen(): | |
305 | miss = 0 |
|
305 | miss = 0 | |
306 | for q in qw: |
|
306 | for q in qw: | |
307 | if not (q in changes[1].lower() or |
|
307 | if not (q in changes[1].lower() or | |
308 | q in changes[4].lower() or |
|
308 | q in changes[4].lower() or | |
309 | q in " ".join(changes[3][:20]).lower()): |
|
309 | q in " ".join(changes[3][:20]).lower()): | |
310 | miss = 1 |
|
310 | miss = 1 | |
311 | break |
|
311 | break | |
312 | if miss: |
|
312 | if miss: | |
313 | continue |
|
313 | continue | |
314 |
|
314 | |||
315 | count += 1 |
|
315 | count += 1 | |
316 | hn = hex(n) |
|
316 | hn = hex(n) | |
317 |
|
317 | |||
318 | yield self.t('searchentry', |
|
318 | yield self.t('searchentry', | |
319 | parity=count & 1, |
|
319 | parity=count & 1, | |
320 | author=changes[1], |
|
320 | author=changes[1], | |
321 | parent=self.siblings(cl.parents(n), cl.rev), |
|
321 | parent=self.siblings(cl.parents(n), cl.rev), | |
322 | child=self.siblings(cl.children(n), cl.rev), |
|
322 | child=self.siblings(cl.children(n), cl.rev), | |
323 | changelogtag=self.showtag("changelogtag",n), |
|
323 | changelogtag=self.showtag("changelogtag",n), | |
324 | manifest=hex(changes[0]), |
|
324 | manifest=hex(changes[0]), | |
325 | desc=changes[4], |
|
325 | desc=changes[4], | |
326 | date=changes[2], |
|
326 | date=changes[2], | |
327 | files=self.listfilediffs(changes[3], n), |
|
327 | files=self.listfilediffs(changes[3], n), | |
328 | rev=i, |
|
328 | rev=i, | |
329 | node=hn) |
|
329 | node=hn) | |
330 |
|
330 | |||
331 | if count >= self.maxchanges: |
|
331 | if count >= self.maxchanges: | |
332 | break |
|
332 | break | |
333 |
|
333 | |||
334 | cl = self.repo.changelog |
|
334 | cl = self.repo.changelog | |
335 | mf = cl.read(cl.tip())[0] |
|
335 | mf = cl.read(cl.tip())[0] | |
336 |
|
336 | |||
337 | yield self.t('search', |
|
337 | yield self.t('search', | |
338 | query=query, |
|
338 | query=query, | |
339 | manifest=hex(mf), |
|
339 | manifest=hex(mf), | |
340 | entries=changelist) |
|
340 | entries=changelist) | |
341 |
|
341 | |||
342 | def changeset(self, nodeid): |
|
342 | def changeset(self, nodeid): | |
343 | cl = self.repo.changelog |
|
343 | cl = self.repo.changelog | |
344 | n = self.repo.lookup(nodeid) |
|
344 | n = self.repo.lookup(nodeid) | |
345 | nodeid = hex(n) |
|
345 | nodeid = hex(n) | |
346 | changes = cl.read(n) |
|
346 | changes = cl.read(n) | |
347 | p1 = cl.parents(n)[0] |
|
347 | p1 = cl.parents(n)[0] | |
348 |
|
348 | |||
349 | files = [] |
|
349 | files = [] | |
350 | mf = self.repo.manifest.read(changes[0]) |
|
350 | mf = self.repo.manifest.read(changes[0]) | |
351 | for f in changes[3]: |
|
351 | for f in changes[3]: | |
352 | files.append(self.t("filenodelink", |
|
352 | files.append(self.t("filenodelink", | |
353 | filenode=hex(mf.get(f, nullid)), file=f)) |
|
353 | filenode=hex(mf.get(f, nullid)), file=f)) | |
354 |
|
354 | |||
355 | def diff(**map): |
|
355 | def diff(**map): | |
356 | yield self.diff(p1, n, None) |
|
356 | yield self.diff(p1, n, None) | |
357 |
|
357 | |||
358 | yield self.t('changeset', |
|
358 | yield self.t('changeset', | |
359 | diff=diff, |
|
359 | diff=diff, | |
360 | rev=cl.rev(n), |
|
360 | rev=cl.rev(n), | |
361 | node=nodeid, |
|
361 | node=nodeid, | |
362 | parent=self.siblings(cl.parents(n), cl.rev), |
|
362 | parent=self.siblings(cl.parents(n), cl.rev), | |
363 | child=self.siblings(cl.children(n), cl.rev), |
|
363 | child=self.siblings(cl.children(n), cl.rev), | |
364 | changesettag=self.showtag("changesettag",n), |
|
364 | changesettag=self.showtag("changesettag",n), | |
365 | manifest=hex(changes[0]), |
|
365 | manifest=hex(changes[0]), | |
366 | author=changes[1], |
|
366 | author=changes[1], | |
367 | desc=changes[4], |
|
367 | desc=changes[4], | |
368 | date=changes[2], |
|
368 | date=changes[2], | |
369 | files=files, |
|
369 | files=files, | |
370 | archives=self.archivelist(nodeid)) |
|
370 | archives=self.archivelist(nodeid)) | |
371 |
|
371 | |||
372 | def filelog(self, f, filenode): |
|
372 | def filelog(self, f, filenode): | |
373 | cl = self.repo.changelog |
|
373 | cl = self.repo.changelog | |
374 | fl = self.repo.file(f) |
|
374 | fl = self.repo.file(f) | |
375 | filenode = hex(fl.lookup(filenode)) |
|
375 | filenode = hex(fl.lookup(filenode)) | |
376 | count = fl.count() |
|
376 | count = fl.count() | |
377 |
|
377 | |||
378 | def entries(**map): |
|
378 | def entries(**map): | |
379 | l = [] |
|
379 | l = [] | |
380 | parity = (count - 1) & 1 |
|
380 | parity = (count - 1) & 1 | |
381 |
|
381 | |||
382 | for i in range(count): |
|
382 | for i in range(count): | |
383 | n = fl.node(i) |
|
383 | n = fl.node(i) | |
384 | lr = fl.linkrev(n) |
|
384 | lr = fl.linkrev(n) | |
385 | cn = cl.node(lr) |
|
385 | cn = cl.node(lr) | |
386 | cs = cl.read(cl.node(lr)) |
|
386 | cs = cl.read(cl.node(lr)) | |
387 |
|
387 | |||
388 | l.insert(0, {"parity": parity, |
|
388 | l.insert(0, {"parity": parity, | |
389 | "filenode": hex(n), |
|
389 | "filenode": hex(n), | |
390 | "filerev": i, |
|
390 | "filerev": i, | |
391 | "file": f, |
|
391 | "file": f, | |
392 | "node": hex(cn), |
|
392 | "node": hex(cn), | |
393 | "author": cs[1], |
|
393 | "author": cs[1], | |
394 | "date": cs[2], |
|
394 | "date": cs[2], | |
395 | "rename": self.renamelink(fl, n), |
|
395 | "rename": self.renamelink(fl, n), | |
396 | "parent": self.siblings(fl.parents(n), |
|
396 | "parent": self.siblings(fl.parents(n), | |
397 | fl.rev, file=f), |
|
397 | fl.rev, file=f), | |
398 | "child": self.siblings(fl.children(n), |
|
398 | "child": self.siblings(fl.children(n), | |
399 | fl.rev, file=f), |
|
399 | fl.rev, file=f), | |
400 | "desc": cs[4]}) |
|
400 | "desc": cs[4]}) | |
401 | parity = 1 - parity |
|
401 | parity = 1 - parity | |
402 |
|
402 | |||
403 | for e in l: |
|
403 | for e in l: | |
404 | yield e |
|
404 | yield e | |
405 |
|
405 | |||
406 | yield self.t("filelog", file=f, filenode=filenode, entries=entries) |
|
406 | yield self.t("filelog", file=f, filenode=filenode, entries=entries) | |
407 |
|
407 | |||
408 | def filerevision(self, f, node): |
|
408 | def filerevision(self, f, node): | |
409 | fl = self.repo.file(f) |
|
409 | fl = self.repo.file(f) | |
410 | n = fl.lookup(node) |
|
410 | n = fl.lookup(node) | |
411 | node = hex(n) |
|
411 | node = hex(n) | |
412 | text = fl.read(n) |
|
412 | text = fl.read(n) | |
413 | changerev = fl.linkrev(n) |
|
413 | changerev = fl.linkrev(n) | |
414 | cl = self.repo.changelog |
|
414 | cl = self.repo.changelog | |
415 | cn = cl.node(changerev) |
|
415 | cn = cl.node(changerev) | |
416 | cs = cl.read(cn) |
|
416 | cs = cl.read(cn) | |
417 | mfn = cs[0] |
|
417 | mfn = cs[0] | |
418 |
|
418 | |||
419 | mt = mimetypes.guess_type(f)[0] |
|
419 | mt = mimetypes.guess_type(f)[0] | |
420 | rawtext = text |
|
420 | rawtext = text | |
421 | if util.binary(text): |
|
421 | if util.binary(text): | |
422 | text = "(binary:%s)" % mt |
|
422 | text = "(binary:%s)" % (mt or 'data') | |
|
423 | mt = mt or 'text/plain' | |||
423 |
|
424 | |||
424 | def lines(): |
|
425 | def lines(): | |
425 | for l, t in enumerate(text.splitlines(1)): |
|
426 | for l, t in enumerate(text.splitlines(1)): | |
426 | yield {"line": t, |
|
427 | yield {"line": t, | |
427 | "linenumber": "% 6d" % (l + 1), |
|
428 | "linenumber": "% 6d" % (l + 1), | |
428 | "parity": l & 1} |
|
429 | "parity": l & 1} | |
429 |
|
430 | |||
430 | yield self.t("filerevision", |
|
431 | yield self.t("filerevision", | |
431 | file=f, |
|
432 | file=f, | |
432 | filenode=node, |
|
433 | filenode=node, | |
433 | path=up(f), |
|
434 | path=up(f), | |
434 | text=lines(), |
|
435 | text=lines(), | |
435 | raw=rawtext, |
|
436 | raw=rawtext, | |
436 | mimetype=mt, |
|
437 | mimetype=mt, | |
437 | rev=changerev, |
|
438 | rev=changerev, | |
438 | node=hex(cn), |
|
439 | node=hex(cn), | |
439 | manifest=hex(mfn), |
|
440 | manifest=hex(mfn), | |
440 | author=cs[1], |
|
441 | author=cs[1], | |
441 | date=cs[2], |
|
442 | date=cs[2], | |
442 | parent=self.siblings(fl.parents(n), fl.rev, file=f), |
|
443 | parent=self.siblings(fl.parents(n), fl.rev, file=f), | |
443 | child=self.siblings(fl.children(n), fl.rev, file=f), |
|
444 | child=self.siblings(fl.children(n), fl.rev, file=f), | |
444 | rename=self.renamelink(fl, n), |
|
445 | rename=self.renamelink(fl, n), | |
445 | permissions=self.repo.manifest.readflags(mfn)[f]) |
|
446 | permissions=self.repo.manifest.readflags(mfn)[f]) | |
446 |
|
447 | |||
447 | def fileannotate(self, f, node): |
|
448 | def fileannotate(self, f, node): | |
448 | bcache = {} |
|
449 | bcache = {} | |
449 | ncache = {} |
|
450 | ncache = {} | |
450 | fl = self.repo.file(f) |
|
451 | fl = self.repo.file(f) | |
451 | n = fl.lookup(node) |
|
452 | n = fl.lookup(node) | |
452 | node = hex(n) |
|
453 | node = hex(n) | |
453 | changerev = fl.linkrev(n) |
|
454 | changerev = fl.linkrev(n) | |
454 |
|
455 | |||
455 | cl = self.repo.changelog |
|
456 | cl = self.repo.changelog | |
456 | cn = cl.node(changerev) |
|
457 | cn = cl.node(changerev) | |
457 | cs = cl.read(cn) |
|
458 | cs = cl.read(cn) | |
458 | mfn = cs[0] |
|
459 | mfn = cs[0] | |
459 |
|
460 | |||
460 | def annotate(**map): |
|
461 | def annotate(**map): | |
461 | parity = 1 |
|
462 | parity = 1 | |
462 | last = None |
|
463 | last = None | |
463 | for r, l in fl.annotate(n): |
|
464 | for r, l in fl.annotate(n): | |
464 | try: |
|
465 | try: | |
465 | cnode = ncache[r] |
|
466 | cnode = ncache[r] | |
466 | except KeyError: |
|
467 | except KeyError: | |
467 | cnode = ncache[r] = self.repo.changelog.node(r) |
|
468 | cnode = ncache[r] = self.repo.changelog.node(r) | |
468 |
|
469 | |||
469 | try: |
|
470 | try: | |
470 | name = bcache[r] |
|
471 | name = bcache[r] | |
471 | except KeyError: |
|
472 | except KeyError: | |
472 | cl = self.repo.changelog.read(cnode) |
|
473 | cl = self.repo.changelog.read(cnode) | |
473 | bcache[r] = name = self.repo.ui.shortuser(cl[1]) |
|
474 | bcache[r] = name = self.repo.ui.shortuser(cl[1]) | |
474 |
|
475 | |||
475 | if last != cnode: |
|
476 | if last != cnode: | |
476 | parity = 1 - parity |
|
477 | parity = 1 - parity | |
477 | last = cnode |
|
478 | last = cnode | |
478 |
|
479 | |||
479 | yield {"parity": parity, |
|
480 | yield {"parity": parity, | |
480 | "node": hex(cnode), |
|
481 | "node": hex(cnode), | |
481 | "rev": r, |
|
482 | "rev": r, | |
482 | "author": name, |
|
483 | "author": name, | |
483 | "file": f, |
|
484 | "file": f, | |
484 | "line": l} |
|
485 | "line": l} | |
485 |
|
486 | |||
486 | yield self.t("fileannotate", |
|
487 | yield self.t("fileannotate", | |
487 | file=f, |
|
488 | file=f, | |
488 | filenode=node, |
|
489 | filenode=node, | |
489 | annotate=annotate, |
|
490 | annotate=annotate, | |
490 | path=up(f), |
|
491 | path=up(f), | |
491 | rev=changerev, |
|
492 | rev=changerev, | |
492 | node=hex(cn), |
|
493 | node=hex(cn), | |
493 | manifest=hex(mfn), |
|
494 | manifest=hex(mfn), | |
494 | author=cs[1], |
|
495 | author=cs[1], | |
495 | date=cs[2], |
|
496 | date=cs[2], | |
496 | rename=self.renamelink(fl, n), |
|
497 | rename=self.renamelink(fl, n), | |
497 | parent=self.siblings(fl.parents(n), fl.rev, file=f), |
|
498 | parent=self.siblings(fl.parents(n), fl.rev, file=f), | |
498 | child=self.siblings(fl.children(n), fl.rev, file=f), |
|
499 | child=self.siblings(fl.children(n), fl.rev, file=f), | |
499 | permissions=self.repo.manifest.readflags(mfn)[f]) |
|
500 | permissions=self.repo.manifest.readflags(mfn)[f]) | |
500 |
|
501 | |||
501 | def manifest(self, mnode, path): |
|
502 | def manifest(self, mnode, path): | |
502 | man = self.repo.manifest |
|
503 | man = self.repo.manifest | |
503 | mn = man.lookup(mnode) |
|
504 | mn = man.lookup(mnode) | |
504 | mnode = hex(mn) |
|
505 | mnode = hex(mn) | |
505 | mf = man.read(mn) |
|
506 | mf = man.read(mn) | |
506 | rev = man.rev(mn) |
|
507 | rev = man.rev(mn) | |
507 | node = self.repo.changelog.node(rev) |
|
508 | node = self.repo.changelog.node(rev) | |
508 | mff = man.readflags(mn) |
|
509 | mff = man.readflags(mn) | |
509 |
|
510 | |||
510 | files = {} |
|
511 | files = {} | |
511 |
|
512 | |||
512 | p = path[1:] |
|
513 | p = path[1:] | |
513 | if p and p[-1] != "/": |
|
514 | if p and p[-1] != "/": | |
514 | p += "/" |
|
515 | p += "/" | |
515 | l = len(p) |
|
516 | l = len(p) | |
516 |
|
517 | |||
517 | for f,n in mf.items(): |
|
518 | for f,n in mf.items(): | |
518 | if f[:l] != p: |
|
519 | if f[:l] != p: | |
519 | continue |
|
520 | continue | |
520 | remain = f[l:] |
|
521 | remain = f[l:] | |
521 | if "/" in remain: |
|
522 | if "/" in remain: | |
522 | short = remain[:remain.find("/") + 1] # bleah |
|
523 | short = remain[:remain.find("/") + 1] # bleah | |
523 | files[short] = (f, None) |
|
524 | files[short] = (f, None) | |
524 | else: |
|
525 | else: | |
525 | short = os.path.basename(remain) |
|
526 | short = os.path.basename(remain) | |
526 | files[short] = (f, n) |
|
527 | files[short] = (f, n) | |
527 |
|
528 | |||
528 | def filelist(**map): |
|
529 | def filelist(**map): | |
529 | parity = 0 |
|
530 | parity = 0 | |
530 | fl = files.keys() |
|
531 | fl = files.keys() | |
531 | fl.sort() |
|
532 | fl.sort() | |
532 | for f in fl: |
|
533 | for f in fl: | |
533 | full, fnode = files[f] |
|
534 | full, fnode = files[f] | |
534 | if not fnode: |
|
535 | if not fnode: | |
535 | continue |
|
536 | continue | |
536 |
|
537 | |||
537 | yield {"file": full, |
|
538 | yield {"file": full, | |
538 | "manifest": mnode, |
|
539 | "manifest": mnode, | |
539 | "filenode": hex(fnode), |
|
540 | "filenode": hex(fnode), | |
540 | "parity": parity, |
|
541 | "parity": parity, | |
541 | "basename": f, |
|
542 | "basename": f, | |
542 | "permissions": mff[full]} |
|
543 | "permissions": mff[full]} | |
543 | parity = 1 - parity |
|
544 | parity = 1 - parity | |
544 |
|
545 | |||
545 | def dirlist(**map): |
|
546 | def dirlist(**map): | |
546 | parity = 0 |
|
547 | parity = 0 | |
547 | fl = files.keys() |
|
548 | fl = files.keys() | |
548 | fl.sort() |
|
549 | fl.sort() | |
549 | for f in fl: |
|
550 | for f in fl: | |
550 | full, fnode = files[f] |
|
551 | full, fnode = files[f] | |
551 | if fnode: |
|
552 | if fnode: | |
552 | continue |
|
553 | continue | |
553 |
|
554 | |||
554 | yield {"parity": parity, |
|
555 | yield {"parity": parity, | |
555 | "path": os.path.join(path, f), |
|
556 | "path": os.path.join(path, f), | |
556 | "manifest": mnode, |
|
557 | "manifest": mnode, | |
557 | "basename": f[:-1]} |
|
558 | "basename": f[:-1]} | |
558 | parity = 1 - parity |
|
559 | parity = 1 - parity | |
559 |
|
560 | |||
560 | yield self.t("manifest", |
|
561 | yield self.t("manifest", | |
561 | manifest=mnode, |
|
562 | manifest=mnode, | |
562 | rev=rev, |
|
563 | rev=rev, | |
563 | node=hex(node), |
|
564 | node=hex(node), | |
564 | path=path, |
|
565 | path=path, | |
565 | up=up(path), |
|
566 | up=up(path), | |
566 | fentries=filelist, |
|
567 | fentries=filelist, | |
567 | dentries=dirlist, |
|
568 | dentries=dirlist, | |
568 | archives=self.archivelist(hex(node))) |
|
569 | archives=self.archivelist(hex(node))) | |
569 |
|
570 | |||
570 | def tags(self): |
|
571 | def tags(self): | |
571 | cl = self.repo.changelog |
|
572 | cl = self.repo.changelog | |
572 | mf = cl.read(cl.tip())[0] |
|
573 | mf = cl.read(cl.tip())[0] | |
573 |
|
574 | |||
574 | i = self.repo.tagslist() |
|
575 | i = self.repo.tagslist() | |
575 | i.reverse() |
|
576 | i.reverse() | |
576 |
|
577 | |||
577 | def entries(notip=False, **map): |
|
578 | def entries(notip=False, **map): | |
578 | parity = 0 |
|
579 | parity = 0 | |
579 | for k,n in i: |
|
580 | for k,n in i: | |
580 | if notip and k == "tip": continue |
|
581 | if notip and k == "tip": continue | |
581 | yield {"parity": parity, |
|
582 | yield {"parity": parity, | |
582 | "tag": k, |
|
583 | "tag": k, | |
583 | "tagmanifest": hex(cl.read(n)[0]), |
|
584 | "tagmanifest": hex(cl.read(n)[0]), | |
584 | "date": cl.read(n)[2], |
|
585 | "date": cl.read(n)[2], | |
585 | "node": hex(n)} |
|
586 | "node": hex(n)} | |
586 | parity = 1 - parity |
|
587 | parity = 1 - parity | |
587 |
|
588 | |||
588 | yield self.t("tags", |
|
589 | yield self.t("tags", | |
589 | manifest=hex(mf), |
|
590 | manifest=hex(mf), | |
590 | entries=lambda **x: entries(False, **x), |
|
591 | entries=lambda **x: entries(False, **x), | |
591 | entriesnotip=lambda **x: entries(True, **x)) |
|
592 | entriesnotip=lambda **x: entries(True, **x)) | |
592 |
|
593 | |||
593 | def summary(self): |
|
594 | def summary(self): | |
594 | cl = self.repo.changelog |
|
595 | cl = self.repo.changelog | |
595 | mf = cl.read(cl.tip())[0] |
|
596 | mf = cl.read(cl.tip())[0] | |
596 |
|
597 | |||
597 | i = self.repo.tagslist() |
|
598 | i = self.repo.tagslist() | |
598 | i.reverse() |
|
599 | i.reverse() | |
599 |
|
600 | |||
600 | def tagentries(**map): |
|
601 | def tagentries(**map): | |
601 | parity = 0 |
|
602 | parity = 0 | |
602 | count = 0 |
|
603 | count = 0 | |
603 | for k,n in i: |
|
604 | for k,n in i: | |
604 | if k == "tip": # skip tip |
|
605 | if k == "tip": # skip tip | |
605 | continue; |
|
606 | continue; | |
606 |
|
607 | |||
607 | count += 1 |
|
608 | count += 1 | |
608 | if count > 10: # limit to 10 tags |
|
609 | if count > 10: # limit to 10 tags | |
609 | break; |
|
610 | break; | |
610 |
|
611 | |||
611 | c = cl.read(n) |
|
612 | c = cl.read(n) | |
612 | m = c[0] |
|
613 | m = c[0] | |
613 | t = c[2] |
|
614 | t = c[2] | |
614 |
|
615 | |||
615 | yield self.t("tagentry", |
|
616 | yield self.t("tagentry", | |
616 | parity = parity, |
|
617 | parity = parity, | |
617 | tag = k, |
|
618 | tag = k, | |
618 | node = hex(n), |
|
619 | node = hex(n), | |
619 | date = t, |
|
620 | date = t, | |
620 | tagmanifest = hex(m)) |
|
621 | tagmanifest = hex(m)) | |
621 | parity = 1 - parity |
|
622 | parity = 1 - parity | |
622 |
|
623 | |||
623 | def changelist(**map): |
|
624 | def changelist(**map): | |
624 | parity = 0 |
|
625 | parity = 0 | |
625 | cl = self.repo.changelog |
|
626 | cl = self.repo.changelog | |
626 | l = [] # build a list in forward order for efficiency |
|
627 | l = [] # build a list in forward order for efficiency | |
627 | for i in range(start, end): |
|
628 | for i in range(start, end): | |
628 | n = cl.node(i) |
|
629 | n = cl.node(i) | |
629 | changes = cl.read(n) |
|
630 | changes = cl.read(n) | |
630 | hn = hex(n) |
|
631 | hn = hex(n) | |
631 | t = changes[2] |
|
632 | t = changes[2] | |
632 |
|
633 | |||
633 | l.insert(0, self.t( |
|
634 | l.insert(0, self.t( | |
634 | 'shortlogentry', |
|
635 | 'shortlogentry', | |
635 | parity = parity, |
|
636 | parity = parity, | |
636 | author = changes[1], |
|
637 | author = changes[1], | |
637 | manifest = hex(changes[0]), |
|
638 | manifest = hex(changes[0]), | |
638 | desc = changes[4], |
|
639 | desc = changes[4], | |
639 | date = t, |
|
640 | date = t, | |
640 | rev = i, |
|
641 | rev = i, | |
641 | node = hn)) |
|
642 | node = hn)) | |
642 | parity = 1 - parity |
|
643 | parity = 1 - parity | |
643 |
|
644 | |||
644 | yield l |
|
645 | yield l | |
645 |
|
646 | |||
646 | cl = self.repo.changelog |
|
647 | cl = self.repo.changelog | |
647 | mf = cl.read(cl.tip())[0] |
|
648 | mf = cl.read(cl.tip())[0] | |
648 | count = cl.count() |
|
649 | count = cl.count() | |
649 | start = max(0, count - self.maxchanges) |
|
650 | start = max(0, count - self.maxchanges) | |
650 | end = min(count, start + self.maxchanges) |
|
651 | end = min(count, start + self.maxchanges) | |
651 | pos = end - 1 |
|
652 | pos = end - 1 | |
652 |
|
653 | |||
653 | yield self.t("summary", |
|
654 | yield self.t("summary", | |
654 | desc = self.repo.ui.config("web", "description", "unknown"), |
|
655 | desc = self.repo.ui.config("web", "description", "unknown"), | |
655 | owner = (self.repo.ui.config("ui", "username") or # preferred |
|
656 | owner = (self.repo.ui.config("ui", "username") or # preferred | |
656 | self.repo.ui.config("web", "contact") or # deprecated |
|
657 | self.repo.ui.config("web", "contact") or # deprecated | |
657 | self.repo.ui.config("web", "author", "unknown")), # also |
|
658 | self.repo.ui.config("web", "author", "unknown")), # also | |
658 | lastchange = (0, 0), # FIXME |
|
659 | lastchange = (0, 0), # FIXME | |
659 | manifest = hex(mf), |
|
660 | manifest = hex(mf), | |
660 | tags = tagentries, |
|
661 | tags = tagentries, | |
661 | shortlog = changelist) |
|
662 | shortlog = changelist) | |
662 |
|
663 | |||
663 | def filediff(self, file, changeset): |
|
664 | def filediff(self, file, changeset): | |
664 | cl = self.repo.changelog |
|
665 | cl = self.repo.changelog | |
665 | n = self.repo.lookup(changeset) |
|
666 | n = self.repo.lookup(changeset) | |
666 | changeset = hex(n) |
|
667 | changeset = hex(n) | |
667 | p1 = cl.parents(n)[0] |
|
668 | p1 = cl.parents(n)[0] | |
668 | cs = cl.read(n) |
|
669 | cs = cl.read(n) | |
669 | mf = self.repo.manifest.read(cs[0]) |
|
670 | mf = self.repo.manifest.read(cs[0]) | |
670 |
|
671 | |||
671 | def diff(**map): |
|
672 | def diff(**map): | |
672 | yield self.diff(p1, n, file) |
|
673 | yield self.diff(p1, n, file) | |
673 |
|
674 | |||
674 | yield self.t("filediff", |
|
675 | yield self.t("filediff", | |
675 | file=file, |
|
676 | file=file, | |
676 | filenode=hex(mf.get(file, nullid)), |
|
677 | filenode=hex(mf.get(file, nullid)), | |
677 | node=changeset, |
|
678 | node=changeset, | |
678 | rev=self.repo.changelog.rev(n), |
|
679 | rev=self.repo.changelog.rev(n), | |
679 | parent=self.siblings(cl.parents(n), cl.rev), |
|
680 | parent=self.siblings(cl.parents(n), cl.rev), | |
680 | child=self.siblings(cl.children(n), cl.rev), |
|
681 | child=self.siblings(cl.children(n), cl.rev), | |
681 | diff=diff) |
|
682 | diff=diff) | |
682 |
|
683 | |||
683 | def archive(self, req, cnode, type): |
|
684 | def archive(self, req, cnode, type): | |
684 | cs = self.repo.changelog.read(cnode) |
|
685 | cs = self.repo.changelog.read(cnode) | |
685 | mnode = cs[0] |
|
686 | mnode = cs[0] | |
686 | mf = self.repo.manifest.read(mnode) |
|
687 | mf = self.repo.manifest.read(mnode) | |
687 | rev = self.repo.manifest.rev(mnode) |
|
688 | rev = self.repo.manifest.rev(mnode) | |
688 | reponame = re.sub(r"\W+", "-", self.reponame) |
|
689 | reponame = re.sub(r"\W+", "-", self.reponame) | |
689 | name = "%s-%s/" % (reponame, short(cnode)) |
|
690 | name = "%s-%s/" % (reponame, short(cnode)) | |
690 |
|
691 | |||
691 | files = mf.keys() |
|
692 | files = mf.keys() | |
692 | files.sort() |
|
693 | files.sort() | |
693 |
|
694 | |||
694 | if type == 'zip': |
|
695 | if type == 'zip': | |
695 | tmp = tempfile.mkstemp()[1] |
|
696 | tmp = tempfile.mkstemp()[1] | |
696 | try: |
|
697 | try: | |
697 | zf = zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED) |
|
698 | zf = zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED) | |
698 |
|
699 | |||
699 | for f in files: |
|
700 | for f in files: | |
700 | zf.writestr(name + f, self.repo.file(f).read(mf[f])) |
|
701 | zf.writestr(name + f, self.repo.file(f).read(mf[f])) | |
701 | zf.close() |
|
702 | zf.close() | |
702 |
|
703 | |||
703 | f = open(tmp, 'r') |
|
704 | f = open(tmp, 'r') | |
704 | req.httphdr('application/zip', name[:-1] + '.zip', |
|
705 | req.httphdr('application/zip', name[:-1] + '.zip', | |
705 | os.path.getsize(tmp)) |
|
706 | os.path.getsize(tmp)) | |
706 | req.write(f.read()) |
|
707 | req.write(f.read()) | |
707 | f.close() |
|
708 | f.close() | |
708 | finally: |
|
709 | finally: | |
709 | os.unlink(tmp) |
|
710 | os.unlink(tmp) | |
710 |
|
711 | |||
711 | else: |
|
712 | else: | |
712 | tf = tarfile.TarFile.open(mode='w|' + type, fileobj=req.out) |
|
713 | tf = tarfile.TarFile.open(mode='w|' + type, fileobj=req.out) | |
713 | mff = self.repo.manifest.readflags(mnode) |
|
714 | mff = self.repo.manifest.readflags(mnode) | |
714 | mtime = int(time.time()) |
|
715 | mtime = int(time.time()) | |
715 |
|
716 | |||
716 | if type == "gz": |
|
717 | if type == "gz": | |
717 | encoding = "gzip" |
|
718 | encoding = "gzip" | |
718 | else: |
|
719 | else: | |
719 | encoding = "x-bzip2" |
|
720 | encoding = "x-bzip2" | |
720 | req.header([('Content-type', 'application/x-tar'), |
|
721 | req.header([('Content-type', 'application/x-tar'), | |
721 | ('Content-disposition', 'attachment; filename=%s%s%s' % |
|
722 | ('Content-disposition', 'attachment; filename=%s%s%s' % | |
722 | (name[:-1], '.tar.', type)), |
|
723 | (name[:-1], '.tar.', type)), | |
723 | ('Content-encoding', encoding)]) |
|
724 | ('Content-encoding', encoding)]) | |
724 | for fname in files: |
|
725 | for fname in files: | |
725 | rcont = self.repo.file(fname).read(mf[fname]) |
|
726 | rcont = self.repo.file(fname).read(mf[fname]) | |
726 | finfo = tarfile.TarInfo(name + fname) |
|
727 | finfo = tarfile.TarInfo(name + fname) | |
727 | finfo.mtime = mtime |
|
728 | finfo.mtime = mtime | |
728 | finfo.size = len(rcont) |
|
729 | finfo.size = len(rcont) | |
729 | finfo.mode = mff[fname] and 0755 or 0644 |
|
730 | finfo.mode = mff[fname] and 0755 or 0644 | |
730 | tf.addfile(finfo, StringIO.StringIO(rcont)) |
|
731 | tf.addfile(finfo, StringIO.StringIO(rcont)) | |
731 | tf.close() |
|
732 | tf.close() | |
732 |
|
733 | |||
733 | # add tags to things |
|
734 | # add tags to things | |
734 | # tags -> list of changesets corresponding to tags |
|
735 | # tags -> list of changesets corresponding to tags | |
735 | # find tag, changeset, file |
|
736 | # find tag, changeset, file | |
736 |
|
737 | |||
737 | def run(self, req=hgrequest()): |
|
738 | def run(self, req=hgrequest()): | |
738 | def clean(path): |
|
739 | def clean(path): | |
739 | p = util.normpath(path) |
|
740 | p = util.normpath(path) | |
740 | if p[:2] == "..": |
|
741 | if p[:2] == "..": | |
741 | raise "suspicious path" |
|
742 | raise "suspicious path" | |
742 | return p |
|
743 | return p | |
743 |
|
744 | |||
744 | def header(**map): |
|
745 | def header(**map): | |
745 | yield self.t("header", **map) |
|
746 | yield self.t("header", **map) | |
746 |
|
747 | |||
747 | def footer(**map): |
|
748 | def footer(**map): | |
748 | yield self.t("footer", **map) |
|
749 | yield self.t("footer", **map) | |
749 |
|
750 | |||
750 | def expand_form(form): |
|
751 | def expand_form(form): | |
751 | shortcuts = { |
|
752 | shortcuts = { | |
752 | 'cl': [('cmd', ['changelog']), ('rev', None)], |
|
753 | 'cl': [('cmd', ['changelog']), ('rev', None)], | |
753 | 'cs': [('cmd', ['changeset']), ('node', None)], |
|
754 | 'cs': [('cmd', ['changeset']), ('node', None)], | |
754 | 'f': [('cmd', ['file']), ('filenode', None)], |
|
755 | 'f': [('cmd', ['file']), ('filenode', None)], | |
755 | 'fl': [('cmd', ['filelog']), ('filenode', None)], |
|
756 | 'fl': [('cmd', ['filelog']), ('filenode', None)], | |
756 | 'fd': [('cmd', ['filediff']), ('node', None)], |
|
757 | 'fd': [('cmd', ['filediff']), ('node', None)], | |
757 | 'fa': [('cmd', ['annotate']), ('filenode', None)], |
|
758 | 'fa': [('cmd', ['annotate']), ('filenode', None)], | |
758 | 'mf': [('cmd', ['manifest']), ('manifest', None)], |
|
759 | 'mf': [('cmd', ['manifest']), ('manifest', None)], | |
759 | 'ca': [('cmd', ['archive']), ('node', None)], |
|
760 | 'ca': [('cmd', ['archive']), ('node', None)], | |
760 | 'tags': [('cmd', ['tags'])], |
|
761 | 'tags': [('cmd', ['tags'])], | |
761 | 'tip': [('cmd', ['changeset']), ('node', ['tip'])], |
|
762 | 'tip': [('cmd', ['changeset']), ('node', ['tip'])], | |
762 | 'static': [('cmd', ['static']), ('file', None)] |
|
763 | 'static': [('cmd', ['static']), ('file', None)] | |
763 | } |
|
764 | } | |
764 |
|
765 | |||
765 | for k in shortcuts.iterkeys(): |
|
766 | for k in shortcuts.iterkeys(): | |
766 | if form.has_key(k): |
|
767 | if form.has_key(k): | |
767 | for name, value in shortcuts[k]: |
|
768 | for name, value in shortcuts[k]: | |
768 | if value is None: |
|
769 | if value is None: | |
769 | value = form[k] |
|
770 | value = form[k] | |
770 | form[name] = value |
|
771 | form[name] = value | |
771 | del form[k] |
|
772 | del form[k] | |
772 |
|
773 | |||
773 | self.refresh() |
|
774 | self.refresh() | |
774 |
|
775 | |||
775 | expand_form(req.form) |
|
776 | expand_form(req.form) | |
776 |
|
777 | |||
777 | t = self.repo.ui.config("web", "templates", templater.templatepath()) |
|
778 | t = self.repo.ui.config("web", "templates", templater.templatepath()) | |
778 | static = self.repo.ui.config("web", "static", os.path.join(t,"static")) |
|
779 | static = self.repo.ui.config("web", "static", os.path.join(t,"static")) | |
779 | m = os.path.join(t, "map") |
|
780 | m = os.path.join(t, "map") | |
780 | style = self.repo.ui.config("web", "style", "") |
|
781 | style = self.repo.ui.config("web", "style", "") | |
781 | if req.form.has_key('style'): |
|
782 | if req.form.has_key('style'): | |
782 | style = req.form['style'][0] |
|
783 | style = req.form['style'][0] | |
783 | if style: |
|
784 | if style: | |
784 | b = os.path.basename("map-" + style) |
|
785 | b = os.path.basename("map-" + style) | |
785 | p = os.path.join(t, b) |
|
786 | p = os.path.join(t, b) | |
786 | if os.path.isfile(p): |
|
787 | if os.path.isfile(p): | |
787 | m = p |
|
788 | m = p | |
788 |
|
789 | |||
789 | port = req.env["SERVER_PORT"] |
|
790 | port = req.env["SERVER_PORT"] | |
790 | port = port != "80" and (":" + port) or "" |
|
791 | port = port != "80" and (":" + port) or "" | |
791 | uri = req.env["REQUEST_URI"] |
|
792 | uri = req.env["REQUEST_URI"] | |
792 | if "?" in uri: |
|
793 | if "?" in uri: | |
793 | uri = uri.split("?")[0] |
|
794 | uri = uri.split("?")[0] | |
794 | url = "http://%s%s%s" % (req.env["SERVER_NAME"], port, uri) |
|
795 | url = "http://%s%s%s" % (req.env["SERVER_NAME"], port, uri) | |
795 | if not self.reponame: |
|
796 | if not self.reponame: | |
796 | self.reponame = (self.repo.ui.config("web", "name") |
|
797 | self.reponame = (self.repo.ui.config("web", "name") | |
797 | or uri.strip('/') or self.repo.root) |
|
798 | or uri.strip('/') or self.repo.root) | |
798 |
|
799 | |||
799 | self.t = templater.templater(m, templater.common_filters, |
|
800 | self.t = templater.templater(m, templater.common_filters, | |
800 | defaults={"url": url, |
|
801 | defaults={"url": url, | |
801 | "repo": self.reponame, |
|
802 | "repo": self.reponame, | |
802 | "header": header, |
|
803 | "header": header, | |
803 | "footer": footer, |
|
804 | "footer": footer, | |
804 | }) |
|
805 | }) | |
805 |
|
806 | |||
806 | if not req.form.has_key('cmd'): |
|
807 | if not req.form.has_key('cmd'): | |
807 | req.form['cmd'] = [self.t.cache['default'],] |
|
808 | req.form['cmd'] = [self.t.cache['default'],] | |
808 |
|
809 | |||
809 | if req.form['cmd'][0] == 'changelog': |
|
810 | if req.form['cmd'][0] == 'changelog': | |
810 | c = self.repo.changelog.count() - 1 |
|
811 | c = self.repo.changelog.count() - 1 | |
811 | hi = c |
|
812 | hi = c | |
812 | if req.form.has_key('rev'): |
|
813 | if req.form.has_key('rev'): | |
813 | hi = req.form['rev'][0] |
|
814 | hi = req.form['rev'][0] | |
814 | try: |
|
815 | try: | |
815 | hi = self.repo.changelog.rev(self.repo.lookup(hi)) |
|
816 | hi = self.repo.changelog.rev(self.repo.lookup(hi)) | |
816 | except hg.RepoError: |
|
817 | except hg.RepoError: | |
817 | req.write(self.search(hi)) |
|
818 | req.write(self.search(hi)) | |
818 | return |
|
819 | return | |
819 |
|
820 | |||
820 | req.write(self.changelog(hi)) |
|
821 | req.write(self.changelog(hi)) | |
821 |
|
822 | |||
822 | elif req.form['cmd'][0] == 'changeset': |
|
823 | elif req.form['cmd'][0] == 'changeset': | |
823 | req.write(self.changeset(req.form['node'][0])) |
|
824 | req.write(self.changeset(req.form['node'][0])) | |
824 |
|
825 | |||
825 | elif req.form['cmd'][0] == 'manifest': |
|
826 | elif req.form['cmd'][0] == 'manifest': | |
826 | req.write(self.manifest(req.form['manifest'][0], |
|
827 | req.write(self.manifest(req.form['manifest'][0], | |
827 | clean(req.form['path'][0]))) |
|
828 | clean(req.form['path'][0]))) | |
828 |
|
829 | |||
829 | elif req.form['cmd'][0] == 'tags': |
|
830 | elif req.form['cmd'][0] == 'tags': | |
830 | req.write(self.tags()) |
|
831 | req.write(self.tags()) | |
831 |
|
832 | |||
832 | elif req.form['cmd'][0] == 'summary': |
|
833 | elif req.form['cmd'][0] == 'summary': | |
833 | req.write(self.summary()) |
|
834 | req.write(self.summary()) | |
834 |
|
835 | |||
835 | elif req.form['cmd'][0] == 'filediff': |
|
836 | elif req.form['cmd'][0] == 'filediff': | |
836 | req.write(self.filediff(clean(req.form['file'][0]), |
|
837 | req.write(self.filediff(clean(req.form['file'][0]), | |
837 | req.form['node'][0])) |
|
838 | req.form['node'][0])) | |
838 |
|
839 | |||
839 | elif req.form['cmd'][0] == 'file': |
|
840 | elif req.form['cmd'][0] == 'file': | |
840 | req.write(self.filerevision(clean(req.form['file'][0]), |
|
841 | req.write(self.filerevision(clean(req.form['file'][0]), | |
841 | req.form['filenode'][0])) |
|
842 | req.form['filenode'][0])) | |
842 |
|
843 | |||
843 | elif req.form['cmd'][0] == 'annotate': |
|
844 | elif req.form['cmd'][0] == 'annotate': | |
844 | req.write(self.fileannotate(clean(req.form['file'][0]), |
|
845 | req.write(self.fileannotate(clean(req.form['file'][0]), | |
845 | req.form['filenode'][0])) |
|
846 | req.form['filenode'][0])) | |
846 |
|
847 | |||
847 | elif req.form['cmd'][0] == 'filelog': |
|
848 | elif req.form['cmd'][0] == 'filelog': | |
848 | req.write(self.filelog(clean(req.form['file'][0]), |
|
849 | req.write(self.filelog(clean(req.form['file'][0]), | |
849 | req.form['filenode'][0])) |
|
850 | req.form['filenode'][0])) | |
850 |
|
851 | |||
851 | elif req.form['cmd'][0] == 'heads': |
|
852 | elif req.form['cmd'][0] == 'heads': | |
852 | req.httphdr("application/mercurial-0.1") |
|
853 | req.httphdr("application/mercurial-0.1") | |
853 | h = self.repo.heads() |
|
854 | h = self.repo.heads() | |
854 | req.write(" ".join(map(hex, h)) + "\n") |
|
855 | req.write(" ".join(map(hex, h)) + "\n") | |
855 |
|
856 | |||
856 | elif req.form['cmd'][0] == 'branches': |
|
857 | elif req.form['cmd'][0] == 'branches': | |
857 | req.httphdr("application/mercurial-0.1") |
|
858 | req.httphdr("application/mercurial-0.1") | |
858 | nodes = [] |
|
859 | nodes = [] | |
859 | if req.form.has_key('nodes'): |
|
860 | if req.form.has_key('nodes'): | |
860 | nodes = map(bin, req.form['nodes'][0].split(" ")) |
|
861 | nodes = map(bin, req.form['nodes'][0].split(" ")) | |
861 | for b in self.repo.branches(nodes): |
|
862 | for b in self.repo.branches(nodes): | |
862 | req.write(" ".join(map(hex, b)) + "\n") |
|
863 | req.write(" ".join(map(hex, b)) + "\n") | |
863 |
|
864 | |||
864 | elif req.form['cmd'][0] == 'between': |
|
865 | elif req.form['cmd'][0] == 'between': | |
865 | req.httphdr("application/mercurial-0.1") |
|
866 | req.httphdr("application/mercurial-0.1") | |
866 | nodes = [] |
|
867 | nodes = [] | |
867 | if req.form.has_key('pairs'): |
|
868 | if req.form.has_key('pairs'): | |
868 | pairs = [map(bin, p.split("-")) |
|
869 | pairs = [map(bin, p.split("-")) | |
869 | for p in req.form['pairs'][0].split(" ")] |
|
870 | for p in req.form['pairs'][0].split(" ")] | |
870 | for b in self.repo.between(pairs): |
|
871 | for b in self.repo.between(pairs): | |
871 | req.write(" ".join(map(hex, b)) + "\n") |
|
872 | req.write(" ".join(map(hex, b)) + "\n") | |
872 |
|
873 | |||
873 | elif req.form['cmd'][0] == 'changegroup': |
|
874 | elif req.form['cmd'][0] == 'changegroup': | |
874 | req.httphdr("application/mercurial-0.1") |
|
875 | req.httphdr("application/mercurial-0.1") | |
875 | nodes = [] |
|
876 | nodes = [] | |
876 | if not self.allowpull: |
|
877 | if not self.allowpull: | |
877 | return |
|
878 | return | |
878 |
|
879 | |||
879 | if req.form.has_key('roots'): |
|
880 | if req.form.has_key('roots'): | |
880 | nodes = map(bin, req.form['roots'][0].split(" ")) |
|
881 | nodes = map(bin, req.form['roots'][0].split(" ")) | |
881 |
|
882 | |||
882 | z = zlib.compressobj() |
|
883 | z = zlib.compressobj() | |
883 | f = self.repo.changegroup(nodes, 'serve') |
|
884 | f = self.repo.changegroup(nodes, 'serve') | |
884 | while 1: |
|
885 | while 1: | |
885 | chunk = f.read(4096) |
|
886 | chunk = f.read(4096) | |
886 | if not chunk: |
|
887 | if not chunk: | |
887 | break |
|
888 | break | |
888 | req.write(z.compress(chunk)) |
|
889 | req.write(z.compress(chunk)) | |
889 |
|
890 | |||
890 | req.write(z.flush()) |
|
891 | req.write(z.flush()) | |
891 |
|
892 | |||
892 | elif req.form['cmd'][0] == 'archive': |
|
893 | elif req.form['cmd'][0] == 'archive': | |
893 | changeset = self.repo.lookup(req.form['node'][0]) |
|
894 | changeset = self.repo.lookup(req.form['node'][0]) | |
894 | type = req.form['type'][0] |
|
895 | type = req.form['type'][0] | |
895 | if (type in self.archives and |
|
896 | if (type in self.archives and | |
896 | self.repo.ui.configbool("web", "allow" + type, False)): |
|
897 | self.repo.ui.configbool("web", "allow" + type, False)): | |
897 | self.archive(req, changeset, type) |
|
898 | self.archive(req, changeset, type) | |
898 | return |
|
899 | return | |
899 |
|
900 | |||
900 | req.write(self.t("error")) |
|
901 | req.write(self.t("error")) | |
901 |
|
902 | |||
902 | elif req.form['cmd'][0] == 'static': |
|
903 | elif req.form['cmd'][0] == 'static': | |
903 | fname = req.form['file'][0] |
|
904 | fname = req.form['file'][0] | |
904 | req.write(staticfile(static, fname) |
|
905 | req.write(staticfile(static, fname) | |
905 | or self.t("error", error="%r not found" % fname)) |
|
906 | or self.t("error", error="%r not found" % fname)) | |
906 |
|
907 | |||
907 | else: |
|
908 | else: | |
908 | req.write(self.t("error")) |
|
909 | req.write(self.t("error")) | |
909 |
|
910 | |||
910 | def create_server(repo): |
|
911 | def create_server(repo): | |
911 |
|
912 | |||
912 | def openlog(opt, default): |
|
913 | def openlog(opt, default): | |
913 | if opt and opt != '-': |
|
914 | if opt and opt != '-': | |
914 | return open(opt, 'w') |
|
915 | return open(opt, 'w') | |
915 | return default |
|
916 | return default | |
916 |
|
917 | |||
917 | address = repo.ui.config("web", "address", "") |
|
918 | address = repo.ui.config("web", "address", "") | |
918 | port = int(repo.ui.config("web", "port", 8000)) |
|
919 | port = int(repo.ui.config("web", "port", 8000)) | |
919 | use_ipv6 = repo.ui.configbool("web", "ipv6") |
|
920 | use_ipv6 = repo.ui.configbool("web", "ipv6") | |
920 | accesslog = openlog(repo.ui.config("web", "accesslog", "-"), sys.stdout) |
|
921 | accesslog = openlog(repo.ui.config("web", "accesslog", "-"), sys.stdout) | |
921 | errorlog = openlog(repo.ui.config("web", "errorlog", "-"), sys.stderr) |
|
922 | errorlog = openlog(repo.ui.config("web", "errorlog", "-"), sys.stderr) | |
922 |
|
923 | |||
923 | class IPv6HTTPServer(BaseHTTPServer.HTTPServer): |
|
924 | class IPv6HTTPServer(BaseHTTPServer.HTTPServer): | |
924 | address_family = getattr(socket, 'AF_INET6', None) |
|
925 | address_family = getattr(socket, 'AF_INET6', None) | |
925 |
|
926 | |||
926 | def __init__(self, *args, **kwargs): |
|
927 | def __init__(self, *args, **kwargs): | |
927 | if self.address_family is None: |
|
928 | if self.address_family is None: | |
928 | raise hg.RepoError(_('IPv6 not available on this system')) |
|
929 | raise hg.RepoError(_('IPv6 not available on this system')) | |
929 | BaseHTTPServer.HTTPServer.__init__(self, *args, **kwargs) |
|
930 | BaseHTTPServer.HTTPServer.__init__(self, *args, **kwargs) | |
930 |
|
931 | |||
931 | class hgwebhandler(BaseHTTPServer.BaseHTTPRequestHandler): |
|
932 | class hgwebhandler(BaseHTTPServer.BaseHTTPRequestHandler): | |
932 | def log_error(self, format, *args): |
|
933 | def log_error(self, format, *args): | |
933 | errorlog.write("%s - - [%s] %s\n" % (self.address_string(), |
|
934 | errorlog.write("%s - - [%s] %s\n" % (self.address_string(), | |
934 | self.log_date_time_string(), |
|
935 | self.log_date_time_string(), | |
935 | format % args)) |
|
936 | format % args)) | |
936 |
|
937 | |||
937 | def log_message(self, format, *args): |
|
938 | def log_message(self, format, *args): | |
938 | accesslog.write("%s - - [%s] %s\n" % (self.address_string(), |
|
939 | accesslog.write("%s - - [%s] %s\n" % (self.address_string(), | |
939 | self.log_date_time_string(), |
|
940 | self.log_date_time_string(), | |
940 | format % args)) |
|
941 | format % args)) | |
941 |
|
942 | |||
942 | def do_POST(self): |
|
943 | def do_POST(self): | |
943 | try: |
|
944 | try: | |
944 | self.do_hgweb() |
|
945 | self.do_hgweb() | |
945 | except socket.error, inst: |
|
946 | except socket.error, inst: | |
946 | if inst[0] != errno.EPIPE: |
|
947 | if inst[0] != errno.EPIPE: | |
947 | raise |
|
948 | raise | |
948 |
|
949 | |||
949 | def do_GET(self): |
|
950 | def do_GET(self): | |
950 | self.do_POST() |
|
951 | self.do_POST() | |
951 |
|
952 | |||
952 | def do_hgweb(self): |
|
953 | def do_hgweb(self): | |
953 | query = "" |
|
954 | query = "" | |
954 | p = self.path.find("?") |
|
955 | p = self.path.find("?") | |
955 | if p: |
|
956 | if p: | |
956 | query = self.path[p + 1:] |
|
957 | query = self.path[p + 1:] | |
957 | query = query.replace('+', ' ') |
|
958 | query = query.replace('+', ' ') | |
958 |
|
959 | |||
959 | env = {} |
|
960 | env = {} | |
960 | env['GATEWAY_INTERFACE'] = 'CGI/1.1' |
|
961 | env['GATEWAY_INTERFACE'] = 'CGI/1.1' | |
961 | env['REQUEST_METHOD'] = self.command |
|
962 | env['REQUEST_METHOD'] = self.command | |
962 | env['SERVER_NAME'] = self.server.server_name |
|
963 | env['SERVER_NAME'] = self.server.server_name | |
963 | env['SERVER_PORT'] = str(self.server.server_port) |
|
964 | env['SERVER_PORT'] = str(self.server.server_port) | |
964 | env['REQUEST_URI'] = "/" |
|
965 | env['REQUEST_URI'] = "/" | |
965 | if query: |
|
966 | if query: | |
966 | env['QUERY_STRING'] = query |
|
967 | env['QUERY_STRING'] = query | |
967 | host = self.address_string() |
|
968 | host = self.address_string() | |
968 | if host != self.client_address[0]: |
|
969 | if host != self.client_address[0]: | |
969 | env['REMOTE_HOST'] = host |
|
970 | env['REMOTE_HOST'] = host | |
970 | env['REMOTE_ADDR'] = self.client_address[0] |
|
971 | env['REMOTE_ADDR'] = self.client_address[0] | |
971 |
|
972 | |||
972 | if self.headers.typeheader is None: |
|
973 | if self.headers.typeheader is None: | |
973 | env['CONTENT_TYPE'] = self.headers.type |
|
974 | env['CONTENT_TYPE'] = self.headers.type | |
974 | else: |
|
975 | else: | |
975 | env['CONTENT_TYPE'] = self.headers.typeheader |
|
976 | env['CONTENT_TYPE'] = self.headers.typeheader | |
976 | length = self.headers.getheader('content-length') |
|
977 | length = self.headers.getheader('content-length') | |
977 | if length: |
|
978 | if length: | |
978 | env['CONTENT_LENGTH'] = length |
|
979 | env['CONTENT_LENGTH'] = length | |
979 | accept = [] |
|
980 | accept = [] | |
980 | for line in self.headers.getallmatchingheaders('accept'): |
|
981 | for line in self.headers.getallmatchingheaders('accept'): | |
981 | if line[:1] in "\t\n\r ": |
|
982 | if line[:1] in "\t\n\r ": | |
982 | accept.append(line.strip()) |
|
983 | accept.append(line.strip()) | |
983 | else: |
|
984 | else: | |
984 | accept = accept + line[7:].split(',') |
|
985 | accept = accept + line[7:].split(',') | |
985 | env['HTTP_ACCEPT'] = ','.join(accept) |
|
986 | env['HTTP_ACCEPT'] = ','.join(accept) | |
986 |
|
987 | |||
987 | req = hgrequest(self.rfile, self.wfile, env) |
|
988 | req = hgrequest(self.rfile, self.wfile, env) | |
988 | self.send_response(200, "Script output follows") |
|
989 | self.send_response(200, "Script output follows") | |
989 | hg.run(req) |
|
990 | hg.run(req) | |
990 |
|
991 | |||
991 | hg = hgweb(repo) |
|
992 | hg = hgweb(repo) | |
992 | if use_ipv6: |
|
993 | if use_ipv6: | |
993 | return IPv6HTTPServer((address, port), hgwebhandler) |
|
994 | return IPv6HTTPServer((address, port), hgwebhandler) | |
994 | else: |
|
995 | else: | |
995 | return BaseHTTPServer.HTTPServer((address, port), hgwebhandler) |
|
996 | return BaseHTTPServer.HTTPServer((address, port), hgwebhandler) | |
996 |
|
997 | |||
997 | # This is a stopgap |
|
998 | # This is a stopgap | |
998 | class hgwebdir(object): |
|
999 | class hgwebdir(object): | |
999 | def __init__(self, config): |
|
1000 | def __init__(self, config): | |
1000 | def cleannames(items): |
|
1001 | def cleannames(items): | |
1001 | return [(name.strip(os.sep), path) for name, path in items] |
|
1002 | return [(name.strip(os.sep), path) for name, path in items] | |
1002 |
|
1003 | |||
1003 | if isinstance(config, (list, tuple)): |
|
1004 | if isinstance(config, (list, tuple)): | |
1004 | self.repos = cleannames(config) |
|
1005 | self.repos = cleannames(config) | |
1005 | elif isinstance(config, dict): |
|
1006 | elif isinstance(config, dict): | |
1006 | self.repos = cleannames(config.items()) |
|
1007 | self.repos = cleannames(config.items()) | |
1007 | self.repos.sort() |
|
1008 | self.repos.sort() | |
1008 | else: |
|
1009 | else: | |
1009 | cp = ConfigParser.SafeConfigParser() |
|
1010 | cp = ConfigParser.SafeConfigParser() | |
1010 | cp.read(config) |
|
1011 | cp.read(config) | |
1011 | self.repos = [] |
|
1012 | self.repos = [] | |
1012 | if cp.has_section('paths'): |
|
1013 | if cp.has_section('paths'): | |
1013 | self.repos.extend(cleannames(cp.items('paths'))) |
|
1014 | self.repos.extend(cleannames(cp.items('paths'))) | |
1014 | if cp.has_section('collections'): |
|
1015 | if cp.has_section('collections'): | |
1015 | for prefix, root in cp.items('collections'): |
|
1016 | for prefix, root in cp.items('collections'): | |
1016 | for path in util.walkrepos(root): |
|
1017 | for path in util.walkrepos(root): | |
1017 | repo = os.path.normpath(path) |
|
1018 | repo = os.path.normpath(path) | |
1018 | name = repo |
|
1019 | name = repo | |
1019 | if name.startswith(prefix): |
|
1020 | if name.startswith(prefix): | |
1020 | name = name[len(prefix):] |
|
1021 | name = name[len(prefix):] | |
1021 | self.repos.append((name.lstrip(os.sep), repo)) |
|
1022 | self.repos.append((name.lstrip(os.sep), repo)) | |
1022 | self.repos.sort() |
|
1023 | self.repos.sort() | |
1023 |
|
1024 | |||
1024 | def run(self, req=hgrequest()): |
|
1025 | def run(self, req=hgrequest()): | |
1025 | def header(**map): |
|
1026 | def header(**map): | |
1026 | yield tmpl("header", **map) |
|
1027 | yield tmpl("header", **map) | |
1027 |
|
1028 | |||
1028 | def footer(**map): |
|
1029 | def footer(**map): | |
1029 | yield tmpl("footer", **map) |
|
1030 | yield tmpl("footer", **map) | |
1030 |
|
1031 | |||
1031 | m = os.path.join(templater.templatepath(), "map") |
|
1032 | m = os.path.join(templater.templatepath(), "map") | |
1032 | tmpl = templater.templater(m, templater.common_filters, |
|
1033 | tmpl = templater.templater(m, templater.common_filters, | |
1033 | defaults={"header": header, |
|
1034 | defaults={"header": header, | |
1034 | "footer": footer}) |
|
1035 | "footer": footer}) | |
1035 |
|
1036 | |||
1036 | def entries(**map): |
|
1037 | def entries(**map): | |
1037 | parity = 0 |
|
1038 | parity = 0 | |
1038 | for name, path in self.repos: |
|
1039 | for name, path in self.repos: | |
1039 | u = ui.ui() |
|
1040 | u = ui.ui() | |
1040 | try: |
|
1041 | try: | |
1041 | u.readconfig(os.path.join(path, '.hg', 'hgrc')) |
|
1042 | u.readconfig(os.path.join(path, '.hg', 'hgrc')) | |
1042 | except IOError: |
|
1043 | except IOError: | |
1043 | pass |
|
1044 | pass | |
1044 | get = u.config |
|
1045 | get = u.config | |
1045 |
|
1046 | |||
1046 | url = ('/'.join([req.env["REQUEST_URI"].split('?')[0], name]) |
|
1047 | url = ('/'.join([req.env["REQUEST_URI"].split('?')[0], name]) | |
1047 | .replace("//", "/")) |
|
1048 | .replace("//", "/")) | |
1048 |
|
1049 | |||
1049 | # update time with local timezone |
|
1050 | # update time with local timezone | |
1050 | try: |
|
1051 | try: | |
1051 | d = (get_mtime(path), util.makedate()[1]) |
|
1052 | d = (get_mtime(path), util.makedate()[1]) | |
1052 | except OSError: |
|
1053 | except OSError: | |
1053 | continue |
|
1054 | continue | |
1054 |
|
1055 | |||
1055 | yield dict(contact=(get("ui", "username") or # preferred |
|
1056 | yield dict(contact=(get("ui", "username") or # preferred | |
1056 | get("web", "contact") or # deprecated |
|
1057 | get("web", "contact") or # deprecated | |
1057 | get("web", "author", "unknown")), # also |
|
1058 | get("web", "author", "unknown")), # also | |
1058 | name=get("web", "name", name), |
|
1059 | name=get("web", "name", name), | |
1059 | url=url, |
|
1060 | url=url, | |
1060 | parity=parity, |
|
1061 | parity=parity, | |
1061 | shortdesc=get("web", "description", "unknown"), |
|
1062 | shortdesc=get("web", "description", "unknown"), | |
1062 | lastupdate=d) |
|
1063 | lastupdate=d) | |
1063 |
|
1064 | |||
1064 | parity = 1 - parity |
|
1065 | parity = 1 - parity | |
1065 |
|
1066 | |||
1066 | virtual = req.env.get("PATH_INFO", "").strip('/') |
|
1067 | virtual = req.env.get("PATH_INFO", "").strip('/') | |
1067 | if virtual: |
|
1068 | if virtual: | |
1068 | real = dict(self.repos).get(virtual) |
|
1069 | real = dict(self.repos).get(virtual) | |
1069 | if real: |
|
1070 | if real: | |
1070 | try: |
|
1071 | try: | |
1071 | hgweb(real).run(req) |
|
1072 | hgweb(real).run(req) | |
1072 | except IOError, inst: |
|
1073 | except IOError, inst: | |
1073 | req.write(tmpl("error", error=inst.strerror)) |
|
1074 | req.write(tmpl("error", error=inst.strerror)) | |
1074 | except hg.RepoError, inst: |
|
1075 | except hg.RepoError, inst: | |
1075 | req.write(tmpl("error", error=str(inst))) |
|
1076 | req.write(tmpl("error", error=str(inst))) | |
1076 | else: |
|
1077 | else: | |
1077 | req.write(tmpl("notfound", repo=virtual)) |
|
1078 | req.write(tmpl("notfound", repo=virtual)) | |
1078 | else: |
|
1079 | else: | |
1079 | if req.form.has_key('static'): |
|
1080 | if req.form.has_key('static'): | |
1080 | static = os.path.join(templater.templatepath(), "static") |
|
1081 | static = os.path.join(templater.templatepath(), "static") | |
1081 | fname = req.form['static'][0] |
|
1082 | fname = req.form['static'][0] | |
1082 | req.write(staticfile(static, fname) |
|
1083 | req.write(staticfile(static, fname) | |
1083 | or tmpl("error", error="%r not found" % fname)) |
|
1084 | or tmpl("error", error="%r not found" % fname)) | |
1084 | else: |
|
1085 | else: | |
1085 | req.write(tmpl("index", entries=entries)) |
|
1086 | req.write(tmpl("index", entries=entries)) |
@@ -1,814 +1,818 b'' | |||||
1 | """ |
|
1 | """ | |
2 | util.py - Mercurial utility functions and platform specfic implementations |
|
2 | util.py - Mercurial utility functions and platform specfic implementations | |
3 |
|
3 | |||
4 | Copyright 2005 K. Thananchayan <thananck@yahoo.com> |
|
4 | Copyright 2005 K. Thananchayan <thananck@yahoo.com> | |
5 |
|
5 | |||
6 | This software may be used and distributed according to the terms |
|
6 | This software may be used and distributed according to the terms | |
7 | of the GNU General Public License, incorporated herein by reference. |
|
7 | of the GNU General Public License, incorporated herein by reference. | |
8 |
|
8 | |||
9 | This contains helper routines that are independent of the SCM core and hide |
|
9 | This contains helper routines that are independent of the SCM core and hide | |
10 | platform-specific details from the core. |
|
10 | platform-specific details from the core. | |
11 | """ |
|
11 | """ | |
12 |
|
12 | |||
13 | import os, errno |
|
13 | import os, errno | |
14 | from i18n import gettext as _ |
|
14 | from i18n import gettext as _ | |
15 | from demandload import * |
|
15 | from demandload import * | |
16 | demandload(globals(), "cStringIO errno popen2 re shutil sys tempfile") |
|
16 | demandload(globals(), "cStringIO errno popen2 re shutil sys tempfile") | |
17 | demandload(globals(), "threading time") |
|
17 | demandload(globals(), "threading time") | |
18 |
|
18 | |||
19 | def pipefilter(s, cmd): |
|
19 | def pipefilter(s, cmd): | |
20 | '''filter string S through command CMD, returning its output''' |
|
20 | '''filter string S through command CMD, returning its output''' | |
21 | (pout, pin) = popen2.popen2(cmd, -1, 'b') |
|
21 | (pout, pin) = popen2.popen2(cmd, -1, 'b') | |
22 | def writer(): |
|
22 | def writer(): | |
|
23 | try: | |||
23 | pin.write(s) |
|
24 | pin.write(s) | |
24 | pin.close() |
|
25 | pin.close() | |
|
26 | except IOError, inst: | |||
|
27 | if inst.errno != errno.EPIPE: | |||
|
28 | raise | |||
25 |
|
29 | |||
26 | # we should use select instead on UNIX, but this will work on most |
|
30 | # we should use select instead on UNIX, but this will work on most | |
27 | # systems, including Windows |
|
31 | # systems, including Windows | |
28 | w = threading.Thread(target=writer) |
|
32 | w = threading.Thread(target=writer) | |
29 | w.start() |
|
33 | w.start() | |
30 | f = pout.read() |
|
34 | f = pout.read() | |
31 | pout.close() |
|
35 | pout.close() | |
32 | w.join() |
|
36 | w.join() | |
33 | return f |
|
37 | return f | |
34 |
|
38 | |||
35 | def tempfilter(s, cmd): |
|
39 | def tempfilter(s, cmd): | |
36 | '''filter string S through a pair of temporary files with CMD. |
|
40 | '''filter string S through a pair of temporary files with CMD. | |
37 | CMD is used as a template to create the real command to be run, |
|
41 | CMD is used as a template to create the real command to be run, | |
38 | with the strings INFILE and OUTFILE replaced by the real names of |
|
42 | with the strings INFILE and OUTFILE replaced by the real names of | |
39 | the temporary files generated.''' |
|
43 | the temporary files generated.''' | |
40 | inname, outname = None, None |
|
44 | inname, outname = None, None | |
41 | try: |
|
45 | try: | |
42 | infd, inname = tempfile.mkstemp(prefix='hgfin') |
|
46 | infd, inname = tempfile.mkstemp(prefix='hgfin') | |
43 | fp = os.fdopen(infd, 'wb') |
|
47 | fp = os.fdopen(infd, 'wb') | |
44 | fp.write(s) |
|
48 | fp.write(s) | |
45 | fp.close() |
|
49 | fp.close() | |
46 | outfd, outname = tempfile.mkstemp(prefix='hgfout') |
|
50 | outfd, outname = tempfile.mkstemp(prefix='hgfout') | |
47 | os.close(outfd) |
|
51 | os.close(outfd) | |
48 | cmd = cmd.replace('INFILE', inname) |
|
52 | cmd = cmd.replace('INFILE', inname) | |
49 | cmd = cmd.replace('OUTFILE', outname) |
|
53 | cmd = cmd.replace('OUTFILE', outname) | |
50 | code = os.system(cmd) |
|
54 | code = os.system(cmd) | |
51 | if code: raise Abort(_("command '%s' failed: %s") % |
|
55 | if code: raise Abort(_("command '%s' failed: %s") % | |
52 | (cmd, explain_exit(code))) |
|
56 | (cmd, explain_exit(code))) | |
53 | return open(outname, 'rb').read() |
|
57 | return open(outname, 'rb').read() | |
54 | finally: |
|
58 | finally: | |
55 | try: |
|
59 | try: | |
56 | if inname: os.unlink(inname) |
|
60 | if inname: os.unlink(inname) | |
57 | except: pass |
|
61 | except: pass | |
58 | try: |
|
62 | try: | |
59 | if outname: os.unlink(outname) |
|
63 | if outname: os.unlink(outname) | |
60 | except: pass |
|
64 | except: pass | |
61 |
|
65 | |||
62 | filtertable = { |
|
66 | filtertable = { | |
63 | 'tempfile:': tempfilter, |
|
67 | 'tempfile:': tempfilter, | |
64 | 'pipe:': pipefilter, |
|
68 | 'pipe:': pipefilter, | |
65 | } |
|
69 | } | |
66 |
|
70 | |||
67 | def filter(s, cmd): |
|
71 | def filter(s, cmd): | |
68 | "filter a string through a command that transforms its input to its output" |
|
72 | "filter a string through a command that transforms its input to its output" | |
69 | for name, fn in filtertable.iteritems(): |
|
73 | for name, fn in filtertable.iteritems(): | |
70 | if cmd.startswith(name): |
|
74 | if cmd.startswith(name): | |
71 | return fn(s, cmd[len(name):].lstrip()) |
|
75 | return fn(s, cmd[len(name):].lstrip()) | |
72 | return pipefilter(s, cmd) |
|
76 | return pipefilter(s, cmd) | |
73 |
|
77 | |||
74 | def find_in_path(name, path, default=None): |
|
78 | def find_in_path(name, path, default=None): | |
75 | '''find name in search path. path can be string (will be split |
|
79 | '''find name in search path. path can be string (will be split | |
76 | with os.pathsep), or iterable thing that returns strings. if name |
|
80 | with os.pathsep), or iterable thing that returns strings. if name | |
77 | found, return path to name. else return default.''' |
|
81 | found, return path to name. else return default.''' | |
78 | if isinstance(path, str): |
|
82 | if isinstance(path, str): | |
79 | path = path.split(os.pathsep) |
|
83 | path = path.split(os.pathsep) | |
80 | for p in path: |
|
84 | for p in path: | |
81 | p_name = os.path.join(p, name) |
|
85 | p_name = os.path.join(p, name) | |
82 | if os.path.exists(p_name): |
|
86 | if os.path.exists(p_name): | |
83 | return p_name |
|
87 | return p_name | |
84 | return default |
|
88 | return default | |
85 |
|
89 | |||
86 | def patch(strip, patchname, ui): |
|
90 | def patch(strip, patchname, ui): | |
87 | """apply the patch <patchname> to the working directory. |
|
91 | """apply the patch <patchname> to the working directory. | |
88 | a list of patched files is returned""" |
|
92 | a list of patched files is returned""" | |
89 | patcher = find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') |
|
93 | patcher = find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') | |
90 | fp = os.popen('"%s" -p%d < "%s"' % (patcher, strip, patchname)) |
|
94 | fp = os.popen('"%s" -p%d < "%s"' % (patcher, strip, patchname)) | |
91 | files = {} |
|
95 | files = {} | |
92 | for line in fp: |
|
96 | for line in fp: | |
93 | line = line.rstrip() |
|
97 | line = line.rstrip() | |
94 | ui.status("%s\n" % line) |
|
98 | ui.status("%s\n" % line) | |
95 | if line.startswith('patching file '): |
|
99 | if line.startswith('patching file '): | |
96 | pf = parse_patch_output(line) |
|
100 | pf = parse_patch_output(line) | |
97 | files.setdefault(pf, 1) |
|
101 | files.setdefault(pf, 1) | |
98 | code = fp.close() |
|
102 | code = fp.close() | |
99 | if code: |
|
103 | if code: | |
100 | raise Abort(_("patch command failed: %s") % explain_exit(code)[0]) |
|
104 | raise Abort(_("patch command failed: %s") % explain_exit(code)[0]) | |
101 | return files.keys() |
|
105 | return files.keys() | |
102 |
|
106 | |||
103 | def binary(s): |
|
107 | def binary(s): | |
104 | """return true if a string is binary data using diff's heuristic""" |
|
108 | """return true if a string is binary data using diff's heuristic""" | |
105 | if s and '\0' in s[:4096]: |
|
109 | if s and '\0' in s[:4096]: | |
106 | return True |
|
110 | return True | |
107 | return False |
|
111 | return False | |
108 |
|
112 | |||
109 | def unique(g): |
|
113 | def unique(g): | |
110 | """return the uniq elements of iterable g""" |
|
114 | """return the uniq elements of iterable g""" | |
111 | seen = {} |
|
115 | seen = {} | |
112 | for f in g: |
|
116 | for f in g: | |
113 | if f not in seen: |
|
117 | if f not in seen: | |
114 | seen[f] = 1 |
|
118 | seen[f] = 1 | |
115 | yield f |
|
119 | yield f | |
116 |
|
120 | |||
117 | class Abort(Exception): |
|
121 | class Abort(Exception): | |
118 | """Raised if a command needs to print an error and exit.""" |
|
122 | """Raised if a command needs to print an error and exit.""" | |
119 |
|
123 | |||
120 | def always(fn): return True |
|
124 | def always(fn): return True | |
121 | def never(fn): return False |
|
125 | def never(fn): return False | |
122 |
|
126 | |||
123 | def patkind(name, dflt_pat='glob'): |
|
127 | def patkind(name, dflt_pat='glob'): | |
124 | """Split a string into an optional pattern kind prefix and the |
|
128 | """Split a string into an optional pattern kind prefix and the | |
125 | actual pattern.""" |
|
129 | actual pattern.""" | |
126 | for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre': |
|
130 | for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre': | |
127 | if name.startswith(prefix + ':'): return name.split(':', 1) |
|
131 | if name.startswith(prefix + ':'): return name.split(':', 1) | |
128 | return dflt_pat, name |
|
132 | return dflt_pat, name | |
129 |
|
133 | |||
130 | def globre(pat, head='^', tail='$'): |
|
134 | def globre(pat, head='^', tail='$'): | |
131 | "convert a glob pattern into a regexp" |
|
135 | "convert a glob pattern into a regexp" | |
132 | i, n = 0, len(pat) |
|
136 | i, n = 0, len(pat) | |
133 | res = '' |
|
137 | res = '' | |
134 | group = False |
|
138 | group = False | |
135 | def peek(): return i < n and pat[i] |
|
139 | def peek(): return i < n and pat[i] | |
136 | while i < n: |
|
140 | while i < n: | |
137 | c = pat[i] |
|
141 | c = pat[i] | |
138 | i = i+1 |
|
142 | i = i+1 | |
139 | if c == '*': |
|
143 | if c == '*': | |
140 | if peek() == '*': |
|
144 | if peek() == '*': | |
141 | i += 1 |
|
145 | i += 1 | |
142 | res += '.*' |
|
146 | res += '.*' | |
143 | else: |
|
147 | else: | |
144 | res += '[^/]*' |
|
148 | res += '[^/]*' | |
145 | elif c == '?': |
|
149 | elif c == '?': | |
146 | res += '.' |
|
150 | res += '.' | |
147 | elif c == '[': |
|
151 | elif c == '[': | |
148 | j = i |
|
152 | j = i | |
149 | if j < n and pat[j] in '!]': |
|
153 | if j < n and pat[j] in '!]': | |
150 | j += 1 |
|
154 | j += 1 | |
151 | while j < n and pat[j] != ']': |
|
155 | while j < n and pat[j] != ']': | |
152 | j += 1 |
|
156 | j += 1 | |
153 | if j >= n: |
|
157 | if j >= n: | |
154 | res += '\\[' |
|
158 | res += '\\[' | |
155 | else: |
|
159 | else: | |
156 | stuff = pat[i:j].replace('\\','\\\\') |
|
160 | stuff = pat[i:j].replace('\\','\\\\') | |
157 | i = j + 1 |
|
161 | i = j + 1 | |
158 | if stuff[0] == '!': |
|
162 | if stuff[0] == '!': | |
159 | stuff = '^' + stuff[1:] |
|
163 | stuff = '^' + stuff[1:] | |
160 | elif stuff[0] == '^': |
|
164 | elif stuff[0] == '^': | |
161 | stuff = '\\' + stuff |
|
165 | stuff = '\\' + stuff | |
162 | res = '%s[%s]' % (res, stuff) |
|
166 | res = '%s[%s]' % (res, stuff) | |
163 | elif c == '{': |
|
167 | elif c == '{': | |
164 | group = True |
|
168 | group = True | |
165 | res += '(?:' |
|
169 | res += '(?:' | |
166 | elif c == '}' and group: |
|
170 | elif c == '}' and group: | |
167 | res += ')' |
|
171 | res += ')' | |
168 | group = False |
|
172 | group = False | |
169 | elif c == ',' and group: |
|
173 | elif c == ',' and group: | |
170 | res += '|' |
|
174 | res += '|' | |
171 | elif c == '\\': |
|
175 | elif c == '\\': | |
172 | p = peek() |
|
176 | p = peek() | |
173 | if p: |
|
177 | if p: | |
174 | i += 1 |
|
178 | i += 1 | |
175 | res += re.escape(p) |
|
179 | res += re.escape(p) | |
176 | else: |
|
180 | else: | |
177 | res += re.escape(c) |
|
181 | res += re.escape(c) | |
178 | else: |
|
182 | else: | |
179 | res += re.escape(c) |
|
183 | res += re.escape(c) | |
180 | return head + res + tail |
|
184 | return head + res + tail | |
181 |
|
185 | |||
182 | _globchars = {'[': 1, '{': 1, '*': 1, '?': 1} |
|
186 | _globchars = {'[': 1, '{': 1, '*': 1, '?': 1} | |
183 |
|
187 | |||
184 | def pathto(n1, n2): |
|
188 | def pathto(n1, n2): | |
185 | '''return the relative path from one place to another. |
|
189 | '''return the relative path from one place to another. | |
186 | this returns a path in the form used by the local filesystem, not hg.''' |
|
190 | this returns a path in the form used by the local filesystem, not hg.''' | |
187 | if not n1: return localpath(n2) |
|
191 | if not n1: return localpath(n2) | |
188 | a, b = n1.split('/'), n2.split('/') |
|
192 | a, b = n1.split('/'), n2.split('/') | |
189 | a.reverse() |
|
193 | a.reverse() | |
190 | b.reverse() |
|
194 | b.reverse() | |
191 | while a and b and a[-1] == b[-1]: |
|
195 | while a and b and a[-1] == b[-1]: | |
192 | a.pop() |
|
196 | a.pop() | |
193 | b.pop() |
|
197 | b.pop() | |
194 | b.reverse() |
|
198 | b.reverse() | |
195 | return os.sep.join((['..'] * len(a)) + b) |
|
199 | return os.sep.join((['..'] * len(a)) + b) | |
196 |
|
200 | |||
197 | def canonpath(root, cwd, myname): |
|
201 | def canonpath(root, cwd, myname): | |
198 | """return the canonical path of myname, given cwd and root""" |
|
202 | """return the canonical path of myname, given cwd and root""" | |
199 | if root == os.sep: |
|
203 | if root == os.sep: | |
200 | rootsep = os.sep |
|
204 | rootsep = os.sep | |
201 | else: |
|
205 | else: | |
202 | rootsep = root + os.sep |
|
206 | rootsep = root + os.sep | |
203 | name = myname |
|
207 | name = myname | |
204 | if not os.path.isabs(name): |
|
208 | if not os.path.isabs(name): | |
205 | name = os.path.join(root, cwd, name) |
|
209 | name = os.path.join(root, cwd, name) | |
206 | name = os.path.normpath(name) |
|
210 | name = os.path.normpath(name) | |
207 | if name.startswith(rootsep): |
|
211 | if name.startswith(rootsep): | |
208 | name = name[len(rootsep):] |
|
212 | name = name[len(rootsep):] | |
209 | audit_path(name) |
|
213 | audit_path(name) | |
210 | return pconvert(name) |
|
214 | return pconvert(name) | |
211 | elif name == root: |
|
215 | elif name == root: | |
212 | return '' |
|
216 | return '' | |
213 | else: |
|
217 | else: | |
214 | raise Abort('%s not under root' % myname) |
|
218 | raise Abort('%s not under root' % myname) | |
215 |
|
219 | |||
216 | def matcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None): |
|
220 | def matcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None): | |
217 | return _matcher(canonroot, cwd, names, inc, exc, head, 'glob', src) |
|
221 | return _matcher(canonroot, cwd, names, inc, exc, head, 'glob', src) | |
218 |
|
222 | |||
219 | def cmdmatcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None): |
|
223 | def cmdmatcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None): | |
220 | if os.name == 'nt': |
|
224 | if os.name == 'nt': | |
221 | dflt_pat = 'glob' |
|
225 | dflt_pat = 'glob' | |
222 | else: |
|
226 | else: | |
223 | dflt_pat = 'relpath' |
|
227 | dflt_pat = 'relpath' | |
224 | return _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src) |
|
228 | return _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src) | |
225 |
|
229 | |||
226 | def _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src): |
|
230 | def _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src): | |
227 | """build a function to match a set of file patterns |
|
231 | """build a function to match a set of file patterns | |
228 |
|
232 | |||
229 | arguments: |
|
233 | arguments: | |
230 | canonroot - the canonical root of the tree you're matching against |
|
234 | canonroot - the canonical root of the tree you're matching against | |
231 | cwd - the current working directory, if relevant |
|
235 | cwd - the current working directory, if relevant | |
232 | names - patterns to find |
|
236 | names - patterns to find | |
233 | inc - patterns to include |
|
237 | inc - patterns to include | |
234 | exc - patterns to exclude |
|
238 | exc - patterns to exclude | |
235 | head - a regex to prepend to patterns to control whether a match is rooted |
|
239 | head - a regex to prepend to patterns to control whether a match is rooted | |
236 |
|
240 | |||
237 | a pattern is one of: |
|
241 | a pattern is one of: | |
238 | 'glob:<rooted glob>' |
|
242 | 'glob:<rooted glob>' | |
239 | 're:<rooted regexp>' |
|
243 | 're:<rooted regexp>' | |
240 | 'path:<rooted path>' |
|
244 | 'path:<rooted path>' | |
241 | 'relglob:<relative glob>' |
|
245 | 'relglob:<relative glob>' | |
242 | 'relpath:<relative path>' |
|
246 | 'relpath:<relative path>' | |
243 | 'relre:<relative regexp>' |
|
247 | 'relre:<relative regexp>' | |
244 | '<rooted path or regexp>' |
|
248 | '<rooted path or regexp>' | |
245 |
|
249 | |||
246 | returns: |
|
250 | returns: | |
247 | a 3-tuple containing |
|
251 | a 3-tuple containing | |
248 | - list of explicit non-pattern names passed in |
|
252 | - list of explicit non-pattern names passed in | |
249 | - a bool match(filename) function |
|
253 | - a bool match(filename) function | |
250 | - a bool indicating if any patterns were passed in |
|
254 | - a bool indicating if any patterns were passed in | |
251 |
|
255 | |||
252 | todo: |
|
256 | todo: | |
253 | make head regex a rooted bool |
|
257 | make head regex a rooted bool | |
254 | """ |
|
258 | """ | |
255 |
|
259 | |||
256 | def contains_glob(name): |
|
260 | def contains_glob(name): | |
257 | for c in name: |
|
261 | for c in name: | |
258 | if c in _globchars: return True |
|
262 | if c in _globchars: return True | |
259 | return False |
|
263 | return False | |
260 |
|
264 | |||
261 | def regex(kind, name, tail): |
|
265 | def regex(kind, name, tail): | |
262 | '''convert a pattern into a regular expression''' |
|
266 | '''convert a pattern into a regular expression''' | |
263 | if kind == 're': |
|
267 | if kind == 're': | |
264 | return name |
|
268 | return name | |
265 | elif kind == 'path': |
|
269 | elif kind == 'path': | |
266 | return '^' + re.escape(name) + '(?:/|$)' |
|
270 | return '^' + re.escape(name) + '(?:/|$)' | |
267 | elif kind == 'relglob': |
|
271 | elif kind == 'relglob': | |
268 | return head + globre(name, '(?:|.*/)', tail) |
|
272 | return head + globre(name, '(?:|.*/)', tail) | |
269 | elif kind == 'relpath': |
|
273 | elif kind == 'relpath': | |
270 | return head + re.escape(name) + tail |
|
274 | return head + re.escape(name) + tail | |
271 | elif kind == 'relre': |
|
275 | elif kind == 'relre': | |
272 | if name.startswith('^'): |
|
276 | if name.startswith('^'): | |
273 | return name |
|
277 | return name | |
274 | return '.*' + name |
|
278 | return '.*' + name | |
275 | return head + globre(name, '', tail) |
|
279 | return head + globre(name, '', tail) | |
276 |
|
280 | |||
277 | def matchfn(pats, tail): |
|
281 | def matchfn(pats, tail): | |
278 | """build a matching function from a set of patterns""" |
|
282 | """build a matching function from a set of patterns""" | |
279 | if not pats: |
|
283 | if not pats: | |
280 | return |
|
284 | return | |
281 | matches = [] |
|
285 | matches = [] | |
282 | for k, p in pats: |
|
286 | for k, p in pats: | |
283 | try: |
|
287 | try: | |
284 | pat = '(?:%s)' % regex(k, p, tail) |
|
288 | pat = '(?:%s)' % regex(k, p, tail) | |
285 | matches.append(re.compile(pat).match) |
|
289 | matches.append(re.compile(pat).match) | |
286 | except re.error: |
|
290 | except re.error: | |
287 | if src: raise Abort("%s: invalid pattern (%s): %s" % (src, k, p)) |
|
291 | if src: raise Abort("%s: invalid pattern (%s): %s" % (src, k, p)) | |
288 | else: raise Abort("invalid pattern (%s): %s" % (k, p)) |
|
292 | else: raise Abort("invalid pattern (%s): %s" % (k, p)) | |
289 |
|
293 | |||
290 | def buildfn(text): |
|
294 | def buildfn(text): | |
291 | for m in matches: |
|
295 | for m in matches: | |
292 | r = m(text) |
|
296 | r = m(text) | |
293 | if r: |
|
297 | if r: | |
294 | return r |
|
298 | return r | |
295 |
|
299 | |||
296 | return buildfn |
|
300 | return buildfn | |
297 |
|
301 | |||
298 | def globprefix(pat): |
|
302 | def globprefix(pat): | |
299 | '''return the non-glob prefix of a path, e.g. foo/* -> foo''' |
|
303 | '''return the non-glob prefix of a path, e.g. foo/* -> foo''' | |
300 | root = [] |
|
304 | root = [] | |
301 | for p in pat.split(os.sep): |
|
305 | for p in pat.split(os.sep): | |
302 | if contains_glob(p): break |
|
306 | if contains_glob(p): break | |
303 | root.append(p) |
|
307 | root.append(p) | |
304 | return '/'.join(root) |
|
308 | return '/'.join(root) | |
305 |
|
309 | |||
306 | pats = [] |
|
310 | pats = [] | |
307 | files = [] |
|
311 | files = [] | |
308 | roots = [] |
|
312 | roots = [] | |
309 | for kind, name in [patkind(p, dflt_pat) for p in names]: |
|
313 | for kind, name in [patkind(p, dflt_pat) for p in names]: | |
310 | if kind in ('glob', 'relpath'): |
|
314 | if kind in ('glob', 'relpath'): | |
311 | name = canonpath(canonroot, cwd, name) |
|
315 | name = canonpath(canonroot, cwd, name) | |
312 | if name == '': |
|
316 | if name == '': | |
313 | kind, name = 'glob', '**' |
|
317 | kind, name = 'glob', '**' | |
314 | if kind in ('glob', 'path', 're'): |
|
318 | if kind in ('glob', 'path', 're'): | |
315 | pats.append((kind, name)) |
|
319 | pats.append((kind, name)) | |
316 | if kind == 'glob': |
|
320 | if kind == 'glob': | |
317 | root = globprefix(name) |
|
321 | root = globprefix(name) | |
318 | if root: roots.append(root) |
|
322 | if root: roots.append(root) | |
319 | elif kind == 'relpath': |
|
323 | elif kind == 'relpath': | |
320 | files.append((kind, name)) |
|
324 | files.append((kind, name)) | |
321 | roots.append(name) |
|
325 | roots.append(name) | |
322 |
|
326 | |||
323 | patmatch = matchfn(pats, '$') or always |
|
327 | patmatch = matchfn(pats, '$') or always | |
324 | filematch = matchfn(files, '(?:/|$)') or always |
|
328 | filematch = matchfn(files, '(?:/|$)') or always | |
325 | incmatch = always |
|
329 | incmatch = always | |
326 | if inc: |
|
330 | if inc: | |
327 | incmatch = matchfn(map(patkind, inc), '(?:/|$)') |
|
331 | incmatch = matchfn(map(patkind, inc), '(?:/|$)') | |
328 | excmatch = lambda fn: False |
|
332 | excmatch = lambda fn: False | |
329 | if exc: |
|
333 | if exc: | |
330 | excmatch = matchfn(map(patkind, exc), '(?:/|$)') |
|
334 | excmatch = matchfn(map(patkind, exc), '(?:/|$)') | |
331 |
|
335 | |||
332 | return (roots, |
|
336 | return (roots, | |
333 | lambda fn: (incmatch(fn) and not excmatch(fn) and |
|
337 | lambda fn: (incmatch(fn) and not excmatch(fn) and | |
334 | (fn.endswith('/') or |
|
338 | (fn.endswith('/') or | |
335 | (not pats and not files) or |
|
339 | (not pats and not files) or | |
336 | (pats and patmatch(fn)) or |
|
340 | (pats and patmatch(fn)) or | |
337 | (files and filematch(fn)))), |
|
341 | (files and filematch(fn)))), | |
338 | (inc or exc or (pats and pats != [('glob', '**')])) and True) |
|
342 | (inc or exc or (pats and pats != [('glob', '**')])) and True) | |
339 |
|
343 | |||
340 | def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None): |
|
344 | def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None): | |
341 | '''enhanced shell command execution. |
|
345 | '''enhanced shell command execution. | |
342 | run with environment maybe modified, maybe in different dir. |
|
346 | run with environment maybe modified, maybe in different dir. | |
343 |
|
347 | |||
344 | if command fails and onerr is None, return status. if ui object, |
|
348 | if command fails and onerr is None, return status. if ui object, | |
345 | print error message and return status, else raise onerr object as |
|
349 | print error message and return status, else raise onerr object as | |
346 | exception.''' |
|
350 | exception.''' | |
347 | oldenv = {} |
|
351 | oldenv = {} | |
348 | for k in environ: |
|
352 | for k in environ: | |
349 | oldenv[k] = os.environ.get(k) |
|
353 | oldenv[k] = os.environ.get(k) | |
350 | if cwd is not None: |
|
354 | if cwd is not None: | |
351 | oldcwd = os.getcwd() |
|
355 | oldcwd = os.getcwd() | |
352 | try: |
|
356 | try: | |
353 | for k, v in environ.iteritems(): |
|
357 | for k, v in environ.iteritems(): | |
354 | os.environ[k] = str(v) |
|
358 | os.environ[k] = str(v) | |
355 | if cwd is not None and oldcwd != cwd: |
|
359 | if cwd is not None and oldcwd != cwd: | |
356 | os.chdir(cwd) |
|
360 | os.chdir(cwd) | |
357 | rc = os.system(cmd) |
|
361 | rc = os.system(cmd) | |
358 | if rc and onerr: |
|
362 | if rc and onerr: | |
359 | errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]), |
|
363 | errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]), | |
360 | explain_exit(rc)[0]) |
|
364 | explain_exit(rc)[0]) | |
361 | if errprefix: |
|
365 | if errprefix: | |
362 | errmsg = '%s: %s' % (errprefix, errmsg) |
|
366 | errmsg = '%s: %s' % (errprefix, errmsg) | |
363 | try: |
|
367 | try: | |
364 | onerr.warn(errmsg + '\n') |
|
368 | onerr.warn(errmsg + '\n') | |
365 | except AttributeError: |
|
369 | except AttributeError: | |
366 | raise onerr(errmsg) |
|
370 | raise onerr(errmsg) | |
367 | return rc |
|
371 | return rc | |
368 | finally: |
|
372 | finally: | |
369 | for k, v in oldenv.iteritems(): |
|
373 | for k, v in oldenv.iteritems(): | |
370 | if v is None: |
|
374 | if v is None: | |
371 | del os.environ[k] |
|
375 | del os.environ[k] | |
372 | else: |
|
376 | else: | |
373 | os.environ[k] = v |
|
377 | os.environ[k] = v | |
374 | if cwd is not None and oldcwd != cwd: |
|
378 | if cwd is not None and oldcwd != cwd: | |
375 | os.chdir(oldcwd) |
|
379 | os.chdir(oldcwd) | |
376 |
|
380 | |||
377 | def rename(src, dst): |
|
381 | def rename(src, dst): | |
378 | """forcibly rename a file""" |
|
382 | """forcibly rename a file""" | |
379 | try: |
|
383 | try: | |
380 | os.rename(src, dst) |
|
384 | os.rename(src, dst) | |
381 | except: |
|
385 | except: | |
382 | os.unlink(dst) |
|
386 | os.unlink(dst) | |
383 | os.rename(src, dst) |
|
387 | os.rename(src, dst) | |
384 |
|
388 | |||
385 | def unlink(f): |
|
389 | def unlink(f): | |
386 | """unlink and remove the directory if it is empty""" |
|
390 | """unlink and remove the directory if it is empty""" | |
387 | os.unlink(f) |
|
391 | os.unlink(f) | |
388 | # try removing directories that might now be empty |
|
392 | # try removing directories that might now be empty | |
389 | try: |
|
393 | try: | |
390 | os.removedirs(os.path.dirname(f)) |
|
394 | os.removedirs(os.path.dirname(f)) | |
391 | except OSError: |
|
395 | except OSError: | |
392 | pass |
|
396 | pass | |
393 |
|
397 | |||
394 | def copyfiles(src, dst, hardlink=None): |
|
398 | def copyfiles(src, dst, hardlink=None): | |
395 | """Copy a directory tree using hardlinks if possible""" |
|
399 | """Copy a directory tree using hardlinks if possible""" | |
396 |
|
400 | |||
397 | if hardlink is None: |
|
401 | if hardlink is None: | |
398 | hardlink = (os.stat(src).st_dev == |
|
402 | hardlink = (os.stat(src).st_dev == | |
399 | os.stat(os.path.dirname(dst)).st_dev) |
|
403 | os.stat(os.path.dirname(dst)).st_dev) | |
400 |
|
404 | |||
401 | if os.path.isdir(src): |
|
405 | if os.path.isdir(src): | |
402 | os.mkdir(dst) |
|
406 | os.mkdir(dst) | |
403 | for name in os.listdir(src): |
|
407 | for name in os.listdir(src): | |
404 | srcname = os.path.join(src, name) |
|
408 | srcname = os.path.join(src, name) | |
405 | dstname = os.path.join(dst, name) |
|
409 | dstname = os.path.join(dst, name) | |
406 | copyfiles(srcname, dstname, hardlink) |
|
410 | copyfiles(srcname, dstname, hardlink) | |
407 | else: |
|
411 | else: | |
408 | if hardlink: |
|
412 | if hardlink: | |
409 | try: |
|
413 | try: | |
410 | os_link(src, dst) |
|
414 | os_link(src, dst) | |
411 | except (IOError, OSError): |
|
415 | except (IOError, OSError): | |
412 | hardlink = False |
|
416 | hardlink = False | |
413 | shutil.copy(src, dst) |
|
417 | shutil.copy(src, dst) | |
414 | else: |
|
418 | else: | |
415 | shutil.copy(src, dst) |
|
419 | shutil.copy(src, dst) | |
416 |
|
420 | |||
417 | def audit_path(path): |
|
421 | def audit_path(path): | |
418 | """Abort if path contains dangerous components""" |
|
422 | """Abort if path contains dangerous components""" | |
419 | parts = os.path.normcase(path).split(os.sep) |
|
423 | parts = os.path.normcase(path).split(os.sep) | |
420 | if (os.path.splitdrive(path)[0] or parts[0] in ('.hg', '') |
|
424 | if (os.path.splitdrive(path)[0] or parts[0] in ('.hg', '') | |
421 | or os.pardir in parts): |
|
425 | or os.pardir in parts): | |
422 | raise Abort(_("path contains illegal component: %s\n") % path) |
|
426 | raise Abort(_("path contains illegal component: %s\n") % path) | |
423 |
|
427 | |||
424 | def opener(base, audit=True): |
|
428 | def opener(base, audit=True): | |
425 | """ |
|
429 | """ | |
426 | return a function that opens files relative to base |
|
430 | return a function that opens files relative to base | |
427 |
|
431 | |||
428 | this function is used to hide the details of COW semantics and |
|
432 | this function is used to hide the details of COW semantics and | |
429 | remote file access from higher level code. |
|
433 | remote file access from higher level code. | |
430 | """ |
|
434 | """ | |
431 | p = base |
|
435 | p = base | |
432 | audit_p = audit |
|
436 | audit_p = audit | |
433 |
|
437 | |||
434 | def mktempcopy(name): |
|
438 | def mktempcopy(name): | |
435 | d, fn = os.path.split(name) |
|
439 | d, fn = os.path.split(name) | |
436 | fd, temp = tempfile.mkstemp(prefix=fn, dir=d) |
|
440 | fd, temp = tempfile.mkstemp(prefix=fn, dir=d) | |
437 | fp = os.fdopen(fd, "wb") |
|
441 | fp = os.fdopen(fd, "wb") | |
438 | try: |
|
442 | try: | |
439 | fp.write(file(name, "rb").read()) |
|
443 | fp.write(file(name, "rb").read()) | |
440 | except: |
|
444 | except: | |
441 | try: os.unlink(temp) |
|
445 | try: os.unlink(temp) | |
442 | except: pass |
|
446 | except: pass | |
443 | raise |
|
447 | raise | |
444 | fp.close() |
|
448 | fp.close() | |
445 | st = os.lstat(name) |
|
449 | st = os.lstat(name) | |
446 | os.chmod(temp, st.st_mode) |
|
450 | os.chmod(temp, st.st_mode) | |
447 | return temp |
|
451 | return temp | |
448 |
|
452 | |||
449 | class atomictempfile(file): |
|
453 | class atomictempfile(file): | |
450 | """the file will only be copied when rename is called""" |
|
454 | """the file will only be copied when rename is called""" | |
451 | def __init__(self, name, mode): |
|
455 | def __init__(self, name, mode): | |
452 | self.__name = name |
|
456 | self.__name = name | |
453 | self.temp = mktempcopy(name) |
|
457 | self.temp = mktempcopy(name) | |
454 | file.__init__(self, self.temp, mode) |
|
458 | file.__init__(self, self.temp, mode) | |
455 | def rename(self): |
|
459 | def rename(self): | |
456 | if not self.closed: |
|
460 | if not self.closed: | |
457 | file.close(self) |
|
461 | file.close(self) | |
458 | rename(self.temp, self.__name) |
|
462 | rename(self.temp, self.__name) | |
459 | def __del__(self): |
|
463 | def __del__(self): | |
460 | if not self.closed: |
|
464 | if not self.closed: | |
461 | try: |
|
465 | try: | |
462 | os.unlink(self.temp) |
|
466 | os.unlink(self.temp) | |
463 | except: pass |
|
467 | except: pass | |
464 | file.close(self) |
|
468 | file.close(self) | |
465 |
|
469 | |||
466 | class atomicfile(atomictempfile): |
|
470 | class atomicfile(atomictempfile): | |
467 | """the file will only be copied on close""" |
|
471 | """the file will only be copied on close""" | |
468 | def __init__(self, name, mode): |
|
472 | def __init__(self, name, mode): | |
469 | atomictempfile.__init__(self, name, mode) |
|
473 | atomictempfile.__init__(self, name, mode) | |
470 | def close(self): |
|
474 | def close(self): | |
471 | self.rename() |
|
475 | self.rename() | |
472 | def __del__(self): |
|
476 | def __del__(self): | |
473 | self.rename() |
|
477 | self.rename() | |
474 |
|
478 | |||
475 | def o(path, mode="r", text=False, atomic=False, atomictemp=False): |
|
479 | def o(path, mode="r", text=False, atomic=False, atomictemp=False): | |
476 | if audit_p: |
|
480 | if audit_p: | |
477 | audit_path(path) |
|
481 | audit_path(path) | |
478 | f = os.path.join(p, path) |
|
482 | f = os.path.join(p, path) | |
479 |
|
483 | |||
480 | if not text: |
|
484 | if not text: | |
481 | mode += "b" # for that other OS |
|
485 | mode += "b" # for that other OS | |
482 |
|
486 | |||
483 | if mode[0] != "r": |
|
487 | if mode[0] != "r": | |
484 | try: |
|
488 | try: | |
485 | nlink = nlinks(f) |
|
489 | nlink = nlinks(f) | |
486 | except OSError: |
|
490 | except OSError: | |
487 | d = os.path.dirname(f) |
|
491 | d = os.path.dirname(f) | |
488 | if not os.path.isdir(d): |
|
492 | if not os.path.isdir(d): | |
489 | os.makedirs(d) |
|
493 | os.makedirs(d) | |
490 | else: |
|
494 | else: | |
491 | if atomic: |
|
495 | if atomic: | |
492 | return atomicfile(f, mode) |
|
496 | return atomicfile(f, mode) | |
493 | elif atomictemp: |
|
497 | elif atomictemp: | |
494 | return atomictempfile(f, mode) |
|
498 | return atomictempfile(f, mode) | |
495 | if nlink > 1: |
|
499 | if nlink > 1: | |
496 | rename(mktempcopy(f), f) |
|
500 | rename(mktempcopy(f), f) | |
497 | return file(f, mode) |
|
501 | return file(f, mode) | |
498 |
|
502 | |||
499 | return o |
|
503 | return o | |
500 |
|
504 | |||
501 | def _makelock_file(info, pathname): |
|
505 | def _makelock_file(info, pathname): | |
502 | ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL) |
|
506 | ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL) | |
503 | os.write(ld, info) |
|
507 | os.write(ld, info) | |
504 | os.close(ld) |
|
508 | os.close(ld) | |
505 |
|
509 | |||
506 | def _readlock_file(pathname): |
|
510 | def _readlock_file(pathname): | |
507 | return file(pathname).read() |
|
511 | return file(pathname).read() | |
508 |
|
512 | |||
509 | def nlinks(pathname): |
|
513 | def nlinks(pathname): | |
510 | """Return number of hardlinks for the given file.""" |
|
514 | """Return number of hardlinks for the given file.""" | |
511 | return os.stat(pathname).st_nlink |
|
515 | return os.stat(pathname).st_nlink | |
512 |
|
516 | |||
513 | if hasattr(os, 'link'): |
|
517 | if hasattr(os, 'link'): | |
514 | os_link = os.link |
|
518 | os_link = os.link | |
515 | else: |
|
519 | else: | |
516 | def os_link(src, dst): |
|
520 | def os_link(src, dst): | |
517 | raise OSError(0, _("Hardlinks not supported")) |
|
521 | raise OSError(0, _("Hardlinks not supported")) | |
518 |
|
522 | |||
519 | # Platform specific variants |
|
523 | # Platform specific variants | |
520 | if os.name == 'nt': |
|
524 | if os.name == 'nt': | |
521 | demandload(globals(), "msvcrt") |
|
525 | demandload(globals(), "msvcrt") | |
522 | nulldev = 'NUL:' |
|
526 | nulldev = 'NUL:' | |
523 |
|
527 | |||
524 | class winstdout: |
|
528 | class winstdout: | |
525 | '''stdout on windows misbehaves if sent through a pipe''' |
|
529 | '''stdout on windows misbehaves if sent through a pipe''' | |
526 |
|
530 | |||
527 | def __init__(self, fp): |
|
531 | def __init__(self, fp): | |
528 | self.fp = fp |
|
532 | self.fp = fp | |
529 |
|
533 | |||
530 | def __getattr__(self, key): |
|
534 | def __getattr__(self, key): | |
531 | return getattr(self.fp, key) |
|
535 | return getattr(self.fp, key) | |
532 |
|
536 | |||
533 | def close(self): |
|
537 | def close(self): | |
534 | try: |
|
538 | try: | |
535 | self.fp.close() |
|
539 | self.fp.close() | |
536 | except: pass |
|
540 | except: pass | |
537 |
|
541 | |||
538 | def write(self, s): |
|
542 | def write(self, s): | |
539 | try: |
|
543 | try: | |
540 | return self.fp.write(s) |
|
544 | return self.fp.write(s) | |
541 | except IOError, inst: |
|
545 | except IOError, inst: | |
542 | if inst.errno != 0: raise |
|
546 | if inst.errno != 0: raise | |
543 | self.close() |
|
547 | self.close() | |
544 | raise IOError(errno.EPIPE, 'Broken pipe') |
|
548 | raise IOError(errno.EPIPE, 'Broken pipe') | |
545 |
|
549 | |||
546 | sys.stdout = winstdout(sys.stdout) |
|
550 | sys.stdout = winstdout(sys.stdout) | |
547 |
|
551 | |||
548 | def system_rcpath(): |
|
552 | def system_rcpath(): | |
549 | return [r'c:\mercurial\mercurial.ini'] |
|
553 | return [r'c:\mercurial\mercurial.ini'] | |
550 |
|
554 | |||
551 | def os_rcpath(): |
|
555 | def os_rcpath(): | |
552 | '''return default os-specific hgrc search path''' |
|
556 | '''return default os-specific hgrc search path''' | |
553 | return system_rcpath() + [os.path.join(os.path.expanduser('~'), |
|
557 | return system_rcpath() + [os.path.join(os.path.expanduser('~'), | |
554 | 'mercurial.ini')] |
|
558 | 'mercurial.ini')] | |
555 |
|
559 | |||
556 | def parse_patch_output(output_line): |
|
560 | def parse_patch_output(output_line): | |
557 | """parses the output produced by patch and returns the file name""" |
|
561 | """parses the output produced by patch and returns the file name""" | |
558 | pf = output_line[14:] |
|
562 | pf = output_line[14:] | |
559 | if pf[0] == '`': |
|
563 | if pf[0] == '`': | |
560 | pf = pf[1:-1] # Remove the quotes |
|
564 | pf = pf[1:-1] # Remove the quotes | |
561 | return pf |
|
565 | return pf | |
562 |
|
566 | |||
563 | def testpid(pid): |
|
567 | def testpid(pid): | |
564 | '''return False if pid dead, True if running or not known''' |
|
568 | '''return False if pid dead, True if running or not known''' | |
565 | return True |
|
569 | return True | |
566 |
|
570 | |||
567 | def is_exec(f, last): |
|
571 | def is_exec(f, last): | |
568 | return last |
|
572 | return last | |
569 |
|
573 | |||
570 | def set_exec(f, mode): |
|
574 | def set_exec(f, mode): | |
571 | pass |
|
575 | pass | |
572 |
|
576 | |||
573 | def set_binary(fd): |
|
577 | def set_binary(fd): | |
574 | msvcrt.setmode(fd.fileno(), os.O_BINARY) |
|
578 | msvcrt.setmode(fd.fileno(), os.O_BINARY) | |
575 |
|
579 | |||
576 | def pconvert(path): |
|
580 | def pconvert(path): | |
577 | return path.replace("\\", "/") |
|
581 | return path.replace("\\", "/") | |
578 |
|
582 | |||
579 | def localpath(path): |
|
583 | def localpath(path): | |
580 | return path.replace('/', '\\') |
|
584 | return path.replace('/', '\\') | |
581 |
|
585 | |||
582 | def normpath(path): |
|
586 | def normpath(path): | |
583 | return pconvert(os.path.normpath(path)) |
|
587 | return pconvert(os.path.normpath(path)) | |
584 |
|
588 | |||
585 | makelock = _makelock_file |
|
589 | makelock = _makelock_file | |
586 | readlock = _readlock_file |
|
590 | readlock = _readlock_file | |
587 |
|
591 | |||
588 | def explain_exit(code): |
|
592 | def explain_exit(code): | |
589 | return _("exited with status %d") % code, code |
|
593 | return _("exited with status %d") % code, code | |
590 |
|
594 | |||
591 | try: |
|
595 | try: | |
592 | # override functions with win32 versions if possible |
|
596 | # override functions with win32 versions if possible | |
593 | from util_win32 import * |
|
597 | from util_win32 import * | |
594 | except ImportError: |
|
598 | except ImportError: | |
595 | pass |
|
599 | pass | |
596 |
|
600 | |||
597 | else: |
|
601 | else: | |
598 | nulldev = '/dev/null' |
|
602 | nulldev = '/dev/null' | |
599 |
|
603 | |||
600 | def rcfiles(path): |
|
604 | def rcfiles(path): | |
601 | rcs = [os.path.join(path, 'hgrc')] |
|
605 | rcs = [os.path.join(path, 'hgrc')] | |
602 | rcdir = os.path.join(path, 'hgrc.d') |
|
606 | rcdir = os.path.join(path, 'hgrc.d') | |
603 | try: |
|
607 | try: | |
604 | rcs.extend([os.path.join(rcdir, f) for f in os.listdir(rcdir) |
|
608 | rcs.extend([os.path.join(rcdir, f) for f in os.listdir(rcdir) | |
605 | if f.endswith(".rc")]) |
|
609 | if f.endswith(".rc")]) | |
606 | except OSError, inst: pass |
|
610 | except OSError, inst: pass | |
607 | return rcs |
|
611 | return rcs | |
608 |
|
612 | |||
609 | def os_rcpath(): |
|
613 | def os_rcpath(): | |
610 | '''return default os-specific hgrc search path''' |
|
614 | '''return default os-specific hgrc search path''' | |
611 | path = [] |
|
615 | path = [] | |
612 | if len(sys.argv) > 0: |
|
616 | if len(sys.argv) > 0: | |
613 | path.extend(rcfiles(os.path.dirname(sys.argv[0]) + |
|
617 | path.extend(rcfiles(os.path.dirname(sys.argv[0]) + | |
614 | '/../etc/mercurial')) |
|
618 | '/../etc/mercurial')) | |
615 | path.extend(rcfiles('/etc/mercurial')) |
|
619 | path.extend(rcfiles('/etc/mercurial')) | |
616 | path.append(os.path.expanduser('~/.hgrc')) |
|
620 | path.append(os.path.expanduser('~/.hgrc')) | |
617 | path = [os.path.normpath(f) for f in path] |
|
621 | path = [os.path.normpath(f) for f in path] | |
618 | return path |
|
622 | return path | |
619 |
|
623 | |||
620 | def parse_patch_output(output_line): |
|
624 | def parse_patch_output(output_line): | |
621 | """parses the output produced by patch and returns the file name""" |
|
625 | """parses the output produced by patch and returns the file name""" | |
622 | pf = output_line[14:] |
|
626 | pf = output_line[14:] | |
623 | if pf.startswith("'") and pf.endswith("'") and pf.find(" ") >= 0: |
|
627 | if pf.startswith("'") and pf.endswith("'") and pf.find(" ") >= 0: | |
624 | pf = pf[1:-1] # Remove the quotes |
|
628 | pf = pf[1:-1] # Remove the quotes | |
625 | return pf |
|
629 | return pf | |
626 |
|
630 | |||
627 | def is_exec(f, last): |
|
631 | def is_exec(f, last): | |
628 | """check whether a file is executable""" |
|
632 | """check whether a file is executable""" | |
629 | return (os.stat(f).st_mode & 0100 != 0) |
|
633 | return (os.stat(f).st_mode & 0100 != 0) | |
630 |
|
634 | |||
631 | def set_exec(f, mode): |
|
635 | def set_exec(f, mode): | |
632 | s = os.stat(f).st_mode |
|
636 | s = os.stat(f).st_mode | |
633 | if (s & 0100 != 0) == mode: |
|
637 | if (s & 0100 != 0) == mode: | |
634 | return |
|
638 | return | |
635 | if mode: |
|
639 | if mode: | |
636 | # Turn on +x for every +r bit when making a file executable |
|
640 | # Turn on +x for every +r bit when making a file executable | |
637 | # and obey umask. |
|
641 | # and obey umask. | |
638 | umask = os.umask(0) |
|
642 | umask = os.umask(0) | |
639 | os.umask(umask) |
|
643 | os.umask(umask) | |
640 | os.chmod(f, s | (s & 0444) >> 2 & ~umask) |
|
644 | os.chmod(f, s | (s & 0444) >> 2 & ~umask) | |
641 | else: |
|
645 | else: | |
642 | os.chmod(f, s & 0666) |
|
646 | os.chmod(f, s & 0666) | |
643 |
|
647 | |||
644 | def set_binary(fd): |
|
648 | def set_binary(fd): | |
645 | pass |
|
649 | pass | |
646 |
|
650 | |||
647 | def pconvert(path): |
|
651 | def pconvert(path): | |
648 | return path |
|
652 | return path | |
649 |
|
653 | |||
650 | def localpath(path): |
|
654 | def localpath(path): | |
651 | return path |
|
655 | return path | |
652 |
|
656 | |||
653 | normpath = os.path.normpath |
|
657 | normpath = os.path.normpath | |
654 |
|
658 | |||
655 | def makelock(info, pathname): |
|
659 | def makelock(info, pathname): | |
656 | try: |
|
660 | try: | |
657 | os.symlink(info, pathname) |
|
661 | os.symlink(info, pathname) | |
658 | except OSError, why: |
|
662 | except OSError, why: | |
659 | if why.errno == errno.EEXIST: |
|
663 | if why.errno == errno.EEXIST: | |
660 | raise |
|
664 | raise | |
661 | else: |
|
665 | else: | |
662 | _makelock_file(info, pathname) |
|
666 | _makelock_file(info, pathname) | |
663 |
|
667 | |||
664 | def readlock(pathname): |
|
668 | def readlock(pathname): | |
665 | try: |
|
669 | try: | |
666 | return os.readlink(pathname) |
|
670 | return os.readlink(pathname) | |
667 | except OSError, why: |
|
671 | except OSError, why: | |
668 | if why.errno == errno.EINVAL: |
|
672 | if why.errno == errno.EINVAL: | |
669 | return _readlock_file(pathname) |
|
673 | return _readlock_file(pathname) | |
670 | else: |
|
674 | else: | |
671 | raise |
|
675 | raise | |
672 |
|
676 | |||
673 | def testpid(pid): |
|
677 | def testpid(pid): | |
674 | '''return False if pid dead, True if running or not sure''' |
|
678 | '''return False if pid dead, True if running or not sure''' | |
675 | try: |
|
679 | try: | |
676 | os.kill(pid, 0) |
|
680 | os.kill(pid, 0) | |
677 | return True |
|
681 | return True | |
678 | except OSError, inst: |
|
682 | except OSError, inst: | |
679 | return inst.errno != errno.ESRCH |
|
683 | return inst.errno != errno.ESRCH | |
680 |
|
684 | |||
681 | def explain_exit(code): |
|
685 | def explain_exit(code): | |
682 | """return a 2-tuple (desc, code) describing a process's status""" |
|
686 | """return a 2-tuple (desc, code) describing a process's status""" | |
683 | if os.WIFEXITED(code): |
|
687 | if os.WIFEXITED(code): | |
684 | val = os.WEXITSTATUS(code) |
|
688 | val = os.WEXITSTATUS(code) | |
685 | return _("exited with status %d") % val, val |
|
689 | return _("exited with status %d") % val, val | |
686 | elif os.WIFSIGNALED(code): |
|
690 | elif os.WIFSIGNALED(code): | |
687 | val = os.WTERMSIG(code) |
|
691 | val = os.WTERMSIG(code) | |
688 | return _("killed by signal %d") % val, val |
|
692 | return _("killed by signal %d") % val, val | |
689 | elif os.WIFSTOPPED(code): |
|
693 | elif os.WIFSTOPPED(code): | |
690 | val = os.WSTOPSIG(code) |
|
694 | val = os.WSTOPSIG(code) | |
691 | return _("stopped by signal %d") % val, val |
|
695 | return _("stopped by signal %d") % val, val | |
692 | raise ValueError(_("invalid exit code")) |
|
696 | raise ValueError(_("invalid exit code")) | |
693 |
|
697 | |||
694 | class chunkbuffer(object): |
|
698 | class chunkbuffer(object): | |
695 | """Allow arbitrary sized chunks of data to be efficiently read from an |
|
699 | """Allow arbitrary sized chunks of data to be efficiently read from an | |
696 | iterator over chunks of arbitrary size.""" |
|
700 | iterator over chunks of arbitrary size.""" | |
697 |
|
701 | |||
698 | def __init__(self, in_iter, targetsize = 2**16): |
|
702 | def __init__(self, in_iter, targetsize = 2**16): | |
699 | """in_iter is the iterator that's iterating over the input chunks. |
|
703 | """in_iter is the iterator that's iterating over the input chunks. | |
700 | targetsize is how big a buffer to try to maintain.""" |
|
704 | targetsize is how big a buffer to try to maintain.""" | |
701 | self.in_iter = iter(in_iter) |
|
705 | self.in_iter = iter(in_iter) | |
702 | self.buf = '' |
|
706 | self.buf = '' | |
703 | self.targetsize = int(targetsize) |
|
707 | self.targetsize = int(targetsize) | |
704 | if self.targetsize <= 0: |
|
708 | if self.targetsize <= 0: | |
705 | raise ValueError(_("targetsize must be greater than 0, was %d") % |
|
709 | raise ValueError(_("targetsize must be greater than 0, was %d") % | |
706 | targetsize) |
|
710 | targetsize) | |
707 | self.iterempty = False |
|
711 | self.iterempty = False | |
708 |
|
712 | |||
709 | def fillbuf(self): |
|
713 | def fillbuf(self): | |
710 | """Ignore target size; read every chunk from iterator until empty.""" |
|
714 | """Ignore target size; read every chunk from iterator until empty.""" | |
711 | if not self.iterempty: |
|
715 | if not self.iterempty: | |
712 | collector = cStringIO.StringIO() |
|
716 | collector = cStringIO.StringIO() | |
713 | collector.write(self.buf) |
|
717 | collector.write(self.buf) | |
714 | for ch in self.in_iter: |
|
718 | for ch in self.in_iter: | |
715 | collector.write(ch) |
|
719 | collector.write(ch) | |
716 | self.buf = collector.getvalue() |
|
720 | self.buf = collector.getvalue() | |
717 | self.iterempty = True |
|
721 | self.iterempty = True | |
718 |
|
722 | |||
719 | def read(self, l): |
|
723 | def read(self, l): | |
720 | """Read L bytes of data from the iterator of chunks of data. |
|
724 | """Read L bytes of data from the iterator of chunks of data. | |
721 | Returns less than L bytes if the iterator runs dry.""" |
|
725 | Returns less than L bytes if the iterator runs dry.""" | |
722 | if l > len(self.buf) and not self.iterempty: |
|
726 | if l > len(self.buf) and not self.iterempty: | |
723 | # Clamp to a multiple of self.targetsize |
|
727 | # Clamp to a multiple of self.targetsize | |
724 | targetsize = self.targetsize * ((l // self.targetsize) + 1) |
|
728 | targetsize = self.targetsize * ((l // self.targetsize) + 1) | |
725 | collector = cStringIO.StringIO() |
|
729 | collector = cStringIO.StringIO() | |
726 | collector.write(self.buf) |
|
730 | collector.write(self.buf) | |
727 | collected = len(self.buf) |
|
731 | collected = len(self.buf) | |
728 | for chunk in self.in_iter: |
|
732 | for chunk in self.in_iter: | |
729 | collector.write(chunk) |
|
733 | collector.write(chunk) | |
730 | collected += len(chunk) |
|
734 | collected += len(chunk) | |
731 | if collected >= targetsize: |
|
735 | if collected >= targetsize: | |
732 | break |
|
736 | break | |
733 | if collected < targetsize: |
|
737 | if collected < targetsize: | |
734 | self.iterempty = True |
|
738 | self.iterempty = True | |
735 | self.buf = collector.getvalue() |
|
739 | self.buf = collector.getvalue() | |
736 | s, self.buf = self.buf[:l], buffer(self.buf, l) |
|
740 | s, self.buf = self.buf[:l], buffer(self.buf, l) | |
737 | return s |
|
741 | return s | |
738 |
|
742 | |||
739 | def filechunkiter(f, size = 65536): |
|
743 | def filechunkiter(f, size = 65536): | |
740 | """Create a generator that produces all the data in the file size |
|
744 | """Create a generator that produces all the data in the file size | |
741 | (default 65536) bytes at a time. Chunks may be less than size |
|
745 | (default 65536) bytes at a time. Chunks may be less than size | |
742 | bytes if the chunk is the last chunk in the file, or the file is a |
|
746 | bytes if the chunk is the last chunk in the file, or the file is a | |
743 | socket or some other type of file that sometimes reads less data |
|
747 | socket or some other type of file that sometimes reads less data | |
744 | than is requested.""" |
|
748 | than is requested.""" | |
745 | s = f.read(size) |
|
749 | s = f.read(size) | |
746 | while len(s) > 0: |
|
750 | while len(s) > 0: | |
747 | yield s |
|
751 | yield s | |
748 | s = f.read(size) |
|
752 | s = f.read(size) | |
749 |
|
753 | |||
750 | def makedate(): |
|
754 | def makedate(): | |
751 | lt = time.localtime() |
|
755 | lt = time.localtime() | |
752 | if lt[8] == 1 and time.daylight: |
|
756 | if lt[8] == 1 and time.daylight: | |
753 | tz = time.altzone |
|
757 | tz = time.altzone | |
754 | else: |
|
758 | else: | |
755 | tz = time.timezone |
|
759 | tz = time.timezone | |
756 | return time.mktime(lt), tz |
|
760 | return time.mktime(lt), tz | |
757 |
|
761 | |||
758 | def datestr(date=None, format='%a %b %d %H:%M:%S %Y', timezone=True): |
|
762 | def datestr(date=None, format='%a %b %d %H:%M:%S %Y', timezone=True): | |
759 | """represent a (unixtime, offset) tuple as a localized time. |
|
763 | """represent a (unixtime, offset) tuple as a localized time. | |
760 | unixtime is seconds since the epoch, and offset is the time zone's |
|
764 | unixtime is seconds since the epoch, and offset is the time zone's | |
761 | number of seconds away from UTC. if timezone is false, do not |
|
765 | number of seconds away from UTC. if timezone is false, do not | |
762 | append time zone to string.""" |
|
766 | append time zone to string.""" | |
763 | t, tz = date or makedate() |
|
767 | t, tz = date or makedate() | |
764 | s = time.strftime(format, time.gmtime(float(t) - tz)) |
|
768 | s = time.strftime(format, time.gmtime(float(t) - tz)) | |
765 | if timezone: |
|
769 | if timezone: | |
766 | s += " %+03d%02d" % (-tz / 3600, ((-tz % 3600) / 60)) |
|
770 | s += " %+03d%02d" % (-tz / 3600, ((-tz % 3600) / 60)) | |
767 | return s |
|
771 | return s | |
768 |
|
772 | |||
769 | def shortuser(user): |
|
773 | def shortuser(user): | |
770 | """Return a short representation of a user name or email address.""" |
|
774 | """Return a short representation of a user name or email address.""" | |
771 | f = user.find('@') |
|
775 | f = user.find('@') | |
772 | if f >= 0: |
|
776 | if f >= 0: | |
773 | user = user[:f] |
|
777 | user = user[:f] | |
774 | f = user.find('<') |
|
778 | f = user.find('<') | |
775 | if f >= 0: |
|
779 | if f >= 0: | |
776 | user = user[f+1:] |
|
780 | user = user[f+1:] | |
777 | return user |
|
781 | return user | |
778 |
|
782 | |||
779 | def walkrepos(path): |
|
783 | def walkrepos(path): | |
780 | '''yield every hg repository under path, recursively.''' |
|
784 | '''yield every hg repository under path, recursively.''' | |
781 | def errhandler(err): |
|
785 | def errhandler(err): | |
782 | if err.filename == path: |
|
786 | if err.filename == path: | |
783 | raise err |
|
787 | raise err | |
784 |
|
788 | |||
785 | for root, dirs, files in os.walk(path, onerror=errhandler): |
|
789 | for root, dirs, files in os.walk(path, onerror=errhandler): | |
786 | for d in dirs: |
|
790 | for d in dirs: | |
787 | if d == '.hg': |
|
791 | if d == '.hg': | |
788 | yield root |
|
792 | yield root | |
789 | dirs[:] = [] |
|
793 | dirs[:] = [] | |
790 | break |
|
794 | break | |
791 |
|
795 | |||
792 | _rcpath = None |
|
796 | _rcpath = None | |
793 |
|
797 | |||
794 | def rcpath(): |
|
798 | def rcpath(): | |
795 | '''return hgrc search path. if env var HGRCPATH is set, use it. |
|
799 | '''return hgrc search path. if env var HGRCPATH is set, use it. | |
796 | for each item in path, if directory, use files ending in .rc, |
|
800 | for each item in path, if directory, use files ending in .rc, | |
797 | else use item. |
|
801 | else use item. | |
798 | make HGRCPATH empty to only look in .hg/hgrc of current repo. |
|
802 | make HGRCPATH empty to only look in .hg/hgrc of current repo. | |
799 | if no HGRCPATH, use default os-specific path.''' |
|
803 | if no HGRCPATH, use default os-specific path.''' | |
800 | global _rcpath |
|
804 | global _rcpath | |
801 | if _rcpath is None: |
|
805 | if _rcpath is None: | |
802 | if 'HGRCPATH' in os.environ: |
|
806 | if 'HGRCPATH' in os.environ: | |
803 | _rcpath = [] |
|
807 | _rcpath = [] | |
804 | for p in os.environ['HGRCPATH'].split(os.pathsep): |
|
808 | for p in os.environ['HGRCPATH'].split(os.pathsep): | |
805 | if not p: continue |
|
809 | if not p: continue | |
806 | if os.path.isdir(p): |
|
810 | if os.path.isdir(p): | |
807 | for f in os.listdir(p): |
|
811 | for f in os.listdir(p): | |
808 | if f.endswith('.rc'): |
|
812 | if f.endswith('.rc'): | |
809 | _rcpath.append(os.path.join(p, f)) |
|
813 | _rcpath.append(os.path.join(p, f)) | |
810 | else: |
|
814 | else: | |
811 | _rcpath.append(p) |
|
815 | _rcpath.append(p) | |
812 | else: |
|
816 | else: | |
813 | _rcpath = os_rcpath() |
|
817 | _rcpath = os_rcpath() | |
814 | return _rcpath |
|
818 | return _rcpath |
@@ -1,16 +1,16 b'' | |||||
1 | header = header-raw.tmpl |
|
1 | header = header-raw.tmpl | |
2 | footer = '' |
|
2 | footer = '' | |
3 | changeset = changeset-raw.tmpl |
|
3 | changeset = changeset-raw.tmpl | |
4 | difflineplus = '#line#' |
|
4 | difflineplus = '#line#' | |
5 | difflineminus = '#line#' |
|
5 | difflineminus = '#line#' | |
6 | difflineat = '#line#' |
|
6 | difflineat = '#line#' | |
7 | diffline = '#line#' |
|
7 | diffline = '#line#' | |
8 | changesetparent = '# parent: #node#' |
|
8 | changesetparent = '# parent: #node#' | |
9 | changesetchild = '# child: #node#' |
|
9 | changesetchild = '# child: #node#' | |
10 | filenodelink = '' |
|
10 | filenodelink = '' | |
11 | filerevision = filerevision-raw.tmpl |
|
11 | filerevision = 'Content-Type: #mimetype#\nContent-Disposition: filename=#file#\n\n#raw#' | |
12 | fileline = '#line#' |
|
12 | fileline = '#line#' | |
13 | diffblock = '#lines#' |
|
13 | diffblock = '#lines#' | |
14 | filediff = filediff-raw.tmpl |
|
14 | filediff = filediff-raw.tmpl | |
15 | fileannotate = fileannotate-raw.tmpl |
|
15 | fileannotate = fileannotate-raw.tmpl | |
16 | annotateline = '#author#@#rev#: #line#' |
|
16 | annotateline = '#author#@#rev#: #line#' |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now