[PATCH 5 of 6] commands: make "hg import" use dirstateguard only for --no-commit

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Thu Oct 8 13:59:04 CDT 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1444330427 -32400
#      Fri Oct 09 03:53:47 2015 +0900
# Node ID f4ff0385ec32d5192ce67fc6228ec87333335b14
# Parent  fd24d7ebe63f0c9d99dc467f1a17885b884ad2cd
commands: make "hg import" use dirstateguard only for --no-commit

Previous patch made dirstate changes in a transaction scope "all or
nothing". Therefore, 'dirstateguard' is meaningless, if its scope is
as same as one of the related transaction.

Before this patch, "hg import" uses 'dirstateguard' always, but
transaction is also started if '--no-commit' isn't specified.

To avoid redundancy, this patch makes "hg import" use dirstateguard
only if transaction isn't started (= '--no-commit' is specified).

In this patch, 'if dsguard' can be examined safely, because 'dsguard'
is initialized (with None) before outermost 'try'.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4407,10 +4407,11 @@
     try:
         try:
             wlock = repo.wlock()
-            dsguard = cmdutil.dirstateguard(repo, 'import')
             if not opts.get('no_commit'):
                 lock = repo.lock()
                 tr = repo.transaction('import')
+            else:
+                dsguard = cmdutil.dirstateguard(repo, 'import')
             parents = repo.parents()
             for patchurl in patches:
                 if patchurl == '-':
@@ -4448,7 +4449,8 @@
                 tr.close()
             if msgs:
                 repo.savecommitmessage('\n* * *\n'.join(msgs))
-            dsguard.close()
+            if dsguard:
+                dsguard.close()
             return ret
         finally:
             # TODO: get rid of this meaningless try/finally enclosing.


More information about the Mercurial-devel mailing list