hgext/histedit.py
changeset 22984 e0b5f5e3afe8
parent 22983 a3a981563ce8
child 22985 0c14b9166da6
equal deleted inserted replaced
22983:a3a981563ce8 22984:e0b5f5e3afe8
   188 #
   188 #
   189 """)
   189 """)
   190 
   190 
   191 class histeditstate(object):
   191 class histeditstate(object):
   192     def __init__(self, repo, parentctx=None, rules=None, keep=None,
   192     def __init__(self, repo, parentctx=None, rules=None, keep=None,
   193             topmost=None, replacements=None):
   193             topmost=None, replacements=None, lock=None, wlock=None):
   194         self.repo = repo
   194         self.repo = repo
   195         self.rules = rules
   195         self.rules = rules
   196         self.keep = keep
   196         self.keep = keep
   197         self.topmost = topmost
   197         self.topmost = topmost
   198         self.parentctx = parentctx
   198         self.parentctx = parentctx
       
   199         self.lock = lock
       
   200         self.wlock = wlock
   199         if replacements is None:
   201         if replacements is None:
   200             self.replacements = []
   202             self.replacements = []
   201         else:
   203         else:
   202             self.replacements = replacements
   204             self.replacements = replacements
   203 
   205 
   535 
   537 
   536     Returns 0 on success, 1 if user intervention is required (not only
   538     Returns 0 on success, 1 if user intervention is required (not only
   537     for intentional "edit" command, but also for resolving unexpected
   539     for intentional "edit" command, but also for resolving unexpected
   538     conflicts).
   540     conflicts).
   539     """
   541     """
   540     lock = wlock = None
   542     state = histeditstate(repo)
   541     try:
   543     try:
   542         wlock = repo.wlock()
   544         state.wlock = repo.wlock()
   543         lock = repo.lock()
   545         state.lock = repo.lock()
   544         _histedit(ui, repo, *freeargs, **opts)
   546         _histedit(ui, repo, state, *freeargs, **opts)
   545     finally:
   547     finally:
   546         release(lock, wlock)
   548         release(state.lock, state.wlock)
   547 
   549 
   548 def _histedit(ui, repo, *freeargs, **opts):
   550 def _histedit(ui, repo, state, *freeargs, **opts):
   549     # TODO only abort if we try and histedit mq patches, not just
   551     # TODO only abort if we try and histedit mq patches, not just
   550     # blanket if mq patches are applied somewhere
   552     # blanket if mq patches are applied somewhere
   551     mq = getattr(repo, 'mq', None)
   553     mq = getattr(repo, 'mq', None)
   552     if mq and mq.applied:
   554     if mq and mq.applied:
   553         raise util.Abort(_('source has mq patches applied'))
   555         raise util.Abort(_('source has mq patches applied'))
   658                  if l and not l.startswith('#')]
   660                  if l and not l.startswith('#')]
   659         rules = verifyrules(rules, repo, ctxs)
   661         rules = verifyrules(rules, repo, ctxs)
   660 
   662 
   661         parentctx = repo[root].parents()[0]
   663         parentctx = repo[root].parents()[0]
   662 
   664 
   663         state = histeditstate(repo, parentctx, rules, keep, topmost,
   665         state.parentctx = parentctx
   664                     replacements)
   666         state.rules = rules
       
   667         state.keep = keep
       
   668         state.topmost = topmost
       
   669         state.replacements = replacements
   665 
   670 
   666     while state.rules:
   671     while state.rules:
   667         state.write()
   672         state.write()
   668         action, ha = state.rules.pop(0)
   673         action, ha = state.rules.pop(0)
   669         ui.debug('histedit: processing %s %s\n' % (action, ha))
   674         ui.debug('histedit: processing %s %s\n' % (action, ha))