largefiles: pay attention to dropped standin files when updating largefiles stable
authorMatt Harbison <matt_harbison@yahoo.com>
Sun, 12 Nov 2017 23:45:14 -0500
branchstable
changeset 35168 b175e54c1103
parent 35167 9fb2b0b41bec
child 35169 898c6f812a51
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 scope. 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.
hgext/largefiles/lfcommands.py
tests/test-largefiles-misc.t
--- a/hgext/largefiles/lfcommands.py	Sun Nov 12 00:24:38 2017 -0500
+++ b/hgext/largefiles/lfcommands.py	Sun Nov 12 23:45:14 2017 -0500
@@ -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 @@
         lfdirstate.write()
 
         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)
 
--- a/tests/test-largefiles-misc.t	Sun Nov 12 00:24:38 2017 -0500
+++ b/tests/test-largefiles-misc.t	Sun Nov 12 23:45:14 2017 -0500
@@ -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/
   .hglf/dir/
   .hglf/dir/subdir/
   .hglf/dir/subdir/large.bin
-  .hglf/dir/subdir2/
-  .hglf/dir/subdir2/large.bin
   .hglf/large
   dir/
   dir/subdir/
@@ -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
     dir/subdir/large.bin
   R dir/subdir/large.bin
   ? large.orig
@@ -1189,13 +1187,10 @@
   .hglf/dir/
   .hglf/dir/subdir2/
   .hglf/dir/subdir2/large.bin
-  .hglf/dir/subdir2/subdir/
-  .hglf/dir/subdir2/subdir/large.bin
   .hglf/large
   dir/
   dir/subdir2/
-  dir/subdir2/subdir/
-  dir/subdir2/subdir/large.bin
+  dir/subdir2/large.bin
   large
   large.orig
 
@@ -1236,9 +1231,6 @@
   .hglf/dir/
   .hglf/dir/subdir/
   .hglf/dir/subdir/large.bin
-  .hglf/dir2/
-  .hglf/dir2/subdir/
-  .hglf/dir2/subdir/large.bin
   .hglf/large
   dir/
   dir/subdir/