# HG changeset patch # User FUJIWARA Katsunori # Date 1444330427 -32400 # Node ID 4688945f316cff0ee877e20177d39a4ce70a92ce # Parent dc2b8c0056973585744123fb4f1e3ee4dd466e10 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 -r dc2b8c005697 -r 4688945f316c mercurial/commands.py --- a/mercurial/commands.py Fri Oct 09 03:53:46 2015 +0900 +++ b/mercurial/commands.py Fri Oct 09 03:53:47 2015 +0900 @@ -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.