[PATCH 4 of 4] largefiles: make the store primary, and the user cache secondary

Benjamin Pollack benjamin at bitquabit.com
Thu Oct 20 12:24:58 CDT 2011


# HG changeset patch
# User Benjamin Pollack <benjamin at bitquabit.com>
# Date 1319131451 14400
# Branch stable
# Node ID 6a5af6f372abd8ed1bd535d1534511a2208efc6d
# Parent  d38c5c99400183f9c52f7b1aed9581aec5517d26
largefiles: make the store primary, and the user cache secondary

This uses the now-properly-named functions and methods from the previous
patch to actually deliver the desired behavior

diff --git a/hgext/largefiles/lfcommands.py b/hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py
+++ b/hgext/largefiles/lfcommands.py
@@ -336,9 +336,7 @@
 def uploadlfiles(ui, rsrc, rdst, files):
     '''upload largefiles to the central store'''
 
-    # Don't upload locally. All largefiles are in the system wide cache
-    # so the other repo can just get them from there.
-    if not files or rdst.local():
+    if not files:
         return
 
     store = basestore._openstore(rsrc, rdst, put=True)
diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -100,11 +100,12 @@
 def findfile(repo, hash):
     if instore(repo, hash):
         repo.ui.note(_('Found %s in store\n') % hash)
-        return storepath(repo, hash)
-    if inusercache(repo.ui, hash):
+    elif inusercache(repo.ui, hash):
         repo.ui.note(_('Found %s in system cache\n') % hash)
-        return usercachepath(repo.ui, hash)
-    return None
+        link(usercachepath(repo.ui, hash), storepath(repo, hash))
+    else:
+        return None
+    return storepath(repo, hash)
 
 class largefiles_dirstate(dirstate.dirstate):
     def __getitem__(self, key):
diff --git a/hgext/largefiles/localstore.py b/hgext/largefiles/localstore.py
--- a/hgext/largefiles/localstore.py
+++ b/hgext/largefiles/localstore.py
@@ -17,27 +17,38 @@
 import basestore
 
 class localstore(basestore.basestore):
-    '''Because there is a system-wide cache, the local store always
-    uses that cache. Since the cache is updated elsewhere, we can
-    just read from it here as if it were the store.'''
+    '''localstore first attempts to grab files out of the store in the remote
+    Mercurial repository.  Failling that, it attempts to grab the files from
+    the user cache.'''
 
     def __init__(self, ui, repo, remote):
         url = os.path.join(remote.path, '.hg', lfutil.longname)
         super(localstore, self).__init__(ui, repo, util.expandpath(url))
+        self.remote = remote
 
-    def put(self, source, filename, hash):
-        '''Any file that is put must already be in the system-wide
-        cache so do nothing.'''
-        return
+    def put(self, source, hash):
+        lfutil.createdir(os.path.dirname(lfutil.storepath(self.remote, hash)))
+        if lfutil.instore(self.remote, hash):
+            return
+        lfutil.link(lfutil.storepath(self.repo, hash),
+                lfutil.storepath(self.remote, hash))
 
     def exists(self, hash):
-        return lfutil.inusercache(self.repo.ui, hash)
+        return lfutil.instore(self.remote, hash)
 
     def _getfile(self, tmpfile, filename, hash):
-        if lfutil.inusercache(self.ui, hash):
-            return lfutil.usercachepath(self.ui, hash)
-        raise basestore.StoreError(filename, hash, '',
-            _("Can't get file locally"))
+        if lfutil.instore(self.remote, hash):
+            path = lfutil.storepath(self.remote, hash)
+        elif lfutil.inusercache(self.ui, hash):
+            path = lfutil.usercachepath(self.ui, hash)
+        else:
+            raise basestore.StoreError(filename, hash, '',
+                _("Can't get file locally"))
+        fd = open(path, 'rb')
+        try:
+            return lfutil.copyandhash(fd, tmpfile)
+        finally:
+            fd.close()
 
     def _verifyfile(self, cctx, cset, contents, standin, verified):
         filename = lfutil.splitstandin(standin)
@@ -50,7 +61,7 @@
 
         expecthash = fctx.data()[0:40]
         verified.add(key)
-        if not lfutil.inusercache(self.ui, expecthash):
+        if not lfutil.instore(self.remote, expecthash):
             self.ui.warn(
                 _('changeset %s: %s missing\n'
                   '  (looked for hash %s)\n')
@@ -58,7 +69,7 @@
             return True                 # failed
 
         if contents:
-            storepath = lfutil.usercachepath(self.ui, expecthash)
+            storepath = lfutil.storepath(self.remote, expecthash)
             actualhash = lfutil.hashfile(storepath)
             if actualhash != expecthash:
                 self.ui.warn(
diff --git a/hgext/largefiles/proto.py b/hgext/largefiles/proto.py
--- a/hgext/largefiles/proto.py
+++ b/hgext/largefiles/proto.py
@@ -17,8 +17,8 @@
                            'file.\n')
 
 def putlfile(repo, proto, sha):
-    '''Put a largefile into a repository's local cache and into the
-    system cache.'''
+    '''Put a largefile into a repository's local store and into the
+    user cache.'''
     f = None
     proto.redirect()
     try:


More information about the Mercurial-devel mailing list