comparison mercurial/cmdutil.py @ 14986:70e11de6964d

export: add %m to file format string (first line of the commit message) $ hg commit -m "Initial commit" $ hg export -o %m.patch tip #It creates Initial_commit.patch file.
author Andrzej Bieniek <andyhelp@gmail.com>
date Sat, 30 Jul 2011 11:08:45 +0100
parents 32302480b402
children 231aac5280ba
comparison
equal deleted inserted replaced
14985:dbf91976f900 14986:70e11de6964d
107 raise util.Abort(_('limit must be positive')) 107 raise util.Abort(_('limit must be positive'))
108 else: 108 else:
109 limit = None 109 limit = None
110 return limit 110 return limit
111 111
112 def makefilename(repo, pat, node, 112 def makefilename(repo, pat, node, desc=None,
113 total=None, seqno=None, revwidth=None, pathname=None): 113 total=None, seqno=None, revwidth=None, pathname=None):
114 node_expander = { 114 node_expander = {
115 'H': lambda: hex(node), 115 'H': lambda: hex(node),
116 'R': lambda: str(repo.changelog.rev(node)), 116 'R': lambda: str(repo.changelog.rev(node)),
117 'h': lambda: short(node), 117 'h': lambda: short(node),
118 'm': lambda: re.sub('[^\w]', '_', str(desc))
118 } 119 }
119 expander = { 120 expander = {
120 '%': lambda: '%', 121 '%': lambda: '%',
121 'b': lambda: os.path.basename(repo.root), 122 'b': lambda: os.path.basename(repo.root),
122 } 123 }
152 return ''.join(newname) 153 return ''.join(newname)
153 except KeyError, inst: 154 except KeyError, inst:
154 raise util.Abort(_("invalid format spec '%%%s' in output filename") % 155 raise util.Abort(_("invalid format spec '%%%s' in output filename") %
155 inst.args[0]) 156 inst.args[0])
156 157
157 def makefileobj(repo, pat, node=None, total=None, 158 def makefileobj(repo, pat, node=None, desc=None, total=None,
158 seqno=None, revwidth=None, mode='wb', pathname=None): 159 seqno=None, revwidth=None, mode='wb', pathname=None):
159 160
160 writable = mode not in ('r', 'rb') 161 writable = mode not in ('r', 'rb')
161 162
162 if not pat or pat == '-': 163 if not pat or pat == '-':
179 return wrappedfileobj(fp) 180 return wrappedfileobj(fp)
180 if util.safehasattr(pat, 'write') and writable: 181 if util.safehasattr(pat, 'write') and writable:
181 return pat 182 return pat
182 if util.safehasattr(pat, 'read') and 'r' in mode: 183 if util.safehasattr(pat, 'read') and 'r' in mode:
183 return pat 184 return pat
184 return open(makefilename(repo, pat, node, total, seqno, revwidth, 185 return open(makefilename(repo, pat, node, desc, total, seqno, revwidth,
185 pathname), 186 pathname),
186 mode) 187 mode)
187 188
188 def openrevlog(repo, cmd, file_, opts): 189 def openrevlog(repo, cmd, file_, opts):
189 """opens the changelog, manifest, a filelog or a given revlog""" 190 """opens the changelog, manifest, a filelog or a given revlog"""
514 parents.reverse() 515 parents.reverse()
515 prev = (parents and parents[0]) or nullid 516 prev = (parents and parents[0]) or nullid
516 517
517 shouldclose = False 518 shouldclose = False
518 if not fp: 519 if not fp:
519 fp = makefileobj(repo, template, node, total=total, seqno=seqno, 520 desc_lines = ctx.description().rstrip().split('\n')
520 revwidth=revwidth, mode='ab') 521 desc = desc_lines[0] #Commit always has a first line.
522 fp = makefileobj(repo, template, node, desc=desc, total=total,
523 seqno=seqno, revwidth=revwidth, mode='ab')
521 if fp != template: 524 if fp != template:
522 shouldclose = True 525 shouldclose = True
523 if fp != sys.stdout and util.safehasattr(fp, 'name'): 526 if fp != sys.stdout and util.safehasattr(fp, 'name'):
524 repo.ui.note("%s\n" % fp.name) 527 repo.ui.note("%s\n" % fp.name)
525 528