remotenames: refactor outputname to outputbranches

Now that we have outputbookmarks that sorts differently for bookmarks,
rename outputname and make it simpler and less generic
This commit is contained in:
Ryan McElroy 2015-01-28 15:26:42 -08:00
parent 13e6ed237a
commit 4d32a9e3bd

View File

@ -133,20 +133,19 @@ def extsetup(ui):
entry[1].append(('a', 'all', None, 'show both remote and local branches'))
entry[1].append(('', 'remote', None, 'show only remote branches'))
def outputname(cmd, orig, ui, repo, *args, **opts):
def outputbranches(orig, ui, repo, *args, **opts):
if not opts.get('remote'):
orig(ui, repo, *args, **opts)
# exit early if namespace doesn't even exist
namespace = 'remote' + cmd
if namespace not in repo.names:
return
ns = repo.names['remote' + cmd]
label = 'log.' + ns.colorname
fm = ui.formatter(cmd, opts)
if opts.get('all') or opts.get('remote'):
# exit early if namespace doesn't even exist
namespace = 'remotebranches'
if namespace not in repo.names:
return
ns = repo.names[namespace]
label = 'log.' + ns.colorname
fm = ui.formatter('branches', opts)
# create a sorted by descending rev list
revs = set()
@ -160,12 +159,6 @@ def outputname(cmd, orig, ui, repo, *args, **opts):
fm.startitem()
padsize = max(31 - len(str(r)) - encoding.colwidth(name), 0)
# bookmarks have a slightly different padding
if cmd == 'bookmarks':
if not ui.quiet:
fm.plain(' ')
padsize = max(25 - encoding.colwidth(name), 0)
fm.write(ns.colorname, '%s', name, label=label)
fmt = ' ' * padsize + ' %d:%s'
fm.condwrite(not ui.quiet, 'rev node', fmt, r,
@ -212,7 +205,7 @@ def bookmarks(orig, ui, repo, *args, **opts):
outputbookmarks(orig, ui, repo, *args, **opts)
def branches(orig, ui, repo, *args, **opts):
outputname('branches', orig, ui, repo, *args, **opts)
outputbranches(orig, ui, repo, *args, **opts)
def activepath(ui, remote):
realpath = ''