mercurial/commands.py
changeset 14358 bf93e78f2638
parent 14331 3b9a896af09c
child 14361 ea7081645987
equal deleted inserted replaced
14357:cb4ff8ef466b 14358:bf93e78f2638
   236     getdate = util.cachefunc(lambda x: datefunc(x[0].date()))
   236     getdate = util.cachefunc(lambda x: datefunc(x[0].date()))
   237 
   237 
   238     if not pats:
   238     if not pats:
   239         raise util.Abort(_('at least one filename or pattern is required'))
   239         raise util.Abort(_('at least one filename or pattern is required'))
   240 
   240 
   241     opmap = [('user', lambda x: ui.shortuser(x[0].user())),
   241     opmap = [('user', ' ', lambda x: ui.shortuser(x[0].user())),
   242              ('number', lambda x: str(x[0].rev())),
   242              ('number', ' ', lambda x: str(x[0].rev())),
   243              ('changeset', lambda x: short(x[0].node())),
   243              ('changeset', ' ', lambda x: short(x[0].node())),
   244              ('date', getdate),
   244              ('date', ' ', getdate),
   245              ('file', lambda x: x[0].path()),
   245              ('file', ' ', lambda x: x[0].path()),
       
   246              ('line_number', ':', lambda x: str(x[1])),
   246             ]
   247             ]
   247 
   248 
   248     if (not opts.get('user') and not opts.get('changeset')
   249     if (not opts.get('user') and not opts.get('changeset')
   249         and not opts.get('date') and not opts.get('file')):
   250         and not opts.get('date') and not opts.get('file')):
   250         opts['number'] = True
   251         opts['number'] = True
   251 
   252 
   252     linenumber = opts.get('line_number') is not None
   253     linenumber = opts.get('line_number') is not None
   253     if linenumber and (not opts.get('changeset')) and (not opts.get('number')):
   254     if linenumber and (not opts.get('changeset')) and (not opts.get('number')):
   254         raise util.Abort(_('at least one of -n/-c is required for -l'))
   255         raise util.Abort(_('at least one of -n/-c is required for -l'))
   255 
   256 
   256     funcmap = [func for op, func in opmap if opts.get(op)]
   257     funcmap = [(func, sep) for op, sep, func in opmap if opts.get(op)]
   257     if linenumber:
   258     funcmap[0] = (funcmap[0][0], '') # no separator in front of first column
   258         lastfunc = funcmap[-1]
       
   259         funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1])
       
   260 
   259 
   261     def bad(x, y):
   260     def bad(x, y):
   262         raise util.Abort("%s: %s" % (x, y))
   261         raise util.Abort("%s: %s" % (x, y))
   263 
   262 
   264     ctx = scmutil.revsingle(repo, opts.get('rev'))
   263     ctx = scmutil.revsingle(repo, opts.get('rev'))
   272             continue
   271             continue
   273 
   272 
   274         lines = fctx.annotate(follow=follow, linenumber=linenumber)
   273         lines = fctx.annotate(follow=follow, linenumber=linenumber)
   275         pieces = []
   274         pieces = []
   276 
   275 
   277         for f in funcmap:
   276         for f, sep in funcmap:
   278             l = [f(n) for n, dummy in lines]
   277             l = [f(n) for n, dummy in lines]
   279             if l:
   278             if l:
   280                 sized = [(x, encoding.colwidth(x)) for x in l]
   279                 sized = [(x, encoding.colwidth(x)) for x in l]
   281                 ml = max([w for x, w in sized])
   280                 ml = max([w for x, w in sized])
   282                 pieces.append(["%s%s" % (' ' * (ml - w), x) for x, w in sized])
   281                 pieces.append(["%s%s%s" % (sep, ' ' * (ml - w), x)
       
   282                                for x, w in sized])
   283 
   283 
   284         if pieces:
   284         if pieces:
   285             for p, l in zip(zip(*pieces), lines):
   285             for p, l in zip(zip(*pieces), lines):
   286                 ui.write("%s: %s" % (" ".join(p), l[1]))
   286                 ui.write("%s: %s" % ("".join(p), l[1]))
   287 
   287 
   288 @command('archive',
   288 @command('archive',
   289     [('', 'no-decode', None, _('do not pass files through decoders')),
   289     [('', 'no-decode', None, _('do not pass files through decoders')),
   290     ('p', 'prefix', '', _('directory prefix for files in archive'),
   290     ('p', 'prefix', '', _('directory prefix for files in archive'),
   291      _('PREFIX')),
   291      _('PREFIX')),