Show More
@@ -1,3349 +1,3380 b'' | |||
|
1 | 1 | # cmdutil.py - help for command processing in mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from node import hex, bin, nullid, nullrev, short |
|
9 | 9 | from i18n import _ |
|
10 | 10 | import os, sys, errno, re, tempfile, cStringIO, shutil |
|
11 | 11 | import util, scmutil, templater, patch, error, templatekw, revlog, copies |
|
12 | 12 | import match as matchmod |
|
13 |
import repair, graphmod, revset, phases, obsolete, pathutil |
|
|
13 | import repair, graphmod, revset, phases, obsolete, pathutil | |
|
14 | 14 | import changelog |
|
15 | 15 | import bookmarks |
|
16 | 16 | import encoding |
|
17 | 17 | import formatter |
|
18 | 18 | import crecord as crecordmod |
|
19 | 19 | import lock as lockmod |
|
20 | 20 | |
|
21 | 21 | def ishunk(x): |
|
22 | 22 | hunkclasses = (crecordmod.uihunk, patch.recordhunk) |
|
23 | 23 | return isinstance(x, hunkclasses) |
|
24 | 24 | |
|
25 | 25 | def newandmodified(chunks, originalchunks): |
|
26 | 26 | newlyaddedandmodifiedfiles = set() |
|
27 | 27 | for chunk in chunks: |
|
28 | 28 | if ishunk(chunk) and chunk.header.isnewfile() and chunk not in \ |
|
29 | 29 | originalchunks: |
|
30 | 30 | newlyaddedandmodifiedfiles.add(chunk.header.filename()) |
|
31 | 31 | return newlyaddedandmodifiedfiles |
|
32 | 32 | |
|
33 | 33 | def parsealiases(cmd): |
|
34 | 34 | return cmd.lstrip("^").split("|") |
|
35 | 35 | |
|
36 | 36 | def setupwrapcolorwrite(ui): |
|
37 | 37 | # wrap ui.write so diff output can be labeled/colorized |
|
38 | 38 | def wrapwrite(orig, *args, **kw): |
|
39 | 39 | label = kw.pop('label', '') |
|
40 | 40 | for chunk, l in patch.difflabel(lambda: args): |
|
41 | 41 | orig(chunk, label=label + l) |
|
42 | 42 | |
|
43 | 43 | oldwrite = ui.write |
|
44 | 44 | def wrap(*args, **kwargs): |
|
45 | 45 | return wrapwrite(oldwrite, *args, **kwargs) |
|
46 | 46 | setattr(ui, 'write', wrap) |
|
47 | 47 | return oldwrite |
|
48 | 48 | |
|
49 | 49 | def filterchunks(ui, originalhunks, usecurses, testfile, operation=None): |
|
50 | 50 | if usecurses: |
|
51 | 51 | if testfile: |
|
52 | 52 | recordfn = crecordmod.testdecorator(testfile, |
|
53 | 53 | crecordmod.testchunkselector) |
|
54 | 54 | else: |
|
55 | 55 | recordfn = crecordmod.chunkselector |
|
56 | 56 | |
|
57 | 57 | return crecordmod.filterpatch(ui, originalhunks, recordfn, operation) |
|
58 | 58 | |
|
59 | 59 | else: |
|
60 | 60 | return patch.filterpatch(ui, originalhunks, operation) |
|
61 | 61 | |
|
62 | 62 | def recordfilter(ui, originalhunks, operation=None): |
|
63 | 63 | """ Prompts the user to filter the originalhunks and return a list of |
|
64 | 64 | selected hunks. |
|
65 | 65 | *operation* is used for ui purposes to indicate the user |
|
66 | 66 | what kind of filtering they are doing: reverting, commiting, shelving, etc. |
|
67 | 67 | *operation* has to be a translated string. |
|
68 | 68 | """ |
|
69 | 69 | usecurses = ui.configbool('experimental', 'crecord', False) |
|
70 | 70 | testfile = ui.config('experimental', 'crecordtest', None) |
|
71 | 71 | oldwrite = setupwrapcolorwrite(ui) |
|
72 | 72 | try: |
|
73 | 73 | newchunks = filterchunks(ui, originalhunks, usecurses, testfile, |
|
74 | 74 | operation) |
|
75 | 75 | finally: |
|
76 | 76 | ui.write = oldwrite |
|
77 | 77 | return newchunks |
|
78 | 78 | |
|
79 | 79 | def dorecord(ui, repo, commitfunc, cmdsuggest, backupall, |
|
80 | 80 | filterfn, *pats, **opts): |
|
81 | 81 | import merge as mergemod |
|
82 | 82 | |
|
83 | 83 | if not ui.interactive(): |
|
84 | 84 | if cmdsuggest: |
|
85 | 85 | msg = _('running non-interactively, use %s instead') % cmdsuggest |
|
86 | 86 | else: |
|
87 | 87 | msg = _('running non-interactively') |
|
88 | 88 | raise util.Abort(msg) |
|
89 | 89 | |
|
90 | 90 | # make sure username is set before going interactive |
|
91 | 91 | if not opts.get('user'): |
|
92 | 92 | ui.username() # raise exception, username not provided |
|
93 | 93 | |
|
94 | 94 | def recordfunc(ui, repo, message, match, opts): |
|
95 | 95 | """This is generic record driver. |
|
96 | 96 | |
|
97 | 97 | Its job is to interactively filter local changes, and |
|
98 | 98 | accordingly prepare working directory into a state in which the |
|
99 | 99 | job can be delegated to a non-interactive commit command such as |
|
100 | 100 | 'commit' or 'qrefresh'. |
|
101 | 101 | |
|
102 | 102 | After the actual job is done by non-interactive command, the |
|
103 | 103 | working directory is restored to its original state. |
|
104 | 104 | |
|
105 | 105 | In the end we'll record interesting changes, and everything else |
|
106 | 106 | will be left in place, so the user can continue working. |
|
107 | 107 | """ |
|
108 | 108 | |
|
109 | 109 | checkunfinished(repo, commit=True) |
|
110 | 110 | merge = len(repo[None].parents()) > 1 |
|
111 | 111 | if merge: |
|
112 | 112 | raise util.Abort(_('cannot partially commit a merge ' |
|
113 | 113 | '(use "hg commit" instead)')) |
|
114 | 114 | |
|
115 | 115 | status = repo.status(match=match) |
|
116 | 116 | diffopts = patch.difffeatureopts(ui, opts=opts, whitespace=True) |
|
117 | 117 | diffopts.nodates = True |
|
118 | 118 | diffopts.git = True |
|
119 | 119 | originaldiff = patch.diff(repo, changes=status, opts=diffopts) |
|
120 | 120 | originalchunks = patch.parsepatch(originaldiff) |
|
121 | 121 | |
|
122 | 122 | # 1. filter patch, so we have intending-to apply subset of it |
|
123 | 123 | try: |
|
124 | 124 | chunks = filterfn(ui, originalchunks) |
|
125 | 125 | except patch.PatchError as err: |
|
126 | 126 | raise util.Abort(_('error parsing patch: %s') % err) |
|
127 | 127 | |
|
128 | 128 | # We need to keep a backup of files that have been newly added and |
|
129 | 129 | # modified during the recording process because there is a previous |
|
130 | 130 | # version without the edit in the workdir |
|
131 | 131 | newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks) |
|
132 | 132 | contenders = set() |
|
133 | 133 | for h in chunks: |
|
134 | 134 | try: |
|
135 | 135 | contenders.update(set(h.files())) |
|
136 | 136 | except AttributeError: |
|
137 | 137 | pass |
|
138 | 138 | |
|
139 | 139 | changed = status.modified + status.added + status.removed |
|
140 | 140 | newfiles = [f for f in changed if f in contenders] |
|
141 | 141 | if not newfiles: |
|
142 | 142 | ui.status(_('no changes to record\n')) |
|
143 | 143 | return 0 |
|
144 | 144 | |
|
145 | 145 | modified = set(status.modified) |
|
146 | 146 | |
|
147 | 147 | # 2. backup changed files, so we can restore them in the end |
|
148 | 148 | |
|
149 | 149 | if backupall: |
|
150 | 150 | tobackup = changed |
|
151 | 151 | else: |
|
152 | 152 | tobackup = [f for f in newfiles if f in modified or f in \ |
|
153 | 153 | newlyaddedandmodifiedfiles] |
|
154 | 154 | backups = {} |
|
155 | 155 | if tobackup: |
|
156 | 156 | backupdir = repo.join('record-backups') |
|
157 | 157 | try: |
|
158 | 158 | os.mkdir(backupdir) |
|
159 | 159 | except OSError as err: |
|
160 | 160 | if err.errno != errno.EEXIST: |
|
161 | 161 | raise |
|
162 | 162 | try: |
|
163 | 163 | # backup continues |
|
164 | 164 | for f in tobackup: |
|
165 | 165 | fd, tmpname = tempfile.mkstemp(prefix=f.replace('/', '_')+'.', |
|
166 | 166 | dir=backupdir) |
|
167 | 167 | os.close(fd) |
|
168 | 168 | ui.debug('backup %r as %r\n' % (f, tmpname)) |
|
169 | 169 | util.copyfile(repo.wjoin(f), tmpname) |
|
170 | 170 | shutil.copystat(repo.wjoin(f), tmpname) |
|
171 | 171 | backups[f] = tmpname |
|
172 | 172 | |
|
173 | 173 | fp = cStringIO.StringIO() |
|
174 | 174 | for c in chunks: |
|
175 | 175 | fname = c.filename() |
|
176 | 176 | if fname in backups: |
|
177 | 177 | c.write(fp) |
|
178 | 178 | dopatch = fp.tell() |
|
179 | 179 | fp.seek(0) |
|
180 | 180 | |
|
181 | 181 | [os.unlink(repo.wjoin(c)) for c in newlyaddedandmodifiedfiles] |
|
182 | 182 | # 3a. apply filtered patch to clean repo (clean) |
|
183 | 183 | if backups: |
|
184 | 184 | # Equivalent to hg.revert |
|
185 | 185 | choices = lambda key: key in backups |
|
186 | 186 | mergemod.update(repo, repo.dirstate.p1(), |
|
187 | 187 | False, True, choices) |
|
188 | 188 | |
|
189 | 189 | # 3b. (apply) |
|
190 | 190 | if dopatch: |
|
191 | 191 | try: |
|
192 | 192 | ui.debug('applying patch\n') |
|
193 | 193 | ui.debug(fp.getvalue()) |
|
194 | 194 | patch.internalpatch(ui, repo, fp, 1, eolmode=None) |
|
195 | 195 | except patch.PatchError as err: |
|
196 | 196 | raise util.Abort(str(err)) |
|
197 | 197 | del fp |
|
198 | 198 | |
|
199 | 199 | # 4. We prepared working directory according to filtered |
|
200 | 200 | # patch. Now is the time to delegate the job to |
|
201 | 201 | # commit/qrefresh or the like! |
|
202 | 202 | |
|
203 | 203 | # Make all of the pathnames absolute. |
|
204 | 204 | newfiles = [repo.wjoin(nf) for nf in newfiles] |
|
205 | 205 | return commitfunc(ui, repo, *newfiles, **opts) |
|
206 | 206 | finally: |
|
207 | 207 | # 5. finally restore backed-up files |
|
208 | 208 | try: |
|
209 | 209 | dirstate = repo.dirstate |
|
210 | 210 | for realname, tmpname in backups.iteritems(): |
|
211 | 211 | ui.debug('restoring %r to %r\n' % (tmpname, realname)) |
|
212 | 212 | |
|
213 | 213 | if dirstate[realname] == 'n': |
|
214 | 214 | # without normallookup, restoring timestamp |
|
215 | 215 | # may cause partially committed files |
|
216 | 216 | # to be treated as unmodified |
|
217 | 217 | dirstate.normallookup(realname) |
|
218 | 218 | |
|
219 | 219 | util.copyfile(tmpname, repo.wjoin(realname)) |
|
220 | 220 | # Our calls to copystat() here and above are a |
|
221 | 221 | # hack to trick any editors that have f open that |
|
222 | 222 | # we haven't modified them. |
|
223 | 223 | # |
|
224 | 224 | # Also note that this racy as an editor could |
|
225 | 225 | # notice the file's mtime before we've finished |
|
226 | 226 | # writing it. |
|
227 | 227 | shutil.copystat(tmpname, repo.wjoin(realname)) |
|
228 | 228 | os.unlink(tmpname) |
|
229 | 229 | if tobackup: |
|
230 | 230 | os.rmdir(backupdir) |
|
231 | 231 | except OSError: |
|
232 | 232 | pass |
|
233 | 233 | |
|
234 | 234 | def recordinwlock(ui, repo, message, match, opts): |
|
235 | 235 | wlock = repo.wlock() |
|
236 | 236 | try: |
|
237 | 237 | return recordfunc(ui, repo, message, match, opts) |
|
238 | 238 | finally: |
|
239 | 239 | wlock.release() |
|
240 | 240 | |
|
241 | 241 | return commit(ui, repo, recordinwlock, pats, opts) |
|
242 | 242 | |
|
243 | 243 | def findpossible(cmd, table, strict=False): |
|
244 | 244 | """ |
|
245 | 245 | Return cmd -> (aliases, command table entry) |
|
246 | 246 | for each matching command. |
|
247 | 247 | Return debug commands (or their aliases) only if no normal command matches. |
|
248 | 248 | """ |
|
249 | 249 | choice = {} |
|
250 | 250 | debugchoice = {} |
|
251 | 251 | |
|
252 | 252 | if cmd in table: |
|
253 | 253 | # short-circuit exact matches, "log" alias beats "^log|history" |
|
254 | 254 | keys = [cmd] |
|
255 | 255 | else: |
|
256 | 256 | keys = table.keys() |
|
257 | 257 | |
|
258 | 258 | allcmds = [] |
|
259 | 259 | for e in keys: |
|
260 | 260 | aliases = parsealiases(e) |
|
261 | 261 | allcmds.extend(aliases) |
|
262 | 262 | found = None |
|
263 | 263 | if cmd in aliases: |
|
264 | 264 | found = cmd |
|
265 | 265 | elif not strict: |
|
266 | 266 | for a in aliases: |
|
267 | 267 | if a.startswith(cmd): |
|
268 | 268 | found = a |
|
269 | 269 | break |
|
270 | 270 | if found is not None: |
|
271 | 271 | if aliases[0].startswith("debug") or found.startswith("debug"): |
|
272 | 272 | debugchoice[found] = (aliases, table[e]) |
|
273 | 273 | else: |
|
274 | 274 | choice[found] = (aliases, table[e]) |
|
275 | 275 | |
|
276 | 276 | if not choice and debugchoice: |
|
277 | 277 | choice = debugchoice |
|
278 | 278 | |
|
279 | 279 | return choice, allcmds |
|
280 | 280 | |
|
281 | 281 | def findcmd(cmd, table, strict=True): |
|
282 | 282 | """Return (aliases, command table entry) for command string.""" |
|
283 | 283 | choice, allcmds = findpossible(cmd, table, strict) |
|
284 | 284 | |
|
285 | 285 | if cmd in choice: |
|
286 | 286 | return choice[cmd] |
|
287 | 287 | |
|
288 | 288 | if len(choice) > 1: |
|
289 | 289 | clist = choice.keys() |
|
290 | 290 | clist.sort() |
|
291 | 291 | raise error.AmbiguousCommand(cmd, clist) |
|
292 | 292 | |
|
293 | 293 | if choice: |
|
294 | 294 | return choice.values()[0] |
|
295 | 295 | |
|
296 | 296 | raise error.UnknownCommand(cmd, allcmds) |
|
297 | 297 | |
|
298 | 298 | def findrepo(p): |
|
299 | 299 | while not os.path.isdir(os.path.join(p, ".hg")): |
|
300 | 300 | oldp, p = p, os.path.dirname(p) |
|
301 | 301 | if p == oldp: |
|
302 | 302 | return None |
|
303 | 303 | |
|
304 | 304 | return p |
|
305 | 305 | |
|
306 | 306 | def bailifchanged(repo, merge=True): |
|
307 | 307 | if merge and repo.dirstate.p2() != nullid: |
|
308 | 308 | raise util.Abort(_('outstanding uncommitted merge')) |
|
309 | 309 | modified, added, removed, deleted = repo.status()[:4] |
|
310 | 310 | if modified or added or removed or deleted: |
|
311 | 311 | raise util.Abort(_('uncommitted changes')) |
|
312 | 312 | ctx = repo[None] |
|
313 | 313 | for s in sorted(ctx.substate): |
|
314 | 314 | ctx.sub(s).bailifchanged() |
|
315 | 315 | |
|
316 | 316 | def logmessage(ui, opts): |
|
317 | 317 | """ get the log message according to -m and -l option """ |
|
318 | 318 | message = opts.get('message') |
|
319 | 319 | logfile = opts.get('logfile') |
|
320 | 320 | |
|
321 | 321 | if message and logfile: |
|
322 | 322 | raise util.Abort(_('options --message and --logfile are mutually ' |
|
323 | 323 | 'exclusive')) |
|
324 | 324 | if not message and logfile: |
|
325 | 325 | try: |
|
326 | 326 | if logfile == '-': |
|
327 | 327 | message = ui.fin.read() |
|
328 | 328 | else: |
|
329 | 329 | message = '\n'.join(util.readfile(logfile).splitlines()) |
|
330 | 330 | except IOError as inst: |
|
331 | 331 | raise util.Abort(_("can't read commit message '%s': %s") % |
|
332 | 332 | (logfile, inst.strerror)) |
|
333 | 333 | return message |
|
334 | 334 | |
|
335 | 335 | def mergeeditform(ctxorbool, baseformname): |
|
336 | 336 | """return appropriate editform name (referencing a committemplate) |
|
337 | 337 | |
|
338 | 338 | 'ctxorbool' is either a ctx to be committed, or a bool indicating whether |
|
339 | 339 | merging is committed. |
|
340 | 340 | |
|
341 | 341 | This returns baseformname with '.merge' appended if it is a merge, |
|
342 | 342 | otherwise '.normal' is appended. |
|
343 | 343 | """ |
|
344 | 344 | if isinstance(ctxorbool, bool): |
|
345 | 345 | if ctxorbool: |
|
346 | 346 | return baseformname + ".merge" |
|
347 | 347 | elif 1 < len(ctxorbool.parents()): |
|
348 | 348 | return baseformname + ".merge" |
|
349 | 349 | |
|
350 | 350 | return baseformname + ".normal" |
|
351 | 351 | |
|
352 | 352 | def getcommiteditor(edit=False, finishdesc=None, extramsg=None, |
|
353 | 353 | editform='', **opts): |
|
354 | 354 | """get appropriate commit message editor according to '--edit' option |
|
355 | 355 | |
|
356 | 356 | 'finishdesc' is a function to be called with edited commit message |
|
357 | 357 | (= 'description' of the new changeset) just after editing, but |
|
358 | 358 | before checking empty-ness. It should return actual text to be |
|
359 | 359 | stored into history. This allows to change description before |
|
360 | 360 | storing. |
|
361 | 361 | |
|
362 | 362 | 'extramsg' is a extra message to be shown in the editor instead of |
|
363 | 363 | 'Leave message empty to abort commit' line. 'HG: ' prefix and EOL |
|
364 | 364 | is automatically added. |
|
365 | 365 | |
|
366 | 366 | 'editform' is a dot-separated list of names, to distinguish |
|
367 | 367 | the purpose of commit text editing. |
|
368 | 368 | |
|
369 | 369 | 'getcommiteditor' returns 'commitforceeditor' regardless of |
|
370 | 370 | 'edit', if one of 'finishdesc' or 'extramsg' is specified, because |
|
371 | 371 | they are specific for usage in MQ. |
|
372 | 372 | """ |
|
373 | 373 | if edit or finishdesc or extramsg: |
|
374 | 374 | return lambda r, c, s: commitforceeditor(r, c, s, |
|
375 | 375 | finishdesc=finishdesc, |
|
376 | 376 | extramsg=extramsg, |
|
377 | 377 | editform=editform) |
|
378 | 378 | elif editform: |
|
379 | 379 | return lambda r, c, s: commiteditor(r, c, s, editform=editform) |
|
380 | 380 | else: |
|
381 | 381 | return commiteditor |
|
382 | 382 | |
|
383 | 383 | def loglimit(opts): |
|
384 | 384 | """get the log limit according to option -l/--limit""" |
|
385 | 385 | limit = opts.get('limit') |
|
386 | 386 | if limit: |
|
387 | 387 | try: |
|
388 | 388 | limit = int(limit) |
|
389 | 389 | except ValueError: |
|
390 | 390 | raise util.Abort(_('limit must be a positive integer')) |
|
391 | 391 | if limit <= 0: |
|
392 | 392 | raise util.Abort(_('limit must be positive')) |
|
393 | 393 | else: |
|
394 | 394 | limit = None |
|
395 | 395 | return limit |
|
396 | 396 | |
|
397 | 397 | def makefilename(repo, pat, node, desc=None, |
|
398 | 398 | total=None, seqno=None, revwidth=None, pathname=None): |
|
399 | 399 | node_expander = { |
|
400 | 400 | 'H': lambda: hex(node), |
|
401 | 401 | 'R': lambda: str(repo.changelog.rev(node)), |
|
402 | 402 | 'h': lambda: short(node), |
|
403 | 403 | 'm': lambda: re.sub('[^\w]', '_', str(desc)) |
|
404 | 404 | } |
|
405 | 405 | expander = { |
|
406 | 406 | '%': lambda: '%', |
|
407 | 407 | 'b': lambda: os.path.basename(repo.root), |
|
408 | 408 | } |
|
409 | 409 | |
|
410 | 410 | try: |
|
411 | 411 | if node: |
|
412 | 412 | expander.update(node_expander) |
|
413 | 413 | if node: |
|
414 | 414 | expander['r'] = (lambda: |
|
415 | 415 | str(repo.changelog.rev(node)).zfill(revwidth or 0)) |
|
416 | 416 | if total is not None: |
|
417 | 417 | expander['N'] = lambda: str(total) |
|
418 | 418 | if seqno is not None: |
|
419 | 419 | expander['n'] = lambda: str(seqno) |
|
420 | 420 | if total is not None and seqno is not None: |
|
421 | 421 | expander['n'] = lambda: str(seqno).zfill(len(str(total))) |
|
422 | 422 | if pathname is not None: |
|
423 | 423 | expander['s'] = lambda: os.path.basename(pathname) |
|
424 | 424 | expander['d'] = lambda: os.path.dirname(pathname) or '.' |
|
425 | 425 | expander['p'] = lambda: pathname |
|
426 | 426 | |
|
427 | 427 | newname = [] |
|
428 | 428 | patlen = len(pat) |
|
429 | 429 | i = 0 |
|
430 | 430 | while i < patlen: |
|
431 | 431 | c = pat[i] |
|
432 | 432 | if c == '%': |
|
433 | 433 | i += 1 |
|
434 | 434 | c = pat[i] |
|
435 | 435 | c = expander[c]() |
|
436 | 436 | newname.append(c) |
|
437 | 437 | i += 1 |
|
438 | 438 | return ''.join(newname) |
|
439 | 439 | except KeyError as inst: |
|
440 | 440 | raise util.Abort(_("invalid format spec '%%%s' in output filename") % |
|
441 | 441 | inst.args[0]) |
|
442 | 442 | |
|
443 | 443 | def makefileobj(repo, pat, node=None, desc=None, total=None, |
|
444 | 444 | seqno=None, revwidth=None, mode='wb', modemap=None, |
|
445 | 445 | pathname=None): |
|
446 | 446 | |
|
447 | 447 | writable = mode not in ('r', 'rb') |
|
448 | 448 | |
|
449 | 449 | if not pat or pat == '-': |
|
450 | 450 | if writable: |
|
451 | 451 | fp = repo.ui.fout |
|
452 | 452 | else: |
|
453 | 453 | fp = repo.ui.fin |
|
454 | 454 | if util.safehasattr(fp, 'fileno'): |
|
455 | 455 | return os.fdopen(os.dup(fp.fileno()), mode) |
|
456 | 456 | else: |
|
457 | 457 | # if this fp can't be duped properly, return |
|
458 | 458 | # a dummy object that can be closed |
|
459 | 459 | class wrappedfileobj(object): |
|
460 | 460 | noop = lambda x: None |
|
461 | 461 | def __init__(self, f): |
|
462 | 462 | self.f = f |
|
463 | 463 | def __getattr__(self, attr): |
|
464 | 464 | if attr == 'close': |
|
465 | 465 | return self.noop |
|
466 | 466 | else: |
|
467 | 467 | return getattr(self.f, attr) |
|
468 | 468 | |
|
469 | 469 | return wrappedfileobj(fp) |
|
470 | 470 | if util.safehasattr(pat, 'write') and writable: |
|
471 | 471 | return pat |
|
472 | 472 | if util.safehasattr(pat, 'read') and 'r' in mode: |
|
473 | 473 | return pat |
|
474 | 474 | fn = makefilename(repo, pat, node, desc, total, seqno, revwidth, pathname) |
|
475 | 475 | if modemap is not None: |
|
476 | 476 | mode = modemap.get(fn, mode) |
|
477 | 477 | if mode == 'wb': |
|
478 | 478 | modemap[fn] = 'ab' |
|
479 | 479 | return open(fn, mode) |
|
480 | 480 | |
|
481 | 481 | def openrevlog(repo, cmd, file_, opts): |
|
482 | 482 | """opens the changelog, manifest, a filelog or a given revlog""" |
|
483 | 483 | cl = opts['changelog'] |
|
484 | 484 | mf = opts['manifest'] |
|
485 | 485 | dir = opts['dir'] |
|
486 | 486 | msg = None |
|
487 | 487 | if cl and mf: |
|
488 | 488 | msg = _('cannot specify --changelog and --manifest at the same time') |
|
489 | 489 | elif cl and dir: |
|
490 | 490 | msg = _('cannot specify --changelog and --dir at the same time') |
|
491 | 491 | elif cl or mf: |
|
492 | 492 | if file_: |
|
493 | 493 | msg = _('cannot specify filename with --changelog or --manifest') |
|
494 | 494 | elif not repo: |
|
495 | 495 | msg = _('cannot specify --changelog or --manifest or --dir ' |
|
496 | 496 | 'without a repository') |
|
497 | 497 | if msg: |
|
498 | 498 | raise util.Abort(msg) |
|
499 | 499 | |
|
500 | 500 | r = None |
|
501 | 501 | if repo: |
|
502 | 502 | if cl: |
|
503 | 503 | r = repo.unfiltered().changelog |
|
504 | 504 | elif dir: |
|
505 | 505 | if 'treemanifest' not in repo.requirements: |
|
506 | 506 | raise util.Abort(_("--dir can only be used on repos with " |
|
507 | 507 | "treemanifest enabled")) |
|
508 | 508 | dirlog = repo.dirlog(file_) |
|
509 | 509 | if len(dirlog): |
|
510 | 510 | r = dirlog |
|
511 | 511 | elif mf: |
|
512 | 512 | r = repo.manifest |
|
513 | 513 | elif file_: |
|
514 | 514 | filelog = repo.file(file_) |
|
515 | 515 | if len(filelog): |
|
516 | 516 | r = filelog |
|
517 | 517 | if not r: |
|
518 | 518 | if not file_: |
|
519 | 519 | raise error.CommandError(cmd, _('invalid arguments')) |
|
520 | 520 | if not os.path.isfile(file_): |
|
521 | 521 | raise util.Abort(_("revlog '%s' not found") % file_) |
|
522 | 522 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), |
|
523 | 523 | file_[:-2] + ".i") |
|
524 | 524 | return r |
|
525 | 525 | |
|
526 | 526 | def copy(ui, repo, pats, opts, rename=False): |
|
527 | 527 | # called with the repo lock held |
|
528 | 528 | # |
|
529 | 529 | # hgsep => pathname that uses "/" to separate directories |
|
530 | 530 | # ossep => pathname that uses os.sep to separate directories |
|
531 | 531 | cwd = repo.getcwd() |
|
532 | 532 | targets = {} |
|
533 | 533 | after = opts.get("after") |
|
534 | 534 | dryrun = opts.get("dry_run") |
|
535 | 535 | wctx = repo[None] |
|
536 | 536 | |
|
537 | 537 | def walkpat(pat): |
|
538 | 538 | srcs = [] |
|
539 | 539 | if after: |
|
540 | 540 | badstates = '?' |
|
541 | 541 | else: |
|
542 | 542 | badstates = '?r' |
|
543 | 543 | m = scmutil.match(repo[None], [pat], opts, globbed=True) |
|
544 | 544 | for abs in repo.walk(m): |
|
545 | 545 | state = repo.dirstate[abs] |
|
546 | 546 | rel = m.rel(abs) |
|
547 | 547 | exact = m.exact(abs) |
|
548 | 548 | if state in badstates: |
|
549 | 549 | if exact and state == '?': |
|
550 | 550 | ui.warn(_('%s: not copying - file is not managed\n') % rel) |
|
551 | 551 | if exact and state == 'r': |
|
552 | 552 | ui.warn(_('%s: not copying - file has been marked for' |
|
553 | 553 | ' remove\n') % rel) |
|
554 | 554 | continue |
|
555 | 555 | # abs: hgsep |
|
556 | 556 | # rel: ossep |
|
557 | 557 | srcs.append((abs, rel, exact)) |
|
558 | 558 | return srcs |
|
559 | 559 | |
|
560 | 560 | # abssrc: hgsep |
|
561 | 561 | # relsrc: ossep |
|
562 | 562 | # otarget: ossep |
|
563 | 563 | def copyfile(abssrc, relsrc, otarget, exact): |
|
564 | 564 | abstarget = pathutil.canonpath(repo.root, cwd, otarget) |
|
565 | 565 | if '/' in abstarget: |
|
566 | 566 | # We cannot normalize abstarget itself, this would prevent |
|
567 | 567 | # case only renames, like a => A. |
|
568 | 568 | abspath, absname = abstarget.rsplit('/', 1) |
|
569 | 569 | abstarget = repo.dirstate.normalize(abspath) + '/' + absname |
|
570 | 570 | reltarget = repo.pathto(abstarget, cwd) |
|
571 | 571 | target = repo.wjoin(abstarget) |
|
572 | 572 | src = repo.wjoin(abssrc) |
|
573 | 573 | state = repo.dirstate[abstarget] |
|
574 | 574 | |
|
575 | 575 | scmutil.checkportable(ui, abstarget) |
|
576 | 576 | |
|
577 | 577 | # check for collisions |
|
578 | 578 | prevsrc = targets.get(abstarget) |
|
579 | 579 | if prevsrc is not None: |
|
580 | 580 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
|
581 | 581 | (reltarget, repo.pathto(abssrc, cwd), |
|
582 | 582 | repo.pathto(prevsrc, cwd))) |
|
583 | 583 | return |
|
584 | 584 | |
|
585 | 585 | # check for overwrites |
|
586 | 586 | exists = os.path.lexists(target) |
|
587 | 587 | samefile = False |
|
588 | 588 | if exists and abssrc != abstarget: |
|
589 | 589 | if (repo.dirstate.normalize(abssrc) == |
|
590 | 590 | repo.dirstate.normalize(abstarget)): |
|
591 | 591 | if not rename: |
|
592 | 592 | ui.warn(_("%s: can't copy - same file\n") % reltarget) |
|
593 | 593 | return |
|
594 | 594 | exists = False |
|
595 | 595 | samefile = True |
|
596 | 596 | |
|
597 | 597 | if not after and exists or after and state in 'mn': |
|
598 | 598 | if not opts['force']: |
|
599 | 599 | ui.warn(_('%s: not overwriting - file exists\n') % |
|
600 | 600 | reltarget) |
|
601 | 601 | return |
|
602 | 602 | |
|
603 | 603 | if after: |
|
604 | 604 | if not exists: |
|
605 | 605 | if rename: |
|
606 | 606 | ui.warn(_('%s: not recording move - %s does not exist\n') % |
|
607 | 607 | (relsrc, reltarget)) |
|
608 | 608 | else: |
|
609 | 609 | ui.warn(_('%s: not recording copy - %s does not exist\n') % |
|
610 | 610 | (relsrc, reltarget)) |
|
611 | 611 | return |
|
612 | 612 | elif not dryrun: |
|
613 | 613 | try: |
|
614 | 614 | if exists: |
|
615 | 615 | os.unlink(target) |
|
616 | 616 | targetdir = os.path.dirname(target) or '.' |
|
617 | 617 | if not os.path.isdir(targetdir): |
|
618 | 618 | os.makedirs(targetdir) |
|
619 | 619 | if samefile: |
|
620 | 620 | tmp = target + "~hgrename" |
|
621 | 621 | os.rename(src, tmp) |
|
622 | 622 | os.rename(tmp, target) |
|
623 | 623 | else: |
|
624 | 624 | util.copyfile(src, target) |
|
625 | 625 | srcexists = True |
|
626 | 626 | except IOError as inst: |
|
627 | 627 | if inst.errno == errno.ENOENT: |
|
628 | 628 | ui.warn(_('%s: deleted in working directory\n') % relsrc) |
|
629 | 629 | srcexists = False |
|
630 | 630 | else: |
|
631 | 631 | ui.warn(_('%s: cannot copy - %s\n') % |
|
632 | 632 | (relsrc, inst.strerror)) |
|
633 | 633 | return True # report a failure |
|
634 | 634 | |
|
635 | 635 | if ui.verbose or not exact: |
|
636 | 636 | if rename: |
|
637 | 637 | ui.status(_('moving %s to %s\n') % (relsrc, reltarget)) |
|
638 | 638 | else: |
|
639 | 639 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
|
640 | 640 | |
|
641 | 641 | targets[abstarget] = abssrc |
|
642 | 642 | |
|
643 | 643 | # fix up dirstate |
|
644 | 644 | scmutil.dirstatecopy(ui, repo, wctx, abssrc, abstarget, |
|
645 | 645 | dryrun=dryrun, cwd=cwd) |
|
646 | 646 | if rename and not dryrun: |
|
647 | 647 | if not after and srcexists and not samefile: |
|
648 | 648 | util.unlinkpath(repo.wjoin(abssrc)) |
|
649 | 649 | wctx.forget([abssrc]) |
|
650 | 650 | |
|
651 | 651 | # pat: ossep |
|
652 | 652 | # dest ossep |
|
653 | 653 | # srcs: list of (hgsep, hgsep, ossep, bool) |
|
654 | 654 | # return: function that takes hgsep and returns ossep |
|
655 | 655 | def targetpathfn(pat, dest, srcs): |
|
656 | 656 | if os.path.isdir(pat): |
|
657 | 657 | abspfx = pathutil.canonpath(repo.root, cwd, pat) |
|
658 | 658 | abspfx = util.localpath(abspfx) |
|
659 | 659 | if destdirexists: |
|
660 | 660 | striplen = len(os.path.split(abspfx)[0]) |
|
661 | 661 | else: |
|
662 | 662 | striplen = len(abspfx) |
|
663 | 663 | if striplen: |
|
664 | 664 | striplen += len(os.sep) |
|
665 | 665 | res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) |
|
666 | 666 | elif destdirexists: |
|
667 | 667 | res = lambda p: os.path.join(dest, |
|
668 | 668 | os.path.basename(util.localpath(p))) |
|
669 | 669 | else: |
|
670 | 670 | res = lambda p: dest |
|
671 | 671 | return res |
|
672 | 672 | |
|
673 | 673 | # pat: ossep |
|
674 | 674 | # dest ossep |
|
675 | 675 | # srcs: list of (hgsep, hgsep, ossep, bool) |
|
676 | 676 | # return: function that takes hgsep and returns ossep |
|
677 | 677 | def targetpathafterfn(pat, dest, srcs): |
|
678 | 678 | if matchmod.patkind(pat): |
|
679 | 679 | # a mercurial pattern |
|
680 | 680 | res = lambda p: os.path.join(dest, |
|
681 | 681 | os.path.basename(util.localpath(p))) |
|
682 | 682 | else: |
|
683 | 683 | abspfx = pathutil.canonpath(repo.root, cwd, pat) |
|
684 | 684 | if len(abspfx) < len(srcs[0][0]): |
|
685 | 685 | # A directory. Either the target path contains the last |
|
686 | 686 | # component of the source path or it does not. |
|
687 | 687 | def evalpath(striplen): |
|
688 | 688 | score = 0 |
|
689 | 689 | for s in srcs: |
|
690 | 690 | t = os.path.join(dest, util.localpath(s[0])[striplen:]) |
|
691 | 691 | if os.path.lexists(t): |
|
692 | 692 | score += 1 |
|
693 | 693 | return score |
|
694 | 694 | |
|
695 | 695 | abspfx = util.localpath(abspfx) |
|
696 | 696 | striplen = len(abspfx) |
|
697 | 697 | if striplen: |
|
698 | 698 | striplen += len(os.sep) |
|
699 | 699 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
|
700 | 700 | score = evalpath(striplen) |
|
701 | 701 | striplen1 = len(os.path.split(abspfx)[0]) |
|
702 | 702 | if striplen1: |
|
703 | 703 | striplen1 += len(os.sep) |
|
704 | 704 | if evalpath(striplen1) > score: |
|
705 | 705 | striplen = striplen1 |
|
706 | 706 | res = lambda p: os.path.join(dest, |
|
707 | 707 | util.localpath(p)[striplen:]) |
|
708 | 708 | else: |
|
709 | 709 | # a file |
|
710 | 710 | if destdirexists: |
|
711 | 711 | res = lambda p: os.path.join(dest, |
|
712 | 712 | os.path.basename(util.localpath(p))) |
|
713 | 713 | else: |
|
714 | 714 | res = lambda p: dest |
|
715 | 715 | return res |
|
716 | 716 | |
|
717 | 717 | pats = scmutil.expandpats(pats) |
|
718 | 718 | if not pats: |
|
719 | 719 | raise util.Abort(_('no source or destination specified')) |
|
720 | 720 | if len(pats) == 1: |
|
721 | 721 | raise util.Abort(_('no destination specified')) |
|
722 | 722 | dest = pats.pop() |
|
723 | 723 | destdirexists = os.path.isdir(dest) and not os.path.islink(dest) |
|
724 | 724 | if not destdirexists: |
|
725 | 725 | if len(pats) > 1 or matchmod.patkind(pats[0]): |
|
726 | 726 | raise util.Abort(_('with multiple sources, destination must be an ' |
|
727 | 727 | 'existing directory')) |
|
728 | 728 | if util.endswithsep(dest): |
|
729 | 729 | raise util.Abort(_('destination %s is not a directory') % dest) |
|
730 | 730 | |
|
731 | 731 | tfn = targetpathfn |
|
732 | 732 | if after: |
|
733 | 733 | tfn = targetpathafterfn |
|
734 | 734 | copylist = [] |
|
735 | 735 | for pat in pats: |
|
736 | 736 | srcs = walkpat(pat) |
|
737 | 737 | if not srcs: |
|
738 | 738 | continue |
|
739 | 739 | copylist.append((tfn(pat, dest, srcs), srcs)) |
|
740 | 740 | if not copylist: |
|
741 | 741 | raise util.Abort(_('no files to copy')) |
|
742 | 742 | |
|
743 | 743 | errors = 0 |
|
744 | 744 | for targetpath, srcs in copylist: |
|
745 | 745 | for abssrc, relsrc, exact in srcs: |
|
746 | 746 | if copyfile(abssrc, relsrc, targetpath(abssrc), exact): |
|
747 | 747 | errors += 1 |
|
748 | 748 | |
|
749 | 749 | if errors: |
|
750 | 750 | ui.warn(_('(consider using --after)\n')) |
|
751 | 751 | |
|
752 | 752 | return errors != 0 |
|
753 | 753 | |
|
754 | 754 | def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None, |
|
755 | 755 | runargs=None, appendpid=False): |
|
756 | 756 | '''Run a command as a service.''' |
|
757 | 757 | |
|
758 | 758 | def writepid(pid): |
|
759 | 759 | if opts['pid_file']: |
|
760 | 760 | if appendpid: |
|
761 | 761 | mode = 'a' |
|
762 | 762 | else: |
|
763 | 763 | mode = 'w' |
|
764 | 764 | fp = open(opts['pid_file'], mode) |
|
765 | 765 | fp.write(str(pid) + '\n') |
|
766 | 766 | fp.close() |
|
767 | 767 | |
|
768 | 768 | if opts['daemon'] and not opts['daemon_pipefds']: |
|
769 | 769 | # Signal child process startup with file removal |
|
770 | 770 | lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-') |
|
771 | 771 | os.close(lockfd) |
|
772 | 772 | try: |
|
773 | 773 | if not runargs: |
|
774 | 774 | runargs = util.hgcmd() + sys.argv[1:] |
|
775 | 775 | runargs.append('--daemon-pipefds=%s' % lockpath) |
|
776 | 776 | # Don't pass --cwd to the child process, because we've already |
|
777 | 777 | # changed directory. |
|
778 | 778 | for i in xrange(1, len(runargs)): |
|
779 | 779 | if runargs[i].startswith('--cwd='): |
|
780 | 780 | del runargs[i] |
|
781 | 781 | break |
|
782 | 782 | elif runargs[i].startswith('--cwd'): |
|
783 | 783 | del runargs[i:i + 2] |
|
784 | 784 | break |
|
785 | 785 | def condfn(): |
|
786 | 786 | return not os.path.exists(lockpath) |
|
787 | 787 | pid = util.rundetached(runargs, condfn) |
|
788 | 788 | if pid < 0: |
|
789 | 789 | raise util.Abort(_('child process failed to start')) |
|
790 | 790 | writepid(pid) |
|
791 | 791 | finally: |
|
792 | 792 | try: |
|
793 | 793 | os.unlink(lockpath) |
|
794 | 794 | except OSError as e: |
|
795 | 795 | if e.errno != errno.ENOENT: |
|
796 | 796 | raise |
|
797 | 797 | if parentfn: |
|
798 | 798 | return parentfn(pid) |
|
799 | 799 | else: |
|
800 | 800 | return |
|
801 | 801 | |
|
802 | 802 | if initfn: |
|
803 | 803 | initfn() |
|
804 | 804 | |
|
805 | 805 | if not opts['daemon']: |
|
806 | 806 | writepid(os.getpid()) |
|
807 | 807 | |
|
808 | 808 | if opts['daemon_pipefds']: |
|
809 | 809 | lockpath = opts['daemon_pipefds'] |
|
810 | 810 | try: |
|
811 | 811 | os.setsid() |
|
812 | 812 | except AttributeError: |
|
813 | 813 | pass |
|
814 | 814 | os.unlink(lockpath) |
|
815 | 815 | util.hidewindow() |
|
816 | 816 | sys.stdout.flush() |
|
817 | 817 | sys.stderr.flush() |
|
818 | 818 | |
|
819 | 819 | nullfd = os.open(os.devnull, os.O_RDWR) |
|
820 | 820 | logfilefd = nullfd |
|
821 | 821 | if logfile: |
|
822 | 822 | logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND) |
|
823 | 823 | os.dup2(nullfd, 0) |
|
824 | 824 | os.dup2(logfilefd, 1) |
|
825 | 825 | os.dup2(logfilefd, 2) |
|
826 | 826 | if nullfd not in (0, 1, 2): |
|
827 | 827 | os.close(nullfd) |
|
828 | 828 | if logfile and logfilefd not in (0, 1, 2): |
|
829 | 829 | os.close(logfilefd) |
|
830 | 830 | |
|
831 | 831 | if runfn: |
|
832 | 832 | return runfn() |
|
833 | 833 | |
|
834 | 834 | def tryimportone(ui, repo, hunk, parents, opts, msgs, updatefunc): |
|
835 | 835 | """Utility function used by commands.import to import a single patch |
|
836 | 836 | |
|
837 | 837 | This function is explicitly defined here to help the evolve extension to |
|
838 | 838 | wrap this part of the import logic. |
|
839 | 839 | |
|
840 | 840 | The API is currently a bit ugly because it a simple code translation from |
|
841 | 841 | the import command. Feel free to make it better. |
|
842 | 842 | |
|
843 | 843 | :hunk: a patch (as a binary string) |
|
844 | 844 | :parents: nodes that will be parent of the created commit |
|
845 | 845 | :opts: the full dict of option passed to the import command |
|
846 | 846 | :msgs: list to save commit message to. |
|
847 | 847 | (used in case we need to save it when failing) |
|
848 | 848 | :updatefunc: a function that update a repo to a given node |
|
849 | 849 | updatefunc(<repo>, <node>) |
|
850 | 850 | """ |
|
851 | 851 | # avoid cycle context -> subrepo -> cmdutil |
|
852 | 852 | import context |
|
853 | 853 | tmpname, message, user, date, branch, nodeid, p1, p2 = \ |
|
854 | 854 | patch.extract(ui, hunk) |
|
855 | 855 | |
|
856 | 856 | update = not opts.get('bypass') |
|
857 | 857 | strip = opts["strip"] |
|
858 | 858 | prefix = opts["prefix"] |
|
859 | 859 | sim = float(opts.get('similarity') or 0) |
|
860 | 860 | if not tmpname: |
|
861 | 861 | return (None, None, False) |
|
862 | 862 | msg = _('applied to working directory') |
|
863 | 863 | |
|
864 | 864 | rejects = False |
|
865 | 865 | dsguard = None |
|
866 | 866 | |
|
867 | 867 | try: |
|
868 | 868 | cmdline_message = logmessage(ui, opts) |
|
869 | 869 | if cmdline_message: |
|
870 | 870 | # pickup the cmdline msg |
|
871 | 871 | message = cmdline_message |
|
872 | 872 | elif message: |
|
873 | 873 | # pickup the patch msg |
|
874 | 874 | message = message.strip() |
|
875 | 875 | else: |
|
876 | 876 | # launch the editor |
|
877 | 877 | message = None |
|
878 | 878 | ui.debug('message:\n%s\n' % message) |
|
879 | 879 | |
|
880 | 880 | if len(parents) == 1: |
|
881 | 881 | parents.append(repo[nullid]) |
|
882 | 882 | if opts.get('exact'): |
|
883 | 883 | if not nodeid or not p1: |
|
884 | 884 | raise util.Abort(_('not a Mercurial patch')) |
|
885 | 885 | p1 = repo[p1] |
|
886 | 886 | p2 = repo[p2 or nullid] |
|
887 | 887 | elif p2: |
|
888 | 888 | try: |
|
889 | 889 | p1 = repo[p1] |
|
890 | 890 | p2 = repo[p2] |
|
891 | 891 | # Without any options, consider p2 only if the |
|
892 | 892 | # patch is being applied on top of the recorded |
|
893 | 893 | # first parent. |
|
894 | 894 | if p1 != parents[0]: |
|
895 | 895 | p1 = parents[0] |
|
896 | 896 | p2 = repo[nullid] |
|
897 | 897 | except error.RepoError: |
|
898 | 898 | p1, p2 = parents |
|
899 | 899 | if p2.node() == nullid: |
|
900 | 900 | ui.warn(_("warning: import the patch as a normal revision\n" |
|
901 | 901 | "(use --exact to import the patch as a merge)\n")) |
|
902 | 902 | else: |
|
903 | 903 | p1, p2 = parents |
|
904 | 904 | |
|
905 | 905 | n = None |
|
906 | 906 | if update: |
|
907 | 907 | dsguard = dirstateguard(repo, 'tryimportone') |
|
908 | 908 | if p1 != parents[0]: |
|
909 | 909 | updatefunc(repo, p1.node()) |
|
910 | 910 | if p2 != parents[1]: |
|
911 | 911 | repo.setparents(p1.node(), p2.node()) |
|
912 | 912 | |
|
913 | 913 | if opts.get('exact') or opts.get('import_branch'): |
|
914 | 914 | repo.dirstate.setbranch(branch or 'default') |
|
915 | 915 | |
|
916 | 916 | partial = opts.get('partial', False) |
|
917 | 917 | files = set() |
|
918 | 918 | try: |
|
919 | 919 | patch.patch(ui, repo, tmpname, strip=strip, prefix=prefix, |
|
920 | 920 | files=files, eolmode=None, similarity=sim / 100.0) |
|
921 | 921 | except patch.PatchError as e: |
|
922 | 922 | if not partial: |
|
923 | 923 | raise util.Abort(str(e)) |
|
924 | 924 | if partial: |
|
925 | 925 | rejects = True |
|
926 | 926 | |
|
927 | 927 | files = list(files) |
|
928 | 928 | if opts.get('no_commit'): |
|
929 | 929 | if message: |
|
930 | 930 | msgs.append(message) |
|
931 | 931 | else: |
|
932 | 932 | if opts.get('exact') or p2: |
|
933 | 933 | # If you got here, you either use --force and know what |
|
934 | 934 | # you are doing or used --exact or a merge patch while |
|
935 | 935 | # being updated to its first parent. |
|
936 | 936 | m = None |
|
937 | 937 | else: |
|
938 | 938 | m = scmutil.matchfiles(repo, files or []) |
|
939 | 939 | editform = mergeeditform(repo[None], 'import.normal') |
|
940 | 940 | if opts.get('exact'): |
|
941 | 941 | editor = None |
|
942 | 942 | else: |
|
943 | 943 | editor = getcommiteditor(editform=editform, **opts) |
|
944 | 944 | allowemptyback = repo.ui.backupconfig('ui', 'allowemptycommit') |
|
945 | 945 | try: |
|
946 | 946 | if partial: |
|
947 | 947 | repo.ui.setconfig('ui', 'allowemptycommit', True) |
|
948 | 948 | n = repo.commit(message, opts.get('user') or user, |
|
949 | 949 | opts.get('date') or date, match=m, |
|
950 | 950 | editor=editor) |
|
951 | 951 | finally: |
|
952 | 952 | repo.ui.restoreconfig(allowemptyback) |
|
953 | 953 | dsguard.close() |
|
954 | 954 | else: |
|
955 | 955 | if opts.get('exact') or opts.get('import_branch'): |
|
956 | 956 | branch = branch or 'default' |
|
957 | 957 | else: |
|
958 | 958 | branch = p1.branch() |
|
959 | 959 | store = patch.filestore() |
|
960 | 960 | try: |
|
961 | 961 | files = set() |
|
962 | 962 | try: |
|
963 | 963 | patch.patchrepo(ui, repo, p1, store, tmpname, strip, prefix, |
|
964 | 964 | files, eolmode=None) |
|
965 | 965 | except patch.PatchError as e: |
|
966 | 966 | raise util.Abort(str(e)) |
|
967 | 967 | if opts.get('exact'): |
|
968 | 968 | editor = None |
|
969 | 969 | else: |
|
970 | 970 | editor = getcommiteditor(editform='import.bypass') |
|
971 | 971 | memctx = context.makememctx(repo, (p1.node(), p2.node()), |
|
972 | 972 | message, |
|
973 | 973 | opts.get('user') or user, |
|
974 | 974 | opts.get('date') or date, |
|
975 | 975 | branch, files, store, |
|
976 | 976 | editor=editor) |
|
977 | 977 | n = memctx.commit() |
|
978 | 978 | finally: |
|
979 | 979 | store.close() |
|
980 | 980 | if opts.get('exact') and opts.get('no_commit'): |
|
981 | 981 | # --exact with --no-commit is still useful in that it does merge |
|
982 | 982 | # and branch bits |
|
983 | 983 | ui.warn(_("warning: can't check exact import with --no-commit\n")) |
|
984 | 984 | elif opts.get('exact') and hex(n) != nodeid: |
|
985 | 985 | raise util.Abort(_('patch is damaged or loses information')) |
|
986 | 986 | if n: |
|
987 | 987 | # i18n: refers to a short changeset id |
|
988 | 988 | msg = _('created %s') % short(n) |
|
989 | 989 | return (msg, n, rejects) |
|
990 | 990 | finally: |
|
991 | 991 | lockmod.release(dsguard) |
|
992 | 992 | os.unlink(tmpname) |
|
993 | 993 | |
|
994 | 994 | def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, |
|
995 | 995 | opts=None, match=None): |
|
996 | 996 | '''export changesets as hg patches.''' |
|
997 | 997 | |
|
998 | 998 | total = len(revs) |
|
999 | 999 | revwidth = max([len(str(rev)) for rev in revs]) |
|
1000 | 1000 | filemode = {} |
|
1001 | 1001 | |
|
1002 | 1002 | def single(rev, seqno, fp): |
|
1003 | 1003 | ctx = repo[rev] |
|
1004 | 1004 | node = ctx.node() |
|
1005 | 1005 | parents = [p.node() for p in ctx.parents() if p] |
|
1006 | 1006 | branch = ctx.branch() |
|
1007 | 1007 | if switch_parent: |
|
1008 | 1008 | parents.reverse() |
|
1009 | 1009 | |
|
1010 | 1010 | if parents: |
|
1011 | 1011 | prev = parents[0] |
|
1012 | 1012 | else: |
|
1013 | 1013 | prev = nullid |
|
1014 | 1014 | |
|
1015 | 1015 | shouldclose = False |
|
1016 | 1016 | if not fp and len(template) > 0: |
|
1017 | 1017 | desc_lines = ctx.description().rstrip().split('\n') |
|
1018 | 1018 | desc = desc_lines[0] #Commit always has a first line. |
|
1019 | 1019 | fp = makefileobj(repo, template, node, desc=desc, total=total, |
|
1020 | 1020 | seqno=seqno, revwidth=revwidth, mode='wb', |
|
1021 | 1021 | modemap=filemode) |
|
1022 | 1022 | if fp != template: |
|
1023 | 1023 | shouldclose = True |
|
1024 | 1024 | if fp and fp != sys.stdout and util.safehasattr(fp, 'name'): |
|
1025 | 1025 | repo.ui.note("%s\n" % fp.name) |
|
1026 | 1026 | |
|
1027 | 1027 | if not fp: |
|
1028 | 1028 | write = repo.ui.write |
|
1029 | 1029 | else: |
|
1030 | 1030 | def write(s, **kw): |
|
1031 | 1031 | fp.write(s) |
|
1032 | 1032 | |
|
1033 | 1033 | write("# HG changeset patch\n") |
|
1034 | 1034 | write("# User %s\n" % ctx.user()) |
|
1035 | 1035 | write("# Date %d %d\n" % ctx.date()) |
|
1036 | 1036 | write("# %s\n" % util.datestr(ctx.date())) |
|
1037 | 1037 | if branch and branch != 'default': |
|
1038 | 1038 | write("# Branch %s\n" % branch) |
|
1039 | 1039 | write("# Node ID %s\n" % hex(node)) |
|
1040 | 1040 | write("# Parent %s\n" % hex(prev)) |
|
1041 | 1041 | if len(parents) > 1: |
|
1042 | 1042 | write("# Parent %s\n" % hex(parents[1])) |
|
1043 | 1043 | write(ctx.description().rstrip()) |
|
1044 | 1044 | write("\n\n") |
|
1045 | 1045 | |
|
1046 | 1046 | for chunk, label in patch.diffui(repo, prev, node, match, opts=opts): |
|
1047 | 1047 | write(chunk, label=label) |
|
1048 | 1048 | |
|
1049 | 1049 | if shouldclose: |
|
1050 | 1050 | fp.close() |
|
1051 | 1051 | |
|
1052 | 1052 | for seqno, rev in enumerate(revs): |
|
1053 | 1053 | single(rev, seqno + 1, fp) |
|
1054 | 1054 | |
|
1055 | 1055 | def diffordiffstat(ui, repo, diffopts, node1, node2, match, |
|
1056 | 1056 | changes=None, stat=False, fp=None, prefix='', |
|
1057 | 1057 | root='', listsubrepos=False): |
|
1058 | 1058 | '''show diff or diffstat.''' |
|
1059 | 1059 | if fp is None: |
|
1060 | 1060 | write = ui.write |
|
1061 | 1061 | else: |
|
1062 | 1062 | def write(s, **kw): |
|
1063 | 1063 | fp.write(s) |
|
1064 | 1064 | |
|
1065 | 1065 | if root: |
|
1066 | 1066 | relroot = pathutil.canonpath(repo.root, repo.getcwd(), root) |
|
1067 | 1067 | else: |
|
1068 | 1068 | relroot = '' |
|
1069 | 1069 | if relroot != '': |
|
1070 | 1070 | # XXX relative roots currently don't work if the root is within a |
|
1071 | 1071 | # subrepo |
|
1072 | 1072 | uirelroot = match.uipath(relroot) |
|
1073 | 1073 | relroot += '/' |
|
1074 | 1074 | for matchroot in match.files(): |
|
1075 | 1075 | if not matchroot.startswith(relroot): |
|
1076 | 1076 | ui.warn(_('warning: %s not inside relative root %s\n') % ( |
|
1077 | 1077 | match.uipath(matchroot), uirelroot)) |
|
1078 | 1078 | |
|
1079 | 1079 | if stat: |
|
1080 | 1080 | diffopts = diffopts.copy(context=0) |
|
1081 | 1081 | width = 80 |
|
1082 | 1082 | if not ui.plain(): |
|
1083 | 1083 | width = ui.termwidth() |
|
1084 | 1084 | chunks = patch.diff(repo, node1, node2, match, changes, diffopts, |
|
1085 | 1085 | prefix=prefix, relroot=relroot) |
|
1086 | 1086 | for chunk, label in patch.diffstatui(util.iterlines(chunks), |
|
1087 | 1087 | width=width, |
|
1088 | 1088 | git=diffopts.git): |
|
1089 | 1089 | write(chunk, label=label) |
|
1090 | 1090 | else: |
|
1091 | 1091 | for chunk, label in patch.diffui(repo, node1, node2, match, |
|
1092 | 1092 | changes, diffopts, prefix=prefix, |
|
1093 | 1093 | relroot=relroot): |
|
1094 | 1094 | write(chunk, label=label) |
|
1095 | 1095 | |
|
1096 | 1096 | if listsubrepos: |
|
1097 | 1097 | ctx1 = repo[node1] |
|
1098 | 1098 | ctx2 = repo[node2] |
|
1099 | 1099 | for subpath, sub in scmutil.itersubrepos(ctx1, ctx2): |
|
1100 | 1100 | tempnode2 = node2 |
|
1101 | 1101 | try: |
|
1102 | 1102 | if node2 is not None: |
|
1103 | 1103 | tempnode2 = ctx2.substate[subpath][1] |
|
1104 | 1104 | except KeyError: |
|
1105 | 1105 | # A subrepo that existed in node1 was deleted between node1 and |
|
1106 | 1106 | # node2 (inclusive). Thus, ctx2's substate won't contain that |
|
1107 | 1107 | # subpath. The best we can do is to ignore it. |
|
1108 | 1108 | tempnode2 = None |
|
1109 | 1109 | submatch = matchmod.narrowmatcher(subpath, match) |
|
1110 | 1110 | sub.diff(ui, diffopts, tempnode2, submatch, changes=changes, |
|
1111 | 1111 | stat=stat, fp=fp, prefix=prefix) |
|
1112 | 1112 | |
|
1113 | 1113 | class changeset_printer(object): |
|
1114 | 1114 | '''show changeset information when templating not requested.''' |
|
1115 | 1115 | |
|
1116 | 1116 | def __init__(self, ui, repo, matchfn, diffopts, buffered): |
|
1117 | 1117 | self.ui = ui |
|
1118 | 1118 | self.repo = repo |
|
1119 | 1119 | self.buffered = buffered |
|
1120 | 1120 | self.matchfn = matchfn |
|
1121 | 1121 | self.diffopts = diffopts |
|
1122 | 1122 | self.header = {} |
|
1123 | 1123 | self.hunk = {} |
|
1124 | 1124 | self.lastheader = None |
|
1125 | 1125 | self.footer = None |
|
1126 | 1126 | |
|
1127 | 1127 | def flush(self, ctx): |
|
1128 | 1128 | rev = ctx.rev() |
|
1129 | 1129 | if rev in self.header: |
|
1130 | 1130 | h = self.header[rev] |
|
1131 | 1131 | if h != self.lastheader: |
|
1132 | 1132 | self.lastheader = h |
|
1133 | 1133 | self.ui.write(h) |
|
1134 | 1134 | del self.header[rev] |
|
1135 | 1135 | if rev in self.hunk: |
|
1136 | 1136 | self.ui.write(self.hunk[rev]) |
|
1137 | 1137 | del self.hunk[rev] |
|
1138 | 1138 | return 1 |
|
1139 | 1139 | return 0 |
|
1140 | 1140 | |
|
1141 | 1141 | def close(self): |
|
1142 | 1142 | if self.footer: |
|
1143 | 1143 | self.ui.write(self.footer) |
|
1144 | 1144 | |
|
1145 | 1145 | def show(self, ctx, copies=None, matchfn=None, **props): |
|
1146 | 1146 | if self.buffered: |
|
1147 | 1147 | self.ui.pushbuffer() |
|
1148 | 1148 | self._show(ctx, copies, matchfn, props) |
|
1149 | 1149 | self.hunk[ctx.rev()] = self.ui.popbuffer(labeled=True) |
|
1150 | 1150 | else: |
|
1151 | 1151 | self._show(ctx, copies, matchfn, props) |
|
1152 | 1152 | |
|
1153 | 1153 | def _show(self, ctx, copies, matchfn, props): |
|
1154 | 1154 | '''show a single changeset or file revision''' |
|
1155 | 1155 | changenode = ctx.node() |
|
1156 | 1156 | rev = ctx.rev() |
|
1157 | 1157 | if self.ui.debugflag: |
|
1158 | 1158 | hexfunc = hex |
|
1159 | 1159 | else: |
|
1160 | 1160 | hexfunc = short |
|
1161 | 1161 | # as of now, wctx.node() and wctx.rev() return None, but we want to |
|
1162 | 1162 | # show the same values as {node} and {rev} templatekw |
|
1163 | 1163 | revnode = (scmutil.intrev(rev), hexfunc(bin(ctx.hex()))) |
|
1164 | 1164 | |
|
1165 | 1165 | if self.ui.quiet: |
|
1166 | 1166 | self.ui.write("%d:%s\n" % revnode, label='log.node') |
|
1167 | 1167 | return |
|
1168 | 1168 | |
|
1169 | 1169 | date = util.datestr(ctx.date()) |
|
1170 | 1170 | |
|
1171 | 1171 | # i18n: column positioning for "hg log" |
|
1172 | 1172 | self.ui.write(_("changeset: %d:%s\n") % revnode, |
|
1173 | 1173 | label='log.changeset changeset.%s' % ctx.phasestr()) |
|
1174 | 1174 | |
|
1175 | 1175 | # branches are shown first before any other names due to backwards |
|
1176 | 1176 | # compatibility |
|
1177 | 1177 | branch = ctx.branch() |
|
1178 | 1178 | # don't show the default branch name |
|
1179 | 1179 | if branch != 'default': |
|
1180 | 1180 | # i18n: column positioning for "hg log" |
|
1181 | 1181 | self.ui.write(_("branch: %s\n") % branch, |
|
1182 | 1182 | label='log.branch') |
|
1183 | 1183 | |
|
1184 | 1184 | for name, ns in self.repo.names.iteritems(): |
|
1185 | 1185 | # branches has special logic already handled above, so here we just |
|
1186 | 1186 | # skip it |
|
1187 | 1187 | if name == 'branches': |
|
1188 | 1188 | continue |
|
1189 | 1189 | # we will use the templatename as the color name since those two |
|
1190 | 1190 | # should be the same |
|
1191 | 1191 | for name in ns.names(self.repo, changenode): |
|
1192 | 1192 | self.ui.write(ns.logfmt % name, |
|
1193 | 1193 | label='log.%s' % ns.colorname) |
|
1194 | 1194 | if self.ui.debugflag: |
|
1195 | 1195 | # i18n: column positioning for "hg log" |
|
1196 | 1196 | self.ui.write(_("phase: %s\n") % ctx.phasestr(), |
|
1197 | 1197 | label='log.phase') |
|
1198 | 1198 | for pctx in scmutil.meaningfulparents(self.repo, ctx): |
|
1199 | 1199 | label = 'log.parent changeset.%s' % pctx.phasestr() |
|
1200 | 1200 | # i18n: column positioning for "hg log" |
|
1201 | 1201 | self.ui.write(_("parent: %d:%s\n") |
|
1202 | 1202 | % (pctx.rev(), hexfunc(pctx.node())), |
|
1203 | 1203 | label=label) |
|
1204 | 1204 | |
|
1205 | 1205 | if self.ui.debugflag and rev is not None: |
|
1206 | 1206 | mnode = ctx.manifestnode() |
|
1207 | 1207 | # i18n: column positioning for "hg log" |
|
1208 | 1208 | self.ui.write(_("manifest: %d:%s\n") % |
|
1209 | 1209 | (self.repo.manifest.rev(mnode), hex(mnode)), |
|
1210 | 1210 | label='ui.debug log.manifest') |
|
1211 | 1211 | # i18n: column positioning for "hg log" |
|
1212 | 1212 | self.ui.write(_("user: %s\n") % ctx.user(), |
|
1213 | 1213 | label='log.user') |
|
1214 | 1214 | # i18n: column positioning for "hg log" |
|
1215 | 1215 | self.ui.write(_("date: %s\n") % date, |
|
1216 | 1216 | label='log.date') |
|
1217 | 1217 | |
|
1218 | 1218 | if self.ui.debugflag: |
|
1219 | 1219 | files = ctx.p1().status(ctx)[:3] |
|
1220 | 1220 | for key, value in zip([# i18n: column positioning for "hg log" |
|
1221 | 1221 | _("files:"), |
|
1222 | 1222 | # i18n: column positioning for "hg log" |
|
1223 | 1223 | _("files+:"), |
|
1224 | 1224 | # i18n: column positioning for "hg log" |
|
1225 | 1225 | _("files-:")], files): |
|
1226 | 1226 | if value: |
|
1227 | 1227 | self.ui.write("%-12s %s\n" % (key, " ".join(value)), |
|
1228 | 1228 | label='ui.debug log.files') |
|
1229 | 1229 | elif ctx.files() and self.ui.verbose: |
|
1230 | 1230 | # i18n: column positioning for "hg log" |
|
1231 | 1231 | self.ui.write(_("files: %s\n") % " ".join(ctx.files()), |
|
1232 | 1232 | label='ui.note log.files') |
|
1233 | 1233 | if copies and self.ui.verbose: |
|
1234 | 1234 | copies = ['%s (%s)' % c for c in copies] |
|
1235 | 1235 | # i18n: column positioning for "hg log" |
|
1236 | 1236 | self.ui.write(_("copies: %s\n") % ' '.join(copies), |
|
1237 | 1237 | label='ui.note log.copies') |
|
1238 | 1238 | |
|
1239 | 1239 | extra = ctx.extra() |
|
1240 | 1240 | if extra and self.ui.debugflag: |
|
1241 | 1241 | for key, value in sorted(extra.items()): |
|
1242 | 1242 | # i18n: column positioning for "hg log" |
|
1243 | 1243 | self.ui.write(_("extra: %s=%s\n") |
|
1244 | 1244 | % (key, value.encode('string_escape')), |
|
1245 | 1245 | label='ui.debug log.extra') |
|
1246 | 1246 | |
|
1247 | 1247 | description = ctx.description().strip() |
|
1248 | 1248 | if description: |
|
1249 | 1249 | if self.ui.verbose: |
|
1250 | 1250 | self.ui.write(_("description:\n"), |
|
1251 | 1251 | label='ui.note log.description') |
|
1252 | 1252 | self.ui.write(description, |
|
1253 | 1253 | label='ui.note log.description') |
|
1254 | 1254 | self.ui.write("\n\n") |
|
1255 | 1255 | else: |
|
1256 | 1256 | # i18n: column positioning for "hg log" |
|
1257 | 1257 | self.ui.write(_("summary: %s\n") % |
|
1258 | 1258 | description.splitlines()[0], |
|
1259 | 1259 | label='log.summary') |
|
1260 | 1260 | self.ui.write("\n") |
|
1261 | 1261 | |
|
1262 | 1262 | self.showpatch(changenode, matchfn) |
|
1263 | 1263 | |
|
1264 | 1264 | def showpatch(self, node, matchfn): |
|
1265 | 1265 | if not matchfn: |
|
1266 | 1266 | matchfn = self.matchfn |
|
1267 | 1267 | if matchfn: |
|
1268 | 1268 | stat = self.diffopts.get('stat') |
|
1269 | 1269 | diff = self.diffopts.get('patch') |
|
1270 | 1270 | diffopts = patch.diffallopts(self.ui, self.diffopts) |
|
1271 | 1271 | prev = self.repo.changelog.parents(node)[0] |
|
1272 | 1272 | if stat: |
|
1273 | 1273 | diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
|
1274 | 1274 | match=matchfn, stat=True) |
|
1275 | 1275 | if diff: |
|
1276 | 1276 | if stat: |
|
1277 | 1277 | self.ui.write("\n") |
|
1278 | 1278 | diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
|
1279 | 1279 | match=matchfn, stat=False) |
|
1280 | 1280 | self.ui.write("\n") |
|
1281 | 1281 | |
|
1282 | 1282 | class jsonchangeset(changeset_printer): |
|
1283 | 1283 | '''format changeset information.''' |
|
1284 | 1284 | |
|
1285 | 1285 | def __init__(self, ui, repo, matchfn, diffopts, buffered): |
|
1286 | 1286 | changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered) |
|
1287 | 1287 | self.cache = {} |
|
1288 | 1288 | self._first = True |
|
1289 | 1289 | |
|
1290 | 1290 | def close(self): |
|
1291 | 1291 | if not self._first: |
|
1292 | 1292 | self.ui.write("\n]\n") |
|
1293 | 1293 | else: |
|
1294 | 1294 | self.ui.write("[]\n") |
|
1295 | 1295 | |
|
1296 | 1296 | def _show(self, ctx, copies, matchfn, props): |
|
1297 | 1297 | '''show a single changeset or file revision''' |
|
1298 | 1298 | rev = ctx.rev() |
|
1299 | 1299 | if rev is None: |
|
1300 | 1300 | jrev = jnode = 'null' |
|
1301 | 1301 | else: |
|
1302 | 1302 | jrev = str(rev) |
|
1303 | 1303 | jnode = '"%s"' % hex(ctx.node()) |
|
1304 | 1304 | j = encoding.jsonescape |
|
1305 | 1305 | |
|
1306 | 1306 | if self._first: |
|
1307 | 1307 | self.ui.write("[\n {") |
|
1308 | 1308 | self._first = False |
|
1309 | 1309 | else: |
|
1310 | 1310 | self.ui.write(",\n {") |
|
1311 | 1311 | |
|
1312 | 1312 | if self.ui.quiet: |
|
1313 | 1313 | self.ui.write('\n "rev": %s' % jrev) |
|
1314 | 1314 | self.ui.write(',\n "node": %s' % jnode) |
|
1315 | 1315 | self.ui.write('\n }') |
|
1316 | 1316 | return |
|
1317 | 1317 | |
|
1318 | 1318 | self.ui.write('\n "rev": %s' % jrev) |
|
1319 | 1319 | self.ui.write(',\n "node": %s' % jnode) |
|
1320 | 1320 | self.ui.write(',\n "branch": "%s"' % j(ctx.branch())) |
|
1321 | 1321 | self.ui.write(',\n "phase": "%s"' % ctx.phasestr()) |
|
1322 | 1322 | self.ui.write(',\n "user": "%s"' % j(ctx.user())) |
|
1323 | 1323 | self.ui.write(',\n "date": [%d, %d]' % ctx.date()) |
|
1324 | 1324 | self.ui.write(',\n "desc": "%s"' % j(ctx.description())) |
|
1325 | 1325 | |
|
1326 | 1326 | self.ui.write(',\n "bookmarks": [%s]' % |
|
1327 | 1327 | ", ".join('"%s"' % j(b) for b in ctx.bookmarks())) |
|
1328 | 1328 | self.ui.write(',\n "tags": [%s]' % |
|
1329 | 1329 | ", ".join('"%s"' % j(t) for t in ctx.tags())) |
|
1330 | 1330 | self.ui.write(',\n "parents": [%s]' % |
|
1331 | 1331 | ", ".join('"%s"' % c.hex() for c in ctx.parents())) |
|
1332 | 1332 | |
|
1333 | 1333 | if self.ui.debugflag: |
|
1334 | 1334 | if rev is None: |
|
1335 | 1335 | jmanifestnode = 'null' |
|
1336 | 1336 | else: |
|
1337 | 1337 | jmanifestnode = '"%s"' % hex(ctx.manifestnode()) |
|
1338 | 1338 | self.ui.write(',\n "manifest": %s' % jmanifestnode) |
|
1339 | 1339 | |
|
1340 | 1340 | self.ui.write(',\n "extra": {%s}' % |
|
1341 | 1341 | ", ".join('"%s": "%s"' % (j(k), j(v)) |
|
1342 | 1342 | for k, v in ctx.extra().items())) |
|
1343 | 1343 | |
|
1344 | 1344 | files = ctx.p1().status(ctx) |
|
1345 | 1345 | self.ui.write(',\n "modified": [%s]' % |
|
1346 | 1346 | ", ".join('"%s"' % j(f) for f in files[0])) |
|
1347 | 1347 | self.ui.write(',\n "added": [%s]' % |
|
1348 | 1348 | ", ".join('"%s"' % j(f) for f in files[1])) |
|
1349 | 1349 | self.ui.write(',\n "removed": [%s]' % |
|
1350 | 1350 | ", ".join('"%s"' % j(f) for f in files[2])) |
|
1351 | 1351 | |
|
1352 | 1352 | elif self.ui.verbose: |
|
1353 | 1353 | self.ui.write(',\n "files": [%s]' % |
|
1354 | 1354 | ", ".join('"%s"' % j(f) for f in ctx.files())) |
|
1355 | 1355 | |
|
1356 | 1356 | if copies: |
|
1357 | 1357 | self.ui.write(',\n "copies": {%s}' % |
|
1358 | 1358 | ", ".join('"%s": "%s"' % (j(k), j(v)) |
|
1359 | 1359 | for k, v in copies)) |
|
1360 | 1360 | |
|
1361 | 1361 | matchfn = self.matchfn |
|
1362 | 1362 | if matchfn: |
|
1363 | 1363 | stat = self.diffopts.get('stat') |
|
1364 | 1364 | diff = self.diffopts.get('patch') |
|
1365 | 1365 | diffopts = patch.difffeatureopts(self.ui, self.diffopts, git=True) |
|
1366 | 1366 | node, prev = ctx.node(), ctx.p1().node() |
|
1367 | 1367 | if stat: |
|
1368 | 1368 | self.ui.pushbuffer() |
|
1369 | 1369 | diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
|
1370 | 1370 | match=matchfn, stat=True) |
|
1371 | 1371 | self.ui.write(',\n "diffstat": "%s"' % j(self.ui.popbuffer())) |
|
1372 | 1372 | if diff: |
|
1373 | 1373 | self.ui.pushbuffer() |
|
1374 | 1374 | diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
|
1375 | 1375 | match=matchfn, stat=False) |
|
1376 | 1376 | self.ui.write(',\n "diff": "%s"' % j(self.ui.popbuffer())) |
|
1377 | 1377 | |
|
1378 | 1378 | self.ui.write("\n }") |
|
1379 | 1379 | |
|
1380 | 1380 | class changeset_templater(changeset_printer): |
|
1381 | 1381 | '''format changeset information.''' |
|
1382 | 1382 | |
|
1383 | 1383 | def __init__(self, ui, repo, matchfn, diffopts, tmpl, mapfile, buffered): |
|
1384 | 1384 | changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered) |
|
1385 | 1385 | formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12]) |
|
1386 | 1386 | defaulttempl = { |
|
1387 | 1387 | 'parent': '{rev}:{node|formatnode} ', |
|
1388 | 1388 | 'manifest': '{rev}:{node|formatnode}', |
|
1389 | 1389 | 'file_copy': '{name} ({source})', |
|
1390 | 1390 | 'extra': '{key}={value|stringescape}' |
|
1391 | 1391 | } |
|
1392 | 1392 | # filecopy is preserved for compatibility reasons |
|
1393 | 1393 | defaulttempl['filecopy'] = defaulttempl['file_copy'] |
|
1394 | 1394 | self.t = templater.templater(mapfile, {'formatnode': formatnode}, |
|
1395 | 1395 | cache=defaulttempl) |
|
1396 | 1396 | if tmpl: |
|
1397 | 1397 | self.t.cache['changeset'] = tmpl |
|
1398 | 1398 | |
|
1399 | 1399 | self.cache = {} |
|
1400 | 1400 | |
|
1401 | 1401 | # find correct templates for current mode |
|
1402 | 1402 | tmplmodes = [ |
|
1403 | 1403 | (True, None), |
|
1404 | 1404 | (self.ui.verbose, 'verbose'), |
|
1405 | 1405 | (self.ui.quiet, 'quiet'), |
|
1406 | 1406 | (self.ui.debugflag, 'debug'), |
|
1407 | 1407 | ] |
|
1408 | 1408 | |
|
1409 | 1409 | self._parts = {'header': '', 'footer': '', 'changeset': 'changeset', |
|
1410 | 1410 | 'docheader': '', 'docfooter': ''} |
|
1411 | 1411 | for mode, postfix in tmplmodes: |
|
1412 | 1412 | for t in self._parts: |
|
1413 | 1413 | cur = t |
|
1414 | 1414 | if postfix: |
|
1415 | 1415 | cur += "_" + postfix |
|
1416 | 1416 | if mode and cur in self.t: |
|
1417 | 1417 | self._parts[t] = cur |
|
1418 | 1418 | |
|
1419 | 1419 | if self._parts['docheader']: |
|
1420 | 1420 | self.ui.write(templater.stringify(self.t(self._parts['docheader']))) |
|
1421 | 1421 | |
|
1422 | 1422 | def close(self): |
|
1423 | 1423 | if self._parts['docfooter']: |
|
1424 | 1424 | if not self.footer: |
|
1425 | 1425 | self.footer = "" |
|
1426 | 1426 | self.footer += templater.stringify(self.t(self._parts['docfooter'])) |
|
1427 | 1427 | return super(changeset_templater, self).close() |
|
1428 | 1428 | |
|
1429 | 1429 | def _show(self, ctx, copies, matchfn, props): |
|
1430 | 1430 | '''show a single changeset or file revision''' |
|
1431 | 1431 | props = props.copy() |
|
1432 | 1432 | props.update(templatekw.keywords) |
|
1433 | 1433 | props['templ'] = self.t |
|
1434 | 1434 | props['ctx'] = ctx |
|
1435 | 1435 | props['repo'] = self.repo |
|
1436 | 1436 | props['revcache'] = {'copies': copies} |
|
1437 | 1437 | props['cache'] = self.cache |
|
1438 | 1438 | |
|
1439 | 1439 | try: |
|
1440 | 1440 | # write header |
|
1441 | 1441 | if self._parts['header']: |
|
1442 | 1442 | h = templater.stringify(self.t(self._parts['header'], **props)) |
|
1443 | 1443 | if self.buffered: |
|
1444 | 1444 | self.header[ctx.rev()] = h |
|
1445 | 1445 | else: |
|
1446 | 1446 | if self.lastheader != h: |
|
1447 | 1447 | self.lastheader = h |
|
1448 | 1448 | self.ui.write(h) |
|
1449 | 1449 | |
|
1450 | 1450 | # write changeset metadata, then patch if requested |
|
1451 | 1451 | key = self._parts['changeset'] |
|
1452 | 1452 | self.ui.write(templater.stringify(self.t(key, **props))) |
|
1453 | 1453 | self.showpatch(ctx.node(), matchfn) |
|
1454 | 1454 | |
|
1455 | 1455 | if self._parts['footer']: |
|
1456 | 1456 | if not self.footer: |
|
1457 | 1457 | self.footer = templater.stringify( |
|
1458 | 1458 | self.t(self._parts['footer'], **props)) |
|
1459 | 1459 | except KeyError as inst: |
|
1460 | 1460 | msg = _("%s: no key named '%s'") |
|
1461 | 1461 | raise util.Abort(msg % (self.t.mapfile, inst.args[0])) |
|
1462 | 1462 | except SyntaxError as inst: |
|
1463 | 1463 | raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0])) |
|
1464 | 1464 | |
|
1465 | 1465 | def gettemplate(ui, tmpl, style): |
|
1466 | 1466 | """ |
|
1467 | 1467 | Find the template matching the given template spec or style. |
|
1468 | 1468 | """ |
|
1469 | 1469 | |
|
1470 | 1470 | # ui settings |
|
1471 | 1471 | if not tmpl and not style: # template are stronger than style |
|
1472 | 1472 | tmpl = ui.config('ui', 'logtemplate') |
|
1473 | 1473 | if tmpl: |
|
1474 | 1474 | try: |
|
1475 | 1475 | tmpl = templater.unquotestring(tmpl) |
|
1476 | 1476 | except SyntaxError: |
|
1477 | 1477 | pass |
|
1478 | 1478 | return tmpl, None |
|
1479 | 1479 | else: |
|
1480 | 1480 | style = util.expandpath(ui.config('ui', 'style', '')) |
|
1481 | 1481 | |
|
1482 | 1482 | if not tmpl and style: |
|
1483 | 1483 | mapfile = style |
|
1484 | 1484 | if not os.path.split(mapfile)[0]: |
|
1485 | 1485 | mapname = (templater.templatepath('map-cmdline.' + mapfile) |
|
1486 | 1486 | or templater.templatepath(mapfile)) |
|
1487 | 1487 | if mapname: |
|
1488 | 1488 | mapfile = mapname |
|
1489 | 1489 | return None, mapfile |
|
1490 | 1490 | |
|
1491 | 1491 | if not tmpl: |
|
1492 | 1492 | return None, None |
|
1493 | 1493 | |
|
1494 | 1494 | return formatter.lookuptemplate(ui, 'changeset', tmpl) |
|
1495 | 1495 | |
|
1496 | 1496 | def show_changeset(ui, repo, opts, buffered=False): |
|
1497 | 1497 | """show one changeset using template or regular display. |
|
1498 | 1498 | |
|
1499 | 1499 | Display format will be the first non-empty hit of: |
|
1500 | 1500 | 1. option 'template' |
|
1501 | 1501 | 2. option 'style' |
|
1502 | 1502 | 3. [ui] setting 'logtemplate' |
|
1503 | 1503 | 4. [ui] setting 'style' |
|
1504 | 1504 | If all of these values are either the unset or the empty string, |
|
1505 | 1505 | regular display via changeset_printer() is done. |
|
1506 | 1506 | """ |
|
1507 | 1507 | # options |
|
1508 | 1508 | matchfn = None |
|
1509 | 1509 | if opts.get('patch') or opts.get('stat'): |
|
1510 | 1510 | matchfn = scmutil.matchall(repo) |
|
1511 | 1511 | |
|
1512 | 1512 | if opts.get('template') == 'json': |
|
1513 | 1513 | return jsonchangeset(ui, repo, matchfn, opts, buffered) |
|
1514 | 1514 | |
|
1515 | 1515 | tmpl, mapfile = gettemplate(ui, opts.get('template'), opts.get('style')) |
|
1516 | 1516 | |
|
1517 | 1517 | if not tmpl and not mapfile: |
|
1518 | 1518 | return changeset_printer(ui, repo, matchfn, opts, buffered) |
|
1519 | 1519 | |
|
1520 | 1520 | try: |
|
1521 | 1521 | t = changeset_templater(ui, repo, matchfn, opts, tmpl, mapfile, |
|
1522 | 1522 | buffered) |
|
1523 | 1523 | except SyntaxError as inst: |
|
1524 | 1524 | raise util.Abort(inst.args[0]) |
|
1525 | 1525 | return t |
|
1526 | 1526 | |
|
1527 | 1527 | def showmarker(ui, marker): |
|
1528 | 1528 | """utility function to display obsolescence marker in a readable way |
|
1529 | 1529 | |
|
1530 | 1530 | To be used by debug function.""" |
|
1531 | 1531 | ui.write(hex(marker.precnode())) |
|
1532 | 1532 | for repl in marker.succnodes(): |
|
1533 | 1533 | ui.write(' ') |
|
1534 | 1534 | ui.write(hex(repl)) |
|
1535 | 1535 | ui.write(' %X ' % marker.flags()) |
|
1536 | 1536 | parents = marker.parentnodes() |
|
1537 | 1537 | if parents is not None: |
|
1538 | 1538 | ui.write('{%s} ' % ', '.join(hex(p) for p in parents)) |
|
1539 | 1539 | ui.write('(%s) ' % util.datestr(marker.date())) |
|
1540 | 1540 | ui.write('{%s}' % (', '.join('%r: %r' % t for t in |
|
1541 | 1541 | sorted(marker.metadata().items()) |
|
1542 | 1542 | if t[0] != 'date'))) |
|
1543 | 1543 | ui.write('\n') |
|
1544 | 1544 | |
|
1545 | 1545 | def finddate(ui, repo, date): |
|
1546 | 1546 | """Find the tipmost changeset that matches the given date spec""" |
|
1547 | 1547 | |
|
1548 | 1548 | df = util.matchdate(date) |
|
1549 | 1549 | m = scmutil.matchall(repo) |
|
1550 | 1550 | results = {} |
|
1551 | 1551 | |
|
1552 | 1552 | def prep(ctx, fns): |
|
1553 | 1553 | d = ctx.date() |
|
1554 | 1554 | if df(d[0]): |
|
1555 | 1555 | results[ctx.rev()] = d |
|
1556 | 1556 | |
|
1557 | 1557 | for ctx in walkchangerevs(repo, m, {'rev': None}, prep): |
|
1558 | 1558 | rev = ctx.rev() |
|
1559 | 1559 | if rev in results: |
|
1560 | 1560 | ui.status(_("found revision %s from %s\n") % |
|
1561 | 1561 | (rev, util.datestr(results[rev]))) |
|
1562 | 1562 | return str(rev) |
|
1563 | 1563 | |
|
1564 | 1564 | raise util.Abort(_("revision matching date not found")) |
|
1565 | 1565 | |
|
1566 | 1566 | def increasingwindows(windowsize=8, sizelimit=512): |
|
1567 | 1567 | while True: |
|
1568 | 1568 | yield windowsize |
|
1569 | 1569 | if windowsize < sizelimit: |
|
1570 | 1570 | windowsize *= 2 |
|
1571 | 1571 | |
|
1572 | 1572 | class FileWalkError(Exception): |
|
1573 | 1573 | pass |
|
1574 | 1574 | |
|
1575 | 1575 | def walkfilerevs(repo, match, follow, revs, fncache): |
|
1576 | 1576 | '''Walks the file history for the matched files. |
|
1577 | 1577 | |
|
1578 | 1578 | Returns the changeset revs that are involved in the file history. |
|
1579 | 1579 | |
|
1580 | 1580 | Throws FileWalkError if the file history can't be walked using |
|
1581 | 1581 | filelogs alone. |
|
1582 | 1582 | ''' |
|
1583 | 1583 | wanted = set() |
|
1584 | 1584 | copies = [] |
|
1585 | 1585 | minrev, maxrev = min(revs), max(revs) |
|
1586 | 1586 | def filerevgen(filelog, last): |
|
1587 | 1587 | """ |
|
1588 | 1588 | Only files, no patterns. Check the history of each file. |
|
1589 | 1589 | |
|
1590 | 1590 | Examines filelog entries within minrev, maxrev linkrev range |
|
1591 | 1591 | Returns an iterator yielding (linkrev, parentlinkrevs, copied) |
|
1592 | 1592 | tuples in backwards order |
|
1593 | 1593 | """ |
|
1594 | 1594 | cl_count = len(repo) |
|
1595 | 1595 | revs = [] |
|
1596 | 1596 | for j in xrange(0, last + 1): |
|
1597 | 1597 | linkrev = filelog.linkrev(j) |
|
1598 | 1598 | if linkrev < minrev: |
|
1599 | 1599 | continue |
|
1600 | 1600 | # only yield rev for which we have the changelog, it can |
|
1601 | 1601 | # happen while doing "hg log" during a pull or commit |
|
1602 | 1602 | if linkrev >= cl_count: |
|
1603 | 1603 | break |
|
1604 | 1604 | |
|
1605 | 1605 | parentlinkrevs = [] |
|
1606 | 1606 | for p in filelog.parentrevs(j): |
|
1607 | 1607 | if p != nullrev: |
|
1608 | 1608 | parentlinkrevs.append(filelog.linkrev(p)) |
|
1609 | 1609 | n = filelog.node(j) |
|
1610 | 1610 | revs.append((linkrev, parentlinkrevs, |
|
1611 | 1611 | follow and filelog.renamed(n))) |
|
1612 | 1612 | |
|
1613 | 1613 | return reversed(revs) |
|
1614 | 1614 | def iterfiles(): |
|
1615 | 1615 | pctx = repo['.'] |
|
1616 | 1616 | for filename in match.files(): |
|
1617 | 1617 | if follow: |
|
1618 | 1618 | if filename not in pctx: |
|
1619 | 1619 | raise util.Abort(_('cannot follow file not in parent ' |
|
1620 | 1620 | 'revision: "%s"') % filename) |
|
1621 | 1621 | yield filename, pctx[filename].filenode() |
|
1622 | 1622 | else: |
|
1623 | 1623 | yield filename, None |
|
1624 | 1624 | for filename_node in copies: |
|
1625 | 1625 | yield filename_node |
|
1626 | 1626 | |
|
1627 | 1627 | for file_, node in iterfiles(): |
|
1628 | 1628 | filelog = repo.file(file_) |
|
1629 | 1629 | if not len(filelog): |
|
1630 | 1630 | if node is None: |
|
1631 | 1631 | # A zero count may be a directory or deleted file, so |
|
1632 | 1632 | # try to find matching entries on the slow path. |
|
1633 | 1633 | if follow: |
|
1634 | 1634 | raise util.Abort( |
|
1635 | 1635 | _('cannot follow nonexistent file: "%s"') % file_) |
|
1636 | 1636 | raise FileWalkError("Cannot walk via filelog") |
|
1637 | 1637 | else: |
|
1638 | 1638 | continue |
|
1639 | 1639 | |
|
1640 | 1640 | if node is None: |
|
1641 | 1641 | last = len(filelog) - 1 |
|
1642 | 1642 | else: |
|
1643 | 1643 | last = filelog.rev(node) |
|
1644 | 1644 | |
|
1645 | 1645 | # keep track of all ancestors of the file |
|
1646 | 1646 | ancestors = set([filelog.linkrev(last)]) |
|
1647 | 1647 | |
|
1648 | 1648 | # iterate from latest to oldest revision |
|
1649 | 1649 | for rev, flparentlinkrevs, copied in filerevgen(filelog, last): |
|
1650 | 1650 | if not follow: |
|
1651 | 1651 | if rev > maxrev: |
|
1652 | 1652 | continue |
|
1653 | 1653 | else: |
|
1654 | 1654 | # Note that last might not be the first interesting |
|
1655 | 1655 | # rev to us: |
|
1656 | 1656 | # if the file has been changed after maxrev, we'll |
|
1657 | 1657 | # have linkrev(last) > maxrev, and we still need |
|
1658 | 1658 | # to explore the file graph |
|
1659 | 1659 | if rev not in ancestors: |
|
1660 | 1660 | continue |
|
1661 | 1661 | # XXX insert 1327 fix here |
|
1662 | 1662 | if flparentlinkrevs: |
|
1663 | 1663 | ancestors.update(flparentlinkrevs) |
|
1664 | 1664 | |
|
1665 | 1665 | fncache.setdefault(rev, []).append(file_) |
|
1666 | 1666 | wanted.add(rev) |
|
1667 | 1667 | if copied: |
|
1668 | 1668 | copies.append(copied) |
|
1669 | 1669 | |
|
1670 | 1670 | return wanted |
|
1671 | 1671 | |
|
1672 | 1672 | class _followfilter(object): |
|
1673 | 1673 | def __init__(self, repo, onlyfirst=False): |
|
1674 | 1674 | self.repo = repo |
|
1675 | 1675 | self.startrev = nullrev |
|
1676 | 1676 | self.roots = set() |
|
1677 | 1677 | self.onlyfirst = onlyfirst |
|
1678 | 1678 | |
|
1679 | 1679 | def match(self, rev): |
|
1680 | 1680 | def realparents(rev): |
|
1681 | 1681 | if self.onlyfirst: |
|
1682 | 1682 | return self.repo.changelog.parentrevs(rev)[0:1] |
|
1683 | 1683 | else: |
|
1684 | 1684 | return filter(lambda x: x != nullrev, |
|
1685 | 1685 | self.repo.changelog.parentrevs(rev)) |
|
1686 | 1686 | |
|
1687 | 1687 | if self.startrev == nullrev: |
|
1688 | 1688 | self.startrev = rev |
|
1689 | 1689 | return True |
|
1690 | 1690 | |
|
1691 | 1691 | if rev > self.startrev: |
|
1692 | 1692 | # forward: all descendants |
|
1693 | 1693 | if not self.roots: |
|
1694 | 1694 | self.roots.add(self.startrev) |
|
1695 | 1695 | for parent in realparents(rev): |
|
1696 | 1696 | if parent in self.roots: |
|
1697 | 1697 | self.roots.add(rev) |
|
1698 | 1698 | return True |
|
1699 | 1699 | else: |
|
1700 | 1700 | # backwards: all parents |
|
1701 | 1701 | if not self.roots: |
|
1702 | 1702 | self.roots.update(realparents(self.startrev)) |
|
1703 | 1703 | if rev in self.roots: |
|
1704 | 1704 | self.roots.remove(rev) |
|
1705 | 1705 | self.roots.update(realparents(rev)) |
|
1706 | 1706 | return True |
|
1707 | 1707 | |
|
1708 | 1708 | return False |
|
1709 | 1709 | |
|
1710 | 1710 | def walkchangerevs(repo, match, opts, prepare): |
|
1711 | 1711 | '''Iterate over files and the revs in which they changed. |
|
1712 | 1712 | |
|
1713 | 1713 | Callers most commonly need to iterate backwards over the history |
|
1714 | 1714 | in which they are interested. Doing so has awful (quadratic-looking) |
|
1715 | 1715 | performance, so we use iterators in a "windowed" way. |
|
1716 | 1716 | |
|
1717 | 1717 | We walk a window of revisions in the desired order. Within the |
|
1718 | 1718 | window, we first walk forwards to gather data, then in the desired |
|
1719 | 1719 | order (usually backwards) to display it. |
|
1720 | 1720 | |
|
1721 | 1721 | This function returns an iterator yielding contexts. Before |
|
1722 | 1722 | yielding each context, the iterator will first call the prepare |
|
1723 | 1723 | function on each context in the window in forward order.''' |
|
1724 | 1724 | |
|
1725 | 1725 | follow = opts.get('follow') or opts.get('follow_first') |
|
1726 | 1726 | revs = _logrevs(repo, opts) |
|
1727 | 1727 | if not revs: |
|
1728 | 1728 | return [] |
|
1729 | 1729 | wanted = set() |
|
1730 | 1730 | slowpath = match.anypats() or ((match.isexact() or match.prefix()) and |
|
1731 | 1731 | opts.get('removed')) |
|
1732 | 1732 | fncache = {} |
|
1733 | 1733 | change = repo.changectx |
|
1734 | 1734 | |
|
1735 | 1735 | # First step is to fill wanted, the set of revisions that we want to yield. |
|
1736 | 1736 | # When it does not induce extra cost, we also fill fncache for revisions in |
|
1737 | 1737 | # wanted: a cache of filenames that were changed (ctx.files()) and that |
|
1738 | 1738 | # match the file filtering conditions. |
|
1739 | 1739 | |
|
1740 | 1740 | if match.always(): |
|
1741 | 1741 | # No files, no patterns. Display all revs. |
|
1742 | 1742 | wanted = revs |
|
1743 | 1743 | elif not slowpath: |
|
1744 | 1744 | # We only have to read through the filelog to find wanted revisions |
|
1745 | 1745 | |
|
1746 | 1746 | try: |
|
1747 | 1747 | wanted = walkfilerevs(repo, match, follow, revs, fncache) |
|
1748 | 1748 | except FileWalkError: |
|
1749 | 1749 | slowpath = True |
|
1750 | 1750 | |
|
1751 | 1751 | # We decided to fall back to the slowpath because at least one |
|
1752 | 1752 | # of the paths was not a file. Check to see if at least one of them |
|
1753 | 1753 | # existed in history, otherwise simply return |
|
1754 | 1754 | for path in match.files(): |
|
1755 | 1755 | if path == '.' or path in repo.store: |
|
1756 | 1756 | break |
|
1757 | 1757 | else: |
|
1758 | 1758 | return [] |
|
1759 | 1759 | |
|
1760 | 1760 | if slowpath: |
|
1761 | 1761 | # We have to read the changelog to match filenames against |
|
1762 | 1762 | # changed files |
|
1763 | 1763 | |
|
1764 | 1764 | if follow: |
|
1765 | 1765 | raise util.Abort(_('can only follow copies/renames for explicit ' |
|
1766 | 1766 | 'filenames')) |
|
1767 | 1767 | |
|
1768 | 1768 | # The slow path checks files modified in every changeset. |
|
1769 | 1769 | # This is really slow on large repos, so compute the set lazily. |
|
1770 | 1770 | class lazywantedset(object): |
|
1771 | 1771 | def __init__(self): |
|
1772 | 1772 | self.set = set() |
|
1773 | 1773 | self.revs = set(revs) |
|
1774 | 1774 | |
|
1775 | 1775 | # No need to worry about locality here because it will be accessed |
|
1776 | 1776 | # in the same order as the increasing window below. |
|
1777 | 1777 | def __contains__(self, value): |
|
1778 | 1778 | if value in self.set: |
|
1779 | 1779 | return True |
|
1780 | 1780 | elif not value in self.revs: |
|
1781 | 1781 | return False |
|
1782 | 1782 | else: |
|
1783 | 1783 | self.revs.discard(value) |
|
1784 | 1784 | ctx = change(value) |
|
1785 | 1785 | matches = filter(match, ctx.files()) |
|
1786 | 1786 | if matches: |
|
1787 | 1787 | fncache[value] = matches |
|
1788 | 1788 | self.set.add(value) |
|
1789 | 1789 | return True |
|
1790 | 1790 | return False |
|
1791 | 1791 | |
|
1792 | 1792 | def discard(self, value): |
|
1793 | 1793 | self.revs.discard(value) |
|
1794 | 1794 | self.set.discard(value) |
|
1795 | 1795 | |
|
1796 | 1796 | wanted = lazywantedset() |
|
1797 | 1797 | |
|
1798 | 1798 | # it might be worthwhile to do this in the iterator if the rev range |
|
1799 | 1799 | # is descending and the prune args are all within that range |
|
1800 | 1800 | for rev in opts.get('prune', ()): |
|
1801 | 1801 | rev = repo[rev].rev() |
|
1802 | 1802 | ff = _followfilter(repo) |
|
1803 | 1803 | stop = min(revs[0], revs[-1]) |
|
1804 | 1804 | for x in xrange(rev, stop - 1, -1): |
|
1805 | 1805 | if ff.match(x): |
|
1806 | 1806 | wanted = wanted - [x] |
|
1807 | 1807 | |
|
1808 | 1808 | # Now that wanted is correctly initialized, we can iterate over the |
|
1809 | 1809 | # revision range, yielding only revisions in wanted. |
|
1810 | 1810 | def iterate(): |
|
1811 | 1811 | if follow and match.always(): |
|
1812 | 1812 | ff = _followfilter(repo, onlyfirst=opts.get('follow_first')) |
|
1813 | 1813 | def want(rev): |
|
1814 | 1814 | return ff.match(rev) and rev in wanted |
|
1815 | 1815 | else: |
|
1816 | 1816 | def want(rev): |
|
1817 | 1817 | return rev in wanted |
|
1818 | 1818 | |
|
1819 | 1819 | it = iter(revs) |
|
1820 | 1820 | stopiteration = False |
|
1821 | 1821 | for windowsize in increasingwindows(): |
|
1822 | 1822 | nrevs = [] |
|
1823 | 1823 | for i in xrange(windowsize): |
|
1824 | 1824 | rev = next(it, None) |
|
1825 | 1825 | if rev is None: |
|
1826 | 1826 | stopiteration = True |
|
1827 | 1827 | break |
|
1828 | 1828 | elif want(rev): |
|
1829 | 1829 | nrevs.append(rev) |
|
1830 | 1830 | for rev in sorted(nrevs): |
|
1831 | 1831 | fns = fncache.get(rev) |
|
1832 | 1832 | ctx = change(rev) |
|
1833 | 1833 | if not fns: |
|
1834 | 1834 | def fns_generator(): |
|
1835 | 1835 | for f in ctx.files(): |
|
1836 | 1836 | if match(f): |
|
1837 | 1837 | yield f |
|
1838 | 1838 | fns = fns_generator() |
|
1839 | 1839 | prepare(ctx, fns) |
|
1840 | 1840 | for rev in nrevs: |
|
1841 | 1841 | yield change(rev) |
|
1842 | 1842 | |
|
1843 | 1843 | if stopiteration: |
|
1844 | 1844 | break |
|
1845 | 1845 | |
|
1846 | 1846 | return iterate() |
|
1847 | 1847 | |
|
1848 | 1848 | def _makefollowlogfilematcher(repo, files, followfirst): |
|
1849 | 1849 | # When displaying a revision with --patch --follow FILE, we have |
|
1850 | 1850 | # to know which file of the revision must be diffed. With |
|
1851 | 1851 | # --follow, we want the names of the ancestors of FILE in the |
|
1852 | 1852 | # revision, stored in "fcache". "fcache" is populated by |
|
1853 | 1853 | # reproducing the graph traversal already done by --follow revset |
|
1854 | 1854 | # and relating linkrevs to file names (which is not "correct" but |
|
1855 | 1855 | # good enough). |
|
1856 | 1856 | fcache = {} |
|
1857 | 1857 | fcacheready = [False] |
|
1858 | 1858 | pctx = repo['.'] |
|
1859 | 1859 | |
|
1860 | 1860 | def populate(): |
|
1861 | 1861 | for fn in files: |
|
1862 | 1862 | for i in ((pctx[fn],), pctx[fn].ancestors(followfirst=followfirst)): |
|
1863 | 1863 | for c in i: |
|
1864 | 1864 | fcache.setdefault(c.linkrev(), set()).add(c.path()) |
|
1865 | 1865 | |
|
1866 | 1866 | def filematcher(rev): |
|
1867 | 1867 | if not fcacheready[0]: |
|
1868 | 1868 | # Lazy initialization |
|
1869 | 1869 | fcacheready[0] = True |
|
1870 | 1870 | populate() |
|
1871 | 1871 | return scmutil.matchfiles(repo, fcache.get(rev, [])) |
|
1872 | 1872 | |
|
1873 | 1873 | return filematcher |
|
1874 | 1874 | |
|
1875 | 1875 | def _makenofollowlogfilematcher(repo, pats, opts): |
|
1876 | 1876 | '''hook for extensions to override the filematcher for non-follow cases''' |
|
1877 | 1877 | return None |
|
1878 | 1878 | |
|
1879 | 1879 | def _makelogrevset(repo, pats, opts, revs): |
|
1880 | 1880 | """Return (expr, filematcher) where expr is a revset string built |
|
1881 | 1881 | from log options and file patterns or None. If --stat or --patch |
|
1882 | 1882 | are not passed filematcher is None. Otherwise it is a callable |
|
1883 | 1883 | taking a revision number and returning a match objects filtering |
|
1884 | 1884 | the files to be detailed when displaying the revision. |
|
1885 | 1885 | """ |
|
1886 | 1886 | opt2revset = { |
|
1887 | 1887 | 'no_merges': ('not merge()', None), |
|
1888 | 1888 | 'only_merges': ('merge()', None), |
|
1889 | 1889 | '_ancestors': ('ancestors(%(val)s)', None), |
|
1890 | 1890 | '_fancestors': ('_firstancestors(%(val)s)', None), |
|
1891 | 1891 | '_descendants': ('descendants(%(val)s)', None), |
|
1892 | 1892 | '_fdescendants': ('_firstdescendants(%(val)s)', None), |
|
1893 | 1893 | '_matchfiles': ('_matchfiles(%(val)s)', None), |
|
1894 | 1894 | 'date': ('date(%(val)r)', None), |
|
1895 | 1895 | 'branch': ('branch(%(val)r)', ' or '), |
|
1896 | 1896 | '_patslog': ('filelog(%(val)r)', ' or '), |
|
1897 | 1897 | '_patsfollow': ('follow(%(val)r)', ' or '), |
|
1898 | 1898 | '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '), |
|
1899 | 1899 | 'keyword': ('keyword(%(val)r)', ' or '), |
|
1900 | 1900 | 'prune': ('not (%(val)r or ancestors(%(val)r))', ' and '), |
|
1901 | 1901 | 'user': ('user(%(val)r)', ' or '), |
|
1902 | 1902 | } |
|
1903 | 1903 | |
|
1904 | 1904 | opts = dict(opts) |
|
1905 | 1905 | # follow or not follow? |
|
1906 | 1906 | follow = opts.get('follow') or opts.get('follow_first') |
|
1907 | 1907 | if opts.get('follow_first'): |
|
1908 | 1908 | followfirst = 1 |
|
1909 | 1909 | else: |
|
1910 | 1910 | followfirst = 0 |
|
1911 | 1911 | # --follow with FILE behavior depends on revs... |
|
1912 | 1912 | it = iter(revs) |
|
1913 | 1913 | startrev = it.next() |
|
1914 | 1914 | followdescendants = startrev < next(it, startrev) |
|
1915 | 1915 | |
|
1916 | 1916 | # branch and only_branch are really aliases and must be handled at |
|
1917 | 1917 | # the same time |
|
1918 | 1918 | opts['branch'] = opts.get('branch', []) + opts.get('only_branch', []) |
|
1919 | 1919 | opts['branch'] = [repo.lookupbranch(b) for b in opts['branch']] |
|
1920 | 1920 | # pats/include/exclude are passed to match.match() directly in |
|
1921 | 1921 | # _matchfiles() revset but walkchangerevs() builds its matcher with |
|
1922 | 1922 | # scmutil.match(). The difference is input pats are globbed on |
|
1923 | 1923 | # platforms without shell expansion (windows). |
|
1924 | 1924 | wctx = repo[None] |
|
1925 | 1925 | match, pats = scmutil.matchandpats(wctx, pats, opts) |
|
1926 | 1926 | slowpath = match.anypats() or ((match.isexact() or match.prefix()) and |
|
1927 | 1927 | opts.get('removed')) |
|
1928 | 1928 | if not slowpath: |
|
1929 | 1929 | for f in match.files(): |
|
1930 | 1930 | if follow and f not in wctx: |
|
1931 | 1931 | # If the file exists, it may be a directory, so let it |
|
1932 | 1932 | # take the slow path. |
|
1933 | 1933 | if os.path.exists(repo.wjoin(f)): |
|
1934 | 1934 | slowpath = True |
|
1935 | 1935 | continue |
|
1936 | 1936 | else: |
|
1937 | 1937 | raise util.Abort(_('cannot follow file not in parent ' |
|
1938 | 1938 | 'revision: "%s"') % f) |
|
1939 | 1939 | filelog = repo.file(f) |
|
1940 | 1940 | if not filelog: |
|
1941 | 1941 | # A zero count may be a directory or deleted file, so |
|
1942 | 1942 | # try to find matching entries on the slow path. |
|
1943 | 1943 | if follow: |
|
1944 | 1944 | raise util.Abort( |
|
1945 | 1945 | _('cannot follow nonexistent file: "%s"') % f) |
|
1946 | 1946 | slowpath = True |
|
1947 | 1947 | |
|
1948 | 1948 | # We decided to fall back to the slowpath because at least one |
|
1949 | 1949 | # of the paths was not a file. Check to see if at least one of them |
|
1950 | 1950 | # existed in history - in that case, we'll continue down the |
|
1951 | 1951 | # slowpath; otherwise, we can turn off the slowpath |
|
1952 | 1952 | if slowpath: |
|
1953 | 1953 | for path in match.files(): |
|
1954 | 1954 | if path == '.' or path in repo.store: |
|
1955 | 1955 | break |
|
1956 | 1956 | else: |
|
1957 | 1957 | slowpath = False |
|
1958 | 1958 | |
|
1959 | 1959 | fpats = ('_patsfollow', '_patsfollowfirst') |
|
1960 | 1960 | fnopats = (('_ancestors', '_fancestors'), |
|
1961 | 1961 | ('_descendants', '_fdescendants')) |
|
1962 | 1962 | if slowpath: |
|
1963 | 1963 | # See walkchangerevs() slow path. |
|
1964 | 1964 | # |
|
1965 | 1965 | # pats/include/exclude cannot be represented as separate |
|
1966 | 1966 | # revset expressions as their filtering logic applies at file |
|
1967 | 1967 | # level. For instance "-I a -X a" matches a revision touching |
|
1968 | 1968 | # "a" and "b" while "file(a) and not file(b)" does |
|
1969 | 1969 | # not. Besides, filesets are evaluated against the working |
|
1970 | 1970 | # directory. |
|
1971 | 1971 | matchargs = ['r:', 'd:relpath'] |
|
1972 | 1972 | for p in pats: |
|
1973 | 1973 | matchargs.append('p:' + p) |
|
1974 | 1974 | for p in opts.get('include', []): |
|
1975 | 1975 | matchargs.append('i:' + p) |
|
1976 | 1976 | for p in opts.get('exclude', []): |
|
1977 | 1977 | matchargs.append('x:' + p) |
|
1978 | 1978 | matchargs = ','.join(('%r' % p) for p in matchargs) |
|
1979 | 1979 | opts['_matchfiles'] = matchargs |
|
1980 | 1980 | if follow: |
|
1981 | 1981 | opts[fnopats[0][followfirst]] = '.' |
|
1982 | 1982 | else: |
|
1983 | 1983 | if follow: |
|
1984 | 1984 | if pats: |
|
1985 | 1985 | # follow() revset interprets its file argument as a |
|
1986 | 1986 | # manifest entry, so use match.files(), not pats. |
|
1987 | 1987 | opts[fpats[followfirst]] = list(match.files()) |
|
1988 | 1988 | else: |
|
1989 | 1989 | op = fnopats[followdescendants][followfirst] |
|
1990 | 1990 | opts[op] = 'rev(%d)' % startrev |
|
1991 | 1991 | else: |
|
1992 | 1992 | opts['_patslog'] = list(pats) |
|
1993 | 1993 | |
|
1994 | 1994 | filematcher = None |
|
1995 | 1995 | if opts.get('patch') or opts.get('stat'): |
|
1996 | 1996 | # When following files, track renames via a special matcher. |
|
1997 | 1997 | # If we're forced to take the slowpath it means we're following |
|
1998 | 1998 | # at least one pattern/directory, so don't bother with rename tracking. |
|
1999 | 1999 | if follow and not match.always() and not slowpath: |
|
2000 | 2000 | # _makefollowlogfilematcher expects its files argument to be |
|
2001 | 2001 | # relative to the repo root, so use match.files(), not pats. |
|
2002 | 2002 | filematcher = _makefollowlogfilematcher(repo, match.files(), |
|
2003 | 2003 | followfirst) |
|
2004 | 2004 | else: |
|
2005 | 2005 | filematcher = _makenofollowlogfilematcher(repo, pats, opts) |
|
2006 | 2006 | if filematcher is None: |
|
2007 | 2007 | filematcher = lambda rev: match |
|
2008 | 2008 | |
|
2009 | 2009 | expr = [] |
|
2010 | 2010 | for op, val in sorted(opts.iteritems()): |
|
2011 | 2011 | if not val: |
|
2012 | 2012 | continue |
|
2013 | 2013 | if op not in opt2revset: |
|
2014 | 2014 | continue |
|
2015 | 2015 | revop, andor = opt2revset[op] |
|
2016 | 2016 | if '%(val)' not in revop: |
|
2017 | 2017 | expr.append(revop) |
|
2018 | 2018 | else: |
|
2019 | 2019 | if not isinstance(val, list): |
|
2020 | 2020 | e = revop % {'val': val} |
|
2021 | 2021 | else: |
|
2022 | 2022 | e = '(' + andor.join((revop % {'val': v}) for v in val) + ')' |
|
2023 | 2023 | expr.append(e) |
|
2024 | 2024 | |
|
2025 | 2025 | if expr: |
|
2026 | 2026 | expr = '(' + ' and '.join(expr) + ')' |
|
2027 | 2027 | else: |
|
2028 | 2028 | expr = None |
|
2029 | 2029 | return expr, filematcher |
|
2030 | 2030 | |
|
2031 | 2031 | def _logrevs(repo, opts): |
|
2032 | 2032 | # Default --rev value depends on --follow but --follow behavior |
|
2033 | 2033 | # depends on revisions resolved from --rev... |
|
2034 | 2034 | follow = opts.get('follow') or opts.get('follow_first') |
|
2035 | 2035 | if opts.get('rev'): |
|
2036 | 2036 | revs = scmutil.revrange(repo, opts['rev']) |
|
2037 | 2037 | elif follow and repo.dirstate.p1() == nullid: |
|
2038 | 2038 | revs = revset.baseset() |
|
2039 | 2039 | elif follow: |
|
2040 | 2040 | revs = repo.revs('reverse(:.)') |
|
2041 | 2041 | else: |
|
2042 | 2042 | revs = revset.spanset(repo) |
|
2043 | 2043 | revs.reverse() |
|
2044 | 2044 | return revs |
|
2045 | 2045 | |
|
2046 | 2046 | def getgraphlogrevs(repo, pats, opts): |
|
2047 | 2047 | """Return (revs, expr, filematcher) where revs is an iterable of |
|
2048 | 2048 | revision numbers, expr is a revset string built from log options |
|
2049 | 2049 | and file patterns or None, and used to filter 'revs'. If --stat or |
|
2050 | 2050 | --patch are not passed filematcher is None. Otherwise it is a |
|
2051 | 2051 | callable taking a revision number and returning a match objects |
|
2052 | 2052 | filtering the files to be detailed when displaying the revision. |
|
2053 | 2053 | """ |
|
2054 | 2054 | limit = loglimit(opts) |
|
2055 | 2055 | revs = _logrevs(repo, opts) |
|
2056 | 2056 | if not revs: |
|
2057 | 2057 | return revset.baseset(), None, None |
|
2058 | 2058 | expr, filematcher = _makelogrevset(repo, pats, opts, revs) |
|
2059 | 2059 | if opts.get('rev'): |
|
2060 | 2060 | # User-specified revs might be unsorted, but don't sort before |
|
2061 | 2061 | # _makelogrevset because it might depend on the order of revs |
|
2062 | 2062 | revs.sort(reverse=True) |
|
2063 | 2063 | if expr: |
|
2064 | 2064 | # Revset matchers often operate faster on revisions in changelog |
|
2065 | 2065 | # order, because most filters deal with the changelog. |
|
2066 | 2066 | revs.reverse() |
|
2067 | 2067 | matcher = revset.match(repo.ui, expr) |
|
2068 | 2068 | # Revset matches can reorder revisions. "A or B" typically returns |
|
2069 | 2069 | # returns the revision matching A then the revision matching B. Sort |
|
2070 | 2070 | # again to fix that. |
|
2071 | 2071 | revs = matcher(repo, revs) |
|
2072 | 2072 | revs.sort(reverse=True) |
|
2073 | 2073 | if limit is not None: |
|
2074 | 2074 | limitedrevs = [] |
|
2075 | 2075 | for idx, rev in enumerate(revs): |
|
2076 | 2076 | if idx >= limit: |
|
2077 | 2077 | break |
|
2078 | 2078 | limitedrevs.append(rev) |
|
2079 | 2079 | revs = revset.baseset(limitedrevs) |
|
2080 | 2080 | |
|
2081 | 2081 | return revs, expr, filematcher |
|
2082 | 2082 | |
|
2083 | 2083 | def getlogrevs(repo, pats, opts): |
|
2084 | 2084 | """Return (revs, expr, filematcher) where revs is an iterable of |
|
2085 | 2085 | revision numbers, expr is a revset string built from log options |
|
2086 | 2086 | and file patterns or None, and used to filter 'revs'. If --stat or |
|
2087 | 2087 | --patch are not passed filematcher is None. Otherwise it is a |
|
2088 | 2088 | callable taking a revision number and returning a match objects |
|
2089 | 2089 | filtering the files to be detailed when displaying the revision. |
|
2090 | 2090 | """ |
|
2091 | 2091 | limit = loglimit(opts) |
|
2092 | 2092 | revs = _logrevs(repo, opts) |
|
2093 | 2093 | if not revs: |
|
2094 | 2094 | return revset.baseset([]), None, None |
|
2095 | 2095 | expr, filematcher = _makelogrevset(repo, pats, opts, revs) |
|
2096 | 2096 | if expr: |
|
2097 | 2097 | # Revset matchers often operate faster on revisions in changelog |
|
2098 | 2098 | # order, because most filters deal with the changelog. |
|
2099 | 2099 | if not opts.get('rev'): |
|
2100 | 2100 | revs.reverse() |
|
2101 | 2101 | matcher = revset.match(repo.ui, expr) |
|
2102 | 2102 | # Revset matches can reorder revisions. "A or B" typically returns |
|
2103 | 2103 | # returns the revision matching A then the revision matching B. Sort |
|
2104 | 2104 | # again to fix that. |
|
2105 | 2105 | revs = matcher(repo, revs) |
|
2106 | 2106 | if not opts.get('rev'): |
|
2107 | 2107 | revs.sort(reverse=True) |
|
2108 | 2108 | if limit is not None: |
|
2109 | 2109 | limitedrevs = [] |
|
2110 | 2110 | for idx, r in enumerate(revs): |
|
2111 | 2111 | if limit <= idx: |
|
2112 | 2112 | break |
|
2113 | 2113 | limitedrevs.append(r) |
|
2114 | 2114 | revs = revset.baseset(limitedrevs) |
|
2115 | 2115 | |
|
2116 | 2116 | return revs, expr, filematcher |
|
2117 | 2117 | |
|
2118 | 2118 | def displaygraph(ui, dag, displayer, showparents, edgefn, getrenamed=None, |
|
2119 | 2119 | filematcher=None): |
|
2120 | 2120 | seen, state = [], graphmod.asciistate() |
|
2121 | 2121 | for rev, type, ctx, parents in dag: |
|
2122 | 2122 | char = 'o' |
|
2123 | 2123 | if ctx.node() in showparents: |
|
2124 | 2124 | char = '@' |
|
2125 | 2125 | elif ctx.obsolete(): |
|
2126 | 2126 | char = 'x' |
|
2127 | 2127 | elif ctx.closesbranch(): |
|
2128 | 2128 | char = '_' |
|
2129 | 2129 | copies = None |
|
2130 | 2130 | if getrenamed and ctx.rev(): |
|
2131 | 2131 | copies = [] |
|
2132 | 2132 | for fn in ctx.files(): |
|
2133 | 2133 | rename = getrenamed(fn, ctx.rev()) |
|
2134 | 2134 | if rename: |
|
2135 | 2135 | copies.append((fn, rename[0])) |
|
2136 | 2136 | revmatchfn = None |
|
2137 | 2137 | if filematcher is not None: |
|
2138 | 2138 | revmatchfn = filematcher(ctx.rev()) |
|
2139 | 2139 | displayer.show(ctx, copies=copies, matchfn=revmatchfn) |
|
2140 | 2140 | lines = displayer.hunk.pop(rev).split('\n') |
|
2141 | 2141 | if not lines[-1]: |
|
2142 | 2142 | del lines[-1] |
|
2143 | 2143 | displayer.flush(ctx) |
|
2144 | 2144 | edges = edgefn(type, char, lines, seen, rev, parents) |
|
2145 | 2145 | for type, char, lines, coldata in edges: |
|
2146 | 2146 | graphmod.ascii(ui, state, type, char, lines, coldata) |
|
2147 | 2147 | displayer.close() |
|
2148 | 2148 | |
|
2149 | 2149 | def graphlog(ui, repo, *pats, **opts): |
|
2150 | 2150 | # Parameters are identical to log command ones |
|
2151 | 2151 | revs, expr, filematcher = getgraphlogrevs(repo, pats, opts) |
|
2152 | 2152 | revdag = graphmod.dagwalker(repo, revs) |
|
2153 | 2153 | |
|
2154 | 2154 | getrenamed = None |
|
2155 | 2155 | if opts.get('copies'): |
|
2156 | 2156 | endrev = None |
|
2157 | 2157 | if opts.get('rev'): |
|
2158 | 2158 | endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1 |
|
2159 | 2159 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) |
|
2160 | 2160 | displayer = show_changeset(ui, repo, opts, buffered=True) |
|
2161 | 2161 | showparents = [ctx.node() for ctx in repo[None].parents()] |
|
2162 | 2162 | displaygraph(ui, revdag, displayer, showparents, |
|
2163 | 2163 | graphmod.asciiedges, getrenamed, filematcher) |
|
2164 | 2164 | |
|
2165 | 2165 | def checkunsupportedgraphflags(pats, opts): |
|
2166 | 2166 | for op in ["newest_first"]: |
|
2167 | 2167 | if op in opts and opts[op]: |
|
2168 | 2168 | raise util.Abort(_("-G/--graph option is incompatible with --%s") |
|
2169 | 2169 | % op.replace("_", "-")) |
|
2170 | 2170 | |
|
2171 | 2171 | def graphrevs(repo, nodes, opts): |
|
2172 | 2172 | limit = loglimit(opts) |
|
2173 | 2173 | nodes.reverse() |
|
2174 | 2174 | if limit is not None: |
|
2175 | 2175 | nodes = nodes[:limit] |
|
2176 | 2176 | return graphmod.nodes(repo, nodes) |
|
2177 | 2177 | |
|
2178 | 2178 | def add(ui, repo, match, prefix, explicitonly, **opts): |
|
2179 | 2179 | join = lambda f: os.path.join(prefix, f) |
|
2180 | 2180 | bad = [] |
|
2181 | 2181 | |
|
2182 | 2182 | badfn = lambda x, y: bad.append(x) or match.bad(x, y) |
|
2183 | 2183 | names = [] |
|
2184 | 2184 | wctx = repo[None] |
|
2185 | 2185 | cca = None |
|
2186 | 2186 | abort, warn = scmutil.checkportabilityalert(ui) |
|
2187 | 2187 | if abort or warn: |
|
2188 | 2188 | cca = scmutil.casecollisionauditor(ui, abort, repo.dirstate) |
|
2189 | 2189 | |
|
2190 | 2190 | badmatch = matchmod.badmatch(match, badfn) |
|
2191 | 2191 | dirstate = repo.dirstate |
|
2192 | 2192 | # We don't want to just call wctx.walk here, since it would return a lot of |
|
2193 | 2193 | # clean files, which we aren't interested in and takes time. |
|
2194 | 2194 | for f in sorted(dirstate.walk(badmatch, sorted(wctx.substate), |
|
2195 | 2195 | True, False, full=False)): |
|
2196 | 2196 | exact = match.exact(f) |
|
2197 | 2197 | if exact or not explicitonly and f not in wctx and repo.wvfs.lexists(f): |
|
2198 | 2198 | if cca: |
|
2199 | 2199 | cca(f) |
|
2200 | 2200 | names.append(f) |
|
2201 | 2201 | if ui.verbose or not exact: |
|
2202 | 2202 | ui.status(_('adding %s\n') % match.rel(f)) |
|
2203 | 2203 | |
|
2204 | 2204 | for subpath in sorted(wctx.substate): |
|
2205 | 2205 | sub = wctx.sub(subpath) |
|
2206 | 2206 | try: |
|
2207 | 2207 | submatch = matchmod.narrowmatcher(subpath, match) |
|
2208 | 2208 | if opts.get('subrepos'): |
|
2209 | 2209 | bad.extend(sub.add(ui, submatch, prefix, False, **opts)) |
|
2210 | 2210 | else: |
|
2211 | 2211 | bad.extend(sub.add(ui, submatch, prefix, True, **opts)) |
|
2212 | 2212 | except error.LookupError: |
|
2213 | 2213 | ui.status(_("skipping missing subrepository: %s\n") |
|
2214 | 2214 | % join(subpath)) |
|
2215 | 2215 | |
|
2216 | 2216 | if not opts.get('dry_run'): |
|
2217 | 2217 | rejected = wctx.add(names, prefix) |
|
2218 | 2218 | bad.extend(f for f in rejected if f in match.files()) |
|
2219 | 2219 | return bad |
|
2220 | 2220 | |
|
2221 | 2221 | def forget(ui, repo, match, prefix, explicitonly): |
|
2222 | 2222 | join = lambda f: os.path.join(prefix, f) |
|
2223 | 2223 | bad = [] |
|
2224 | 2224 | badfn = lambda x, y: bad.append(x) or match.bad(x, y) |
|
2225 | 2225 | wctx = repo[None] |
|
2226 | 2226 | forgot = [] |
|
2227 | 2227 | |
|
2228 | 2228 | s = repo.status(match=matchmod.badmatch(match, badfn), clean=True) |
|
2229 | 2229 | forget = sorted(s[0] + s[1] + s[3] + s[6]) |
|
2230 | 2230 | if explicitonly: |
|
2231 | 2231 | forget = [f for f in forget if match.exact(f)] |
|
2232 | 2232 | |
|
2233 | 2233 | for subpath in sorted(wctx.substate): |
|
2234 | 2234 | sub = wctx.sub(subpath) |
|
2235 | 2235 | try: |
|
2236 | 2236 | submatch = matchmod.narrowmatcher(subpath, match) |
|
2237 | 2237 | subbad, subforgot = sub.forget(submatch, prefix) |
|
2238 | 2238 | bad.extend([subpath + '/' + f for f in subbad]) |
|
2239 | 2239 | forgot.extend([subpath + '/' + f for f in subforgot]) |
|
2240 | 2240 | except error.LookupError: |
|
2241 | 2241 | ui.status(_("skipping missing subrepository: %s\n") |
|
2242 | 2242 | % join(subpath)) |
|
2243 | 2243 | |
|
2244 | 2244 | if not explicitonly: |
|
2245 | 2245 | for f in match.files(): |
|
2246 | 2246 | if f not in repo.dirstate and not repo.wvfs.isdir(f): |
|
2247 | 2247 | if f not in forgot: |
|
2248 | 2248 | if repo.wvfs.exists(f): |
|
2249 | 2249 | # Don't complain if the exact case match wasn't given. |
|
2250 | 2250 | # But don't do this until after checking 'forgot', so |
|
2251 | 2251 | # that subrepo files aren't normalized, and this op is |
|
2252 | 2252 | # purely from data cached by the status walk above. |
|
2253 | 2253 | if repo.dirstate.normalize(f) in repo.dirstate: |
|
2254 | 2254 | continue |
|
2255 | 2255 | ui.warn(_('not removing %s: ' |
|
2256 | 2256 | 'file is already untracked\n') |
|
2257 | 2257 | % match.rel(f)) |
|
2258 | 2258 | bad.append(f) |
|
2259 | 2259 | |
|
2260 | 2260 | for f in forget: |
|
2261 | 2261 | if ui.verbose or not match.exact(f): |
|
2262 | 2262 | ui.status(_('removing %s\n') % match.rel(f)) |
|
2263 | 2263 | |
|
2264 | 2264 | rejected = wctx.forget(forget, prefix) |
|
2265 | 2265 | bad.extend(f for f in rejected if f in match.files()) |
|
2266 | 2266 | forgot.extend(f for f in forget if f not in rejected) |
|
2267 | 2267 | return bad, forgot |
|
2268 | 2268 | |
|
2269 | 2269 | def files(ui, ctx, m, fm, fmt, subrepos): |
|
2270 | 2270 | rev = ctx.rev() |
|
2271 | 2271 | ret = 1 |
|
2272 | 2272 | ds = ctx.repo().dirstate |
|
2273 | 2273 | |
|
2274 | 2274 | for f in ctx.matches(m): |
|
2275 | 2275 | if rev is None and ds[f] == 'r': |
|
2276 | 2276 | continue |
|
2277 | 2277 | fm.startitem() |
|
2278 | 2278 | if ui.verbose: |
|
2279 | 2279 | fc = ctx[f] |
|
2280 | 2280 | fm.write('size flags', '% 10d % 1s ', fc.size(), fc.flags()) |
|
2281 | 2281 | fm.data(abspath=f) |
|
2282 | 2282 | fm.write('path', fmt, m.rel(f)) |
|
2283 | 2283 | ret = 0 |
|
2284 | 2284 | |
|
2285 | 2285 | for subpath in sorted(ctx.substate): |
|
2286 | 2286 | def matchessubrepo(subpath): |
|
2287 | 2287 | return (m.always() or m.exact(subpath) |
|
2288 | 2288 | or any(f.startswith(subpath + '/') for f in m.files())) |
|
2289 | 2289 | |
|
2290 | 2290 | if subrepos or matchessubrepo(subpath): |
|
2291 | 2291 | sub = ctx.sub(subpath) |
|
2292 | 2292 | try: |
|
2293 | 2293 | submatch = matchmod.narrowmatcher(subpath, m) |
|
2294 | 2294 | if sub.printfiles(ui, submatch, fm, fmt, subrepos) == 0: |
|
2295 | 2295 | ret = 0 |
|
2296 | 2296 | except error.LookupError: |
|
2297 | 2297 | ui.status(_("skipping missing subrepository: %s\n") |
|
2298 | 2298 | % m.abs(subpath)) |
|
2299 | 2299 | |
|
2300 | 2300 | return ret |
|
2301 | 2301 | |
|
2302 | 2302 | def remove(ui, repo, m, prefix, after, force, subrepos): |
|
2303 | 2303 | join = lambda f: os.path.join(prefix, f) |
|
2304 | 2304 | ret = 0 |
|
2305 | 2305 | s = repo.status(match=m, clean=True) |
|
2306 | 2306 | modified, added, deleted, clean = s[0], s[1], s[3], s[6] |
|
2307 | 2307 | |
|
2308 | 2308 | wctx = repo[None] |
|
2309 | 2309 | |
|
2310 | 2310 | for subpath in sorted(wctx.substate): |
|
2311 | 2311 | def matchessubrepo(matcher, subpath): |
|
2312 | 2312 | if matcher.exact(subpath): |
|
2313 | 2313 | return True |
|
2314 | 2314 | for f in matcher.files(): |
|
2315 | 2315 | if f.startswith(subpath): |
|
2316 | 2316 | return True |
|
2317 | 2317 | return False |
|
2318 | 2318 | |
|
2319 | 2319 | if subrepos or matchessubrepo(m, subpath): |
|
2320 | 2320 | sub = wctx.sub(subpath) |
|
2321 | 2321 | try: |
|
2322 | 2322 | submatch = matchmod.narrowmatcher(subpath, m) |
|
2323 | 2323 | if sub.removefiles(submatch, prefix, after, force, subrepos): |
|
2324 | 2324 | ret = 1 |
|
2325 | 2325 | except error.LookupError: |
|
2326 | 2326 | ui.status(_("skipping missing subrepository: %s\n") |
|
2327 | 2327 | % join(subpath)) |
|
2328 | 2328 | |
|
2329 | 2329 | # warn about failure to delete explicit files/dirs |
|
2330 | 2330 | deleteddirs = util.dirs(deleted) |
|
2331 | 2331 | for f in m.files(): |
|
2332 | 2332 | def insubrepo(): |
|
2333 | 2333 | for subpath in wctx.substate: |
|
2334 | 2334 | if f.startswith(subpath): |
|
2335 | 2335 | return True |
|
2336 | 2336 | return False |
|
2337 | 2337 | |
|
2338 | 2338 | isdir = f in deleteddirs or wctx.hasdir(f) |
|
2339 | 2339 | if f in repo.dirstate or isdir or f == '.' or insubrepo(): |
|
2340 | 2340 | continue |
|
2341 | 2341 | |
|
2342 | 2342 | if repo.wvfs.exists(f): |
|
2343 | 2343 | if repo.wvfs.isdir(f): |
|
2344 | 2344 | ui.warn(_('not removing %s: no tracked files\n') |
|
2345 | 2345 | % m.rel(f)) |
|
2346 | 2346 | else: |
|
2347 | 2347 | ui.warn(_('not removing %s: file is untracked\n') |
|
2348 | 2348 | % m.rel(f)) |
|
2349 | 2349 | # missing files will generate a warning elsewhere |
|
2350 | 2350 | ret = 1 |
|
2351 | 2351 | |
|
2352 | 2352 | if force: |
|
2353 | 2353 | list = modified + deleted + clean + added |
|
2354 | 2354 | elif after: |
|
2355 | 2355 | list = deleted |
|
2356 | 2356 | for f in modified + added + clean: |
|
2357 | 2357 | ui.warn(_('not removing %s: file still exists\n') % m.rel(f)) |
|
2358 | 2358 | ret = 1 |
|
2359 | 2359 | else: |
|
2360 | 2360 | list = deleted + clean |
|
2361 | 2361 | for f in modified: |
|
2362 | 2362 | ui.warn(_('not removing %s: file is modified (use -f' |
|
2363 | 2363 | ' to force removal)\n') % m.rel(f)) |
|
2364 | 2364 | ret = 1 |
|
2365 | 2365 | for f in added: |
|
2366 | 2366 | ui.warn(_('not removing %s: file has been marked for add' |
|
2367 | 2367 | ' (use forget to undo)\n') % m.rel(f)) |
|
2368 | 2368 | ret = 1 |
|
2369 | 2369 | |
|
2370 | 2370 | for f in sorted(list): |
|
2371 | 2371 | if ui.verbose or not m.exact(f): |
|
2372 | 2372 | ui.status(_('removing %s\n') % m.rel(f)) |
|
2373 | 2373 | |
|
2374 | 2374 | wlock = repo.wlock() |
|
2375 | 2375 | try: |
|
2376 | 2376 | if not after: |
|
2377 | 2377 | for f in list: |
|
2378 | 2378 | if f in added: |
|
2379 | 2379 | continue # we never unlink added files on remove |
|
2380 | 2380 | util.unlinkpath(repo.wjoin(f), ignoremissing=True) |
|
2381 | 2381 | repo[None].forget(list) |
|
2382 | 2382 | finally: |
|
2383 | 2383 | wlock.release() |
|
2384 | 2384 | |
|
2385 | 2385 | return ret |
|
2386 | 2386 | |
|
2387 | 2387 | def cat(ui, repo, ctx, matcher, prefix, **opts): |
|
2388 | 2388 | err = 1 |
|
2389 | 2389 | |
|
2390 | 2390 | def write(path): |
|
2391 | 2391 | fp = makefileobj(repo, opts.get('output'), ctx.node(), |
|
2392 | 2392 | pathname=os.path.join(prefix, path)) |
|
2393 | 2393 | data = ctx[path].data() |
|
2394 | 2394 | if opts.get('decode'): |
|
2395 | 2395 | data = repo.wwritedata(path, data) |
|
2396 | 2396 | fp.write(data) |
|
2397 | 2397 | fp.close() |
|
2398 | 2398 | |
|
2399 | 2399 | # Automation often uses hg cat on single files, so special case it |
|
2400 | 2400 | # for performance to avoid the cost of parsing the manifest. |
|
2401 | 2401 | if len(matcher.files()) == 1 and not matcher.anypats(): |
|
2402 | 2402 | file = matcher.files()[0] |
|
2403 | 2403 | mf = repo.manifest |
|
2404 | 2404 | mfnode = ctx.manifestnode() |
|
2405 | 2405 | if mfnode and mf.find(mfnode, file)[0]: |
|
2406 | 2406 | write(file) |
|
2407 | 2407 | return 0 |
|
2408 | 2408 | |
|
2409 | 2409 | # Don't warn about "missing" files that are really in subrepos |
|
2410 | 2410 | def badfn(path, msg): |
|
2411 | 2411 | for subpath in ctx.substate: |
|
2412 | 2412 | if path.startswith(subpath): |
|
2413 | 2413 | return |
|
2414 | 2414 | matcher.bad(path, msg) |
|
2415 | 2415 | |
|
2416 | 2416 | for abs in ctx.walk(matchmod.badmatch(matcher, badfn)): |
|
2417 | 2417 | write(abs) |
|
2418 | 2418 | err = 0 |
|
2419 | 2419 | |
|
2420 | 2420 | for subpath in sorted(ctx.substate): |
|
2421 | 2421 | sub = ctx.sub(subpath) |
|
2422 | 2422 | try: |
|
2423 | 2423 | submatch = matchmod.narrowmatcher(subpath, matcher) |
|
2424 | 2424 | |
|
2425 | 2425 | if not sub.cat(submatch, os.path.join(prefix, sub._path), |
|
2426 | 2426 | **opts): |
|
2427 | 2427 | err = 0 |
|
2428 | 2428 | except error.RepoLookupError: |
|
2429 | 2429 | ui.status(_("skipping missing subrepository: %s\n") |
|
2430 | 2430 | % os.path.join(prefix, subpath)) |
|
2431 | 2431 | |
|
2432 | 2432 | return err |
|
2433 | 2433 | |
|
2434 | 2434 | def commit(ui, repo, commitfunc, pats, opts): |
|
2435 | 2435 | '''commit the specified files or all outstanding changes''' |
|
2436 | 2436 | date = opts.get('date') |
|
2437 | 2437 | if date: |
|
2438 | 2438 | opts['date'] = util.parsedate(date) |
|
2439 | 2439 | message = logmessage(ui, opts) |
|
2440 | 2440 | matcher = scmutil.match(repo[None], pats, opts) |
|
2441 | 2441 | |
|
2442 | 2442 | # extract addremove carefully -- this function can be called from a command |
|
2443 | 2443 | # that doesn't support addremove |
|
2444 | 2444 | if opts.get('addremove'): |
|
2445 | 2445 | if scmutil.addremove(repo, matcher, "", opts) != 0: |
|
2446 | 2446 | raise util.Abort( |
|
2447 | 2447 | _("failed to mark all new/missing files as added/removed")) |
|
2448 | 2448 | |
|
2449 | 2449 | return commitfunc(ui, repo, message, matcher, opts) |
|
2450 | 2450 | |
|
2451 | 2451 | def amend(ui, repo, commitfunc, old, extra, pats, opts): |
|
2452 | 2452 | # avoid cycle context -> subrepo -> cmdutil |
|
2453 | 2453 | import context |
|
2454 | 2454 | |
|
2455 | 2455 | # amend will reuse the existing user if not specified, but the obsolete |
|
2456 | 2456 | # marker creation requires that the current user's name is specified. |
|
2457 | 2457 | if obsolete.isenabled(repo, obsolete.createmarkersopt): |
|
2458 | 2458 | ui.username() # raise exception if username not set |
|
2459 | 2459 | |
|
2460 | 2460 | ui.note(_('amending changeset %s\n') % old) |
|
2461 | 2461 | base = old.p1() |
|
2462 | 2462 | createmarkers = obsolete.isenabled(repo, obsolete.createmarkersopt) |
|
2463 | 2463 | |
|
2464 | 2464 | wlock = dsguard = lock = newid = None |
|
2465 | 2465 | try: |
|
2466 | 2466 | wlock = repo.wlock() |
|
2467 | 2467 | dsguard = dirstateguard(repo, 'amend') |
|
2468 | 2468 | lock = repo.lock() |
|
2469 | 2469 | tr = repo.transaction('amend') |
|
2470 | 2470 | try: |
|
2471 | 2471 | # See if we got a message from -m or -l, if not, open the editor |
|
2472 | 2472 | # with the message of the changeset to amend |
|
2473 | 2473 | message = logmessage(ui, opts) |
|
2474 | 2474 | # ensure logfile does not conflict with later enforcement of the |
|
2475 | 2475 | # message. potential logfile content has been processed by |
|
2476 | 2476 | # `logmessage` anyway. |
|
2477 | 2477 | opts.pop('logfile') |
|
2478 | 2478 | # First, do a regular commit to record all changes in the working |
|
2479 | 2479 | # directory (if there are any) |
|
2480 | 2480 | ui.callhooks = False |
|
2481 | 2481 | activebookmark = repo._activebookmark |
|
2482 | 2482 | try: |
|
2483 | 2483 | repo._activebookmark = None |
|
2484 | 2484 | opts['message'] = 'temporary amend commit for %s' % old |
|
2485 | 2485 | node = commit(ui, repo, commitfunc, pats, opts) |
|
2486 | 2486 | finally: |
|
2487 | 2487 | repo._activebookmark = activebookmark |
|
2488 | 2488 | ui.callhooks = True |
|
2489 | 2489 | ctx = repo[node] |
|
2490 | 2490 | |
|
2491 | 2491 | # Participating changesets: |
|
2492 | 2492 | # |
|
2493 | 2493 | # node/ctx o - new (intermediate) commit that contains changes |
|
2494 | 2494 | # | from working dir to go into amending commit |
|
2495 | 2495 | # | (or a workingctx if there were no changes) |
|
2496 | 2496 | # | |
|
2497 | 2497 | # old o - changeset to amend |
|
2498 | 2498 | # | |
|
2499 | 2499 | # base o - parent of amending changeset |
|
2500 | 2500 | |
|
2501 | 2501 | # Update extra dict from amended commit (e.g. to preserve graft |
|
2502 | 2502 | # source) |
|
2503 | 2503 | extra.update(old.extra()) |
|
2504 | 2504 | |
|
2505 | 2505 | # Also update it from the intermediate commit or from the wctx |
|
2506 | 2506 | extra.update(ctx.extra()) |
|
2507 | 2507 | |
|
2508 | 2508 | if len(old.parents()) > 1: |
|
2509 | 2509 | # ctx.files() isn't reliable for merges, so fall back to the |
|
2510 | 2510 | # slower repo.status() method |
|
2511 | 2511 | files = set([fn for st in repo.status(base, old)[:3] |
|
2512 | 2512 | for fn in st]) |
|
2513 | 2513 | else: |
|
2514 | 2514 | files = set(old.files()) |
|
2515 | 2515 | |
|
2516 | 2516 | # Second, we use either the commit we just did, or if there were no |
|
2517 | 2517 | # changes the parent of the working directory as the version of the |
|
2518 | 2518 | # files in the final amend commit |
|
2519 | 2519 | if node: |
|
2520 | 2520 | ui.note(_('copying changeset %s to %s\n') % (ctx, base)) |
|
2521 | 2521 | |
|
2522 | 2522 | user = ctx.user() |
|
2523 | 2523 | date = ctx.date() |
|
2524 | 2524 | # Recompute copies (avoid recording a -> b -> a) |
|
2525 | 2525 | copied = copies.pathcopies(base, ctx) |
|
2526 | 2526 | if old.p2: |
|
2527 | 2527 | copied.update(copies.pathcopies(old.p2(), ctx)) |
|
2528 | 2528 | |
|
2529 | 2529 | # Prune files which were reverted by the updates: if old |
|
2530 | 2530 | # introduced file X and our intermediate commit, node, |
|
2531 | 2531 | # renamed that file, then those two files are the same and |
|
2532 | 2532 | # we can discard X from our list of files. Likewise if X |
|
2533 | 2533 | # was deleted, it's no longer relevant |
|
2534 | 2534 | files.update(ctx.files()) |
|
2535 | 2535 | |
|
2536 | 2536 | def samefile(f): |
|
2537 | 2537 | if f in ctx.manifest(): |
|
2538 | 2538 | a = ctx.filectx(f) |
|
2539 | 2539 | if f in base.manifest(): |
|
2540 | 2540 | b = base.filectx(f) |
|
2541 | 2541 | return (not a.cmp(b) |
|
2542 | 2542 | and a.flags() == b.flags()) |
|
2543 | 2543 | else: |
|
2544 | 2544 | return False |
|
2545 | 2545 | else: |
|
2546 | 2546 | return f not in base.manifest() |
|
2547 | 2547 | files = [f for f in files if not samefile(f)] |
|
2548 | 2548 | |
|
2549 | 2549 | def filectxfn(repo, ctx_, path): |
|
2550 | 2550 | try: |
|
2551 | 2551 | fctx = ctx[path] |
|
2552 | 2552 | flags = fctx.flags() |
|
2553 | 2553 | mctx = context.memfilectx(repo, |
|
2554 | 2554 | fctx.path(), fctx.data(), |
|
2555 | 2555 | islink='l' in flags, |
|
2556 | 2556 | isexec='x' in flags, |
|
2557 | 2557 | copied=copied.get(path)) |
|
2558 | 2558 | return mctx |
|
2559 | 2559 | except KeyError: |
|
2560 | 2560 | return None |
|
2561 | 2561 | else: |
|
2562 | 2562 | ui.note(_('copying changeset %s to %s\n') % (old, base)) |
|
2563 | 2563 | |
|
2564 | 2564 | # Use version of files as in the old cset |
|
2565 | 2565 | def filectxfn(repo, ctx_, path): |
|
2566 | 2566 | try: |
|
2567 | 2567 | return old.filectx(path) |
|
2568 | 2568 | except KeyError: |
|
2569 | 2569 | return None |
|
2570 | 2570 | |
|
2571 | 2571 | user = opts.get('user') or old.user() |
|
2572 | 2572 | date = opts.get('date') or old.date() |
|
2573 | 2573 | editform = mergeeditform(old, 'commit.amend') |
|
2574 | 2574 | editor = getcommiteditor(editform=editform, **opts) |
|
2575 | 2575 | if not message: |
|
2576 | 2576 | editor = getcommiteditor(edit=True, editform=editform) |
|
2577 | 2577 | message = old.description() |
|
2578 | 2578 | |
|
2579 | 2579 | pureextra = extra.copy() |
|
2580 | 2580 | extra['amend_source'] = old.hex() |
|
2581 | 2581 | |
|
2582 | 2582 | new = context.memctx(repo, |
|
2583 | 2583 | parents=[base.node(), old.p2().node()], |
|
2584 | 2584 | text=message, |
|
2585 | 2585 | files=files, |
|
2586 | 2586 | filectxfn=filectxfn, |
|
2587 | 2587 | user=user, |
|
2588 | 2588 | date=date, |
|
2589 | 2589 | extra=extra, |
|
2590 | 2590 | editor=editor) |
|
2591 | 2591 | |
|
2592 | 2592 | newdesc = changelog.stripdesc(new.description()) |
|
2593 | 2593 | if ((not node) |
|
2594 | 2594 | and newdesc == old.description() |
|
2595 | 2595 | and user == old.user() |
|
2596 | 2596 | and date == old.date() |
|
2597 | 2597 | and pureextra == old.extra()): |
|
2598 | 2598 | # nothing changed. continuing here would create a new node |
|
2599 | 2599 | # anyway because of the amend_source noise. |
|
2600 | 2600 | # |
|
2601 | 2601 | # This not what we expect from amend. |
|
2602 | 2602 | return old.node() |
|
2603 | 2603 | |
|
2604 | 2604 | ph = repo.ui.config('phases', 'new-commit', phases.draft) |
|
2605 | 2605 | try: |
|
2606 | 2606 | if opts.get('secret'): |
|
2607 | 2607 | commitphase = 'secret' |
|
2608 | 2608 | else: |
|
2609 | 2609 | commitphase = old.phase() |
|
2610 | 2610 | repo.ui.setconfig('phases', 'new-commit', commitphase, 'amend') |
|
2611 | 2611 | newid = repo.commitctx(new) |
|
2612 | 2612 | finally: |
|
2613 | 2613 | repo.ui.setconfig('phases', 'new-commit', ph, 'amend') |
|
2614 | 2614 | if newid != old.node(): |
|
2615 | 2615 | # Reroute the working copy parent to the new changeset |
|
2616 | 2616 | repo.setparents(newid, nullid) |
|
2617 | 2617 | |
|
2618 | 2618 | # Move bookmarks from old parent to amend commit |
|
2619 | 2619 | bms = repo.nodebookmarks(old.node()) |
|
2620 | 2620 | if bms: |
|
2621 | 2621 | marks = repo._bookmarks |
|
2622 | 2622 | for bm in bms: |
|
2623 | 2623 | ui.debug('moving bookmarks %r from %s to %s\n' % |
|
2624 | 2624 | (marks, old.hex(), hex(newid))) |
|
2625 | 2625 | marks[bm] = newid |
|
2626 | 2626 | marks.recordchange(tr) |
|
2627 | 2627 | #commit the whole amend process |
|
2628 | 2628 | if createmarkers: |
|
2629 | 2629 | # mark the new changeset as successor of the rewritten one |
|
2630 | 2630 | new = repo[newid] |
|
2631 | 2631 | obs = [(old, (new,))] |
|
2632 | 2632 | if node: |
|
2633 | 2633 | obs.append((ctx, ())) |
|
2634 | 2634 | |
|
2635 | 2635 | obsolete.createmarkers(repo, obs) |
|
2636 | 2636 | tr.close() |
|
2637 | 2637 | finally: |
|
2638 | 2638 | tr.release() |
|
2639 | 2639 | dsguard.close() |
|
2640 | 2640 | if not createmarkers and newid != old.node(): |
|
2641 | 2641 | # Strip the intermediate commit (if there was one) and the amended |
|
2642 | 2642 | # commit |
|
2643 | 2643 | if node: |
|
2644 | 2644 | ui.note(_('stripping intermediate changeset %s\n') % ctx) |
|
2645 | 2645 | ui.note(_('stripping amended changeset %s\n') % old) |
|
2646 | 2646 | repair.strip(ui, repo, old.node(), topic='amend-backup') |
|
2647 | 2647 | finally: |
|
2648 | 2648 | lockmod.release(lock, dsguard, wlock) |
|
2649 | 2649 | return newid |
|
2650 | 2650 | |
|
2651 | 2651 | def commiteditor(repo, ctx, subs, editform=''): |
|
2652 | 2652 | if ctx.description(): |
|
2653 | 2653 | return ctx.description() |
|
2654 | 2654 | return commitforceeditor(repo, ctx, subs, editform=editform) |
|
2655 | 2655 | |
|
2656 | 2656 | def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None, |
|
2657 | 2657 | editform=''): |
|
2658 | 2658 | if not extramsg: |
|
2659 | 2659 | extramsg = _("Leave message empty to abort commit.") |
|
2660 | 2660 | |
|
2661 | 2661 | forms = [e for e in editform.split('.') if e] |
|
2662 | 2662 | forms.insert(0, 'changeset') |
|
2663 | 2663 | while forms: |
|
2664 | 2664 | tmpl = repo.ui.config('committemplate', '.'.join(forms)) |
|
2665 | 2665 | if tmpl: |
|
2666 | 2666 | committext = buildcommittemplate(repo, ctx, subs, extramsg, tmpl) |
|
2667 | 2667 | break |
|
2668 | 2668 | forms.pop() |
|
2669 | 2669 | else: |
|
2670 | 2670 | committext = buildcommittext(repo, ctx, subs, extramsg) |
|
2671 | 2671 | |
|
2672 | 2672 | # run editor in the repository root |
|
2673 | 2673 | olddir = os.getcwd() |
|
2674 | 2674 | os.chdir(repo.root) |
|
2675 | 2675 | text = repo.ui.edit(committext, ctx.user(), ctx.extra(), editform=editform) |
|
2676 | 2676 | text = re.sub("(?m)^HG:.*(\n|$)", "", text) |
|
2677 | 2677 | os.chdir(olddir) |
|
2678 | 2678 | |
|
2679 | 2679 | if finishdesc: |
|
2680 | 2680 | text = finishdesc(text) |
|
2681 | 2681 | if not text.strip(): |
|
2682 | 2682 | raise util.Abort(_("empty commit message")) |
|
2683 | 2683 | |
|
2684 | 2684 | return text |
|
2685 | 2685 | |
|
2686 | 2686 | def buildcommittemplate(repo, ctx, subs, extramsg, tmpl): |
|
2687 | 2687 | ui = repo.ui |
|
2688 | 2688 | tmpl, mapfile = gettemplate(ui, tmpl, None) |
|
2689 | 2689 | |
|
2690 | 2690 | try: |
|
2691 | 2691 | t = changeset_templater(ui, repo, None, {}, tmpl, mapfile, False) |
|
2692 | 2692 | except SyntaxError as inst: |
|
2693 | 2693 | raise util.Abort(inst.args[0]) |
|
2694 | 2694 | |
|
2695 | 2695 | for k, v in repo.ui.configitems('committemplate'): |
|
2696 | 2696 | if k != 'changeset': |
|
2697 | 2697 | t.t.cache[k] = v |
|
2698 | 2698 | |
|
2699 | 2699 | if not extramsg: |
|
2700 | 2700 | extramsg = '' # ensure that extramsg is string |
|
2701 | 2701 | |
|
2702 | 2702 | ui.pushbuffer() |
|
2703 | 2703 | t.show(ctx, extramsg=extramsg) |
|
2704 | 2704 | return ui.popbuffer() |
|
2705 | 2705 | |
|
2706 | 2706 | def hgprefix(msg): |
|
2707 | 2707 | return "\n".join(["HG: %s" % a for a in msg.split("\n") if a]) |
|
2708 | 2708 | |
|
2709 | 2709 | def buildcommittext(repo, ctx, subs, extramsg): |
|
2710 | 2710 | edittext = [] |
|
2711 | 2711 | modified, added, removed = ctx.modified(), ctx.added(), ctx.removed() |
|
2712 | 2712 | if ctx.description(): |
|
2713 | 2713 | edittext.append(ctx.description()) |
|
2714 | 2714 | edittext.append("") |
|
2715 | 2715 | edittext.append("") # Empty line between message and comments. |
|
2716 | 2716 | edittext.append(hgprefix(_("Enter commit message." |
|
2717 | 2717 | " Lines beginning with 'HG:' are removed."))) |
|
2718 | 2718 | edittext.append(hgprefix(extramsg)) |
|
2719 | 2719 | edittext.append("HG: --") |
|
2720 | 2720 | edittext.append(hgprefix(_("user: %s") % ctx.user())) |
|
2721 | 2721 | if ctx.p2(): |
|
2722 | 2722 | edittext.append(hgprefix(_("branch merge"))) |
|
2723 | 2723 | if ctx.branch(): |
|
2724 | 2724 | edittext.append(hgprefix(_("branch '%s'") % ctx.branch())) |
|
2725 | 2725 | if bookmarks.isactivewdirparent(repo): |
|
2726 | 2726 | edittext.append(hgprefix(_("bookmark '%s'") % repo._activebookmark)) |
|
2727 | 2727 | edittext.extend([hgprefix(_("subrepo %s") % s) for s in subs]) |
|
2728 | 2728 | edittext.extend([hgprefix(_("added %s") % f) for f in added]) |
|
2729 | 2729 | edittext.extend([hgprefix(_("changed %s") % f) for f in modified]) |
|
2730 | 2730 | edittext.extend([hgprefix(_("removed %s") % f) for f in removed]) |
|
2731 | 2731 | if not added and not modified and not removed: |
|
2732 | 2732 | edittext.append(hgprefix(_("no files changed"))) |
|
2733 | 2733 | edittext.append("") |
|
2734 | 2734 | |
|
2735 | 2735 | return "\n".join(edittext) |
|
2736 | 2736 | |
|
2737 | 2737 | def commitstatus(repo, node, branch, bheads=None, opts=None): |
|
2738 | 2738 | if opts is None: |
|
2739 | 2739 | opts = {} |
|
2740 | 2740 | ctx = repo[node] |
|
2741 | 2741 | parents = ctx.parents() |
|
2742 | 2742 | |
|
2743 | 2743 | if (not opts.get('amend') and bheads and node not in bheads and not |
|
2744 | 2744 | [x for x in parents if x.node() in bheads and x.branch() == branch]): |
|
2745 | 2745 | repo.ui.status(_('created new head\n')) |
|
2746 | 2746 | # The message is not printed for initial roots. For the other |
|
2747 | 2747 | # changesets, it is printed in the following situations: |
|
2748 | 2748 | # |
|
2749 | 2749 | # Par column: for the 2 parents with ... |
|
2750 | 2750 | # N: null or no parent |
|
2751 | 2751 | # B: parent is on another named branch |
|
2752 | 2752 | # C: parent is a regular non head changeset |
|
2753 | 2753 | # H: parent was a branch head of the current branch |
|
2754 | 2754 | # Msg column: whether we print "created new head" message |
|
2755 | 2755 | # In the following, it is assumed that there already exists some |
|
2756 | 2756 | # initial branch heads of the current branch, otherwise nothing is |
|
2757 | 2757 | # printed anyway. |
|
2758 | 2758 | # |
|
2759 | 2759 | # Par Msg Comment |
|
2760 | 2760 | # N N y additional topo root |
|
2761 | 2761 | # |
|
2762 | 2762 | # B N y additional branch root |
|
2763 | 2763 | # C N y additional topo head |
|
2764 | 2764 | # H N n usual case |
|
2765 | 2765 | # |
|
2766 | 2766 | # B B y weird additional branch root |
|
2767 | 2767 | # C B y branch merge |
|
2768 | 2768 | # H B n merge with named branch |
|
2769 | 2769 | # |
|
2770 | 2770 | # C C y additional head from merge |
|
2771 | 2771 | # C H n merge with a head |
|
2772 | 2772 | # |
|
2773 | 2773 | # H H n head merge: head count decreases |
|
2774 | 2774 | |
|
2775 | 2775 | if not opts.get('close_branch'): |
|
2776 | 2776 | for r in parents: |
|
2777 | 2777 | if r.closesbranch() and r.branch() == branch: |
|
2778 | 2778 | repo.ui.status(_('reopening closed branch head %d\n') % r) |
|
2779 | 2779 | |
|
2780 | 2780 | if repo.ui.debugflag: |
|
2781 | 2781 | repo.ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx.hex())) |
|
2782 | 2782 | elif repo.ui.verbose: |
|
2783 | 2783 | repo.ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx)) |
|
2784 | 2784 | |
|
2785 | 2785 | def revert(ui, repo, ctx, parents, *pats, **opts): |
|
2786 | 2786 | parent, p2 = parents |
|
2787 | 2787 | node = ctx.node() |
|
2788 | 2788 | |
|
2789 | 2789 | mf = ctx.manifest() |
|
2790 | 2790 | if node == p2: |
|
2791 | 2791 | parent = p2 |
|
2792 | 2792 | if node == parent: |
|
2793 | 2793 | pmf = mf |
|
2794 | 2794 | else: |
|
2795 | 2795 | pmf = None |
|
2796 | 2796 | |
|
2797 | 2797 | # need all matching names in dirstate and manifest of target rev, |
|
2798 | 2798 | # so have to walk both. do not print errors if files exist in one |
|
2799 | 2799 | # but not other. in both cases, filesets should be evaluated against |
|
2800 | 2800 | # workingctx to get consistent result (issue4497). this means 'set:**' |
|
2801 | 2801 | # cannot be used to select missing files from target rev. |
|
2802 | 2802 | |
|
2803 | 2803 | # `names` is a mapping for all elements in working copy and target revision |
|
2804 | 2804 | # The mapping is in the form: |
|
2805 | 2805 | # <asb path in repo> -> (<path from CWD>, <exactly specified by matcher?>) |
|
2806 | 2806 | names = {} |
|
2807 | 2807 | |
|
2808 | 2808 | wlock = repo.wlock() |
|
2809 | 2809 | try: |
|
2810 | 2810 | ## filling of the `names` mapping |
|
2811 | 2811 | # walk dirstate to fill `names` |
|
2812 | 2812 | |
|
2813 | 2813 | interactive = opts.get('interactive', False) |
|
2814 | 2814 | wctx = repo[None] |
|
2815 | 2815 | m = scmutil.match(wctx, pats, opts) |
|
2816 | 2816 | |
|
2817 | 2817 | # we'll need this later |
|
2818 | 2818 | targetsubs = sorted(s for s in wctx.substate if m(s)) |
|
2819 | 2819 | |
|
2820 | 2820 | if not m.always(): |
|
2821 | 2821 | for abs in repo.walk(matchmod.badmatch(m, lambda x, y: False)): |
|
2822 | 2822 | names[abs] = m.rel(abs), m.exact(abs) |
|
2823 | 2823 | |
|
2824 | 2824 | # walk target manifest to fill `names` |
|
2825 | 2825 | |
|
2826 | 2826 | def badfn(path, msg): |
|
2827 | 2827 | if path in names: |
|
2828 | 2828 | return |
|
2829 | 2829 | if path in ctx.substate: |
|
2830 | 2830 | return |
|
2831 | 2831 | path_ = path + '/' |
|
2832 | 2832 | for f in names: |
|
2833 | 2833 | if f.startswith(path_): |
|
2834 | 2834 | return |
|
2835 | 2835 | ui.warn("%s: %s\n" % (m.rel(path), msg)) |
|
2836 | 2836 | |
|
2837 | 2837 | for abs in ctx.walk(matchmod.badmatch(m, badfn)): |
|
2838 | 2838 | if abs not in names: |
|
2839 | 2839 | names[abs] = m.rel(abs), m.exact(abs) |
|
2840 | 2840 | |
|
2841 | 2841 | # Find status of all file in `names`. |
|
2842 | 2842 | m = scmutil.matchfiles(repo, names) |
|
2843 | 2843 | |
|
2844 | 2844 | changes = repo.status(node1=node, match=m, |
|
2845 | 2845 | unknown=True, ignored=True, clean=True) |
|
2846 | 2846 | else: |
|
2847 | 2847 | changes = repo.status(node1=node, match=m) |
|
2848 | 2848 | for kind in changes: |
|
2849 | 2849 | for abs in kind: |
|
2850 | 2850 | names[abs] = m.rel(abs), m.exact(abs) |
|
2851 | 2851 | |
|
2852 | 2852 | m = scmutil.matchfiles(repo, names) |
|
2853 | 2853 | |
|
2854 | 2854 | modified = set(changes.modified) |
|
2855 | 2855 | added = set(changes.added) |
|
2856 | 2856 | removed = set(changes.removed) |
|
2857 | 2857 | _deleted = set(changes.deleted) |
|
2858 | 2858 | unknown = set(changes.unknown) |
|
2859 | 2859 | unknown.update(changes.ignored) |
|
2860 | 2860 | clean = set(changes.clean) |
|
2861 | 2861 | modadded = set() |
|
2862 | 2862 | |
|
2863 | 2863 | # split between files known in target manifest and the others |
|
2864 | 2864 | smf = set(mf) |
|
2865 | 2865 | |
|
2866 | 2866 | # determine the exact nature of the deleted changesets |
|
2867 | 2867 | deladded = _deleted - smf |
|
2868 | 2868 | deleted = _deleted - deladded |
|
2869 | 2869 | |
|
2870 | 2870 | # We need to account for the state of the file in the dirstate, |
|
2871 | 2871 | # even when we revert against something else than parent. This will |
|
2872 | 2872 | # slightly alter the behavior of revert (doing back up or not, delete |
|
2873 | 2873 | # or just forget etc). |
|
2874 | 2874 | if parent == node: |
|
2875 | 2875 | dsmodified = modified |
|
2876 | 2876 | dsadded = added |
|
2877 | 2877 | dsremoved = removed |
|
2878 | 2878 | # store all local modifications, useful later for rename detection |
|
2879 | 2879 | localchanges = dsmodified | dsadded |
|
2880 | 2880 | modified, added, removed = set(), set(), set() |
|
2881 | 2881 | else: |
|
2882 | 2882 | changes = repo.status(node1=parent, match=m) |
|
2883 | 2883 | dsmodified = set(changes.modified) |
|
2884 | 2884 | dsadded = set(changes.added) |
|
2885 | 2885 | dsremoved = set(changes.removed) |
|
2886 | 2886 | # store all local modifications, useful later for rename detection |
|
2887 | 2887 | localchanges = dsmodified | dsadded |
|
2888 | 2888 | |
|
2889 | 2889 | # only take into account for removes between wc and target |
|
2890 | 2890 | clean |= dsremoved - removed |
|
2891 | 2891 | dsremoved &= removed |
|
2892 | 2892 | # distinct between dirstate remove and other |
|
2893 | 2893 | removed -= dsremoved |
|
2894 | 2894 | |
|
2895 | 2895 | modadded = added & dsmodified |
|
2896 | 2896 | added -= modadded |
|
2897 | 2897 | |
|
2898 | 2898 | # tell newly modified apart. |
|
2899 | 2899 | dsmodified &= modified |
|
2900 | 2900 | dsmodified |= modified & dsadded # dirstate added may needs backup |
|
2901 | 2901 | modified -= dsmodified |
|
2902 | 2902 | |
|
2903 | 2903 | # We need to wait for some post-processing to update this set |
|
2904 | 2904 | # before making the distinction. The dirstate will be used for |
|
2905 | 2905 | # that purpose. |
|
2906 | 2906 | dsadded = added |
|
2907 | 2907 | |
|
2908 | 2908 | # in case of merge, files that are actually added can be reported as |
|
2909 | 2909 | # modified, we need to post process the result |
|
2910 | 2910 | if p2 != nullid: |
|
2911 | 2911 | if pmf is None: |
|
2912 | 2912 | # only need parent manifest in the merge case, |
|
2913 | 2913 | # so do not read by default |
|
2914 | 2914 | pmf = repo[parent].manifest() |
|
2915 | 2915 | mergeadd = dsmodified - set(pmf) |
|
2916 | 2916 | dsadded |= mergeadd |
|
2917 | 2917 | dsmodified -= mergeadd |
|
2918 | 2918 | |
|
2919 | 2919 | # if f is a rename, update `names` to also revert the source |
|
2920 | 2920 | cwd = repo.getcwd() |
|
2921 | 2921 | for f in localchanges: |
|
2922 | 2922 | src = repo.dirstate.copied(f) |
|
2923 | 2923 | # XXX should we check for rename down to target node? |
|
2924 | 2924 | if src and src not in names and repo.dirstate[src] == 'r': |
|
2925 | 2925 | dsremoved.add(src) |
|
2926 | 2926 | names[src] = (repo.pathto(src, cwd), True) |
|
2927 | 2927 | |
|
2928 | 2928 | # distinguish between file to forget and the other |
|
2929 | 2929 | added = set() |
|
2930 | 2930 | for abs in dsadded: |
|
2931 | 2931 | if repo.dirstate[abs] != 'a': |
|
2932 | 2932 | added.add(abs) |
|
2933 | 2933 | dsadded -= added |
|
2934 | 2934 | |
|
2935 | 2935 | for abs in deladded: |
|
2936 | 2936 | if repo.dirstate[abs] == 'a': |
|
2937 | 2937 | dsadded.add(abs) |
|
2938 | 2938 | deladded -= dsadded |
|
2939 | 2939 | |
|
2940 | 2940 | # For files marked as removed, we check if an unknown file is present at |
|
2941 | 2941 | # the same path. If a such file exists it may need to be backed up. |
|
2942 | 2942 | # Making the distinction at this stage helps have simpler backup |
|
2943 | 2943 | # logic. |
|
2944 | 2944 | removunk = set() |
|
2945 | 2945 | for abs in removed: |
|
2946 | 2946 | target = repo.wjoin(abs) |
|
2947 | 2947 | if os.path.lexists(target): |
|
2948 | 2948 | removunk.add(abs) |
|
2949 | 2949 | removed -= removunk |
|
2950 | 2950 | |
|
2951 | 2951 | dsremovunk = set() |
|
2952 | 2952 | for abs in dsremoved: |
|
2953 | 2953 | target = repo.wjoin(abs) |
|
2954 | 2954 | if os.path.lexists(target): |
|
2955 | 2955 | dsremovunk.add(abs) |
|
2956 | 2956 | dsremoved -= dsremovunk |
|
2957 | 2957 | |
|
2958 | 2958 | # action to be actually performed by revert |
|
2959 | 2959 | # (<list of file>, message>) tuple |
|
2960 | 2960 | actions = {'revert': ([], _('reverting %s\n')), |
|
2961 | 2961 | 'add': ([], _('adding %s\n')), |
|
2962 | 2962 | 'remove': ([], _('removing %s\n')), |
|
2963 | 2963 | 'drop': ([], _('removing %s\n')), |
|
2964 | 2964 | 'forget': ([], _('forgetting %s\n')), |
|
2965 | 2965 | 'undelete': ([], _('undeleting %s\n')), |
|
2966 | 2966 | 'noop': (None, _('no changes needed to %s\n')), |
|
2967 | 2967 | 'unknown': (None, _('file not managed: %s\n')), |
|
2968 | 2968 | } |
|
2969 | 2969 | |
|
2970 | 2970 | # "constant" that convey the backup strategy. |
|
2971 | 2971 | # All set to `discard` if `no-backup` is set do avoid checking |
|
2972 | 2972 | # no_backup lower in the code. |
|
2973 | 2973 | # These values are ordered for comparison purposes |
|
2974 | 2974 | backup = 2 # unconditionally do backup |
|
2975 | 2975 | check = 1 # check if the existing file differs from target |
|
2976 | 2976 | discard = 0 # never do backup |
|
2977 | 2977 | if opts.get('no_backup'): |
|
2978 | 2978 | backup = check = discard |
|
2979 | 2979 | |
|
2980 | 2980 | backupanddel = actions['remove'] |
|
2981 | 2981 | if not opts.get('no_backup'): |
|
2982 | 2982 | backupanddel = actions['drop'] |
|
2983 | 2983 | |
|
2984 | 2984 | disptable = ( |
|
2985 | 2985 | # dispatch table: |
|
2986 | 2986 | # file state |
|
2987 | 2987 | # action |
|
2988 | 2988 | # make backup |
|
2989 | 2989 | |
|
2990 | 2990 | ## Sets that results that will change file on disk |
|
2991 | 2991 | # Modified compared to target, no local change |
|
2992 | 2992 | (modified, actions['revert'], discard), |
|
2993 | 2993 | # Modified compared to target, but local file is deleted |
|
2994 | 2994 | (deleted, actions['revert'], discard), |
|
2995 | 2995 | # Modified compared to target, local change |
|
2996 | 2996 | (dsmodified, actions['revert'], backup), |
|
2997 | 2997 | # Added since target |
|
2998 | 2998 | (added, actions['remove'], discard), |
|
2999 | 2999 | # Added in working directory |
|
3000 | 3000 | (dsadded, actions['forget'], discard), |
|
3001 | 3001 | # Added since target, have local modification |
|
3002 | 3002 | (modadded, backupanddel, backup), |
|
3003 | 3003 | # Added since target but file is missing in working directory |
|
3004 | 3004 | (deladded, actions['drop'], discard), |
|
3005 | 3005 | # Removed since target, before working copy parent |
|
3006 | 3006 | (removed, actions['add'], discard), |
|
3007 | 3007 | # Same as `removed` but an unknown file exists at the same path |
|
3008 | 3008 | (removunk, actions['add'], check), |
|
3009 | 3009 | # Removed since targe, marked as such in working copy parent |
|
3010 | 3010 | (dsremoved, actions['undelete'], discard), |
|
3011 | 3011 | # Same as `dsremoved` but an unknown file exists at the same path |
|
3012 | 3012 | (dsremovunk, actions['undelete'], check), |
|
3013 | 3013 | ## the following sets does not result in any file changes |
|
3014 | 3014 | # File with no modification |
|
3015 | 3015 | (clean, actions['noop'], discard), |
|
3016 | 3016 | # Existing file, not tracked anywhere |
|
3017 | 3017 | (unknown, actions['unknown'], discard), |
|
3018 | 3018 | ) |
|
3019 | 3019 | |
|
3020 | 3020 | for abs, (rel, exact) in sorted(names.items()): |
|
3021 | 3021 | # target file to be touch on disk (relative to cwd) |
|
3022 | 3022 | target = repo.wjoin(abs) |
|
3023 | 3023 | # search the entry in the dispatch table. |
|
3024 | 3024 | # if the file is in any of these sets, it was touched in the working |
|
3025 | 3025 | # directory parent and we are sure it needs to be reverted. |
|
3026 | 3026 | for table, (xlist, msg), dobackup in disptable: |
|
3027 | 3027 | if abs not in table: |
|
3028 | 3028 | continue |
|
3029 | 3029 | if xlist is not None: |
|
3030 | 3030 | xlist.append(abs) |
|
3031 | 3031 | if dobackup and (backup <= dobackup |
|
3032 | 3032 | or wctx[abs].cmp(ctx[abs])): |
|
3033 | 3033 | bakname = "%s.orig" % rel |
|
3034 | 3034 | ui.note(_('saving current version of %s as %s\n') % |
|
3035 | 3035 | (rel, bakname)) |
|
3036 | 3036 | if not opts.get('dry_run'): |
|
3037 | 3037 | if interactive: |
|
3038 | 3038 | util.copyfile(target, bakname) |
|
3039 | 3039 | else: |
|
3040 | 3040 | util.rename(target, bakname) |
|
3041 | 3041 | if ui.verbose or not exact: |
|
3042 | 3042 | if not isinstance(msg, basestring): |
|
3043 | 3043 | msg = msg(abs) |
|
3044 | 3044 | ui.status(msg % rel) |
|
3045 | 3045 | elif exact: |
|
3046 | 3046 | ui.warn(msg % rel) |
|
3047 | 3047 | break |
|
3048 | 3048 | |
|
3049 | 3049 | if not opts.get('dry_run'): |
|
3050 | 3050 | needdata = ('revert', 'add', 'undelete') |
|
3051 | 3051 | _revertprefetch(repo, ctx, *[actions[name][0] for name in needdata]) |
|
3052 | 3052 | _performrevert(repo, parents, ctx, actions, interactive) |
|
3053 | 3053 | |
|
3054 | 3054 | if targetsubs: |
|
3055 | 3055 | # Revert the subrepos on the revert list |
|
3056 | 3056 | for sub in targetsubs: |
|
3057 | 3057 | try: |
|
3058 | 3058 | wctx.sub(sub).revert(ctx.substate[sub], *pats, **opts) |
|
3059 | 3059 | except KeyError: |
|
3060 | 3060 | raise util.Abort("subrepository '%s' does not exist in %s!" |
|
3061 | 3061 | % (sub, short(ctx.node()))) |
|
3062 | 3062 | finally: |
|
3063 | 3063 | wlock.release() |
|
3064 | 3064 | |
|
3065 | 3065 | def _revertprefetch(repo, ctx, *files): |
|
3066 | 3066 | """Let extension changing the storage layer prefetch content""" |
|
3067 | 3067 | pass |
|
3068 | 3068 | |
|
3069 | 3069 | def _performrevert(repo, parents, ctx, actions, interactive=False): |
|
3070 | 3070 | """function that actually perform all the actions computed for revert |
|
3071 | 3071 | |
|
3072 | 3072 | This is an independent function to let extension to plug in and react to |
|
3073 | 3073 | the imminent revert. |
|
3074 | 3074 | |
|
3075 | 3075 | Make sure you have the working directory locked when calling this function. |
|
3076 | 3076 | """ |
|
3077 | 3077 | parent, p2 = parents |
|
3078 | 3078 | node = ctx.node() |
|
3079 | 3079 | def checkout(f): |
|
3080 | 3080 | fc = ctx[f] |
|
3081 | 3081 | repo.wwrite(f, fc.data(), fc.flags()) |
|
3082 | 3082 | |
|
3083 | 3083 | audit_path = pathutil.pathauditor(repo.root) |
|
3084 | 3084 | for f in actions['forget'][0]: |
|
3085 | 3085 | repo.dirstate.drop(f) |
|
3086 | 3086 | for f in actions['remove'][0]: |
|
3087 | 3087 | audit_path(f) |
|
3088 | 3088 | try: |
|
3089 | 3089 | util.unlinkpath(repo.wjoin(f)) |
|
3090 | 3090 | except OSError: |
|
3091 | 3091 | pass |
|
3092 | 3092 | repo.dirstate.remove(f) |
|
3093 | 3093 | for f in actions['drop'][0]: |
|
3094 | 3094 | audit_path(f) |
|
3095 | 3095 | repo.dirstate.remove(f) |
|
3096 | 3096 | |
|
3097 | 3097 | normal = None |
|
3098 | 3098 | if node == parent: |
|
3099 | 3099 | # We're reverting to our parent. If possible, we'd like status |
|
3100 | 3100 | # to report the file as clean. We have to use normallookup for |
|
3101 | 3101 | # merges to avoid losing information about merged/dirty files. |
|
3102 | 3102 | if p2 != nullid: |
|
3103 | 3103 | normal = repo.dirstate.normallookup |
|
3104 | 3104 | else: |
|
3105 | 3105 | normal = repo.dirstate.normal |
|
3106 | 3106 | |
|
3107 | 3107 | newlyaddedandmodifiedfiles = set() |
|
3108 | 3108 | if interactive: |
|
3109 | 3109 | # Prompt the user for changes to revert |
|
3110 | 3110 | torevert = [repo.wjoin(f) for f in actions['revert'][0]] |
|
3111 | 3111 | m = scmutil.match(ctx, torevert, {}) |
|
3112 | 3112 | diffopts = patch.difffeatureopts(repo.ui, whitespace=True) |
|
3113 | 3113 | diffopts.nodates = True |
|
3114 | 3114 | diffopts.git = True |
|
3115 | 3115 | reversehunks = repo.ui.configbool('experimental', |
|
3116 | 3116 | 'revertalternateinteractivemode', |
|
3117 | 3117 | True) |
|
3118 | 3118 | if reversehunks: |
|
3119 | 3119 | diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts) |
|
3120 | 3120 | else: |
|
3121 | 3121 | diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts) |
|
3122 | 3122 | originalchunks = patch.parsepatch(diff) |
|
3123 | 3123 | |
|
3124 | 3124 | try: |
|
3125 | 3125 | |
|
3126 | 3126 | chunks = recordfilter(repo.ui, originalchunks) |
|
3127 | 3127 | if reversehunks: |
|
3128 | 3128 | chunks = patch.reversehunks(chunks) |
|
3129 | 3129 | |
|
3130 | 3130 | except patch.PatchError as err: |
|
3131 | 3131 | raise util.Abort(_('error parsing patch: %s') % err) |
|
3132 | 3132 | |
|
3133 | 3133 | newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks) |
|
3134 | 3134 | # Apply changes |
|
3135 | 3135 | fp = cStringIO.StringIO() |
|
3136 | 3136 | for c in chunks: |
|
3137 | 3137 | c.write(fp) |
|
3138 | 3138 | dopatch = fp.tell() |
|
3139 | 3139 | fp.seek(0) |
|
3140 | 3140 | if dopatch: |
|
3141 | 3141 | try: |
|
3142 | 3142 | patch.internalpatch(repo.ui, repo, fp, 1, eolmode=None) |
|
3143 | 3143 | except patch.PatchError as err: |
|
3144 | 3144 | raise util.Abort(str(err)) |
|
3145 | 3145 | del fp |
|
3146 | 3146 | else: |
|
3147 | 3147 | for f in actions['revert'][0]: |
|
3148 | 3148 | checkout(f) |
|
3149 | 3149 | if normal: |
|
3150 | 3150 | normal(f) |
|
3151 | 3151 | |
|
3152 | 3152 | for f in actions['add'][0]: |
|
3153 | 3153 | # Don't checkout modified files, they are already created by the diff |
|
3154 | 3154 | if f not in newlyaddedandmodifiedfiles: |
|
3155 | 3155 | checkout(f) |
|
3156 | 3156 | repo.dirstate.add(f) |
|
3157 | 3157 | |
|
3158 | 3158 | normal = repo.dirstate.normallookup |
|
3159 | 3159 | if node == parent and p2 == nullid: |
|
3160 | 3160 | normal = repo.dirstate.normal |
|
3161 | 3161 | for f in actions['undelete'][0]: |
|
3162 | 3162 | checkout(f) |
|
3163 | 3163 | normal(f) |
|
3164 | 3164 | |
|
3165 | 3165 | copied = copies.pathcopies(repo[parent], ctx) |
|
3166 | 3166 | |
|
3167 | 3167 | for f in actions['add'][0] + actions['undelete'][0] + actions['revert'][0]: |
|
3168 | 3168 | if f in copied: |
|
3169 | 3169 | repo.dirstate.copy(copied[f], f) |
|
3170 | 3170 | |
|
3171 | 3171 | def command(table): |
|
3172 | 3172 | """Returns a function object to be used as a decorator for making commands. |
|
3173 | 3173 | |
|
3174 | 3174 | This function receives a command table as its argument. The table should |
|
3175 | 3175 | be a dict. |
|
3176 | 3176 | |
|
3177 | 3177 | The returned function can be used as a decorator for adding commands |
|
3178 | 3178 | to that command table. This function accepts multiple arguments to define |
|
3179 | 3179 | a command. |
|
3180 | 3180 | |
|
3181 | 3181 | The first argument is the command name. |
|
3182 | 3182 | |
|
3183 | 3183 | The options argument is an iterable of tuples defining command arguments. |
|
3184 | 3184 | See ``mercurial.fancyopts.fancyopts()`` for the format of each tuple. |
|
3185 | 3185 | |
|
3186 | 3186 | The synopsis argument defines a short, one line summary of how to use the |
|
3187 | 3187 | command. This shows up in the help output. |
|
3188 | 3188 | |
|
3189 | 3189 | The norepo argument defines whether the command does not require a |
|
3190 | 3190 | local repository. Most commands operate against a repository, thus the |
|
3191 | 3191 | default is False. |
|
3192 | 3192 | |
|
3193 | 3193 | The optionalrepo argument defines whether the command optionally requires |
|
3194 | 3194 | a local repository. |
|
3195 | 3195 | |
|
3196 | 3196 | The inferrepo argument defines whether to try to find a repository from the |
|
3197 | 3197 | command line arguments. If True, arguments will be examined for potential |
|
3198 | 3198 | repository locations. See ``findrepo()``. If a repository is found, it |
|
3199 | 3199 | will be used. |
|
3200 | 3200 | """ |
|
3201 | 3201 | def cmd(name, options=(), synopsis=None, norepo=False, optionalrepo=False, |
|
3202 | 3202 | inferrepo=False): |
|
3203 | 3203 | def decorator(func): |
|
3204 | 3204 | if synopsis: |
|
3205 | 3205 | table[name] = func, list(options), synopsis |
|
3206 | 3206 | else: |
|
3207 | 3207 | table[name] = func, list(options) |
|
3208 | 3208 | |
|
3209 | 3209 | if norepo: |
|
3210 | 3210 | # Avoid import cycle. |
|
3211 | 3211 | import commands |
|
3212 | 3212 | commands.norepo += ' %s' % ' '.join(parsealiases(name)) |
|
3213 | 3213 | |
|
3214 | 3214 | if optionalrepo: |
|
3215 | 3215 | import commands |
|
3216 | 3216 | commands.optionalrepo += ' %s' % ' '.join(parsealiases(name)) |
|
3217 | 3217 | |
|
3218 | 3218 | if inferrepo: |
|
3219 | 3219 | import commands |
|
3220 | 3220 | commands.inferrepo += ' %s' % ' '.join(parsealiases(name)) |
|
3221 | 3221 | |
|
3222 | 3222 | return func |
|
3223 | 3223 | return decorator |
|
3224 | 3224 | |
|
3225 | 3225 | return cmd |
|
3226 | 3226 | |
|
3227 | 3227 | # a list of (ui, repo, otherpeer, opts, missing) functions called by |
|
3228 | 3228 | # commands.outgoing. "missing" is "missing" of the result of |
|
3229 | 3229 | # "findcommonoutgoing()" |
|
3230 | 3230 | outgoinghooks = util.hooks() |
|
3231 | 3231 | |
|
3232 | 3232 | # a list of (ui, repo) functions called by commands.summary |
|
3233 | 3233 | summaryhooks = util.hooks() |
|
3234 | 3234 | |
|
3235 | 3235 | # a list of (ui, repo, opts, changes) functions called by commands.summary. |
|
3236 | 3236 | # |
|
3237 | 3237 | # functions should return tuple of booleans below, if 'changes' is None: |
|
3238 | 3238 | # (whether-incomings-are-needed, whether-outgoings-are-needed) |
|
3239 | 3239 | # |
|
3240 | 3240 | # otherwise, 'changes' is a tuple of tuples below: |
|
3241 | 3241 | # - (sourceurl, sourcebranch, sourcepeer, incoming) |
|
3242 | 3242 | # - (desturl, destbranch, destpeer, outgoing) |
|
3243 | 3243 | summaryremotehooks = util.hooks() |
|
3244 | 3244 | |
|
3245 | 3245 | # A list of state files kept by multistep operations like graft. |
|
3246 | 3246 | # Since graft cannot be aborted, it is considered 'clearable' by update. |
|
3247 | 3247 | # note: bisect is intentionally excluded |
|
3248 | 3248 | # (state file, clearable, allowcommit, error, hint) |
|
3249 | 3249 | unfinishedstates = [ |
|
3250 | 3250 | ('graftstate', True, False, _('graft in progress'), |
|
3251 | 3251 | _("use 'hg graft --continue' or 'hg update' to abort")), |
|
3252 | 3252 | ('updatestate', True, False, _('last update was interrupted'), |
|
3253 | 3253 | _("use 'hg update' to get a consistent checkout")) |
|
3254 | 3254 | ] |
|
3255 | 3255 | |
|
3256 | 3256 | def checkunfinished(repo, commit=False): |
|
3257 | 3257 | '''Look for an unfinished multistep operation, like graft, and abort |
|
3258 | 3258 | if found. It's probably good to check this right before |
|
3259 | 3259 | bailifchanged(). |
|
3260 | 3260 | ''' |
|
3261 | 3261 | for f, clearable, allowcommit, msg, hint in unfinishedstates: |
|
3262 | 3262 | if commit and allowcommit: |
|
3263 | 3263 | continue |
|
3264 | 3264 | if repo.vfs.exists(f): |
|
3265 | 3265 | raise util.Abort(msg, hint=hint) |
|
3266 | 3266 | |
|
3267 | 3267 | def clearunfinished(repo): |
|
3268 | 3268 | '''Check for unfinished operations (as above), and clear the ones |
|
3269 | 3269 | that are clearable. |
|
3270 | 3270 | ''' |
|
3271 | 3271 | for f, clearable, allowcommit, msg, hint in unfinishedstates: |
|
3272 | 3272 | if not clearable and repo.vfs.exists(f): |
|
3273 | 3273 | raise util.Abort(msg, hint=hint) |
|
3274 | 3274 | for f, clearable, allowcommit, msg, hint in unfinishedstates: |
|
3275 | 3275 | if clearable and repo.vfs.exists(f): |
|
3276 | 3276 | util.unlink(repo.join(f)) |
|
3277 | 3277 | |
|
3278 | 3278 | class dirstateguard(object): |
|
3279 | 3279 | '''Restore dirstate at unexpected failure. |
|
3280 | 3280 | |
|
3281 | 3281 | At the construction, this class does: |
|
3282 | 3282 | |
|
3283 | 3283 | - write current ``repo.dirstate`` out, and |
|
3284 | 3284 | - save ``.hg/dirstate`` into the backup file |
|
3285 | 3285 | |
|
3286 | 3286 | This restores ``.hg/dirstate`` from backup file, if ``release()`` |
|
3287 | 3287 | is invoked before ``close()``. |
|
3288 | 3288 | |
|
3289 | 3289 | This just removes the backup file at ``close()`` before ``release()``. |
|
3290 | 3290 | ''' |
|
3291 | 3291 | |
|
3292 | 3292 | def __init__(self, repo, name): |
|
3293 | 3293 | repo.dirstate.write() |
|
3294 | 3294 | self._repo = repo |
|
3295 | 3295 | self._filename = 'dirstate.backup.%s.%d' % (name, id(self)) |
|
3296 | 3296 | repo.vfs.write(self._filename, repo.vfs.tryread('dirstate')) |
|
3297 | 3297 | self._active = True |
|
3298 | 3298 | self._closed = False |
|
3299 | 3299 | |
|
3300 | 3300 | def __del__(self): |
|
3301 | 3301 | if self._active: # still active |
|
3302 | 3302 | # this may occur, even if this class is used correctly: |
|
3303 | 3303 | # for example, releasing other resources like transaction |
|
3304 | 3304 | # may raise exception before ``dirstateguard.release`` in |
|
3305 | 3305 | # ``release(tr, ....)``. |
|
3306 | 3306 | self._abort() |
|
3307 | 3307 | |
|
3308 | 3308 | def close(self): |
|
3309 | 3309 | if not self._active: # already inactivated |
|
3310 | 3310 | msg = (_("can't close already inactivated backup: %s") |
|
3311 | 3311 | % self._filename) |
|
3312 | 3312 | raise util.Abort(msg) |
|
3313 | 3313 | |
|
3314 | 3314 | self._repo.vfs.unlink(self._filename) |
|
3315 | 3315 | self._active = False |
|
3316 | 3316 | self._closed = True |
|
3317 | 3317 | |
|
3318 | 3318 | def _abort(self): |
|
3319 | 3319 | # this "invalidate()" prevents "wlock.release()" from writing |
|
3320 | 3320 | # changes of dirstate out after restoring to original status |
|
3321 | 3321 | self._repo.dirstate.invalidate() |
|
3322 | 3322 | |
|
3323 | 3323 | self._repo.vfs.rename(self._filename, 'dirstate') |
|
3324 | 3324 | self._active = False |
|
3325 | 3325 | |
|
3326 | 3326 | def release(self): |
|
3327 | 3327 | if not self._closed: |
|
3328 | 3328 | if not self._active: # already inactivated |
|
3329 | 3329 | msg = (_("can't release already inactivated backup: %s") |
|
3330 | 3330 | % self._filename) |
|
3331 | 3331 | raise util.Abort(msg) |
|
3332 | 3332 | self._abort() |
|
3333 | 3333 | |
|
3334 | def parsebundletype(bundletype): | |
|
3334 | _bundlecompspecs = {'none': None, | |
|
3335 | 'bzip2': 'BZ', | |
|
3336 | 'gzip': 'GZ', | |
|
3337 | } | |
|
3338 | ||
|
3339 | _bundleversionspecs = {'v1': '01', | |
|
3340 | 'v2': '02', | |
|
3341 | 'bundle2': '02', #legacy | |
|
3342 | } | |
|
3343 | ||
|
3344 | def parsebundletype(repo, spec): | |
|
3335 | 3345 | """return the internal bundle type to use from a user input |
|
3336 | 3346 | |
|
3337 | 3347 | This is parsing user specified bundle type as accepted in: |
|
3338 | 3348 | |
|
3339 | 3349 | 'hg bundle --type TYPE'. |
|
3350 | ||
|
3351 | It accept format in the form [compression][-version]|[version] | |
|
3340 | 3352 | """ |
|
3341 | btypes = {'none': 'HG10UN', | |
|
3342 | 'bzip2': 'HG10BZ', | |
|
3343 | 'gzip': 'HG10GZ', | |
|
3344 | 'bundle2': 'HG20'} | |
|
3345 | bundletype = btypes.get(bundletype) | |
|
3346 | if bundletype not in changegroup.bundletypes: | |
|
3353 | comp, version = None, None | |
|
3354 | ||
|
3355 | if '-' in spec: | |
|
3356 | comp, version = spec.split('-', 1) | |
|
3357 | elif spec in _bundlecompspecs: | |
|
3358 | comp = spec | |
|
3359 | elif spec in _bundleversionspecs: | |
|
3360 | version = spec | |
|
3361 | else: | |
|
3347 | 3362 | raise util.Abort(_('unknown bundle type specified with --type')) |
|
3348 | return bundletype | |
|
3349 | ||
|
3363 | ||
|
3364 | if comp is None: | |
|
3365 | comp = 'BZ' | |
|
3366 | else: | |
|
3367 | try: | |
|
3368 | comp = _bundlecompspecs[comp] | |
|
3369 | except KeyError: | |
|
3370 | raise util.Abort(_('unknown bundle type specified with --type')) | |
|
3371 | ||
|
3372 | if version is None: | |
|
3373 | version = '01' | |
|
3374 | else: | |
|
3375 | try: | |
|
3376 | version = _bundleversionspecs[version] | |
|
3377 | except KeyError: | |
|
3378 | raise util.Abort(_('unknown bundle type specified with --type')) | |
|
3379 | ||
|
3380 | return version, comp |
@@ -1,6636 +1,6649 b'' | |||
|
1 | 1 | # commands.py - command processing for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from node import hex, bin, nullid, nullrev, short |
|
9 | 9 | from lock import release |
|
10 | 10 | from i18n import _ |
|
11 | 11 | import os, re, difflib, time, tempfile, errno, shlex |
|
12 | 12 | import sys, socket |
|
13 | 13 | import hg, scmutil, util, revlog, copies, error, bookmarks |
|
14 | 14 | import patch, help, encoding, templatekw, discovery |
|
15 | 15 | import archival, changegroup, cmdutil, hbisect |
|
16 | 16 | import sshserver, hgweb |
|
17 | 17 | import extensions |
|
18 | 18 | from hgweb import server as hgweb_server |
|
19 | 19 | import merge as mergemod |
|
20 | 20 | import minirst, revset, fileset |
|
21 | 21 | import dagparser, context, simplemerge, graphmod, copies |
|
22 | 22 | import random, operator |
|
23 | 23 | import setdiscovery, treediscovery, dagutil, pvec, localrepo |
|
24 | 24 | import phases, obsolete, exchange, bundle2, repair, lock as lockmod |
|
25 | 25 | import ui as uimod |
|
26 | 26 | |
|
27 | 27 | table = {} |
|
28 | 28 | |
|
29 | 29 | command = cmdutil.command(table) |
|
30 | 30 | |
|
31 | 31 | # Space delimited list of commands that don't require local repositories. |
|
32 | 32 | # This should be populated by passing norepo=True into the @command decorator. |
|
33 | 33 | norepo = '' |
|
34 | 34 | # Space delimited list of commands that optionally require local repositories. |
|
35 | 35 | # This should be populated by passing optionalrepo=True into the @command |
|
36 | 36 | # decorator. |
|
37 | 37 | optionalrepo = '' |
|
38 | 38 | # Space delimited list of commands that will examine arguments looking for |
|
39 | 39 | # a repository. This should be populated by passing inferrepo=True into the |
|
40 | 40 | # @command decorator. |
|
41 | 41 | inferrepo = '' |
|
42 | 42 | |
|
43 | 43 | # label constants |
|
44 | 44 | # until 3.5, bookmarks.current was the advertised name, not |
|
45 | 45 | # bookmarks.active, so we must use both to avoid breaking old |
|
46 | 46 | # custom styles |
|
47 | 47 | activebookmarklabel = 'bookmarks.active bookmarks.current' |
|
48 | 48 | |
|
49 | 49 | # common command options |
|
50 | 50 | |
|
51 | 51 | globalopts = [ |
|
52 | 52 | ('R', 'repository', '', |
|
53 | 53 | _('repository root directory or name of overlay bundle file'), |
|
54 | 54 | _('REPO')), |
|
55 | 55 | ('', 'cwd', '', |
|
56 | 56 | _('change working directory'), _('DIR')), |
|
57 | 57 | ('y', 'noninteractive', None, |
|
58 | 58 | _('do not prompt, automatically pick the first choice for all prompts')), |
|
59 | 59 | ('q', 'quiet', None, _('suppress output')), |
|
60 | 60 | ('v', 'verbose', None, _('enable additional output')), |
|
61 | 61 | ('', 'config', [], |
|
62 | 62 | _('set/override config option (use \'section.name=value\')'), |
|
63 | 63 | _('CONFIG')), |
|
64 | 64 | ('', 'debug', None, _('enable debugging output')), |
|
65 | 65 | ('', 'debugger', None, _('start debugger')), |
|
66 | 66 | ('', 'encoding', encoding.encoding, _('set the charset encoding'), |
|
67 | 67 | _('ENCODE')), |
|
68 | 68 | ('', 'encodingmode', encoding.encodingmode, |
|
69 | 69 | _('set the charset encoding mode'), _('MODE')), |
|
70 | 70 | ('', 'traceback', None, _('always print a traceback on exception')), |
|
71 | 71 | ('', 'time', None, _('time how long the command takes')), |
|
72 | 72 | ('', 'profile', None, _('print command execution profile')), |
|
73 | 73 | ('', 'version', None, _('output version information and exit')), |
|
74 | 74 | ('h', 'help', None, _('display help and exit')), |
|
75 | 75 | ('', 'hidden', False, _('consider hidden changesets')), |
|
76 | 76 | ] |
|
77 | 77 | |
|
78 | 78 | dryrunopts = [('n', 'dry-run', None, |
|
79 | 79 | _('do not perform actions, just print output'))] |
|
80 | 80 | |
|
81 | 81 | remoteopts = [ |
|
82 | 82 | ('e', 'ssh', '', |
|
83 | 83 | _('specify ssh command to use'), _('CMD')), |
|
84 | 84 | ('', 'remotecmd', '', |
|
85 | 85 | _('specify hg command to run on the remote side'), _('CMD')), |
|
86 | 86 | ('', 'insecure', None, |
|
87 | 87 | _('do not verify server certificate (ignoring web.cacerts config)')), |
|
88 | 88 | ] |
|
89 | 89 | |
|
90 | 90 | walkopts = [ |
|
91 | 91 | ('I', 'include', [], |
|
92 | 92 | _('include names matching the given patterns'), _('PATTERN')), |
|
93 | 93 | ('X', 'exclude', [], |
|
94 | 94 | _('exclude names matching the given patterns'), _('PATTERN')), |
|
95 | 95 | ] |
|
96 | 96 | |
|
97 | 97 | commitopts = [ |
|
98 | 98 | ('m', 'message', '', |
|
99 | 99 | _('use text as commit message'), _('TEXT')), |
|
100 | 100 | ('l', 'logfile', '', |
|
101 | 101 | _('read commit message from file'), _('FILE')), |
|
102 | 102 | ] |
|
103 | 103 | |
|
104 | 104 | commitopts2 = [ |
|
105 | 105 | ('d', 'date', '', |
|
106 | 106 | _('record the specified date as commit date'), _('DATE')), |
|
107 | 107 | ('u', 'user', '', |
|
108 | 108 | _('record the specified user as committer'), _('USER')), |
|
109 | 109 | ] |
|
110 | 110 | |
|
111 | 111 | # hidden for now |
|
112 | 112 | formatteropts = [ |
|
113 | 113 | ('T', 'template', '', |
|
114 | 114 | _('display with template (EXPERIMENTAL)'), _('TEMPLATE')), |
|
115 | 115 | ] |
|
116 | 116 | |
|
117 | 117 | templateopts = [ |
|
118 | 118 | ('', 'style', '', |
|
119 | 119 | _('display using template map file (DEPRECATED)'), _('STYLE')), |
|
120 | 120 | ('T', 'template', '', |
|
121 | 121 | _('display with template'), _('TEMPLATE')), |
|
122 | 122 | ] |
|
123 | 123 | |
|
124 | 124 | logopts = [ |
|
125 | 125 | ('p', 'patch', None, _('show patch')), |
|
126 | 126 | ('g', 'git', None, _('use git extended diff format')), |
|
127 | 127 | ('l', 'limit', '', |
|
128 | 128 | _('limit number of changes displayed'), _('NUM')), |
|
129 | 129 | ('M', 'no-merges', None, _('do not show merges')), |
|
130 | 130 | ('', 'stat', None, _('output diffstat-style summary of changes')), |
|
131 | 131 | ('G', 'graph', None, _("show the revision DAG")), |
|
132 | 132 | ] + templateopts |
|
133 | 133 | |
|
134 | 134 | diffopts = [ |
|
135 | 135 | ('a', 'text', None, _('treat all files as text')), |
|
136 | 136 | ('g', 'git', None, _('use git extended diff format')), |
|
137 | 137 | ('', 'nodates', None, _('omit dates from diff headers')) |
|
138 | 138 | ] |
|
139 | 139 | |
|
140 | 140 | diffwsopts = [ |
|
141 | 141 | ('w', 'ignore-all-space', None, |
|
142 | 142 | _('ignore white space when comparing lines')), |
|
143 | 143 | ('b', 'ignore-space-change', None, |
|
144 | 144 | _('ignore changes in the amount of white space')), |
|
145 | 145 | ('B', 'ignore-blank-lines', None, |
|
146 | 146 | _('ignore changes whose lines are all blank')), |
|
147 | 147 | ] |
|
148 | 148 | |
|
149 | 149 | diffopts2 = [ |
|
150 | 150 | ('', 'noprefix', None, _('omit a/ and b/ prefixes from filenames')), |
|
151 | 151 | ('p', 'show-function', None, _('show which function each change is in')), |
|
152 | 152 | ('', 'reverse', None, _('produce a diff that undoes the changes')), |
|
153 | 153 | ] + diffwsopts + [ |
|
154 | 154 | ('U', 'unified', '', |
|
155 | 155 | _('number of lines of context to show'), _('NUM')), |
|
156 | 156 | ('', 'stat', None, _('output diffstat-style summary of changes')), |
|
157 | 157 | ('', 'root', '', _('produce diffs relative to subdirectory'), _('DIR')), |
|
158 | 158 | ] |
|
159 | 159 | |
|
160 | 160 | mergetoolopts = [ |
|
161 | 161 | ('t', 'tool', '', _('specify merge tool')), |
|
162 | 162 | ] |
|
163 | 163 | |
|
164 | 164 | similarityopts = [ |
|
165 | 165 | ('s', 'similarity', '', |
|
166 | 166 | _('guess renamed files by similarity (0<=s<=100)'), _('SIMILARITY')) |
|
167 | 167 | ] |
|
168 | 168 | |
|
169 | 169 | subrepoopts = [ |
|
170 | 170 | ('S', 'subrepos', None, |
|
171 | 171 | _('recurse into subrepositories')) |
|
172 | 172 | ] |
|
173 | 173 | |
|
174 | 174 | # Commands start here, listed alphabetically |
|
175 | 175 | |
|
176 | 176 | @command('^add', |
|
177 | 177 | walkopts + subrepoopts + dryrunopts, |
|
178 | 178 | _('[OPTION]... [FILE]...'), |
|
179 | 179 | inferrepo=True) |
|
180 | 180 | def add(ui, repo, *pats, **opts): |
|
181 | 181 | """add the specified files on the next commit |
|
182 | 182 | |
|
183 | 183 | Schedule files to be version controlled and added to the |
|
184 | 184 | repository. |
|
185 | 185 | |
|
186 | 186 | The files will be added to the repository at the next commit. To |
|
187 | 187 | undo an add before that, see :hg:`forget`. |
|
188 | 188 | |
|
189 | 189 | If no names are given, add all files to the repository. |
|
190 | 190 | |
|
191 | 191 | .. container:: verbose |
|
192 | 192 | |
|
193 | 193 | An example showing how new (unknown) files are added |
|
194 | 194 | automatically by :hg:`add`:: |
|
195 | 195 | |
|
196 | 196 | $ ls |
|
197 | 197 | foo.c |
|
198 | 198 | $ hg status |
|
199 | 199 | ? foo.c |
|
200 | 200 | $ hg add |
|
201 | 201 | adding foo.c |
|
202 | 202 | $ hg status |
|
203 | 203 | A foo.c |
|
204 | 204 | |
|
205 | 205 | Returns 0 if all files are successfully added. |
|
206 | 206 | """ |
|
207 | 207 | |
|
208 | 208 | m = scmutil.match(repo[None], pats, opts) |
|
209 | 209 | rejected = cmdutil.add(ui, repo, m, "", False, **opts) |
|
210 | 210 | return rejected and 1 or 0 |
|
211 | 211 | |
|
212 | 212 | @command('addremove', |
|
213 | 213 | similarityopts + subrepoopts + walkopts + dryrunopts, |
|
214 | 214 | _('[OPTION]... [FILE]...'), |
|
215 | 215 | inferrepo=True) |
|
216 | 216 | def addremove(ui, repo, *pats, **opts): |
|
217 | 217 | """add all new files, delete all missing files |
|
218 | 218 | |
|
219 | 219 | Add all new files and remove all missing files from the |
|
220 | 220 | repository. |
|
221 | 221 | |
|
222 | 222 | New files are ignored if they match any of the patterns in |
|
223 | 223 | ``.hgignore``. As with add, these changes take effect at the next |
|
224 | 224 | commit. |
|
225 | 225 | |
|
226 | 226 | Use the -s/--similarity option to detect renamed files. This |
|
227 | 227 | option takes a percentage between 0 (disabled) and 100 (files must |
|
228 | 228 | be identical) as its parameter. With a parameter greater than 0, |
|
229 | 229 | this compares every removed file with every added file and records |
|
230 | 230 | those similar enough as renames. Detecting renamed files this way |
|
231 | 231 | can be expensive. After using this option, :hg:`status -C` can be |
|
232 | 232 | used to check which files were identified as moved or renamed. If |
|
233 | 233 | not specified, -s/--similarity defaults to 100 and only renames of |
|
234 | 234 | identical files are detected. |
|
235 | 235 | |
|
236 | 236 | Returns 0 if all files are successfully added. |
|
237 | 237 | """ |
|
238 | 238 | try: |
|
239 | 239 | sim = float(opts.get('similarity') or 100) |
|
240 | 240 | except ValueError: |
|
241 | 241 | raise util.Abort(_('similarity must be a number')) |
|
242 | 242 | if sim < 0 or sim > 100: |
|
243 | 243 | raise util.Abort(_('similarity must be between 0 and 100')) |
|
244 | 244 | matcher = scmutil.match(repo[None], pats, opts) |
|
245 | 245 | return scmutil.addremove(repo, matcher, "", opts, similarity=sim / 100.0) |
|
246 | 246 | |
|
247 | 247 | @command('^annotate|blame', |
|
248 | 248 | [('r', 'rev', '', _('annotate the specified revision'), _('REV')), |
|
249 | 249 | ('', 'follow', None, |
|
250 | 250 | _('follow copies/renames and list the filename (DEPRECATED)')), |
|
251 | 251 | ('', 'no-follow', None, _("don't follow copies and renames")), |
|
252 | 252 | ('a', 'text', None, _('treat all files as text')), |
|
253 | 253 | ('u', 'user', None, _('list the author (long with -v)')), |
|
254 | 254 | ('f', 'file', None, _('list the filename')), |
|
255 | 255 | ('d', 'date', None, _('list the date (short with -q)')), |
|
256 | 256 | ('n', 'number', None, _('list the revision number (default)')), |
|
257 | 257 | ('c', 'changeset', None, _('list the changeset')), |
|
258 | 258 | ('l', 'line-number', None, _('show line number at the first appearance')) |
|
259 | 259 | ] + diffwsopts + walkopts + formatteropts, |
|
260 | 260 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'), |
|
261 | 261 | inferrepo=True) |
|
262 | 262 | def annotate(ui, repo, *pats, **opts): |
|
263 | 263 | """show changeset information by line for each file |
|
264 | 264 | |
|
265 | 265 | List changes in files, showing the revision id responsible for |
|
266 | 266 | each line |
|
267 | 267 | |
|
268 | 268 | This command is useful for discovering when a change was made and |
|
269 | 269 | by whom. |
|
270 | 270 | |
|
271 | 271 | Without the -a/--text option, annotate will avoid processing files |
|
272 | 272 | it detects as binary. With -a, annotate will annotate the file |
|
273 | 273 | anyway, although the results will probably be neither useful |
|
274 | 274 | nor desirable. |
|
275 | 275 | |
|
276 | 276 | Returns 0 on success. |
|
277 | 277 | """ |
|
278 | 278 | if not pats: |
|
279 | 279 | raise util.Abort(_('at least one filename or pattern is required')) |
|
280 | 280 | |
|
281 | 281 | if opts.get('follow'): |
|
282 | 282 | # --follow is deprecated and now just an alias for -f/--file |
|
283 | 283 | # to mimic the behavior of Mercurial before version 1.5 |
|
284 | 284 | opts['file'] = True |
|
285 | 285 | |
|
286 | 286 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
287 | 287 | |
|
288 | 288 | fm = ui.formatter('annotate', opts) |
|
289 | 289 | if ui.quiet: |
|
290 | 290 | datefunc = util.shortdate |
|
291 | 291 | else: |
|
292 | 292 | datefunc = util.datestr |
|
293 | 293 | if ctx.rev() is None: |
|
294 | 294 | def hexfn(node): |
|
295 | 295 | if node is None: |
|
296 | 296 | return None |
|
297 | 297 | else: |
|
298 | 298 | return fm.hexfunc(node) |
|
299 | 299 | if opts.get('changeset'): |
|
300 | 300 | # omit "+" suffix which is appended to node hex |
|
301 | 301 | def formatrev(rev): |
|
302 | 302 | if rev is None: |
|
303 | 303 | return '%d' % ctx.p1().rev() |
|
304 | 304 | else: |
|
305 | 305 | return '%d' % rev |
|
306 | 306 | else: |
|
307 | 307 | def formatrev(rev): |
|
308 | 308 | if rev is None: |
|
309 | 309 | return '%d+' % ctx.p1().rev() |
|
310 | 310 | else: |
|
311 | 311 | return '%d ' % rev |
|
312 | 312 | def formathex(hex): |
|
313 | 313 | if hex is None: |
|
314 | 314 | return '%s+' % fm.hexfunc(ctx.p1().node()) |
|
315 | 315 | else: |
|
316 | 316 | return '%s ' % hex |
|
317 | 317 | else: |
|
318 | 318 | hexfn = fm.hexfunc |
|
319 | 319 | formatrev = formathex = str |
|
320 | 320 | |
|
321 | 321 | opmap = [('user', ' ', lambda x: x[0].user(), ui.shortuser), |
|
322 | 322 | ('number', ' ', lambda x: x[0].rev(), formatrev), |
|
323 | 323 | ('changeset', ' ', lambda x: hexfn(x[0].node()), formathex), |
|
324 | 324 | ('date', ' ', lambda x: x[0].date(), util.cachefunc(datefunc)), |
|
325 | 325 | ('file', ' ', lambda x: x[0].path(), str), |
|
326 | 326 | ('line_number', ':', lambda x: x[1], str), |
|
327 | 327 | ] |
|
328 | 328 | fieldnamemap = {'number': 'rev', 'changeset': 'node'} |
|
329 | 329 | |
|
330 | 330 | if (not opts.get('user') and not opts.get('changeset') |
|
331 | 331 | and not opts.get('date') and not opts.get('file')): |
|
332 | 332 | opts['number'] = True |
|
333 | 333 | |
|
334 | 334 | linenumber = opts.get('line_number') is not None |
|
335 | 335 | if linenumber and (not opts.get('changeset')) and (not opts.get('number')): |
|
336 | 336 | raise util.Abort(_('at least one of -n/-c is required for -l')) |
|
337 | 337 | |
|
338 | 338 | if fm: |
|
339 | 339 | def makefunc(get, fmt): |
|
340 | 340 | return get |
|
341 | 341 | else: |
|
342 | 342 | def makefunc(get, fmt): |
|
343 | 343 | return lambda x: fmt(get(x)) |
|
344 | 344 | funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap |
|
345 | 345 | if opts.get(op)] |
|
346 | 346 | funcmap[0] = (funcmap[0][0], '') # no separator in front of first column |
|
347 | 347 | fields = ' '.join(fieldnamemap.get(op, op) for op, sep, get, fmt in opmap |
|
348 | 348 | if opts.get(op)) |
|
349 | 349 | |
|
350 | 350 | def bad(x, y): |
|
351 | 351 | raise util.Abort("%s: %s" % (x, y)) |
|
352 | 352 | |
|
353 | 353 | m = scmutil.match(ctx, pats, opts, badfn=bad) |
|
354 | 354 | |
|
355 | 355 | follow = not opts.get('no_follow') |
|
356 | 356 | diffopts = patch.difffeatureopts(ui, opts, section='annotate', |
|
357 | 357 | whitespace=True) |
|
358 | 358 | for abs in ctx.walk(m): |
|
359 | 359 | fctx = ctx[abs] |
|
360 | 360 | if not opts.get('text') and util.binary(fctx.data()): |
|
361 | 361 | fm.plain(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs)) |
|
362 | 362 | continue |
|
363 | 363 | |
|
364 | 364 | lines = fctx.annotate(follow=follow, linenumber=linenumber, |
|
365 | 365 | diffopts=diffopts) |
|
366 | 366 | formats = [] |
|
367 | 367 | pieces = [] |
|
368 | 368 | |
|
369 | 369 | for f, sep in funcmap: |
|
370 | 370 | l = [f(n) for n, dummy in lines] |
|
371 | 371 | if l: |
|
372 | 372 | if fm: |
|
373 | 373 | formats.append(['%s' for x in l]) |
|
374 | 374 | else: |
|
375 | 375 | sizes = [encoding.colwidth(x) for x in l] |
|
376 | 376 | ml = max(sizes) |
|
377 | 377 | formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes]) |
|
378 | 378 | pieces.append(l) |
|
379 | 379 | |
|
380 | 380 | for f, p, l in zip(zip(*formats), zip(*pieces), lines): |
|
381 | 381 | fm.startitem() |
|
382 | 382 | fm.write(fields, "".join(f), *p) |
|
383 | 383 | fm.write('line', ": %s", l[1]) |
|
384 | 384 | |
|
385 | 385 | if lines and not lines[-1][1].endswith('\n'): |
|
386 | 386 | fm.plain('\n') |
|
387 | 387 | |
|
388 | 388 | fm.end() |
|
389 | 389 | |
|
390 | 390 | @command('archive', |
|
391 | 391 | [('', 'no-decode', None, _('do not pass files through decoders')), |
|
392 | 392 | ('p', 'prefix', '', _('directory prefix for files in archive'), |
|
393 | 393 | _('PREFIX')), |
|
394 | 394 | ('r', 'rev', '', _('revision to distribute'), _('REV')), |
|
395 | 395 | ('t', 'type', '', _('type of distribution to create'), _('TYPE')), |
|
396 | 396 | ] + subrepoopts + walkopts, |
|
397 | 397 | _('[OPTION]... DEST')) |
|
398 | 398 | def archive(ui, repo, dest, **opts): |
|
399 | 399 | '''create an unversioned archive of a repository revision |
|
400 | 400 | |
|
401 | 401 | By default, the revision used is the parent of the working |
|
402 | 402 | directory; use -r/--rev to specify a different revision. |
|
403 | 403 | |
|
404 | 404 | The archive type is automatically detected based on file |
|
405 | 405 | extension (or override using -t/--type). |
|
406 | 406 | |
|
407 | 407 | .. container:: verbose |
|
408 | 408 | |
|
409 | 409 | Examples: |
|
410 | 410 | |
|
411 | 411 | - create a zip file containing the 1.0 release:: |
|
412 | 412 | |
|
413 | 413 | hg archive -r 1.0 project-1.0.zip |
|
414 | 414 | |
|
415 | 415 | - create a tarball excluding .hg files:: |
|
416 | 416 | |
|
417 | 417 | hg archive project.tar.gz -X ".hg*" |
|
418 | 418 | |
|
419 | 419 | Valid types are: |
|
420 | 420 | |
|
421 | 421 | :``files``: a directory full of files (default) |
|
422 | 422 | :``tar``: tar archive, uncompressed |
|
423 | 423 | :``tbz2``: tar archive, compressed using bzip2 |
|
424 | 424 | :``tgz``: tar archive, compressed using gzip |
|
425 | 425 | :``uzip``: zip archive, uncompressed |
|
426 | 426 | :``zip``: zip archive, compressed using deflate |
|
427 | 427 | |
|
428 | 428 | The exact name of the destination archive or directory is given |
|
429 | 429 | using a format string; see :hg:`help export` for details. |
|
430 | 430 | |
|
431 | 431 | Each member added to an archive file has a directory prefix |
|
432 | 432 | prepended. Use -p/--prefix to specify a format string for the |
|
433 | 433 | prefix. The default is the basename of the archive, with suffixes |
|
434 | 434 | removed. |
|
435 | 435 | |
|
436 | 436 | Returns 0 on success. |
|
437 | 437 | ''' |
|
438 | 438 | |
|
439 | 439 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
440 | 440 | if not ctx: |
|
441 | 441 | raise util.Abort(_('no working directory: please specify a revision')) |
|
442 | 442 | node = ctx.node() |
|
443 | 443 | dest = cmdutil.makefilename(repo, dest, node) |
|
444 | 444 | if os.path.realpath(dest) == repo.root: |
|
445 | 445 | raise util.Abort(_('repository root cannot be destination')) |
|
446 | 446 | |
|
447 | 447 | kind = opts.get('type') or archival.guesskind(dest) or 'files' |
|
448 | 448 | prefix = opts.get('prefix') |
|
449 | 449 | |
|
450 | 450 | if dest == '-': |
|
451 | 451 | if kind == 'files': |
|
452 | 452 | raise util.Abort(_('cannot archive plain files to stdout')) |
|
453 | 453 | dest = cmdutil.makefileobj(repo, dest) |
|
454 | 454 | if not prefix: |
|
455 | 455 | prefix = os.path.basename(repo.root) + '-%h' |
|
456 | 456 | |
|
457 | 457 | prefix = cmdutil.makefilename(repo, prefix, node) |
|
458 | 458 | matchfn = scmutil.match(ctx, [], opts) |
|
459 | 459 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), |
|
460 | 460 | matchfn, prefix, subrepos=opts.get('subrepos')) |
|
461 | 461 | |
|
462 | 462 | @command('backout', |
|
463 | 463 | [('', 'merge', None, _('merge with old dirstate parent after backout')), |
|
464 | 464 | ('', 'commit', None, _('commit if no conflicts were encountered')), |
|
465 | 465 | ('', 'parent', '', |
|
466 | 466 | _('parent to choose when backing out merge (DEPRECATED)'), _('REV')), |
|
467 | 467 | ('r', 'rev', '', _('revision to backout'), _('REV')), |
|
468 | 468 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
469 | 469 | ] + mergetoolopts + walkopts + commitopts + commitopts2, |
|
470 | 470 | _('[OPTION]... [-r] REV')) |
|
471 | 471 | def backout(ui, repo, node=None, rev=None, commit=False, **opts): |
|
472 | 472 | '''reverse effect of earlier changeset |
|
473 | 473 | |
|
474 | 474 | Prepare a new changeset with the effect of REV undone in the |
|
475 | 475 | current working directory. |
|
476 | 476 | |
|
477 | 477 | If REV is the parent of the working directory, then this new changeset |
|
478 | 478 | is committed automatically. Otherwise, hg needs to merge the |
|
479 | 479 | changes and the merged result is left uncommitted. |
|
480 | 480 | |
|
481 | 481 | .. note:: |
|
482 | 482 | |
|
483 | 483 | backout cannot be used to fix either an unwanted or |
|
484 | 484 | incorrect merge. |
|
485 | 485 | |
|
486 | 486 | .. container:: verbose |
|
487 | 487 | |
|
488 | 488 | By default, the pending changeset will have one parent, |
|
489 | 489 | maintaining a linear history. With --merge, the pending |
|
490 | 490 | changeset will instead have two parents: the old parent of the |
|
491 | 491 | working directory and a new child of REV that simply undoes REV. |
|
492 | 492 | |
|
493 | 493 | Before version 1.7, the behavior without --merge was equivalent |
|
494 | 494 | to specifying --merge followed by :hg:`update --clean .` to |
|
495 | 495 | cancel the merge and leave the child of REV as a head to be |
|
496 | 496 | merged separately. |
|
497 | 497 | |
|
498 | 498 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
499 | 499 | |
|
500 | 500 | See :hg:`help revert` for a way to restore files to the state |
|
501 | 501 | of another revision. |
|
502 | 502 | |
|
503 | 503 | Returns 0 on success, 1 if nothing to backout or there are unresolved |
|
504 | 504 | files. |
|
505 | 505 | ''' |
|
506 | 506 | if rev and node: |
|
507 | 507 | raise util.Abort(_("please specify just one revision")) |
|
508 | 508 | |
|
509 | 509 | if not rev: |
|
510 | 510 | rev = node |
|
511 | 511 | |
|
512 | 512 | if not rev: |
|
513 | 513 | raise util.Abort(_("please specify a revision to backout")) |
|
514 | 514 | |
|
515 | 515 | date = opts.get('date') |
|
516 | 516 | if date: |
|
517 | 517 | opts['date'] = util.parsedate(date) |
|
518 | 518 | |
|
519 | 519 | cmdutil.checkunfinished(repo) |
|
520 | 520 | cmdutil.bailifchanged(repo) |
|
521 | 521 | node = scmutil.revsingle(repo, rev).node() |
|
522 | 522 | |
|
523 | 523 | op1, op2 = repo.dirstate.parents() |
|
524 | 524 | if not repo.changelog.isancestor(node, op1): |
|
525 | 525 | raise util.Abort(_('cannot backout change that is not an ancestor')) |
|
526 | 526 | |
|
527 | 527 | p1, p2 = repo.changelog.parents(node) |
|
528 | 528 | if p1 == nullid: |
|
529 | 529 | raise util.Abort(_('cannot backout a change with no parents')) |
|
530 | 530 | if p2 != nullid: |
|
531 | 531 | if not opts.get('parent'): |
|
532 | 532 | raise util.Abort(_('cannot backout a merge changeset')) |
|
533 | 533 | p = repo.lookup(opts['parent']) |
|
534 | 534 | if p not in (p1, p2): |
|
535 | 535 | raise util.Abort(_('%s is not a parent of %s') % |
|
536 | 536 | (short(p), short(node))) |
|
537 | 537 | parent = p |
|
538 | 538 | else: |
|
539 | 539 | if opts.get('parent'): |
|
540 | 540 | raise util.Abort(_('cannot use --parent on non-merge changeset')) |
|
541 | 541 | parent = p1 |
|
542 | 542 | |
|
543 | 543 | # the backout should appear on the same branch |
|
544 | 544 | wlock = repo.wlock() |
|
545 | 545 | try: |
|
546 | 546 | branch = repo.dirstate.branch() |
|
547 | 547 | bheads = repo.branchheads(branch) |
|
548 | 548 | rctx = scmutil.revsingle(repo, hex(parent)) |
|
549 | 549 | if not opts.get('merge') and op1 != node: |
|
550 | 550 | try: |
|
551 | 551 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
552 | 552 | 'backout') |
|
553 | 553 | repo.dirstate.beginparentchange() |
|
554 | 554 | stats = mergemod.update(repo, parent, True, True, False, |
|
555 | 555 | node, False) |
|
556 | 556 | repo.setparents(op1, op2) |
|
557 | 557 | repo.dirstate.endparentchange() |
|
558 | 558 | hg._showstats(repo, stats) |
|
559 | 559 | if stats[3]: |
|
560 | 560 | repo.ui.status(_("use 'hg resolve' to retry unresolved " |
|
561 | 561 | "file merges\n")) |
|
562 | 562 | return 1 |
|
563 | 563 | elif not commit: |
|
564 | 564 | msg = _("changeset %s backed out, " |
|
565 | 565 | "don't forget to commit.\n") |
|
566 | 566 | ui.status(msg % short(node)) |
|
567 | 567 | return 0 |
|
568 | 568 | finally: |
|
569 | 569 | ui.setconfig('ui', 'forcemerge', '', '') |
|
570 | 570 | else: |
|
571 | 571 | hg.clean(repo, node, show_stats=False) |
|
572 | 572 | repo.dirstate.setbranch(branch) |
|
573 | 573 | cmdutil.revert(ui, repo, rctx, repo.dirstate.parents()) |
|
574 | 574 | |
|
575 | 575 | |
|
576 | 576 | def commitfunc(ui, repo, message, match, opts): |
|
577 | 577 | editform = 'backout' |
|
578 | 578 | e = cmdutil.getcommiteditor(editform=editform, **opts) |
|
579 | 579 | if not message: |
|
580 | 580 | # we don't translate commit messages |
|
581 | 581 | message = "Backed out changeset %s" % short(node) |
|
582 | 582 | e = cmdutil.getcommiteditor(edit=True, editform=editform) |
|
583 | 583 | return repo.commit(message, opts.get('user'), opts.get('date'), |
|
584 | 584 | match, editor=e) |
|
585 | 585 | newnode = cmdutil.commit(ui, repo, commitfunc, [], opts) |
|
586 | 586 | if not newnode: |
|
587 | 587 | ui.status(_("nothing changed\n")) |
|
588 | 588 | return 1 |
|
589 | 589 | cmdutil.commitstatus(repo, newnode, branch, bheads) |
|
590 | 590 | |
|
591 | 591 | def nice(node): |
|
592 | 592 | return '%d:%s' % (repo.changelog.rev(node), short(node)) |
|
593 | 593 | ui.status(_('changeset %s backs out changeset %s\n') % |
|
594 | 594 | (nice(repo.changelog.tip()), nice(node))) |
|
595 | 595 | if opts.get('merge') and op1 != node: |
|
596 | 596 | hg.clean(repo, op1, show_stats=False) |
|
597 | 597 | ui.status(_('merging with changeset %s\n') |
|
598 | 598 | % nice(repo.changelog.tip())) |
|
599 | 599 | try: |
|
600 | 600 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
601 | 601 | 'backout') |
|
602 | 602 | return hg.merge(repo, hex(repo.changelog.tip())) |
|
603 | 603 | finally: |
|
604 | 604 | ui.setconfig('ui', 'forcemerge', '', '') |
|
605 | 605 | finally: |
|
606 | 606 | wlock.release() |
|
607 | 607 | return 0 |
|
608 | 608 | |
|
609 | 609 | @command('bisect', |
|
610 | 610 | [('r', 'reset', False, _('reset bisect state')), |
|
611 | 611 | ('g', 'good', False, _('mark changeset good')), |
|
612 | 612 | ('b', 'bad', False, _('mark changeset bad')), |
|
613 | 613 | ('s', 'skip', False, _('skip testing changeset')), |
|
614 | 614 | ('e', 'extend', False, _('extend the bisect range')), |
|
615 | 615 | ('c', 'command', '', _('use command to check changeset state'), _('CMD')), |
|
616 | 616 | ('U', 'noupdate', False, _('do not update to target'))], |
|
617 | 617 | _("[-gbsr] [-U] [-c CMD] [REV]")) |
|
618 | 618 | def bisect(ui, repo, rev=None, extra=None, command=None, |
|
619 | 619 | reset=None, good=None, bad=None, skip=None, extend=None, |
|
620 | 620 | noupdate=None): |
|
621 | 621 | """subdivision search of changesets |
|
622 | 622 | |
|
623 | 623 | This command helps to find changesets which introduce problems. To |
|
624 | 624 | use, mark the earliest changeset you know exhibits the problem as |
|
625 | 625 | bad, then mark the latest changeset which is free from the problem |
|
626 | 626 | as good. Bisect will update your working directory to a revision |
|
627 | 627 | for testing (unless the -U/--noupdate option is specified). Once |
|
628 | 628 | you have performed tests, mark the working directory as good or |
|
629 | 629 | bad, and bisect will either update to another candidate changeset |
|
630 | 630 | or announce that it has found the bad revision. |
|
631 | 631 | |
|
632 | 632 | As a shortcut, you can also use the revision argument to mark a |
|
633 | 633 | revision as good or bad without checking it out first. |
|
634 | 634 | |
|
635 | 635 | If you supply a command, it will be used for automatic bisection. |
|
636 | 636 | The environment variable HG_NODE will contain the ID of the |
|
637 | 637 | changeset being tested. The exit status of the command will be |
|
638 | 638 | used to mark revisions as good or bad: status 0 means good, 125 |
|
639 | 639 | means to skip the revision, 127 (command not found) will abort the |
|
640 | 640 | bisection, and any other non-zero exit status means the revision |
|
641 | 641 | is bad. |
|
642 | 642 | |
|
643 | 643 | .. container:: verbose |
|
644 | 644 | |
|
645 | 645 | Some examples: |
|
646 | 646 | |
|
647 | 647 | - start a bisection with known bad revision 34, and good revision 12:: |
|
648 | 648 | |
|
649 | 649 | hg bisect --bad 34 |
|
650 | 650 | hg bisect --good 12 |
|
651 | 651 | |
|
652 | 652 | - advance the current bisection by marking current revision as good or |
|
653 | 653 | bad:: |
|
654 | 654 | |
|
655 | 655 | hg bisect --good |
|
656 | 656 | hg bisect --bad |
|
657 | 657 | |
|
658 | 658 | - mark the current revision, or a known revision, to be skipped (e.g. if |
|
659 | 659 | that revision is not usable because of another issue):: |
|
660 | 660 | |
|
661 | 661 | hg bisect --skip |
|
662 | 662 | hg bisect --skip 23 |
|
663 | 663 | |
|
664 | 664 | - skip all revisions that do not touch directories ``foo`` or ``bar``:: |
|
665 | 665 | |
|
666 | 666 | hg bisect --skip "!( file('path:foo') & file('path:bar') )" |
|
667 | 667 | |
|
668 | 668 | - forget the current bisection:: |
|
669 | 669 | |
|
670 | 670 | hg bisect --reset |
|
671 | 671 | |
|
672 | 672 | - use 'make && make tests' to automatically find the first broken |
|
673 | 673 | revision:: |
|
674 | 674 | |
|
675 | 675 | hg bisect --reset |
|
676 | 676 | hg bisect --bad 34 |
|
677 | 677 | hg bisect --good 12 |
|
678 | 678 | hg bisect --command "make && make tests" |
|
679 | 679 | |
|
680 | 680 | - see all changesets whose states are already known in the current |
|
681 | 681 | bisection:: |
|
682 | 682 | |
|
683 | 683 | hg log -r "bisect(pruned)" |
|
684 | 684 | |
|
685 | 685 | - see the changeset currently being bisected (especially useful |
|
686 | 686 | if running with -U/--noupdate):: |
|
687 | 687 | |
|
688 | 688 | hg log -r "bisect(current)" |
|
689 | 689 | |
|
690 | 690 | - see all changesets that took part in the current bisection:: |
|
691 | 691 | |
|
692 | 692 | hg log -r "bisect(range)" |
|
693 | 693 | |
|
694 | 694 | - you can even get a nice graph:: |
|
695 | 695 | |
|
696 | 696 | hg log --graph -r "bisect(range)" |
|
697 | 697 | |
|
698 | 698 | See :hg:`help revsets` for more about the `bisect()` keyword. |
|
699 | 699 | |
|
700 | 700 | Returns 0 on success. |
|
701 | 701 | """ |
|
702 | 702 | def extendbisectrange(nodes, good): |
|
703 | 703 | # bisect is incomplete when it ends on a merge node and |
|
704 | 704 | # one of the parent was not checked. |
|
705 | 705 | parents = repo[nodes[0]].parents() |
|
706 | 706 | if len(parents) > 1: |
|
707 | 707 | if good: |
|
708 | 708 | side = state['bad'] |
|
709 | 709 | else: |
|
710 | 710 | side = state['good'] |
|
711 | 711 | num = len(set(i.node() for i in parents) & set(side)) |
|
712 | 712 | if num == 1: |
|
713 | 713 | return parents[0].ancestor(parents[1]) |
|
714 | 714 | return None |
|
715 | 715 | |
|
716 | 716 | def print_result(nodes, good): |
|
717 | 717 | displayer = cmdutil.show_changeset(ui, repo, {}) |
|
718 | 718 | if len(nodes) == 1: |
|
719 | 719 | # narrowed it down to a single revision |
|
720 | 720 | if good: |
|
721 | 721 | ui.write(_("The first good revision is:\n")) |
|
722 | 722 | else: |
|
723 | 723 | ui.write(_("The first bad revision is:\n")) |
|
724 | 724 | displayer.show(repo[nodes[0]]) |
|
725 | 725 | extendnode = extendbisectrange(nodes, good) |
|
726 | 726 | if extendnode is not None: |
|
727 | 727 | ui.write(_('Not all ancestors of this changeset have been' |
|
728 | 728 | ' checked.\nUse bisect --extend to continue the ' |
|
729 | 729 | 'bisection from\nthe common ancestor, %s.\n') |
|
730 | 730 | % extendnode) |
|
731 | 731 | else: |
|
732 | 732 | # multiple possible revisions |
|
733 | 733 | if good: |
|
734 | 734 | ui.write(_("Due to skipped revisions, the first " |
|
735 | 735 | "good revision could be any of:\n")) |
|
736 | 736 | else: |
|
737 | 737 | ui.write(_("Due to skipped revisions, the first " |
|
738 | 738 | "bad revision could be any of:\n")) |
|
739 | 739 | for n in nodes: |
|
740 | 740 | displayer.show(repo[n]) |
|
741 | 741 | displayer.close() |
|
742 | 742 | |
|
743 | 743 | def check_state(state, interactive=True): |
|
744 | 744 | if not state['good'] or not state['bad']: |
|
745 | 745 | if (good or bad or skip or reset) and interactive: |
|
746 | 746 | return |
|
747 | 747 | if not state['good']: |
|
748 | 748 | raise util.Abort(_('cannot bisect (no known good revisions)')) |
|
749 | 749 | else: |
|
750 | 750 | raise util.Abort(_('cannot bisect (no known bad revisions)')) |
|
751 | 751 | return True |
|
752 | 752 | |
|
753 | 753 | # backward compatibility |
|
754 | 754 | if rev in "good bad reset init".split(): |
|
755 | 755 | ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n")) |
|
756 | 756 | cmd, rev, extra = rev, extra, None |
|
757 | 757 | if cmd == "good": |
|
758 | 758 | good = True |
|
759 | 759 | elif cmd == "bad": |
|
760 | 760 | bad = True |
|
761 | 761 | else: |
|
762 | 762 | reset = True |
|
763 | 763 | elif extra or good + bad + skip + reset + extend + bool(command) > 1: |
|
764 | 764 | raise util.Abort(_('incompatible arguments')) |
|
765 | 765 | |
|
766 | 766 | cmdutil.checkunfinished(repo) |
|
767 | 767 | |
|
768 | 768 | if reset: |
|
769 | 769 | p = repo.join("bisect.state") |
|
770 | 770 | if os.path.exists(p): |
|
771 | 771 | os.unlink(p) |
|
772 | 772 | return |
|
773 | 773 | |
|
774 | 774 | state = hbisect.load_state(repo) |
|
775 | 775 | |
|
776 | 776 | if command: |
|
777 | 777 | changesets = 1 |
|
778 | 778 | if noupdate: |
|
779 | 779 | try: |
|
780 | 780 | node = state['current'][0] |
|
781 | 781 | except LookupError: |
|
782 | 782 | raise util.Abort(_('current bisect revision is unknown - ' |
|
783 | 783 | 'start a new bisect to fix')) |
|
784 | 784 | else: |
|
785 | 785 | node, p2 = repo.dirstate.parents() |
|
786 | 786 | if p2 != nullid: |
|
787 | 787 | raise util.Abort(_('current bisect revision is a merge')) |
|
788 | 788 | try: |
|
789 | 789 | while changesets: |
|
790 | 790 | # update state |
|
791 | 791 | state['current'] = [node] |
|
792 | 792 | hbisect.save_state(repo, state) |
|
793 | 793 | status = ui.system(command, environ={'HG_NODE': hex(node)}) |
|
794 | 794 | if status == 125: |
|
795 | 795 | transition = "skip" |
|
796 | 796 | elif status == 0: |
|
797 | 797 | transition = "good" |
|
798 | 798 | # status < 0 means process was killed |
|
799 | 799 | elif status == 127: |
|
800 | 800 | raise util.Abort(_("failed to execute %s") % command) |
|
801 | 801 | elif status < 0: |
|
802 | 802 | raise util.Abort(_("%s killed") % command) |
|
803 | 803 | else: |
|
804 | 804 | transition = "bad" |
|
805 | 805 | ctx = scmutil.revsingle(repo, rev, node) |
|
806 | 806 | rev = None # clear for future iterations |
|
807 | 807 | state[transition].append(ctx.node()) |
|
808 | 808 | ui.status(_('changeset %d:%s: %s\n') % (ctx, ctx, transition)) |
|
809 | 809 | check_state(state, interactive=False) |
|
810 | 810 | # bisect |
|
811 | 811 | nodes, changesets, bgood = hbisect.bisect(repo.changelog, state) |
|
812 | 812 | # update to next check |
|
813 | 813 | node = nodes[0] |
|
814 | 814 | if not noupdate: |
|
815 | 815 | cmdutil.bailifchanged(repo) |
|
816 | 816 | hg.clean(repo, node, show_stats=False) |
|
817 | 817 | finally: |
|
818 | 818 | state['current'] = [node] |
|
819 | 819 | hbisect.save_state(repo, state) |
|
820 | 820 | print_result(nodes, bgood) |
|
821 | 821 | return |
|
822 | 822 | |
|
823 | 823 | # update state |
|
824 | 824 | |
|
825 | 825 | if rev: |
|
826 | 826 | nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])] |
|
827 | 827 | else: |
|
828 | 828 | nodes = [repo.lookup('.')] |
|
829 | 829 | |
|
830 | 830 | if good or bad or skip: |
|
831 | 831 | if good: |
|
832 | 832 | state['good'] += nodes |
|
833 | 833 | elif bad: |
|
834 | 834 | state['bad'] += nodes |
|
835 | 835 | elif skip: |
|
836 | 836 | state['skip'] += nodes |
|
837 | 837 | hbisect.save_state(repo, state) |
|
838 | 838 | |
|
839 | 839 | if not check_state(state): |
|
840 | 840 | return |
|
841 | 841 | |
|
842 | 842 | # actually bisect |
|
843 | 843 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
|
844 | 844 | if extend: |
|
845 | 845 | if not changesets: |
|
846 | 846 | extendnode = extendbisectrange(nodes, good) |
|
847 | 847 | if extendnode is not None: |
|
848 | 848 | ui.write(_("Extending search to changeset %d:%s\n") |
|
849 | 849 | % (extendnode.rev(), extendnode)) |
|
850 | 850 | state['current'] = [extendnode.node()] |
|
851 | 851 | hbisect.save_state(repo, state) |
|
852 | 852 | if noupdate: |
|
853 | 853 | return |
|
854 | 854 | cmdutil.bailifchanged(repo) |
|
855 | 855 | return hg.clean(repo, extendnode.node()) |
|
856 | 856 | raise util.Abort(_("nothing to extend")) |
|
857 | 857 | |
|
858 | 858 | if changesets == 0: |
|
859 | 859 | print_result(nodes, good) |
|
860 | 860 | else: |
|
861 | 861 | assert len(nodes) == 1 # only a single node can be tested next |
|
862 | 862 | node = nodes[0] |
|
863 | 863 | # compute the approximate number of remaining tests |
|
864 | 864 | tests, size = 0, 2 |
|
865 | 865 | while size <= changesets: |
|
866 | 866 | tests, size = tests + 1, size * 2 |
|
867 | 867 | rev = repo.changelog.rev(node) |
|
868 | 868 | ui.write(_("Testing changeset %d:%s " |
|
869 | 869 | "(%d changesets remaining, ~%d tests)\n") |
|
870 | 870 | % (rev, short(node), changesets, tests)) |
|
871 | 871 | state['current'] = [node] |
|
872 | 872 | hbisect.save_state(repo, state) |
|
873 | 873 | if not noupdate: |
|
874 | 874 | cmdutil.bailifchanged(repo) |
|
875 | 875 | return hg.clean(repo, node) |
|
876 | 876 | |
|
877 | 877 | @command('bookmarks|bookmark', |
|
878 | 878 | [('f', 'force', False, _('force')), |
|
879 | 879 | ('r', 'rev', '', _('revision'), _('REV')), |
|
880 | 880 | ('d', 'delete', False, _('delete a given bookmark')), |
|
881 | 881 | ('m', 'rename', '', _('rename a given bookmark'), _('OLD')), |
|
882 | 882 | ('i', 'inactive', False, _('mark a bookmark inactive')), |
|
883 | 883 | ] + formatteropts, |
|
884 | 884 | _('hg bookmarks [OPTIONS]... [NAME]...')) |
|
885 | 885 | def bookmark(ui, repo, *names, **opts): |
|
886 | 886 | '''create a new bookmark or list existing bookmarks |
|
887 | 887 | |
|
888 | 888 | Bookmarks are labels on changesets to help track lines of development. |
|
889 | 889 | Bookmarks are unversioned and can be moved, renamed and deleted. |
|
890 | 890 | Deleting or moving a bookmark has no effect on the associated changesets. |
|
891 | 891 | |
|
892 | 892 | Creating or updating to a bookmark causes it to be marked as 'active'. |
|
893 | 893 | The active bookmark is indicated with a '*'. |
|
894 | 894 | When a commit is made, the active bookmark will advance to the new commit. |
|
895 | 895 | A plain :hg:`update` will also advance an active bookmark, if possible. |
|
896 | 896 | Updating away from a bookmark will cause it to be deactivated. |
|
897 | 897 | |
|
898 | 898 | Bookmarks can be pushed and pulled between repositories (see |
|
899 | 899 | :hg:`help push` and :hg:`help pull`). If a shared bookmark has |
|
900 | 900 | diverged, a new 'divergent bookmark' of the form 'name@path' will |
|
901 | 901 | be created. Using :hg:`merge` will resolve the divergence. |
|
902 | 902 | |
|
903 | 903 | A bookmark named '@' has the special property that :hg:`clone` will |
|
904 | 904 | check it out by default if it exists. |
|
905 | 905 | |
|
906 | 906 | .. container:: verbose |
|
907 | 907 | |
|
908 | 908 | Examples: |
|
909 | 909 | |
|
910 | 910 | - create an active bookmark for a new line of development:: |
|
911 | 911 | |
|
912 | 912 | hg book new-feature |
|
913 | 913 | |
|
914 | 914 | - create an inactive bookmark as a place marker:: |
|
915 | 915 | |
|
916 | 916 | hg book -i reviewed |
|
917 | 917 | |
|
918 | 918 | - create an inactive bookmark on another changeset:: |
|
919 | 919 | |
|
920 | 920 | hg book -r .^ tested |
|
921 | 921 | |
|
922 | 922 | - rename bookmark turkey to dinner:: |
|
923 | 923 | |
|
924 | 924 | hg book -m turkey dinner |
|
925 | 925 | |
|
926 | 926 | - move the '@' bookmark from another branch:: |
|
927 | 927 | |
|
928 | 928 | hg book -f @ |
|
929 | 929 | ''' |
|
930 | 930 | force = opts.get('force') |
|
931 | 931 | rev = opts.get('rev') |
|
932 | 932 | delete = opts.get('delete') |
|
933 | 933 | rename = opts.get('rename') |
|
934 | 934 | inactive = opts.get('inactive') |
|
935 | 935 | |
|
936 | 936 | def checkformat(mark): |
|
937 | 937 | mark = mark.strip() |
|
938 | 938 | if not mark: |
|
939 | 939 | raise util.Abort(_("bookmark names cannot consist entirely of " |
|
940 | 940 | "whitespace")) |
|
941 | 941 | scmutil.checknewlabel(repo, mark, 'bookmark') |
|
942 | 942 | return mark |
|
943 | 943 | |
|
944 | 944 | def checkconflict(repo, mark, cur, force=False, target=None): |
|
945 | 945 | if mark in marks and not force: |
|
946 | 946 | if target: |
|
947 | 947 | if marks[mark] == target and target == cur: |
|
948 | 948 | # re-activating a bookmark |
|
949 | 949 | return |
|
950 | 950 | anc = repo.changelog.ancestors([repo[target].rev()]) |
|
951 | 951 | bmctx = repo[marks[mark]] |
|
952 | 952 | divs = [repo[b].node() for b in marks |
|
953 | 953 | if b.split('@', 1)[0] == mark.split('@', 1)[0]] |
|
954 | 954 | |
|
955 | 955 | # allow resolving a single divergent bookmark even if moving |
|
956 | 956 | # the bookmark across branches when a revision is specified |
|
957 | 957 | # that contains a divergent bookmark |
|
958 | 958 | if bmctx.rev() not in anc and target in divs: |
|
959 | 959 | bookmarks.deletedivergent(repo, [target], mark) |
|
960 | 960 | return |
|
961 | 961 | |
|
962 | 962 | deletefrom = [b for b in divs |
|
963 | 963 | if repo[b].rev() in anc or b == target] |
|
964 | 964 | bookmarks.deletedivergent(repo, deletefrom, mark) |
|
965 | 965 | if bookmarks.validdest(repo, bmctx, repo[target]): |
|
966 | 966 | ui.status(_("moving bookmark '%s' forward from %s\n") % |
|
967 | 967 | (mark, short(bmctx.node()))) |
|
968 | 968 | return |
|
969 | 969 | raise util.Abort(_("bookmark '%s' already exists " |
|
970 | 970 | "(use -f to force)") % mark) |
|
971 | 971 | if ((mark in repo.branchmap() or mark == repo.dirstate.branch()) |
|
972 | 972 | and not force): |
|
973 | 973 | raise util.Abort( |
|
974 | 974 | _("a bookmark cannot have the name of an existing branch")) |
|
975 | 975 | |
|
976 | 976 | if delete and rename: |
|
977 | 977 | raise util.Abort(_("--delete and --rename are incompatible")) |
|
978 | 978 | if delete and rev: |
|
979 | 979 | raise util.Abort(_("--rev is incompatible with --delete")) |
|
980 | 980 | if rename and rev: |
|
981 | 981 | raise util.Abort(_("--rev is incompatible with --rename")) |
|
982 | 982 | if not names and (delete or rev): |
|
983 | 983 | raise util.Abort(_("bookmark name required")) |
|
984 | 984 | |
|
985 | 985 | if delete or rename or names or inactive: |
|
986 | 986 | wlock = lock = tr = None |
|
987 | 987 | try: |
|
988 | 988 | wlock = repo.wlock() |
|
989 | 989 | lock = repo.lock() |
|
990 | 990 | cur = repo.changectx('.').node() |
|
991 | 991 | marks = repo._bookmarks |
|
992 | 992 | if delete: |
|
993 | 993 | tr = repo.transaction('bookmark') |
|
994 | 994 | for mark in names: |
|
995 | 995 | if mark not in marks: |
|
996 | 996 | raise util.Abort(_("bookmark '%s' does not exist") % |
|
997 | 997 | mark) |
|
998 | 998 | if mark == repo._activebookmark: |
|
999 | 999 | bookmarks.deactivate(repo) |
|
1000 | 1000 | del marks[mark] |
|
1001 | 1001 | |
|
1002 | 1002 | elif rename: |
|
1003 | 1003 | tr = repo.transaction('bookmark') |
|
1004 | 1004 | if not names: |
|
1005 | 1005 | raise util.Abort(_("new bookmark name required")) |
|
1006 | 1006 | elif len(names) > 1: |
|
1007 | 1007 | raise util.Abort(_("only one new bookmark name allowed")) |
|
1008 | 1008 | mark = checkformat(names[0]) |
|
1009 | 1009 | if rename not in marks: |
|
1010 | 1010 | raise util.Abort(_("bookmark '%s' does not exist") % rename) |
|
1011 | 1011 | checkconflict(repo, mark, cur, force) |
|
1012 | 1012 | marks[mark] = marks[rename] |
|
1013 | 1013 | if repo._activebookmark == rename and not inactive: |
|
1014 | 1014 | bookmarks.activate(repo, mark) |
|
1015 | 1015 | del marks[rename] |
|
1016 | 1016 | elif names: |
|
1017 | 1017 | tr = repo.transaction('bookmark') |
|
1018 | 1018 | newact = None |
|
1019 | 1019 | for mark in names: |
|
1020 | 1020 | mark = checkformat(mark) |
|
1021 | 1021 | if newact is None: |
|
1022 | 1022 | newact = mark |
|
1023 | 1023 | if inactive and mark == repo._activebookmark: |
|
1024 | 1024 | bookmarks.deactivate(repo) |
|
1025 | 1025 | return |
|
1026 | 1026 | tgt = cur |
|
1027 | 1027 | if rev: |
|
1028 | 1028 | tgt = scmutil.revsingle(repo, rev).node() |
|
1029 | 1029 | checkconflict(repo, mark, cur, force, tgt) |
|
1030 | 1030 | marks[mark] = tgt |
|
1031 | 1031 | if not inactive and cur == marks[newact] and not rev: |
|
1032 | 1032 | bookmarks.activate(repo, newact) |
|
1033 | 1033 | elif cur != tgt and newact == repo._activebookmark: |
|
1034 | 1034 | bookmarks.deactivate(repo) |
|
1035 | 1035 | elif inactive: |
|
1036 | 1036 | if len(marks) == 0: |
|
1037 | 1037 | ui.status(_("no bookmarks set\n")) |
|
1038 | 1038 | elif not repo._activebookmark: |
|
1039 | 1039 | ui.status(_("no active bookmark\n")) |
|
1040 | 1040 | else: |
|
1041 | 1041 | bookmarks.deactivate(repo) |
|
1042 | 1042 | if tr is not None: |
|
1043 | 1043 | marks.recordchange(tr) |
|
1044 | 1044 | tr.close() |
|
1045 | 1045 | finally: |
|
1046 | 1046 | lockmod.release(tr, lock, wlock) |
|
1047 | 1047 | else: # show bookmarks |
|
1048 | 1048 | fm = ui.formatter('bookmarks', opts) |
|
1049 | 1049 | hexfn = fm.hexfunc |
|
1050 | 1050 | marks = repo._bookmarks |
|
1051 | 1051 | if len(marks) == 0 and not fm: |
|
1052 | 1052 | ui.status(_("no bookmarks set\n")) |
|
1053 | 1053 | for bmark, n in sorted(marks.iteritems()): |
|
1054 | 1054 | active = repo._activebookmark |
|
1055 | 1055 | if bmark == active: |
|
1056 | 1056 | prefix, label = '*', activebookmarklabel |
|
1057 | 1057 | else: |
|
1058 | 1058 | prefix, label = ' ', '' |
|
1059 | 1059 | |
|
1060 | 1060 | fm.startitem() |
|
1061 | 1061 | if not ui.quiet: |
|
1062 | 1062 | fm.plain(' %s ' % prefix, label=label) |
|
1063 | 1063 | fm.write('bookmark', '%s', bmark, label=label) |
|
1064 | 1064 | pad = " " * (25 - encoding.colwidth(bmark)) |
|
1065 | 1065 | fm.condwrite(not ui.quiet, 'rev node', pad + ' %d:%s', |
|
1066 | 1066 | repo.changelog.rev(n), hexfn(n), label=label) |
|
1067 | 1067 | fm.data(active=(bmark == active)) |
|
1068 | 1068 | fm.plain('\n') |
|
1069 | 1069 | fm.end() |
|
1070 | 1070 | |
|
1071 | 1071 | @command('branch', |
|
1072 | 1072 | [('f', 'force', None, |
|
1073 | 1073 | _('set branch name even if it shadows an existing branch')), |
|
1074 | 1074 | ('C', 'clean', None, _('reset branch name to parent branch name'))], |
|
1075 | 1075 | _('[-fC] [NAME]')) |
|
1076 | 1076 | def branch(ui, repo, label=None, **opts): |
|
1077 | 1077 | """set or show the current branch name |
|
1078 | 1078 | |
|
1079 | 1079 | .. note:: |
|
1080 | 1080 | |
|
1081 | 1081 | Branch names are permanent and global. Use :hg:`bookmark` to create a |
|
1082 | 1082 | light-weight bookmark instead. See :hg:`help glossary` for more |
|
1083 | 1083 | information about named branches and bookmarks. |
|
1084 | 1084 | |
|
1085 | 1085 | With no argument, show the current branch name. With one argument, |
|
1086 | 1086 | set the working directory branch name (the branch will not exist |
|
1087 | 1087 | in the repository until the next commit). Standard practice |
|
1088 | 1088 | recommends that primary development take place on the 'default' |
|
1089 | 1089 | branch. |
|
1090 | 1090 | |
|
1091 | 1091 | Unless -f/--force is specified, branch will not let you set a |
|
1092 | 1092 | branch name that already exists. |
|
1093 | 1093 | |
|
1094 | 1094 | Use -C/--clean to reset the working directory branch to that of |
|
1095 | 1095 | the parent of the working directory, negating a previous branch |
|
1096 | 1096 | change. |
|
1097 | 1097 | |
|
1098 | 1098 | Use the command :hg:`update` to switch to an existing branch. Use |
|
1099 | 1099 | :hg:`commit --close-branch` to mark this branch head as closed. |
|
1100 | 1100 | When all heads of the branch are closed, the branch will be |
|
1101 | 1101 | considered closed. |
|
1102 | 1102 | |
|
1103 | 1103 | Returns 0 on success. |
|
1104 | 1104 | """ |
|
1105 | 1105 | if label: |
|
1106 | 1106 | label = label.strip() |
|
1107 | 1107 | |
|
1108 | 1108 | if not opts.get('clean') and not label: |
|
1109 | 1109 | ui.write("%s\n" % repo.dirstate.branch()) |
|
1110 | 1110 | return |
|
1111 | 1111 | |
|
1112 | 1112 | wlock = repo.wlock() |
|
1113 | 1113 | try: |
|
1114 | 1114 | if opts.get('clean'): |
|
1115 | 1115 | label = repo[None].p1().branch() |
|
1116 | 1116 | repo.dirstate.setbranch(label) |
|
1117 | 1117 | ui.status(_('reset working directory to branch %s\n') % label) |
|
1118 | 1118 | elif label: |
|
1119 | 1119 | if not opts.get('force') and label in repo.branchmap(): |
|
1120 | 1120 | if label not in [p.branch() for p in repo.parents()]: |
|
1121 | 1121 | raise util.Abort(_('a branch of the same name already' |
|
1122 | 1122 | ' exists'), |
|
1123 | 1123 | # i18n: "it" refers to an existing branch |
|
1124 | 1124 | hint=_("use 'hg update' to switch to it")) |
|
1125 | 1125 | scmutil.checknewlabel(repo, label, 'branch') |
|
1126 | 1126 | repo.dirstate.setbranch(label) |
|
1127 | 1127 | ui.status(_('marked working directory as branch %s\n') % label) |
|
1128 | 1128 | |
|
1129 | 1129 | # find any open named branches aside from default |
|
1130 | 1130 | others = [n for n, h, t, c in repo.branchmap().iterbranches() |
|
1131 | 1131 | if n != "default" and not c] |
|
1132 | 1132 | if not others: |
|
1133 | 1133 | ui.status(_('(branches are permanent and global, ' |
|
1134 | 1134 | 'did you want a bookmark?)\n')) |
|
1135 | 1135 | finally: |
|
1136 | 1136 | wlock.release() |
|
1137 | 1137 | |
|
1138 | 1138 | @command('branches', |
|
1139 | 1139 | [('a', 'active', False, |
|
1140 | 1140 | _('show only branches that have unmerged heads (DEPRECATED)')), |
|
1141 | 1141 | ('c', 'closed', False, _('show normal and closed branches')), |
|
1142 | 1142 | ] + formatteropts, |
|
1143 | 1143 | _('[-ac]')) |
|
1144 | 1144 | def branches(ui, repo, active=False, closed=False, **opts): |
|
1145 | 1145 | """list repository named branches |
|
1146 | 1146 | |
|
1147 | 1147 | List the repository's named branches, indicating which ones are |
|
1148 | 1148 | inactive. If -c/--closed is specified, also list branches which have |
|
1149 | 1149 | been marked closed (see :hg:`commit --close-branch`). |
|
1150 | 1150 | |
|
1151 | 1151 | Use the command :hg:`update` to switch to an existing branch. |
|
1152 | 1152 | |
|
1153 | 1153 | Returns 0. |
|
1154 | 1154 | """ |
|
1155 | 1155 | |
|
1156 | 1156 | fm = ui.formatter('branches', opts) |
|
1157 | 1157 | hexfunc = fm.hexfunc |
|
1158 | 1158 | |
|
1159 | 1159 | allheads = set(repo.heads()) |
|
1160 | 1160 | branches = [] |
|
1161 | 1161 | for tag, heads, tip, isclosed in repo.branchmap().iterbranches(): |
|
1162 | 1162 | isactive = not isclosed and bool(set(heads) & allheads) |
|
1163 | 1163 | branches.append((tag, repo[tip], isactive, not isclosed)) |
|
1164 | 1164 | branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]), |
|
1165 | 1165 | reverse=True) |
|
1166 | 1166 | |
|
1167 | 1167 | for tag, ctx, isactive, isopen in branches: |
|
1168 | 1168 | if active and not isactive: |
|
1169 | 1169 | continue |
|
1170 | 1170 | if isactive: |
|
1171 | 1171 | label = 'branches.active' |
|
1172 | 1172 | notice = '' |
|
1173 | 1173 | elif not isopen: |
|
1174 | 1174 | if not closed: |
|
1175 | 1175 | continue |
|
1176 | 1176 | label = 'branches.closed' |
|
1177 | 1177 | notice = _(' (closed)') |
|
1178 | 1178 | else: |
|
1179 | 1179 | label = 'branches.inactive' |
|
1180 | 1180 | notice = _(' (inactive)') |
|
1181 | 1181 | current = (tag == repo.dirstate.branch()) |
|
1182 | 1182 | if current: |
|
1183 | 1183 | label = 'branches.current' |
|
1184 | 1184 | |
|
1185 | 1185 | fm.startitem() |
|
1186 | 1186 | fm.write('branch', '%s', tag, label=label) |
|
1187 | 1187 | rev = ctx.rev() |
|
1188 | 1188 | padsize = max(31 - len(str(rev)) - encoding.colwidth(tag), 0) |
|
1189 | 1189 | fmt = ' ' * padsize + ' %d:%s' |
|
1190 | 1190 | fm.condwrite(not ui.quiet, 'rev node', fmt, rev, hexfunc(ctx.node()), |
|
1191 | 1191 | label='log.changeset changeset.%s' % ctx.phasestr()) |
|
1192 | 1192 | fm.data(active=isactive, closed=not isopen, current=current) |
|
1193 | 1193 | if not ui.quiet: |
|
1194 | 1194 | fm.plain(notice) |
|
1195 | 1195 | fm.plain('\n') |
|
1196 | 1196 | fm.end() |
|
1197 | 1197 | |
|
1198 | 1198 | @command('bundle', |
|
1199 | 1199 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
1200 | 1200 | ('r', 'rev', [], _('a changeset intended to be added to the destination'), |
|
1201 | 1201 | _('REV')), |
|
1202 | 1202 | ('b', 'branch', [], _('a specific branch you would like to bundle'), |
|
1203 | 1203 | _('BRANCH')), |
|
1204 | 1204 | ('', 'base', [], |
|
1205 | 1205 | _('a base changeset assumed to be available at the destination'), |
|
1206 | 1206 | _('REV')), |
|
1207 | 1207 | ('a', 'all', None, _('bundle all changesets in the repository')), |
|
1208 | 1208 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE')), |
|
1209 | 1209 | ] + remoteopts, |
|
1210 | 1210 | _('[-f] [-t TYPE] [-a] [-r REV]... [--base REV]... FILE [DEST]')) |
|
1211 | 1211 | def bundle(ui, repo, fname, dest=None, **opts): |
|
1212 | 1212 | """create a changegroup file |
|
1213 | 1213 | |
|
1214 | 1214 | Generate a compressed changegroup file collecting changesets not |
|
1215 | 1215 | known to be in another repository. |
|
1216 | 1216 | |
|
1217 | 1217 | If you omit the destination repository, then hg assumes the |
|
1218 | 1218 | destination will have all the nodes you specify with --base |
|
1219 | 1219 | parameters. To create a bundle containing all changesets, use |
|
1220 | 1220 | -a/--all (or --base null). |
|
1221 | 1221 | |
|
1222 |
You can change |
|
|
1223 | The available compression methods are: none, bzip2, and | |
|
1224 | gzip (by default, bundles are compressed using bzip2). | |
|
1222 | You can change bundle format with the -t/--type option. You can | |
|
1223 | specify a compression, a bundle version or both using a dash | |
|
1224 | (comp-version). The available compression methods are: none, bzip2, | |
|
1225 | and gzip (by default, bundles are compressed using bzip2). The | |
|
1226 | available format are: v1, v2 (default to v1). | |
|
1225 | 1227 | |
|
1226 | 1228 | The bundle file can then be transferred using conventional means |
|
1227 | 1229 | and applied to another repository with the unbundle or pull |
|
1228 | 1230 | command. This is useful when direct push and pull are not |
|
1229 | 1231 | available or when exporting an entire repository is undesirable. |
|
1230 | 1232 | |
|
1231 | 1233 | Applying bundles preserves all changeset contents including |
|
1232 | 1234 | permissions, copy/rename information, and revision history. |
|
1233 | 1235 | |
|
1234 | 1236 | Returns 0 on success, 1 if no changes found. |
|
1235 | 1237 | """ |
|
1236 | 1238 | revs = None |
|
1237 | 1239 | if 'rev' in opts: |
|
1238 | 1240 | revs = scmutil.revrange(repo, opts['rev']) |
|
1239 | 1241 | |
|
1240 | 1242 | bundletype = opts.get('type', 'bzip2').lower() |
|
1241 |
|
|
|
1243 | cgversion, bcompression = cmdutil.parsebundletype(repo, bundletype) | |
|
1242 | 1244 | |
|
1243 | 1245 | if opts.get('all'): |
|
1244 | 1246 | base = ['null'] |
|
1245 | 1247 | else: |
|
1246 | 1248 | base = scmutil.revrange(repo, opts.get('base')) |
|
1247 | 1249 | # TODO: get desired bundlecaps from command line. |
|
1248 | 1250 | bundlecaps = None |
|
1249 | 1251 | if base: |
|
1250 | 1252 | if dest: |
|
1251 | 1253 | raise util.Abort(_("--base is incompatible with specifying " |
|
1252 | 1254 | "a destination")) |
|
1253 | 1255 | common = [repo.lookup(rev) for rev in base] |
|
1254 | 1256 | heads = revs and map(repo.lookup, revs) or revs |
|
1255 | 1257 | cg = changegroup.getchangegroup(repo, 'bundle', heads=heads, |
|
1256 |
common=common, bundlecaps=bundlecaps |
|
|
1258 | common=common, bundlecaps=bundlecaps, | |
|
1259 | version=cgversion) | |
|
1257 | 1260 | outgoing = None |
|
1258 | 1261 | else: |
|
1259 | 1262 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
1260 | 1263 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
1261 | 1264 | other = hg.peer(repo, opts, dest) |
|
1262 | 1265 | revs, checkout = hg.addbranchrevs(repo, repo, branches, revs) |
|
1263 | 1266 | heads = revs and map(repo.lookup, revs) or revs |
|
1264 | 1267 | outgoing = discovery.findcommonoutgoing(repo, other, |
|
1265 | 1268 | onlyheads=heads, |
|
1266 | 1269 | force=opts.get('force'), |
|
1267 | 1270 | portable=True) |
|
1268 | 1271 | cg = changegroup.getlocalchangegroup(repo, 'bundle', outgoing, |
|
1269 | bundlecaps) | |
|
1272 | bundlecaps, version=cgversion) | |
|
1270 | 1273 | if not cg: |
|
1271 | 1274 | scmutil.nochangesfound(ui, repo, outgoing and outgoing.excluded) |
|
1272 | 1275 | return 1 |
|
1273 | 1276 | |
|
1274 | changegroup.writebundle(ui, cg, fname, bundletype) | |
|
1277 | if cgversion == '01': #bundle1 | |
|
1278 | if bcompression is None: | |
|
1279 | bcompression = 'UN' | |
|
1280 | bversion = 'HG10' + bcompression | |
|
1281 | bcompression = None | |
|
1282 | else: | |
|
1283 | assert cgversion == '02' | |
|
1284 | bversion = 'HG20' | |
|
1285 | ||
|
1286 | ||
|
1287 | changegroup.writebundle(ui, cg, fname, bversion, compression=bcompression) | |
|
1275 | 1288 | |
|
1276 | 1289 | @command('cat', |
|
1277 | 1290 | [('o', 'output', '', |
|
1278 | 1291 | _('print output to file with formatted name'), _('FORMAT')), |
|
1279 | 1292 | ('r', 'rev', '', _('print the given revision'), _('REV')), |
|
1280 | 1293 | ('', 'decode', None, _('apply any matching decode filter')), |
|
1281 | 1294 | ] + walkopts, |
|
1282 | 1295 | _('[OPTION]... FILE...'), |
|
1283 | 1296 | inferrepo=True) |
|
1284 | 1297 | def cat(ui, repo, file1, *pats, **opts): |
|
1285 | 1298 | """output the current or given revision of files |
|
1286 | 1299 | |
|
1287 | 1300 | Print the specified files as they were at the given revision. If |
|
1288 | 1301 | no revision is given, the parent of the working directory is used. |
|
1289 | 1302 | |
|
1290 | 1303 | Output may be to a file, in which case the name of the file is |
|
1291 | 1304 | given using a format string. The formatting rules as follows: |
|
1292 | 1305 | |
|
1293 | 1306 | :``%%``: literal "%" character |
|
1294 | 1307 | :``%s``: basename of file being printed |
|
1295 | 1308 | :``%d``: dirname of file being printed, or '.' if in repository root |
|
1296 | 1309 | :``%p``: root-relative path name of file being printed |
|
1297 | 1310 | :``%H``: changeset hash (40 hexadecimal digits) |
|
1298 | 1311 | :``%R``: changeset revision number |
|
1299 | 1312 | :``%h``: short-form changeset hash (12 hexadecimal digits) |
|
1300 | 1313 | :``%r``: zero-padded changeset revision number |
|
1301 | 1314 | :``%b``: basename of the exporting repository |
|
1302 | 1315 | |
|
1303 | 1316 | Returns 0 on success. |
|
1304 | 1317 | """ |
|
1305 | 1318 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
1306 | 1319 | m = scmutil.match(ctx, (file1,) + pats, opts) |
|
1307 | 1320 | |
|
1308 | 1321 | return cmdutil.cat(ui, repo, ctx, m, '', **opts) |
|
1309 | 1322 | |
|
1310 | 1323 | @command('^clone', |
|
1311 | 1324 | [('U', 'noupdate', None, _('the clone will include an empty working ' |
|
1312 | 1325 | 'directory (only a repository)')), |
|
1313 | 1326 | ('u', 'updaterev', '', _('revision, tag or branch to check out'), _('REV')), |
|
1314 | 1327 | ('r', 'rev', [], _('include the specified changeset'), _('REV')), |
|
1315 | 1328 | ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')), |
|
1316 | 1329 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
1317 | 1330 | ('', 'uncompressed', None, _('use uncompressed transfer (fast over LAN)')), |
|
1318 | 1331 | ] + remoteopts, |
|
1319 | 1332 | _('[OPTION]... SOURCE [DEST]'), |
|
1320 | 1333 | norepo=True) |
|
1321 | 1334 | def clone(ui, source, dest=None, **opts): |
|
1322 | 1335 | """make a copy of an existing repository |
|
1323 | 1336 | |
|
1324 | 1337 | Create a copy of an existing repository in a new directory. |
|
1325 | 1338 | |
|
1326 | 1339 | If no destination directory name is specified, it defaults to the |
|
1327 | 1340 | basename of the source. |
|
1328 | 1341 | |
|
1329 | 1342 | The location of the source is added to the new repository's |
|
1330 | 1343 | ``.hg/hgrc`` file, as the default to be used for future pulls. |
|
1331 | 1344 | |
|
1332 | 1345 | Only local paths and ``ssh://`` URLs are supported as |
|
1333 | 1346 | destinations. For ``ssh://`` destinations, no working directory or |
|
1334 | 1347 | ``.hg/hgrc`` will be created on the remote side. |
|
1335 | 1348 | |
|
1336 | 1349 | To pull only a subset of changesets, specify one or more revisions |
|
1337 | 1350 | identifiers with -r/--rev or branches with -b/--branch. The |
|
1338 | 1351 | resulting clone will contain only the specified changesets and |
|
1339 | 1352 | their ancestors. These options (or 'clone src#rev dest') imply |
|
1340 | 1353 | --pull, even for local source repositories. Note that specifying a |
|
1341 | 1354 | tag will include the tagged changeset but not the changeset |
|
1342 | 1355 | containing the tag. |
|
1343 | 1356 | |
|
1344 | 1357 | If the source repository has a bookmark called '@' set, that |
|
1345 | 1358 | revision will be checked out in the new repository by default. |
|
1346 | 1359 | |
|
1347 | 1360 | To check out a particular version, use -u/--update, or |
|
1348 | 1361 | -U/--noupdate to create a clone with no working directory. |
|
1349 | 1362 | |
|
1350 | 1363 | .. container:: verbose |
|
1351 | 1364 | |
|
1352 | 1365 | For efficiency, hardlinks are used for cloning whenever the |
|
1353 | 1366 | source and destination are on the same filesystem (note this |
|
1354 | 1367 | applies only to the repository data, not to the working |
|
1355 | 1368 | directory). Some filesystems, such as AFS, implement hardlinking |
|
1356 | 1369 | incorrectly, but do not report errors. In these cases, use the |
|
1357 | 1370 | --pull option to avoid hardlinking. |
|
1358 | 1371 | |
|
1359 | 1372 | In some cases, you can clone repositories and the working |
|
1360 | 1373 | directory using full hardlinks with :: |
|
1361 | 1374 | |
|
1362 | 1375 | $ cp -al REPO REPOCLONE |
|
1363 | 1376 | |
|
1364 | 1377 | This is the fastest way to clone, but it is not always safe. The |
|
1365 | 1378 | operation is not atomic (making sure REPO is not modified during |
|
1366 | 1379 | the operation is up to you) and you have to make sure your |
|
1367 | 1380 | editor breaks hardlinks (Emacs and most Linux Kernel tools do |
|
1368 | 1381 | so). Also, this is not compatible with certain extensions that |
|
1369 | 1382 | place their metadata under the .hg directory, such as mq. |
|
1370 | 1383 | |
|
1371 | 1384 | Mercurial will update the working directory to the first applicable |
|
1372 | 1385 | revision from this list: |
|
1373 | 1386 | |
|
1374 | 1387 | a) null if -U or the source repository has no changesets |
|
1375 | 1388 | b) if -u . and the source repository is local, the first parent of |
|
1376 | 1389 | the source repository's working directory |
|
1377 | 1390 | c) the changeset specified with -u (if a branch name, this means the |
|
1378 | 1391 | latest head of that branch) |
|
1379 | 1392 | d) the changeset specified with -r |
|
1380 | 1393 | e) the tipmost head specified with -b |
|
1381 | 1394 | f) the tipmost head specified with the url#branch source syntax |
|
1382 | 1395 | g) the revision marked with the '@' bookmark, if present |
|
1383 | 1396 | h) the tipmost head of the default branch |
|
1384 | 1397 | i) tip |
|
1385 | 1398 | |
|
1386 | 1399 | Examples: |
|
1387 | 1400 | |
|
1388 | 1401 | - clone a remote repository to a new directory named hg/:: |
|
1389 | 1402 | |
|
1390 | 1403 | hg clone http://selenic.com/hg |
|
1391 | 1404 | |
|
1392 | 1405 | - create a lightweight local clone:: |
|
1393 | 1406 | |
|
1394 | 1407 | hg clone project/ project-feature/ |
|
1395 | 1408 | |
|
1396 | 1409 | - clone from an absolute path on an ssh server (note double-slash):: |
|
1397 | 1410 | |
|
1398 | 1411 | hg clone ssh://user@server//home/projects/alpha/ |
|
1399 | 1412 | |
|
1400 | 1413 | - do a high-speed clone over a LAN while checking out a |
|
1401 | 1414 | specified version:: |
|
1402 | 1415 | |
|
1403 | 1416 | hg clone --uncompressed http://server/repo -u 1.5 |
|
1404 | 1417 | |
|
1405 | 1418 | - create a repository without changesets after a particular revision:: |
|
1406 | 1419 | |
|
1407 | 1420 | hg clone -r 04e544 experimental/ good/ |
|
1408 | 1421 | |
|
1409 | 1422 | - clone (and track) a particular named branch:: |
|
1410 | 1423 | |
|
1411 | 1424 | hg clone http://selenic.com/hg#stable |
|
1412 | 1425 | |
|
1413 | 1426 | See :hg:`help urls` for details on specifying URLs. |
|
1414 | 1427 | |
|
1415 | 1428 | Returns 0 on success. |
|
1416 | 1429 | """ |
|
1417 | 1430 | if opts.get('noupdate') and opts.get('updaterev'): |
|
1418 | 1431 | raise util.Abort(_("cannot specify both --noupdate and --updaterev")) |
|
1419 | 1432 | |
|
1420 | 1433 | r = hg.clone(ui, opts, source, dest, |
|
1421 | 1434 | pull=opts.get('pull'), |
|
1422 | 1435 | stream=opts.get('uncompressed'), |
|
1423 | 1436 | rev=opts.get('rev'), |
|
1424 | 1437 | update=opts.get('updaterev') or not opts.get('noupdate'), |
|
1425 | 1438 | branch=opts.get('branch'), |
|
1426 | 1439 | shareopts=opts.get('shareopts')) |
|
1427 | 1440 | |
|
1428 | 1441 | return r is None |
|
1429 | 1442 | |
|
1430 | 1443 | @command('^commit|ci', |
|
1431 | 1444 | [('A', 'addremove', None, |
|
1432 | 1445 | _('mark new/missing files as added/removed before committing')), |
|
1433 | 1446 | ('', 'close-branch', None, |
|
1434 | 1447 | _('mark a branch head as closed')), |
|
1435 | 1448 | ('', 'amend', None, _('amend the parent of the working directory')), |
|
1436 | 1449 | ('s', 'secret', None, _('use the secret phase for committing')), |
|
1437 | 1450 | ('e', 'edit', None, _('invoke editor on commit messages')), |
|
1438 | 1451 | ('i', 'interactive', None, _('use interactive mode')), |
|
1439 | 1452 | ] + walkopts + commitopts + commitopts2 + subrepoopts, |
|
1440 | 1453 | _('[OPTION]... [FILE]...'), |
|
1441 | 1454 | inferrepo=True) |
|
1442 | 1455 | def commit(ui, repo, *pats, **opts): |
|
1443 | 1456 | """commit the specified files or all outstanding changes |
|
1444 | 1457 | |
|
1445 | 1458 | Commit changes to the given files into the repository. Unlike a |
|
1446 | 1459 | centralized SCM, this operation is a local operation. See |
|
1447 | 1460 | :hg:`push` for a way to actively distribute your changes. |
|
1448 | 1461 | |
|
1449 | 1462 | If a list of files is omitted, all changes reported by :hg:`status` |
|
1450 | 1463 | will be committed. |
|
1451 | 1464 | |
|
1452 | 1465 | If you are committing the result of a merge, do not provide any |
|
1453 | 1466 | filenames or -I/-X filters. |
|
1454 | 1467 | |
|
1455 | 1468 | If no commit message is specified, Mercurial starts your |
|
1456 | 1469 | configured editor where you can enter a message. In case your |
|
1457 | 1470 | commit fails, you will find a backup of your message in |
|
1458 | 1471 | ``.hg/last-message.txt``. |
|
1459 | 1472 | |
|
1460 | 1473 | The --close-branch flag can be used to mark the current branch |
|
1461 | 1474 | head closed. When all heads of a branch are closed, the branch |
|
1462 | 1475 | will be considered closed and no longer listed. |
|
1463 | 1476 | |
|
1464 | 1477 | The --amend flag can be used to amend the parent of the |
|
1465 | 1478 | working directory with a new commit that contains the changes |
|
1466 | 1479 | in the parent in addition to those currently reported by :hg:`status`, |
|
1467 | 1480 | if there are any. The old commit is stored in a backup bundle in |
|
1468 | 1481 | ``.hg/strip-backup`` (see :hg:`help bundle` and :hg:`help unbundle` |
|
1469 | 1482 | on how to restore it). |
|
1470 | 1483 | |
|
1471 | 1484 | Message, user and date are taken from the amended commit unless |
|
1472 | 1485 | specified. When a message isn't specified on the command line, |
|
1473 | 1486 | the editor will open with the message of the amended commit. |
|
1474 | 1487 | |
|
1475 | 1488 | It is not possible to amend public changesets (see :hg:`help phases`) |
|
1476 | 1489 | or changesets that have children. |
|
1477 | 1490 | |
|
1478 | 1491 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
1479 | 1492 | |
|
1480 | 1493 | Returns 0 on success, 1 if nothing changed. |
|
1481 | 1494 | """ |
|
1482 | 1495 | if opts.get('interactive'): |
|
1483 | 1496 | opts.pop('interactive') |
|
1484 | 1497 | cmdutil.dorecord(ui, repo, commit, None, False, |
|
1485 | 1498 | cmdutil.recordfilter, *pats, **opts) |
|
1486 | 1499 | return |
|
1487 | 1500 | |
|
1488 | 1501 | if opts.get('subrepos'): |
|
1489 | 1502 | if opts.get('amend'): |
|
1490 | 1503 | raise util.Abort(_('cannot amend with --subrepos')) |
|
1491 | 1504 | # Let --subrepos on the command line override config setting. |
|
1492 | 1505 | ui.setconfig('ui', 'commitsubrepos', True, 'commit') |
|
1493 | 1506 | |
|
1494 | 1507 | cmdutil.checkunfinished(repo, commit=True) |
|
1495 | 1508 | |
|
1496 | 1509 | branch = repo[None].branch() |
|
1497 | 1510 | bheads = repo.branchheads(branch) |
|
1498 | 1511 | |
|
1499 | 1512 | extra = {} |
|
1500 | 1513 | if opts.get('close_branch'): |
|
1501 | 1514 | extra['close'] = 1 |
|
1502 | 1515 | |
|
1503 | 1516 | if not bheads: |
|
1504 | 1517 | raise util.Abort(_('can only close branch heads')) |
|
1505 | 1518 | elif opts.get('amend'): |
|
1506 | 1519 | if repo.parents()[0].p1().branch() != branch and \ |
|
1507 | 1520 | repo.parents()[0].p2().branch() != branch: |
|
1508 | 1521 | raise util.Abort(_('can only close branch heads')) |
|
1509 | 1522 | |
|
1510 | 1523 | if opts.get('amend'): |
|
1511 | 1524 | if ui.configbool('ui', 'commitsubrepos'): |
|
1512 | 1525 | raise util.Abort(_('cannot amend with ui.commitsubrepos enabled')) |
|
1513 | 1526 | |
|
1514 | 1527 | old = repo['.'] |
|
1515 | 1528 | if not old.mutable(): |
|
1516 | 1529 | raise util.Abort(_('cannot amend public changesets')) |
|
1517 | 1530 | if len(repo[None].parents()) > 1: |
|
1518 | 1531 | raise util.Abort(_('cannot amend while merging')) |
|
1519 | 1532 | allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt) |
|
1520 | 1533 | if not allowunstable and old.children(): |
|
1521 | 1534 | raise util.Abort(_('cannot amend changeset with children')) |
|
1522 | 1535 | |
|
1523 | 1536 | # commitfunc is used only for temporary amend commit by cmdutil.amend |
|
1524 | 1537 | def commitfunc(ui, repo, message, match, opts): |
|
1525 | 1538 | return repo.commit(message, |
|
1526 | 1539 | opts.get('user') or old.user(), |
|
1527 | 1540 | opts.get('date') or old.date(), |
|
1528 | 1541 | match, |
|
1529 | 1542 | extra=extra) |
|
1530 | 1543 | |
|
1531 | 1544 | node = cmdutil.amend(ui, repo, commitfunc, old, extra, pats, opts) |
|
1532 | 1545 | if node == old.node(): |
|
1533 | 1546 | ui.status(_("nothing changed\n")) |
|
1534 | 1547 | return 1 |
|
1535 | 1548 | else: |
|
1536 | 1549 | def commitfunc(ui, repo, message, match, opts): |
|
1537 | 1550 | backup = ui.backupconfig('phases', 'new-commit') |
|
1538 | 1551 | baseui = repo.baseui |
|
1539 | 1552 | basebackup = baseui.backupconfig('phases', 'new-commit') |
|
1540 | 1553 | try: |
|
1541 | 1554 | if opts.get('secret'): |
|
1542 | 1555 | ui.setconfig('phases', 'new-commit', 'secret', 'commit') |
|
1543 | 1556 | # Propagate to subrepos |
|
1544 | 1557 | baseui.setconfig('phases', 'new-commit', 'secret', 'commit') |
|
1545 | 1558 | |
|
1546 | 1559 | editform = cmdutil.mergeeditform(repo[None], 'commit.normal') |
|
1547 | 1560 | editor = cmdutil.getcommiteditor(editform=editform, **opts) |
|
1548 | 1561 | return repo.commit(message, opts.get('user'), opts.get('date'), |
|
1549 | 1562 | match, |
|
1550 | 1563 | editor=editor, |
|
1551 | 1564 | extra=extra) |
|
1552 | 1565 | finally: |
|
1553 | 1566 | ui.restoreconfig(backup) |
|
1554 | 1567 | repo.baseui.restoreconfig(basebackup) |
|
1555 | 1568 | |
|
1556 | 1569 | |
|
1557 | 1570 | node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
|
1558 | 1571 | |
|
1559 | 1572 | if not node: |
|
1560 | 1573 | stat = repo.status(match=scmutil.match(repo[None], pats, opts)) |
|
1561 | 1574 | if stat[3]: |
|
1562 | 1575 | ui.status(_("nothing changed (%d missing files, see " |
|
1563 | 1576 | "'hg status')\n") % len(stat[3])) |
|
1564 | 1577 | else: |
|
1565 | 1578 | ui.status(_("nothing changed\n")) |
|
1566 | 1579 | return 1 |
|
1567 | 1580 | |
|
1568 | 1581 | cmdutil.commitstatus(repo, node, branch, bheads, opts) |
|
1569 | 1582 | |
|
1570 | 1583 | @command('config|showconfig|debugconfig', |
|
1571 | 1584 | [('u', 'untrusted', None, _('show untrusted configuration options')), |
|
1572 | 1585 | ('e', 'edit', None, _('edit user config')), |
|
1573 | 1586 | ('l', 'local', None, _('edit repository config')), |
|
1574 | 1587 | ('g', 'global', None, _('edit global config'))], |
|
1575 | 1588 | _('[-u] [NAME]...'), |
|
1576 | 1589 | optionalrepo=True) |
|
1577 | 1590 | def config(ui, repo, *values, **opts): |
|
1578 | 1591 | """show combined config settings from all hgrc files |
|
1579 | 1592 | |
|
1580 | 1593 | With no arguments, print names and values of all config items. |
|
1581 | 1594 | |
|
1582 | 1595 | With one argument of the form section.name, print just the value |
|
1583 | 1596 | of that config item. |
|
1584 | 1597 | |
|
1585 | 1598 | With multiple arguments, print names and values of all config |
|
1586 | 1599 | items with matching section names. |
|
1587 | 1600 | |
|
1588 | 1601 | With --edit, start an editor on the user-level config file. With |
|
1589 | 1602 | --global, edit the system-wide config file. With --local, edit the |
|
1590 | 1603 | repository-level config file. |
|
1591 | 1604 | |
|
1592 | 1605 | With --debug, the source (filename and line number) is printed |
|
1593 | 1606 | for each config item. |
|
1594 | 1607 | |
|
1595 | 1608 | See :hg:`help config` for more information about config files. |
|
1596 | 1609 | |
|
1597 | 1610 | Returns 0 on success, 1 if NAME does not exist. |
|
1598 | 1611 | |
|
1599 | 1612 | """ |
|
1600 | 1613 | |
|
1601 | 1614 | if opts.get('edit') or opts.get('local') or opts.get('global'): |
|
1602 | 1615 | if opts.get('local') and opts.get('global'): |
|
1603 | 1616 | raise util.Abort(_("can't use --local and --global together")) |
|
1604 | 1617 | |
|
1605 | 1618 | if opts.get('local'): |
|
1606 | 1619 | if not repo: |
|
1607 | 1620 | raise util.Abort(_("can't use --local outside a repository")) |
|
1608 | 1621 | paths = [repo.join('hgrc')] |
|
1609 | 1622 | elif opts.get('global'): |
|
1610 | 1623 | paths = scmutil.systemrcpath() |
|
1611 | 1624 | else: |
|
1612 | 1625 | paths = scmutil.userrcpath() |
|
1613 | 1626 | |
|
1614 | 1627 | for f in paths: |
|
1615 | 1628 | if os.path.exists(f): |
|
1616 | 1629 | break |
|
1617 | 1630 | else: |
|
1618 | 1631 | if opts.get('global'): |
|
1619 | 1632 | samplehgrc = uimod.samplehgrcs['global'] |
|
1620 | 1633 | elif opts.get('local'): |
|
1621 | 1634 | samplehgrc = uimod.samplehgrcs['local'] |
|
1622 | 1635 | else: |
|
1623 | 1636 | samplehgrc = uimod.samplehgrcs['user'] |
|
1624 | 1637 | |
|
1625 | 1638 | f = paths[0] |
|
1626 | 1639 | fp = open(f, "w") |
|
1627 | 1640 | fp.write(samplehgrc) |
|
1628 | 1641 | fp.close() |
|
1629 | 1642 | |
|
1630 | 1643 | editor = ui.geteditor() |
|
1631 | 1644 | ui.system("%s \"%s\"" % (editor, f), |
|
1632 | 1645 | onerr=util.Abort, errprefix=_("edit failed")) |
|
1633 | 1646 | return |
|
1634 | 1647 | |
|
1635 | 1648 | for f in scmutil.rcpath(): |
|
1636 | 1649 | ui.debug('read config from: %s\n' % f) |
|
1637 | 1650 | untrusted = bool(opts.get('untrusted')) |
|
1638 | 1651 | if values: |
|
1639 | 1652 | sections = [v for v in values if '.' not in v] |
|
1640 | 1653 | items = [v for v in values if '.' in v] |
|
1641 | 1654 | if len(items) > 1 or items and sections: |
|
1642 | 1655 | raise util.Abort(_('only one config item permitted')) |
|
1643 | 1656 | matched = False |
|
1644 | 1657 | for section, name, value in ui.walkconfig(untrusted=untrusted): |
|
1645 | 1658 | value = str(value).replace('\n', '\\n') |
|
1646 | 1659 | sectname = section + '.' + name |
|
1647 | 1660 | if values: |
|
1648 | 1661 | for v in values: |
|
1649 | 1662 | if v == section: |
|
1650 | 1663 | ui.debug('%s: ' % |
|
1651 | 1664 | ui.configsource(section, name, untrusted)) |
|
1652 | 1665 | ui.write('%s=%s\n' % (sectname, value)) |
|
1653 | 1666 | matched = True |
|
1654 | 1667 | elif v == sectname: |
|
1655 | 1668 | ui.debug('%s: ' % |
|
1656 | 1669 | ui.configsource(section, name, untrusted)) |
|
1657 | 1670 | ui.write(value, '\n') |
|
1658 | 1671 | matched = True |
|
1659 | 1672 | else: |
|
1660 | 1673 | ui.debug('%s: ' % |
|
1661 | 1674 | ui.configsource(section, name, untrusted)) |
|
1662 | 1675 | ui.write('%s=%s\n' % (sectname, value)) |
|
1663 | 1676 | matched = True |
|
1664 | 1677 | if matched: |
|
1665 | 1678 | return 0 |
|
1666 | 1679 | return 1 |
|
1667 | 1680 | |
|
1668 | 1681 | @command('copy|cp', |
|
1669 | 1682 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
1670 | 1683 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
1671 | 1684 | ] + walkopts + dryrunopts, |
|
1672 | 1685 | _('[OPTION]... [SOURCE]... DEST')) |
|
1673 | 1686 | def copy(ui, repo, *pats, **opts): |
|
1674 | 1687 | """mark files as copied for the next commit |
|
1675 | 1688 | |
|
1676 | 1689 | Mark dest as having copies of source files. If dest is a |
|
1677 | 1690 | directory, copies are put in that directory. If dest is a file, |
|
1678 | 1691 | the source must be a single file. |
|
1679 | 1692 | |
|
1680 | 1693 | By default, this command copies the contents of files as they |
|
1681 | 1694 | exist in the working directory. If invoked with -A/--after, the |
|
1682 | 1695 | operation is recorded, but no copying is performed. |
|
1683 | 1696 | |
|
1684 | 1697 | This command takes effect with the next commit. To undo a copy |
|
1685 | 1698 | before that, see :hg:`revert`. |
|
1686 | 1699 | |
|
1687 | 1700 | Returns 0 on success, 1 if errors are encountered. |
|
1688 | 1701 | """ |
|
1689 | 1702 | wlock = repo.wlock(False) |
|
1690 | 1703 | try: |
|
1691 | 1704 | return cmdutil.copy(ui, repo, pats, opts) |
|
1692 | 1705 | finally: |
|
1693 | 1706 | wlock.release() |
|
1694 | 1707 | |
|
1695 | 1708 | @command('debugancestor', [], _('[INDEX] REV1 REV2'), optionalrepo=True) |
|
1696 | 1709 | def debugancestor(ui, repo, *args): |
|
1697 | 1710 | """find the ancestor revision of two revisions in a given index""" |
|
1698 | 1711 | if len(args) == 3: |
|
1699 | 1712 | index, rev1, rev2 = args |
|
1700 | 1713 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), index) |
|
1701 | 1714 | lookup = r.lookup |
|
1702 | 1715 | elif len(args) == 2: |
|
1703 | 1716 | if not repo: |
|
1704 | 1717 | raise util.Abort(_("there is no Mercurial repository here " |
|
1705 | 1718 | "(.hg not found)")) |
|
1706 | 1719 | rev1, rev2 = args |
|
1707 | 1720 | r = repo.changelog |
|
1708 | 1721 | lookup = repo.lookup |
|
1709 | 1722 | else: |
|
1710 | 1723 | raise util.Abort(_('either two or three arguments required')) |
|
1711 | 1724 | a = r.ancestor(lookup(rev1), lookup(rev2)) |
|
1712 | 1725 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
1713 | 1726 | |
|
1714 | 1727 | @command('debugbuilddag', |
|
1715 | 1728 | [('m', 'mergeable-file', None, _('add single file mergeable changes')), |
|
1716 | 1729 | ('o', 'overwritten-file', None, _('add single file all revs overwrite')), |
|
1717 | 1730 | ('n', 'new-file', None, _('add new file at each rev'))], |
|
1718 | 1731 | _('[OPTION]... [TEXT]')) |
|
1719 | 1732 | def debugbuilddag(ui, repo, text=None, |
|
1720 | 1733 | mergeable_file=False, |
|
1721 | 1734 | overwritten_file=False, |
|
1722 | 1735 | new_file=False): |
|
1723 | 1736 | """builds a repo with a given DAG from scratch in the current empty repo |
|
1724 | 1737 | |
|
1725 | 1738 | The description of the DAG is read from stdin if not given on the |
|
1726 | 1739 | command line. |
|
1727 | 1740 | |
|
1728 | 1741 | Elements: |
|
1729 | 1742 | |
|
1730 | 1743 | - "+n" is a linear run of n nodes based on the current default parent |
|
1731 | 1744 | - "." is a single node based on the current default parent |
|
1732 | 1745 | - "$" resets the default parent to null (implied at the start); |
|
1733 | 1746 | otherwise the default parent is always the last node created |
|
1734 | 1747 | - "<p" sets the default parent to the backref p |
|
1735 | 1748 | - "*p" is a fork at parent p, which is a backref |
|
1736 | 1749 | - "*p1/p2" is a merge of parents p1 and p2, which are backrefs |
|
1737 | 1750 | - "/p2" is a merge of the preceding node and p2 |
|
1738 | 1751 | - ":tag" defines a local tag for the preceding node |
|
1739 | 1752 | - "@branch" sets the named branch for subsequent nodes |
|
1740 | 1753 | - "#...\\n" is a comment up to the end of the line |
|
1741 | 1754 | |
|
1742 | 1755 | Whitespace between the above elements is ignored. |
|
1743 | 1756 | |
|
1744 | 1757 | A backref is either |
|
1745 | 1758 | |
|
1746 | 1759 | - a number n, which references the node curr-n, where curr is the current |
|
1747 | 1760 | node, or |
|
1748 | 1761 | - the name of a local tag you placed earlier using ":tag", or |
|
1749 | 1762 | - empty to denote the default parent. |
|
1750 | 1763 | |
|
1751 | 1764 | All string valued-elements are either strictly alphanumeric, or must |
|
1752 | 1765 | be enclosed in double quotes ("..."), with "\\" as escape character. |
|
1753 | 1766 | """ |
|
1754 | 1767 | |
|
1755 | 1768 | if text is None: |
|
1756 | 1769 | ui.status(_("reading DAG from stdin\n")) |
|
1757 | 1770 | text = ui.fin.read() |
|
1758 | 1771 | |
|
1759 | 1772 | cl = repo.changelog |
|
1760 | 1773 | if len(cl) > 0: |
|
1761 | 1774 | raise util.Abort(_('repository is not empty')) |
|
1762 | 1775 | |
|
1763 | 1776 | # determine number of revs in DAG |
|
1764 | 1777 | total = 0 |
|
1765 | 1778 | for type, data in dagparser.parsedag(text): |
|
1766 | 1779 | if type == 'n': |
|
1767 | 1780 | total += 1 |
|
1768 | 1781 | |
|
1769 | 1782 | if mergeable_file: |
|
1770 | 1783 | linesperrev = 2 |
|
1771 | 1784 | # make a file with k lines per rev |
|
1772 | 1785 | initialmergedlines = [str(i) for i in xrange(0, total * linesperrev)] |
|
1773 | 1786 | initialmergedlines.append("") |
|
1774 | 1787 | |
|
1775 | 1788 | tags = [] |
|
1776 | 1789 | |
|
1777 | 1790 | lock = tr = None |
|
1778 | 1791 | try: |
|
1779 | 1792 | lock = repo.lock() |
|
1780 | 1793 | tr = repo.transaction("builddag") |
|
1781 | 1794 | |
|
1782 | 1795 | at = -1 |
|
1783 | 1796 | atbranch = 'default' |
|
1784 | 1797 | nodeids = [] |
|
1785 | 1798 | id = 0 |
|
1786 | 1799 | ui.progress(_('building'), id, unit=_('revisions'), total=total) |
|
1787 | 1800 | for type, data in dagparser.parsedag(text): |
|
1788 | 1801 | if type == 'n': |
|
1789 | 1802 | ui.note(('node %s\n' % str(data))) |
|
1790 | 1803 | id, ps = data |
|
1791 | 1804 | |
|
1792 | 1805 | files = [] |
|
1793 | 1806 | fctxs = {} |
|
1794 | 1807 | |
|
1795 | 1808 | p2 = None |
|
1796 | 1809 | if mergeable_file: |
|
1797 | 1810 | fn = "mf" |
|
1798 | 1811 | p1 = repo[ps[0]] |
|
1799 | 1812 | if len(ps) > 1: |
|
1800 | 1813 | p2 = repo[ps[1]] |
|
1801 | 1814 | pa = p1.ancestor(p2) |
|
1802 | 1815 | base, local, other = [x[fn].data() for x in (pa, p1, |
|
1803 | 1816 | p2)] |
|
1804 | 1817 | m3 = simplemerge.Merge3Text(base, local, other) |
|
1805 | 1818 | ml = [l.strip() for l in m3.merge_lines()] |
|
1806 | 1819 | ml.append("") |
|
1807 | 1820 | elif at > 0: |
|
1808 | 1821 | ml = p1[fn].data().split("\n") |
|
1809 | 1822 | else: |
|
1810 | 1823 | ml = initialmergedlines |
|
1811 | 1824 | ml[id * linesperrev] += " r%i" % id |
|
1812 | 1825 | mergedtext = "\n".join(ml) |
|
1813 | 1826 | files.append(fn) |
|
1814 | 1827 | fctxs[fn] = context.memfilectx(repo, fn, mergedtext) |
|
1815 | 1828 | |
|
1816 | 1829 | if overwritten_file: |
|
1817 | 1830 | fn = "of" |
|
1818 | 1831 | files.append(fn) |
|
1819 | 1832 | fctxs[fn] = context.memfilectx(repo, fn, "r%i\n" % id) |
|
1820 | 1833 | |
|
1821 | 1834 | if new_file: |
|
1822 | 1835 | fn = "nf%i" % id |
|
1823 | 1836 | files.append(fn) |
|
1824 | 1837 | fctxs[fn] = context.memfilectx(repo, fn, "r%i\n" % id) |
|
1825 | 1838 | if len(ps) > 1: |
|
1826 | 1839 | if not p2: |
|
1827 | 1840 | p2 = repo[ps[1]] |
|
1828 | 1841 | for fn in p2: |
|
1829 | 1842 | if fn.startswith("nf"): |
|
1830 | 1843 | files.append(fn) |
|
1831 | 1844 | fctxs[fn] = p2[fn] |
|
1832 | 1845 | |
|
1833 | 1846 | def fctxfn(repo, cx, path): |
|
1834 | 1847 | return fctxs.get(path) |
|
1835 | 1848 | |
|
1836 | 1849 | if len(ps) == 0 or ps[0] < 0: |
|
1837 | 1850 | pars = [None, None] |
|
1838 | 1851 | elif len(ps) == 1: |
|
1839 | 1852 | pars = [nodeids[ps[0]], None] |
|
1840 | 1853 | else: |
|
1841 | 1854 | pars = [nodeids[p] for p in ps] |
|
1842 | 1855 | cx = context.memctx(repo, pars, "r%i" % id, files, fctxfn, |
|
1843 | 1856 | date=(id, 0), |
|
1844 | 1857 | user="debugbuilddag", |
|
1845 | 1858 | extra={'branch': atbranch}) |
|
1846 | 1859 | nodeid = repo.commitctx(cx) |
|
1847 | 1860 | nodeids.append(nodeid) |
|
1848 | 1861 | at = id |
|
1849 | 1862 | elif type == 'l': |
|
1850 | 1863 | id, name = data |
|
1851 | 1864 | ui.note(('tag %s\n' % name)) |
|
1852 | 1865 | tags.append("%s %s\n" % (hex(repo.changelog.node(id)), name)) |
|
1853 | 1866 | elif type == 'a': |
|
1854 | 1867 | ui.note(('branch %s\n' % data)) |
|
1855 | 1868 | atbranch = data |
|
1856 | 1869 | ui.progress(_('building'), id, unit=_('revisions'), total=total) |
|
1857 | 1870 | tr.close() |
|
1858 | 1871 | |
|
1859 | 1872 | if tags: |
|
1860 | 1873 | repo.vfs.write("localtags", "".join(tags)) |
|
1861 | 1874 | finally: |
|
1862 | 1875 | ui.progress(_('building'), None) |
|
1863 | 1876 | release(tr, lock) |
|
1864 | 1877 | |
|
1865 | 1878 | @command('debugbundle', |
|
1866 | 1879 | [('a', 'all', None, _('show all details'))], |
|
1867 | 1880 | _('FILE'), |
|
1868 | 1881 | norepo=True) |
|
1869 | 1882 | def debugbundle(ui, bundlepath, all=None, **opts): |
|
1870 | 1883 | """lists the contents of a bundle""" |
|
1871 | 1884 | f = hg.openpath(ui, bundlepath) |
|
1872 | 1885 | try: |
|
1873 | 1886 | gen = exchange.readbundle(ui, f, bundlepath) |
|
1874 | 1887 | if isinstance(gen, bundle2.unbundle20): |
|
1875 | 1888 | return _debugbundle2(ui, gen, all=all, **opts) |
|
1876 | 1889 | if all: |
|
1877 | 1890 | ui.write(("format: id, p1, p2, cset, delta base, len(delta)\n")) |
|
1878 | 1891 | |
|
1879 | 1892 | def showchunks(named): |
|
1880 | 1893 | ui.write("\n%s\n" % named) |
|
1881 | 1894 | chain = None |
|
1882 | 1895 | while True: |
|
1883 | 1896 | chunkdata = gen.deltachunk(chain) |
|
1884 | 1897 | if not chunkdata: |
|
1885 | 1898 | break |
|
1886 | 1899 | node = chunkdata['node'] |
|
1887 | 1900 | p1 = chunkdata['p1'] |
|
1888 | 1901 | p2 = chunkdata['p2'] |
|
1889 | 1902 | cs = chunkdata['cs'] |
|
1890 | 1903 | deltabase = chunkdata['deltabase'] |
|
1891 | 1904 | delta = chunkdata['delta'] |
|
1892 | 1905 | ui.write("%s %s %s %s %s %s\n" % |
|
1893 | 1906 | (hex(node), hex(p1), hex(p2), |
|
1894 | 1907 | hex(cs), hex(deltabase), len(delta))) |
|
1895 | 1908 | chain = node |
|
1896 | 1909 | |
|
1897 | 1910 | chunkdata = gen.changelogheader() |
|
1898 | 1911 | showchunks("changelog") |
|
1899 | 1912 | chunkdata = gen.manifestheader() |
|
1900 | 1913 | showchunks("manifest") |
|
1901 | 1914 | while True: |
|
1902 | 1915 | chunkdata = gen.filelogheader() |
|
1903 | 1916 | if not chunkdata: |
|
1904 | 1917 | break |
|
1905 | 1918 | fname = chunkdata['filename'] |
|
1906 | 1919 | showchunks(fname) |
|
1907 | 1920 | else: |
|
1908 | 1921 | if isinstance(gen, bundle2.unbundle20): |
|
1909 | 1922 | raise util.Abort(_('use debugbundle2 for this file')) |
|
1910 | 1923 | chunkdata = gen.changelogheader() |
|
1911 | 1924 | chain = None |
|
1912 | 1925 | while True: |
|
1913 | 1926 | chunkdata = gen.deltachunk(chain) |
|
1914 | 1927 | if not chunkdata: |
|
1915 | 1928 | break |
|
1916 | 1929 | node = chunkdata['node'] |
|
1917 | 1930 | ui.write("%s\n" % hex(node)) |
|
1918 | 1931 | chain = node |
|
1919 | 1932 | finally: |
|
1920 | 1933 | f.close() |
|
1921 | 1934 | |
|
1922 | 1935 | def _debugbundle2(ui, gen, **opts): |
|
1923 | 1936 | """lists the contents of a bundle2""" |
|
1924 | 1937 | if not isinstance(gen, bundle2.unbundle20): |
|
1925 | 1938 | raise util.Abort(_('not a bundle2 file')) |
|
1926 | 1939 | ui.write(('Stream params: %s\n' % repr(gen.params))) |
|
1927 | 1940 | for part in gen.iterparts(): |
|
1928 | 1941 | ui.write('%s -- %r\n' % (part.type, repr(part.params))) |
|
1929 | 1942 | if part.type == 'changegroup': |
|
1930 | 1943 | version = part.params.get('version', '01') |
|
1931 | 1944 | cg = changegroup.packermap[version][1](part, 'UN') |
|
1932 | 1945 | chunkdata = cg.changelogheader() |
|
1933 | 1946 | chain = None |
|
1934 | 1947 | while True: |
|
1935 | 1948 | chunkdata = cg.deltachunk(chain) |
|
1936 | 1949 | if not chunkdata: |
|
1937 | 1950 | break |
|
1938 | 1951 | node = chunkdata['node'] |
|
1939 | 1952 | ui.write(" %s\n" % hex(node)) |
|
1940 | 1953 | chain = node |
|
1941 | 1954 | |
|
1942 | 1955 | @command('debugcheckstate', [], '') |
|
1943 | 1956 | def debugcheckstate(ui, repo): |
|
1944 | 1957 | """validate the correctness of the current dirstate""" |
|
1945 | 1958 | parent1, parent2 = repo.dirstate.parents() |
|
1946 | 1959 | m1 = repo[parent1].manifest() |
|
1947 | 1960 | m2 = repo[parent2].manifest() |
|
1948 | 1961 | errors = 0 |
|
1949 | 1962 | for f in repo.dirstate: |
|
1950 | 1963 | state = repo.dirstate[f] |
|
1951 | 1964 | if state in "nr" and f not in m1: |
|
1952 | 1965 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
1953 | 1966 | errors += 1 |
|
1954 | 1967 | if state in "a" and f in m1: |
|
1955 | 1968 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
1956 | 1969 | errors += 1 |
|
1957 | 1970 | if state in "m" and f not in m1 and f not in m2: |
|
1958 | 1971 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
1959 | 1972 | (f, state)) |
|
1960 | 1973 | errors += 1 |
|
1961 | 1974 | for f in m1: |
|
1962 | 1975 | state = repo.dirstate[f] |
|
1963 | 1976 | if state not in "nrm": |
|
1964 | 1977 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
1965 | 1978 | errors += 1 |
|
1966 | 1979 | if errors: |
|
1967 | 1980 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
1968 | 1981 | raise util.Abort(error) |
|
1969 | 1982 | |
|
1970 | 1983 | @command('debugcommands', [], _('[COMMAND]'), norepo=True) |
|
1971 | 1984 | def debugcommands(ui, cmd='', *args): |
|
1972 | 1985 | """list all available commands and options""" |
|
1973 | 1986 | for cmd, vals in sorted(table.iteritems()): |
|
1974 | 1987 | cmd = cmd.split('|')[0].strip('^') |
|
1975 | 1988 | opts = ', '.join([i[1] for i in vals[1]]) |
|
1976 | 1989 | ui.write('%s: %s\n' % (cmd, opts)) |
|
1977 | 1990 | |
|
1978 | 1991 | @command('debugcomplete', |
|
1979 | 1992 | [('o', 'options', None, _('show the command options'))], |
|
1980 | 1993 | _('[-o] CMD'), |
|
1981 | 1994 | norepo=True) |
|
1982 | 1995 | def debugcomplete(ui, cmd='', **opts): |
|
1983 | 1996 | """returns the completion list associated with the given command""" |
|
1984 | 1997 | |
|
1985 | 1998 | if opts.get('options'): |
|
1986 | 1999 | options = [] |
|
1987 | 2000 | otables = [globalopts] |
|
1988 | 2001 | if cmd: |
|
1989 | 2002 | aliases, entry = cmdutil.findcmd(cmd, table, False) |
|
1990 | 2003 | otables.append(entry[1]) |
|
1991 | 2004 | for t in otables: |
|
1992 | 2005 | for o in t: |
|
1993 | 2006 | if "(DEPRECATED)" in o[3]: |
|
1994 | 2007 | continue |
|
1995 | 2008 | if o[0]: |
|
1996 | 2009 | options.append('-%s' % o[0]) |
|
1997 | 2010 | options.append('--%s' % o[1]) |
|
1998 | 2011 | ui.write("%s\n" % "\n".join(options)) |
|
1999 | 2012 | return |
|
2000 | 2013 | |
|
2001 | 2014 | cmdlist, unused_allcmds = cmdutil.findpossible(cmd, table) |
|
2002 | 2015 | if ui.verbose: |
|
2003 | 2016 | cmdlist = [' '.join(c[0]) for c in cmdlist.values()] |
|
2004 | 2017 | ui.write("%s\n" % "\n".join(sorted(cmdlist))) |
|
2005 | 2018 | |
|
2006 | 2019 | @command('debugdag', |
|
2007 | 2020 | [('t', 'tags', None, _('use tags as labels')), |
|
2008 | 2021 | ('b', 'branches', None, _('annotate with branch names')), |
|
2009 | 2022 | ('', 'dots', None, _('use dots for runs')), |
|
2010 | 2023 | ('s', 'spaces', None, _('separate elements by spaces'))], |
|
2011 | 2024 | _('[OPTION]... [FILE [REV]...]'), |
|
2012 | 2025 | optionalrepo=True) |
|
2013 | 2026 | def debugdag(ui, repo, file_=None, *revs, **opts): |
|
2014 | 2027 | """format the changelog or an index DAG as a concise textual description |
|
2015 | 2028 | |
|
2016 | 2029 | If you pass a revlog index, the revlog's DAG is emitted. If you list |
|
2017 | 2030 | revision numbers, they get labeled in the output as rN. |
|
2018 | 2031 | |
|
2019 | 2032 | Otherwise, the changelog DAG of the current repo is emitted. |
|
2020 | 2033 | """ |
|
2021 | 2034 | spaces = opts.get('spaces') |
|
2022 | 2035 | dots = opts.get('dots') |
|
2023 | 2036 | if file_: |
|
2024 | 2037 | rlog = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) |
|
2025 | 2038 | revs = set((int(r) for r in revs)) |
|
2026 | 2039 | def events(): |
|
2027 | 2040 | for r in rlog: |
|
2028 | 2041 | yield 'n', (r, list(p for p in rlog.parentrevs(r) |
|
2029 | 2042 | if p != -1)) |
|
2030 | 2043 | if r in revs: |
|
2031 | 2044 | yield 'l', (r, "r%i" % r) |
|
2032 | 2045 | elif repo: |
|
2033 | 2046 | cl = repo.changelog |
|
2034 | 2047 | tags = opts.get('tags') |
|
2035 | 2048 | branches = opts.get('branches') |
|
2036 | 2049 | if tags: |
|
2037 | 2050 | labels = {} |
|
2038 | 2051 | for l, n in repo.tags().items(): |
|
2039 | 2052 | labels.setdefault(cl.rev(n), []).append(l) |
|
2040 | 2053 | def events(): |
|
2041 | 2054 | b = "default" |
|
2042 | 2055 | for r in cl: |
|
2043 | 2056 | if branches: |
|
2044 | 2057 | newb = cl.read(cl.node(r))[5]['branch'] |
|
2045 | 2058 | if newb != b: |
|
2046 | 2059 | yield 'a', newb |
|
2047 | 2060 | b = newb |
|
2048 | 2061 | yield 'n', (r, list(p for p in cl.parentrevs(r) |
|
2049 | 2062 | if p != -1)) |
|
2050 | 2063 | if tags: |
|
2051 | 2064 | ls = labels.get(r) |
|
2052 | 2065 | if ls: |
|
2053 | 2066 | for l in ls: |
|
2054 | 2067 | yield 'l', (r, l) |
|
2055 | 2068 | else: |
|
2056 | 2069 | raise util.Abort(_('need repo for changelog dag')) |
|
2057 | 2070 | |
|
2058 | 2071 | for line in dagparser.dagtextlines(events(), |
|
2059 | 2072 | addspaces=spaces, |
|
2060 | 2073 | wraplabels=True, |
|
2061 | 2074 | wrapannotations=True, |
|
2062 | 2075 | wrapnonlinear=dots, |
|
2063 | 2076 | usedots=dots, |
|
2064 | 2077 | maxlinewidth=70): |
|
2065 | 2078 | ui.write(line) |
|
2066 | 2079 | ui.write("\n") |
|
2067 | 2080 | |
|
2068 | 2081 | @command('debugdata', |
|
2069 | 2082 | [('c', 'changelog', False, _('open changelog')), |
|
2070 | 2083 | ('m', 'manifest', False, _('open manifest')), |
|
2071 | 2084 | ('', 'dir', False, _('open directory manifest'))], |
|
2072 | 2085 | _('-c|-m|FILE REV')) |
|
2073 | 2086 | def debugdata(ui, repo, file_, rev=None, **opts): |
|
2074 | 2087 | """dump the contents of a data file revision""" |
|
2075 | 2088 | if opts.get('changelog') or opts.get('manifest'): |
|
2076 | 2089 | file_, rev = None, file_ |
|
2077 | 2090 | elif rev is None: |
|
2078 | 2091 | raise error.CommandError('debugdata', _('invalid arguments')) |
|
2079 | 2092 | r = cmdutil.openrevlog(repo, 'debugdata', file_, opts) |
|
2080 | 2093 | try: |
|
2081 | 2094 | ui.write(r.revision(r.lookup(rev))) |
|
2082 | 2095 | except KeyError: |
|
2083 | 2096 | raise util.Abort(_('invalid revision identifier %s') % rev) |
|
2084 | 2097 | |
|
2085 | 2098 | @command('debugdate', |
|
2086 | 2099 | [('e', 'extended', None, _('try extended date formats'))], |
|
2087 | 2100 | _('[-e] DATE [RANGE]'), |
|
2088 | 2101 | norepo=True, optionalrepo=True) |
|
2089 | 2102 | def debugdate(ui, date, range=None, **opts): |
|
2090 | 2103 | """parse and display a date""" |
|
2091 | 2104 | if opts["extended"]: |
|
2092 | 2105 | d = util.parsedate(date, util.extendeddateformats) |
|
2093 | 2106 | else: |
|
2094 | 2107 | d = util.parsedate(date) |
|
2095 | 2108 | ui.write(("internal: %s %s\n") % d) |
|
2096 | 2109 | ui.write(("standard: %s\n") % util.datestr(d)) |
|
2097 | 2110 | if range: |
|
2098 | 2111 | m = util.matchdate(range) |
|
2099 | 2112 | ui.write(("match: %s\n") % m(d[0])) |
|
2100 | 2113 | |
|
2101 | 2114 | @command('debugdiscovery', |
|
2102 | 2115 | [('', 'old', None, _('use old-style discovery')), |
|
2103 | 2116 | ('', 'nonheads', None, |
|
2104 | 2117 | _('use old-style discovery with non-heads included')), |
|
2105 | 2118 | ] + remoteopts, |
|
2106 | 2119 | _('[-l REV] [-r REV] [-b BRANCH]... [OTHER]')) |
|
2107 | 2120 | def debugdiscovery(ui, repo, remoteurl="default", **opts): |
|
2108 | 2121 | """runs the changeset discovery protocol in isolation""" |
|
2109 | 2122 | remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl), |
|
2110 | 2123 | opts.get('branch')) |
|
2111 | 2124 | remote = hg.peer(repo, opts, remoteurl) |
|
2112 | 2125 | ui.status(_('comparing with %s\n') % util.hidepassword(remoteurl)) |
|
2113 | 2126 | |
|
2114 | 2127 | # make sure tests are repeatable |
|
2115 | 2128 | random.seed(12323) |
|
2116 | 2129 | |
|
2117 | 2130 | def doit(localheads, remoteheads, remote=remote): |
|
2118 | 2131 | if opts.get('old'): |
|
2119 | 2132 | if localheads: |
|
2120 | 2133 | raise util.Abort('cannot use localheads with old style ' |
|
2121 | 2134 | 'discovery') |
|
2122 | 2135 | if not util.safehasattr(remote, 'branches'): |
|
2123 | 2136 | # enable in-client legacy support |
|
2124 | 2137 | remote = localrepo.locallegacypeer(remote.local()) |
|
2125 | 2138 | common, _in, hds = treediscovery.findcommonincoming(repo, remote, |
|
2126 | 2139 | force=True) |
|
2127 | 2140 | common = set(common) |
|
2128 | 2141 | if not opts.get('nonheads'): |
|
2129 | 2142 | ui.write(("unpruned common: %s\n") % |
|
2130 | 2143 | " ".join(sorted(short(n) for n in common))) |
|
2131 | 2144 | dag = dagutil.revlogdag(repo.changelog) |
|
2132 | 2145 | all = dag.ancestorset(dag.internalizeall(common)) |
|
2133 | 2146 | common = dag.externalizeall(dag.headsetofconnecteds(all)) |
|
2134 | 2147 | else: |
|
2135 | 2148 | common, any, hds = setdiscovery.findcommonheads(ui, repo, remote) |
|
2136 | 2149 | common = set(common) |
|
2137 | 2150 | rheads = set(hds) |
|
2138 | 2151 | lheads = set(repo.heads()) |
|
2139 | 2152 | ui.write(("common heads: %s\n") % |
|
2140 | 2153 | " ".join(sorted(short(n) for n in common))) |
|
2141 | 2154 | if lheads <= common: |
|
2142 | 2155 | ui.write(("local is subset\n")) |
|
2143 | 2156 | elif rheads <= common: |
|
2144 | 2157 | ui.write(("remote is subset\n")) |
|
2145 | 2158 | |
|
2146 | 2159 | serverlogs = opts.get('serverlog') |
|
2147 | 2160 | if serverlogs: |
|
2148 | 2161 | for filename in serverlogs: |
|
2149 | 2162 | logfile = open(filename, 'r') |
|
2150 | 2163 | try: |
|
2151 | 2164 | line = logfile.readline() |
|
2152 | 2165 | while line: |
|
2153 | 2166 | parts = line.strip().split(';') |
|
2154 | 2167 | op = parts[1] |
|
2155 | 2168 | if op == 'cg': |
|
2156 | 2169 | pass |
|
2157 | 2170 | elif op == 'cgss': |
|
2158 | 2171 | doit(parts[2].split(' '), parts[3].split(' ')) |
|
2159 | 2172 | elif op == 'unb': |
|
2160 | 2173 | doit(parts[3].split(' '), parts[2].split(' ')) |
|
2161 | 2174 | line = logfile.readline() |
|
2162 | 2175 | finally: |
|
2163 | 2176 | logfile.close() |
|
2164 | 2177 | |
|
2165 | 2178 | else: |
|
2166 | 2179 | remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, |
|
2167 | 2180 | opts.get('remote_head')) |
|
2168 | 2181 | localrevs = opts.get('local_head') |
|
2169 | 2182 | doit(localrevs, remoterevs) |
|
2170 | 2183 | |
|
2171 | 2184 | @command('debugextensions', formatteropts, [], norepo=True) |
|
2172 | 2185 | def debugextensions(ui, **opts): |
|
2173 | 2186 | '''show information about active extensions''' |
|
2174 | 2187 | exts = extensions.extensions(ui) |
|
2175 | 2188 | fm = ui.formatter('debugextensions', opts) |
|
2176 | 2189 | for extname, extmod in sorted(exts, key=operator.itemgetter(0)): |
|
2177 | 2190 | extsource = extmod.__file__ |
|
2178 | 2191 | exttestedwith = getattr(extmod, 'testedwith', None) |
|
2179 | 2192 | if exttestedwith is not None: |
|
2180 | 2193 | exttestedwith = exttestedwith.split() |
|
2181 | 2194 | extbuglink = getattr(extmod, 'buglink', None) |
|
2182 | 2195 | |
|
2183 | 2196 | fm.startitem() |
|
2184 | 2197 | |
|
2185 | 2198 | if ui.quiet or ui.verbose: |
|
2186 | 2199 | fm.write('name', '%s\n', extname) |
|
2187 | 2200 | else: |
|
2188 | 2201 | fm.write('name', '%s', extname) |
|
2189 | 2202 | if not exttestedwith: |
|
2190 | 2203 | fm.plain(_(' (untested!)\n')) |
|
2191 | 2204 | else: |
|
2192 | 2205 | if exttestedwith == ['internal'] or \ |
|
2193 | 2206 | util.version() in exttestedwith: |
|
2194 | 2207 | fm.plain('\n') |
|
2195 | 2208 | else: |
|
2196 | 2209 | lasttestedversion = exttestedwith[-1] |
|
2197 | 2210 | fm.plain(' (%s!)\n' % lasttestedversion) |
|
2198 | 2211 | |
|
2199 | 2212 | fm.condwrite(ui.verbose and extsource, 'source', |
|
2200 | 2213 | _(' location: %s\n'), extsource or "") |
|
2201 | 2214 | |
|
2202 | 2215 | fm.condwrite(ui.verbose and exttestedwith, 'testedwith', |
|
2203 | 2216 | _(' tested with: %s\n'), ' '.join(exttestedwith or [])) |
|
2204 | 2217 | |
|
2205 | 2218 | fm.condwrite(ui.verbose and extbuglink, 'buglink', |
|
2206 | 2219 | _(' bug reporting: %s\n'), extbuglink or "") |
|
2207 | 2220 | |
|
2208 | 2221 | fm.end() |
|
2209 | 2222 | |
|
2210 | 2223 | @command('debugfileset', |
|
2211 | 2224 | [('r', 'rev', '', _('apply the filespec on this revision'), _('REV'))], |
|
2212 | 2225 | _('[-r REV] FILESPEC')) |
|
2213 | 2226 | def debugfileset(ui, repo, expr, **opts): |
|
2214 | 2227 | '''parse and apply a fileset specification''' |
|
2215 | 2228 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) |
|
2216 | 2229 | if ui.verbose: |
|
2217 | 2230 | tree = fileset.parse(expr) |
|
2218 | 2231 | ui.note(fileset.prettyformat(tree), "\n") |
|
2219 | 2232 | |
|
2220 | 2233 | for f in ctx.getfileset(expr): |
|
2221 | 2234 | ui.write("%s\n" % f) |
|
2222 | 2235 | |
|
2223 | 2236 | @command('debugfsinfo', [], _('[PATH]'), norepo=True) |
|
2224 | 2237 | def debugfsinfo(ui, path="."): |
|
2225 | 2238 | """show information detected about current filesystem""" |
|
2226 | 2239 | util.writefile('.debugfsinfo', '') |
|
2227 | 2240 | ui.write(('exec: %s\n') % (util.checkexec(path) and 'yes' or 'no')) |
|
2228 | 2241 | ui.write(('symlink: %s\n') % (util.checklink(path) and 'yes' or 'no')) |
|
2229 | 2242 | ui.write(('hardlink: %s\n') % (util.checknlink(path) and 'yes' or 'no')) |
|
2230 | 2243 | ui.write(('case-sensitive: %s\n') % (util.checkcase('.debugfsinfo') |
|
2231 | 2244 | and 'yes' or 'no')) |
|
2232 | 2245 | os.unlink('.debugfsinfo') |
|
2233 | 2246 | |
|
2234 | 2247 | @command('debuggetbundle', |
|
2235 | 2248 | [('H', 'head', [], _('id of head node'), _('ID')), |
|
2236 | 2249 | ('C', 'common', [], _('id of common node'), _('ID')), |
|
2237 | 2250 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE'))], |
|
2238 | 2251 | _('REPO FILE [-H|-C ID]...'), |
|
2239 | 2252 | norepo=True) |
|
2240 | 2253 | def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts): |
|
2241 | 2254 | """retrieves a bundle from a repo |
|
2242 | 2255 | |
|
2243 | 2256 | Every ID must be a full-length hex node id string. Saves the bundle to the |
|
2244 | 2257 | given file. |
|
2245 | 2258 | """ |
|
2246 | 2259 | repo = hg.peer(ui, opts, repopath) |
|
2247 | 2260 | if not repo.capable('getbundle'): |
|
2248 | 2261 | raise util.Abort("getbundle() not supported by target repository") |
|
2249 | 2262 | args = {} |
|
2250 | 2263 | if common: |
|
2251 | 2264 | args['common'] = [bin(s) for s in common] |
|
2252 | 2265 | if head: |
|
2253 | 2266 | args['heads'] = [bin(s) for s in head] |
|
2254 | 2267 | # TODO: get desired bundlecaps from command line. |
|
2255 | 2268 | args['bundlecaps'] = None |
|
2256 | 2269 | bundle = repo.getbundle('debug', **args) |
|
2257 | 2270 | |
|
2258 | 2271 | bundletype = opts.get('type', 'bzip2').lower() |
|
2259 | 2272 | btypes = {'none': 'HG10UN', |
|
2260 | 2273 | 'bzip2': 'HG10BZ', |
|
2261 | 2274 | 'gzip': 'HG10GZ', |
|
2262 | 2275 | 'bundle2': 'HG20'} |
|
2263 | 2276 | bundletype = btypes.get(bundletype) |
|
2264 | 2277 | if bundletype not in changegroup.bundletypes: |
|
2265 | 2278 | raise util.Abort(_('unknown bundle type specified with --type')) |
|
2266 | 2279 | changegroup.writebundle(ui, bundle, bundlepath, bundletype) |
|
2267 | 2280 | |
|
2268 | 2281 | @command('debugignore', [], '') |
|
2269 | 2282 | def debugignore(ui, repo, *values, **opts): |
|
2270 | 2283 | """display the combined ignore pattern""" |
|
2271 | 2284 | ignore = repo.dirstate._ignore |
|
2272 | 2285 | includepat = getattr(ignore, 'includepat', None) |
|
2273 | 2286 | if includepat is not None: |
|
2274 | 2287 | ui.write("%s\n" % includepat) |
|
2275 | 2288 | else: |
|
2276 | 2289 | raise util.Abort(_("no ignore patterns found")) |
|
2277 | 2290 | |
|
2278 | 2291 | @command('debugindex', |
|
2279 | 2292 | [('c', 'changelog', False, _('open changelog')), |
|
2280 | 2293 | ('m', 'manifest', False, _('open manifest')), |
|
2281 | 2294 | ('', 'dir', False, _('open directory manifest')), |
|
2282 | 2295 | ('f', 'format', 0, _('revlog format'), _('FORMAT'))], |
|
2283 | 2296 | _('[-f FORMAT] -c|-m|FILE'), |
|
2284 | 2297 | optionalrepo=True) |
|
2285 | 2298 | def debugindex(ui, repo, file_=None, **opts): |
|
2286 | 2299 | """dump the contents of an index file""" |
|
2287 | 2300 | r = cmdutil.openrevlog(repo, 'debugindex', file_, opts) |
|
2288 | 2301 | format = opts.get('format', 0) |
|
2289 | 2302 | if format not in (0, 1): |
|
2290 | 2303 | raise util.Abort(_("unknown format %d") % format) |
|
2291 | 2304 | |
|
2292 | 2305 | generaldelta = r.version & revlog.REVLOGGENERALDELTA |
|
2293 | 2306 | if generaldelta: |
|
2294 | 2307 | basehdr = ' delta' |
|
2295 | 2308 | else: |
|
2296 | 2309 | basehdr = ' base' |
|
2297 | 2310 | |
|
2298 | 2311 | if ui.debugflag: |
|
2299 | 2312 | shortfn = hex |
|
2300 | 2313 | else: |
|
2301 | 2314 | shortfn = short |
|
2302 | 2315 | |
|
2303 | 2316 | # There might not be anything in r, so have a sane default |
|
2304 | 2317 | idlen = 12 |
|
2305 | 2318 | for i in r: |
|
2306 | 2319 | idlen = len(shortfn(r.node(i))) |
|
2307 | 2320 | break |
|
2308 | 2321 | |
|
2309 | 2322 | if format == 0: |
|
2310 | 2323 | ui.write(" rev offset length " + basehdr + " linkrev" |
|
2311 | 2324 | " %s %s p2\n" % ("nodeid".ljust(idlen), "p1".ljust(idlen))) |
|
2312 | 2325 | elif format == 1: |
|
2313 | 2326 | ui.write(" rev flag offset length" |
|
2314 | 2327 | " size " + basehdr + " link p1 p2" |
|
2315 | 2328 | " %s\n" % "nodeid".rjust(idlen)) |
|
2316 | 2329 | |
|
2317 | 2330 | for i in r: |
|
2318 | 2331 | node = r.node(i) |
|
2319 | 2332 | if generaldelta: |
|
2320 | 2333 | base = r.deltaparent(i) |
|
2321 | 2334 | else: |
|
2322 | 2335 | base = r.chainbase(i) |
|
2323 | 2336 | if format == 0: |
|
2324 | 2337 | try: |
|
2325 | 2338 | pp = r.parents(node) |
|
2326 | 2339 | except Exception: |
|
2327 | 2340 | pp = [nullid, nullid] |
|
2328 | 2341 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
2329 | 2342 | i, r.start(i), r.length(i), base, r.linkrev(i), |
|
2330 | 2343 | shortfn(node), shortfn(pp[0]), shortfn(pp[1]))) |
|
2331 | 2344 | elif format == 1: |
|
2332 | 2345 | pr = r.parentrevs(i) |
|
2333 | 2346 | ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d % 6d %s\n" % ( |
|
2334 | 2347 | i, r.flags(i), r.start(i), r.length(i), r.rawsize(i), |
|
2335 | 2348 | base, r.linkrev(i), pr[0], pr[1], shortfn(node))) |
|
2336 | 2349 | |
|
2337 | 2350 | @command('debugindexdot', [], _('FILE'), optionalrepo=True) |
|
2338 | 2351 | def debugindexdot(ui, repo, file_): |
|
2339 | 2352 | """dump an index DAG as a graphviz dot file""" |
|
2340 | 2353 | r = None |
|
2341 | 2354 | if repo: |
|
2342 | 2355 | filelog = repo.file(file_) |
|
2343 | 2356 | if len(filelog): |
|
2344 | 2357 | r = filelog |
|
2345 | 2358 | if not r: |
|
2346 | 2359 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) |
|
2347 | 2360 | ui.write(("digraph G {\n")) |
|
2348 | 2361 | for i in r: |
|
2349 | 2362 | node = r.node(i) |
|
2350 | 2363 | pp = r.parents(node) |
|
2351 | 2364 | ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) |
|
2352 | 2365 | if pp[1] != nullid: |
|
2353 | 2366 | ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) |
|
2354 | 2367 | ui.write("}\n") |
|
2355 | 2368 | |
|
2356 | 2369 | @command('debuginstall', [], '', norepo=True) |
|
2357 | 2370 | def debuginstall(ui): |
|
2358 | 2371 | '''test Mercurial installation |
|
2359 | 2372 | |
|
2360 | 2373 | Returns 0 on success. |
|
2361 | 2374 | ''' |
|
2362 | 2375 | |
|
2363 | 2376 | def writetemp(contents): |
|
2364 | 2377 | (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-") |
|
2365 | 2378 | f = os.fdopen(fd, "wb") |
|
2366 | 2379 | f.write(contents) |
|
2367 | 2380 | f.close() |
|
2368 | 2381 | return name |
|
2369 | 2382 | |
|
2370 | 2383 | problems = 0 |
|
2371 | 2384 | |
|
2372 | 2385 | # encoding |
|
2373 | 2386 | ui.status(_("checking encoding (%s)...\n") % encoding.encoding) |
|
2374 | 2387 | try: |
|
2375 | 2388 | encoding.fromlocal("test") |
|
2376 | 2389 | except util.Abort as inst: |
|
2377 | 2390 | ui.write(" %s\n" % inst) |
|
2378 | 2391 | ui.write(_(" (check that your locale is properly set)\n")) |
|
2379 | 2392 | problems += 1 |
|
2380 | 2393 | |
|
2381 | 2394 | # Python |
|
2382 | 2395 | ui.status(_("checking Python executable (%s)\n") % sys.executable) |
|
2383 | 2396 | ui.status(_("checking Python version (%s)\n") |
|
2384 | 2397 | % ("%s.%s.%s" % sys.version_info[:3])) |
|
2385 | 2398 | ui.status(_("checking Python lib (%s)...\n") |
|
2386 | 2399 | % os.path.dirname(os.__file__)) |
|
2387 | 2400 | |
|
2388 | 2401 | # compiled modules |
|
2389 | 2402 | ui.status(_("checking installed modules (%s)...\n") |
|
2390 | 2403 | % os.path.dirname(__file__)) |
|
2391 | 2404 | try: |
|
2392 | 2405 | import bdiff, mpatch, base85, osutil |
|
2393 | 2406 | dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes |
|
2394 | 2407 | except Exception as inst: |
|
2395 | 2408 | ui.write(" %s\n" % inst) |
|
2396 | 2409 | ui.write(_(" One or more extensions could not be found")) |
|
2397 | 2410 | ui.write(_(" (check that you compiled the extensions)\n")) |
|
2398 | 2411 | problems += 1 |
|
2399 | 2412 | |
|
2400 | 2413 | # templates |
|
2401 | 2414 | import templater |
|
2402 | 2415 | p = templater.templatepaths() |
|
2403 | 2416 | ui.status(_("checking templates (%s)...\n") % ' '.join(p)) |
|
2404 | 2417 | if p: |
|
2405 | 2418 | m = templater.templatepath("map-cmdline.default") |
|
2406 | 2419 | if m: |
|
2407 | 2420 | # template found, check if it is working |
|
2408 | 2421 | try: |
|
2409 | 2422 | templater.templater(m) |
|
2410 | 2423 | except Exception as inst: |
|
2411 | 2424 | ui.write(" %s\n" % inst) |
|
2412 | 2425 | p = None |
|
2413 | 2426 | else: |
|
2414 | 2427 | ui.write(_(" template 'default' not found\n")) |
|
2415 | 2428 | p = None |
|
2416 | 2429 | else: |
|
2417 | 2430 | ui.write(_(" no template directories found\n")) |
|
2418 | 2431 | if not p: |
|
2419 | 2432 | ui.write(_(" (templates seem to have been installed incorrectly)\n")) |
|
2420 | 2433 | problems += 1 |
|
2421 | 2434 | |
|
2422 | 2435 | # editor |
|
2423 | 2436 | ui.status(_("checking commit editor...\n")) |
|
2424 | 2437 | editor = ui.geteditor() |
|
2425 | 2438 | editor = util.expandpath(editor) |
|
2426 | 2439 | cmdpath = util.findexe(shlex.split(editor)[0]) |
|
2427 | 2440 | if not cmdpath: |
|
2428 | 2441 | if editor == 'vi': |
|
2429 | 2442 | ui.write(_(" No commit editor set and can't find vi in PATH\n")) |
|
2430 | 2443 | ui.write(_(" (specify a commit editor in your configuration" |
|
2431 | 2444 | " file)\n")) |
|
2432 | 2445 | else: |
|
2433 | 2446 | ui.write(_(" Can't find editor '%s' in PATH\n") % editor) |
|
2434 | 2447 | ui.write(_(" (specify a commit editor in your configuration" |
|
2435 | 2448 | " file)\n")) |
|
2436 | 2449 | problems += 1 |
|
2437 | 2450 | |
|
2438 | 2451 | # check username |
|
2439 | 2452 | ui.status(_("checking username...\n")) |
|
2440 | 2453 | try: |
|
2441 | 2454 | ui.username() |
|
2442 | 2455 | except util.Abort as e: |
|
2443 | 2456 | ui.write(" %s\n" % e) |
|
2444 | 2457 | ui.write(_(" (specify a username in your configuration file)\n")) |
|
2445 | 2458 | problems += 1 |
|
2446 | 2459 | |
|
2447 | 2460 | if not problems: |
|
2448 | 2461 | ui.status(_("no problems detected\n")) |
|
2449 | 2462 | else: |
|
2450 | 2463 | ui.write(_("%s problems detected," |
|
2451 | 2464 | " please check your install!\n") % problems) |
|
2452 | 2465 | |
|
2453 | 2466 | return problems |
|
2454 | 2467 | |
|
2455 | 2468 | @command('debugknown', [], _('REPO ID...'), norepo=True) |
|
2456 | 2469 | def debugknown(ui, repopath, *ids, **opts): |
|
2457 | 2470 | """test whether node ids are known to a repo |
|
2458 | 2471 | |
|
2459 | 2472 | Every ID must be a full-length hex node id string. Returns a list of 0s |
|
2460 | 2473 | and 1s indicating unknown/known. |
|
2461 | 2474 | """ |
|
2462 | 2475 | repo = hg.peer(ui, opts, repopath) |
|
2463 | 2476 | if not repo.capable('known'): |
|
2464 | 2477 | raise util.Abort("known() not supported by target repository") |
|
2465 | 2478 | flags = repo.known([bin(s) for s in ids]) |
|
2466 | 2479 | ui.write("%s\n" % ("".join([f and "1" or "0" for f in flags]))) |
|
2467 | 2480 | |
|
2468 | 2481 | @command('debuglabelcomplete', [], _('LABEL...')) |
|
2469 | 2482 | def debuglabelcomplete(ui, repo, *args): |
|
2470 | 2483 | '''backwards compatibility with old bash completion scripts (DEPRECATED)''' |
|
2471 | 2484 | debugnamecomplete(ui, repo, *args) |
|
2472 | 2485 | |
|
2473 | 2486 | @command('debugmergestate', [], '') |
|
2474 | 2487 | def debugmergestate(ui, repo, *args): |
|
2475 | 2488 | """print merge state |
|
2476 | 2489 | |
|
2477 | 2490 | Use --verbose to print out information about whether v1 or v2 merge state |
|
2478 | 2491 | was chosen.""" |
|
2479 | 2492 | def printrecords(version): |
|
2480 | 2493 | ui.write(('* version %s records\n') % version) |
|
2481 | 2494 | if version == 1: |
|
2482 | 2495 | records = v1records |
|
2483 | 2496 | else: |
|
2484 | 2497 | records = v2records |
|
2485 | 2498 | |
|
2486 | 2499 | for rtype, record in records: |
|
2487 | 2500 | # pretty print some record types |
|
2488 | 2501 | if rtype == 'L': |
|
2489 | 2502 | ui.write(('local: %s\n') % record) |
|
2490 | 2503 | elif rtype == 'O': |
|
2491 | 2504 | ui.write(('other: %s\n') % record) |
|
2492 | 2505 | elif rtype == 'F': |
|
2493 | 2506 | r = record.split('\0') |
|
2494 | 2507 | f, state, hash, lfile, afile, anode, ofile = r[0:7] |
|
2495 | 2508 | if version == 1: |
|
2496 | 2509 | onode = 'not stored in v1 format' |
|
2497 | 2510 | flags = r[7] |
|
2498 | 2511 | else: |
|
2499 | 2512 | onode, flags = r[7:9] |
|
2500 | 2513 | ui.write(('file: %s (state "%s", hash %s)\n') |
|
2501 | 2514 | % (f, state, hash)) |
|
2502 | 2515 | ui.write((' local path: %s (flags "%s")\n') % (lfile, flags)) |
|
2503 | 2516 | ui.write((' ancestor path: %s (node %s)\n') % (afile, anode)) |
|
2504 | 2517 | ui.write((' other path: %s (node %s)\n') % (ofile, onode)) |
|
2505 | 2518 | else: |
|
2506 | 2519 | ui.write(('unrecognized entry: %s\t%s\n') |
|
2507 | 2520 | % (rtype, record.replace('\0', '\t'))) |
|
2508 | 2521 | |
|
2509 | 2522 | ms = mergemod.mergestate(repo) |
|
2510 | 2523 | |
|
2511 | 2524 | # sort so that reasonable information is on top |
|
2512 | 2525 | v1records = ms._readrecordsv1() |
|
2513 | 2526 | v2records = ms._readrecordsv2() |
|
2514 | 2527 | order = 'LO' |
|
2515 | 2528 | def key(r): |
|
2516 | 2529 | idx = order.find(r[0]) |
|
2517 | 2530 | if idx == -1: |
|
2518 | 2531 | return (1, r[1]) |
|
2519 | 2532 | else: |
|
2520 | 2533 | return (0, idx) |
|
2521 | 2534 | v1records.sort(key=key) |
|
2522 | 2535 | v2records.sort(key=key) |
|
2523 | 2536 | |
|
2524 | 2537 | if not v1records and not v2records: |
|
2525 | 2538 | ui.write(('no merge state found\n')) |
|
2526 | 2539 | elif not v2records: |
|
2527 | 2540 | ui.note(('no version 2 merge state\n')) |
|
2528 | 2541 | printrecords(1) |
|
2529 | 2542 | elif ms._v1v2match(v1records, v2records): |
|
2530 | 2543 | ui.note(('v1 and v2 states match: using v2\n')) |
|
2531 | 2544 | printrecords(2) |
|
2532 | 2545 | else: |
|
2533 | 2546 | ui.note(('v1 and v2 states mismatch: using v1\n')) |
|
2534 | 2547 | printrecords(1) |
|
2535 | 2548 | if ui.verbose: |
|
2536 | 2549 | printrecords(2) |
|
2537 | 2550 | |
|
2538 | 2551 | @command('debugnamecomplete', [], _('NAME...')) |
|
2539 | 2552 | def debugnamecomplete(ui, repo, *args): |
|
2540 | 2553 | '''complete "names" - tags, open branch names, bookmark names''' |
|
2541 | 2554 | |
|
2542 | 2555 | names = set() |
|
2543 | 2556 | # since we previously only listed open branches, we will handle that |
|
2544 | 2557 | # specially (after this for loop) |
|
2545 | 2558 | for name, ns in repo.names.iteritems(): |
|
2546 | 2559 | if name != 'branches': |
|
2547 | 2560 | names.update(ns.listnames(repo)) |
|
2548 | 2561 | names.update(tag for (tag, heads, tip, closed) |
|
2549 | 2562 | in repo.branchmap().iterbranches() if not closed) |
|
2550 | 2563 | completions = set() |
|
2551 | 2564 | if not args: |
|
2552 | 2565 | args = [''] |
|
2553 | 2566 | for a in args: |
|
2554 | 2567 | completions.update(n for n in names if n.startswith(a)) |
|
2555 | 2568 | ui.write('\n'.join(sorted(completions))) |
|
2556 | 2569 | ui.write('\n') |
|
2557 | 2570 | |
|
2558 | 2571 | @command('debuglocks', |
|
2559 | 2572 | [('L', 'force-lock', None, _('free the store lock (DANGEROUS)')), |
|
2560 | 2573 | ('W', 'force-wlock', None, |
|
2561 | 2574 | _('free the working state lock (DANGEROUS)'))], |
|
2562 | 2575 | _('[OPTION]...')) |
|
2563 | 2576 | def debuglocks(ui, repo, **opts): |
|
2564 | 2577 | """show or modify state of locks |
|
2565 | 2578 | |
|
2566 | 2579 | By default, this command will show which locks are held. This |
|
2567 | 2580 | includes the user and process holding the lock, the amount of time |
|
2568 | 2581 | the lock has been held, and the machine name where the process is |
|
2569 | 2582 | running if it's not local. |
|
2570 | 2583 | |
|
2571 | 2584 | Locks protect the integrity of Mercurial's data, so should be |
|
2572 | 2585 | treated with care. System crashes or other interruptions may cause |
|
2573 | 2586 | locks to not be properly released, though Mercurial will usually |
|
2574 | 2587 | detect and remove such stale locks automatically. |
|
2575 | 2588 | |
|
2576 | 2589 | However, detecting stale locks may not always be possible (for |
|
2577 | 2590 | instance, on a shared filesystem). Removing locks may also be |
|
2578 | 2591 | blocked by filesystem permissions. |
|
2579 | 2592 | |
|
2580 | 2593 | Returns 0 if no locks are held. |
|
2581 | 2594 | |
|
2582 | 2595 | """ |
|
2583 | 2596 | |
|
2584 | 2597 | if opts.get('force_lock'): |
|
2585 | 2598 | repo.svfs.unlink('lock') |
|
2586 | 2599 | if opts.get('force_wlock'): |
|
2587 | 2600 | repo.vfs.unlink('wlock') |
|
2588 | 2601 | if opts.get('force_lock') or opts.get('force_lock'): |
|
2589 | 2602 | return 0 |
|
2590 | 2603 | |
|
2591 | 2604 | now = time.time() |
|
2592 | 2605 | held = 0 |
|
2593 | 2606 | |
|
2594 | 2607 | def report(vfs, name, method): |
|
2595 | 2608 | # this causes stale locks to get reaped for more accurate reporting |
|
2596 | 2609 | try: |
|
2597 | 2610 | l = method(False) |
|
2598 | 2611 | except error.LockHeld: |
|
2599 | 2612 | l = None |
|
2600 | 2613 | |
|
2601 | 2614 | if l: |
|
2602 | 2615 | l.release() |
|
2603 | 2616 | else: |
|
2604 | 2617 | try: |
|
2605 | 2618 | stat = vfs.lstat(name) |
|
2606 | 2619 | age = now - stat.st_mtime |
|
2607 | 2620 | user = util.username(stat.st_uid) |
|
2608 | 2621 | locker = vfs.readlock(name) |
|
2609 | 2622 | if ":" in locker: |
|
2610 | 2623 | host, pid = locker.split(':') |
|
2611 | 2624 | if host == socket.gethostname(): |
|
2612 | 2625 | locker = 'user %s, process %s' % (user, pid) |
|
2613 | 2626 | else: |
|
2614 | 2627 | locker = 'user %s, process %s, host %s' \ |
|
2615 | 2628 | % (user, pid, host) |
|
2616 | 2629 | ui.write("%-6s %s (%ds)\n" % (name + ":", locker, age)) |
|
2617 | 2630 | return 1 |
|
2618 | 2631 | except OSError as e: |
|
2619 | 2632 | if e.errno != errno.ENOENT: |
|
2620 | 2633 | raise |
|
2621 | 2634 | |
|
2622 | 2635 | ui.write("%-6s free\n" % (name + ":")) |
|
2623 | 2636 | return 0 |
|
2624 | 2637 | |
|
2625 | 2638 | held += report(repo.svfs, "lock", repo.lock) |
|
2626 | 2639 | held += report(repo.vfs, "wlock", repo.wlock) |
|
2627 | 2640 | |
|
2628 | 2641 | return held |
|
2629 | 2642 | |
|
2630 | 2643 | @command('debugobsolete', |
|
2631 | 2644 | [('', 'flags', 0, _('markers flag')), |
|
2632 | 2645 | ('', 'record-parents', False, |
|
2633 | 2646 | _('record parent information for the precursor')), |
|
2634 | 2647 | ('r', 'rev', [], _('display markers relevant to REV')), |
|
2635 | 2648 | ] + commitopts2, |
|
2636 | 2649 | _('[OBSOLETED [REPLACEMENT] [REPL... ]')) |
|
2637 | 2650 | def debugobsolete(ui, repo, precursor=None, *successors, **opts): |
|
2638 | 2651 | """create arbitrary obsolete marker |
|
2639 | 2652 | |
|
2640 | 2653 | With no arguments, displays the list of obsolescence markers.""" |
|
2641 | 2654 | |
|
2642 | 2655 | def parsenodeid(s): |
|
2643 | 2656 | try: |
|
2644 | 2657 | # We do not use revsingle/revrange functions here to accept |
|
2645 | 2658 | # arbitrary node identifiers, possibly not present in the |
|
2646 | 2659 | # local repository. |
|
2647 | 2660 | n = bin(s) |
|
2648 | 2661 | if len(n) != len(nullid): |
|
2649 | 2662 | raise TypeError() |
|
2650 | 2663 | return n |
|
2651 | 2664 | except TypeError: |
|
2652 | 2665 | raise util.Abort('changeset references must be full hexadecimal ' |
|
2653 | 2666 | 'node identifiers') |
|
2654 | 2667 | |
|
2655 | 2668 | if precursor is not None: |
|
2656 | 2669 | if opts['rev']: |
|
2657 | 2670 | raise util.Abort('cannot select revision when creating marker') |
|
2658 | 2671 | metadata = {} |
|
2659 | 2672 | metadata['user'] = opts['user'] or ui.username() |
|
2660 | 2673 | succs = tuple(parsenodeid(succ) for succ in successors) |
|
2661 | 2674 | l = repo.lock() |
|
2662 | 2675 | try: |
|
2663 | 2676 | tr = repo.transaction('debugobsolete') |
|
2664 | 2677 | try: |
|
2665 | 2678 | date = opts.get('date') |
|
2666 | 2679 | if date: |
|
2667 | 2680 | date = util.parsedate(date) |
|
2668 | 2681 | else: |
|
2669 | 2682 | date = None |
|
2670 | 2683 | prec = parsenodeid(precursor) |
|
2671 | 2684 | parents = None |
|
2672 | 2685 | if opts['record_parents']: |
|
2673 | 2686 | if prec not in repo.unfiltered(): |
|
2674 | 2687 | raise util.Abort('cannot used --record-parents on ' |
|
2675 | 2688 | 'unknown changesets') |
|
2676 | 2689 | parents = repo.unfiltered()[prec].parents() |
|
2677 | 2690 | parents = tuple(p.node() for p in parents) |
|
2678 | 2691 | repo.obsstore.create(tr, prec, succs, opts['flags'], |
|
2679 | 2692 | parents=parents, date=date, |
|
2680 | 2693 | metadata=metadata) |
|
2681 | 2694 | tr.close() |
|
2682 | 2695 | except ValueError as exc: |
|
2683 | 2696 | raise util.Abort(_('bad obsmarker input: %s') % exc) |
|
2684 | 2697 | finally: |
|
2685 | 2698 | tr.release() |
|
2686 | 2699 | finally: |
|
2687 | 2700 | l.release() |
|
2688 | 2701 | else: |
|
2689 | 2702 | if opts['rev']: |
|
2690 | 2703 | revs = scmutil.revrange(repo, opts['rev']) |
|
2691 | 2704 | nodes = [repo[r].node() for r in revs] |
|
2692 | 2705 | markers = list(obsolete.getmarkers(repo, nodes=nodes)) |
|
2693 | 2706 | markers.sort(key=lambda x: x._data) |
|
2694 | 2707 | else: |
|
2695 | 2708 | markers = obsolete.getmarkers(repo) |
|
2696 | 2709 | |
|
2697 | 2710 | for m in markers: |
|
2698 | 2711 | cmdutil.showmarker(ui, m) |
|
2699 | 2712 | |
|
2700 | 2713 | @command('debugpathcomplete', |
|
2701 | 2714 | [('f', 'full', None, _('complete an entire path')), |
|
2702 | 2715 | ('n', 'normal', None, _('show only normal files')), |
|
2703 | 2716 | ('a', 'added', None, _('show only added files')), |
|
2704 | 2717 | ('r', 'removed', None, _('show only removed files'))], |
|
2705 | 2718 | _('FILESPEC...')) |
|
2706 | 2719 | def debugpathcomplete(ui, repo, *specs, **opts): |
|
2707 | 2720 | '''complete part or all of a tracked path |
|
2708 | 2721 | |
|
2709 | 2722 | This command supports shells that offer path name completion. It |
|
2710 | 2723 | currently completes only files already known to the dirstate. |
|
2711 | 2724 | |
|
2712 | 2725 | Completion extends only to the next path segment unless |
|
2713 | 2726 | --full is specified, in which case entire paths are used.''' |
|
2714 | 2727 | |
|
2715 | 2728 | def complete(path, acceptable): |
|
2716 | 2729 | dirstate = repo.dirstate |
|
2717 | 2730 | spec = os.path.normpath(os.path.join(os.getcwd(), path)) |
|
2718 | 2731 | rootdir = repo.root + os.sep |
|
2719 | 2732 | if spec != repo.root and not spec.startswith(rootdir): |
|
2720 | 2733 | return [], [] |
|
2721 | 2734 | if os.path.isdir(spec): |
|
2722 | 2735 | spec += '/' |
|
2723 | 2736 | spec = spec[len(rootdir):] |
|
2724 | 2737 | fixpaths = os.sep != '/' |
|
2725 | 2738 | if fixpaths: |
|
2726 | 2739 | spec = spec.replace(os.sep, '/') |
|
2727 | 2740 | speclen = len(spec) |
|
2728 | 2741 | fullpaths = opts['full'] |
|
2729 | 2742 | files, dirs = set(), set() |
|
2730 | 2743 | adddir, addfile = dirs.add, files.add |
|
2731 | 2744 | for f, st in dirstate.iteritems(): |
|
2732 | 2745 | if f.startswith(spec) and st[0] in acceptable: |
|
2733 | 2746 | if fixpaths: |
|
2734 | 2747 | f = f.replace('/', os.sep) |
|
2735 | 2748 | if fullpaths: |
|
2736 | 2749 | addfile(f) |
|
2737 | 2750 | continue |
|
2738 | 2751 | s = f.find(os.sep, speclen) |
|
2739 | 2752 | if s >= 0: |
|
2740 | 2753 | adddir(f[:s]) |
|
2741 | 2754 | else: |
|
2742 | 2755 | addfile(f) |
|
2743 | 2756 | return files, dirs |
|
2744 | 2757 | |
|
2745 | 2758 | acceptable = '' |
|
2746 | 2759 | if opts['normal']: |
|
2747 | 2760 | acceptable += 'nm' |
|
2748 | 2761 | if opts['added']: |
|
2749 | 2762 | acceptable += 'a' |
|
2750 | 2763 | if opts['removed']: |
|
2751 | 2764 | acceptable += 'r' |
|
2752 | 2765 | cwd = repo.getcwd() |
|
2753 | 2766 | if not specs: |
|
2754 | 2767 | specs = ['.'] |
|
2755 | 2768 | |
|
2756 | 2769 | files, dirs = set(), set() |
|
2757 | 2770 | for spec in specs: |
|
2758 | 2771 | f, d = complete(spec, acceptable or 'nmar') |
|
2759 | 2772 | files.update(f) |
|
2760 | 2773 | dirs.update(d) |
|
2761 | 2774 | files.update(dirs) |
|
2762 | 2775 | ui.write('\n'.join(repo.pathto(p, cwd) for p in sorted(files))) |
|
2763 | 2776 | ui.write('\n') |
|
2764 | 2777 | |
|
2765 | 2778 | @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'), norepo=True) |
|
2766 | 2779 | def debugpushkey(ui, repopath, namespace, *keyinfo, **opts): |
|
2767 | 2780 | '''access the pushkey key/value protocol |
|
2768 | 2781 | |
|
2769 | 2782 | With two args, list the keys in the given namespace. |
|
2770 | 2783 | |
|
2771 | 2784 | With five args, set a key to new if it currently is set to old. |
|
2772 | 2785 | Reports success or failure. |
|
2773 | 2786 | ''' |
|
2774 | 2787 | |
|
2775 | 2788 | target = hg.peer(ui, {}, repopath) |
|
2776 | 2789 | if keyinfo: |
|
2777 | 2790 | key, old, new = keyinfo |
|
2778 | 2791 | r = target.pushkey(namespace, key, old, new) |
|
2779 | 2792 | ui.status(str(r) + '\n') |
|
2780 | 2793 | return not r |
|
2781 | 2794 | else: |
|
2782 | 2795 | for k, v in sorted(target.listkeys(namespace).iteritems()): |
|
2783 | 2796 | ui.write("%s\t%s\n" % (k.encode('string-escape'), |
|
2784 | 2797 | v.encode('string-escape'))) |
|
2785 | 2798 | |
|
2786 | 2799 | @command('debugpvec', [], _('A B')) |
|
2787 | 2800 | def debugpvec(ui, repo, a, b=None): |
|
2788 | 2801 | ca = scmutil.revsingle(repo, a) |
|
2789 | 2802 | cb = scmutil.revsingle(repo, b) |
|
2790 | 2803 | pa = pvec.ctxpvec(ca) |
|
2791 | 2804 | pb = pvec.ctxpvec(cb) |
|
2792 | 2805 | if pa == pb: |
|
2793 | 2806 | rel = "=" |
|
2794 | 2807 | elif pa > pb: |
|
2795 | 2808 | rel = ">" |
|
2796 | 2809 | elif pa < pb: |
|
2797 | 2810 | rel = "<" |
|
2798 | 2811 | elif pa | pb: |
|
2799 | 2812 | rel = "|" |
|
2800 | 2813 | ui.write(_("a: %s\n") % pa) |
|
2801 | 2814 | ui.write(_("b: %s\n") % pb) |
|
2802 | 2815 | ui.write(_("depth(a): %d depth(b): %d\n") % (pa._depth, pb._depth)) |
|
2803 | 2816 | ui.write(_("delta: %d hdist: %d distance: %d relation: %s\n") % |
|
2804 | 2817 | (abs(pa._depth - pb._depth), pvec._hamming(pa._vec, pb._vec), |
|
2805 | 2818 | pa.distance(pb), rel)) |
|
2806 | 2819 | |
|
2807 | 2820 | @command('debugrebuilddirstate|debugrebuildstate', |
|
2808 | 2821 | [('r', 'rev', '', _('revision to rebuild to'), _('REV')), |
|
2809 | 2822 | ('', 'minimal', None, _('only rebuild files that are inconsistent with ' |
|
2810 | 2823 | 'the working copy parent')), |
|
2811 | 2824 | ], |
|
2812 | 2825 | _('[-r REV]')) |
|
2813 | 2826 | def debugrebuilddirstate(ui, repo, rev, **opts): |
|
2814 | 2827 | """rebuild the dirstate as it would look like for the given revision |
|
2815 | 2828 | |
|
2816 | 2829 | If no revision is specified the first current parent will be used. |
|
2817 | 2830 | |
|
2818 | 2831 | The dirstate will be set to the files of the given revision. |
|
2819 | 2832 | The actual working directory content or existing dirstate |
|
2820 | 2833 | information such as adds or removes is not considered. |
|
2821 | 2834 | |
|
2822 | 2835 | ``minimal`` will only rebuild the dirstate status for files that claim to be |
|
2823 | 2836 | tracked but are not in the parent manifest, or that exist in the parent |
|
2824 | 2837 | manifest but are not in the dirstate. It will not change adds, removes, or |
|
2825 | 2838 | modified files that are in the working copy parent. |
|
2826 | 2839 | |
|
2827 | 2840 | One use of this command is to make the next :hg:`status` invocation |
|
2828 | 2841 | check the actual file content. |
|
2829 | 2842 | """ |
|
2830 | 2843 | ctx = scmutil.revsingle(repo, rev) |
|
2831 | 2844 | wlock = repo.wlock() |
|
2832 | 2845 | try: |
|
2833 | 2846 | dirstate = repo.dirstate |
|
2834 | 2847 | |
|
2835 | 2848 | # See command doc for what minimal does. |
|
2836 | 2849 | if opts.get('minimal'): |
|
2837 | 2850 | dirstatefiles = set(dirstate) |
|
2838 | 2851 | ctxfiles = set(ctx.manifest().keys()) |
|
2839 | 2852 | for file in (dirstatefiles | ctxfiles): |
|
2840 | 2853 | indirstate = file in dirstatefiles |
|
2841 | 2854 | inctx = file in ctxfiles |
|
2842 | 2855 | |
|
2843 | 2856 | if indirstate and not inctx and dirstate[file] != 'a': |
|
2844 | 2857 | dirstate.drop(file) |
|
2845 | 2858 | elif inctx and not indirstate: |
|
2846 | 2859 | dirstate.normallookup(file) |
|
2847 | 2860 | else: |
|
2848 | 2861 | dirstate.rebuild(ctx.node(), ctx.manifest()) |
|
2849 | 2862 | finally: |
|
2850 | 2863 | wlock.release() |
|
2851 | 2864 | |
|
2852 | 2865 | @command('debugrebuildfncache', [], '') |
|
2853 | 2866 | def debugrebuildfncache(ui, repo): |
|
2854 | 2867 | """rebuild the fncache file""" |
|
2855 | 2868 | repair.rebuildfncache(ui, repo) |
|
2856 | 2869 | |
|
2857 | 2870 | @command('debugrename', |
|
2858 | 2871 | [('r', 'rev', '', _('revision to debug'), _('REV'))], |
|
2859 | 2872 | _('[-r REV] FILE')) |
|
2860 | 2873 | def debugrename(ui, repo, file1, *pats, **opts): |
|
2861 | 2874 | """dump rename information""" |
|
2862 | 2875 | |
|
2863 | 2876 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
2864 | 2877 | m = scmutil.match(ctx, (file1,) + pats, opts) |
|
2865 | 2878 | for abs in ctx.walk(m): |
|
2866 | 2879 | fctx = ctx[abs] |
|
2867 | 2880 | o = fctx.filelog().renamed(fctx.filenode()) |
|
2868 | 2881 | rel = m.rel(abs) |
|
2869 | 2882 | if o: |
|
2870 | 2883 | ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1]))) |
|
2871 | 2884 | else: |
|
2872 | 2885 | ui.write(_("%s not renamed\n") % rel) |
|
2873 | 2886 | |
|
2874 | 2887 | @command('debugrevlog', |
|
2875 | 2888 | [('c', 'changelog', False, _('open changelog')), |
|
2876 | 2889 | ('m', 'manifest', False, _('open manifest')), |
|
2877 | 2890 | ('', 'dir', False, _('open directory manifest')), |
|
2878 | 2891 | ('d', 'dump', False, _('dump index data'))], |
|
2879 | 2892 | _('-c|-m|FILE'), |
|
2880 | 2893 | optionalrepo=True) |
|
2881 | 2894 | def debugrevlog(ui, repo, file_=None, **opts): |
|
2882 | 2895 | """show data and statistics about a revlog""" |
|
2883 | 2896 | r = cmdutil.openrevlog(repo, 'debugrevlog', file_, opts) |
|
2884 | 2897 | |
|
2885 | 2898 | if opts.get("dump"): |
|
2886 | 2899 | numrevs = len(r) |
|
2887 | 2900 | ui.write("# rev p1rev p2rev start end deltastart base p1 p2" |
|
2888 | 2901 | " rawsize totalsize compression heads chainlen\n") |
|
2889 | 2902 | ts = 0 |
|
2890 | 2903 | heads = set() |
|
2891 | 2904 | |
|
2892 | 2905 | for rev in xrange(numrevs): |
|
2893 | 2906 | dbase = r.deltaparent(rev) |
|
2894 | 2907 | if dbase == -1: |
|
2895 | 2908 | dbase = rev |
|
2896 | 2909 | cbase = r.chainbase(rev) |
|
2897 | 2910 | clen = r.chainlen(rev) |
|
2898 | 2911 | p1, p2 = r.parentrevs(rev) |
|
2899 | 2912 | rs = r.rawsize(rev) |
|
2900 | 2913 | ts = ts + rs |
|
2901 | 2914 | heads -= set(r.parentrevs(rev)) |
|
2902 | 2915 | heads.add(rev) |
|
2903 | 2916 | ui.write("%5d %5d %5d %5d %5d %10d %4d %4d %4d %7d %9d " |
|
2904 | 2917 | "%11d %5d %8d\n" % |
|
2905 | 2918 | (rev, p1, p2, r.start(rev), r.end(rev), |
|
2906 | 2919 | r.start(dbase), r.start(cbase), |
|
2907 | 2920 | r.start(p1), r.start(p2), |
|
2908 | 2921 | rs, ts, ts / r.end(rev), len(heads), clen)) |
|
2909 | 2922 | return 0 |
|
2910 | 2923 | |
|
2911 | 2924 | v = r.version |
|
2912 | 2925 | format = v & 0xFFFF |
|
2913 | 2926 | flags = [] |
|
2914 | 2927 | gdelta = False |
|
2915 | 2928 | if v & revlog.REVLOGNGINLINEDATA: |
|
2916 | 2929 | flags.append('inline') |
|
2917 | 2930 | if v & revlog.REVLOGGENERALDELTA: |
|
2918 | 2931 | gdelta = True |
|
2919 | 2932 | flags.append('generaldelta') |
|
2920 | 2933 | if not flags: |
|
2921 | 2934 | flags = ['(none)'] |
|
2922 | 2935 | |
|
2923 | 2936 | nummerges = 0 |
|
2924 | 2937 | numfull = 0 |
|
2925 | 2938 | numprev = 0 |
|
2926 | 2939 | nump1 = 0 |
|
2927 | 2940 | nump2 = 0 |
|
2928 | 2941 | numother = 0 |
|
2929 | 2942 | nump1prev = 0 |
|
2930 | 2943 | nump2prev = 0 |
|
2931 | 2944 | chainlengths = [] |
|
2932 | 2945 | |
|
2933 | 2946 | datasize = [None, 0, 0L] |
|
2934 | 2947 | fullsize = [None, 0, 0L] |
|
2935 | 2948 | deltasize = [None, 0, 0L] |
|
2936 | 2949 | |
|
2937 | 2950 | def addsize(size, l): |
|
2938 | 2951 | if l[0] is None or size < l[0]: |
|
2939 | 2952 | l[0] = size |
|
2940 | 2953 | if size > l[1]: |
|
2941 | 2954 | l[1] = size |
|
2942 | 2955 | l[2] += size |
|
2943 | 2956 | |
|
2944 | 2957 | numrevs = len(r) |
|
2945 | 2958 | for rev in xrange(numrevs): |
|
2946 | 2959 | p1, p2 = r.parentrevs(rev) |
|
2947 | 2960 | delta = r.deltaparent(rev) |
|
2948 | 2961 | if format > 0: |
|
2949 | 2962 | addsize(r.rawsize(rev), datasize) |
|
2950 | 2963 | if p2 != nullrev: |
|
2951 | 2964 | nummerges += 1 |
|
2952 | 2965 | size = r.length(rev) |
|
2953 | 2966 | if delta == nullrev: |
|
2954 | 2967 | chainlengths.append(0) |
|
2955 | 2968 | numfull += 1 |
|
2956 | 2969 | addsize(size, fullsize) |
|
2957 | 2970 | else: |
|
2958 | 2971 | chainlengths.append(chainlengths[delta] + 1) |
|
2959 | 2972 | addsize(size, deltasize) |
|
2960 | 2973 | if delta == rev - 1: |
|
2961 | 2974 | numprev += 1 |
|
2962 | 2975 | if delta == p1: |
|
2963 | 2976 | nump1prev += 1 |
|
2964 | 2977 | elif delta == p2: |
|
2965 | 2978 | nump2prev += 1 |
|
2966 | 2979 | elif delta == p1: |
|
2967 | 2980 | nump1 += 1 |
|
2968 | 2981 | elif delta == p2: |
|
2969 | 2982 | nump2 += 1 |
|
2970 | 2983 | elif delta != nullrev: |
|
2971 | 2984 | numother += 1 |
|
2972 | 2985 | |
|
2973 | 2986 | # Adjust size min value for empty cases |
|
2974 | 2987 | for size in (datasize, fullsize, deltasize): |
|
2975 | 2988 | if size[0] is None: |
|
2976 | 2989 | size[0] = 0 |
|
2977 | 2990 | |
|
2978 | 2991 | numdeltas = numrevs - numfull |
|
2979 | 2992 | numoprev = numprev - nump1prev - nump2prev |
|
2980 | 2993 | totalrawsize = datasize[2] |
|
2981 | 2994 | datasize[2] /= numrevs |
|
2982 | 2995 | fulltotal = fullsize[2] |
|
2983 | 2996 | fullsize[2] /= numfull |
|
2984 | 2997 | deltatotal = deltasize[2] |
|
2985 | 2998 | if numrevs - numfull > 0: |
|
2986 | 2999 | deltasize[2] /= numrevs - numfull |
|
2987 | 3000 | totalsize = fulltotal + deltatotal |
|
2988 | 3001 | avgchainlen = sum(chainlengths) / numrevs |
|
2989 | 3002 | maxchainlen = max(chainlengths) |
|
2990 | 3003 | compratio = totalrawsize / totalsize |
|
2991 | 3004 | |
|
2992 | 3005 | basedfmtstr = '%%%dd\n' |
|
2993 | 3006 | basepcfmtstr = '%%%dd %s(%%5.2f%%%%)\n' |
|
2994 | 3007 | |
|
2995 | 3008 | def dfmtstr(max): |
|
2996 | 3009 | return basedfmtstr % len(str(max)) |
|
2997 | 3010 | def pcfmtstr(max, padding=0): |
|
2998 | 3011 | return basepcfmtstr % (len(str(max)), ' ' * padding) |
|
2999 | 3012 | |
|
3000 | 3013 | def pcfmt(value, total): |
|
3001 | 3014 | return (value, 100 * float(value) / total) |
|
3002 | 3015 | |
|
3003 | 3016 | ui.write(('format : %d\n') % format) |
|
3004 | 3017 | ui.write(('flags : %s\n') % ', '.join(flags)) |
|
3005 | 3018 | |
|
3006 | 3019 | ui.write('\n') |
|
3007 | 3020 | fmt = pcfmtstr(totalsize) |
|
3008 | 3021 | fmt2 = dfmtstr(totalsize) |
|
3009 | 3022 | ui.write(('revisions : ') + fmt2 % numrevs) |
|
3010 | 3023 | ui.write((' merges : ') + fmt % pcfmt(nummerges, numrevs)) |
|
3011 | 3024 | ui.write((' normal : ') + fmt % pcfmt(numrevs - nummerges, numrevs)) |
|
3012 | 3025 | ui.write(('revisions : ') + fmt2 % numrevs) |
|
3013 | 3026 | ui.write((' full : ') + fmt % pcfmt(numfull, numrevs)) |
|
3014 | 3027 | ui.write((' deltas : ') + fmt % pcfmt(numdeltas, numrevs)) |
|
3015 | 3028 | ui.write(('revision size : ') + fmt2 % totalsize) |
|
3016 | 3029 | ui.write((' full : ') + fmt % pcfmt(fulltotal, totalsize)) |
|
3017 | 3030 | ui.write((' deltas : ') + fmt % pcfmt(deltatotal, totalsize)) |
|
3018 | 3031 | |
|
3019 | 3032 | ui.write('\n') |
|
3020 | 3033 | fmt = dfmtstr(max(avgchainlen, compratio)) |
|
3021 | 3034 | ui.write(('avg chain length : ') + fmt % avgchainlen) |
|
3022 | 3035 | ui.write(('max chain length : ') + fmt % maxchainlen) |
|
3023 | 3036 | ui.write(('compression ratio : ') + fmt % compratio) |
|
3024 | 3037 | |
|
3025 | 3038 | if format > 0: |
|
3026 | 3039 | ui.write('\n') |
|
3027 | 3040 | ui.write(('uncompressed data size (min/max/avg) : %d / %d / %d\n') |
|
3028 | 3041 | % tuple(datasize)) |
|
3029 | 3042 | ui.write(('full revision size (min/max/avg) : %d / %d / %d\n') |
|
3030 | 3043 | % tuple(fullsize)) |
|
3031 | 3044 | ui.write(('delta size (min/max/avg) : %d / %d / %d\n') |
|
3032 | 3045 | % tuple(deltasize)) |
|
3033 | 3046 | |
|
3034 | 3047 | if numdeltas > 0: |
|
3035 | 3048 | ui.write('\n') |
|
3036 | 3049 | fmt = pcfmtstr(numdeltas) |
|
3037 | 3050 | fmt2 = pcfmtstr(numdeltas, 4) |
|
3038 | 3051 | ui.write(('deltas against prev : ') + fmt % pcfmt(numprev, numdeltas)) |
|
3039 | 3052 | if numprev > 0: |
|
3040 | 3053 | ui.write((' where prev = p1 : ') + fmt2 % pcfmt(nump1prev, |
|
3041 | 3054 | numprev)) |
|
3042 | 3055 | ui.write((' where prev = p2 : ') + fmt2 % pcfmt(nump2prev, |
|
3043 | 3056 | numprev)) |
|
3044 | 3057 | ui.write((' other : ') + fmt2 % pcfmt(numoprev, |
|
3045 | 3058 | numprev)) |
|
3046 | 3059 | if gdelta: |
|
3047 | 3060 | ui.write(('deltas against p1 : ') |
|
3048 | 3061 | + fmt % pcfmt(nump1, numdeltas)) |
|
3049 | 3062 | ui.write(('deltas against p2 : ') |
|
3050 | 3063 | + fmt % pcfmt(nump2, numdeltas)) |
|
3051 | 3064 | ui.write(('deltas against other : ') + fmt % pcfmt(numother, |
|
3052 | 3065 | numdeltas)) |
|
3053 | 3066 | |
|
3054 | 3067 | @command('debugrevspec', |
|
3055 | 3068 | [('', 'optimize', None, _('print parsed tree after optimizing'))], |
|
3056 | 3069 | ('REVSPEC')) |
|
3057 | 3070 | def debugrevspec(ui, repo, expr, **opts): |
|
3058 | 3071 | """parse and apply a revision specification |
|
3059 | 3072 | |
|
3060 | 3073 | Use --verbose to print the parsed tree before and after aliases |
|
3061 | 3074 | expansion. |
|
3062 | 3075 | """ |
|
3063 | 3076 | if ui.verbose: |
|
3064 | 3077 | tree = revset.parse(expr, lookup=repo.__contains__) |
|
3065 | 3078 | ui.note(revset.prettyformat(tree), "\n") |
|
3066 | 3079 | newtree = revset.findaliases(ui, tree) |
|
3067 | 3080 | if newtree != tree: |
|
3068 | 3081 | ui.note(revset.prettyformat(newtree), "\n") |
|
3069 | 3082 | tree = newtree |
|
3070 | 3083 | newtree = revset.foldconcat(tree) |
|
3071 | 3084 | if newtree != tree: |
|
3072 | 3085 | ui.note(revset.prettyformat(newtree), "\n") |
|
3073 | 3086 | if opts["optimize"]: |
|
3074 | 3087 | weight, optimizedtree = revset.optimize(newtree, True) |
|
3075 | 3088 | ui.note("* optimized:\n", revset.prettyformat(optimizedtree), "\n") |
|
3076 | 3089 | func = revset.match(ui, expr, repo) |
|
3077 | 3090 | revs = func(repo) |
|
3078 | 3091 | if ui.verbose: |
|
3079 | 3092 | ui.note("* set:\n", revset.prettyformatset(revs), "\n") |
|
3080 | 3093 | for c in revs: |
|
3081 | 3094 | ui.write("%s\n" % c) |
|
3082 | 3095 | |
|
3083 | 3096 | @command('debugsetparents', [], _('REV1 [REV2]')) |
|
3084 | 3097 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
3085 | 3098 | """manually set the parents of the current working directory |
|
3086 | 3099 | |
|
3087 | 3100 | This is useful for writing repository conversion tools, but should |
|
3088 | 3101 | be used with care. For example, neither the working directory nor the |
|
3089 | 3102 | dirstate is updated, so file status may be incorrect after running this |
|
3090 | 3103 | command. |
|
3091 | 3104 | |
|
3092 | 3105 | Returns 0 on success. |
|
3093 | 3106 | """ |
|
3094 | 3107 | |
|
3095 | 3108 | r1 = scmutil.revsingle(repo, rev1).node() |
|
3096 | 3109 | r2 = scmutil.revsingle(repo, rev2, 'null').node() |
|
3097 | 3110 | |
|
3098 | 3111 | wlock = repo.wlock() |
|
3099 | 3112 | try: |
|
3100 | 3113 | repo.dirstate.beginparentchange() |
|
3101 | 3114 | repo.setparents(r1, r2) |
|
3102 | 3115 | repo.dirstate.endparentchange() |
|
3103 | 3116 | finally: |
|
3104 | 3117 | wlock.release() |
|
3105 | 3118 | |
|
3106 | 3119 | @command('debugdirstate|debugstate', |
|
3107 | 3120 | [('', 'nodates', None, _('do not display the saved mtime')), |
|
3108 | 3121 | ('', 'datesort', None, _('sort by saved mtime'))], |
|
3109 | 3122 | _('[OPTION]...')) |
|
3110 | 3123 | def debugstate(ui, repo, nodates=None, datesort=None): |
|
3111 | 3124 | """show the contents of the current dirstate""" |
|
3112 | 3125 | timestr = "" |
|
3113 | 3126 | if datesort: |
|
3114 | 3127 | keyfunc = lambda x: (x[1][3], x[0]) # sort by mtime, then by filename |
|
3115 | 3128 | else: |
|
3116 | 3129 | keyfunc = None # sort by filename |
|
3117 | 3130 | for file_, ent in sorted(repo.dirstate._map.iteritems(), key=keyfunc): |
|
3118 | 3131 | if ent[3] == -1: |
|
3119 | 3132 | timestr = 'unset ' |
|
3120 | 3133 | elif nodates: |
|
3121 | 3134 | timestr = 'set ' |
|
3122 | 3135 | else: |
|
3123 | 3136 | timestr = time.strftime("%Y-%m-%d %H:%M:%S ", |
|
3124 | 3137 | time.localtime(ent[3])) |
|
3125 | 3138 | if ent[1] & 0o20000: |
|
3126 | 3139 | mode = 'lnk' |
|
3127 | 3140 | else: |
|
3128 | 3141 | mode = '%3o' % (ent[1] & 0o777 & ~util.umask) |
|
3129 | 3142 | ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_)) |
|
3130 | 3143 | for f in repo.dirstate.copies(): |
|
3131 | 3144 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) |
|
3132 | 3145 | |
|
3133 | 3146 | @command('debugsub', |
|
3134 | 3147 | [('r', 'rev', '', |
|
3135 | 3148 | _('revision to check'), _('REV'))], |
|
3136 | 3149 | _('[-r REV] [REV]')) |
|
3137 | 3150 | def debugsub(ui, repo, rev=None): |
|
3138 | 3151 | ctx = scmutil.revsingle(repo, rev, None) |
|
3139 | 3152 | for k, v in sorted(ctx.substate.items()): |
|
3140 | 3153 | ui.write(('path %s\n') % k) |
|
3141 | 3154 | ui.write((' source %s\n') % v[0]) |
|
3142 | 3155 | ui.write((' revision %s\n') % v[1]) |
|
3143 | 3156 | |
|
3144 | 3157 | @command('debugsuccessorssets', |
|
3145 | 3158 | [], |
|
3146 | 3159 | _('[REV]')) |
|
3147 | 3160 | def debugsuccessorssets(ui, repo, *revs): |
|
3148 | 3161 | """show set of successors for revision |
|
3149 | 3162 | |
|
3150 | 3163 | A successors set of changeset A is a consistent group of revisions that |
|
3151 | 3164 | succeed A. It contains non-obsolete changesets only. |
|
3152 | 3165 | |
|
3153 | 3166 | In most cases a changeset A has a single successors set containing a single |
|
3154 | 3167 | successor (changeset A replaced by A'). |
|
3155 | 3168 | |
|
3156 | 3169 | A changeset that is made obsolete with no successors are called "pruned". |
|
3157 | 3170 | Such changesets have no successors sets at all. |
|
3158 | 3171 | |
|
3159 | 3172 | A changeset that has been "split" will have a successors set containing |
|
3160 | 3173 | more than one successor. |
|
3161 | 3174 | |
|
3162 | 3175 | A changeset that has been rewritten in multiple different ways is called |
|
3163 | 3176 | "divergent". Such changesets have multiple successor sets (each of which |
|
3164 | 3177 | may also be split, i.e. have multiple successors). |
|
3165 | 3178 | |
|
3166 | 3179 | Results are displayed as follows:: |
|
3167 | 3180 | |
|
3168 | 3181 | <rev1> |
|
3169 | 3182 | <successors-1A> |
|
3170 | 3183 | <rev2> |
|
3171 | 3184 | <successors-2A> |
|
3172 | 3185 | <successors-2B1> <successors-2B2> <successors-2B3> |
|
3173 | 3186 | |
|
3174 | 3187 | Here rev2 has two possible (i.e. divergent) successors sets. The first |
|
3175 | 3188 | holds one element, whereas the second holds three (i.e. the changeset has |
|
3176 | 3189 | been split). |
|
3177 | 3190 | """ |
|
3178 | 3191 | # passed to successorssets caching computation from one call to another |
|
3179 | 3192 | cache = {} |
|
3180 | 3193 | ctx2str = str |
|
3181 | 3194 | node2str = short |
|
3182 | 3195 | if ui.debug(): |
|
3183 | 3196 | def ctx2str(ctx): |
|
3184 | 3197 | return ctx.hex() |
|
3185 | 3198 | node2str = hex |
|
3186 | 3199 | for rev in scmutil.revrange(repo, revs): |
|
3187 | 3200 | ctx = repo[rev] |
|
3188 | 3201 | ui.write('%s\n'% ctx2str(ctx)) |
|
3189 | 3202 | for succsset in obsolete.successorssets(repo, ctx.node(), cache): |
|
3190 | 3203 | if succsset: |
|
3191 | 3204 | ui.write(' ') |
|
3192 | 3205 | ui.write(node2str(succsset[0])) |
|
3193 | 3206 | for node in succsset[1:]: |
|
3194 | 3207 | ui.write(' ') |
|
3195 | 3208 | ui.write(node2str(node)) |
|
3196 | 3209 | ui.write('\n') |
|
3197 | 3210 | |
|
3198 | 3211 | @command('debugwalk', walkopts, _('[OPTION]... [FILE]...'), inferrepo=True) |
|
3199 | 3212 | def debugwalk(ui, repo, *pats, **opts): |
|
3200 | 3213 | """show how files match on given patterns""" |
|
3201 | 3214 | m = scmutil.match(repo[None], pats, opts) |
|
3202 | 3215 | items = list(repo.walk(m)) |
|
3203 | 3216 | if not items: |
|
3204 | 3217 | return |
|
3205 | 3218 | f = lambda fn: fn |
|
3206 | 3219 | if ui.configbool('ui', 'slash') and os.sep != '/': |
|
3207 | 3220 | f = lambda fn: util.normpath(fn) |
|
3208 | 3221 | fmt = 'f %%-%ds %%-%ds %%s' % ( |
|
3209 | 3222 | max([len(abs) for abs in items]), |
|
3210 | 3223 | max([len(m.rel(abs)) for abs in items])) |
|
3211 | 3224 | for abs in items: |
|
3212 | 3225 | line = fmt % (abs, f(m.rel(abs)), m.exact(abs) and 'exact' or '') |
|
3213 | 3226 | ui.write("%s\n" % line.rstrip()) |
|
3214 | 3227 | |
|
3215 | 3228 | @command('debugwireargs', |
|
3216 | 3229 | [('', 'three', '', 'three'), |
|
3217 | 3230 | ('', 'four', '', 'four'), |
|
3218 | 3231 | ('', 'five', '', 'five'), |
|
3219 | 3232 | ] + remoteopts, |
|
3220 | 3233 | _('REPO [OPTIONS]... [ONE [TWO]]'), |
|
3221 | 3234 | norepo=True) |
|
3222 | 3235 | def debugwireargs(ui, repopath, *vals, **opts): |
|
3223 | 3236 | repo = hg.peer(ui, opts, repopath) |
|
3224 | 3237 | for opt in remoteopts: |
|
3225 | 3238 | del opts[opt[1]] |
|
3226 | 3239 | args = {} |
|
3227 | 3240 | for k, v in opts.iteritems(): |
|
3228 | 3241 | if v: |
|
3229 | 3242 | args[k] = v |
|
3230 | 3243 | # run twice to check that we don't mess up the stream for the next command |
|
3231 | 3244 | res1 = repo.debugwireargs(*vals, **args) |
|
3232 | 3245 | res2 = repo.debugwireargs(*vals, **args) |
|
3233 | 3246 | ui.write("%s\n" % res1) |
|
3234 | 3247 | if res1 != res2: |
|
3235 | 3248 | ui.warn("%s\n" % res2) |
|
3236 | 3249 | |
|
3237 | 3250 | @command('^diff', |
|
3238 | 3251 | [('r', 'rev', [], _('revision'), _('REV')), |
|
3239 | 3252 | ('c', 'change', '', _('change made by revision'), _('REV')) |
|
3240 | 3253 | ] + diffopts + diffopts2 + walkopts + subrepoopts, |
|
3241 | 3254 | _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'), |
|
3242 | 3255 | inferrepo=True) |
|
3243 | 3256 | def diff(ui, repo, *pats, **opts): |
|
3244 | 3257 | """diff repository (or selected files) |
|
3245 | 3258 | |
|
3246 | 3259 | Show differences between revisions for the specified files. |
|
3247 | 3260 | |
|
3248 | 3261 | Differences between files are shown using the unified diff format. |
|
3249 | 3262 | |
|
3250 | 3263 | .. note:: |
|
3251 | 3264 | |
|
3252 | 3265 | diff may generate unexpected results for merges, as it will |
|
3253 | 3266 | default to comparing against the working directory's first |
|
3254 | 3267 | parent changeset if no revisions are specified. |
|
3255 | 3268 | |
|
3256 | 3269 | When two revision arguments are given, then changes are shown |
|
3257 | 3270 | between those revisions. If only one revision is specified then |
|
3258 | 3271 | that revision is compared to the working directory, and, when no |
|
3259 | 3272 | revisions are specified, the working directory files are compared |
|
3260 | 3273 | to its parent. |
|
3261 | 3274 | |
|
3262 | 3275 | Alternatively you can specify -c/--change with a revision to see |
|
3263 | 3276 | the changes in that changeset relative to its first parent. |
|
3264 | 3277 | |
|
3265 | 3278 | Without the -a/--text option, diff will avoid generating diffs of |
|
3266 | 3279 | files it detects as binary. With -a, diff will generate a diff |
|
3267 | 3280 | anyway, probably with undesirable results. |
|
3268 | 3281 | |
|
3269 | 3282 | Use the -g/--git option to generate diffs in the git extended diff |
|
3270 | 3283 | format. For more information, read :hg:`help diffs`. |
|
3271 | 3284 | |
|
3272 | 3285 | .. container:: verbose |
|
3273 | 3286 | |
|
3274 | 3287 | Examples: |
|
3275 | 3288 | |
|
3276 | 3289 | - compare a file in the current working directory to its parent:: |
|
3277 | 3290 | |
|
3278 | 3291 | hg diff foo.c |
|
3279 | 3292 | |
|
3280 | 3293 | - compare two historical versions of a directory, with rename info:: |
|
3281 | 3294 | |
|
3282 | 3295 | hg diff --git -r 1.0:1.2 lib/ |
|
3283 | 3296 | |
|
3284 | 3297 | - get change stats relative to the last change on some date:: |
|
3285 | 3298 | |
|
3286 | 3299 | hg diff --stat -r "date('may 2')" |
|
3287 | 3300 | |
|
3288 | 3301 | - diff all newly-added files that contain a keyword:: |
|
3289 | 3302 | |
|
3290 | 3303 | hg diff "set:added() and grep(GNU)" |
|
3291 | 3304 | |
|
3292 | 3305 | - compare a revision and its parents:: |
|
3293 | 3306 | |
|
3294 | 3307 | hg diff -c 9353 # compare against first parent |
|
3295 | 3308 | hg diff -r 9353^:9353 # same using revset syntax |
|
3296 | 3309 | hg diff -r 9353^2:9353 # compare against the second parent |
|
3297 | 3310 | |
|
3298 | 3311 | Returns 0 on success. |
|
3299 | 3312 | """ |
|
3300 | 3313 | |
|
3301 | 3314 | revs = opts.get('rev') |
|
3302 | 3315 | change = opts.get('change') |
|
3303 | 3316 | stat = opts.get('stat') |
|
3304 | 3317 | reverse = opts.get('reverse') |
|
3305 | 3318 | |
|
3306 | 3319 | if revs and change: |
|
3307 | 3320 | msg = _('cannot specify --rev and --change at the same time') |
|
3308 | 3321 | raise util.Abort(msg) |
|
3309 | 3322 | elif change: |
|
3310 | 3323 | node2 = scmutil.revsingle(repo, change, None).node() |
|
3311 | 3324 | node1 = repo[node2].p1().node() |
|
3312 | 3325 | else: |
|
3313 | 3326 | node1, node2 = scmutil.revpair(repo, revs) |
|
3314 | 3327 | |
|
3315 | 3328 | if reverse: |
|
3316 | 3329 | node1, node2 = node2, node1 |
|
3317 | 3330 | |
|
3318 | 3331 | diffopts = patch.diffallopts(ui, opts) |
|
3319 | 3332 | m = scmutil.match(repo[node2], pats, opts) |
|
3320 | 3333 | cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, |
|
3321 | 3334 | listsubrepos=opts.get('subrepos'), |
|
3322 | 3335 | root=opts.get('root')) |
|
3323 | 3336 | |
|
3324 | 3337 | @command('^export', |
|
3325 | 3338 | [('o', 'output', '', |
|
3326 | 3339 | _('print output to file with formatted name'), _('FORMAT')), |
|
3327 | 3340 | ('', 'switch-parent', None, _('diff against the second parent')), |
|
3328 | 3341 | ('r', 'rev', [], _('revisions to export'), _('REV')), |
|
3329 | 3342 | ] + diffopts, |
|
3330 | 3343 | _('[OPTION]... [-o OUTFILESPEC] [-r] [REV]...')) |
|
3331 | 3344 | def export(ui, repo, *changesets, **opts): |
|
3332 | 3345 | """dump the header and diffs for one or more changesets |
|
3333 | 3346 | |
|
3334 | 3347 | Print the changeset header and diffs for one or more revisions. |
|
3335 | 3348 | If no revision is given, the parent of the working directory is used. |
|
3336 | 3349 | |
|
3337 | 3350 | The information shown in the changeset header is: author, date, |
|
3338 | 3351 | branch name (if non-default), changeset hash, parent(s) and commit |
|
3339 | 3352 | comment. |
|
3340 | 3353 | |
|
3341 | 3354 | .. note:: |
|
3342 | 3355 | |
|
3343 | 3356 | export may generate unexpected diff output for merge |
|
3344 | 3357 | changesets, as it will compare the merge changeset against its |
|
3345 | 3358 | first parent only. |
|
3346 | 3359 | |
|
3347 | 3360 | Output may be to a file, in which case the name of the file is |
|
3348 | 3361 | given using a format string. The formatting rules are as follows: |
|
3349 | 3362 | |
|
3350 | 3363 | :``%%``: literal "%" character |
|
3351 | 3364 | :``%H``: changeset hash (40 hexadecimal digits) |
|
3352 | 3365 | :``%N``: number of patches being generated |
|
3353 | 3366 | :``%R``: changeset revision number |
|
3354 | 3367 | :``%b``: basename of the exporting repository |
|
3355 | 3368 | :``%h``: short-form changeset hash (12 hexadecimal digits) |
|
3356 | 3369 | :``%m``: first line of the commit message (only alphanumeric characters) |
|
3357 | 3370 | :``%n``: zero-padded sequence number, starting at 1 |
|
3358 | 3371 | :``%r``: zero-padded changeset revision number |
|
3359 | 3372 | |
|
3360 | 3373 | Without the -a/--text option, export will avoid generating diffs |
|
3361 | 3374 | of files it detects as binary. With -a, export will generate a |
|
3362 | 3375 | diff anyway, probably with undesirable results. |
|
3363 | 3376 | |
|
3364 | 3377 | Use the -g/--git option to generate diffs in the git extended diff |
|
3365 | 3378 | format. See :hg:`help diffs` for more information. |
|
3366 | 3379 | |
|
3367 | 3380 | With the --switch-parent option, the diff will be against the |
|
3368 | 3381 | second parent. It can be useful to review a merge. |
|
3369 | 3382 | |
|
3370 | 3383 | .. container:: verbose |
|
3371 | 3384 | |
|
3372 | 3385 | Examples: |
|
3373 | 3386 | |
|
3374 | 3387 | - use export and import to transplant a bugfix to the current |
|
3375 | 3388 | branch:: |
|
3376 | 3389 | |
|
3377 | 3390 | hg export -r 9353 | hg import - |
|
3378 | 3391 | |
|
3379 | 3392 | - export all the changesets between two revisions to a file with |
|
3380 | 3393 | rename information:: |
|
3381 | 3394 | |
|
3382 | 3395 | hg export --git -r 123:150 > changes.txt |
|
3383 | 3396 | |
|
3384 | 3397 | - split outgoing changes into a series of patches with |
|
3385 | 3398 | descriptive names:: |
|
3386 | 3399 | |
|
3387 | 3400 | hg export -r "outgoing()" -o "%n-%m.patch" |
|
3388 | 3401 | |
|
3389 | 3402 | Returns 0 on success. |
|
3390 | 3403 | """ |
|
3391 | 3404 | changesets += tuple(opts.get('rev', [])) |
|
3392 | 3405 | if not changesets: |
|
3393 | 3406 | changesets = ['.'] |
|
3394 | 3407 | revs = scmutil.revrange(repo, changesets) |
|
3395 | 3408 | if not revs: |
|
3396 | 3409 | raise util.Abort(_("export requires at least one changeset")) |
|
3397 | 3410 | if len(revs) > 1: |
|
3398 | 3411 | ui.note(_('exporting patches:\n')) |
|
3399 | 3412 | else: |
|
3400 | 3413 | ui.note(_('exporting patch:\n')) |
|
3401 | 3414 | cmdutil.export(repo, revs, template=opts.get('output'), |
|
3402 | 3415 | switch_parent=opts.get('switch_parent'), |
|
3403 | 3416 | opts=patch.diffallopts(ui, opts)) |
|
3404 | 3417 | |
|
3405 | 3418 | @command('files', |
|
3406 | 3419 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), |
|
3407 | 3420 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
3408 | 3421 | ] + walkopts + formatteropts + subrepoopts, |
|
3409 | 3422 | _('[OPTION]... [PATTERN]...')) |
|
3410 | 3423 | def files(ui, repo, *pats, **opts): |
|
3411 | 3424 | """list tracked files |
|
3412 | 3425 | |
|
3413 | 3426 | Print files under Mercurial control in the working directory or |
|
3414 | 3427 | specified revision whose names match the given patterns (excluding |
|
3415 | 3428 | removed files). |
|
3416 | 3429 | |
|
3417 | 3430 | If no patterns are given to match, this command prints the names |
|
3418 | 3431 | of all files under Mercurial control in the working directory. |
|
3419 | 3432 | |
|
3420 | 3433 | .. container:: verbose |
|
3421 | 3434 | |
|
3422 | 3435 | Examples: |
|
3423 | 3436 | |
|
3424 | 3437 | - list all files under the current directory:: |
|
3425 | 3438 | |
|
3426 | 3439 | hg files . |
|
3427 | 3440 | |
|
3428 | 3441 | - shows sizes and flags for current revision:: |
|
3429 | 3442 | |
|
3430 | 3443 | hg files -vr . |
|
3431 | 3444 | |
|
3432 | 3445 | - list all files named README:: |
|
3433 | 3446 | |
|
3434 | 3447 | hg files -I "**/README" |
|
3435 | 3448 | |
|
3436 | 3449 | - list all binary files:: |
|
3437 | 3450 | |
|
3438 | 3451 | hg files "set:binary()" |
|
3439 | 3452 | |
|
3440 | 3453 | - find files containing a regular expression:: |
|
3441 | 3454 | |
|
3442 | 3455 | hg files "set:grep('bob')" |
|
3443 | 3456 | |
|
3444 | 3457 | - search tracked file contents with xargs and grep:: |
|
3445 | 3458 | |
|
3446 | 3459 | hg files -0 | xargs -0 grep foo |
|
3447 | 3460 | |
|
3448 | 3461 | See :hg:`help patterns` and :hg:`help filesets` for more information |
|
3449 | 3462 | on specifying file patterns. |
|
3450 | 3463 | |
|
3451 | 3464 | Returns 0 if a match is found, 1 otherwise. |
|
3452 | 3465 | |
|
3453 | 3466 | """ |
|
3454 | 3467 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) |
|
3455 | 3468 | |
|
3456 | 3469 | end = '\n' |
|
3457 | 3470 | if opts.get('print0'): |
|
3458 | 3471 | end = '\0' |
|
3459 | 3472 | fm = ui.formatter('files', opts) |
|
3460 | 3473 | fmt = '%s' + end |
|
3461 | 3474 | |
|
3462 | 3475 | m = scmutil.match(ctx, pats, opts) |
|
3463 | 3476 | ret = cmdutil.files(ui, ctx, m, fm, fmt, opts.get('subrepos')) |
|
3464 | 3477 | |
|
3465 | 3478 | fm.end() |
|
3466 | 3479 | |
|
3467 | 3480 | return ret |
|
3468 | 3481 | |
|
3469 | 3482 | @command('^forget', walkopts, _('[OPTION]... FILE...'), inferrepo=True) |
|
3470 | 3483 | def forget(ui, repo, *pats, **opts): |
|
3471 | 3484 | """forget the specified files on the next commit |
|
3472 | 3485 | |
|
3473 | 3486 | Mark the specified files so they will no longer be tracked |
|
3474 | 3487 | after the next commit. |
|
3475 | 3488 | |
|
3476 | 3489 | This only removes files from the current branch, not from the |
|
3477 | 3490 | entire project history, and it does not delete them from the |
|
3478 | 3491 | working directory. |
|
3479 | 3492 | |
|
3480 | 3493 | To delete the file from the working directory, see :hg:`remove`. |
|
3481 | 3494 | |
|
3482 | 3495 | To undo a forget before the next commit, see :hg:`add`. |
|
3483 | 3496 | |
|
3484 | 3497 | .. container:: verbose |
|
3485 | 3498 | |
|
3486 | 3499 | Examples: |
|
3487 | 3500 | |
|
3488 | 3501 | - forget newly-added binary files:: |
|
3489 | 3502 | |
|
3490 | 3503 | hg forget "set:added() and binary()" |
|
3491 | 3504 | |
|
3492 | 3505 | - forget files that would be excluded by .hgignore:: |
|
3493 | 3506 | |
|
3494 | 3507 | hg forget "set:hgignore()" |
|
3495 | 3508 | |
|
3496 | 3509 | Returns 0 on success. |
|
3497 | 3510 | """ |
|
3498 | 3511 | |
|
3499 | 3512 | if not pats: |
|
3500 | 3513 | raise util.Abort(_('no files specified')) |
|
3501 | 3514 | |
|
3502 | 3515 | m = scmutil.match(repo[None], pats, opts) |
|
3503 | 3516 | rejected = cmdutil.forget(ui, repo, m, prefix="", explicitonly=False)[0] |
|
3504 | 3517 | return rejected and 1 or 0 |
|
3505 | 3518 | |
|
3506 | 3519 | @command( |
|
3507 | 3520 | 'graft', |
|
3508 | 3521 | [('r', 'rev', [], _('revisions to graft'), _('REV')), |
|
3509 | 3522 | ('c', 'continue', False, _('resume interrupted graft')), |
|
3510 | 3523 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
3511 | 3524 | ('', 'log', None, _('append graft info to log message')), |
|
3512 | 3525 | ('f', 'force', False, _('force graft')), |
|
3513 | 3526 | ('D', 'currentdate', False, |
|
3514 | 3527 | _('record the current date as commit date')), |
|
3515 | 3528 | ('U', 'currentuser', False, |
|
3516 | 3529 | _('record the current user as committer'), _('DATE'))] |
|
3517 | 3530 | + commitopts2 + mergetoolopts + dryrunopts, |
|
3518 | 3531 | _('[OPTION]... [-r] REV...')) |
|
3519 | 3532 | def graft(ui, repo, *revs, **opts): |
|
3520 | 3533 | '''copy changes from other branches onto the current branch |
|
3521 | 3534 | |
|
3522 | 3535 | This command uses Mercurial's merge logic to copy individual |
|
3523 | 3536 | changes from other branches without merging branches in the |
|
3524 | 3537 | history graph. This is sometimes known as 'backporting' or |
|
3525 | 3538 | 'cherry-picking'. By default, graft will copy user, date, and |
|
3526 | 3539 | description from the source changesets. |
|
3527 | 3540 | |
|
3528 | 3541 | Changesets that are ancestors of the current revision, that have |
|
3529 | 3542 | already been grafted, or that are merges will be skipped. |
|
3530 | 3543 | |
|
3531 | 3544 | If --log is specified, log messages will have a comment appended |
|
3532 | 3545 | of the form:: |
|
3533 | 3546 | |
|
3534 | 3547 | (grafted from CHANGESETHASH) |
|
3535 | 3548 | |
|
3536 | 3549 | If --force is specified, revisions will be grafted even if they |
|
3537 | 3550 | are already ancestors of or have been grafted to the destination. |
|
3538 | 3551 | This is useful when the revisions have since been backed out. |
|
3539 | 3552 | |
|
3540 | 3553 | If a graft merge results in conflicts, the graft process is |
|
3541 | 3554 | interrupted so that the current merge can be manually resolved. |
|
3542 | 3555 | Once all conflicts are addressed, the graft process can be |
|
3543 | 3556 | continued with the -c/--continue option. |
|
3544 | 3557 | |
|
3545 | 3558 | .. note:: |
|
3546 | 3559 | |
|
3547 | 3560 | The -c/--continue option does not reapply earlier options, except |
|
3548 | 3561 | for --force. |
|
3549 | 3562 | |
|
3550 | 3563 | .. container:: verbose |
|
3551 | 3564 | |
|
3552 | 3565 | Examples: |
|
3553 | 3566 | |
|
3554 | 3567 | - copy a single change to the stable branch and edit its description:: |
|
3555 | 3568 | |
|
3556 | 3569 | hg update stable |
|
3557 | 3570 | hg graft --edit 9393 |
|
3558 | 3571 | |
|
3559 | 3572 | - graft a range of changesets with one exception, updating dates:: |
|
3560 | 3573 | |
|
3561 | 3574 | hg graft -D "2085::2093 and not 2091" |
|
3562 | 3575 | |
|
3563 | 3576 | - continue a graft after resolving conflicts:: |
|
3564 | 3577 | |
|
3565 | 3578 | hg graft -c |
|
3566 | 3579 | |
|
3567 | 3580 | - show the source of a grafted changeset:: |
|
3568 | 3581 | |
|
3569 | 3582 | hg log --debug -r . |
|
3570 | 3583 | |
|
3571 | 3584 | See :hg:`help revisions` and :hg:`help revsets` for more about |
|
3572 | 3585 | specifying revisions. |
|
3573 | 3586 | |
|
3574 | 3587 | Returns 0 on successful completion. |
|
3575 | 3588 | ''' |
|
3576 | 3589 | |
|
3577 | 3590 | revs = list(revs) |
|
3578 | 3591 | revs.extend(opts['rev']) |
|
3579 | 3592 | |
|
3580 | 3593 | if not opts.get('user') and opts.get('currentuser'): |
|
3581 | 3594 | opts['user'] = ui.username() |
|
3582 | 3595 | if not opts.get('date') and opts.get('currentdate'): |
|
3583 | 3596 | opts['date'] = "%d %d" % util.makedate() |
|
3584 | 3597 | |
|
3585 | 3598 | editor = cmdutil.getcommiteditor(editform='graft', **opts) |
|
3586 | 3599 | |
|
3587 | 3600 | cont = False |
|
3588 | 3601 | if opts['continue']: |
|
3589 | 3602 | cont = True |
|
3590 | 3603 | if revs: |
|
3591 | 3604 | raise util.Abort(_("can't specify --continue and revisions")) |
|
3592 | 3605 | # read in unfinished revisions |
|
3593 | 3606 | try: |
|
3594 | 3607 | nodes = repo.vfs.read('graftstate').splitlines() |
|
3595 | 3608 | revs = [repo[node].rev() for node in nodes] |
|
3596 | 3609 | except IOError as inst: |
|
3597 | 3610 | if inst.errno != errno.ENOENT: |
|
3598 | 3611 | raise |
|
3599 | 3612 | raise util.Abort(_("no graft state found, can't continue")) |
|
3600 | 3613 | else: |
|
3601 | 3614 | cmdutil.checkunfinished(repo) |
|
3602 | 3615 | cmdutil.bailifchanged(repo) |
|
3603 | 3616 | if not revs: |
|
3604 | 3617 | raise util.Abort(_('no revisions specified')) |
|
3605 | 3618 | revs = scmutil.revrange(repo, revs) |
|
3606 | 3619 | |
|
3607 | 3620 | skipped = set() |
|
3608 | 3621 | # check for merges |
|
3609 | 3622 | for rev in repo.revs('%ld and merge()', revs): |
|
3610 | 3623 | ui.warn(_('skipping ungraftable merge revision %s\n') % rev) |
|
3611 | 3624 | skipped.add(rev) |
|
3612 | 3625 | revs = [r for r in revs if r not in skipped] |
|
3613 | 3626 | if not revs: |
|
3614 | 3627 | return -1 |
|
3615 | 3628 | |
|
3616 | 3629 | # Don't check in the --continue case, in effect retaining --force across |
|
3617 | 3630 | # --continues. That's because without --force, any revisions we decided to |
|
3618 | 3631 | # skip would have been filtered out here, so they wouldn't have made their |
|
3619 | 3632 | # way to the graftstate. With --force, any revisions we would have otherwise |
|
3620 | 3633 | # skipped would not have been filtered out, and if they hadn't been applied |
|
3621 | 3634 | # already, they'd have been in the graftstate. |
|
3622 | 3635 | if not (cont or opts.get('force')): |
|
3623 | 3636 | # check for ancestors of dest branch |
|
3624 | 3637 | crev = repo['.'].rev() |
|
3625 | 3638 | ancestors = repo.changelog.ancestors([crev], inclusive=True) |
|
3626 | 3639 | # Cannot use x.remove(y) on smart set, this has to be a list. |
|
3627 | 3640 | # XXX make this lazy in the future |
|
3628 | 3641 | revs = list(revs) |
|
3629 | 3642 | # don't mutate while iterating, create a copy |
|
3630 | 3643 | for rev in list(revs): |
|
3631 | 3644 | if rev in ancestors: |
|
3632 | 3645 | ui.warn(_('skipping ancestor revision %d:%s\n') % |
|
3633 | 3646 | (rev, repo[rev])) |
|
3634 | 3647 | # XXX remove on list is slow |
|
3635 | 3648 | revs.remove(rev) |
|
3636 | 3649 | if not revs: |
|
3637 | 3650 | return -1 |
|
3638 | 3651 | |
|
3639 | 3652 | # analyze revs for earlier grafts |
|
3640 | 3653 | ids = {} |
|
3641 | 3654 | for ctx in repo.set("%ld", revs): |
|
3642 | 3655 | ids[ctx.hex()] = ctx.rev() |
|
3643 | 3656 | n = ctx.extra().get('source') |
|
3644 | 3657 | if n: |
|
3645 | 3658 | ids[n] = ctx.rev() |
|
3646 | 3659 | |
|
3647 | 3660 | # check ancestors for earlier grafts |
|
3648 | 3661 | ui.debug('scanning for duplicate grafts\n') |
|
3649 | 3662 | |
|
3650 | 3663 | for rev in repo.changelog.findmissingrevs(revs, [crev]): |
|
3651 | 3664 | ctx = repo[rev] |
|
3652 | 3665 | n = ctx.extra().get('source') |
|
3653 | 3666 | if n in ids: |
|
3654 | 3667 | try: |
|
3655 | 3668 | r = repo[n].rev() |
|
3656 | 3669 | except error.RepoLookupError: |
|
3657 | 3670 | r = None |
|
3658 | 3671 | if r in revs: |
|
3659 | 3672 | ui.warn(_('skipping revision %d:%s ' |
|
3660 | 3673 | '(already grafted to %d:%s)\n') |
|
3661 | 3674 | % (r, repo[r], rev, ctx)) |
|
3662 | 3675 | revs.remove(r) |
|
3663 | 3676 | elif ids[n] in revs: |
|
3664 | 3677 | if r is None: |
|
3665 | 3678 | ui.warn(_('skipping already grafted revision %d:%s ' |
|
3666 | 3679 | '(%d:%s also has unknown origin %s)\n') |
|
3667 | 3680 | % (ids[n], repo[ids[n]], rev, ctx, n[:12])) |
|
3668 | 3681 | else: |
|
3669 | 3682 | ui.warn(_('skipping already grafted revision %d:%s ' |
|
3670 | 3683 | '(%d:%s also has origin %d:%s)\n') |
|
3671 | 3684 | % (ids[n], repo[ids[n]], rev, ctx, r, n[:12])) |
|
3672 | 3685 | revs.remove(ids[n]) |
|
3673 | 3686 | elif ctx.hex() in ids: |
|
3674 | 3687 | r = ids[ctx.hex()] |
|
3675 | 3688 | ui.warn(_('skipping already grafted revision %d:%s ' |
|
3676 | 3689 | '(was grafted from %d:%s)\n') % |
|
3677 | 3690 | (r, repo[r], rev, ctx)) |
|
3678 | 3691 | revs.remove(r) |
|
3679 | 3692 | if not revs: |
|
3680 | 3693 | return -1 |
|
3681 | 3694 | |
|
3682 | 3695 | wlock = repo.wlock() |
|
3683 | 3696 | try: |
|
3684 | 3697 | for pos, ctx in enumerate(repo.set("%ld", revs)): |
|
3685 | 3698 | desc = '%d:%s "%s"' % (ctx.rev(), ctx, |
|
3686 | 3699 | ctx.description().split('\n', 1)[0]) |
|
3687 | 3700 | names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node()) |
|
3688 | 3701 | if names: |
|
3689 | 3702 | desc += ' (%s)' % ' '.join(names) |
|
3690 | 3703 | ui.status(_('grafting %s\n') % desc) |
|
3691 | 3704 | if opts.get('dry_run'): |
|
3692 | 3705 | continue |
|
3693 | 3706 | |
|
3694 | 3707 | source = ctx.extra().get('source') |
|
3695 | 3708 | extra = {} |
|
3696 | 3709 | if source: |
|
3697 | 3710 | extra['source'] = source |
|
3698 | 3711 | extra['intermediate-source'] = ctx.hex() |
|
3699 | 3712 | else: |
|
3700 | 3713 | extra['source'] = ctx.hex() |
|
3701 | 3714 | user = ctx.user() |
|
3702 | 3715 | if opts.get('user'): |
|
3703 | 3716 | user = opts['user'] |
|
3704 | 3717 | date = ctx.date() |
|
3705 | 3718 | if opts.get('date'): |
|
3706 | 3719 | date = opts['date'] |
|
3707 | 3720 | message = ctx.description() |
|
3708 | 3721 | if opts.get('log'): |
|
3709 | 3722 | message += '\n(grafted from %s)' % ctx.hex() |
|
3710 | 3723 | |
|
3711 | 3724 | # we don't merge the first commit when continuing |
|
3712 | 3725 | if not cont: |
|
3713 | 3726 | # perform the graft merge with p1(rev) as 'ancestor' |
|
3714 | 3727 | try: |
|
3715 | 3728 | # ui.forcemerge is an internal variable, do not document |
|
3716 | 3729 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
3717 | 3730 | 'graft') |
|
3718 | 3731 | stats = mergemod.graft(repo, ctx, ctx.p1(), |
|
3719 | 3732 | ['local', 'graft']) |
|
3720 | 3733 | finally: |
|
3721 | 3734 | repo.ui.setconfig('ui', 'forcemerge', '', 'graft') |
|
3722 | 3735 | # report any conflicts |
|
3723 | 3736 | if stats and stats[3] > 0: |
|
3724 | 3737 | # write out state for --continue |
|
3725 | 3738 | nodelines = [repo[rev].hex() + "\n" for rev in revs[pos:]] |
|
3726 | 3739 | repo.vfs.write('graftstate', ''.join(nodelines)) |
|
3727 | 3740 | raise util.Abort( |
|
3728 | 3741 | _("unresolved conflicts, can't continue"), |
|
3729 | 3742 | hint=_('use hg resolve and hg graft --continue')) |
|
3730 | 3743 | else: |
|
3731 | 3744 | cont = False |
|
3732 | 3745 | |
|
3733 | 3746 | # commit |
|
3734 | 3747 | node = repo.commit(text=message, user=user, |
|
3735 | 3748 | date=date, extra=extra, editor=editor) |
|
3736 | 3749 | if node is None: |
|
3737 | 3750 | ui.warn( |
|
3738 | 3751 | _('note: graft of %d:%s created no changes to commit\n') % |
|
3739 | 3752 | (ctx.rev(), ctx)) |
|
3740 | 3753 | finally: |
|
3741 | 3754 | wlock.release() |
|
3742 | 3755 | |
|
3743 | 3756 | # remove state when we complete successfully |
|
3744 | 3757 | if not opts.get('dry_run'): |
|
3745 | 3758 | util.unlinkpath(repo.join('graftstate'), ignoremissing=True) |
|
3746 | 3759 | |
|
3747 | 3760 | return 0 |
|
3748 | 3761 | |
|
3749 | 3762 | @command('grep', |
|
3750 | 3763 | [('0', 'print0', None, _('end fields with NUL')), |
|
3751 | 3764 | ('', 'all', None, _('print all revisions that match')), |
|
3752 | 3765 | ('a', 'text', None, _('treat all files as text')), |
|
3753 | 3766 | ('f', 'follow', None, |
|
3754 | 3767 | _('follow changeset history,' |
|
3755 | 3768 | ' or file history across copies and renames')), |
|
3756 | 3769 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
3757 | 3770 | ('l', 'files-with-matches', None, |
|
3758 | 3771 | _('print only filenames and revisions that match')), |
|
3759 | 3772 | ('n', 'line-number', None, _('print matching line numbers')), |
|
3760 | 3773 | ('r', 'rev', [], |
|
3761 | 3774 | _('only search files changed within revision range'), _('REV')), |
|
3762 | 3775 | ('u', 'user', None, _('list the author (long with -v)')), |
|
3763 | 3776 | ('d', 'date', None, _('list the date (short with -q)')), |
|
3764 | 3777 | ] + walkopts, |
|
3765 | 3778 | _('[OPTION]... PATTERN [FILE]...'), |
|
3766 | 3779 | inferrepo=True) |
|
3767 | 3780 | def grep(ui, repo, pattern, *pats, **opts): |
|
3768 | 3781 | """search for a pattern in specified files and revisions |
|
3769 | 3782 | |
|
3770 | 3783 | Search revisions of files for a regular expression. |
|
3771 | 3784 | |
|
3772 | 3785 | This command behaves differently than Unix grep. It only accepts |
|
3773 | 3786 | Python/Perl regexps. It searches repository history, not the |
|
3774 | 3787 | working directory. It always prints the revision number in which a |
|
3775 | 3788 | match appears. |
|
3776 | 3789 | |
|
3777 | 3790 | By default, grep only prints output for the first revision of a |
|
3778 | 3791 | file in which it finds a match. To get it to print every revision |
|
3779 | 3792 | that contains a change in match status ("-" for a match that |
|
3780 | 3793 | becomes a non-match, or "+" for a non-match that becomes a match), |
|
3781 | 3794 | use the --all flag. |
|
3782 | 3795 | |
|
3783 | 3796 | Returns 0 if a match is found, 1 otherwise. |
|
3784 | 3797 | """ |
|
3785 | 3798 | reflags = re.M |
|
3786 | 3799 | if opts.get('ignore_case'): |
|
3787 | 3800 | reflags |= re.I |
|
3788 | 3801 | try: |
|
3789 | 3802 | regexp = util.re.compile(pattern, reflags) |
|
3790 | 3803 | except re.error as inst: |
|
3791 | 3804 | ui.warn(_("grep: invalid match pattern: %s\n") % inst) |
|
3792 | 3805 | return 1 |
|
3793 | 3806 | sep, eol = ':', '\n' |
|
3794 | 3807 | if opts.get('print0'): |
|
3795 | 3808 | sep = eol = '\0' |
|
3796 | 3809 | |
|
3797 | 3810 | getfile = util.lrucachefunc(repo.file) |
|
3798 | 3811 | |
|
3799 | 3812 | def matchlines(body): |
|
3800 | 3813 | begin = 0 |
|
3801 | 3814 | linenum = 0 |
|
3802 | 3815 | while begin < len(body): |
|
3803 | 3816 | match = regexp.search(body, begin) |
|
3804 | 3817 | if not match: |
|
3805 | 3818 | break |
|
3806 | 3819 | mstart, mend = match.span() |
|
3807 | 3820 | linenum += body.count('\n', begin, mstart) + 1 |
|
3808 | 3821 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
3809 | 3822 | begin = body.find('\n', mend) + 1 or len(body) + 1 |
|
3810 | 3823 | lend = begin - 1 |
|
3811 | 3824 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
3812 | 3825 | |
|
3813 | 3826 | class linestate(object): |
|
3814 | 3827 | def __init__(self, line, linenum, colstart, colend): |
|
3815 | 3828 | self.line = line |
|
3816 | 3829 | self.linenum = linenum |
|
3817 | 3830 | self.colstart = colstart |
|
3818 | 3831 | self.colend = colend |
|
3819 | 3832 | |
|
3820 | 3833 | def __hash__(self): |
|
3821 | 3834 | return hash((self.linenum, self.line)) |
|
3822 | 3835 | |
|
3823 | 3836 | def __eq__(self, other): |
|
3824 | 3837 | return self.line == other.line |
|
3825 | 3838 | |
|
3826 | 3839 | def __iter__(self): |
|
3827 | 3840 | yield (self.line[:self.colstart], '') |
|
3828 | 3841 | yield (self.line[self.colstart:self.colend], 'grep.match') |
|
3829 | 3842 | rest = self.line[self.colend:] |
|
3830 | 3843 | while rest != '': |
|
3831 | 3844 | match = regexp.search(rest) |
|
3832 | 3845 | if not match: |
|
3833 | 3846 | yield (rest, '') |
|
3834 | 3847 | break |
|
3835 | 3848 | mstart, mend = match.span() |
|
3836 | 3849 | yield (rest[:mstart], '') |
|
3837 | 3850 | yield (rest[mstart:mend], 'grep.match') |
|
3838 | 3851 | rest = rest[mend:] |
|
3839 | 3852 | |
|
3840 | 3853 | matches = {} |
|
3841 | 3854 | copies = {} |
|
3842 | 3855 | def grepbody(fn, rev, body): |
|
3843 | 3856 | matches[rev].setdefault(fn, []) |
|
3844 | 3857 | m = matches[rev][fn] |
|
3845 | 3858 | for lnum, cstart, cend, line in matchlines(body): |
|
3846 | 3859 | s = linestate(line, lnum, cstart, cend) |
|
3847 | 3860 | m.append(s) |
|
3848 | 3861 | |
|
3849 | 3862 | def difflinestates(a, b): |
|
3850 | 3863 | sm = difflib.SequenceMatcher(None, a, b) |
|
3851 | 3864 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): |
|
3852 | 3865 | if tag == 'insert': |
|
3853 | 3866 | for i in xrange(blo, bhi): |
|
3854 | 3867 | yield ('+', b[i]) |
|
3855 | 3868 | elif tag == 'delete': |
|
3856 | 3869 | for i in xrange(alo, ahi): |
|
3857 | 3870 | yield ('-', a[i]) |
|
3858 | 3871 | elif tag == 'replace': |
|
3859 | 3872 | for i in xrange(alo, ahi): |
|
3860 | 3873 | yield ('-', a[i]) |
|
3861 | 3874 | for i in xrange(blo, bhi): |
|
3862 | 3875 | yield ('+', b[i]) |
|
3863 | 3876 | |
|
3864 | 3877 | def display(fn, ctx, pstates, states): |
|
3865 | 3878 | rev = ctx.rev() |
|
3866 | 3879 | if ui.quiet: |
|
3867 | 3880 | datefunc = util.shortdate |
|
3868 | 3881 | else: |
|
3869 | 3882 | datefunc = util.datestr |
|
3870 | 3883 | found = False |
|
3871 | 3884 | @util.cachefunc |
|
3872 | 3885 | def binary(): |
|
3873 | 3886 | flog = getfile(fn) |
|
3874 | 3887 | return util.binary(flog.read(ctx.filenode(fn))) |
|
3875 | 3888 | |
|
3876 | 3889 | if opts.get('all'): |
|
3877 | 3890 | iter = difflinestates(pstates, states) |
|
3878 | 3891 | else: |
|
3879 | 3892 | iter = [('', l) for l in states] |
|
3880 | 3893 | for change, l in iter: |
|
3881 | 3894 | cols = [(fn, 'grep.filename'), (str(rev), 'grep.rev')] |
|
3882 | 3895 | |
|
3883 | 3896 | if opts.get('line_number'): |
|
3884 | 3897 | cols.append((str(l.linenum), 'grep.linenumber')) |
|
3885 | 3898 | if opts.get('all'): |
|
3886 | 3899 | cols.append((change, 'grep.change')) |
|
3887 | 3900 | if opts.get('user'): |
|
3888 | 3901 | cols.append((ui.shortuser(ctx.user()), 'grep.user')) |
|
3889 | 3902 | if opts.get('date'): |
|
3890 | 3903 | cols.append((datefunc(ctx.date()), 'grep.date')) |
|
3891 | 3904 | for col, label in cols[:-1]: |
|
3892 | 3905 | ui.write(col, label=label) |
|
3893 | 3906 | ui.write(sep, label='grep.sep') |
|
3894 | 3907 | ui.write(cols[-1][0], label=cols[-1][1]) |
|
3895 | 3908 | if not opts.get('files_with_matches'): |
|
3896 | 3909 | ui.write(sep, label='grep.sep') |
|
3897 | 3910 | if not opts.get('text') and binary(): |
|
3898 | 3911 | ui.write(" Binary file matches") |
|
3899 | 3912 | else: |
|
3900 | 3913 | for s, label in l: |
|
3901 | 3914 | ui.write(s, label=label) |
|
3902 | 3915 | ui.write(eol) |
|
3903 | 3916 | found = True |
|
3904 | 3917 | if opts.get('files_with_matches'): |
|
3905 | 3918 | break |
|
3906 | 3919 | return found |
|
3907 | 3920 | |
|
3908 | 3921 | skip = {} |
|
3909 | 3922 | revfiles = {} |
|
3910 | 3923 | matchfn = scmutil.match(repo[None], pats, opts) |
|
3911 | 3924 | found = False |
|
3912 | 3925 | follow = opts.get('follow') |
|
3913 | 3926 | |
|
3914 | 3927 | def prep(ctx, fns): |
|
3915 | 3928 | rev = ctx.rev() |
|
3916 | 3929 | pctx = ctx.p1() |
|
3917 | 3930 | parent = pctx.rev() |
|
3918 | 3931 | matches.setdefault(rev, {}) |
|
3919 | 3932 | matches.setdefault(parent, {}) |
|
3920 | 3933 | files = revfiles.setdefault(rev, []) |
|
3921 | 3934 | for fn in fns: |
|
3922 | 3935 | flog = getfile(fn) |
|
3923 | 3936 | try: |
|
3924 | 3937 | fnode = ctx.filenode(fn) |
|
3925 | 3938 | except error.LookupError: |
|
3926 | 3939 | continue |
|
3927 | 3940 | |
|
3928 | 3941 | copied = flog.renamed(fnode) |
|
3929 | 3942 | copy = follow and copied and copied[0] |
|
3930 | 3943 | if copy: |
|
3931 | 3944 | copies.setdefault(rev, {})[fn] = copy |
|
3932 | 3945 | if fn in skip: |
|
3933 | 3946 | if copy: |
|
3934 | 3947 | skip[copy] = True |
|
3935 | 3948 | continue |
|
3936 | 3949 | files.append(fn) |
|
3937 | 3950 | |
|
3938 | 3951 | if fn not in matches[rev]: |
|
3939 | 3952 | grepbody(fn, rev, flog.read(fnode)) |
|
3940 | 3953 | |
|
3941 | 3954 | pfn = copy or fn |
|
3942 | 3955 | if pfn not in matches[parent]: |
|
3943 | 3956 | try: |
|
3944 | 3957 | fnode = pctx.filenode(pfn) |
|
3945 | 3958 | grepbody(pfn, parent, flog.read(fnode)) |
|
3946 | 3959 | except error.LookupError: |
|
3947 | 3960 | pass |
|
3948 | 3961 | |
|
3949 | 3962 | for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep): |
|
3950 | 3963 | rev = ctx.rev() |
|
3951 | 3964 | parent = ctx.p1().rev() |
|
3952 | 3965 | for fn in sorted(revfiles.get(rev, [])): |
|
3953 | 3966 | states = matches[rev][fn] |
|
3954 | 3967 | copy = copies.get(rev, {}).get(fn) |
|
3955 | 3968 | if fn in skip: |
|
3956 | 3969 | if copy: |
|
3957 | 3970 | skip[copy] = True |
|
3958 | 3971 | continue |
|
3959 | 3972 | pstates = matches.get(parent, {}).get(copy or fn, []) |
|
3960 | 3973 | if pstates or states: |
|
3961 | 3974 | r = display(fn, ctx, pstates, states) |
|
3962 | 3975 | found = found or r |
|
3963 | 3976 | if r and not opts.get('all'): |
|
3964 | 3977 | skip[fn] = True |
|
3965 | 3978 | if copy: |
|
3966 | 3979 | skip[copy] = True |
|
3967 | 3980 | del matches[rev] |
|
3968 | 3981 | del revfiles[rev] |
|
3969 | 3982 | |
|
3970 | 3983 | return not found |
|
3971 | 3984 | |
|
3972 | 3985 | @command('heads', |
|
3973 | 3986 | [('r', 'rev', '', |
|
3974 | 3987 | _('show only heads which are descendants of STARTREV'), _('STARTREV')), |
|
3975 | 3988 | ('t', 'topo', False, _('show topological heads only')), |
|
3976 | 3989 | ('a', 'active', False, _('show active branchheads only (DEPRECATED)')), |
|
3977 | 3990 | ('c', 'closed', False, _('show normal and closed branch heads')), |
|
3978 | 3991 | ] + templateopts, |
|
3979 | 3992 | _('[-ct] [-r STARTREV] [REV]...')) |
|
3980 | 3993 | def heads(ui, repo, *branchrevs, **opts): |
|
3981 | 3994 | """show branch heads |
|
3982 | 3995 | |
|
3983 | 3996 | With no arguments, show all open branch heads in the repository. |
|
3984 | 3997 | Branch heads are changesets that have no descendants on the |
|
3985 | 3998 | same branch. They are where development generally takes place and |
|
3986 | 3999 | are the usual targets for update and merge operations. |
|
3987 | 4000 | |
|
3988 | 4001 | If one or more REVs are given, only open branch heads on the |
|
3989 | 4002 | branches associated with the specified changesets are shown. This |
|
3990 | 4003 | means that you can use :hg:`heads .` to see the heads on the |
|
3991 | 4004 | currently checked-out branch. |
|
3992 | 4005 | |
|
3993 | 4006 | If -c/--closed is specified, also show branch heads marked closed |
|
3994 | 4007 | (see :hg:`commit --close-branch`). |
|
3995 | 4008 | |
|
3996 | 4009 | If STARTREV is specified, only those heads that are descendants of |
|
3997 | 4010 | STARTREV will be displayed. |
|
3998 | 4011 | |
|
3999 | 4012 | If -t/--topo is specified, named branch mechanics will be ignored and only |
|
4000 | 4013 | topological heads (changesets with no children) will be shown. |
|
4001 | 4014 | |
|
4002 | 4015 | Returns 0 if matching heads are found, 1 if not. |
|
4003 | 4016 | """ |
|
4004 | 4017 | |
|
4005 | 4018 | start = None |
|
4006 | 4019 | if 'rev' in opts: |
|
4007 | 4020 | start = scmutil.revsingle(repo, opts['rev'], None).node() |
|
4008 | 4021 | |
|
4009 | 4022 | if opts.get('topo'): |
|
4010 | 4023 | heads = [repo[h] for h in repo.heads(start)] |
|
4011 | 4024 | else: |
|
4012 | 4025 | heads = [] |
|
4013 | 4026 | for branch in repo.branchmap(): |
|
4014 | 4027 | heads += repo.branchheads(branch, start, opts.get('closed')) |
|
4015 | 4028 | heads = [repo[h] for h in heads] |
|
4016 | 4029 | |
|
4017 | 4030 | if branchrevs: |
|
4018 | 4031 | branches = set(repo[br].branch() for br in branchrevs) |
|
4019 | 4032 | heads = [h for h in heads if h.branch() in branches] |
|
4020 | 4033 | |
|
4021 | 4034 | if opts.get('active') and branchrevs: |
|
4022 | 4035 | dagheads = repo.heads(start) |
|
4023 | 4036 | heads = [h for h in heads if h.node() in dagheads] |
|
4024 | 4037 | |
|
4025 | 4038 | if branchrevs: |
|
4026 | 4039 | haveheads = set(h.branch() for h in heads) |
|
4027 | 4040 | if branches - haveheads: |
|
4028 | 4041 | headless = ', '.join(b for b in branches - haveheads) |
|
4029 | 4042 | msg = _('no open branch heads found on branches %s') |
|
4030 | 4043 | if opts.get('rev'): |
|
4031 | 4044 | msg += _(' (started at %s)') % opts['rev'] |
|
4032 | 4045 | ui.warn((msg + '\n') % headless) |
|
4033 | 4046 | |
|
4034 | 4047 | if not heads: |
|
4035 | 4048 | return 1 |
|
4036 | 4049 | |
|
4037 | 4050 | heads = sorted(heads, key=lambda x: -x.rev()) |
|
4038 | 4051 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
4039 | 4052 | for ctx in heads: |
|
4040 | 4053 | displayer.show(ctx) |
|
4041 | 4054 | displayer.close() |
|
4042 | 4055 | |
|
4043 | 4056 | @command('help', |
|
4044 | 4057 | [('e', 'extension', None, _('show only help for extensions')), |
|
4045 | 4058 | ('c', 'command', None, _('show only help for commands')), |
|
4046 | 4059 | ('k', 'keyword', None, _('show topics matching keyword')), |
|
4047 | 4060 | ], |
|
4048 | 4061 | _('[-eck] [TOPIC]'), |
|
4049 | 4062 | norepo=True) |
|
4050 | 4063 | def help_(ui, name=None, **opts): |
|
4051 | 4064 | """show help for a given topic or a help overview |
|
4052 | 4065 | |
|
4053 | 4066 | With no arguments, print a list of commands with short help messages. |
|
4054 | 4067 | |
|
4055 | 4068 | Given a topic, extension, or command name, print help for that |
|
4056 | 4069 | topic. |
|
4057 | 4070 | |
|
4058 | 4071 | Returns 0 if successful. |
|
4059 | 4072 | """ |
|
4060 | 4073 | |
|
4061 | 4074 | textwidth = min(ui.termwidth(), 80) - 2 |
|
4062 | 4075 | |
|
4063 | 4076 | keep = [] |
|
4064 | 4077 | if ui.verbose: |
|
4065 | 4078 | keep.append('verbose') |
|
4066 | 4079 | if sys.platform.startswith('win'): |
|
4067 | 4080 | keep.append('windows') |
|
4068 | 4081 | elif sys.platform == 'OpenVMS': |
|
4069 | 4082 | keep.append('vms') |
|
4070 | 4083 | elif sys.platform == 'plan9': |
|
4071 | 4084 | keep.append('plan9') |
|
4072 | 4085 | else: |
|
4073 | 4086 | keep.append('unix') |
|
4074 | 4087 | keep.append(sys.platform.lower()) |
|
4075 | 4088 | |
|
4076 | 4089 | section = None |
|
4077 | 4090 | if name and '.' in name: |
|
4078 | 4091 | name, section = name.split('.', 1) |
|
4079 | 4092 | section = section.lower() |
|
4080 | 4093 | |
|
4081 | 4094 | text = help.help_(ui, name, **opts) |
|
4082 | 4095 | |
|
4083 | 4096 | formatted, pruned = minirst.format(text, textwidth, keep=keep, |
|
4084 | 4097 | section=section) |
|
4085 | 4098 | |
|
4086 | 4099 | # We could have been given a weird ".foo" section without a name |
|
4087 | 4100 | # to look for, or we could have simply failed to found "foo.bar" |
|
4088 | 4101 | # because bar isn't a section of foo |
|
4089 | 4102 | if section and not (formatted and name): |
|
4090 | 4103 | raise util.Abort(_("help section not found")) |
|
4091 | 4104 | |
|
4092 | 4105 | if 'verbose' in pruned: |
|
4093 | 4106 | keep.append('omitted') |
|
4094 | 4107 | else: |
|
4095 | 4108 | keep.append('notomitted') |
|
4096 | 4109 | formatted, pruned = minirst.format(text, textwidth, keep=keep, |
|
4097 | 4110 | section=section) |
|
4098 | 4111 | ui.write(formatted) |
|
4099 | 4112 | |
|
4100 | 4113 | |
|
4101 | 4114 | @command('identify|id', |
|
4102 | 4115 | [('r', 'rev', '', |
|
4103 | 4116 | _('identify the specified revision'), _('REV')), |
|
4104 | 4117 | ('n', 'num', None, _('show local revision number')), |
|
4105 | 4118 | ('i', 'id', None, _('show global revision id')), |
|
4106 | 4119 | ('b', 'branch', None, _('show branch')), |
|
4107 | 4120 | ('t', 'tags', None, _('show tags')), |
|
4108 | 4121 | ('B', 'bookmarks', None, _('show bookmarks')), |
|
4109 | 4122 | ] + remoteopts, |
|
4110 | 4123 | _('[-nibtB] [-r REV] [SOURCE]'), |
|
4111 | 4124 | optionalrepo=True) |
|
4112 | 4125 | def identify(ui, repo, source=None, rev=None, |
|
4113 | 4126 | num=None, id=None, branch=None, tags=None, bookmarks=None, **opts): |
|
4114 | 4127 | """identify the working directory or specified revision |
|
4115 | 4128 | |
|
4116 | 4129 | Print a summary identifying the repository state at REV using one or |
|
4117 | 4130 | two parent hash identifiers, followed by a "+" if the working |
|
4118 | 4131 | directory has uncommitted changes, the branch name (if not default), |
|
4119 | 4132 | a list of tags, and a list of bookmarks. |
|
4120 | 4133 | |
|
4121 | 4134 | When REV is not given, print a summary of the current state of the |
|
4122 | 4135 | repository. |
|
4123 | 4136 | |
|
4124 | 4137 | Specifying a path to a repository root or Mercurial bundle will |
|
4125 | 4138 | cause lookup to operate on that repository/bundle. |
|
4126 | 4139 | |
|
4127 | 4140 | .. container:: verbose |
|
4128 | 4141 | |
|
4129 | 4142 | Examples: |
|
4130 | 4143 | |
|
4131 | 4144 | - generate a build identifier for the working directory:: |
|
4132 | 4145 | |
|
4133 | 4146 | hg id --id > build-id.dat |
|
4134 | 4147 | |
|
4135 | 4148 | - find the revision corresponding to a tag:: |
|
4136 | 4149 | |
|
4137 | 4150 | hg id -n -r 1.3 |
|
4138 | 4151 | |
|
4139 | 4152 | - check the most recent revision of a remote repository:: |
|
4140 | 4153 | |
|
4141 | 4154 | hg id -r tip http://selenic.com/hg/ |
|
4142 | 4155 | |
|
4143 | 4156 | Returns 0 if successful. |
|
4144 | 4157 | """ |
|
4145 | 4158 | |
|
4146 | 4159 | if not repo and not source: |
|
4147 | 4160 | raise util.Abort(_("there is no Mercurial repository here " |
|
4148 | 4161 | "(.hg not found)")) |
|
4149 | 4162 | |
|
4150 | 4163 | if ui.debugflag: |
|
4151 | 4164 | hexfunc = hex |
|
4152 | 4165 | else: |
|
4153 | 4166 | hexfunc = short |
|
4154 | 4167 | default = not (num or id or branch or tags or bookmarks) |
|
4155 | 4168 | output = [] |
|
4156 | 4169 | revs = [] |
|
4157 | 4170 | |
|
4158 | 4171 | if source: |
|
4159 | 4172 | source, branches = hg.parseurl(ui.expandpath(source)) |
|
4160 | 4173 | peer = hg.peer(repo or ui, opts, source) # only pass ui when no repo |
|
4161 | 4174 | repo = peer.local() |
|
4162 | 4175 | revs, checkout = hg.addbranchrevs(repo, peer, branches, None) |
|
4163 | 4176 | |
|
4164 | 4177 | if not repo: |
|
4165 | 4178 | if num or branch or tags: |
|
4166 | 4179 | raise util.Abort( |
|
4167 | 4180 | _("can't query remote revision number, branch, or tags")) |
|
4168 | 4181 | if not rev and revs: |
|
4169 | 4182 | rev = revs[0] |
|
4170 | 4183 | if not rev: |
|
4171 | 4184 | rev = "tip" |
|
4172 | 4185 | |
|
4173 | 4186 | remoterev = peer.lookup(rev) |
|
4174 | 4187 | if default or id: |
|
4175 | 4188 | output = [hexfunc(remoterev)] |
|
4176 | 4189 | |
|
4177 | 4190 | def getbms(): |
|
4178 | 4191 | bms = [] |
|
4179 | 4192 | |
|
4180 | 4193 | if 'bookmarks' in peer.listkeys('namespaces'): |
|
4181 | 4194 | hexremoterev = hex(remoterev) |
|
4182 | 4195 | bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems() |
|
4183 | 4196 | if bmr == hexremoterev] |
|
4184 | 4197 | |
|
4185 | 4198 | return sorted(bms) |
|
4186 | 4199 | |
|
4187 | 4200 | if bookmarks: |
|
4188 | 4201 | output.extend(getbms()) |
|
4189 | 4202 | elif default and not ui.quiet: |
|
4190 | 4203 | # multiple bookmarks for a single parent separated by '/' |
|
4191 | 4204 | bm = '/'.join(getbms()) |
|
4192 | 4205 | if bm: |
|
4193 | 4206 | output.append(bm) |
|
4194 | 4207 | else: |
|
4195 | 4208 | ctx = scmutil.revsingle(repo, rev, None) |
|
4196 | 4209 | |
|
4197 | 4210 | if ctx.rev() is None: |
|
4198 | 4211 | ctx = repo[None] |
|
4199 | 4212 | parents = ctx.parents() |
|
4200 | 4213 | taglist = [] |
|
4201 | 4214 | for p in parents: |
|
4202 | 4215 | taglist.extend(p.tags()) |
|
4203 | 4216 | |
|
4204 | 4217 | changed = "" |
|
4205 | 4218 | if default or id or num: |
|
4206 | 4219 | if (any(repo.status()) |
|
4207 | 4220 | or any(ctx.sub(s).dirty() for s in ctx.substate)): |
|
4208 | 4221 | changed = '+' |
|
4209 | 4222 | if default or id: |
|
4210 | 4223 | output = ["%s%s" % |
|
4211 | 4224 | ('+'.join([hexfunc(p.node()) for p in parents]), changed)] |
|
4212 | 4225 | if num: |
|
4213 | 4226 | output.append("%s%s" % |
|
4214 | 4227 | ('+'.join([str(p.rev()) for p in parents]), changed)) |
|
4215 | 4228 | else: |
|
4216 | 4229 | if default or id: |
|
4217 | 4230 | output = [hexfunc(ctx.node())] |
|
4218 | 4231 | if num: |
|
4219 | 4232 | output.append(str(ctx.rev())) |
|
4220 | 4233 | taglist = ctx.tags() |
|
4221 | 4234 | |
|
4222 | 4235 | if default and not ui.quiet: |
|
4223 | 4236 | b = ctx.branch() |
|
4224 | 4237 | if b != 'default': |
|
4225 | 4238 | output.append("(%s)" % b) |
|
4226 | 4239 | |
|
4227 | 4240 | # multiple tags for a single parent separated by '/' |
|
4228 | 4241 | t = '/'.join(taglist) |
|
4229 | 4242 | if t: |
|
4230 | 4243 | output.append(t) |
|
4231 | 4244 | |
|
4232 | 4245 | # multiple bookmarks for a single parent separated by '/' |
|
4233 | 4246 | bm = '/'.join(ctx.bookmarks()) |
|
4234 | 4247 | if bm: |
|
4235 | 4248 | output.append(bm) |
|
4236 | 4249 | else: |
|
4237 | 4250 | if branch: |
|
4238 | 4251 | output.append(ctx.branch()) |
|
4239 | 4252 | |
|
4240 | 4253 | if tags: |
|
4241 | 4254 | output.extend(taglist) |
|
4242 | 4255 | |
|
4243 | 4256 | if bookmarks: |
|
4244 | 4257 | output.extend(ctx.bookmarks()) |
|
4245 | 4258 | |
|
4246 | 4259 | ui.write("%s\n" % ' '.join(output)) |
|
4247 | 4260 | |
|
4248 | 4261 | @command('import|patch', |
|
4249 | 4262 | [('p', 'strip', 1, |
|
4250 | 4263 | _('directory strip option for patch. This has the same ' |
|
4251 | 4264 | 'meaning as the corresponding patch option'), _('NUM')), |
|
4252 | 4265 | ('b', 'base', '', _('base path (DEPRECATED)'), _('PATH')), |
|
4253 | 4266 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
4254 | 4267 | ('f', 'force', None, |
|
4255 | 4268 | _('skip check for outstanding uncommitted changes (DEPRECATED)')), |
|
4256 | 4269 | ('', 'no-commit', None, |
|
4257 | 4270 | _("don't commit, just update the working directory")), |
|
4258 | 4271 | ('', 'bypass', None, |
|
4259 | 4272 | _("apply patch without touching the working directory")), |
|
4260 | 4273 | ('', 'partial', None, |
|
4261 | 4274 | _('commit even if some hunks fail')), |
|
4262 | 4275 | ('', 'exact', None, |
|
4263 | 4276 | _('apply patch to the nodes from which it was generated')), |
|
4264 | 4277 | ('', 'prefix', '', |
|
4265 | 4278 | _('apply patch to subdirectory'), _('DIR')), |
|
4266 | 4279 | ('', 'import-branch', None, |
|
4267 | 4280 | _('use any branch information in patch (implied by --exact)'))] + |
|
4268 | 4281 | commitopts + commitopts2 + similarityopts, |
|
4269 | 4282 | _('[OPTION]... PATCH...')) |
|
4270 | 4283 | def import_(ui, repo, patch1=None, *patches, **opts): |
|
4271 | 4284 | """import an ordered set of patches |
|
4272 | 4285 | |
|
4273 | 4286 | Import a list of patches and commit them individually (unless |
|
4274 | 4287 | --no-commit is specified). |
|
4275 | 4288 | |
|
4276 | 4289 | Because import first applies changes to the working directory, |
|
4277 | 4290 | import will abort if there are outstanding changes. |
|
4278 | 4291 | |
|
4279 | 4292 | You can import a patch straight from a mail message. Even patches |
|
4280 | 4293 | as attachments work (to use the body part, it must have type |
|
4281 | 4294 | text/plain or text/x-patch). From and Subject headers of email |
|
4282 | 4295 | message are used as default committer and commit message. All |
|
4283 | 4296 | text/plain body parts before first diff are added to commit |
|
4284 | 4297 | message. |
|
4285 | 4298 | |
|
4286 | 4299 | If the imported patch was generated by :hg:`export`, user and |
|
4287 | 4300 | description from patch override values from message headers and |
|
4288 | 4301 | body. Values given on command line with -m/--message and -u/--user |
|
4289 | 4302 | override these. |
|
4290 | 4303 | |
|
4291 | 4304 | If --exact is specified, import will set the working directory to |
|
4292 | 4305 | the parent of each patch before applying it, and will abort if the |
|
4293 | 4306 | resulting changeset has a different ID than the one recorded in |
|
4294 | 4307 | the patch. This may happen due to character set problems or other |
|
4295 | 4308 | deficiencies in the text patch format. |
|
4296 | 4309 | |
|
4297 | 4310 | Use --bypass to apply and commit patches directly to the |
|
4298 | 4311 | repository, not touching the working directory. Without --exact, |
|
4299 | 4312 | patches will be applied on top of the working directory parent |
|
4300 | 4313 | revision. |
|
4301 | 4314 | |
|
4302 | 4315 | With -s/--similarity, hg will attempt to discover renames and |
|
4303 | 4316 | copies in the patch in the same way as :hg:`addremove`. |
|
4304 | 4317 | |
|
4305 | 4318 | Use --partial to ensure a changeset will be created from the patch |
|
4306 | 4319 | even if some hunks fail to apply. Hunks that fail to apply will be |
|
4307 | 4320 | written to a <target-file>.rej file. Conflicts can then be resolved |
|
4308 | 4321 | by hand before :hg:`commit --amend` is run to update the created |
|
4309 | 4322 | changeset. This flag exists to let people import patches that |
|
4310 | 4323 | partially apply without losing the associated metadata (author, |
|
4311 | 4324 | date, description, ...). Note that when none of the hunk applies |
|
4312 | 4325 | cleanly, :hg:`import --partial` will create an empty changeset, |
|
4313 | 4326 | importing only the patch metadata. |
|
4314 | 4327 | |
|
4315 | 4328 | It is possible to use external patch programs to perform the patch |
|
4316 | 4329 | by setting the ``ui.patch`` configuration option. For the default |
|
4317 | 4330 | internal tool, the fuzz can also be configured via ``patch.fuzz``. |
|
4318 | 4331 | See :hg:`help config` for more information about configuration |
|
4319 | 4332 | files and how to use these options. |
|
4320 | 4333 | |
|
4321 | 4334 | To read a patch from standard input, use "-" as the patch name. If |
|
4322 | 4335 | a URL is specified, the patch will be downloaded from it. |
|
4323 | 4336 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
4324 | 4337 | |
|
4325 | 4338 | .. container:: verbose |
|
4326 | 4339 | |
|
4327 | 4340 | Examples: |
|
4328 | 4341 | |
|
4329 | 4342 | - import a traditional patch from a website and detect renames:: |
|
4330 | 4343 | |
|
4331 | 4344 | hg import -s 80 http://example.com/bugfix.patch |
|
4332 | 4345 | |
|
4333 | 4346 | - import a changeset from an hgweb server:: |
|
4334 | 4347 | |
|
4335 | 4348 | hg import http://www.selenic.com/hg/rev/5ca8c111e9aa |
|
4336 | 4349 | |
|
4337 | 4350 | - import all the patches in an Unix-style mbox:: |
|
4338 | 4351 | |
|
4339 | 4352 | hg import incoming-patches.mbox |
|
4340 | 4353 | |
|
4341 | 4354 | - attempt to exactly restore an exported changeset (not always |
|
4342 | 4355 | possible):: |
|
4343 | 4356 | |
|
4344 | 4357 | hg import --exact proposed-fix.patch |
|
4345 | 4358 | |
|
4346 | 4359 | - use an external tool to apply a patch which is too fuzzy for |
|
4347 | 4360 | the default internal tool. |
|
4348 | 4361 | |
|
4349 | 4362 | hg import --config ui.patch="patch --merge" fuzzy.patch |
|
4350 | 4363 | |
|
4351 | 4364 | - change the default fuzzing from 2 to a less strict 7 |
|
4352 | 4365 | |
|
4353 | 4366 | hg import --config ui.fuzz=7 fuzz.patch |
|
4354 | 4367 | |
|
4355 | 4368 | Returns 0 on success, 1 on partial success (see --partial). |
|
4356 | 4369 | """ |
|
4357 | 4370 | |
|
4358 | 4371 | if not patch1: |
|
4359 | 4372 | raise util.Abort(_('need at least one patch to import')) |
|
4360 | 4373 | |
|
4361 | 4374 | patches = (patch1,) + patches |
|
4362 | 4375 | |
|
4363 | 4376 | date = opts.get('date') |
|
4364 | 4377 | if date: |
|
4365 | 4378 | opts['date'] = util.parsedate(date) |
|
4366 | 4379 | |
|
4367 | 4380 | update = not opts.get('bypass') |
|
4368 | 4381 | if not update and opts.get('no_commit'): |
|
4369 | 4382 | raise util.Abort(_('cannot use --no-commit with --bypass')) |
|
4370 | 4383 | try: |
|
4371 | 4384 | sim = float(opts.get('similarity') or 0) |
|
4372 | 4385 | except ValueError: |
|
4373 | 4386 | raise util.Abort(_('similarity must be a number')) |
|
4374 | 4387 | if sim < 0 or sim > 100: |
|
4375 | 4388 | raise util.Abort(_('similarity must be between 0 and 100')) |
|
4376 | 4389 | if sim and not update: |
|
4377 | 4390 | raise util.Abort(_('cannot use --similarity with --bypass')) |
|
4378 | 4391 | if opts.get('exact') and opts.get('edit'): |
|
4379 | 4392 | raise util.Abort(_('cannot use --exact with --edit')) |
|
4380 | 4393 | if opts.get('exact') and opts.get('prefix'): |
|
4381 | 4394 | raise util.Abort(_('cannot use --exact with --prefix')) |
|
4382 | 4395 | |
|
4383 | 4396 | if update: |
|
4384 | 4397 | cmdutil.checkunfinished(repo) |
|
4385 | 4398 | if (opts.get('exact') or not opts.get('force')) and update: |
|
4386 | 4399 | cmdutil.bailifchanged(repo) |
|
4387 | 4400 | |
|
4388 | 4401 | base = opts["base"] |
|
4389 | 4402 | wlock = dsguard = lock = tr = None |
|
4390 | 4403 | msgs = [] |
|
4391 | 4404 | ret = 0 |
|
4392 | 4405 | |
|
4393 | 4406 | |
|
4394 | 4407 | try: |
|
4395 | 4408 | try: |
|
4396 | 4409 | wlock = repo.wlock() |
|
4397 | 4410 | dsguard = cmdutil.dirstateguard(repo, 'import') |
|
4398 | 4411 | if not opts.get('no_commit'): |
|
4399 | 4412 | lock = repo.lock() |
|
4400 | 4413 | tr = repo.transaction('import') |
|
4401 | 4414 | parents = repo.parents() |
|
4402 | 4415 | for patchurl in patches: |
|
4403 | 4416 | if patchurl == '-': |
|
4404 | 4417 | ui.status(_('applying patch from stdin\n')) |
|
4405 | 4418 | patchfile = ui.fin |
|
4406 | 4419 | patchurl = 'stdin' # for error message |
|
4407 | 4420 | else: |
|
4408 | 4421 | patchurl = os.path.join(base, patchurl) |
|
4409 | 4422 | ui.status(_('applying %s\n') % patchurl) |
|
4410 | 4423 | patchfile = hg.openpath(ui, patchurl) |
|
4411 | 4424 | |
|
4412 | 4425 | haspatch = False |
|
4413 | 4426 | for hunk in patch.split(patchfile): |
|
4414 | 4427 | (msg, node, rej) = cmdutil.tryimportone(ui, repo, hunk, |
|
4415 | 4428 | parents, opts, |
|
4416 | 4429 | msgs, hg.clean) |
|
4417 | 4430 | if msg: |
|
4418 | 4431 | haspatch = True |
|
4419 | 4432 | ui.note(msg + '\n') |
|
4420 | 4433 | if update or opts.get('exact'): |
|
4421 | 4434 | parents = repo.parents() |
|
4422 | 4435 | else: |
|
4423 | 4436 | parents = [repo[node]] |
|
4424 | 4437 | if rej: |
|
4425 | 4438 | ui.write_err(_("patch applied partially\n")) |
|
4426 | 4439 | ui.write_err(_("(fix the .rej files and run " |
|
4427 | 4440 | "`hg commit --amend`)\n")) |
|
4428 | 4441 | ret = 1 |
|
4429 | 4442 | break |
|
4430 | 4443 | |
|
4431 | 4444 | if not haspatch: |
|
4432 | 4445 | raise util.Abort(_('%s: no diffs found') % patchurl) |
|
4433 | 4446 | |
|
4434 | 4447 | if tr: |
|
4435 | 4448 | tr.close() |
|
4436 | 4449 | if msgs: |
|
4437 | 4450 | repo.savecommitmessage('\n* * *\n'.join(msgs)) |
|
4438 | 4451 | dsguard.close() |
|
4439 | 4452 | return ret |
|
4440 | 4453 | finally: |
|
4441 | 4454 | # TODO: get rid of this meaningless try/finally enclosing. |
|
4442 | 4455 | # this is kept only to reduce changes in a patch. |
|
4443 | 4456 | pass |
|
4444 | 4457 | finally: |
|
4445 | 4458 | if tr: |
|
4446 | 4459 | tr.release() |
|
4447 | 4460 | release(lock, dsguard, wlock) |
|
4448 | 4461 | |
|
4449 | 4462 | @command('incoming|in', |
|
4450 | 4463 | [('f', 'force', None, |
|
4451 | 4464 | _('run even if remote repository is unrelated')), |
|
4452 | 4465 | ('n', 'newest-first', None, _('show newest record first')), |
|
4453 | 4466 | ('', 'bundle', '', |
|
4454 | 4467 | _('file to store the bundles into'), _('FILE')), |
|
4455 | 4468 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
4456 | 4469 | ('B', 'bookmarks', False, _("compare bookmarks")), |
|
4457 | 4470 | ('b', 'branch', [], |
|
4458 | 4471 | _('a specific branch you would like to pull'), _('BRANCH')), |
|
4459 | 4472 | ] + logopts + remoteopts + subrepoopts, |
|
4460 | 4473 | _('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]')) |
|
4461 | 4474 | def incoming(ui, repo, source="default", **opts): |
|
4462 | 4475 | """show new changesets found in source |
|
4463 | 4476 | |
|
4464 | 4477 | Show new changesets found in the specified path/URL or the default |
|
4465 | 4478 | pull location. These are the changesets that would have been pulled |
|
4466 | 4479 | if a pull at the time you issued this command. |
|
4467 | 4480 | |
|
4468 | 4481 | See pull for valid source format details. |
|
4469 | 4482 | |
|
4470 | 4483 | .. container:: verbose |
|
4471 | 4484 | |
|
4472 | 4485 | With -B/--bookmarks, the result of bookmark comparison between |
|
4473 | 4486 | local and remote repositories is displayed. With -v/--verbose, |
|
4474 | 4487 | status is also displayed for each bookmark like below:: |
|
4475 | 4488 | |
|
4476 | 4489 | BM1 01234567890a added |
|
4477 | 4490 | BM2 1234567890ab advanced |
|
4478 | 4491 | BM3 234567890abc diverged |
|
4479 | 4492 | BM4 34567890abcd changed |
|
4480 | 4493 | |
|
4481 | 4494 | The action taken locally when pulling depends on the |
|
4482 | 4495 | status of each bookmark: |
|
4483 | 4496 | |
|
4484 | 4497 | :``added``: pull will create it |
|
4485 | 4498 | :``advanced``: pull will update it |
|
4486 | 4499 | :``diverged``: pull will create a divergent bookmark |
|
4487 | 4500 | :``changed``: result depends on remote changesets |
|
4488 | 4501 | |
|
4489 | 4502 | From the point of view of pulling behavior, bookmark |
|
4490 | 4503 | existing only in the remote repository are treated as ``added``, |
|
4491 | 4504 | even if it is in fact locally deleted. |
|
4492 | 4505 | |
|
4493 | 4506 | .. container:: verbose |
|
4494 | 4507 | |
|
4495 | 4508 | For remote repository, using --bundle avoids downloading the |
|
4496 | 4509 | changesets twice if the incoming is followed by a pull. |
|
4497 | 4510 | |
|
4498 | 4511 | Examples: |
|
4499 | 4512 | |
|
4500 | 4513 | - show incoming changes with patches and full description:: |
|
4501 | 4514 | |
|
4502 | 4515 | hg incoming -vp |
|
4503 | 4516 | |
|
4504 | 4517 | - show incoming changes excluding merges, store a bundle:: |
|
4505 | 4518 | |
|
4506 | 4519 | hg in -vpM --bundle incoming.hg |
|
4507 | 4520 | hg pull incoming.hg |
|
4508 | 4521 | |
|
4509 | 4522 | - briefly list changes inside a bundle:: |
|
4510 | 4523 | |
|
4511 | 4524 | hg in changes.hg -T "{desc|firstline}\\n" |
|
4512 | 4525 | |
|
4513 | 4526 | Returns 0 if there are incoming changes, 1 otherwise. |
|
4514 | 4527 | """ |
|
4515 | 4528 | if opts.get('graph'): |
|
4516 | 4529 | cmdutil.checkunsupportedgraphflags([], opts) |
|
4517 | 4530 | def display(other, chlist, displayer): |
|
4518 | 4531 | revdag = cmdutil.graphrevs(other, chlist, opts) |
|
4519 | 4532 | showparents = [ctx.node() for ctx in repo[None].parents()] |
|
4520 | 4533 | cmdutil.displaygraph(ui, revdag, displayer, showparents, |
|
4521 | 4534 | graphmod.asciiedges) |
|
4522 | 4535 | |
|
4523 | 4536 | hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True) |
|
4524 | 4537 | return 0 |
|
4525 | 4538 | |
|
4526 | 4539 | if opts.get('bundle') and opts.get('subrepos'): |
|
4527 | 4540 | raise util.Abort(_('cannot combine --bundle and --subrepos')) |
|
4528 | 4541 | |
|
4529 | 4542 | if opts.get('bookmarks'): |
|
4530 | 4543 | source, branches = hg.parseurl(ui.expandpath(source), |
|
4531 | 4544 | opts.get('branch')) |
|
4532 | 4545 | other = hg.peer(repo, opts, source) |
|
4533 | 4546 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
4534 | 4547 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
4535 | 4548 | return 0 |
|
4536 | 4549 | ui.status(_('comparing with %s\n') % util.hidepassword(source)) |
|
4537 | 4550 | return bookmarks.incoming(ui, repo, other) |
|
4538 | 4551 | |
|
4539 | 4552 | repo._subtoppath = ui.expandpath(source) |
|
4540 | 4553 | try: |
|
4541 | 4554 | return hg.incoming(ui, repo, source, opts) |
|
4542 | 4555 | finally: |
|
4543 | 4556 | del repo._subtoppath |
|
4544 | 4557 | |
|
4545 | 4558 | |
|
4546 | 4559 | @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'), |
|
4547 | 4560 | norepo=True) |
|
4548 | 4561 | def init(ui, dest=".", **opts): |
|
4549 | 4562 | """create a new repository in the given directory |
|
4550 | 4563 | |
|
4551 | 4564 | Initialize a new repository in the given directory. If the given |
|
4552 | 4565 | directory does not exist, it will be created. |
|
4553 | 4566 | |
|
4554 | 4567 | If no directory is given, the current directory is used. |
|
4555 | 4568 | |
|
4556 | 4569 | It is possible to specify an ``ssh://`` URL as the destination. |
|
4557 | 4570 | See :hg:`help urls` for more information. |
|
4558 | 4571 | |
|
4559 | 4572 | Returns 0 on success. |
|
4560 | 4573 | """ |
|
4561 | 4574 | hg.peer(ui, opts, ui.expandpath(dest), create=True) |
|
4562 | 4575 | |
|
4563 | 4576 | @command('locate', |
|
4564 | 4577 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), |
|
4565 | 4578 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
4566 | 4579 | ('f', 'fullpath', None, _('print complete paths from the filesystem root')), |
|
4567 | 4580 | ] + walkopts, |
|
4568 | 4581 | _('[OPTION]... [PATTERN]...')) |
|
4569 | 4582 | def locate(ui, repo, *pats, **opts): |
|
4570 | 4583 | """locate files matching specific patterns (DEPRECATED) |
|
4571 | 4584 | |
|
4572 | 4585 | Print files under Mercurial control in the working directory whose |
|
4573 | 4586 | names match the given patterns. |
|
4574 | 4587 | |
|
4575 | 4588 | By default, this command searches all directories in the working |
|
4576 | 4589 | directory. To search just the current directory and its |
|
4577 | 4590 | subdirectories, use "--include .". |
|
4578 | 4591 | |
|
4579 | 4592 | If no patterns are given to match, this command prints the names |
|
4580 | 4593 | of all files under Mercurial control in the working directory. |
|
4581 | 4594 | |
|
4582 | 4595 | If you want to feed the output of this command into the "xargs" |
|
4583 | 4596 | command, use the -0 option to both this command and "xargs". This |
|
4584 | 4597 | will avoid the problem of "xargs" treating single filenames that |
|
4585 | 4598 | contain whitespace as multiple filenames. |
|
4586 | 4599 | |
|
4587 | 4600 | See :hg:`help files` for a more versatile command. |
|
4588 | 4601 | |
|
4589 | 4602 | Returns 0 if a match is found, 1 otherwise. |
|
4590 | 4603 | """ |
|
4591 | 4604 | if opts.get('print0'): |
|
4592 | 4605 | end = '\0' |
|
4593 | 4606 | else: |
|
4594 | 4607 | end = '\n' |
|
4595 | 4608 | rev = scmutil.revsingle(repo, opts.get('rev'), None).node() |
|
4596 | 4609 | |
|
4597 | 4610 | ret = 1 |
|
4598 | 4611 | ctx = repo[rev] |
|
4599 | 4612 | m = scmutil.match(ctx, pats, opts, default='relglob', |
|
4600 | 4613 | badfn=lambda x, y: False) |
|
4601 | 4614 | |
|
4602 | 4615 | for abs in ctx.matches(m): |
|
4603 | 4616 | if opts.get('fullpath'): |
|
4604 | 4617 | ui.write(repo.wjoin(abs), end) |
|
4605 | 4618 | else: |
|
4606 | 4619 | ui.write(((pats and m.rel(abs)) or abs), end) |
|
4607 | 4620 | ret = 0 |
|
4608 | 4621 | |
|
4609 | 4622 | return ret |
|
4610 | 4623 | |
|
4611 | 4624 | @command('^log|history', |
|
4612 | 4625 | [('f', 'follow', None, |
|
4613 | 4626 | _('follow changeset history, or file history across copies and renames')), |
|
4614 | 4627 | ('', 'follow-first', None, |
|
4615 | 4628 | _('only follow the first parent of merge changesets (DEPRECATED)')), |
|
4616 | 4629 | ('d', 'date', '', _('show revisions matching date spec'), _('DATE')), |
|
4617 | 4630 | ('C', 'copies', None, _('show copied files')), |
|
4618 | 4631 | ('k', 'keyword', [], |
|
4619 | 4632 | _('do case-insensitive search for a given text'), _('TEXT')), |
|
4620 | 4633 | ('r', 'rev', [], _('show the specified revision or revset'), _('REV')), |
|
4621 | 4634 | ('', 'removed', None, _('include revisions where files were removed')), |
|
4622 | 4635 | ('m', 'only-merges', None, _('show only merges (DEPRECATED)')), |
|
4623 | 4636 | ('u', 'user', [], _('revisions committed by user'), _('USER')), |
|
4624 | 4637 | ('', 'only-branch', [], |
|
4625 | 4638 | _('show only changesets within the given named branch (DEPRECATED)'), |
|
4626 | 4639 | _('BRANCH')), |
|
4627 | 4640 | ('b', 'branch', [], |
|
4628 | 4641 | _('show changesets within the given named branch'), _('BRANCH')), |
|
4629 | 4642 | ('P', 'prune', [], |
|
4630 | 4643 | _('do not display revision or any of its ancestors'), _('REV')), |
|
4631 | 4644 | ] + logopts + walkopts, |
|
4632 | 4645 | _('[OPTION]... [FILE]'), |
|
4633 | 4646 | inferrepo=True) |
|
4634 | 4647 | def log(ui, repo, *pats, **opts): |
|
4635 | 4648 | """show revision history of entire repository or files |
|
4636 | 4649 | |
|
4637 | 4650 | Print the revision history of the specified files or the entire |
|
4638 | 4651 | project. |
|
4639 | 4652 | |
|
4640 | 4653 | If no revision range is specified, the default is ``tip:0`` unless |
|
4641 | 4654 | --follow is set, in which case the working directory parent is |
|
4642 | 4655 | used as the starting revision. |
|
4643 | 4656 | |
|
4644 | 4657 | File history is shown without following rename or copy history of |
|
4645 | 4658 | files. Use -f/--follow with a filename to follow history across |
|
4646 | 4659 | renames and copies. --follow without a filename will only show |
|
4647 | 4660 | ancestors or descendants of the starting revision. |
|
4648 | 4661 | |
|
4649 | 4662 | By default this command prints revision number and changeset id, |
|
4650 | 4663 | tags, non-trivial parents, user, date and time, and a summary for |
|
4651 | 4664 | each commit. When the -v/--verbose switch is used, the list of |
|
4652 | 4665 | changed files and full commit message are shown. |
|
4653 | 4666 | |
|
4654 | 4667 | With --graph the revisions are shown as an ASCII art DAG with the most |
|
4655 | 4668 | recent changeset at the top. |
|
4656 | 4669 | 'o' is a changeset, '@' is a working directory parent, 'x' is obsolete, |
|
4657 | 4670 | and '+' represents a fork where the changeset from the lines below is a |
|
4658 | 4671 | parent of the 'o' merge on the same line. |
|
4659 | 4672 | |
|
4660 | 4673 | .. note:: |
|
4661 | 4674 | |
|
4662 | 4675 | log -p/--patch may generate unexpected diff output for merge |
|
4663 | 4676 | changesets, as it will only compare the merge changeset against |
|
4664 | 4677 | its first parent. Also, only files different from BOTH parents |
|
4665 | 4678 | will appear in files:. |
|
4666 | 4679 | |
|
4667 | 4680 | .. note:: |
|
4668 | 4681 | |
|
4669 | 4682 | for performance reasons, log FILE may omit duplicate changes |
|
4670 | 4683 | made on branches and will not show removals or mode changes. To |
|
4671 | 4684 | see all such changes, use the --removed switch. |
|
4672 | 4685 | |
|
4673 | 4686 | .. container:: verbose |
|
4674 | 4687 | |
|
4675 | 4688 | Some examples: |
|
4676 | 4689 | |
|
4677 | 4690 | - changesets with full descriptions and file lists:: |
|
4678 | 4691 | |
|
4679 | 4692 | hg log -v |
|
4680 | 4693 | |
|
4681 | 4694 | - changesets ancestral to the working directory:: |
|
4682 | 4695 | |
|
4683 | 4696 | hg log -f |
|
4684 | 4697 | |
|
4685 | 4698 | - last 10 commits on the current branch:: |
|
4686 | 4699 | |
|
4687 | 4700 | hg log -l 10 -b . |
|
4688 | 4701 | |
|
4689 | 4702 | - changesets showing all modifications of a file, including removals:: |
|
4690 | 4703 | |
|
4691 | 4704 | hg log --removed file.c |
|
4692 | 4705 | |
|
4693 | 4706 | - all changesets that touch a directory, with diffs, excluding merges:: |
|
4694 | 4707 | |
|
4695 | 4708 | hg log -Mp lib/ |
|
4696 | 4709 | |
|
4697 | 4710 | - all revision numbers that match a keyword:: |
|
4698 | 4711 | |
|
4699 | 4712 | hg log -k bug --template "{rev}\\n" |
|
4700 | 4713 | |
|
4701 | 4714 | - list available log templates:: |
|
4702 | 4715 | |
|
4703 | 4716 | hg log -T list |
|
4704 | 4717 | |
|
4705 | 4718 | - check if a given changeset is included in a tagged release:: |
|
4706 | 4719 | |
|
4707 | 4720 | hg log -r "a21ccf and ancestor(1.9)" |
|
4708 | 4721 | |
|
4709 | 4722 | - find all changesets by some user in a date range:: |
|
4710 | 4723 | |
|
4711 | 4724 | hg log -k alice -d "may 2008 to jul 2008" |
|
4712 | 4725 | |
|
4713 | 4726 | - summary of all changesets after the last tag:: |
|
4714 | 4727 | |
|
4715 | 4728 | hg log -r "last(tagged())::" --template "{desc|firstline}\\n" |
|
4716 | 4729 | |
|
4717 | 4730 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
4718 | 4731 | |
|
4719 | 4732 | See :hg:`help revisions` and :hg:`help revsets` for more about |
|
4720 | 4733 | specifying revisions. |
|
4721 | 4734 | |
|
4722 | 4735 | See :hg:`help templates` for more about pre-packaged styles and |
|
4723 | 4736 | specifying custom templates. |
|
4724 | 4737 | |
|
4725 | 4738 | Returns 0 on success. |
|
4726 | 4739 | |
|
4727 | 4740 | """ |
|
4728 | 4741 | if opts.get('follow') and opts.get('rev'): |
|
4729 | 4742 | opts['rev'] = [revset.formatspec('reverse(::%lr)', opts.get('rev'))] |
|
4730 | 4743 | del opts['follow'] |
|
4731 | 4744 | |
|
4732 | 4745 | if opts.get('graph'): |
|
4733 | 4746 | return cmdutil.graphlog(ui, repo, *pats, **opts) |
|
4734 | 4747 | |
|
4735 | 4748 | revs, expr, filematcher = cmdutil.getlogrevs(repo, pats, opts) |
|
4736 | 4749 | limit = cmdutil.loglimit(opts) |
|
4737 | 4750 | count = 0 |
|
4738 | 4751 | |
|
4739 | 4752 | getrenamed = None |
|
4740 | 4753 | if opts.get('copies'): |
|
4741 | 4754 | endrev = None |
|
4742 | 4755 | if opts.get('rev'): |
|
4743 | 4756 | endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1 |
|
4744 | 4757 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) |
|
4745 | 4758 | |
|
4746 | 4759 | displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) |
|
4747 | 4760 | for rev in revs: |
|
4748 | 4761 | if count == limit: |
|
4749 | 4762 | break |
|
4750 | 4763 | ctx = repo[rev] |
|
4751 | 4764 | copies = None |
|
4752 | 4765 | if getrenamed is not None and rev: |
|
4753 | 4766 | copies = [] |
|
4754 | 4767 | for fn in ctx.files(): |
|
4755 | 4768 | rename = getrenamed(fn, rev) |
|
4756 | 4769 | if rename: |
|
4757 | 4770 | copies.append((fn, rename[0])) |
|
4758 | 4771 | if filematcher: |
|
4759 | 4772 | revmatchfn = filematcher(ctx.rev()) |
|
4760 | 4773 | else: |
|
4761 | 4774 | revmatchfn = None |
|
4762 | 4775 | displayer.show(ctx, copies=copies, matchfn=revmatchfn) |
|
4763 | 4776 | if displayer.flush(ctx): |
|
4764 | 4777 | count += 1 |
|
4765 | 4778 | |
|
4766 | 4779 | displayer.close() |
|
4767 | 4780 | |
|
4768 | 4781 | @command('manifest', |
|
4769 | 4782 | [('r', 'rev', '', _('revision to display'), _('REV')), |
|
4770 | 4783 | ('', 'all', False, _("list files from all revisions"))] |
|
4771 | 4784 | + formatteropts, |
|
4772 | 4785 | _('[-r REV]')) |
|
4773 | 4786 | def manifest(ui, repo, node=None, rev=None, **opts): |
|
4774 | 4787 | """output the current or given revision of the project manifest |
|
4775 | 4788 | |
|
4776 | 4789 | Print a list of version controlled files for the given revision. |
|
4777 | 4790 | If no revision is given, the first parent of the working directory |
|
4778 | 4791 | is used, or the null revision if no revision is checked out. |
|
4779 | 4792 | |
|
4780 | 4793 | With -v, print file permissions, symlink and executable bits. |
|
4781 | 4794 | With --debug, print file revision hashes. |
|
4782 | 4795 | |
|
4783 | 4796 | If option --all is specified, the list of all files from all revisions |
|
4784 | 4797 | is printed. This includes deleted and renamed files. |
|
4785 | 4798 | |
|
4786 | 4799 | Returns 0 on success. |
|
4787 | 4800 | """ |
|
4788 | 4801 | |
|
4789 | 4802 | fm = ui.formatter('manifest', opts) |
|
4790 | 4803 | |
|
4791 | 4804 | if opts.get('all'): |
|
4792 | 4805 | if rev or node: |
|
4793 | 4806 | raise util.Abort(_("can't specify a revision with --all")) |
|
4794 | 4807 | |
|
4795 | 4808 | res = [] |
|
4796 | 4809 | prefix = "data/" |
|
4797 | 4810 | suffix = ".i" |
|
4798 | 4811 | plen = len(prefix) |
|
4799 | 4812 | slen = len(suffix) |
|
4800 | 4813 | lock = repo.lock() |
|
4801 | 4814 | try: |
|
4802 | 4815 | for fn, b, size in repo.store.datafiles(): |
|
4803 | 4816 | if size != 0 and fn[-slen:] == suffix and fn[:plen] == prefix: |
|
4804 | 4817 | res.append(fn[plen:-slen]) |
|
4805 | 4818 | finally: |
|
4806 | 4819 | lock.release() |
|
4807 | 4820 | for f in res: |
|
4808 | 4821 | fm.startitem() |
|
4809 | 4822 | fm.write("path", '%s\n', f) |
|
4810 | 4823 | fm.end() |
|
4811 | 4824 | return |
|
4812 | 4825 | |
|
4813 | 4826 | if rev and node: |
|
4814 | 4827 | raise util.Abort(_("please specify just one revision")) |
|
4815 | 4828 | |
|
4816 | 4829 | if not node: |
|
4817 | 4830 | node = rev |
|
4818 | 4831 | |
|
4819 | 4832 | char = {'l': '@', 'x': '*', '': ''} |
|
4820 | 4833 | mode = {'l': '644', 'x': '755', '': '644'} |
|
4821 | 4834 | ctx = scmutil.revsingle(repo, node) |
|
4822 | 4835 | mf = ctx.manifest() |
|
4823 | 4836 | for f in ctx: |
|
4824 | 4837 | fm.startitem() |
|
4825 | 4838 | fl = ctx[f].flags() |
|
4826 | 4839 | fm.condwrite(ui.debugflag, 'hash', '%s ', hex(mf[f])) |
|
4827 | 4840 | fm.condwrite(ui.verbose, 'mode type', '%s %1s ', mode[fl], char[fl]) |
|
4828 | 4841 | fm.write('path', '%s\n', f) |
|
4829 | 4842 | fm.end() |
|
4830 | 4843 | |
|
4831 | 4844 | @command('^merge', |
|
4832 | 4845 | [('f', 'force', None, |
|
4833 | 4846 | _('force a merge including outstanding changes (DEPRECATED)')), |
|
4834 | 4847 | ('r', 'rev', '', _('revision to merge'), _('REV')), |
|
4835 | 4848 | ('P', 'preview', None, |
|
4836 | 4849 | _('review revisions to merge (no merge is performed)')) |
|
4837 | 4850 | ] + mergetoolopts, |
|
4838 | 4851 | _('[-P] [-f] [[-r] REV]')) |
|
4839 | 4852 | def merge(ui, repo, node=None, **opts): |
|
4840 | 4853 | """merge another revision into working directory |
|
4841 | 4854 | |
|
4842 | 4855 | The current working directory is updated with all changes made in |
|
4843 | 4856 | the requested revision since the last common predecessor revision. |
|
4844 | 4857 | |
|
4845 | 4858 | Files that changed between either parent are marked as changed for |
|
4846 | 4859 | the next commit and a commit must be performed before any further |
|
4847 | 4860 | updates to the repository are allowed. The next commit will have |
|
4848 | 4861 | two parents. |
|
4849 | 4862 | |
|
4850 | 4863 | ``--tool`` can be used to specify the merge tool used for file |
|
4851 | 4864 | merges. It overrides the HGMERGE environment variable and your |
|
4852 | 4865 | configuration files. See :hg:`help merge-tools` for options. |
|
4853 | 4866 | |
|
4854 | 4867 | If no revision is specified, the working directory's parent is a |
|
4855 | 4868 | head revision, and the current branch contains exactly one other |
|
4856 | 4869 | head, the other head is merged with by default. Otherwise, an |
|
4857 | 4870 | explicit revision with which to merge with must be provided. |
|
4858 | 4871 | |
|
4859 | 4872 | :hg:`resolve` must be used to resolve unresolved files. |
|
4860 | 4873 | |
|
4861 | 4874 | To undo an uncommitted merge, use :hg:`update --clean .` which |
|
4862 | 4875 | will check out a clean copy of the original merge parent, losing |
|
4863 | 4876 | all changes. |
|
4864 | 4877 | |
|
4865 | 4878 | Returns 0 on success, 1 if there are unresolved files. |
|
4866 | 4879 | """ |
|
4867 | 4880 | |
|
4868 | 4881 | if opts.get('rev') and node: |
|
4869 | 4882 | raise util.Abort(_("please specify just one revision")) |
|
4870 | 4883 | if not node: |
|
4871 | 4884 | node = opts.get('rev') |
|
4872 | 4885 | |
|
4873 | 4886 | if node: |
|
4874 | 4887 | node = scmutil.revsingle(repo, node).node() |
|
4875 | 4888 | |
|
4876 | 4889 | if not node: |
|
4877 | 4890 | node = scmutil.revsingle(repo, '_mergedefaultdest()').node() |
|
4878 | 4891 | |
|
4879 | 4892 | if opts.get('preview'): |
|
4880 | 4893 | # find nodes that are ancestors of p2 but not of p1 |
|
4881 | 4894 | p1 = repo.lookup('.') |
|
4882 | 4895 | p2 = repo.lookup(node) |
|
4883 | 4896 | nodes = repo.changelog.findmissing(common=[p1], heads=[p2]) |
|
4884 | 4897 | |
|
4885 | 4898 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
4886 | 4899 | for node in nodes: |
|
4887 | 4900 | displayer.show(repo[node]) |
|
4888 | 4901 | displayer.close() |
|
4889 | 4902 | return 0 |
|
4890 | 4903 | |
|
4891 | 4904 | try: |
|
4892 | 4905 | # ui.forcemerge is an internal variable, do not document |
|
4893 | 4906 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'merge') |
|
4894 | 4907 | return hg.merge(repo, node, force=opts.get('force')) |
|
4895 | 4908 | finally: |
|
4896 | 4909 | ui.setconfig('ui', 'forcemerge', '', 'merge') |
|
4897 | 4910 | |
|
4898 | 4911 | @command('outgoing|out', |
|
4899 | 4912 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
4900 | 4913 | ('r', 'rev', [], |
|
4901 | 4914 | _('a changeset intended to be included in the destination'), _('REV')), |
|
4902 | 4915 | ('n', 'newest-first', None, _('show newest record first')), |
|
4903 | 4916 | ('B', 'bookmarks', False, _('compare bookmarks')), |
|
4904 | 4917 | ('b', 'branch', [], _('a specific branch you would like to push'), |
|
4905 | 4918 | _('BRANCH')), |
|
4906 | 4919 | ] + logopts + remoteopts + subrepoopts, |
|
4907 | 4920 | _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')) |
|
4908 | 4921 | def outgoing(ui, repo, dest=None, **opts): |
|
4909 | 4922 | """show changesets not found in the destination |
|
4910 | 4923 | |
|
4911 | 4924 | Show changesets not found in the specified destination repository |
|
4912 | 4925 | or the default push location. These are the changesets that would |
|
4913 | 4926 | be pushed if a push was requested. |
|
4914 | 4927 | |
|
4915 | 4928 | See pull for details of valid destination formats. |
|
4916 | 4929 | |
|
4917 | 4930 | .. container:: verbose |
|
4918 | 4931 | |
|
4919 | 4932 | With -B/--bookmarks, the result of bookmark comparison between |
|
4920 | 4933 | local and remote repositories is displayed. With -v/--verbose, |
|
4921 | 4934 | status is also displayed for each bookmark like below:: |
|
4922 | 4935 | |
|
4923 | 4936 | BM1 01234567890a added |
|
4924 | 4937 | BM2 deleted |
|
4925 | 4938 | BM3 234567890abc advanced |
|
4926 | 4939 | BM4 34567890abcd diverged |
|
4927 | 4940 | BM5 4567890abcde changed |
|
4928 | 4941 | |
|
4929 | 4942 | The action taken when pushing depends on the |
|
4930 | 4943 | status of each bookmark: |
|
4931 | 4944 | |
|
4932 | 4945 | :``added``: push with ``-B`` will create it |
|
4933 | 4946 | :``deleted``: push with ``-B`` will delete it |
|
4934 | 4947 | :``advanced``: push will update it |
|
4935 | 4948 | :``diverged``: push with ``-B`` will update it |
|
4936 | 4949 | :``changed``: push with ``-B`` will update it |
|
4937 | 4950 | |
|
4938 | 4951 | From the point of view of pushing behavior, bookmarks |
|
4939 | 4952 | existing only in the remote repository are treated as |
|
4940 | 4953 | ``deleted``, even if it is in fact added remotely. |
|
4941 | 4954 | |
|
4942 | 4955 | Returns 0 if there are outgoing changes, 1 otherwise. |
|
4943 | 4956 | """ |
|
4944 | 4957 | if opts.get('graph'): |
|
4945 | 4958 | cmdutil.checkunsupportedgraphflags([], opts) |
|
4946 | 4959 | o, other = hg._outgoing(ui, repo, dest, opts) |
|
4947 | 4960 | if not o: |
|
4948 | 4961 | cmdutil.outgoinghooks(ui, repo, other, opts, o) |
|
4949 | 4962 | return |
|
4950 | 4963 | |
|
4951 | 4964 | revdag = cmdutil.graphrevs(repo, o, opts) |
|
4952 | 4965 | displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) |
|
4953 | 4966 | showparents = [ctx.node() for ctx in repo[None].parents()] |
|
4954 | 4967 | cmdutil.displaygraph(ui, revdag, displayer, showparents, |
|
4955 | 4968 | graphmod.asciiedges) |
|
4956 | 4969 | cmdutil.outgoinghooks(ui, repo, other, opts, o) |
|
4957 | 4970 | return 0 |
|
4958 | 4971 | |
|
4959 | 4972 | if opts.get('bookmarks'): |
|
4960 | 4973 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
4961 | 4974 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
4962 | 4975 | other = hg.peer(repo, opts, dest) |
|
4963 | 4976 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
4964 | 4977 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
4965 | 4978 | return 0 |
|
4966 | 4979 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) |
|
4967 | 4980 | return bookmarks.outgoing(ui, repo, other) |
|
4968 | 4981 | |
|
4969 | 4982 | repo._subtoppath = ui.expandpath(dest or 'default-push', dest or 'default') |
|
4970 | 4983 | try: |
|
4971 | 4984 | return hg.outgoing(ui, repo, dest, opts) |
|
4972 | 4985 | finally: |
|
4973 | 4986 | del repo._subtoppath |
|
4974 | 4987 | |
|
4975 | 4988 | @command('parents', |
|
4976 | 4989 | [('r', 'rev', '', _('show parents of the specified revision'), _('REV')), |
|
4977 | 4990 | ] + templateopts, |
|
4978 | 4991 | _('[-r REV] [FILE]'), |
|
4979 | 4992 | inferrepo=True) |
|
4980 | 4993 | def parents(ui, repo, file_=None, **opts): |
|
4981 | 4994 | """show the parents of the working directory or revision (DEPRECATED) |
|
4982 | 4995 | |
|
4983 | 4996 | Print the working directory's parent revisions. If a revision is |
|
4984 | 4997 | given via -r/--rev, the parent of that revision will be printed. |
|
4985 | 4998 | If a file argument is given, the revision in which the file was |
|
4986 | 4999 | last changed (before the working directory revision or the |
|
4987 | 5000 | argument to --rev if given) is printed. |
|
4988 | 5001 | |
|
4989 | 5002 | See :hg:`summary` and :hg:`help revsets` for related information. |
|
4990 | 5003 | |
|
4991 | 5004 | Returns 0 on success. |
|
4992 | 5005 | """ |
|
4993 | 5006 | |
|
4994 | 5007 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) |
|
4995 | 5008 | |
|
4996 | 5009 | if file_: |
|
4997 | 5010 | m = scmutil.match(ctx, (file_,), opts) |
|
4998 | 5011 | if m.anypats() or len(m.files()) != 1: |
|
4999 | 5012 | raise util.Abort(_('can only specify an explicit filename')) |
|
5000 | 5013 | file_ = m.files()[0] |
|
5001 | 5014 | filenodes = [] |
|
5002 | 5015 | for cp in ctx.parents(): |
|
5003 | 5016 | if not cp: |
|
5004 | 5017 | continue |
|
5005 | 5018 | try: |
|
5006 | 5019 | filenodes.append(cp.filenode(file_)) |
|
5007 | 5020 | except error.LookupError: |
|
5008 | 5021 | pass |
|
5009 | 5022 | if not filenodes: |
|
5010 | 5023 | raise util.Abort(_("'%s' not found in manifest!") % file_) |
|
5011 | 5024 | p = [] |
|
5012 | 5025 | for fn in filenodes: |
|
5013 | 5026 | fctx = repo.filectx(file_, fileid=fn) |
|
5014 | 5027 | p.append(fctx.node()) |
|
5015 | 5028 | else: |
|
5016 | 5029 | p = [cp.node() for cp in ctx.parents()] |
|
5017 | 5030 | |
|
5018 | 5031 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
5019 | 5032 | for n in p: |
|
5020 | 5033 | if n != nullid: |
|
5021 | 5034 | displayer.show(repo[n]) |
|
5022 | 5035 | displayer.close() |
|
5023 | 5036 | |
|
5024 | 5037 | @command('paths', [], _('[NAME]'), optionalrepo=True) |
|
5025 | 5038 | def paths(ui, repo, search=None): |
|
5026 | 5039 | """show aliases for remote repositories |
|
5027 | 5040 | |
|
5028 | 5041 | Show definition of symbolic path name NAME. If no name is given, |
|
5029 | 5042 | show definition of all available names. |
|
5030 | 5043 | |
|
5031 | 5044 | Option -q/--quiet suppresses all output when searching for NAME |
|
5032 | 5045 | and shows only the path names when listing all definitions. |
|
5033 | 5046 | |
|
5034 | 5047 | Path names are defined in the [paths] section of your |
|
5035 | 5048 | configuration file and in ``/etc/mercurial/hgrc``. If run inside a |
|
5036 | 5049 | repository, ``.hg/hgrc`` is used, too. |
|
5037 | 5050 | |
|
5038 | 5051 | The path names ``default`` and ``default-push`` have a special |
|
5039 | 5052 | meaning. When performing a push or pull operation, they are used |
|
5040 | 5053 | as fallbacks if no location is specified on the command-line. |
|
5041 | 5054 | When ``default-push`` is set, it will be used for push and |
|
5042 | 5055 | ``default`` will be used for pull; otherwise ``default`` is used |
|
5043 | 5056 | as the fallback for both. When cloning a repository, the clone |
|
5044 | 5057 | source is written as ``default`` in ``.hg/hgrc``. Note that |
|
5045 | 5058 | ``default`` and ``default-push`` apply to all inbound (e.g. |
|
5046 | 5059 | :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email` and |
|
5047 | 5060 | :hg:`bundle`) operations. |
|
5048 | 5061 | |
|
5049 | 5062 | See :hg:`help urls` for more information. |
|
5050 | 5063 | |
|
5051 | 5064 | Returns 0 on success. |
|
5052 | 5065 | """ |
|
5053 | 5066 | if search: |
|
5054 | 5067 | for name, path in sorted(ui.paths.iteritems()): |
|
5055 | 5068 | if name == search: |
|
5056 | 5069 | ui.status("%s\n" % util.hidepassword(path.loc)) |
|
5057 | 5070 | return |
|
5058 | 5071 | if not ui.quiet: |
|
5059 | 5072 | ui.warn(_("not found!\n")) |
|
5060 | 5073 | return 1 |
|
5061 | 5074 | else: |
|
5062 | 5075 | for name, path in sorted(ui.paths.iteritems()): |
|
5063 | 5076 | if ui.quiet: |
|
5064 | 5077 | ui.write("%s\n" % name) |
|
5065 | 5078 | else: |
|
5066 | 5079 | ui.write("%s = %s\n" % (name, |
|
5067 | 5080 | util.hidepassword(path.loc))) |
|
5068 | 5081 | |
|
5069 | 5082 | @command('phase', |
|
5070 | 5083 | [('p', 'public', False, _('set changeset phase to public')), |
|
5071 | 5084 | ('d', 'draft', False, _('set changeset phase to draft')), |
|
5072 | 5085 | ('s', 'secret', False, _('set changeset phase to secret')), |
|
5073 | 5086 | ('f', 'force', False, _('allow to move boundary backward')), |
|
5074 | 5087 | ('r', 'rev', [], _('target revision'), _('REV')), |
|
5075 | 5088 | ], |
|
5076 | 5089 | _('[-p|-d|-s] [-f] [-r] [REV...]')) |
|
5077 | 5090 | def phase(ui, repo, *revs, **opts): |
|
5078 | 5091 | """set or show the current phase name |
|
5079 | 5092 | |
|
5080 | 5093 | With no argument, show the phase name of the current revision(s). |
|
5081 | 5094 | |
|
5082 | 5095 | With one of -p/--public, -d/--draft or -s/--secret, change the |
|
5083 | 5096 | phase value of the specified revisions. |
|
5084 | 5097 | |
|
5085 | 5098 | Unless -f/--force is specified, :hg:`phase` won't move changeset from a |
|
5086 | 5099 | lower phase to an higher phase. Phases are ordered as follows:: |
|
5087 | 5100 | |
|
5088 | 5101 | public < draft < secret |
|
5089 | 5102 | |
|
5090 | 5103 | Returns 0 on success, 1 if some phases could not be changed. |
|
5091 | 5104 | |
|
5092 | 5105 | (For more information about the phases concept, see :hg:`help phases`.) |
|
5093 | 5106 | """ |
|
5094 | 5107 | # search for a unique phase argument |
|
5095 | 5108 | targetphase = None |
|
5096 | 5109 | for idx, name in enumerate(phases.phasenames): |
|
5097 | 5110 | if opts[name]: |
|
5098 | 5111 | if targetphase is not None: |
|
5099 | 5112 | raise util.Abort(_('only one phase can be specified')) |
|
5100 | 5113 | targetphase = idx |
|
5101 | 5114 | |
|
5102 | 5115 | # look for specified revision |
|
5103 | 5116 | revs = list(revs) |
|
5104 | 5117 | revs.extend(opts['rev']) |
|
5105 | 5118 | if not revs: |
|
5106 | 5119 | # display both parents as the second parent phase can influence |
|
5107 | 5120 | # the phase of a merge commit |
|
5108 | 5121 | revs = [c.rev() for c in repo[None].parents()] |
|
5109 | 5122 | |
|
5110 | 5123 | revs = scmutil.revrange(repo, revs) |
|
5111 | 5124 | |
|
5112 | 5125 | lock = None |
|
5113 | 5126 | ret = 0 |
|
5114 | 5127 | if targetphase is None: |
|
5115 | 5128 | # display |
|
5116 | 5129 | for r in revs: |
|
5117 | 5130 | ctx = repo[r] |
|
5118 | 5131 | ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr())) |
|
5119 | 5132 | else: |
|
5120 | 5133 | tr = None |
|
5121 | 5134 | lock = repo.lock() |
|
5122 | 5135 | try: |
|
5123 | 5136 | tr = repo.transaction("phase") |
|
5124 | 5137 | # set phase |
|
5125 | 5138 | if not revs: |
|
5126 | 5139 | raise util.Abort(_('empty revision set')) |
|
5127 | 5140 | nodes = [repo[r].node() for r in revs] |
|
5128 | 5141 | # moving revision from public to draft may hide them |
|
5129 | 5142 | # We have to check result on an unfiltered repository |
|
5130 | 5143 | unfi = repo.unfiltered() |
|
5131 | 5144 | getphase = unfi._phasecache.phase |
|
5132 | 5145 | olddata = [getphase(unfi, r) for r in unfi] |
|
5133 | 5146 | phases.advanceboundary(repo, tr, targetphase, nodes) |
|
5134 | 5147 | if opts['force']: |
|
5135 | 5148 | phases.retractboundary(repo, tr, targetphase, nodes) |
|
5136 | 5149 | tr.close() |
|
5137 | 5150 | finally: |
|
5138 | 5151 | if tr is not None: |
|
5139 | 5152 | tr.release() |
|
5140 | 5153 | lock.release() |
|
5141 | 5154 | getphase = unfi._phasecache.phase |
|
5142 | 5155 | newdata = [getphase(unfi, r) for r in unfi] |
|
5143 | 5156 | changes = sum(newdata[r] != olddata[r] for r in unfi) |
|
5144 | 5157 | cl = unfi.changelog |
|
5145 | 5158 | rejected = [n for n in nodes |
|
5146 | 5159 | if newdata[cl.rev(n)] < targetphase] |
|
5147 | 5160 | if rejected: |
|
5148 | 5161 | ui.warn(_('cannot move %i changesets to a higher ' |
|
5149 | 5162 | 'phase, use --force\n') % len(rejected)) |
|
5150 | 5163 | ret = 1 |
|
5151 | 5164 | if changes: |
|
5152 | 5165 | msg = _('phase changed for %i changesets\n') % changes |
|
5153 | 5166 | if ret: |
|
5154 | 5167 | ui.status(msg) |
|
5155 | 5168 | else: |
|
5156 | 5169 | ui.note(msg) |
|
5157 | 5170 | else: |
|
5158 | 5171 | ui.warn(_('no phases changed\n')) |
|
5159 | 5172 | return ret |
|
5160 | 5173 | |
|
5161 | 5174 | def postincoming(ui, repo, modheads, optupdate, checkout): |
|
5162 | 5175 | if modheads == 0: |
|
5163 | 5176 | return |
|
5164 | 5177 | if optupdate: |
|
5165 | 5178 | checkout, movemarkfrom = bookmarks.calculateupdate(ui, repo, checkout) |
|
5166 | 5179 | try: |
|
5167 | 5180 | ret = hg.update(repo, checkout) |
|
5168 | 5181 | except util.Abort as inst: |
|
5169 | 5182 | ui.warn(_("not updating: %s\n") % str(inst)) |
|
5170 | 5183 | if inst.hint: |
|
5171 | 5184 | ui.warn(_("(%s)\n") % inst.hint) |
|
5172 | 5185 | return 0 |
|
5173 | 5186 | if not ret and not checkout: |
|
5174 | 5187 | if bookmarks.update(repo, [movemarkfrom], repo['.'].node()): |
|
5175 | 5188 | ui.status(_("updating bookmark %s\n") % repo._activebookmark) |
|
5176 | 5189 | return ret |
|
5177 | 5190 | if modheads > 1: |
|
5178 | 5191 | currentbranchheads = len(repo.branchheads()) |
|
5179 | 5192 | if currentbranchheads == modheads: |
|
5180 | 5193 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
5181 | 5194 | elif currentbranchheads > 1: |
|
5182 | 5195 | ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to " |
|
5183 | 5196 | "merge)\n")) |
|
5184 | 5197 | else: |
|
5185 | 5198 | ui.status(_("(run 'hg heads' to see heads)\n")) |
|
5186 | 5199 | else: |
|
5187 | 5200 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
5188 | 5201 | |
|
5189 | 5202 | @command('^pull', |
|
5190 | 5203 | [('u', 'update', None, |
|
5191 | 5204 | _('update to new branch head if changesets were pulled')), |
|
5192 | 5205 | ('f', 'force', None, _('run even when remote repository is unrelated')), |
|
5193 | 5206 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
5194 | 5207 | ('B', 'bookmark', [], _("bookmark to pull"), _('BOOKMARK')), |
|
5195 | 5208 | ('b', 'branch', [], _('a specific branch you would like to pull'), |
|
5196 | 5209 | _('BRANCH')), |
|
5197 | 5210 | ] + remoteopts, |
|
5198 | 5211 | _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')) |
|
5199 | 5212 | def pull(ui, repo, source="default", **opts): |
|
5200 | 5213 | """pull changes from the specified source |
|
5201 | 5214 | |
|
5202 | 5215 | Pull changes from a remote repository to a local one. |
|
5203 | 5216 | |
|
5204 | 5217 | This finds all changes from the repository at the specified path |
|
5205 | 5218 | or URL and adds them to a local repository (the current one unless |
|
5206 | 5219 | -R is specified). By default, this does not update the copy of the |
|
5207 | 5220 | project in the working directory. |
|
5208 | 5221 | |
|
5209 | 5222 | Use :hg:`incoming` if you want to see what would have been added |
|
5210 | 5223 | by a pull at the time you issued this command. If you then decide |
|
5211 | 5224 | to add those changes to the repository, you should use :hg:`pull |
|
5212 | 5225 | -r X` where ``X`` is the last changeset listed by :hg:`incoming`. |
|
5213 | 5226 | |
|
5214 | 5227 | If SOURCE is omitted, the 'default' path will be used. |
|
5215 | 5228 | See :hg:`help urls` for more information. |
|
5216 | 5229 | |
|
5217 | 5230 | Returns 0 on success, 1 if an update had unresolved files. |
|
5218 | 5231 | """ |
|
5219 | 5232 | source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) |
|
5220 | 5233 | ui.status(_('pulling from %s\n') % util.hidepassword(source)) |
|
5221 | 5234 | other = hg.peer(repo, opts, source) |
|
5222 | 5235 | try: |
|
5223 | 5236 | revs, checkout = hg.addbranchrevs(repo, other, branches, |
|
5224 | 5237 | opts.get('rev')) |
|
5225 | 5238 | |
|
5226 | 5239 | |
|
5227 | 5240 | pullopargs = {} |
|
5228 | 5241 | if opts.get('bookmark'): |
|
5229 | 5242 | if not revs: |
|
5230 | 5243 | revs = [] |
|
5231 | 5244 | # The list of bookmark used here is not the one used to actually |
|
5232 | 5245 | # update the bookmark name. This can result in the revision pulled |
|
5233 | 5246 | # not ending up with the name of the bookmark because of a race |
|
5234 | 5247 | # condition on the server. (See issue 4689 for details) |
|
5235 | 5248 | remotebookmarks = other.listkeys('bookmarks') |
|
5236 | 5249 | pullopargs['remotebookmarks'] = remotebookmarks |
|
5237 | 5250 | for b in opts['bookmark']: |
|
5238 | 5251 | if b not in remotebookmarks: |
|
5239 | 5252 | raise util.Abort(_('remote bookmark %s not found!') % b) |
|
5240 | 5253 | revs.append(remotebookmarks[b]) |
|
5241 | 5254 | |
|
5242 | 5255 | if revs: |
|
5243 | 5256 | try: |
|
5244 | 5257 | # When 'rev' is a bookmark name, we cannot guarantee that it |
|
5245 | 5258 | # will be updated with that name because of a race condition |
|
5246 | 5259 | # server side. (See issue 4689 for details) |
|
5247 | 5260 | oldrevs = revs |
|
5248 | 5261 | revs = [] # actually, nodes |
|
5249 | 5262 | for r in oldrevs: |
|
5250 | 5263 | node = other.lookup(r) |
|
5251 | 5264 | revs.append(node) |
|
5252 | 5265 | if r == checkout: |
|
5253 | 5266 | checkout = node |
|
5254 | 5267 | except error.CapabilityError: |
|
5255 | 5268 | err = _("other repository doesn't support revision lookup, " |
|
5256 | 5269 | "so a rev cannot be specified.") |
|
5257 | 5270 | raise util.Abort(err) |
|
5258 | 5271 | |
|
5259 | 5272 | modheads = exchange.pull(repo, other, heads=revs, |
|
5260 | 5273 | force=opts.get('force'), |
|
5261 | 5274 | bookmarks=opts.get('bookmark', ()), |
|
5262 | 5275 | opargs=pullopargs).cgresult |
|
5263 | 5276 | if checkout: |
|
5264 | 5277 | checkout = str(repo.changelog.rev(checkout)) |
|
5265 | 5278 | repo._subtoppath = source |
|
5266 | 5279 | try: |
|
5267 | 5280 | ret = postincoming(ui, repo, modheads, opts.get('update'), checkout) |
|
5268 | 5281 | |
|
5269 | 5282 | finally: |
|
5270 | 5283 | del repo._subtoppath |
|
5271 | 5284 | |
|
5272 | 5285 | finally: |
|
5273 | 5286 | other.close() |
|
5274 | 5287 | return ret |
|
5275 | 5288 | |
|
5276 | 5289 | @command('^push', |
|
5277 | 5290 | [('f', 'force', None, _('force push')), |
|
5278 | 5291 | ('r', 'rev', [], |
|
5279 | 5292 | _('a changeset intended to be included in the destination'), |
|
5280 | 5293 | _('REV')), |
|
5281 | 5294 | ('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')), |
|
5282 | 5295 | ('b', 'branch', [], |
|
5283 | 5296 | _('a specific branch you would like to push'), _('BRANCH')), |
|
5284 | 5297 | ('', 'new-branch', False, _('allow pushing a new branch')), |
|
5285 | 5298 | ] + remoteopts, |
|
5286 | 5299 | _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')) |
|
5287 | 5300 | def push(ui, repo, dest=None, **opts): |
|
5288 | 5301 | """push changes to the specified destination |
|
5289 | 5302 | |
|
5290 | 5303 | Push changesets from the local repository to the specified |
|
5291 | 5304 | destination. |
|
5292 | 5305 | |
|
5293 | 5306 | This operation is symmetrical to pull: it is identical to a pull |
|
5294 | 5307 | in the destination repository from the current one. |
|
5295 | 5308 | |
|
5296 | 5309 | By default, push will not allow creation of new heads at the |
|
5297 | 5310 | destination, since multiple heads would make it unclear which head |
|
5298 | 5311 | to use. In this situation, it is recommended to pull and merge |
|
5299 | 5312 | before pushing. |
|
5300 | 5313 | |
|
5301 | 5314 | Use --new-branch if you want to allow push to create a new named |
|
5302 | 5315 | branch that is not present at the destination. This allows you to |
|
5303 | 5316 | only create a new branch without forcing other changes. |
|
5304 | 5317 | |
|
5305 | 5318 | .. note:: |
|
5306 | 5319 | |
|
5307 | 5320 | Extra care should be taken with the -f/--force option, |
|
5308 | 5321 | which will push all new heads on all branches, an action which will |
|
5309 | 5322 | almost always cause confusion for collaborators. |
|
5310 | 5323 | |
|
5311 | 5324 | If -r/--rev is used, the specified revision and all its ancestors |
|
5312 | 5325 | will be pushed to the remote repository. |
|
5313 | 5326 | |
|
5314 | 5327 | If -B/--bookmark is used, the specified bookmarked revision, its |
|
5315 | 5328 | ancestors, and the bookmark will be pushed to the remote |
|
5316 | 5329 | repository. |
|
5317 | 5330 | |
|
5318 | 5331 | Please see :hg:`help urls` for important details about ``ssh://`` |
|
5319 | 5332 | URLs. If DESTINATION is omitted, a default path will be used. |
|
5320 | 5333 | |
|
5321 | 5334 | Returns 0 if push was successful, 1 if nothing to push. |
|
5322 | 5335 | """ |
|
5323 | 5336 | |
|
5324 | 5337 | if opts.get('bookmark'): |
|
5325 | 5338 | ui.setconfig('bookmarks', 'pushing', opts['bookmark'], 'push') |
|
5326 | 5339 | for b in opts['bookmark']: |
|
5327 | 5340 | # translate -B options to -r so changesets get pushed |
|
5328 | 5341 | if b in repo._bookmarks: |
|
5329 | 5342 | opts.setdefault('rev', []).append(b) |
|
5330 | 5343 | else: |
|
5331 | 5344 | # if we try to push a deleted bookmark, translate it to null |
|
5332 | 5345 | # this lets simultaneous -r, -b options continue working |
|
5333 | 5346 | opts.setdefault('rev', []).append("null") |
|
5334 | 5347 | |
|
5335 | 5348 | path = ui.paths.getpath(dest, default='default') |
|
5336 | 5349 | if not path: |
|
5337 | 5350 | raise util.Abort(_('default repository not configured!'), |
|
5338 | 5351 | hint=_('see the "path" section in "hg help config"')) |
|
5339 | 5352 | dest, branches = path.pushloc, (path.branch, opts.get('branch') or []) |
|
5340 | 5353 | ui.status(_('pushing to %s\n') % util.hidepassword(dest)) |
|
5341 | 5354 | revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) |
|
5342 | 5355 | other = hg.peer(repo, opts, dest) |
|
5343 | 5356 | |
|
5344 | 5357 | if revs: |
|
5345 | 5358 | revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)] |
|
5346 | 5359 | if not revs: |
|
5347 | 5360 | raise util.Abort(_("specified revisions evaluate to an empty set"), |
|
5348 | 5361 | hint=_("use different revision arguments")) |
|
5349 | 5362 | |
|
5350 | 5363 | repo._subtoppath = dest |
|
5351 | 5364 | try: |
|
5352 | 5365 | # push subrepos depth-first for coherent ordering |
|
5353 | 5366 | c = repo[''] |
|
5354 | 5367 | subs = c.substate # only repos that are committed |
|
5355 | 5368 | for s in sorted(subs): |
|
5356 | 5369 | result = c.sub(s).push(opts) |
|
5357 | 5370 | if result == 0: |
|
5358 | 5371 | return not result |
|
5359 | 5372 | finally: |
|
5360 | 5373 | del repo._subtoppath |
|
5361 | 5374 | pushop = exchange.push(repo, other, opts.get('force'), revs=revs, |
|
5362 | 5375 | newbranch=opts.get('new_branch'), |
|
5363 | 5376 | bookmarks=opts.get('bookmark', ())) |
|
5364 | 5377 | |
|
5365 | 5378 | result = not pushop.cgresult |
|
5366 | 5379 | |
|
5367 | 5380 | if pushop.bkresult is not None: |
|
5368 | 5381 | if pushop.bkresult == 2: |
|
5369 | 5382 | result = 2 |
|
5370 | 5383 | elif not result and pushop.bkresult: |
|
5371 | 5384 | result = 2 |
|
5372 | 5385 | |
|
5373 | 5386 | return result |
|
5374 | 5387 | |
|
5375 | 5388 | @command('recover', []) |
|
5376 | 5389 | def recover(ui, repo): |
|
5377 | 5390 | """roll back an interrupted transaction |
|
5378 | 5391 | |
|
5379 | 5392 | Recover from an interrupted commit or pull. |
|
5380 | 5393 | |
|
5381 | 5394 | This command tries to fix the repository status after an |
|
5382 | 5395 | interrupted operation. It should only be necessary when Mercurial |
|
5383 | 5396 | suggests it. |
|
5384 | 5397 | |
|
5385 | 5398 | Returns 0 if successful, 1 if nothing to recover or verify fails. |
|
5386 | 5399 | """ |
|
5387 | 5400 | if repo.recover(): |
|
5388 | 5401 | return hg.verify(repo) |
|
5389 | 5402 | return 1 |
|
5390 | 5403 | |
|
5391 | 5404 | @command('^remove|rm', |
|
5392 | 5405 | [('A', 'after', None, _('record delete for missing files')), |
|
5393 | 5406 | ('f', 'force', None, |
|
5394 | 5407 | _('remove (and delete) file even if added or modified')), |
|
5395 | 5408 | ] + subrepoopts + walkopts, |
|
5396 | 5409 | _('[OPTION]... FILE...'), |
|
5397 | 5410 | inferrepo=True) |
|
5398 | 5411 | def remove(ui, repo, *pats, **opts): |
|
5399 | 5412 | """remove the specified files on the next commit |
|
5400 | 5413 | |
|
5401 | 5414 | Schedule the indicated files for removal from the current branch. |
|
5402 | 5415 | |
|
5403 | 5416 | This command schedules the files to be removed at the next commit. |
|
5404 | 5417 | To undo a remove before that, see :hg:`revert`. To undo added |
|
5405 | 5418 | files, see :hg:`forget`. |
|
5406 | 5419 | |
|
5407 | 5420 | .. container:: verbose |
|
5408 | 5421 | |
|
5409 | 5422 | -A/--after can be used to remove only files that have already |
|
5410 | 5423 | been deleted, -f/--force can be used to force deletion, and -Af |
|
5411 | 5424 | can be used to remove files from the next revision without |
|
5412 | 5425 | deleting them from the working directory. |
|
5413 | 5426 | |
|
5414 | 5427 | The following table details the behavior of remove for different |
|
5415 | 5428 | file states (columns) and option combinations (rows). The file |
|
5416 | 5429 | states are Added [A], Clean [C], Modified [M] and Missing [!] |
|
5417 | 5430 | (as reported by :hg:`status`). The actions are Warn, Remove |
|
5418 | 5431 | (from branch) and Delete (from disk): |
|
5419 | 5432 | |
|
5420 | 5433 | ========= == == == == |
|
5421 | 5434 | opt/state A C M ! |
|
5422 | 5435 | ========= == == == == |
|
5423 | 5436 | none W RD W R |
|
5424 | 5437 | -f R RD RD R |
|
5425 | 5438 | -A W W W R |
|
5426 | 5439 | -Af R R R R |
|
5427 | 5440 | ========= == == == == |
|
5428 | 5441 | |
|
5429 | 5442 | Note that remove never deletes files in Added [A] state from the |
|
5430 | 5443 | working directory, not even if option --force is specified. |
|
5431 | 5444 | |
|
5432 | 5445 | Returns 0 on success, 1 if any warnings encountered. |
|
5433 | 5446 | """ |
|
5434 | 5447 | |
|
5435 | 5448 | after, force = opts.get('after'), opts.get('force') |
|
5436 | 5449 | if not pats and not after: |
|
5437 | 5450 | raise util.Abort(_('no files specified')) |
|
5438 | 5451 | |
|
5439 | 5452 | m = scmutil.match(repo[None], pats, opts) |
|
5440 | 5453 | subrepos = opts.get('subrepos') |
|
5441 | 5454 | return cmdutil.remove(ui, repo, m, "", after, force, subrepos) |
|
5442 | 5455 | |
|
5443 | 5456 | @command('rename|move|mv', |
|
5444 | 5457 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
5445 | 5458 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
5446 | 5459 | ] + walkopts + dryrunopts, |
|
5447 | 5460 | _('[OPTION]... SOURCE... DEST')) |
|
5448 | 5461 | def rename(ui, repo, *pats, **opts): |
|
5449 | 5462 | """rename files; equivalent of copy + remove |
|
5450 | 5463 | |
|
5451 | 5464 | Mark dest as copies of sources; mark sources for deletion. If dest |
|
5452 | 5465 | is a directory, copies are put in that directory. If dest is a |
|
5453 | 5466 | file, there can only be one source. |
|
5454 | 5467 | |
|
5455 | 5468 | By default, this command copies the contents of files as they |
|
5456 | 5469 | exist in the working directory. If invoked with -A/--after, the |
|
5457 | 5470 | operation is recorded, but no copying is performed. |
|
5458 | 5471 | |
|
5459 | 5472 | This command takes effect at the next commit. To undo a rename |
|
5460 | 5473 | before that, see :hg:`revert`. |
|
5461 | 5474 | |
|
5462 | 5475 | Returns 0 on success, 1 if errors are encountered. |
|
5463 | 5476 | """ |
|
5464 | 5477 | wlock = repo.wlock(False) |
|
5465 | 5478 | try: |
|
5466 | 5479 | return cmdutil.copy(ui, repo, pats, opts, rename=True) |
|
5467 | 5480 | finally: |
|
5468 | 5481 | wlock.release() |
|
5469 | 5482 | |
|
5470 | 5483 | @command('resolve', |
|
5471 | 5484 | [('a', 'all', None, _('select all unresolved files')), |
|
5472 | 5485 | ('l', 'list', None, _('list state of files needing merge')), |
|
5473 | 5486 | ('m', 'mark', None, _('mark files as resolved')), |
|
5474 | 5487 | ('u', 'unmark', None, _('mark files as unresolved')), |
|
5475 | 5488 | ('n', 'no-status', None, _('hide status prefix'))] |
|
5476 | 5489 | + mergetoolopts + walkopts + formatteropts, |
|
5477 | 5490 | _('[OPTION]... [FILE]...'), |
|
5478 | 5491 | inferrepo=True) |
|
5479 | 5492 | def resolve(ui, repo, *pats, **opts): |
|
5480 | 5493 | """redo merges or set/view the merge status of files |
|
5481 | 5494 | |
|
5482 | 5495 | Merges with unresolved conflicts are often the result of |
|
5483 | 5496 | non-interactive merging using the ``internal:merge`` configuration |
|
5484 | 5497 | setting, or a command-line merge tool like ``diff3``. The resolve |
|
5485 | 5498 | command is used to manage the files involved in a merge, after |
|
5486 | 5499 | :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the |
|
5487 | 5500 | working directory must have two parents). See :hg:`help |
|
5488 | 5501 | merge-tools` for information on configuring merge tools. |
|
5489 | 5502 | |
|
5490 | 5503 | The resolve command can be used in the following ways: |
|
5491 | 5504 | |
|
5492 | 5505 | - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified |
|
5493 | 5506 | files, discarding any previous merge attempts. Re-merging is not |
|
5494 | 5507 | performed for files already marked as resolved. Use ``--all/-a`` |
|
5495 | 5508 | to select all unresolved files. ``--tool`` can be used to specify |
|
5496 | 5509 | the merge tool used for the given files. It overrides the HGMERGE |
|
5497 | 5510 | environment variable and your configuration files. Previous file |
|
5498 | 5511 | contents are saved with a ``.orig`` suffix. |
|
5499 | 5512 | |
|
5500 | 5513 | - :hg:`resolve -m [FILE]`: mark a file as having been resolved |
|
5501 | 5514 | (e.g. after having manually fixed-up the files). The default is |
|
5502 | 5515 | to mark all unresolved files. |
|
5503 | 5516 | |
|
5504 | 5517 | - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The |
|
5505 | 5518 | default is to mark all resolved files. |
|
5506 | 5519 | |
|
5507 | 5520 | - :hg:`resolve -l`: list files which had or still have conflicts. |
|
5508 | 5521 | In the printed list, ``U`` = unresolved and ``R`` = resolved. |
|
5509 | 5522 | |
|
5510 | 5523 | Note that Mercurial will not let you commit files with unresolved |
|
5511 | 5524 | merge conflicts. You must use :hg:`resolve -m ...` before you can |
|
5512 | 5525 | commit after a conflicting merge. |
|
5513 | 5526 | |
|
5514 | 5527 | Returns 0 on success, 1 if any files fail a resolve attempt. |
|
5515 | 5528 | """ |
|
5516 | 5529 | |
|
5517 | 5530 | all, mark, unmark, show, nostatus = \ |
|
5518 | 5531 | [opts.get(o) for o in 'all mark unmark list no_status'.split()] |
|
5519 | 5532 | |
|
5520 | 5533 | if (show and (mark or unmark)) or (mark and unmark): |
|
5521 | 5534 | raise util.Abort(_("too many options specified")) |
|
5522 | 5535 | if pats and all: |
|
5523 | 5536 | raise util.Abort(_("can't specify --all and patterns")) |
|
5524 | 5537 | if not (all or pats or show or mark or unmark): |
|
5525 | 5538 | raise util.Abort(_('no files or directories specified'), |
|
5526 | 5539 | hint=('use --all to re-merge all unresolved files')) |
|
5527 | 5540 | |
|
5528 | 5541 | if show: |
|
5529 | 5542 | fm = ui.formatter('resolve', opts) |
|
5530 | 5543 | ms = mergemod.mergestate(repo) |
|
5531 | 5544 | m = scmutil.match(repo[None], pats, opts) |
|
5532 | 5545 | for f in ms: |
|
5533 | 5546 | if not m(f): |
|
5534 | 5547 | continue |
|
5535 | 5548 | l = 'resolve.' + {'u': 'unresolved', 'r': 'resolved'}[ms[f]] |
|
5536 | 5549 | fm.startitem() |
|
5537 | 5550 | fm.condwrite(not nostatus, 'status', '%s ', ms[f].upper(), label=l) |
|
5538 | 5551 | fm.write('path', '%s\n', f, label=l) |
|
5539 | 5552 | fm.end() |
|
5540 | 5553 | return 0 |
|
5541 | 5554 | |
|
5542 | 5555 | wlock = repo.wlock() |
|
5543 | 5556 | try: |
|
5544 | 5557 | ms = mergemod.mergestate(repo) |
|
5545 | 5558 | |
|
5546 | 5559 | if not (ms.active() or repo.dirstate.p2() != nullid): |
|
5547 | 5560 | raise util.Abort( |
|
5548 | 5561 | _('resolve command not applicable when not merging')) |
|
5549 | 5562 | |
|
5550 | 5563 | m = scmutil.match(repo[None], pats, opts) |
|
5551 | 5564 | ret = 0 |
|
5552 | 5565 | didwork = False |
|
5553 | 5566 | |
|
5554 | 5567 | for f in ms: |
|
5555 | 5568 | if not m(f): |
|
5556 | 5569 | continue |
|
5557 | 5570 | |
|
5558 | 5571 | didwork = True |
|
5559 | 5572 | |
|
5560 | 5573 | if mark: |
|
5561 | 5574 | ms.mark(f, "r") |
|
5562 | 5575 | elif unmark: |
|
5563 | 5576 | ms.mark(f, "u") |
|
5564 | 5577 | else: |
|
5565 | 5578 | wctx = repo[None] |
|
5566 | 5579 | |
|
5567 | 5580 | # backup pre-resolve (merge uses .orig for its own purposes) |
|
5568 | 5581 | a = repo.wjoin(f) |
|
5569 | 5582 | util.copyfile(a, a + ".resolve") |
|
5570 | 5583 | |
|
5571 | 5584 | try: |
|
5572 | 5585 | # resolve file |
|
5573 | 5586 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
5574 | 5587 | 'resolve') |
|
5575 | 5588 | if ms.resolve(f, wctx): |
|
5576 | 5589 | ret = 1 |
|
5577 | 5590 | finally: |
|
5578 | 5591 | ui.setconfig('ui', 'forcemerge', '', 'resolve') |
|
5579 | 5592 | ms.commit() |
|
5580 | 5593 | |
|
5581 | 5594 | # replace filemerge's .orig file with our resolve file |
|
5582 | 5595 | util.rename(a + ".resolve", a + ".orig") |
|
5583 | 5596 | |
|
5584 | 5597 | ms.commit() |
|
5585 | 5598 | |
|
5586 | 5599 | if not didwork and pats: |
|
5587 | 5600 | ui.warn(_("arguments do not match paths that need resolving\n")) |
|
5588 | 5601 | |
|
5589 | 5602 | finally: |
|
5590 | 5603 | wlock.release() |
|
5591 | 5604 | |
|
5592 | 5605 | # Nudge users into finishing an unfinished operation |
|
5593 | 5606 | if not list(ms.unresolved()): |
|
5594 | 5607 | ui.status(_('(no more unresolved files)\n')) |
|
5595 | 5608 | |
|
5596 | 5609 | return ret |
|
5597 | 5610 | |
|
5598 | 5611 | @command('revert', |
|
5599 | 5612 | [('a', 'all', None, _('revert all changes when no arguments given')), |
|
5600 | 5613 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
5601 | 5614 | ('r', 'rev', '', _('revert to the specified revision'), _('REV')), |
|
5602 | 5615 | ('C', 'no-backup', None, _('do not save backup copies of files')), |
|
5603 | 5616 | ('i', 'interactive', None, |
|
5604 | 5617 | _('interactively select the changes (EXPERIMENTAL)')), |
|
5605 | 5618 | ] + walkopts + dryrunopts, |
|
5606 | 5619 | _('[OPTION]... [-r REV] [NAME]...')) |
|
5607 | 5620 | def revert(ui, repo, *pats, **opts): |
|
5608 | 5621 | """restore files to their checkout state |
|
5609 | 5622 | |
|
5610 | 5623 | .. note:: |
|
5611 | 5624 | |
|
5612 | 5625 | To check out earlier revisions, you should use :hg:`update REV`. |
|
5613 | 5626 | To cancel an uncommitted merge (and lose your changes), |
|
5614 | 5627 | use :hg:`update --clean .`. |
|
5615 | 5628 | |
|
5616 | 5629 | With no revision specified, revert the specified files or directories |
|
5617 | 5630 | to the contents they had in the parent of the working directory. |
|
5618 | 5631 | This restores the contents of files to an unmodified |
|
5619 | 5632 | state and unschedules adds, removes, copies, and renames. If the |
|
5620 | 5633 | working directory has two parents, you must explicitly specify a |
|
5621 | 5634 | revision. |
|
5622 | 5635 | |
|
5623 | 5636 | Using the -r/--rev or -d/--date options, revert the given files or |
|
5624 | 5637 | directories to their states as of a specific revision. Because |
|
5625 | 5638 | revert does not change the working directory parents, this will |
|
5626 | 5639 | cause these files to appear modified. This can be helpful to "back |
|
5627 | 5640 | out" some or all of an earlier change. See :hg:`backout` for a |
|
5628 | 5641 | related method. |
|
5629 | 5642 | |
|
5630 | 5643 | Modified files are saved with a .orig suffix before reverting. |
|
5631 | 5644 | To disable these backups, use --no-backup. |
|
5632 | 5645 | |
|
5633 | 5646 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
5634 | 5647 | |
|
5635 | 5648 | See :hg:`help backout` for a way to reverse the effect of an |
|
5636 | 5649 | earlier changeset. |
|
5637 | 5650 | |
|
5638 | 5651 | Returns 0 on success. |
|
5639 | 5652 | """ |
|
5640 | 5653 | |
|
5641 | 5654 | if opts.get("date"): |
|
5642 | 5655 | if opts.get("rev"): |
|
5643 | 5656 | raise util.Abort(_("you can't specify a revision and a date")) |
|
5644 | 5657 | opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) |
|
5645 | 5658 | |
|
5646 | 5659 | parent, p2 = repo.dirstate.parents() |
|
5647 | 5660 | if not opts.get('rev') and p2 != nullid: |
|
5648 | 5661 | # revert after merge is a trap for new users (issue2915) |
|
5649 | 5662 | raise util.Abort(_('uncommitted merge with no revision specified'), |
|
5650 | 5663 | hint=_('use "hg update" or see "hg help revert"')) |
|
5651 | 5664 | |
|
5652 | 5665 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
5653 | 5666 | |
|
5654 | 5667 | if (not (pats or opts.get('include') or opts.get('exclude') or |
|
5655 | 5668 | opts.get('all') or opts.get('interactive'))): |
|
5656 | 5669 | msg = _("no files or directories specified") |
|
5657 | 5670 | if p2 != nullid: |
|
5658 | 5671 | hint = _("uncommitted merge, use --all to discard all changes," |
|
5659 | 5672 | " or 'hg update -C .' to abort the merge") |
|
5660 | 5673 | raise util.Abort(msg, hint=hint) |
|
5661 | 5674 | dirty = any(repo.status()) |
|
5662 | 5675 | node = ctx.node() |
|
5663 | 5676 | if node != parent: |
|
5664 | 5677 | if dirty: |
|
5665 | 5678 | hint = _("uncommitted changes, use --all to discard all" |
|
5666 | 5679 | " changes, or 'hg update %s' to update") % ctx.rev() |
|
5667 | 5680 | else: |
|
5668 | 5681 | hint = _("use --all to revert all files," |
|
5669 | 5682 | " or 'hg update %s' to update") % ctx.rev() |
|
5670 | 5683 | elif dirty: |
|
5671 | 5684 | hint = _("uncommitted changes, use --all to discard all changes") |
|
5672 | 5685 | else: |
|
5673 | 5686 | hint = _("use --all to revert all files") |
|
5674 | 5687 | raise util.Abort(msg, hint=hint) |
|
5675 | 5688 | |
|
5676 | 5689 | return cmdutil.revert(ui, repo, ctx, (parent, p2), *pats, **opts) |
|
5677 | 5690 | |
|
5678 | 5691 | @command('rollback', dryrunopts + |
|
5679 | 5692 | [('f', 'force', False, _('ignore safety measures'))]) |
|
5680 | 5693 | def rollback(ui, repo, **opts): |
|
5681 | 5694 | """roll back the last transaction (DANGEROUS) (DEPRECATED) |
|
5682 | 5695 | |
|
5683 | 5696 | Please use :hg:`commit --amend` instead of rollback to correct |
|
5684 | 5697 | mistakes in the last commit. |
|
5685 | 5698 | |
|
5686 | 5699 | This command should be used with care. There is only one level of |
|
5687 | 5700 | rollback, and there is no way to undo a rollback. It will also |
|
5688 | 5701 | restore the dirstate at the time of the last transaction, losing |
|
5689 | 5702 | any dirstate changes since that time. This command does not alter |
|
5690 | 5703 | the working directory. |
|
5691 | 5704 | |
|
5692 | 5705 | Transactions are used to encapsulate the effects of all commands |
|
5693 | 5706 | that create new changesets or propagate existing changesets into a |
|
5694 | 5707 | repository. |
|
5695 | 5708 | |
|
5696 | 5709 | .. container:: verbose |
|
5697 | 5710 | |
|
5698 | 5711 | For example, the following commands are transactional, and their |
|
5699 | 5712 | effects can be rolled back: |
|
5700 | 5713 | |
|
5701 | 5714 | - commit |
|
5702 | 5715 | - import |
|
5703 | 5716 | - pull |
|
5704 | 5717 | - push (with this repository as the destination) |
|
5705 | 5718 | - unbundle |
|
5706 | 5719 | |
|
5707 | 5720 | To avoid permanent data loss, rollback will refuse to rollback a |
|
5708 | 5721 | commit transaction if it isn't checked out. Use --force to |
|
5709 | 5722 | override this protection. |
|
5710 | 5723 | |
|
5711 | 5724 | This command is not intended for use on public repositories. Once |
|
5712 | 5725 | changes are visible for pull by other users, rolling a transaction |
|
5713 | 5726 | back locally is ineffective (someone else may already have pulled |
|
5714 | 5727 | the changes). Furthermore, a race is possible with readers of the |
|
5715 | 5728 | repository; for example an in-progress pull from the repository |
|
5716 | 5729 | may fail if a rollback is performed. |
|
5717 | 5730 | |
|
5718 | 5731 | Returns 0 on success, 1 if no rollback data is available. |
|
5719 | 5732 | """ |
|
5720 | 5733 | return repo.rollback(dryrun=opts.get('dry_run'), |
|
5721 | 5734 | force=opts.get('force')) |
|
5722 | 5735 | |
|
5723 | 5736 | @command('root', []) |
|
5724 | 5737 | def root(ui, repo): |
|
5725 | 5738 | """print the root (top) of the current working directory |
|
5726 | 5739 | |
|
5727 | 5740 | Print the root directory of the current repository. |
|
5728 | 5741 | |
|
5729 | 5742 | Returns 0 on success. |
|
5730 | 5743 | """ |
|
5731 | 5744 | ui.write(repo.root + "\n") |
|
5732 | 5745 | |
|
5733 | 5746 | @command('^serve', |
|
5734 | 5747 | [('A', 'accesslog', '', _('name of access log file to write to'), |
|
5735 | 5748 | _('FILE')), |
|
5736 | 5749 | ('d', 'daemon', None, _('run server in background')), |
|
5737 | 5750 | ('', 'daemon-pipefds', '', _('used internally by daemon mode'), _('FILE')), |
|
5738 | 5751 | ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')), |
|
5739 | 5752 | # use string type, then we can check if something was passed |
|
5740 | 5753 | ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')), |
|
5741 | 5754 | ('a', 'address', '', _('address to listen on (default: all interfaces)'), |
|
5742 | 5755 | _('ADDR')), |
|
5743 | 5756 | ('', 'prefix', '', _('prefix path to serve from (default: server root)'), |
|
5744 | 5757 | _('PREFIX')), |
|
5745 | 5758 | ('n', 'name', '', |
|
5746 | 5759 | _('name to show in web pages (default: working directory)'), _('NAME')), |
|
5747 | 5760 | ('', 'web-conf', '', |
|
5748 | 5761 | _('name of the hgweb config file (see "hg help hgweb")'), _('FILE')), |
|
5749 | 5762 | ('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'), |
|
5750 | 5763 | _('FILE')), |
|
5751 | 5764 | ('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')), |
|
5752 | 5765 | ('', 'stdio', None, _('for remote clients')), |
|
5753 | 5766 | ('', 'cmdserver', '', _('for remote clients'), _('MODE')), |
|
5754 | 5767 | ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')), |
|
5755 | 5768 | ('', 'style', '', _('template style to use'), _('STYLE')), |
|
5756 | 5769 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')), |
|
5757 | 5770 | ('', 'certificate', '', _('SSL certificate file'), _('FILE'))], |
|
5758 | 5771 | _('[OPTION]...'), |
|
5759 | 5772 | optionalrepo=True) |
|
5760 | 5773 | def serve(ui, repo, **opts): |
|
5761 | 5774 | """start stand-alone webserver |
|
5762 | 5775 | |
|
5763 | 5776 | Start a local HTTP repository browser and pull server. You can use |
|
5764 | 5777 | this for ad-hoc sharing and browsing of repositories. It is |
|
5765 | 5778 | recommended to use a real web server to serve a repository for |
|
5766 | 5779 | longer periods of time. |
|
5767 | 5780 | |
|
5768 | 5781 | Please note that the server does not implement access control. |
|
5769 | 5782 | This means that, by default, anybody can read from the server and |
|
5770 | 5783 | nobody can write to it by default. Set the ``web.allow_push`` |
|
5771 | 5784 | option to ``*`` to allow everybody to push to the server. You |
|
5772 | 5785 | should use a real web server if you need to authenticate users. |
|
5773 | 5786 | |
|
5774 | 5787 | By default, the server logs accesses to stdout and errors to |
|
5775 | 5788 | stderr. Use the -A/--accesslog and -E/--errorlog options to log to |
|
5776 | 5789 | files. |
|
5777 | 5790 | |
|
5778 | 5791 | To have the server choose a free port number to listen on, specify |
|
5779 | 5792 | a port number of 0; in this case, the server will print the port |
|
5780 | 5793 | number it uses. |
|
5781 | 5794 | |
|
5782 | 5795 | Returns 0 on success. |
|
5783 | 5796 | """ |
|
5784 | 5797 | |
|
5785 | 5798 | if opts["stdio"] and opts["cmdserver"]: |
|
5786 | 5799 | raise util.Abort(_("cannot use --stdio with --cmdserver")) |
|
5787 | 5800 | |
|
5788 | 5801 | if opts["stdio"]: |
|
5789 | 5802 | if repo is None: |
|
5790 | 5803 | raise error.RepoError(_("there is no Mercurial repository here" |
|
5791 | 5804 | " (.hg not found)")) |
|
5792 | 5805 | s = sshserver.sshserver(ui, repo) |
|
5793 | 5806 | s.serve_forever() |
|
5794 | 5807 | |
|
5795 | 5808 | if opts["cmdserver"]: |
|
5796 | 5809 | import commandserver |
|
5797 | 5810 | service = commandserver.createservice(ui, repo, opts) |
|
5798 | 5811 | return cmdutil.service(opts, initfn=service.init, runfn=service.run) |
|
5799 | 5812 | |
|
5800 | 5813 | # this way we can check if something was given in the command-line |
|
5801 | 5814 | if opts.get('port'): |
|
5802 | 5815 | opts['port'] = util.getport(opts.get('port')) |
|
5803 | 5816 | |
|
5804 | 5817 | if repo: |
|
5805 | 5818 | baseui = repo.baseui |
|
5806 | 5819 | else: |
|
5807 | 5820 | baseui = ui |
|
5808 | 5821 | optlist = ("name templates style address port prefix ipv6" |
|
5809 | 5822 | " accesslog errorlog certificate encoding") |
|
5810 | 5823 | for o in optlist.split(): |
|
5811 | 5824 | val = opts.get(o, '') |
|
5812 | 5825 | if val in (None, ''): # should check against default options instead |
|
5813 | 5826 | continue |
|
5814 | 5827 | baseui.setconfig("web", o, val, 'serve') |
|
5815 | 5828 | if repo and repo.ui != baseui: |
|
5816 | 5829 | repo.ui.setconfig("web", o, val, 'serve') |
|
5817 | 5830 | |
|
5818 | 5831 | o = opts.get('web_conf') or opts.get('webdir_conf') |
|
5819 | 5832 | if not o: |
|
5820 | 5833 | if not repo: |
|
5821 | 5834 | raise error.RepoError(_("there is no Mercurial repository" |
|
5822 | 5835 | " here (.hg not found)")) |
|
5823 | 5836 | o = repo |
|
5824 | 5837 | |
|
5825 | 5838 | app = hgweb.hgweb(o, baseui=baseui) |
|
5826 | 5839 | service = httpservice(ui, app, opts) |
|
5827 | 5840 | cmdutil.service(opts, initfn=service.init, runfn=service.run) |
|
5828 | 5841 | |
|
5829 | 5842 | class httpservice(object): |
|
5830 | 5843 | def __init__(self, ui, app, opts): |
|
5831 | 5844 | self.ui = ui |
|
5832 | 5845 | self.app = app |
|
5833 | 5846 | self.opts = opts |
|
5834 | 5847 | |
|
5835 | 5848 | def init(self): |
|
5836 | 5849 | util.setsignalhandler() |
|
5837 | 5850 | self.httpd = hgweb_server.create_server(self.ui, self.app) |
|
5838 | 5851 | |
|
5839 | 5852 | if self.opts['port'] and not self.ui.verbose: |
|
5840 | 5853 | return |
|
5841 | 5854 | |
|
5842 | 5855 | if self.httpd.prefix: |
|
5843 | 5856 | prefix = self.httpd.prefix.strip('/') + '/' |
|
5844 | 5857 | else: |
|
5845 | 5858 | prefix = '' |
|
5846 | 5859 | |
|
5847 | 5860 | port = ':%d' % self.httpd.port |
|
5848 | 5861 | if port == ':80': |
|
5849 | 5862 | port = '' |
|
5850 | 5863 | |
|
5851 | 5864 | bindaddr = self.httpd.addr |
|
5852 | 5865 | if bindaddr == '0.0.0.0': |
|
5853 | 5866 | bindaddr = '*' |
|
5854 | 5867 | elif ':' in bindaddr: # IPv6 |
|
5855 | 5868 | bindaddr = '[%s]' % bindaddr |
|
5856 | 5869 | |
|
5857 | 5870 | fqaddr = self.httpd.fqaddr |
|
5858 | 5871 | if ':' in fqaddr: |
|
5859 | 5872 | fqaddr = '[%s]' % fqaddr |
|
5860 | 5873 | if self.opts['port']: |
|
5861 | 5874 | write = self.ui.status |
|
5862 | 5875 | else: |
|
5863 | 5876 | write = self.ui.write |
|
5864 | 5877 | write(_('listening at http://%s%s/%s (bound to %s:%d)\n') % |
|
5865 | 5878 | (fqaddr, port, prefix, bindaddr, self.httpd.port)) |
|
5866 | 5879 | self.ui.flush() # avoid buffering of status message |
|
5867 | 5880 | |
|
5868 | 5881 | def run(self): |
|
5869 | 5882 | self.httpd.serve_forever() |
|
5870 | 5883 | |
|
5871 | 5884 | |
|
5872 | 5885 | @command('^status|st', |
|
5873 | 5886 | [('A', 'all', None, _('show status of all files')), |
|
5874 | 5887 | ('m', 'modified', None, _('show only modified files')), |
|
5875 | 5888 | ('a', 'added', None, _('show only added files')), |
|
5876 | 5889 | ('r', 'removed', None, _('show only removed files')), |
|
5877 | 5890 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
5878 | 5891 | ('c', 'clean', None, _('show only files without changes')), |
|
5879 | 5892 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
5880 | 5893 | ('i', 'ignored', None, _('show only ignored files')), |
|
5881 | 5894 | ('n', 'no-status', None, _('hide status prefix')), |
|
5882 | 5895 | ('C', 'copies', None, _('show source of copied files')), |
|
5883 | 5896 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
5884 | 5897 | ('', 'rev', [], _('show difference from revision'), _('REV')), |
|
5885 | 5898 | ('', 'change', '', _('list the changed files of a revision'), _('REV')), |
|
5886 | 5899 | ] + walkopts + subrepoopts + formatteropts, |
|
5887 | 5900 | _('[OPTION]... [FILE]...'), |
|
5888 | 5901 | inferrepo=True) |
|
5889 | 5902 | def status(ui, repo, *pats, **opts): |
|
5890 | 5903 | """show changed files in the working directory |
|
5891 | 5904 | |
|
5892 | 5905 | Show status of files in the repository. If names are given, only |
|
5893 | 5906 | files that match are shown. Files that are clean or ignored or |
|
5894 | 5907 | the source of a copy/move operation, are not listed unless |
|
5895 | 5908 | -c/--clean, -i/--ignored, -C/--copies or -A/--all are given. |
|
5896 | 5909 | Unless options described with "show only ..." are given, the |
|
5897 | 5910 | options -mardu are used. |
|
5898 | 5911 | |
|
5899 | 5912 | Option -q/--quiet hides untracked (unknown and ignored) files |
|
5900 | 5913 | unless explicitly requested with -u/--unknown or -i/--ignored. |
|
5901 | 5914 | |
|
5902 | 5915 | .. note:: |
|
5903 | 5916 | |
|
5904 | 5917 | status may appear to disagree with diff if permissions have |
|
5905 | 5918 | changed or a merge has occurred. The standard diff format does |
|
5906 | 5919 | not report permission changes and diff only reports changes |
|
5907 | 5920 | relative to one merge parent. |
|
5908 | 5921 | |
|
5909 | 5922 | If one revision is given, it is used as the base revision. |
|
5910 | 5923 | If two revisions are given, the differences between them are |
|
5911 | 5924 | shown. The --change option can also be used as a shortcut to list |
|
5912 | 5925 | the changed files of a revision from its first parent. |
|
5913 | 5926 | |
|
5914 | 5927 | The codes used to show the status of files are:: |
|
5915 | 5928 | |
|
5916 | 5929 | M = modified |
|
5917 | 5930 | A = added |
|
5918 | 5931 | R = removed |
|
5919 | 5932 | C = clean |
|
5920 | 5933 | ! = missing (deleted by non-hg command, but still tracked) |
|
5921 | 5934 | ? = not tracked |
|
5922 | 5935 | I = ignored |
|
5923 | 5936 | = origin of the previous file (with --copies) |
|
5924 | 5937 | |
|
5925 | 5938 | .. container:: verbose |
|
5926 | 5939 | |
|
5927 | 5940 | Examples: |
|
5928 | 5941 | |
|
5929 | 5942 | - show changes in the working directory relative to a |
|
5930 | 5943 | changeset:: |
|
5931 | 5944 | |
|
5932 | 5945 | hg status --rev 9353 |
|
5933 | 5946 | |
|
5934 | 5947 | - show changes in the working directory relative to the |
|
5935 | 5948 | current directory (see :hg:`help patterns` for more information):: |
|
5936 | 5949 | |
|
5937 | 5950 | hg status re: |
|
5938 | 5951 | |
|
5939 | 5952 | - show all changes including copies in an existing changeset:: |
|
5940 | 5953 | |
|
5941 | 5954 | hg status --copies --change 9353 |
|
5942 | 5955 | |
|
5943 | 5956 | - get a NUL separated list of added files, suitable for xargs:: |
|
5944 | 5957 | |
|
5945 | 5958 | hg status -an0 |
|
5946 | 5959 | |
|
5947 | 5960 | Returns 0 on success. |
|
5948 | 5961 | """ |
|
5949 | 5962 | |
|
5950 | 5963 | revs = opts.get('rev') |
|
5951 | 5964 | change = opts.get('change') |
|
5952 | 5965 | |
|
5953 | 5966 | if revs and change: |
|
5954 | 5967 | msg = _('cannot specify --rev and --change at the same time') |
|
5955 | 5968 | raise util.Abort(msg) |
|
5956 | 5969 | elif change: |
|
5957 | 5970 | node2 = scmutil.revsingle(repo, change, None).node() |
|
5958 | 5971 | node1 = repo[node2].p1().node() |
|
5959 | 5972 | else: |
|
5960 | 5973 | node1, node2 = scmutil.revpair(repo, revs) |
|
5961 | 5974 | |
|
5962 | 5975 | if pats: |
|
5963 | 5976 | cwd = repo.getcwd() |
|
5964 | 5977 | else: |
|
5965 | 5978 | cwd = '' |
|
5966 | 5979 | |
|
5967 | 5980 | if opts.get('print0'): |
|
5968 | 5981 | end = '\0' |
|
5969 | 5982 | else: |
|
5970 | 5983 | end = '\n' |
|
5971 | 5984 | copy = {} |
|
5972 | 5985 | states = 'modified added removed deleted unknown ignored clean'.split() |
|
5973 | 5986 | show = [k for k in states if opts.get(k)] |
|
5974 | 5987 | if opts.get('all'): |
|
5975 | 5988 | show += ui.quiet and (states[:4] + ['clean']) or states |
|
5976 | 5989 | if not show: |
|
5977 | 5990 | if ui.quiet: |
|
5978 | 5991 | show = states[:4] |
|
5979 | 5992 | else: |
|
5980 | 5993 | show = states[:5] |
|
5981 | 5994 | |
|
5982 | 5995 | m = scmutil.match(repo[node2], pats, opts) |
|
5983 | 5996 | stat = repo.status(node1, node2, m, |
|
5984 | 5997 | 'ignored' in show, 'clean' in show, 'unknown' in show, |
|
5985 | 5998 | opts.get('subrepos')) |
|
5986 | 5999 | changestates = zip(states, 'MAR!?IC', stat) |
|
5987 | 6000 | |
|
5988 | 6001 | if (opts.get('all') or opts.get('copies') |
|
5989 | 6002 | or ui.configbool('ui', 'statuscopies')) and not opts.get('no_status'): |
|
5990 | 6003 | copy = copies.pathcopies(repo[node1], repo[node2], m) |
|
5991 | 6004 | |
|
5992 | 6005 | fm = ui.formatter('status', opts) |
|
5993 | 6006 | fmt = '%s' + end |
|
5994 | 6007 | showchar = not opts.get('no_status') |
|
5995 | 6008 | |
|
5996 | 6009 | for state, char, files in changestates: |
|
5997 | 6010 | if state in show: |
|
5998 | 6011 | label = 'status.' + state |
|
5999 | 6012 | for f in files: |
|
6000 | 6013 | fm.startitem() |
|
6001 | 6014 | fm.condwrite(showchar, 'status', '%s ', char, label=label) |
|
6002 | 6015 | fm.write('path', fmt, repo.pathto(f, cwd), label=label) |
|
6003 | 6016 | if f in copy: |
|
6004 | 6017 | fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd), |
|
6005 | 6018 | label='status.copied') |
|
6006 | 6019 | fm.end() |
|
6007 | 6020 | |
|
6008 | 6021 | @command('^summary|sum', |
|
6009 | 6022 | [('', 'remote', None, _('check for push and pull'))], '[--remote]') |
|
6010 | 6023 | def summary(ui, repo, **opts): |
|
6011 | 6024 | """summarize working directory state |
|
6012 | 6025 | |
|
6013 | 6026 | This generates a brief summary of the working directory state, |
|
6014 | 6027 | including parents, branch, commit status, phase and available updates. |
|
6015 | 6028 | |
|
6016 | 6029 | With the --remote option, this will check the default paths for |
|
6017 | 6030 | incoming and outgoing changes. This can be time-consuming. |
|
6018 | 6031 | |
|
6019 | 6032 | Returns 0 on success. |
|
6020 | 6033 | """ |
|
6021 | 6034 | |
|
6022 | 6035 | ctx = repo[None] |
|
6023 | 6036 | parents = ctx.parents() |
|
6024 | 6037 | pnode = parents[0].node() |
|
6025 | 6038 | marks = [] |
|
6026 | 6039 | |
|
6027 | 6040 | for p in parents: |
|
6028 | 6041 | # label with log.changeset (instead of log.parent) since this |
|
6029 | 6042 | # shows a working directory parent *changeset*: |
|
6030 | 6043 | # i18n: column positioning for "hg summary" |
|
6031 | 6044 | ui.write(_('parent: %d:%s ') % (p.rev(), str(p)), |
|
6032 | 6045 | label='log.changeset changeset.%s' % p.phasestr()) |
|
6033 | 6046 | ui.write(' '.join(p.tags()), label='log.tag') |
|
6034 | 6047 | if p.bookmarks(): |
|
6035 | 6048 | marks.extend(p.bookmarks()) |
|
6036 | 6049 | if p.rev() == -1: |
|
6037 | 6050 | if not len(repo): |
|
6038 | 6051 | ui.write(_(' (empty repository)')) |
|
6039 | 6052 | else: |
|
6040 | 6053 | ui.write(_(' (no revision checked out)')) |
|
6041 | 6054 | ui.write('\n') |
|
6042 | 6055 | if p.description(): |
|
6043 | 6056 | ui.status(' ' + p.description().splitlines()[0].strip() + '\n', |
|
6044 | 6057 | label='log.summary') |
|
6045 | 6058 | |
|
6046 | 6059 | branch = ctx.branch() |
|
6047 | 6060 | bheads = repo.branchheads(branch) |
|
6048 | 6061 | # i18n: column positioning for "hg summary" |
|
6049 | 6062 | m = _('branch: %s\n') % branch |
|
6050 | 6063 | if branch != 'default': |
|
6051 | 6064 | ui.write(m, label='log.branch') |
|
6052 | 6065 | else: |
|
6053 | 6066 | ui.status(m, label='log.branch') |
|
6054 | 6067 | |
|
6055 | 6068 | if marks: |
|
6056 | 6069 | active = repo._activebookmark |
|
6057 | 6070 | # i18n: column positioning for "hg summary" |
|
6058 | 6071 | ui.write(_('bookmarks:'), label='log.bookmark') |
|
6059 | 6072 | if active is not None: |
|
6060 | 6073 | if active in marks: |
|
6061 | 6074 | ui.write(' *' + active, label=activebookmarklabel) |
|
6062 | 6075 | marks.remove(active) |
|
6063 | 6076 | else: |
|
6064 | 6077 | ui.write(' [%s]' % active, label=activebookmarklabel) |
|
6065 | 6078 | for m in marks: |
|
6066 | 6079 | ui.write(' ' + m, label='log.bookmark') |
|
6067 | 6080 | ui.write('\n', label='log.bookmark') |
|
6068 | 6081 | |
|
6069 | 6082 | status = repo.status(unknown=True) |
|
6070 | 6083 | |
|
6071 | 6084 | c = repo.dirstate.copies() |
|
6072 | 6085 | copied, renamed = [], [] |
|
6073 | 6086 | for d, s in c.iteritems(): |
|
6074 | 6087 | if s in status.removed: |
|
6075 | 6088 | status.removed.remove(s) |
|
6076 | 6089 | renamed.append(d) |
|
6077 | 6090 | else: |
|
6078 | 6091 | copied.append(d) |
|
6079 | 6092 | if d in status.added: |
|
6080 | 6093 | status.added.remove(d) |
|
6081 | 6094 | |
|
6082 | 6095 | ms = mergemod.mergestate(repo) |
|
6083 | 6096 | unresolved = [f for f in ms if ms[f] == 'u'] |
|
6084 | 6097 | |
|
6085 | 6098 | subs = [s for s in ctx.substate if ctx.sub(s).dirty()] |
|
6086 | 6099 | |
|
6087 | 6100 | labels = [(ui.label(_('%d modified'), 'status.modified'), status.modified), |
|
6088 | 6101 | (ui.label(_('%d added'), 'status.added'), status.added), |
|
6089 | 6102 | (ui.label(_('%d removed'), 'status.removed'), status.removed), |
|
6090 | 6103 | (ui.label(_('%d renamed'), 'status.copied'), renamed), |
|
6091 | 6104 | (ui.label(_('%d copied'), 'status.copied'), copied), |
|
6092 | 6105 | (ui.label(_('%d deleted'), 'status.deleted'), status.deleted), |
|
6093 | 6106 | (ui.label(_('%d unknown'), 'status.unknown'), status.unknown), |
|
6094 | 6107 | (ui.label(_('%d unresolved'), 'resolve.unresolved'), unresolved), |
|
6095 | 6108 | (ui.label(_('%d subrepos'), 'status.modified'), subs)] |
|
6096 | 6109 | t = [] |
|
6097 | 6110 | for l, s in labels: |
|
6098 | 6111 | if s: |
|
6099 | 6112 | t.append(l % len(s)) |
|
6100 | 6113 | |
|
6101 | 6114 | t = ', '.join(t) |
|
6102 | 6115 | cleanworkdir = False |
|
6103 | 6116 | |
|
6104 | 6117 | if repo.vfs.exists('updatestate'): |
|
6105 | 6118 | t += _(' (interrupted update)') |
|
6106 | 6119 | elif len(parents) > 1: |
|
6107 | 6120 | t += _(' (merge)') |
|
6108 | 6121 | elif branch != parents[0].branch(): |
|
6109 | 6122 | t += _(' (new branch)') |
|
6110 | 6123 | elif (parents[0].closesbranch() and |
|
6111 | 6124 | pnode in repo.branchheads(branch, closed=True)): |
|
6112 | 6125 | t += _(' (head closed)') |
|
6113 | 6126 | elif not (status.modified or status.added or status.removed or renamed or |
|
6114 | 6127 | copied or subs): |
|
6115 | 6128 | t += _(' (clean)') |
|
6116 | 6129 | cleanworkdir = True |
|
6117 | 6130 | elif pnode not in bheads: |
|
6118 | 6131 | t += _(' (new branch head)') |
|
6119 | 6132 | |
|
6120 | 6133 | if parents: |
|
6121 | 6134 | pendingphase = max(p.phase() for p in parents) |
|
6122 | 6135 | else: |
|
6123 | 6136 | pendingphase = phases.public |
|
6124 | 6137 | |
|
6125 | 6138 | if pendingphase > phases.newcommitphase(ui): |
|
6126 | 6139 | t += ' (%s)' % phases.phasenames[pendingphase] |
|
6127 | 6140 | |
|
6128 | 6141 | if cleanworkdir: |
|
6129 | 6142 | # i18n: column positioning for "hg summary" |
|
6130 | 6143 | ui.status(_('commit: %s\n') % t.strip()) |
|
6131 | 6144 | else: |
|
6132 | 6145 | # i18n: column positioning for "hg summary" |
|
6133 | 6146 | ui.write(_('commit: %s\n') % t.strip()) |
|
6134 | 6147 | |
|
6135 | 6148 | # all ancestors of branch heads - all ancestors of parent = new csets |
|
6136 | 6149 | new = len(repo.changelog.findmissing([pctx.node() for pctx in parents], |
|
6137 | 6150 | bheads)) |
|
6138 | 6151 | |
|
6139 | 6152 | if new == 0: |
|
6140 | 6153 | # i18n: column positioning for "hg summary" |
|
6141 | 6154 | ui.status(_('update: (current)\n')) |
|
6142 | 6155 | elif pnode not in bheads: |
|
6143 | 6156 | # i18n: column positioning for "hg summary" |
|
6144 | 6157 | ui.write(_('update: %d new changesets (update)\n') % new) |
|
6145 | 6158 | else: |
|
6146 | 6159 | # i18n: column positioning for "hg summary" |
|
6147 | 6160 | ui.write(_('update: %d new changesets, %d branch heads (merge)\n') % |
|
6148 | 6161 | (new, len(bheads))) |
|
6149 | 6162 | |
|
6150 | 6163 | t = [] |
|
6151 | 6164 | draft = len(repo.revs('draft()')) |
|
6152 | 6165 | if draft: |
|
6153 | 6166 | t.append(_('%d draft') % draft) |
|
6154 | 6167 | secret = len(repo.revs('secret()')) |
|
6155 | 6168 | if secret: |
|
6156 | 6169 | t.append(_('%d secret') % secret) |
|
6157 | 6170 | |
|
6158 | 6171 | if draft or secret: |
|
6159 | 6172 | ui.status(_('phases: %s\n') % ', '.join(t)) |
|
6160 | 6173 | |
|
6161 | 6174 | cmdutil.summaryhooks(ui, repo) |
|
6162 | 6175 | |
|
6163 | 6176 | if opts.get('remote'): |
|
6164 | 6177 | needsincoming, needsoutgoing = True, True |
|
6165 | 6178 | else: |
|
6166 | 6179 | needsincoming, needsoutgoing = False, False |
|
6167 | 6180 | for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None): |
|
6168 | 6181 | if i: |
|
6169 | 6182 | needsincoming = True |
|
6170 | 6183 | if o: |
|
6171 | 6184 | needsoutgoing = True |
|
6172 | 6185 | if not needsincoming and not needsoutgoing: |
|
6173 | 6186 | return |
|
6174 | 6187 | |
|
6175 | 6188 | def getincoming(): |
|
6176 | 6189 | source, branches = hg.parseurl(ui.expandpath('default')) |
|
6177 | 6190 | sbranch = branches[0] |
|
6178 | 6191 | try: |
|
6179 | 6192 | other = hg.peer(repo, {}, source) |
|
6180 | 6193 | except error.RepoError: |
|
6181 | 6194 | if opts.get('remote'): |
|
6182 | 6195 | raise |
|
6183 | 6196 | return source, sbranch, None, None, None |
|
6184 | 6197 | revs, checkout = hg.addbranchrevs(repo, other, branches, None) |
|
6185 | 6198 | if revs: |
|
6186 | 6199 | revs = [other.lookup(rev) for rev in revs] |
|
6187 | 6200 | ui.debug('comparing with %s\n' % util.hidepassword(source)) |
|
6188 | 6201 | repo.ui.pushbuffer() |
|
6189 | 6202 | commoninc = discovery.findcommonincoming(repo, other, heads=revs) |
|
6190 | 6203 | repo.ui.popbuffer() |
|
6191 | 6204 | return source, sbranch, other, commoninc, commoninc[1] |
|
6192 | 6205 | |
|
6193 | 6206 | if needsincoming: |
|
6194 | 6207 | source, sbranch, sother, commoninc, incoming = getincoming() |
|
6195 | 6208 | else: |
|
6196 | 6209 | source = sbranch = sother = commoninc = incoming = None |
|
6197 | 6210 | |
|
6198 | 6211 | def getoutgoing(): |
|
6199 | 6212 | dest, branches = hg.parseurl(ui.expandpath('default-push', 'default')) |
|
6200 | 6213 | dbranch = branches[0] |
|
6201 | 6214 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) |
|
6202 | 6215 | if source != dest: |
|
6203 | 6216 | try: |
|
6204 | 6217 | dother = hg.peer(repo, {}, dest) |
|
6205 | 6218 | except error.RepoError: |
|
6206 | 6219 | if opts.get('remote'): |
|
6207 | 6220 | raise |
|
6208 | 6221 | return dest, dbranch, None, None |
|
6209 | 6222 | ui.debug('comparing with %s\n' % util.hidepassword(dest)) |
|
6210 | 6223 | elif sother is None: |
|
6211 | 6224 | # there is no explicit destination peer, but source one is invalid |
|
6212 | 6225 | return dest, dbranch, None, None |
|
6213 | 6226 | else: |
|
6214 | 6227 | dother = sother |
|
6215 | 6228 | if (source != dest or (sbranch is not None and sbranch != dbranch)): |
|
6216 | 6229 | common = None |
|
6217 | 6230 | else: |
|
6218 | 6231 | common = commoninc |
|
6219 | 6232 | if revs: |
|
6220 | 6233 | revs = [repo.lookup(rev) for rev in revs] |
|
6221 | 6234 | repo.ui.pushbuffer() |
|
6222 | 6235 | outgoing = discovery.findcommonoutgoing(repo, dother, onlyheads=revs, |
|
6223 | 6236 | commoninc=common) |
|
6224 | 6237 | repo.ui.popbuffer() |
|
6225 | 6238 | return dest, dbranch, dother, outgoing |
|
6226 | 6239 | |
|
6227 | 6240 | if needsoutgoing: |
|
6228 | 6241 | dest, dbranch, dother, outgoing = getoutgoing() |
|
6229 | 6242 | else: |
|
6230 | 6243 | dest = dbranch = dother = outgoing = None |
|
6231 | 6244 | |
|
6232 | 6245 | if opts.get('remote'): |
|
6233 | 6246 | t = [] |
|
6234 | 6247 | if incoming: |
|
6235 | 6248 | t.append(_('1 or more incoming')) |
|
6236 | 6249 | o = outgoing.missing |
|
6237 | 6250 | if o: |
|
6238 | 6251 | t.append(_('%d outgoing') % len(o)) |
|
6239 | 6252 | other = dother or sother |
|
6240 | 6253 | if 'bookmarks' in other.listkeys('namespaces'): |
|
6241 | 6254 | counts = bookmarks.summary(repo, other) |
|
6242 | 6255 | if counts[0] > 0: |
|
6243 | 6256 | t.append(_('%d incoming bookmarks') % counts[0]) |
|
6244 | 6257 | if counts[1] > 0: |
|
6245 | 6258 | t.append(_('%d outgoing bookmarks') % counts[1]) |
|
6246 | 6259 | |
|
6247 | 6260 | if t: |
|
6248 | 6261 | # i18n: column positioning for "hg summary" |
|
6249 | 6262 | ui.write(_('remote: %s\n') % (', '.join(t))) |
|
6250 | 6263 | else: |
|
6251 | 6264 | # i18n: column positioning for "hg summary" |
|
6252 | 6265 | ui.status(_('remote: (synced)\n')) |
|
6253 | 6266 | |
|
6254 | 6267 | cmdutil.summaryremotehooks(ui, repo, opts, |
|
6255 | 6268 | ((source, sbranch, sother, commoninc), |
|
6256 | 6269 | (dest, dbranch, dother, outgoing))) |
|
6257 | 6270 | |
|
6258 | 6271 | @command('tag', |
|
6259 | 6272 | [('f', 'force', None, _('force tag')), |
|
6260 | 6273 | ('l', 'local', None, _('make the tag local')), |
|
6261 | 6274 | ('r', 'rev', '', _('revision to tag'), _('REV')), |
|
6262 | 6275 | ('', 'remove', None, _('remove a tag')), |
|
6263 | 6276 | # -l/--local is already there, commitopts cannot be used |
|
6264 | 6277 | ('e', 'edit', None, _('invoke editor on commit messages')), |
|
6265 | 6278 | ('m', 'message', '', _('use text as commit message'), _('TEXT')), |
|
6266 | 6279 | ] + commitopts2, |
|
6267 | 6280 | _('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')) |
|
6268 | 6281 | def tag(ui, repo, name1, *names, **opts): |
|
6269 | 6282 | """add one or more tags for the current or given revision |
|
6270 | 6283 | |
|
6271 | 6284 | Name a particular revision using <name>. |
|
6272 | 6285 | |
|
6273 | 6286 | Tags are used to name particular revisions of the repository and are |
|
6274 | 6287 | very useful to compare different revisions, to go back to significant |
|
6275 | 6288 | earlier versions or to mark branch points as releases, etc. Changing |
|
6276 | 6289 | an existing tag is normally disallowed; use -f/--force to override. |
|
6277 | 6290 | |
|
6278 | 6291 | If no revision is given, the parent of the working directory is |
|
6279 | 6292 | used. |
|
6280 | 6293 | |
|
6281 | 6294 | To facilitate version control, distribution, and merging of tags, |
|
6282 | 6295 | they are stored as a file named ".hgtags" which is managed similarly |
|
6283 | 6296 | to other project files and can be hand-edited if necessary. This |
|
6284 | 6297 | also means that tagging creates a new commit. The file |
|
6285 | 6298 | ".hg/localtags" is used for local tags (not shared among |
|
6286 | 6299 | repositories). |
|
6287 | 6300 | |
|
6288 | 6301 | Tag commits are usually made at the head of a branch. If the parent |
|
6289 | 6302 | of the working directory is not a branch head, :hg:`tag` aborts; use |
|
6290 | 6303 | -f/--force to force the tag commit to be based on a non-head |
|
6291 | 6304 | changeset. |
|
6292 | 6305 | |
|
6293 | 6306 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
6294 | 6307 | |
|
6295 | 6308 | Since tag names have priority over branch names during revision |
|
6296 | 6309 | lookup, using an existing branch name as a tag name is discouraged. |
|
6297 | 6310 | |
|
6298 | 6311 | Returns 0 on success. |
|
6299 | 6312 | """ |
|
6300 | 6313 | wlock = lock = None |
|
6301 | 6314 | try: |
|
6302 | 6315 | wlock = repo.wlock() |
|
6303 | 6316 | lock = repo.lock() |
|
6304 | 6317 | rev_ = "." |
|
6305 | 6318 | names = [t.strip() for t in (name1,) + names] |
|
6306 | 6319 | if len(names) != len(set(names)): |
|
6307 | 6320 | raise util.Abort(_('tag names must be unique')) |
|
6308 | 6321 | for n in names: |
|
6309 | 6322 | scmutil.checknewlabel(repo, n, 'tag') |
|
6310 | 6323 | if not n: |
|
6311 | 6324 | raise util.Abort(_('tag names cannot consist entirely of ' |
|
6312 | 6325 | 'whitespace')) |
|
6313 | 6326 | if opts.get('rev') and opts.get('remove'): |
|
6314 | 6327 | raise util.Abort(_("--rev and --remove are incompatible")) |
|
6315 | 6328 | if opts.get('rev'): |
|
6316 | 6329 | rev_ = opts['rev'] |
|
6317 | 6330 | message = opts.get('message') |
|
6318 | 6331 | if opts.get('remove'): |
|
6319 | 6332 | if opts.get('local'): |
|
6320 | 6333 | expectedtype = 'local' |
|
6321 | 6334 | else: |
|
6322 | 6335 | expectedtype = 'global' |
|
6323 | 6336 | |
|
6324 | 6337 | for n in names: |
|
6325 | 6338 | if not repo.tagtype(n): |
|
6326 | 6339 | raise util.Abort(_("tag '%s' does not exist") % n) |
|
6327 | 6340 | if repo.tagtype(n) != expectedtype: |
|
6328 | 6341 | if expectedtype == 'global': |
|
6329 | 6342 | raise util.Abort(_("tag '%s' is not a global tag") % n) |
|
6330 | 6343 | else: |
|
6331 | 6344 | raise util.Abort(_("tag '%s' is not a local tag") % n) |
|
6332 | 6345 | rev_ = 'null' |
|
6333 | 6346 | if not message: |
|
6334 | 6347 | # we don't translate commit messages |
|
6335 | 6348 | message = 'Removed tag %s' % ', '.join(names) |
|
6336 | 6349 | elif not opts.get('force'): |
|
6337 | 6350 | for n in names: |
|
6338 | 6351 | if n in repo.tags(): |
|
6339 | 6352 | raise util.Abort(_("tag '%s' already exists " |
|
6340 | 6353 | "(use -f to force)") % n) |
|
6341 | 6354 | if not opts.get('local'): |
|
6342 | 6355 | p1, p2 = repo.dirstate.parents() |
|
6343 | 6356 | if p2 != nullid: |
|
6344 | 6357 | raise util.Abort(_('uncommitted merge')) |
|
6345 | 6358 | bheads = repo.branchheads() |
|
6346 | 6359 | if not opts.get('force') and bheads and p1 not in bheads: |
|
6347 | 6360 | raise util.Abort(_('not at a branch head (use -f to force)')) |
|
6348 | 6361 | r = scmutil.revsingle(repo, rev_).node() |
|
6349 | 6362 | |
|
6350 | 6363 | if not message: |
|
6351 | 6364 | # we don't translate commit messages |
|
6352 | 6365 | message = ('Added tag %s for changeset %s' % |
|
6353 | 6366 | (', '.join(names), short(r))) |
|
6354 | 6367 | |
|
6355 | 6368 | date = opts.get('date') |
|
6356 | 6369 | if date: |
|
6357 | 6370 | date = util.parsedate(date) |
|
6358 | 6371 | |
|
6359 | 6372 | if opts.get('remove'): |
|
6360 | 6373 | editform = 'tag.remove' |
|
6361 | 6374 | else: |
|
6362 | 6375 | editform = 'tag.add' |
|
6363 | 6376 | editor = cmdutil.getcommiteditor(editform=editform, **opts) |
|
6364 | 6377 | |
|
6365 | 6378 | # don't allow tagging the null rev |
|
6366 | 6379 | if (not opts.get('remove') and |
|
6367 | 6380 | scmutil.revsingle(repo, rev_).rev() == nullrev): |
|
6368 | 6381 | raise util.Abort(_("cannot tag null revision")) |
|
6369 | 6382 | |
|
6370 | 6383 | repo.tag(names, r, message, opts.get('local'), opts.get('user'), date, |
|
6371 | 6384 | editor=editor) |
|
6372 | 6385 | finally: |
|
6373 | 6386 | release(lock, wlock) |
|
6374 | 6387 | |
|
6375 | 6388 | @command('tags', formatteropts, '') |
|
6376 | 6389 | def tags(ui, repo, **opts): |
|
6377 | 6390 | """list repository tags |
|
6378 | 6391 | |
|
6379 | 6392 | This lists both regular and local tags. When the -v/--verbose |
|
6380 | 6393 | switch is used, a third column "local" is printed for local tags. |
|
6381 | 6394 | |
|
6382 | 6395 | Returns 0 on success. |
|
6383 | 6396 | """ |
|
6384 | 6397 | |
|
6385 | 6398 | fm = ui.formatter('tags', opts) |
|
6386 | 6399 | hexfunc = fm.hexfunc |
|
6387 | 6400 | tagtype = "" |
|
6388 | 6401 | |
|
6389 | 6402 | for t, n in reversed(repo.tagslist()): |
|
6390 | 6403 | hn = hexfunc(n) |
|
6391 | 6404 | label = 'tags.normal' |
|
6392 | 6405 | tagtype = '' |
|
6393 | 6406 | if repo.tagtype(t) == 'local': |
|
6394 | 6407 | label = 'tags.local' |
|
6395 | 6408 | tagtype = 'local' |
|
6396 | 6409 | |
|
6397 | 6410 | fm.startitem() |
|
6398 | 6411 | fm.write('tag', '%s', t, label=label) |
|
6399 | 6412 | fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s' |
|
6400 | 6413 | fm.condwrite(not ui.quiet, 'rev node', fmt, |
|
6401 | 6414 | repo.changelog.rev(n), hn, label=label) |
|
6402 | 6415 | fm.condwrite(ui.verbose and tagtype, 'type', ' %s', |
|
6403 | 6416 | tagtype, label=label) |
|
6404 | 6417 | fm.plain('\n') |
|
6405 | 6418 | fm.end() |
|
6406 | 6419 | |
|
6407 | 6420 | @command('tip', |
|
6408 | 6421 | [('p', 'patch', None, _('show patch')), |
|
6409 | 6422 | ('g', 'git', None, _('use git extended diff format')), |
|
6410 | 6423 | ] + templateopts, |
|
6411 | 6424 | _('[-p] [-g]')) |
|
6412 | 6425 | def tip(ui, repo, **opts): |
|
6413 | 6426 | """show the tip revision (DEPRECATED) |
|
6414 | 6427 | |
|
6415 | 6428 | The tip revision (usually just called the tip) is the changeset |
|
6416 | 6429 | most recently added to the repository (and therefore the most |
|
6417 | 6430 | recently changed head). |
|
6418 | 6431 | |
|
6419 | 6432 | If you have just made a commit, that commit will be the tip. If |
|
6420 | 6433 | you have just pulled changes from another repository, the tip of |
|
6421 | 6434 | that repository becomes the current tip. The "tip" tag is special |
|
6422 | 6435 | and cannot be renamed or assigned to a different changeset. |
|
6423 | 6436 | |
|
6424 | 6437 | This command is deprecated, please use :hg:`heads` instead. |
|
6425 | 6438 | |
|
6426 | 6439 | Returns 0 on success. |
|
6427 | 6440 | """ |
|
6428 | 6441 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
6429 | 6442 | displayer.show(repo['tip']) |
|
6430 | 6443 | displayer.close() |
|
6431 | 6444 | |
|
6432 | 6445 | @command('unbundle', |
|
6433 | 6446 | [('u', 'update', None, |
|
6434 | 6447 | _('update to new branch head if changesets were unbundled'))], |
|
6435 | 6448 | _('[-u] FILE...')) |
|
6436 | 6449 | def unbundle(ui, repo, fname1, *fnames, **opts): |
|
6437 | 6450 | """apply one or more changegroup files |
|
6438 | 6451 | |
|
6439 | 6452 | Apply one or more compressed changegroup files generated by the |
|
6440 | 6453 | bundle command. |
|
6441 | 6454 | |
|
6442 | 6455 | Returns 0 on success, 1 if an update has unresolved files. |
|
6443 | 6456 | """ |
|
6444 | 6457 | fnames = (fname1,) + fnames |
|
6445 | 6458 | |
|
6446 | 6459 | lock = repo.lock() |
|
6447 | 6460 | try: |
|
6448 | 6461 | for fname in fnames: |
|
6449 | 6462 | f = hg.openpath(ui, fname) |
|
6450 | 6463 | gen = exchange.readbundle(ui, f, fname) |
|
6451 | 6464 | if isinstance(gen, bundle2.unbundle20): |
|
6452 | 6465 | tr = repo.transaction('unbundle') |
|
6453 | 6466 | try: |
|
6454 | 6467 | op = bundle2.processbundle(repo, gen, lambda: tr) |
|
6455 | 6468 | tr.close() |
|
6456 | 6469 | except error.BundleUnknownFeatureError as exc: |
|
6457 | 6470 | raise util.Abort(_('%s: unknown bundle feature, %s') |
|
6458 | 6471 | % (fname, exc), |
|
6459 | 6472 | hint=_("see https://mercurial-scm.org/" |
|
6460 | 6473 | "wiki/BundleFeature for more " |
|
6461 | 6474 | "information")) |
|
6462 | 6475 | finally: |
|
6463 | 6476 | if tr: |
|
6464 | 6477 | tr.release() |
|
6465 | 6478 | changes = [r.get('result', 0) |
|
6466 | 6479 | for r in op.records['changegroup']] |
|
6467 | 6480 | modheads = changegroup.combineresults(changes) |
|
6468 | 6481 | else: |
|
6469 | 6482 | modheads = changegroup.addchangegroup(repo, gen, 'unbundle', |
|
6470 | 6483 | 'bundle:' + fname) |
|
6471 | 6484 | finally: |
|
6472 | 6485 | lock.release() |
|
6473 | 6486 | |
|
6474 | 6487 | return postincoming(ui, repo, modheads, opts.get('update'), None) |
|
6475 | 6488 | |
|
6476 | 6489 | @command('^update|up|checkout|co', |
|
6477 | 6490 | [('C', 'clean', None, _('discard uncommitted changes (no backup)')), |
|
6478 | 6491 | ('c', 'check', None, |
|
6479 | 6492 | _('update across branches if no uncommitted changes')), |
|
6480 | 6493 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
6481 | 6494 | ('r', 'rev', '', _('revision'), _('REV')) |
|
6482 | 6495 | ] + mergetoolopts, |
|
6483 | 6496 | _('[-c] [-C] [-d DATE] [[-r] REV]')) |
|
6484 | 6497 | def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False, |
|
6485 | 6498 | tool=None): |
|
6486 | 6499 | """update working directory (or switch revisions) |
|
6487 | 6500 | |
|
6488 | 6501 | Update the repository's working directory to the specified |
|
6489 | 6502 | changeset. If no changeset is specified, update to the tip of the |
|
6490 | 6503 | current named branch and move the active bookmark (see :hg:`help |
|
6491 | 6504 | bookmarks`). |
|
6492 | 6505 | |
|
6493 | 6506 | Update sets the working directory's parent revision to the specified |
|
6494 | 6507 | changeset (see :hg:`help parents`). |
|
6495 | 6508 | |
|
6496 | 6509 | If the changeset is not a descendant or ancestor of the working |
|
6497 | 6510 | directory's parent, the update is aborted. With the -c/--check |
|
6498 | 6511 | option, the working directory is checked for uncommitted changes; if |
|
6499 | 6512 | none are found, the working directory is updated to the specified |
|
6500 | 6513 | changeset. |
|
6501 | 6514 | |
|
6502 | 6515 | .. container:: verbose |
|
6503 | 6516 | |
|
6504 | 6517 | The following rules apply when the working directory contains |
|
6505 | 6518 | uncommitted changes: |
|
6506 | 6519 | |
|
6507 | 6520 | 1. If neither -c/--check nor -C/--clean is specified, and if |
|
6508 | 6521 | the requested changeset is an ancestor or descendant of |
|
6509 | 6522 | the working directory's parent, the uncommitted changes |
|
6510 | 6523 | are merged into the requested changeset and the merged |
|
6511 | 6524 | result is left uncommitted. If the requested changeset is |
|
6512 | 6525 | not an ancestor or descendant (that is, it is on another |
|
6513 | 6526 | branch), the update is aborted and the uncommitted changes |
|
6514 | 6527 | are preserved. |
|
6515 | 6528 | |
|
6516 | 6529 | 2. With the -c/--check option, the update is aborted and the |
|
6517 | 6530 | uncommitted changes are preserved. |
|
6518 | 6531 | |
|
6519 | 6532 | 3. With the -C/--clean option, uncommitted changes are discarded and |
|
6520 | 6533 | the working directory is updated to the requested changeset. |
|
6521 | 6534 | |
|
6522 | 6535 | To cancel an uncommitted merge (and lose your changes), use |
|
6523 | 6536 | :hg:`update --clean .`. |
|
6524 | 6537 | |
|
6525 | 6538 | Use null as the changeset to remove the working directory (like |
|
6526 | 6539 | :hg:`clone -U`). |
|
6527 | 6540 | |
|
6528 | 6541 | If you want to revert just one file to an older revision, use |
|
6529 | 6542 | :hg:`revert [-r REV] NAME`. |
|
6530 | 6543 | |
|
6531 | 6544 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
6532 | 6545 | |
|
6533 | 6546 | Returns 0 on success, 1 if there are unresolved files. |
|
6534 | 6547 | """ |
|
6535 | 6548 | if rev and node: |
|
6536 | 6549 | raise util.Abort(_("please specify just one revision")) |
|
6537 | 6550 | |
|
6538 | 6551 | if rev is None or rev == '': |
|
6539 | 6552 | rev = node |
|
6540 | 6553 | |
|
6541 | 6554 | wlock = repo.wlock() |
|
6542 | 6555 | try: |
|
6543 | 6556 | cmdutil.clearunfinished(repo) |
|
6544 | 6557 | |
|
6545 | 6558 | if date: |
|
6546 | 6559 | if rev is not None: |
|
6547 | 6560 | raise util.Abort(_("you can't specify a revision and a date")) |
|
6548 | 6561 | rev = cmdutil.finddate(ui, repo, date) |
|
6549 | 6562 | |
|
6550 | 6563 | # with no argument, we also move the active bookmark, if any |
|
6551 | 6564 | rev, movemarkfrom = bookmarks.calculateupdate(ui, repo, rev) |
|
6552 | 6565 | |
|
6553 | 6566 | # if we defined a bookmark, we have to remember the original name |
|
6554 | 6567 | brev = rev |
|
6555 | 6568 | rev = scmutil.revsingle(repo, rev, rev).rev() |
|
6556 | 6569 | |
|
6557 | 6570 | if check and clean: |
|
6558 | 6571 | raise util.Abort(_("cannot specify both -c/--check and -C/--clean")) |
|
6559 | 6572 | |
|
6560 | 6573 | if check: |
|
6561 | 6574 | cmdutil.bailifchanged(repo, merge=False) |
|
6562 | 6575 | if rev is None: |
|
6563 | 6576 | rev = repo[repo[None].branch()].rev() |
|
6564 | 6577 | |
|
6565 | 6578 | repo.ui.setconfig('ui', 'forcemerge', tool, 'update') |
|
6566 | 6579 | |
|
6567 | 6580 | if clean: |
|
6568 | 6581 | ret = hg.clean(repo, rev) |
|
6569 | 6582 | else: |
|
6570 | 6583 | ret = hg.update(repo, rev) |
|
6571 | 6584 | |
|
6572 | 6585 | if not ret and movemarkfrom: |
|
6573 | 6586 | if bookmarks.update(repo, [movemarkfrom], repo['.'].node()): |
|
6574 | 6587 | ui.status(_("updating bookmark %s\n") % repo._activebookmark) |
|
6575 | 6588 | else: |
|
6576 | 6589 | # this can happen with a non-linear update |
|
6577 | 6590 | ui.status(_("(leaving bookmark %s)\n") % |
|
6578 | 6591 | repo._activebookmark) |
|
6579 | 6592 | bookmarks.deactivate(repo) |
|
6580 | 6593 | elif brev in repo._bookmarks: |
|
6581 | 6594 | bookmarks.activate(repo, brev) |
|
6582 | 6595 | ui.status(_("(activating bookmark %s)\n") % brev) |
|
6583 | 6596 | elif brev: |
|
6584 | 6597 | if repo._activebookmark: |
|
6585 | 6598 | ui.status(_("(leaving bookmark %s)\n") % |
|
6586 | 6599 | repo._activebookmark) |
|
6587 | 6600 | bookmarks.deactivate(repo) |
|
6588 | 6601 | finally: |
|
6589 | 6602 | wlock.release() |
|
6590 | 6603 | |
|
6591 | 6604 | return ret |
|
6592 | 6605 | |
|
6593 | 6606 | @command('verify', []) |
|
6594 | 6607 | def verify(ui, repo): |
|
6595 | 6608 | """verify the integrity of the repository |
|
6596 | 6609 | |
|
6597 | 6610 | Verify the integrity of the current repository. |
|
6598 | 6611 | |
|
6599 | 6612 | This will perform an extensive check of the repository's |
|
6600 | 6613 | integrity, validating the hashes and checksums of each entry in |
|
6601 | 6614 | the changelog, manifest, and tracked files, as well as the |
|
6602 | 6615 | integrity of their crosslinks and indices. |
|
6603 | 6616 | |
|
6604 | 6617 | Please see https://mercurial-scm.org/wiki/RepositoryCorruption |
|
6605 | 6618 | for more information about recovery from corruption of the |
|
6606 | 6619 | repository. |
|
6607 | 6620 | |
|
6608 | 6621 | Returns 0 on success, 1 if errors are encountered. |
|
6609 | 6622 | """ |
|
6610 | 6623 | return hg.verify(repo) |
|
6611 | 6624 | |
|
6612 | 6625 | @command('version', [], norepo=True) |
|
6613 | 6626 | def version_(ui): |
|
6614 | 6627 | """output version and copyright information""" |
|
6615 | 6628 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
6616 | 6629 | % util.version()) |
|
6617 | 6630 | ui.status(_( |
|
6618 | 6631 | "(see https://mercurial-scm.org for more information)\n" |
|
6619 | 6632 | "\nCopyright (C) 2005-2015 Matt Mackall and others\n" |
|
6620 | 6633 | "This is free software; see the source for copying conditions. " |
|
6621 | 6634 | "There is NO\nwarranty; " |
|
6622 | 6635 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
6623 | 6636 | )) |
|
6624 | 6637 | |
|
6625 | 6638 | ui.note(_("\nEnabled extensions:\n\n")) |
|
6626 | 6639 | if ui.verbose: |
|
6627 | 6640 | # format names and versions into columns |
|
6628 | 6641 | names = [] |
|
6629 | 6642 | vers = [] |
|
6630 | 6643 | for name, module in extensions.extensions(): |
|
6631 | 6644 | names.append(name) |
|
6632 | 6645 | vers.append(extensions.moduleversion(module)) |
|
6633 | 6646 | if names: |
|
6634 | 6647 | maxnamelen = max(len(n) for n in names) |
|
6635 | 6648 | for i, name in enumerate(names): |
|
6636 | 6649 | ui.write(" %-*s %s\n" % (maxnamelen, name, vers[i])) |
@@ -1,79 +1,107 b'' | |||
|
1 | 1 | bundle w/o type option |
|
2 | 2 | |
|
3 | 3 | $ hg init t1 |
|
4 | 4 | $ hg init t2 |
|
5 | 5 | $ cd t1 |
|
6 | 6 | $ echo blablablablabla > file.txt |
|
7 | 7 | $ hg ci -Ama |
|
8 | 8 | adding file.txt |
|
9 | 9 | $ hg log | grep summary |
|
10 | 10 | summary: a |
|
11 | 11 | $ hg bundle ../b1 ../t2 |
|
12 | 12 | searching for changes |
|
13 | 13 | 1 changesets found |
|
14 | 14 | |
|
15 | 15 | $ cd ../t2 |
|
16 | 16 | $ hg pull ../b1 |
|
17 | 17 | pulling from ../b1 |
|
18 | 18 | requesting all changes |
|
19 | 19 | adding changesets |
|
20 | 20 | adding manifests |
|
21 | 21 | adding file changes |
|
22 | 22 | added 1 changesets with 1 changes to 1 files |
|
23 | 23 | (run 'hg update' to get a working copy) |
|
24 | 24 | $ hg up |
|
25 | 25 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
26 | 26 | $ hg log | grep summary |
|
27 | 27 | summary: a |
|
28 | 28 | $ cd .. |
|
29 | 29 | |
|
30 | 30 | test bundle types |
|
31 | 31 | |
|
32 | $ for t in "None" "bzip2" "gzip"; do | |
|
32 | $ for t in "None" "bzip2" "gzip" "none-v2" "v2" "v1" "gzip-v1"; do | |
|
33 | 33 | > echo % test bundle type $t |
|
34 | 34 | > hg init t$t |
|
35 | 35 | > cd t1 |
|
36 | 36 | > hg bundle -t $t ../b$t ../t$t |
|
37 | 37 | > cut -b 1-6 ../b$t | head -n 1 |
|
38 | 38 | > cd ../t$t |
|
39 | 39 | > hg debugbundle ../b$t |
|
40 | 40 | > echo |
|
41 | 41 | > cd .. |
|
42 | 42 | > done |
|
43 | 43 | % test bundle type None |
|
44 | 44 | searching for changes |
|
45 | 45 | 1 changesets found |
|
46 | 46 | HG10UN |
|
47 | 47 | c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf |
|
48 | 48 | |
|
49 | 49 | % test bundle type bzip2 |
|
50 | 50 | searching for changes |
|
51 | 51 | 1 changesets found |
|
52 | 52 | HG10BZ |
|
53 | 53 | c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf |
|
54 | 54 | |
|
55 | 55 | % test bundle type gzip |
|
56 | 56 | searching for changes |
|
57 | 57 | 1 changesets found |
|
58 | 58 | HG10GZ |
|
59 | 59 | c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf |
|
60 | 60 | |
|
61 | % test bundle type none-v2 | |
|
62 | searching for changes | |
|
63 | 1 changesets found | |
|
64 | HG20\x00\x00 (esc) | |
|
65 | Stream params: {} | |
|
66 | changegroup -- "{'version': '01'}" | |
|
67 | c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf | |
|
68 | ||
|
69 | % test bundle type v2 | |
|
70 | searching for changes | |
|
71 | 1 changesets found | |
|
72 | HG20\x00\x00 (esc) | |
|
73 | Stream params: {'Compression': 'BZ'} | |
|
74 | changegroup -- "{'version': '01'}" | |
|
75 | c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf | |
|
76 | ||
|
77 | % test bundle type v1 | |
|
78 | searching for changes | |
|
79 | 1 changesets found | |
|
80 | HG10BZ | |
|
81 | c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf | |
|
82 | ||
|
83 | % test bundle type gzip-v1 | |
|
84 | searching for changes | |
|
85 | 1 changesets found | |
|
86 | HG10GZ | |
|
87 | c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf | |
|
88 | ||
|
61 | 89 | |
|
62 | 90 | test garbage file |
|
63 | 91 | |
|
64 | 92 | $ echo garbage > bgarbage |
|
65 | 93 | $ hg init tgarbage |
|
66 | 94 | $ cd tgarbage |
|
67 | 95 | $ hg pull ../bgarbage |
|
68 | 96 | pulling from ../bgarbage |
|
69 | 97 | abort: ../bgarbage: not a Mercurial bundle |
|
70 | 98 | [255] |
|
71 | 99 | $ cd .. |
|
72 | 100 | |
|
73 | 101 | test invalid bundle type |
|
74 | 102 | |
|
75 | 103 | $ cd t1 |
|
76 | 104 | $ hg bundle -a -t garbage ../bgarbage |
|
77 | 105 | abort: unknown bundle type specified with --type |
|
78 | 106 | [255] |
|
79 | 107 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now