mercurial/commands.py
changeset 24421 77881cade20e
parent 24413 a8595176dd64
child 24429 69bd0ec2f9be
equal deleted inserted replaced
24420:065b886f61c6 24421:77881cade20e
   264     Without the -a/--text option, annotate will avoid processing files
   264     Without the -a/--text option, annotate will avoid processing files
   265     it detects as binary. With -a, annotate will annotate the file
   265     it detects as binary. With -a, annotate will annotate the file
   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:
   272         raise util.Abort(_('at least one filename or pattern is required'))
   275         raise util.Abort(_('at least one filename or pattern is required'))
   273 
   276 
   274     if opts.get('follow'):
   277     if opts.get('follow'):
   275         # --follow is deprecated and now just an alias for -f/--file
   278         # --follow is deprecated and now just an alias for -f/--file
   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
       
   281 
       
   282     ctx = scmutil.revsingle(repo, opts.get('rev'))
   278 
   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),
   292             ]
   323             ]
   293     fieldnamemap = {'number': 'rev', 'changeset': 'node'}
   324     fieldnamemap = {'number': 'rev', 'changeset': 'node'}
   313                       if opts.get(op))
   344                       if opts.get(op))
   314 
   345 
   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')
   322     diffopts = patch.difffeatureopts(ui, opts, section='annotate',
   352     diffopts = patch.difffeatureopts(ui, opts, section='annotate',
   323                                      whitespace=True)
   353                                      whitespace=True)