Mercurial > hg
comparison hgext/histedit.py @ 29465:00d2bf4137e6
histedit: move autoverb logic from torule to ruleeditor
This is needed for an upcoming change that will automatically rearrange the
rules based on the commit message. Before this patch, the autoverb logic only
applied to one rule at a time. This moves that logic one step up so that it can
iterate over all the rules and rearrange as needed.
author | Sean Farley <sean@farley.io> |
---|---|
date | Thu, 26 May 2016 16:46:10 -0700 |
parents | b501579147f1 |
children | a0efbfbba7b5 |
comparison
equal
deleted
inserted
replaced
29464:87c184c9bfef | 29465:00d2bf4137e6 |
---|---|
421 """ | 421 """ |
422 ctx = self.repo[self.node] | 422 ctx = self.repo[self.node] |
423 summary = '' | 423 summary = '' |
424 if ctx.description(): | 424 if ctx.description(): |
425 summary = ctx.description().splitlines()[0] | 425 summary = ctx.description().splitlines()[0] |
426 | |
427 fword = summary.split(' ', 1)[0].lower() | |
428 # if it doesn't end with the special character '!' just skip this | |
429 if (self.repo.ui.configbool("experimental", "histedit.autoverb") and | |
430 initial and fword.endswith('!')): | |
431 fword = fword[:-1] | |
432 if fword in primaryactions | secondaryactions | tertiaryactions: | |
433 self.verb = fword | |
434 line = '%s %s %d %s' % (self.verb, ctx, ctx.rev(), summary) | 426 line = '%s %s %d %s' % (self.verb, ctx, ctx.rev(), summary) |
435 # trim to 75 columns by default so it's not stupidly wide in my editor | 427 # trim to 75 columns by default so it's not stupidly wide in my editor |
436 # (the 5 more are left for verb) | 428 # (the 5 more are left for verb) |
437 maxlen = self.repo.ui.configint('histedit', 'linelen', default=80) | 429 maxlen = self.repo.ui.configint('histedit', 'linelen', default=80) |
438 maxlen = max(maxlen, 22) # avoid truncating hash | 430 maxlen = max(maxlen, 22) # avoid truncating hash |
1315 def ruleeditor(repo, ui, actions, editcomment=""): | 1307 def ruleeditor(repo, ui, actions, editcomment=""): |
1316 """open an editor to edit rules | 1308 """open an editor to edit rules |
1317 | 1309 |
1318 rules are in the format [ [act, ctx], ...] like in state.rules | 1310 rules are in the format [ [act, ctx], ...] like in state.rules |
1319 """ | 1311 """ |
1312 if repo.ui.configbool("experimental", "histedit.autoverb"): | |
1313 for act in actions: | |
1314 ctx = repo[act.node] | |
1315 summary = '' | |
1316 if ctx.description(): | |
1317 summary = ctx.description().splitlines()[0] | |
1318 | |
1319 fword = summary.split(' ', 1)[0].lower() | |
1320 # if it doesn't end with the special character '!' just skip this | |
1321 if fword.endswith('!'): | |
1322 fword = fword[:-1] | |
1323 if fword in primaryactions | secondaryactions | tertiaryactions: | |
1324 act.verb = fword | |
1325 | |
1320 rules = '\n'.join([act.torule(initial=True) for act in actions]) | 1326 rules = '\n'.join([act.torule(initial=True) for act in actions]) |
1321 rules += '\n\n' | 1327 rules += '\n\n' |
1322 rules += editcomment | 1328 rules += editcomment |
1323 rules = ui.edit(rules, ui.username(), {'prefix': 'histedit'}) | 1329 rules = ui.edit(rules, ui.username(), {'prefix': 'histedit'}) |
1324 | 1330 |