comparison mercurial/cmdutil.py @ 36205:976e1cfb2f64

cmdutil: pass ctx to makefileobj() in place of repo/node pair (API)
author Yuya Nishihara <yuya@tcha.org>
date Thu, 02 Apr 2015 23:28:16 +0900
parents 33ed8b511185
children 9ddc884e9a32
comparison
equal deleted inserted replaced
36204:33ed8b511185 36205:976e1cfb2f64
954 return self 954 return self
955 955
956 def __exit__(self, exc_type, exc_value, exc_tb): 956 def __exit__(self, exc_type, exc_value, exc_tb):
957 pass 957 pass
958 958
959 def makefileobj(repo, pat, node, desc=None, total=None, 959 def makefileobj(ctx, pat, desc=None, total=None,
960 seqno=None, revwidth=None, mode='wb', modemap=None, 960 seqno=None, revwidth=None, mode='wb', modemap=None,
961 pathname=None): 961 pathname=None):
962 962
963 writable = mode not in ('r', 'rb') 963 writable = mode not in ('r', 'rb')
964 964
965 if isstdiofilename(pat): 965 if isstdiofilename(pat):
966 repo = ctx.repo()
966 if writable: 967 if writable:
967 fp = repo.ui.fout 968 fp = repo.ui.fout
968 else: 969 else:
969 fp = repo.ui.fin 970 fp = repo.ui.fin
970 return _unclosablefile(fp) 971 return _unclosablefile(fp)
971 ctx = repo[node]
972 fn = makefilename(ctx, pat, desc, total, seqno, revwidth, pathname) 972 fn = makefilename(ctx, pat, desc, total, seqno, revwidth, pathname)
973 if modemap is not None: 973 if modemap is not None:
974 mode = modemap.get(fn, mode) 974 mode = modemap.get(fn, mode)
975 if mode == 'wb': 975 if mode == 'wb':
976 modemap[fn] = 'ab' 976 modemap[fn] = 'ab'
1544 ctx = repo[rev] 1544 ctx = repo[rev]
1545 fo = None 1545 fo = None
1546 if not fp and fntemplate: 1546 if not fp and fntemplate:
1547 desc_lines = ctx.description().rstrip().split('\n') 1547 desc_lines = ctx.description().rstrip().split('\n')
1548 desc = desc_lines[0] #Commit always has a first line. 1548 desc = desc_lines[0] #Commit always has a first line.
1549 fo = makefileobj(repo, fntemplate, ctx.node(), desc=desc, 1549 fo = makefileobj(ctx, fntemplate, desc=desc,
1550 total=total, seqno=seqno, revwidth=revwidth, 1550 total=total, seqno=seqno, revwidth=revwidth,
1551 mode='wb', modemap=filemode) 1551 mode='wb', modemap=filemode)
1552 dest = fo.name 1552 dest = fo.name
1553 def write(s, **kw): 1553 def write(s, **kw):
1554 fo.write(s) 1554 fo.write(s)