Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/cmdutil.py @ 36245:cc46e68f050f
cmdutil: build "%m" (desc|firstline) in makefilename()
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 06 Jan 2018 17:44:57 +0900 |
parents | 9ddc884e9a32 |
children | 428de1a59f2d |
comparison
equal
deleted
inserted
replaced
36244:9ddc884e9a32 | 36245:cc46e68f050f |
---|---|
889 elif editform: | 889 elif editform: |
890 return lambda r, c, s: commiteditor(r, c, s, editform=editform) | 890 return lambda r, c, s: commiteditor(r, c, s, editform=editform) |
891 else: | 891 else: |
892 return commiteditor | 892 return commiteditor |
893 | 893 |
894 def makefilename(ctx, pat, desc=None, | 894 def makefilename(ctx, pat, |
895 total=None, seqno=None, revwidth=None, pathname=None): | 895 total=None, seqno=None, revwidth=None, pathname=None): |
896 expander = { | 896 expander = { |
897 'H': lambda: ctx.hex(), | 897 'H': lambda: ctx.hex(), |
898 'R': lambda: '%d' % ctx.rev(), | 898 'R': lambda: '%d' % ctx.rev(), |
899 'h': lambda: short(ctx.node()), | 899 'h': lambda: short(ctx.node()), |
900 'm': lambda: re.sub('[^\w]', '_', desc or ''), | 900 'm': lambda: re.sub('[^\w]', '_', |
901 ctx.description().rstrip().splitlines()[0]), | |
901 'r': lambda: ('%d' % ctx.rev()).zfill(revwidth or 0), | 902 'r': lambda: ('%d' % ctx.rev()).zfill(revwidth or 0), |
902 '%': lambda: '%', | 903 '%': lambda: '%', |
903 'b': lambda: os.path.basename(ctx.repo().root), | 904 'b': lambda: os.path.basename(ctx.repo().root), |
904 } | 905 } |
905 | 906 |
952 return self | 953 return self |
953 | 954 |
954 def __exit__(self, exc_type, exc_value, exc_tb): | 955 def __exit__(self, exc_type, exc_value, exc_tb): |
955 pass | 956 pass |
956 | 957 |
957 def makefileobj(ctx, pat, desc=None, total=None, | 958 def makefileobj(ctx, pat, total=None, |
958 seqno=None, revwidth=None, mode='wb', modemap=None, | 959 seqno=None, revwidth=None, mode='wb', modemap=None, |
959 pathname=None): | 960 pathname=None): |
960 | 961 |
961 writable = mode not in ('r', 'rb') | 962 writable = mode not in ('r', 'rb') |
962 | 963 |
965 if writable: | 966 if writable: |
966 fp = repo.ui.fout | 967 fp = repo.ui.fout |
967 else: | 968 else: |
968 fp = repo.ui.fin | 969 fp = repo.ui.fin |
969 return _unclosablefile(fp) | 970 return _unclosablefile(fp) |
970 fn = makefilename(ctx, pat, desc, total, seqno, revwidth, pathname) | 971 fn = makefilename(ctx, pat, total, seqno, revwidth, pathname) |
971 if modemap is not None: | 972 if modemap is not None: |
972 mode = modemap.get(fn, mode) | 973 mode = modemap.get(fn, mode) |
973 if mode == 'wb': | 974 if mode == 'wb': |
974 modemap[fn] = 'ab' | 975 modemap[fn] = 'ab' |
975 return open(fn, mode) | 976 return open(fn, mode) |
1540 | 1541 |
1541 for seqno, rev in enumerate(revs, 1): | 1542 for seqno, rev in enumerate(revs, 1): |
1542 ctx = repo[rev] | 1543 ctx = repo[rev] |
1543 fo = None | 1544 fo = None |
1544 if not fp and fntemplate: | 1545 if not fp and fntemplate: |
1545 desc_lines = ctx.description().rstrip().split('\n') | 1546 fo = makefileobj(ctx, fntemplate, |
1546 desc = desc_lines[0] #Commit always has a first line. | |
1547 fo = makefileobj(ctx, fntemplate, desc=desc, | |
1548 total=total, seqno=seqno, revwidth=revwidth, | 1547 total=total, seqno=seqno, revwidth=revwidth, |
1549 mode='wb', modemap=filemode) | 1548 mode='wb', modemap=filemode) |
1550 dest = fo.name | 1549 dest = fo.name |
1551 def write(s, **kw): | 1550 def write(s, **kw): |
1552 fo.write(s) | 1551 fo.write(s) |