[PATCH 2 of 3] import: separate parents selection from working dir update

Patrick Mezard pmezard at gmail.com
Sat Jun 11 08:20:04 CDT 2011


# HG changeset patch
# User Patrick Mezard <pmezard at gmail.com>
# Date 1307796660 -7200
# Node ID 231c722c1d8db6a9181a22e41272320114f87093
# Parent  1fe290d68004ebb01730cbf2fb1d799258e2c9a8
import: separate parents selection from working dir update

This will be useful when patching without updating the dirstate

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3086,23 +3086,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')
 


More information about the Mercurial-devel mailing list