[PATCH 3 of 8] largefiles: wrap "autocommit" for specific code path at automated committing

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Tue Sep 9 13:18:47 CDT 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1410286453 -32400
#      Wed Sep 10 03:14:13 2014 +0900
# Node ID 0fc224b5f3f12b6459453ac8e809039ae3a9603e
# Parent  e1ea239437e1eba86dd66d8d78cdacc8076466ba
largefiles: wrap "autocommit" for specific code path at automated committing

"_lfautocommit" attribute makes "lfilesrepo.commit" assume that:

  - standins are already updated, and
  - largefiles have to be synchronize to standins

Then, at the 1st commit of resuming, this may cause corruption of
largefiles modified manually before resuming.

This patch avoids creating the scope of "_lfautocommit" attribute at
the 1st commit of resuming.

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -1327,3 +1327,24 @@
                                 printmessage=False, normallookup=True)
 
     return result
+
+def cmdutilautocommit(orig, commandname, repo, commitfunc, **props):
+    if props.get('resuming', False):
+        # Even while automated committing, "_lfautocommit" attribute
+        # must not be created at the 1st commit of resuming.
+        # "_lfautocommit" attribute causes executing "Case 0" code
+        # path in "lfilesrepo.commit()", and may corrupt largefiles
+        # possibly modified manually before resuming.
+        wrapper = commitfunc
+    else:
+        def wrapper(*args, **kwargs):
+            # to detect unexpected nesting scope
+            assert not getattr(repo, '_lfautocommit', False)
+
+            repo._lfautocommit = commandname
+            try:
+                return commitfunc(*args, **kwargs)
+            finally:
+                repo._lfautocommit = False
+
+    return orig(commandname, repo, wrapper, **props)
diff --git a/hgext/largefiles/uisetup.py b/hgext/largefiles/uisetup.py
--- a/hgext/largefiles/uisetup.py
+++ b/hgext/largefiles/uisetup.py
@@ -124,6 +124,8 @@
                             overrides.hgsubrepoarchive)
     extensions.wrapfunction(cmdutil, 'bailifchanged',
                             overrides.overridebailifchanged)
+    extensions.wrapfunction(cmdutil, 'autocommit',
+                            overrides.cmdutilautocommit)
 
     extensions.wrapfunction(scmutil, 'marktouched',
                             overrides.scmutilmarktouched)


More information about the Mercurial-devel mailing list