##// END OF EJS Templates
annotate: add option to annotate working-directory files...
Yuya Nishihara -
r24421:77881cad default
parent child Browse files
Show More
@@ -266,6 +266,9 b' def annotate(ui, repo, *pats, **opts):'
266 anyway, although the results will probably be neither useful
266 anyway, although the results will probably be neither useful
267 nor desirable.
267 nor desirable.
268
268
269 By default, annotate files in the parent of the working directory.
270 Use -r "wdir()" to annotate the working directory files.
271
269 Returns 0 on success.
272 Returns 0 on success.
270 """
273 """
271 if not pats:
274 if not pats:
@@ -276,16 +279,44 b' def annotate(ui, repo, *pats, **opts):'
276 # to mimic the behavior of Mercurial before version 1.5
279 # to mimic the behavior of Mercurial before version 1.5
277 opts['file'] = True
280 opts['file'] = True
278
281
282 ctx = scmutil.revsingle(repo, opts.get('rev'))
283
279 fm = ui.formatter('annotate', opts)
284 fm = ui.formatter('annotate', opts)
280 if ui.quiet:
285 if ui.quiet:
281 datefunc = util.shortdate
286 datefunc = util.shortdate
282 else:
287 else:
283 datefunc = util.datestr
288 datefunc = util.datestr
284 hexfn = fm.hexfunc
289 if ctx.rev() is None:
290 def hexfn(node):
291 if node is None:
292 return None
293 else:
294 return fm.hexfunc(node)
295 if opts.get('changeset'):
296 # omit "+" suffix which is appended to node hex
297 def formatrev(rev):
298 if rev is None:
299 return '%d' % ctx.p1().rev()
300 else:
301 return '%d' % rev
302 else:
303 def formatrev(rev):
304 if rev is None:
305 return '%d+' % ctx.p1().rev()
306 else:
307 return '%d ' % rev
308 def formathex(hex):
309 if hex is None:
310 return '%s+' % fm.hexfunc(ctx.p1().node())
311 else:
312 return '%s ' % hex
313 else:
314 hexfn = fm.hexfunc
315 formatrev = formathex = str
285
316
286 opmap = [('user', ' ', lambda x: x[0].user(), ui.shortuser),
317 opmap = [('user', ' ', lambda x: x[0].user(), ui.shortuser),
287 ('number', ' ', lambda x: x[0].rev(), str),
318 ('number', ' ', lambda x: x[0].rev(), formatrev),
288 ('changeset', ' ', lambda x: hexfn(x[0].node()), str),
319 ('changeset', ' ', lambda x: hexfn(x[0].node()), formathex),
289 ('date', ' ', lambda x: x[0].date(), util.cachefunc(datefunc)),
320 ('date', ' ', lambda x: x[0].date(), util.cachefunc(datefunc)),
290 ('file', ' ', lambda x: x[0].path(), str),
321 ('file', ' ', lambda x: x[0].path(), str),
291 ('line_number', ':', lambda x: x[1], str),
322 ('line_number', ':', lambda x: x[1], str),
@@ -315,7 +346,6 b' def annotate(ui, repo, *pats, **opts):'
315 def bad(x, y):
346 def bad(x, y):
316 raise util.Abort("%s: %s" % (x, y))
347 raise util.Abort("%s: %s" % (x, y))
317
348
318 ctx = scmutil.revsingle(repo, opts.get('rev'))
319 m = scmutil.match(ctx, pats, opts)
349 m = scmutil.match(ctx, pats, opts)
320 m.bad = bad
350 m.bad = bad
321 follow = not opts.get('no_follow')
351 follow = not opts.get('no_follow')
@@ -398,6 +398,76 b' and its ancestor by overriding "repo._fi'
398 20: 4 baz:4
398 20: 4 baz:4
399 16: 5
399 16: 5
400
400
401 annotate clean file
402
403 $ hg annotate -ncr "wdir()" foo
404 11 472b18db256d : foo
405
406 annotate modified file
407
408 $ echo foofoo >> foo
409 $ hg annotate -r "wdir()" foo
410 11 : foo
411 20+: foofoo
412
413 $ hg annotate -cr "wdir()" foo
414 472b18db256d : foo
415 b6bedd5477e7+: foofoo
416
417 $ hg annotate -ncr "wdir()" foo
418 11 472b18db256d : foo
419 20 b6bedd5477e7+: foofoo
420
421 $ hg annotate --debug -ncr "wdir()" foo
422 11 472b18db256d1e8282064eab4bfdaf48cbfe83cd : foo
423 20 b6bedd5477e797f25e568a6402d4697f3f895a72+: foofoo
424
425 $ hg annotate -udr "wdir()" foo
426 test Thu Jan 01 00:00:00 1970 +0000: foo
427 test [A-Za-z0-9:+ ]+: foofoo (re)
428
429 $ hg annotate -ncr "wdir()" -Tjson foo
430 [
431 {
432 "line": "foo\n",
433 "node": "472b18db256d1e8282064eab4bfdaf48cbfe83cd",
434 "rev": 11
435 },
436 {
437 "line": "foofoo\n",
438 "node": null,
439 "rev": null
440 }
441 ]
442
443 annotate added file
444
445 $ echo bar > bar
446 $ hg add bar
447 $ hg annotate -ncr "wdir()" bar
448 20 b6bedd5477e7+: bar
449
450 annotate renamed file
451
452 $ hg rename foo renamefoo2
453 $ hg annotate -ncr "wdir()" renamefoo2
454 11 472b18db256d : foo
455 20 b6bedd5477e7+: foofoo
456
457 annotate missing file
458
459 $ rm baz
460 $ hg annotate -ncr "wdir()" baz
461 abort: No such file or directory: $TESTTMP/repo/baz
462 [255]
463
464 annotate removed file
465
466 $ hg rm baz
467 $ hg annotate -ncr "wdir()" baz
468 abort: No such file or directory: $TESTTMP/repo/baz
469 [255]
470
401 Test annotate with whitespace options
471 Test annotate with whitespace options
402
472
403 $ cd ..
473 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now