hgext/evolve.py
changeset 932 bcd0c12070b2
parent 919 ffce88754767
parent 931 32915143d448
child 937 43cceb37324c
--- a/hgext/evolve.py	Wed Apr 23 15:58:55 2014 -0700
+++ b/hgext/evolve.py	Sun May 11 01:29:11 2014 -0700
@@ -57,6 +57,7 @@
 from mercurial import merge
 from mercurial import node
 from mercurial import phases
+from mercurial import patch
 from mercurial import revset
 from mercurial import scmutil
 from mercurial import templatekw
@@ -804,7 +805,10 @@
         destbookmarks = repo.nodebookmarks(dest.node())
         nodesrc = orig.node()
         destphase = repo[nodesrc].phase()
+        wlock = lock = None
         try:
+            wlock = repo.wlock()
+            lock = repo.lock()
             r = rebase.rebasenode(repo, orig.node(), dest.node(),
                                   {node.nullrev: node.nullrev}, False)
             if r[-1]: #some conflict
@@ -818,6 +822,8 @@
                 pass
             exc.__class__ = LocalMergeFailure
             raise
+        finally:
+            lockmod.release(lock, wlock)
         oldbookmarks = repo.nodebookmarks(nodesrc)
         if nodenew is not None:
             phases.retractboundary(repo, destphase, [nodenew])
@@ -869,6 +875,38 @@
      _('record the specified user in metadata'), _('USER')),
 ]
 
+if getattr(mercurial.cmdutil, 'tryimportone', None) is not None:
+    # hg 3.0 and greate
+    @eh.uisetup
+    def _installimportobsolete(ui):
+        entry = cmdutil.findcmd('import', commands.table)[1]
+        entry[1].append(('', 'obsolete', False,
+                        _('mark the old node as obsoleted by'
+                          'the created commit')))
+
+    @eh.wrapfunction(mercurial.cmdutil, 'tryimportone')
+    def tryimportone(orig, ui, repo, hunk, parents, opts, *args, **kwargs):
+        extracted = patch.extract(ui, hunk)
+        expected = extracted[5]
+        oldextract = patch.extract
+        try:
+            patch.extract = lambda ui, hunk: extracted
+            ret = orig(ui, repo, hunk, parents, opts, *args, **kwargs)
+        finally:
+            patch.extract = oldextract
+        created = ret[1]
+        if opts['obsolete'] and created is not None and created != expected:
+                tr = repo.transaction('import-obs')
+                try:
+                    metadata = {'user': ui.username()}
+                    repo.obsstore.create(tr, node.bin(expected), (created,),
+                                         metadata=metadata)
+                    tr.close()
+                finally:
+                    tr.release()
+        return ret
+
+
 def _deprecatealias(oldalias, newalias):
     '''Deprecates an alias for a command in favour of another
 
@@ -1672,7 +1710,7 @@
         for p in sortedrevs(revs):
             cp = repo[p]
             if not cp.mutable():
-                # note: create marker would had raise something anyway
+                # note: createmarkers() would have raised something anyway
                 raise util.Abort('cannot prune immutable changeset: %s' % cp,
                                  hint='see "hg help phases" for details')
             precs.append(cp)
@@ -1698,11 +1736,19 @@
 
         # informs that changeset have been pruned
         ui.status(_('%i changesets pruned\n') % len(precs))
-        # update to an unkilled parent
+
         wdp = repo['.']
-        newnode = wdp
-        while newnode.obsolete():
-            newnode = newnode.parents()[0]
+
+        if len(sucs) == 1 and len(precs) == 1 and wdp in precs:
+            # '.' killed, so update to the successor
+            newnode = sucs[0]
+        else:
+            # update to an unkilled parent
+            newnode = wdp
+
+            while newnode.obsolete():
+                newnode = newnode.parents()[0]
+
         if newnode.node() != wdp.node():
             commands.update(ui, repo, newnode.rev())
             ui.status(_('working directory now at %s\n') % newnode)
@@ -1884,7 +1930,7 @@
             updatebookmarks(newid)
             if not repo[newid].files():
                 ui.warn(_("new changeset is empty\n"))
-                ui.status(_('(use "hg kill ." to remove it)\n'))
+                ui.status(_('(use "hg prune ." to remove it)\n'))
         finally:
             wlock.release()
     finally: