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