Mercurial > hg-stable
diff mercurial/cmdutil.py @ 17460:a306837f8c87
color: enabled color support for export command (issue1507)
The export command didn't output the diffs in color, even when color support
was enabled. This patch fixes that by making the export command use the default
ui.write method, instead of directly manipulating the ui.fout file object.
Also added a test case to verify color output to test-export.t.
author | Ankur Dahiya <ankurd@fb.com> |
---|---|
date | Mon, 27 Aug 2012 09:37:49 -0700 |
parents | e7cfe3587ea4 |
children | 8fea378242e3 |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Thu Sep 06 22:51:32 2012 +0200 +++ b/mercurial/cmdutil.py Mon Aug 27 09:37:49 2012 -0700 @@ -547,30 +547,37 @@ prev = (parents and parents[0]) or nullid shouldclose = False - if not fp: + if not fp and len(template) > 0: desc_lines = ctx.description().rstrip().split('\n') desc = desc_lines[0] #Commit always has a first line. fp = makefileobj(repo, template, node, desc=desc, total=total, seqno=seqno, revwidth=revwidth, mode='ab') if fp != template: shouldclose = True - if fp != sys.stdout and util.safehasattr(fp, 'name'): + if fp and fp != sys.stdout and util.safehasattr(fp, 'name'): repo.ui.note("%s\n" % fp.name) - fp.write("# HG changeset patch\n") - fp.write("# User %s\n" % ctx.user()) - fp.write("# Date %d %d\n" % ctx.date()) + if not fp: + write = repo.ui.write + else: + def write(s, **kw): + fp.write(s) + + + write("# HG changeset patch\n") + write("# User %s\n" % ctx.user()) + write("# Date %d %d\n" % ctx.date()) if branch and branch != 'default': - fp.write("# Branch %s\n" % branch) - fp.write("# Node ID %s\n" % hex(node)) - fp.write("# Parent %s\n" % hex(prev)) + write("# Branch %s\n" % branch) + write("# Node ID %s\n" % hex(node)) + write("# Parent %s\n" % hex(prev)) if len(parents) > 1: - fp.write("# Parent %s\n" % hex(parents[1])) - fp.write(ctx.description().rstrip()) - fp.write("\n\n") + write("# Parent %s\n" % hex(parents[1])) + write(ctx.description().rstrip()) + write("\n\n") - for chunk in patch.diff(repo, prev, node, opts=opts): - fp.write(chunk) + for chunk, label in patch.diffui(repo, prev, node, opts=opts): + write(chunk, label=label) if shouldclose: fp.close()