Patchwork [2,of,3] largefiles: refactor _usercachedir() to allow reuse with lfs

login
register
mail settings
Submitter Matt Harbison
Date Dec. 7, 2017, 5:29 a.m.
Message ID <e5797615fbb18b4e73a9.1512624547@Envy>
Download mbox | patch
Permalink /patch/25988/
State Accepted
Headers show

Comments

Matt Harbison - Dec. 7, 2017, 5:29 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1512533339 18000
#      Tue Dec 05 23:08:59 2017 -0500
# Node ID e5797615fbb18b4e73a9d413694fc346c6f19378
# Parent  a7be2d8c84f3c039d1be507328b04bfd89f2901f
largefiles: refactor _usercachedir() to allow reuse with lfs

Largefiles puts everything into a flat directory, while lfs divides files up by
creating subdirectories consisting of the first two characters of the hash.
Therefore, pointing at the largefiles cache won't work.

Patch

diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -69,31 +69,31 @@ 
     to preserve download bandwidth and storage space.'''
     return os.path.join(_usercachedir(ui), hash)
 
-def _usercachedir(ui):
+def _usercachedir(ui, name=longname):
     '''Return the location of the "global" largefiles cache.'''
-    path = ui.configpath(longname, 'usercache')
+    path = ui.configpath(name, 'usercache')
     if path:
         return path
     if pycompat.iswindows:
         appdata = encoding.environ.get('LOCALAPPDATA',\
                         encoding.environ.get('APPDATA'))
         if appdata:
-            return os.path.join(appdata, longname)
+            return os.path.join(appdata, name)
     elif pycompat.isdarwin:
         home = encoding.environ.get('HOME')
         if home:
-            return os.path.join(home, 'Library', 'Caches', longname)
+            return os.path.join(home, 'Library', 'Caches', name)
     elif pycompat.isposix:
         path = encoding.environ.get('XDG_CACHE_HOME')
         if path:
-            return os.path.join(path, longname)
+            return os.path.join(path, name)
         home = encoding.environ.get('HOME')
         if home:
-            return os.path.join(home, '.cache', longname)
+            return os.path.join(home, '.cache', name)
     else:
         raise error.Abort(_('unknown operating system: %s\n')
                           % pycompat.osname)
-    raise error.Abort(_('unknown %s usercache location') % longname)
+    raise error.Abort(_('unknown %s usercache location') % name)
 
 def inusercache(ui, hash):
     path = usercachepath(ui, hash)