[PATCH] largefiles: cache new largefiles for new heads when pulling

Na'Tosha Bard natosha at unity3d.com
Wed Jan 18 04:34:03 CST 2012


# HG changeset patch
# User Na'Tosha Bard <natosha at unity3d.com>
# Date 1326882794 -3600
# Node ID 658ad6c3eb10ca6a975626cbbecb9fac3ded0798
# Parent  d25169284e9883bfff74faf4fdafdd74a6a5ba27
largefiles: cache new largefiles for new heads when pulling

When the user pulls from a remote repository that is not his default repo, it
is quite likely that he will pull a new head.  This means that if he tries to
merge or rebase with the other head, he will run into a problem becuase
largefiles has no way of tracking where the remote repository for this other
head is, so it cannot download the largefiles from this other remote repository.
It will attempt to download them from its default remote repository, which will
not yet contain the largefiles.

This patch solves this problem by caching any new largefiles for all heads
directly into the system cache at the time of the pull, so they are available
later.

This behavior is actually more in line with Mercurial's distributed nature,
because pulling already implies we have a connection to the remote server, but
merging or rebasing does not.

diff -r d25169284e98 -r 658ad6c3eb10 hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py	Mon Jan 16 19:45:35 2012 +0100
+++ b/hgext/largefiles/overrides.py	Wed Jan 18 11:33:14 2012 +0100
@@ -658,6 +658,19 @@
         if not source:
             source = 'default'
         result = orig(ui, repo, source, **opts)
+        # If we do not have the new largefiles for any new heads we pulled, we
+        # will run into a problem later if we try to merge or rebase with one of
+        # these heads, so cache the largefiles now direclty into the system
+        # cache.
+        ui.status(_("caching new largefiles\n"))
+        numcached = 0
+        branches = repo.branchmap()
+        for branch in branches:
+            heads = repo.branchheads(branch)
+            for head in heads:
+                (cached, missing) = lfcommands.cachelfiles(ui, repo, head)
+                numcached += len(cached)
+        ui.status(_("%d largefiles cached\n" % numcached))
     return result
 
 def override_rebase(orig, ui, repo, **opts):
diff -r d25169284e98 -r 658ad6c3eb10 tests/test-largefiles-cache.t
--- a/tests/test-largefiles-cache.t	Mon Jan 16 19:45:35 2012 +0100
+++ b/tests/test-largefiles-cache.t	Wed Jan 18 11:33:14 2012 +0100
@@ -37,6 +37,8 @@
   adding file changes
   added 1 changesets with 1 changes to 1 files
   (run 'hg update' to get a working copy)
+  caching new largefiles
+  0 largefiles cached
 
 Update working directory to "tip", which requires largefile("large"),
 but there is no cache file for it.  So, hg must treat it as
diff -r d25169284e98 -r 658ad6c3eb10 tests/test-largefiles.t
--- a/tests/test-largefiles.t	Mon Jan 16 19:45:35 2012 +0100
+++ b/tests/test-largefiles.t	Wed Jan 18 11:33:14 2012 +0100
@@ -460,6 +460,8 @@
   adding file changes
   added 1 changesets with 2 changes to 2 files (+1 heads)
   (run 'hg heads' to see heads, 'hg merge' to merge)
+  caching new largefiles
+  0 largefiles cached
   $ hg rebase
   getting changed largefiles
   1 largefiles updated, 0 removed
@@ -602,11 +604,12 @@
   searching 1 changesets for largefiles
   verified existence of 3 revisions of 3 largefiles
 
-Merging does not revert to old versions of largefiles (this has also
-been very problematic).
+Merging does not revert to old versions of largefiles and also check
+that merging after having pulled from a non-default remote works
+correctly.
 
   $ cd ..
-  $ hg clone -r 7 e f
+  $ hg clone -r 7 e temp
   adding changesets
   adding manifests
   adding file changes
@@ -615,6 +618,14 @@
   5 files updated, 0 files merged, 0 files removed, 0 files unresolved
   getting changed largefiles
   3 largefiles updated, 0 removed
+  $ hg clone temp f
+  updating to branch default
+  5 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  getting changed largefiles
+  3 largefiles updated, 0 removed
+# Delete the largefiles in the largefiles system cache so that we have an
+# opportunity to test that caching after a pull works.
+  $ rm ${USERCACHE}/*
   $ cd f
   $ echo "large4-merge-test" > sub/large4
   $ hg commit -m "Modify large4 to test merge"
@@ -628,6 +639,8 @@
   adding file changes
   added 2 changesets with 4 changes to 4 files (+1 heads)
   (run 'hg heads' to see heads, 'hg merge' to merge)
+  caching new largefiles
+  2 largefiles cached
   $ hg merge
   merging sub/large4
   largefile sub/large4 has a merge conflict


More information about the Mercurial-devel mailing list