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

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Sept. 9, 2014, 6:18 p.m.
Message ID <0fc224b5f3f12b645945.1410286727@feefifofum>
Download mbox | patch
Permalink /patch/5750/
State Changes Requested
Headers show

Comments

Katsunori FUJIWARA - Sept. 9, 2014, 6:18 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@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.

Patch

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)