Mercurial > public > mercurial-scm > hg-stable
comparison 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 |
comparison
equal
deleted
inserted
replaced
17459:f4d15f3b96c0 | 17460:a306837f8c87 |
---|---|
545 if switch_parent: | 545 if switch_parent: |
546 parents.reverse() | 546 parents.reverse() |
547 prev = (parents and parents[0]) or nullid | 547 prev = (parents and parents[0]) or nullid |
548 | 548 |
549 shouldclose = False | 549 shouldclose = False |
550 if not fp: | 550 if not fp and len(template) > 0: |
551 desc_lines = ctx.description().rstrip().split('\n') | 551 desc_lines = ctx.description().rstrip().split('\n') |
552 desc = desc_lines[0] #Commit always has a first line. | 552 desc = desc_lines[0] #Commit always has a first line. |
553 fp = makefileobj(repo, template, node, desc=desc, total=total, | 553 fp = makefileobj(repo, template, node, desc=desc, total=total, |
554 seqno=seqno, revwidth=revwidth, mode='ab') | 554 seqno=seqno, revwidth=revwidth, mode='ab') |
555 if fp != template: | 555 if fp != template: |
556 shouldclose = True | 556 shouldclose = True |
557 if fp != sys.stdout and util.safehasattr(fp, 'name'): | 557 if fp and fp != sys.stdout and util.safehasattr(fp, 'name'): |
558 repo.ui.note("%s\n" % fp.name) | 558 repo.ui.note("%s\n" % fp.name) |
559 | 559 |
560 fp.write("# HG changeset patch\n") | 560 if not fp: |
561 fp.write("# User %s\n" % ctx.user()) | 561 write = repo.ui.write |
562 fp.write("# Date %d %d\n" % ctx.date()) | 562 else: |
563 def write(s, **kw): | |
564 fp.write(s) | |
565 | |
566 | |
567 write("# HG changeset patch\n") | |
568 write("# User %s\n" % ctx.user()) | |
569 write("# Date %d %d\n" % ctx.date()) | |
563 if branch and branch != 'default': | 570 if branch and branch != 'default': |
564 fp.write("# Branch %s\n" % branch) | 571 write("# Branch %s\n" % branch) |
565 fp.write("# Node ID %s\n" % hex(node)) | 572 write("# Node ID %s\n" % hex(node)) |
566 fp.write("# Parent %s\n" % hex(prev)) | 573 write("# Parent %s\n" % hex(prev)) |
567 if len(parents) > 1: | 574 if len(parents) > 1: |
568 fp.write("# Parent %s\n" % hex(parents[1])) | 575 write("# Parent %s\n" % hex(parents[1])) |
569 fp.write(ctx.description().rstrip()) | 576 write(ctx.description().rstrip()) |
570 fp.write("\n\n") | 577 write("\n\n") |
571 | 578 |
572 for chunk in patch.diff(repo, prev, node, opts=opts): | 579 for chunk, label in patch.diffui(repo, prev, node, opts=opts): |
573 fp.write(chunk) | 580 write(chunk, label=label) |
574 | 581 |
575 if shouldclose: | 582 if shouldclose: |
576 fp.close() | 583 fp.close() |
577 | 584 |
578 for seqno, rev in enumerate(revs): | 585 for seqno, rev in enumerate(revs): |