hgext/evolve.py
branchstable
changeset 930 cac35bef8aee
parent 927 154510dc4318
child 931 32915143d448
equal deleted inserted replaced
929:306f67906a6c 930:cac35bef8aee
    50 from mercurial import hg
    50 from mercurial import hg
    51 from mercurial import lock as lockmod
    51 from mercurial import lock as lockmod
    52 from mercurial import merge
    52 from mercurial import merge
    53 from mercurial import node
    53 from mercurial import node
    54 from mercurial import phases
    54 from mercurial import phases
       
    55 from mercurial import patch
    55 from mercurial import revset
    56 from mercurial import revset
    56 from mercurial import scmutil
    57 from mercurial import scmutil
    57 from mercurial import templatekw
    58 from mercurial import templatekw
    58 from mercurial.i18n import _
    59 from mercurial.i18n import _
    59 from mercurial.commands import walkopts, commitopts, commitopts2
    60 from mercurial.commands import walkopts, commitopts, commitopts2
   820     ('d', 'date', '',
   821     ('d', 'date', '',
   821      _('record the specified date in metadata'), _('DATE')),
   822      _('record the specified date in metadata'), _('DATE')),
   822     ('u', 'user', '',
   823     ('u', 'user', '',
   823      _('record the specified user in metadata'), _('USER')),
   824      _('record the specified user in metadata'), _('USER')),
   824 ]
   825 ]
       
   826 
       
   827 if getattr(mercurial.cmdutil, 'tryimportone', None) is not None:
       
   828     # hg 3.0 and greate
       
   829     @eh.uisetup
       
   830     def _installimportobsolete(ui):
       
   831         entry = cmdutil.findcmd('import', commands.table)[1]
       
   832         entry[1].append(('', 'obsolete', False,
       
   833                         _('mark the old node as obsoleted by'
       
   834                           'the created commit')))
       
   835 
       
   836     @eh.wrapfunction(mercurial.cmdutil, 'tryimportone')
       
   837     def tryimportone(orig, ui, repo, hunk, parents, opts, *args, **kwargs):
       
   838         extracted = patch.extract(ui, hunk)
       
   839         expected = extracted[5]
       
   840         oldextract = patch.extract
       
   841         try:
       
   842             patch.extract = lambda ui, hunk: extracted
       
   843             ret = orig(ui, repo, hunk, parents, opts, *args, **kwargs)
       
   844         finally:
       
   845             patch.extract = oldextract
       
   846         created = ret[1]
       
   847         if opts['obsolete'] and created is not None and created != expected:
       
   848                 tr = repo.transaction('import-obs')
       
   849                 try:
       
   850                     metadata = {'user': ui.username()}
       
   851                     repo.obsstore.create(tr, node.bin(expected), (created,),
       
   852                                          metadata=metadata)
       
   853                     tr.close()
       
   854                 finally:
       
   855                     tr.release()
       
   856         return ret
   825 
   857 
   826 
   858 
   827 @command('^evolve|stabilize|solve',
   859 @command('^evolve|stabilize|solve',
   828     [('n', 'dry-run', False, 'do not perform actions, just print what would be done'),
   860     [('n', 'dry-run', False, 'do not perform actions, just print what would be done'),
   829     ('A', 'any', False, 'evolve any troubled changeset'),
   861     ('A', 'any', False, 'evolve any troubled changeset'),