Patchwork [3,of,3,STABLE] largefiles: pay attention to dropped standin files when updating largefiles

mail settings
Submitter Matt Harbison
Date Dec. 1, 2017, 6:14 a.m.
Message ID <02a45cff5f4165db5c0e.1512108840@Envy>
Download mbox | patch
Permalink /patch/25847/
State Accepted
Headers show


Matt Harbison - Dec. 1, 2017, 6:14 a.m.
# HG changeset patch
# User Matt Harbison <>
# Date 1510548314 18000
#      Sun Nov 12 23:45:14 2017 -0500
# Branch stable
# Node ID 02a45cff5f4165db5c0e3a707244016ef1781e53
# Parent  87ce3c78d4cf79ef785df530c7a5b121b71e9bd4
largefiles: pay attention to dropped standin files when updating largefiles

Previously, the largefile for a dropped standin would be deleted here, and then
restored from the cache.  This had the effect of clobbering uncommitted changes
if a revert caused the file to be forgotten, which is not what happens with a
normal file.  Now the removal and update is skipped for dropped largefiles, and
the corresponding standin is deleted from disk.

This was noticed when working on issue5738 because the forgotten standin files
were left behind, and that changes the behavior of the next rename to that
directory.  My first attempt was to cleanup the standins before calling this.
That failed, because this function deletes the largefile if the corresponding
standin is missing.

This function is called by the revert command, merge (and therefore update), and
patch, via the scmutil.marktouched() override.  So it should be pretty narrow in

I didn't mark issue5738 as fixed because the move related issues can still
happen if the main tree and the .hglf subtree get out of sync somehow.  I don't
see an easy fix for that, but that should be an edge case.  If whoever queues
this thinks it is good enough to close out the bug and can cram it into the
summary, go for it.


diff --git a/hgext/largefiles/ b/hgext/largefiles/
--- a/hgext/largefiles/
+++ b/hgext/largefiles/
@@ -455,6 +455,7 @@ 
             lfiles = [f for f in lfiles if f in filelist]
         update = {}
+        dropped = set()
         updated, removed = 0, 0
         wvfs = repo.wvfs
         wctx = repo[None]
@@ -476,7 +477,11 @@ 
                 expecthash = lfutil.readasstandin(wctx[relstandin])
                 if expecthash != '':
                     if lfile not in wctx: # not switched to normal file
-                        wvfs.unlinkpath(rellfile, ignoremissing=True)
+                        if repo.dirstate[relstandin] != '?':
+                            wvfs.unlinkpath(rellfile, ignoremissing=True)
+                        else:
+                            dropped.add(rellfile)
                     # use normallookup() to allocate an entry in largefiles
                     # dirstate to prevent lfilesrepo.status() from reporting
                     # missing files as removed.
@@ -496,6 +501,15 @@ 
         if lfiles:
+            lfiles = [f for f in lfiles if f not in dropped]
+            for f in dropped:
+                repo.wvfs.unlinkpath(lfutil.standin(f))
+                # This needs to happen for dropped files, otherwise they stay in
+                # the M state.
+                lfutil.synclfdirstate(repo, lfdirstate, f, normallookup)
             statuswriter(_('getting changed largefiles\n'))
             cachelfiles(ui, repo, None, lfiles)
diff --git a/tests/test-largefiles-misc.t b/tests/test-largefiles-misc.t
--- a/tests/test-largefiles-misc.t
+++ b/tests/test-largefiles-misc.t
@@ -1148,20 +1148,18 @@ 
   ? dir/subdir2/large.bin
   ? large.orig
-BUG: The content of the forgotten file shouldn't be clobbered
+The content of the forgotten file shouldn't be clobbered
   $ cat dir/subdir2/large.bin
-  large2
+  modified
-BUG: the standin for subdir2 should be deleted, not just dropped
+The standin for subdir2 should be deleted, not just dropped
   $ listtree .hglf dir* large*
-  .hglf/dir/subdir2/
-  .hglf/dir/subdir2/large.bin
@@ -1173,13 +1171,13 @@ 
   $ rm -r dir/subdir2
-BUG: subdir should not be in the destination.  This is caused by the directory
-existing under .hglf/.
+'subdir' should not be in the destination.  It would be if the subdir2 directory
+existed under .hglf/.
   $ hg mv dir/subdir dir/subdir2
-  moving .hglf/dir/subdir/large.bin to .hglf/dir/subdir2/subdir/large.bin (glob)
+  moving .hglf/dir/subdir/large.bin to .hglf/dir/subdir2/large.bin (glob)
   $ hg status -C
-  A dir/subdir2/subdir/large.bin
+  A dir/subdir2/large.bin
   R dir/subdir/large.bin
   ? large.orig
@@ -1189,13 +1187,10 @@ 
-  .hglf/dir/subdir2/subdir/
-  .hglf/dir/subdir2/subdir/large.bin
-  dir/subdir2/subdir/
-  dir/subdir2/subdir/large.bin
+  dir/subdir2/large.bin
@@ -1236,9 +1231,6 @@ 
-  .hglf/dir2/
-  .hglf/dir2/subdir/
-  .hglf/dir2/subdir/large.bin