comparison hgext/histedit.py @ 27207:2d8dbeb2462c

histedit: change state.rules uses to state.actions This change is replacing most of state.rules uses with state.actions uses. The next change will change histeditstate class to actually uses state actions.
author Mateusz Kwapich <mitrandir@fb.com>
date Wed, 02 Dec 2015 12:19:01 -0800
parents 7a523b6d5265
children 994d8dced775
comparison
equal deleted inserted replaced
27206:7a523b6d5265 27207:2d8dbeb2462c
1055 'histedit') 1055 'histedit')
1056 state.backupfile = backupfile 1056 state.backupfile = backupfile
1057 1057
1058 # preprocess rules so that we can hide inner folds from the user 1058 # preprocess rules so that we can hide inner folds from the user
1059 # and only show one editor 1059 # and only show one editor
1060 rules = state.rules[:] 1060 actions = state.actions[:]
1061 for idx, ((action, ha), (nextact, unused)) in enumerate( 1061 for idx, (action, nextact) in enumerate(
1062 zip(rules, rules[1:] + [(None, None)])): 1062 zip(actions, actions[1:] + [None])):
1063 if action == 'fold' and nextact == 'fold': 1063 if action.verb == 'fold' and nextact and nextact.verb == 'fold':
1064 state.rules[idx] = '_multifold', ha 1064 state.actions[idx].__class__ = _multifold
1065 1065 state.rules[idx] = '_multifold', action.nodetoverify() # TODO remove this
1066 while state.rules: 1066
1067 while state.actions:
1067 state.write() 1068 state.write()
1068 action, ha = state.rules.pop(0) 1069 actobj = state.actions.pop(0)
1069 ui.debug('histedit: processing %s %s\n' % (action, ha[:12])) 1070 state.rules.pop(0) # TODO remove this
1070 actobj = actiontable[action].fromrule(state, ha) 1071 ui.debug('histedit: processing %s %s\n' % (actobj.verb,\
1072 actobj.torule()))
1071 parentctx, replacement_ = actobj.run() 1073 parentctx, replacement_ = actobj.run()
1072 state.parentctxnode = parentctx.node() 1074 state.parentctxnode = parentctx.node()
1073 state.replacements.extend(replacement_) 1075 state.replacements.extend(replacement_)
1074 state.write() 1076 state.write()
1075 1077
1115 if os.path.exists(repo.sjoin('undo')): 1117 if os.path.exists(repo.sjoin('undo')):
1116 os.unlink(repo.sjoin('undo')) 1118 os.unlink(repo.sjoin('undo'))
1117 1119
1118 def bootstrapcontinue(ui, state, opts): 1120 def bootstrapcontinue(ui, state, opts):
1119 repo = state.repo 1121 repo = state.repo
1120 if state.rules: 1122 if state.actions:
1121 action, currentnode = state.rules.pop(0) 1123 actobj = state.actions.pop(0)
1122 1124 state.rules.pop(0) # TODO remove this
1123 actobj = actiontable[action].fromrule(state, currentnode)
1124 1125
1125 if _isdirtywc(repo): 1126 if _isdirtywc(repo):
1126 actobj.continuedirty() 1127 actobj.continuedirty()
1127 if _isdirtywc(repo): 1128 if _isdirtywc(repo):
1128 abortdirty() 1129 abortdirty()
1368 if isinstance(nodelist, str): 1369 if isinstance(nodelist, str):
1369 nodelist = [nodelist] 1370 nodelist = [nodelist]
1370 if os.path.exists(os.path.join(repo.path, 'histedit-state')): 1371 if os.path.exists(os.path.join(repo.path, 'histedit-state')):
1371 state = histeditstate(repo) 1372 state = histeditstate(repo)
1372 state.read() 1373 state.read()
1373 histedit_nodes = set([repo[rulehash].node() for (action, rulehash) 1374 histedit_nodes = set([action.nodetoverify() for action
1374 in state.rules if rulehash in repo]) 1375 in state.actions if action.nodetoverify()])
1375 strip_nodes = set([repo[n].node() for n in nodelist]) 1376 strip_nodes = set([repo[n].node() for n in nodelist])
1376 common_nodes = histedit_nodes & strip_nodes 1377 common_nodes = histedit_nodes & strip_nodes
1377 if common_nodes: 1378 if common_nodes:
1378 raise error.Abort(_("histedit in progress, can't strip %s") 1379 raise error.Abort(_("histedit in progress, can't strip %s")
1379 % ', '.join(node.short(x) for x in common_nodes)) 1380 % ', '.join(node.short(x) for x in common_nodes))
1384 def summaryhook(ui, repo): 1385 def summaryhook(ui, repo):
1385 if not os.path.exists(repo.join('histedit-state')): 1386 if not os.path.exists(repo.join('histedit-state')):
1386 return 1387 return
1387 state = histeditstate(repo) 1388 state = histeditstate(repo)
1388 state.read() 1389 state.read()
1389 if state.rules: 1390 if state.actions:
1390 # i18n: column positioning for "hg summary" 1391 # i18n: column positioning for "hg summary"
1391 ui.write(_('hist: %s (histedit --continue)\n') % 1392 ui.write(_('hist: %s (histedit --continue)\n') %
1392 (ui.label(_('%d remaining'), 'histedit.remaining') % 1393 (ui.label(_('%d remaining'), 'histedit.remaining') %
1393 len(state.rules))) 1394 len(state.actions)))
1394 1395
1395 def extsetup(ui): 1396 def extsetup(ui):
1396 cmdutil.summaryhooks.add('histedit', summaryhook) 1397 cmdutil.summaryhooks.add('histedit', summaryhook)
1397 cmdutil.unfinishedstates.append( 1398 cmdutil.unfinishedstates.append(
1398 ['histedit-state', False, True, _('histedit in progress'), 1399 ['histedit-state', False, True, _('histedit in progress'),