Mercurial > hg-stable
changeset 32472:69c864149d69
cmdutil: avoid redefining write() function in export if possible
Doing less work inside the loop just feels better to me.
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 22 May 2017 15:05:18 -0400 |
parents | 7feaf5550a9e |
children | bb5dc19484b8 |
files | mercurial/cmdutil.py |
diffstat | 1 files changed, 10 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Mon May 22 13:34:03 2017 -0400 +++ b/mercurial/cmdutil.py Mon May 22 15:05:18 2017 -0400 @@ -1205,11 +1205,19 @@ revwidth = max(len(str(rev)) for rev in revs) filemode = {} + write = None + dest = '<unnamed>' + if fp: + dest = getattr(fp, 'name', dest) + def write(s, **kw): + fp.write(s) + elif not fntemplate: + write = repo.ui.write + for seqno, rev in enumerate(revs, 1): ctx = repo[rev] fo = None - dest = '<unnamed>' - if not fp and len(fntemplate) > 0: + if not fp and fntemplate: desc_lines = ctx.description().rstrip().split('\n') desc = desc_lines[0] #Commit always has a first line. fo = makefileobj(repo, fntemplate, ctx.node(), desc=desc, @@ -1218,12 +1226,6 @@ dest = fo.name def write(s, **kw): fo.write(s) - elif fp: - dest = getattr(fp, 'name', dest) - def write(s, **kw): - fp.write(s) - else: - write = repo.ui.write if not dest.startswith('<'): repo.ui.note("%s\n" % dest) _exportsingle(