import: separate parents selection from working dir update
authorPatrick Mezard <pmezard@gmail.com>
Tue, 14 Jun 2011 23:24:40 +0200
changeset 14610 5d6244930559
parent 14609 f53dc0787424
child 14611 adbf5e7df96d
import: separate parents selection from working dir update This will be useful when patching without updating the dirstate
mercurial/commands.py
--- a/mercurial/commands.py	Tue Jun 14 23:24:34 2011 +0200
+++ b/mercurial/commands.py	Tue Jun 14 23:24:40 2011 +0200
@@ -3087,23 +3087,27 @@
             ui.debug('message:\n%s\n' % message)
 
             wp = repo.parents()
+            if len(wp) == 1:
+                wp.append(repo[nullid])
             if opts.get('exact'):
                 if not nodeid or not p1:
                     raise util.Abort(_('not a Mercurial patch'))
-                p1 = repo.lookup(p1)
-                p2 = repo.lookup(p2 or hex(nullid))
-
-                if p1 != wp[0].node():
-                    hg.clean(repo, p1)
-                repo.dirstate.setparents(p1, p2)
+                p1 = repo[p1]
+                p2 = repo[p2 or nullid]
             elif p2:
                 try:
-                    p1 = repo.lookup(p1)
-                    p2 = repo.lookup(p2)
-                    if p1 == wp[0].node():
-                        repo.dirstate.setparents(p1, p2)
+                    p1 = repo[p1]
+                    p2 = repo[p2]
                 except error.RepoError:
-                    pass
+                    p1, p2 = wp
+            else:
+                p1, p2 = wp
+
+            if opts.get('exact') and p1 != wp[0]:
+                hg.clean(repo, p1.node())
+            if p1 != wp[0] and p2 != wp[1]:
+                repo.dirstate.setparents(p1.node(), p2.node())
+
             if opts.get('exact') or opts.get('import_branch'):
                 repo.dirstate.setbranch(branch or 'default')