# HG changeset patch # User Matt Harbison # Date 2017-11-13 04:45:14 # Node ID b175e54c11039f7c5c92be9bbc978905d8795c89 # Parent 9fb2b0b41becdf24b40c05f76da5897f565e4a53 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. diff --git a/hgext/largefiles/lfcommands.py b/hgext/largefiles/lfcommands.py --- a/hgext/largefiles/lfcommands.py +++ b/hgext/largefiles/lfcommands.py @@ -455,6 +455,7 @@ def updatelfiles(ui, repo, filelist=None 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 @@ def updatelfiles(ui, repo, filelist=None 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 @@ def updatelfiles(ui, repo, filelist=None 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) 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 @@ Move (and then undo) a directory move wi ? 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 @@ BUG: the standin for subdir2 should be d $ 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 @@ existing under .hglf/. .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 @@ Start from scratch, and rename something .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/