Mercurial > hg-stable
changeset 739:36edb39e8e8c
Split make_file back out into make_filename and make_file.
It turns out that make_filename is useful by itself.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Wed, 20 Jul 2005 04:08:11 -0800 |
parents | 32a97c9d8e98 |
children | d2422f10c136 |
files | mercurial/commands.py |
diffstat | 1 files changed, 16 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Wed Jul 20 03:55:16 2005 -0800 +++ b/mercurial/commands.py Wed Jul 20 04:08:11 2005 -0800 @@ -116,15 +116,8 @@ else: yield spec -def make_file(repo, r, pat, node=None, - total=None, seqno=None, revwidth=None, mode='wb'): - if not pat or pat == '-': - if 'w' in mode: return sys.stdout - else: return sys.stdin - if hasattr(pat, 'write') and 'w' in mode: - return pat - if hasattr(pat, 'read') and 'r' in mode: - return pat +def make_filename(repo, r, pat, node=None, + total=None, seqno=None, revwidth=None): node_expander = { 'H': lambda: hg.hex(node), 'R': lambda: str(r.rev(node)), @@ -158,11 +151,23 @@ c = expander[c]() newname.append(c) i += 1 - return open(''.join(newname), mode) + return ''.join(newname) except KeyError, inst: raise Abort("invalid format spec '%%%s' in output file name", inst.args[0]) +def make_file(repo, r, pat, node=None, + total=None, seqno=None, revwidth=None, mode='wb'): + if not pat or pat == '-': + if 'w' in mode: return sys.stdout + else: return sys.stdin + if hasattr(pat, 'write') and 'w' in mode: + return pat + if hasattr(pat, 'read') and 'r' in mode: + return pat + return open(make_filename(repo, r, pat, node, total, seqno, revwidth), + mode) + def dodiff(fp, ui, repo, files=None, node1=None, node2=None): def date(c): return time.asctime(time.gmtime(float(c[2].split(' ')[0]))) @@ -590,6 +595,7 @@ fp.write("\n\n") dodiff(fp, ui, repo, None, prev, node) + if fp != sys.stdout: fp.close() def export(ui, repo, *changesets, **opts): """dump the header and diffs for one or more changesets"""