Mercurial > hg
comparison hgext/histedit.py @ 27545:a67d2e059a51
histedit: use parse-error exception for parsing
author | timeless <timeless@mozdev.org> |
---|---|
date | Sun, 27 Dec 2015 03:33:09 +0000 |
parents | ff0e4c8e642d |
children | c00924c54607 |
comparison
equal
deleted
inserted
replaced
27544:a4f008612727 | 27545:a67d2e059a51 |
---|---|
363 repo = self.repo | 363 repo = self.repo |
364 ha = node.hex(self.node) | 364 ha = node.hex(self.node) |
365 try: | 365 try: |
366 self.node = repo[ha].node() | 366 self.node = repo[ha].node() |
367 except error.RepoError: | 367 except error.RepoError: |
368 raise error.Abort(_('unknown changeset %s listed') | 368 raise error.ParseError(_('unknown changeset %s listed') |
369 % ha[:12]) | 369 % ha[:12]) |
370 | 370 |
371 def torule(self): | 371 def torule(self): |
372 """build a histedit rule line for an action | 372 """build a histedit rule line for an action |
373 | 373 |
507 ctxs = list(repo.set('%d::%d', first, last)) | 507 ctxs = list(repo.set('%d::%d', first, last)) |
508 if not ctxs: | 508 if not ctxs: |
509 return None | 509 return None |
510 for c in ctxs: | 510 for c in ctxs: |
511 if not c.mutable(): | 511 if not c.mutable(): |
512 raise error.Abort( | 512 raise error.ParseError( |
513 _("cannot fold into public change %s") % node.short(c.node())) | 513 _("cannot fold into public change %s") % node.short(c.node())) |
514 base = first.parents()[0] | 514 base = first.parents()[0] |
515 | 515 |
516 # commit a new version of the old changeset, including the update | 516 # commit a new version of the old changeset, including the update |
517 # collect all files which might be affected | 517 # collect all files which might be affected |
631 elif not prev.verb in ('pick', 'base'): | 631 elif not prev.verb in ('pick', 'base'): |
632 return | 632 return |
633 else: | 633 else: |
634 c = repo[prev.node] | 634 c = repo[prev.node] |
635 if not c.mutable(): | 635 if not c.mutable(): |
636 raise error.Abort( | 636 raise error.ParseError( |
637 _("cannot fold into public change %s") % node.short(c.node())) | 637 _("cannot fold into public change %s") % node.short(c.node())) |
638 | 638 |
639 | 639 |
640 def continuedirty(self): | 640 def continuedirty(self): |
641 repo = self.repo | 641 repo = self.repo |
1205 rules = [l for l in (r.strip() for r in rules.splitlines()) | 1205 rules = [l for l in (r.strip() for r in rules.splitlines()) |
1206 if l and not l.startswith('#')] | 1206 if l and not l.startswith('#')] |
1207 actions = [] | 1207 actions = [] |
1208 for r in rules: | 1208 for r in rules: |
1209 if ' ' not in r: | 1209 if ' ' not in r: |
1210 raise error.Abort(_('malformed line "%s"') % r) | 1210 raise error.ParseError(_('malformed line "%s"') % r) |
1211 verb, rest = r.split(' ', 1) | 1211 verb, rest = r.split(' ', 1) |
1212 | 1212 |
1213 if verb not in actiontable: | 1213 if verb not in actiontable: |
1214 raise error.Abort(_('unknown action "%s"') % verb) | 1214 raise error.ParseError(_('unknown action "%s"') % verb) |
1215 | 1215 |
1216 action = actiontable[verb].fromrule(state, rest) | 1216 action = actiontable[verb].fromrule(state, rest) |
1217 actions.append(action) | 1217 actions.append(action) |
1218 return actions | 1218 return actions |
1219 | 1219 |
1220 def warnverifyactions(ui, repo, actions, state, ctxs): | 1220 def warnverifyactions(ui, repo, actions, state, ctxs): |
1221 try: | 1221 try: |
1222 verifyactions(actions, state, ctxs) | 1222 verifyactions(actions, state, ctxs) |
1223 except error.Abort: | 1223 except error.ParseError: |
1224 if repo.vfs.exists('histedit-last-edit.txt'): | 1224 if repo.vfs.exists('histedit-last-edit.txt'): |
1225 ui.warn(_('warning: histedit rules saved ' | 1225 ui.warn(_('warning: histedit rules saved ' |
1226 'to: .hg/histedit-last-edit.txt\n')) | 1226 'to: .hg/histedit-last-edit.txt\n')) |
1227 raise | 1227 raise |
1228 | 1228 |
1240 action.verify(prev) | 1240 action.verify(prev) |
1241 prev = action | 1241 prev = action |
1242 constraints = action.constraints() | 1242 constraints = action.constraints() |
1243 for constraint in constraints: | 1243 for constraint in constraints: |
1244 if constraint not in _constraints.known(): | 1244 if constraint not in _constraints.known(): |
1245 raise error.Abort(_('unknown constraint "%s"') % constraint) | 1245 raise error.ParseError(_('unknown constraint "%s"') % |
1246 constraint) | |
1246 | 1247 |
1247 nodetoverify = action.nodetoverify() | 1248 nodetoverify = action.nodetoverify() |
1248 if nodetoverify is not None: | 1249 if nodetoverify is not None: |
1249 ha = node.hex(nodetoverify) | 1250 ha = node.hex(nodetoverify) |
1250 if _constraints.noother in constraints and ha not in expected: | 1251 if _constraints.noother in constraints and ha not in expected: |
1251 raise error.Abort( | 1252 raise error.ParseError( |
1252 _('may not use "%s" with changesets ' | 1253 _('may not use "%s" with changesets ' |
1253 'other than the ones listed') % action.verb) | 1254 'other than the ones listed') % action.verb) |
1254 if _constraints.forceother in constraints and ha in expected: | 1255 if _constraints.forceother in constraints and ha in expected: |
1255 raise error.Abort( | 1256 raise error.ParseError( |
1256 _('may not use "%s" with changesets ' | 1257 _('may not use "%s" with changesets ' |
1257 'within the edited list') % action.verb) | 1258 'within the edited list') % action.verb) |
1258 if _constraints.noduplicates in constraints and ha in seen: | 1259 if _constraints.noduplicates in constraints and ha in seen: |
1259 raise error.Abort(_('duplicated command for changeset %s') % | 1260 raise error.ParseError(_( |
1261 'duplicated command for changeset %s') % | |
1260 ha[:12]) | 1262 ha[:12]) |
1261 seen.add(ha) | 1263 seen.add(ha) |
1262 missing = sorted(expected - seen) # sort to stabilize output | 1264 missing = sorted(expected - seen) # sort to stabilize output |
1263 | 1265 |
1264 if state.repo.ui.configbool('histedit', 'dropmissing'): | 1266 if state.repo.ui.configbool('histedit', 'dropmissing'): |
1265 drops = [drop(state, node.bin(n)) for n in missing] | 1267 drops = [drop(state, node.bin(n)) for n in missing] |
1266 # put the in the beginning so they execute immediately and | 1268 # put the in the beginning so they execute immediately and |
1267 # don't show in the edit-plan in the future | 1269 # don't show in the edit-plan in the future |
1268 actions[:0] = drops | 1270 actions[:0] = drops |
1269 elif missing: | 1271 elif missing: |
1270 raise error.Abort(_('missing rules for changeset %s') % | 1272 raise error.ParseError(_('missing rules for changeset %s') % |
1271 missing[0][:12], | 1273 missing[0][:12], |
1272 hint=_('use "drop %s" to discard, see also: ' | 1274 hint=_('use "drop %s" to discard, see also: ' |
1273 '"hg help -e histedit.config"') % missing[0][:12]) | 1275 '"hg help -e histedit.config"') % missing[0][:12]) |
1274 | 1276 |
1275 def newnodestoabort(state): | 1277 def newnodestoabort(state): |