comparison mercurial/commands.py @ 39369:34ba47117164

formatter: rename {abspath}/{file} to {path}, and drop relative {path} (BC) Note that {path} in status is either relative-to-cwd or repository-absolute depending on the command argument and config knob, which can't be reproduced by using the {path|relpath} filter. The default template is updated to always use a relative path. .. bc:: ``{abspath}`` and ``{file}`` in generic templates are renamed to ``{path}``. Any ``{path}`` is a repository-absolute path. Use ``{path|relpath}`` to convert it to a filesystem path.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 05 Aug 2018 16:44:16 +0900
parents 3fec8aa9b454
children 46f3ff64bea7
comparison
equal deleted inserted replaced
39368:5b1d406b39f1 39369:34ba47117164
335 335
336 opmap = [('user', ' ', lambda x: x.fctx.user(), ui.shortuser), 336 opmap = [('user', ' ', lambda x: x.fctx.user(), ui.shortuser),
337 ('rev', ' ', lambda x: x.fctx.rev(), formatrev), 337 ('rev', ' ', lambda x: x.fctx.rev(), formatrev),
338 ('node', ' ', lambda x: hexfn(x.fctx.node()), formathex), 338 ('node', ' ', lambda x: hexfn(x.fctx.node()), formathex),
339 ('date', ' ', lambda x: x.fctx.date(), util.cachefunc(datefunc)), 339 ('date', ' ', lambda x: x.fctx.date(), util.cachefunc(datefunc)),
340 ('file', ' ', lambda x: x.fctx.path(), pycompat.bytestr), 340 ('path', ' ', lambda x: x.fctx.path(), pycompat.bytestr),
341 ('line_number', ':', lambda x: x.lineno, pycompat.bytestr), 341 ('line_number', ':', lambda x: x.lineno, pycompat.bytestr),
342 ] 342 ]
343 opnamemap = {'rev': 'number', 'node': 'changeset'} 343 opnamemap = {'rev': 'number', 'node': 'changeset', 'path': 'file'}
344 344
345 if (not opts.get('user') and not opts.get('changeset') 345 if (not opts.get('user') and not opts.get('changeset')
346 and not opts.get('date') and not opts.get('file')): 346 and not opts.get('date') and not opts.get('file')):
347 opts['number'] = True 347 opts['number'] = True
348 348
378 skiprevs = scmutil.revrange(repo, skiprevs) 378 skiprevs = scmutil.revrange(repo, skiprevs)
379 379
380 for abs in ctx.walk(m): 380 for abs in ctx.walk(m):
381 fctx = ctx[abs] 381 fctx = ctx[abs]
382 rootfm.startitem() 382 rootfm.startitem()
383 rootfm.data(abspath=abs, path=m.rel(abs)) 383 rootfm.data(path=abs)
384 if not opts.get('text') and fctx.isbinary(): 384 if not opts.get('text') and fctx.isbinary():
385 rootfm.plain(_("%s: binary file\n") 385 rootfm.plain(_("%s: binary file\n")
386 % ((pats and m.rel(abs)) or abs)) 386 % ((pats and m.rel(abs)) or abs))
387 continue 387 continue
388 388
2658 try: 2658 try:
2659 return stringutil.binary(flog.read(ctx.filenode(fn))) 2659 return stringutil.binary(flog.read(ctx.filenode(fn)))
2660 except error.WdirUnsupported: 2660 except error.WdirUnsupported:
2661 return ctx[fn].isbinary() 2661 return ctx[fn].isbinary()
2662 2662
2663 fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'} 2663 fieldnamemap = {'filename': 'path', 'linenumber': 'line_number'}
2664 if diff: 2664 if diff:
2665 iter = difflinestates(pstates, states) 2665 iter = difflinestates(pstates, states)
2666 else: 2666 else:
2667 iter = [('', l) for l in states] 2667 iter = [('', l) for l in states]
2668 for change, l in iter: 2668 for change, l in iter:
5185 if state in show: 5185 if state in show:
5186 label = 'status.' + state 5186 label = 'status.' + state
5187 for f in files: 5187 for f in files:
5188 fm.startitem() 5188 fm.startitem()
5189 fm.context(ctx=ctx2) 5189 fm.context(ctx=ctx2)
5190 fm.data(path=f)
5190 fm.condwrite(showchar, 'status', '%s ', char, label=label) 5191 fm.condwrite(showchar, 'status', '%s ', char, label=label)
5191 fm.write('path', fmt, repo.pathto(f, cwd), label=label) 5192 fm.plain(fmt % repo.pathto(f, cwd), label=label)
5192 if f in copy: 5193 if f in copy:
5193 fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd), 5194 fm.data(copy=copy[f])
5195 fm.plain((' %s' + end) % repo.pathto(copy[f], cwd),
5194 label='status.copied') 5196 label='status.copied')
5195 5197
5196 if ((ui.verbose or ui.configbool('commands', 'status.verbose')) 5198 if ((ui.verbose or ui.configbool('commands', 'status.verbose'))
5197 and not ui.plain()): 5199 and not ui.plain()):
5198 cmdutil.morestatus(repo, fm) 5200 cmdutil.morestatus(repo, fm)