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

mail settings
Submitter Katsunori FUJIWARA
Date Oct. 8, 2015, 6:59 p.m.
Message ID <f4ff0385ec32d5192ce6.1444330744@feefifofum>
Download mbox | patch
Permalink /patch/10884/
State Accepted
Headers show


Katsunori FUJIWARA - Oct. 8, 2015, 6:59 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <>
# 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/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -4407,10 +4407,11 @@ 
             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 @@ 
             if msgs:
                 repo.savecommitmessage('\n* * *\n'.join(msgs))
-            dsguard.close()
+            if dsguard:
+                dsguard.close()
             return ret
             # TODO: get rid of this meaningless try/finally enclosing.