Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/cmdutil.py @ 21869:e353fac7db26
cmdutil: separate building commit text from 'commitforceeditor'
This separation makes it easier to extend/hook building commit text
from the specified context.
This patch uses 'committext' instead of 'edittext' for names of newly
added variable and function, because the former is more purpose
specific than the latter, even though 'edittext' in 'buildcommittext'
is left as it is to reduce amount of diff.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Tue, 15 Jul 2014 00:59:09 +0900 |
parents | 4b93e19cd6e6 |
children | abae1eb695c0 |
comparison
equal
deleted
inserted
replaced
21866:a2ca9dcb4b77 | 21869:e353fac7db26 |
---|---|
2168 if ctx.description(): | 2168 if ctx.description(): |
2169 return ctx.description() | 2169 return ctx.description() |
2170 return commitforceeditor(repo, ctx, subs) | 2170 return commitforceeditor(repo, ctx, subs) |
2171 | 2171 |
2172 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None): | 2172 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None): |
2173 committext = buildcommittext(repo, ctx, subs, extramsg) | |
2174 | |
2175 # run editor in the repository root | |
2176 olddir = os.getcwd() | |
2177 os.chdir(repo.root) | |
2178 text = repo.ui.edit(committext, ctx.user(), ctx.extra()) | |
2179 text = re.sub("(?m)^HG:.*(\n|$)", "", text) | |
2180 os.chdir(olddir) | |
2181 | |
2182 if finishdesc: | |
2183 text = finishdesc(text) | |
2184 if not text.strip(): | |
2185 raise util.Abort(_("empty commit message")) | |
2186 | |
2187 return text | |
2188 | |
2189 def buildcommittext(repo, ctx, subs, extramsg): | |
2173 edittext = [] | 2190 edittext = [] |
2174 modified, added, removed = ctx.modified(), ctx.added(), ctx.removed() | 2191 modified, added, removed = ctx.modified(), ctx.added(), ctx.removed() |
2175 if ctx.description(): | 2192 if ctx.description(): |
2176 edittext.append(ctx.description()) | 2193 edittext.append(ctx.description()) |
2177 edittext.append("") | 2194 edittext.append("") |
2195 edittext.extend([_("HG: changed %s") % f for f in modified]) | 2212 edittext.extend([_("HG: changed %s") % f for f in modified]) |
2196 edittext.extend([_("HG: removed %s") % f for f in removed]) | 2213 edittext.extend([_("HG: removed %s") % f for f in removed]) |
2197 if not added and not modified and not removed: | 2214 if not added and not modified and not removed: |
2198 edittext.append(_("HG: no files changed")) | 2215 edittext.append(_("HG: no files changed")) |
2199 edittext.append("") | 2216 edittext.append("") |
2200 # run editor in the repository root | 2217 |
2201 olddir = os.getcwd() | 2218 return "\n".join(edittext) |
2202 os.chdir(repo.root) | |
2203 text = repo.ui.edit("\n".join(edittext), ctx.user(), ctx.extra()) | |
2204 text = re.sub("(?m)^HG:.*(\n|$)", "", text) | |
2205 os.chdir(olddir) | |
2206 | |
2207 if finishdesc: | |
2208 text = finishdesc(text) | |
2209 if not text.strip(): | |
2210 raise util.Abort(_("empty commit message")) | |
2211 | |
2212 return text | |
2213 | 2219 |
2214 def commitstatus(repo, node, branch, bheads=None, opts={}): | 2220 def commitstatus(repo, node, branch, bheads=None, opts={}): |
2215 ctx = repo[node] | 2221 ctx = repo[node] |
2216 parents = ctx.parents() | 2222 parents = ctx.parents() |
2217 | 2223 |