[PATCH 1 of 2] largefiles: for update -C, only update largefiles when necessary

Mads Kiilerich mads at kiilerich.com
Wed Apr 15 19:22:51 UTC 2015


# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1429125736 14400
#      Wed Apr 15 15:22:16 2015 -0400
# Node ID e65b603cd5e24f877d1aa93f45e4324fd2cb36f9
# Parent  c560d8c687916cb70a6d54c2c9ddcb5c9e457be2
largefiles: for update -C, only update largefiles when necessary

Before, a --clean update with largefiles would use the "optimization" that it
didn't read hashes from standin files before and after the update. Instead of
trusting the content of the standin files, it would rehash all the actual
largefiles that lfdirstate reported clean and update the standins that didn't
have the expected content. It could thus in some "impossible" situations
automatically recover from some "largefile got out sync with its standin"
issues (even there apparently still were weird corner cases where it could
fail). This extra checking is similar to what core --clean intentionally do
not do, and it made update --clean unbearable slow.

Usually in core Mercurial, --clean will rely on the dirstate to find the files
it should update. (It is thus intentionally possible (when trying to trick the
system or if there should be bugs) to end up in situations where --clean not
will restore the working directory content correctly.) Checking every file when
we "know" it is ok is however not an option - that would be too slow.

Instead, trust the content of the standin files. Use the same logic for --clean
as for linear updates and trust the dirstate and that our "logic" will keep
them in sync. It is much cheaper to just rehash the largefiles reported dirty
by a status walk and read all standins than to hash largefiles.

Most of the changes are just a change of indentation now when the different
kinds of updates no longer are handled that differently. Standins for added
files are however only written when doing a normal update, while deleted and
removed files only will be updated for --clean updates.

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -1318,45 +1318,37 @@ def mergeupdate(orig, repo, node, branch
         # (*) don't care
         # (*1) deprecated, but used internally (e.g: "rebase --collapse")
 
-        linearmerge = not branchmerge and not force and not partial
+        lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
+        unsure, s = lfdirstate.status(match_.always(repo.root,
+                                                    repo.getcwd()),
+                                      [], False, False, False)
+        pctx = repo['.']
+        for lfile in unsure + s.modified:
+            lfileabs = repo.wvfs.join(lfile)
+            if not os.path.exists(lfileabs):
+                continue
+            lfhash = lfutil.hashrepofile(repo, lfile)
+            standin = lfutil.standin(lfile)
+            lfutil.writestandin(repo, standin, lfhash,
+                                lfutil.getexecutable(lfileabs))
+            if (standin in pctx and
+                lfhash == lfutil.readstandin(repo, lfile, '.')):
+                lfdirstate.normal(lfile)
+        for lfile in s.added:
+            lfutil.updatestandin(repo, lfutil.standin(lfile))
+        lfdirstate.write()
 
-        if linearmerge or (branchmerge and force and not partial):
-            # update standins for linear-merge or force-branch-merge,
-            # because largefiles in the working directory may be modified
-            lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
-            unsure, s = lfdirstate.status(match_.always(repo.root,
-                                                        repo.getcwd()),
-                                          [], False, False, False)
-            pctx = repo['.']
-            for lfile in unsure + s.modified:
-                lfileabs = repo.wvfs.join(lfile)
-                if not os.path.exists(lfileabs):
-                    continue
-                lfhash = lfutil.hashrepofile(repo, lfile)
-                standin = lfutil.standin(lfile)
-                lfutil.writestandin(repo, standin, lfhash,
-                                    lfutil.getexecutable(lfileabs))
-                if (standin in pctx and
-                    lfhash == lfutil.readstandin(repo, lfile, '.')):
-                    lfdirstate.normal(lfile)
-            for lfile in s.added:
-                lfutil.updatestandin(repo, lfutil.standin(lfile))
-            lfdirstate.write()
-
-        if linearmerge:
-            # Only call updatelfiles on the standins that have changed
-            # to save time
-            oldstandins = lfutil.getstandinsstate(repo)
+        oldstandins = lfutil.getstandinsstate(repo)
 
         result = orig(repo, node, branchmerge, force, partial, *args, **kwargs)
 
-        filelist = None
-        if linearmerge:
-            newstandins = lfutil.getstandinsstate(repo)
-            filelist = lfutil.getlfilestoupdate(oldstandins, newstandins)
+        newstandins = lfutil.getstandinsstate(repo)
+        filelist = lfutil.getlfilestoupdate(oldstandins, newstandins)
+        if branchmerge or force or partial:
+            filelist.extend(s.deleted + s.removed)
 
         lfcommands.updatelfiles(repo.ui, repo, filelist=filelist,
-                                normallookup=partial, checked=linearmerge)
+                                normallookup=partial, checked=True)
 
         return result
     finally:
diff --git a/tests/test-issue3084.t b/tests/test-issue3084.t
--- a/tests/test-issue3084.t
+++ b/tests/test-issue3084.t
@@ -113,8 +113,6 @@ Largefile in the working copy, keeping t
   $ echo "l" | hg merge --config ui.interactive=Yes
   remote turned local largefile foo into a normal file
   keep (l)argefile or use (n)ormal file? l
-  getting changed largefiles
-  0 largefiles updated, 0 removed
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
 
@@ -249,8 +247,6 @@ swap
 
   $ hg up -Cqr large
   $ hg merge -r normal-id
-  getting changed largefiles
-  0 largefiles updated, 0 removed
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
   $ cat f
@@ -271,8 +267,6 @@ swap
 
   $ hg up -Cqr large
   $ hg merge -r normal-same
-  getting changed largefiles
-  0 largefiles updated, 0 removed
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
   $ cat f
@@ -307,8 +301,6 @@ swap
   $ hg merge -r normal2
   remote turned local largefile f into a normal file
   keep (l)argefile or use (n)ormal file? l
-  getting changed largefiles
-  0 largefiles updated, 0 removed
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
   $ cat f
@@ -372,8 +364,6 @@ Ancestor: large   Parent: large2   Paren
   $ hg merge -r normal
   remote turned local largefile f into a normal file
   keep (l)argefile or use (n)ormal file? l
-  getting changed largefiles
-  0 largefiles updated, 0 removed
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
   $ cat f
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
@@ -364,8 +364,6 @@ Test update with subrepos.
   $ hg update -C
   getting changed largefiles
   1 largefiles updated, 0 removed
-  getting changed largefiles
-  0 largefiles updated, 0 removed
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg status -S
 
@@ -805,8 +803,6 @@ merge action 'd' for 'local renamed dire
   R d1/f
   $ hg merge
   merging d2/f and d1/f to d2/f
-  getting changed largefiles
-  0 largefiles updated, 0 removed
   1 files updated, 1 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
   $ cd ..
diff --git a/tests/test-largefiles.t b/tests/test-largefiles.t
--- a/tests/test-largefiles.t
+++ b/tests/test-largefiles.t
@@ -581,8 +581,6 @@ Test 3507 (both normal files and largefi
   C sub2/large6
   C sub2/large7
   $ hg up -C '.^'
-  getting changed largefiles
-  0 largefiles updated, 0 removed
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg remove large
   $ hg addremove --traceback
@@ -1431,8 +1429,6 @@ Rollback on largefiles.
 
 verify that largefile .orig file no longer is overwritten on every update -C:
   $ hg update --clean
-  getting changed largefiles
-  0 largefiles updated, 0 removed
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ cat sub2/large7.orig
   mistake


More information about the Mercurial-devel mailing list