[PATCH 2 of 3] largefiles: drop partial support for not having a user cache

Mads Kiilerich mads at kiilerich.com
Sat Mar 19 11:28:38 EDT 2016


# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1458401274 25200
#      Sat Mar 19 08:27:54 2016 -0700
# Node ID 0889791def23cfaabfa61559162914c21d4f0d86
# Parent  91af18ff7988b8e8b624e532266f9501a464485f
largefiles: drop partial support for not having a user cache

971c55ce03b8 introduced support for not having a "global" user cache.
In the rare cases where the environment didn't provide the location of the
current home directory, the usercachepath function could return None.
That functionality has since bitrotten and several code paths did not correctly
check for usercachepath returning None:

  $ HOME= XDG_CACHE_HOME= hg up --config extensions.largefiles=
  getting changed largefiles
  abort: unknown largefiles usercache location

Dropping the partial support for it is thus not really a backward compatibility
breaking change.

Thus: consistently fail early if the usercache location is unknown.

It is relevant to be able to control where the largefiles are stored and how
they propagate, but that should probably be done differently. The dysfunctional
code just gets in the way.

diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -55,10 +55,7 @@ def usercachepath(ui, hash):
     with the given hash.
     This cache is used for sharing of largefiles across repositories - both
     to preserve download bandwidth and storage space.'''
-    path = _usercachedir(ui)
-    if path:
-        return os.path.join(path, hash)
-    return None
+    return os.path.join(_usercachedir(ui), hash)
 
 def _usercachedir(ui):
     '''Return the location of the "global" largefiles cache.'''
@@ -82,11 +79,11 @@ def _usercachedir(ui):
             return os.path.join(home, '.cache', longname)
     else:
         raise error.Abort(_('unknown operating system: %s\n') % os.name)
-    return None
+    raise error.Abort(_('unknown %s usercache location\n') % longname)
 
 def inusercache(ui, hash):
     path = usercachepath(ui, hash)
-    return path and os.path.exists(path)
+    return os.path.exists(path)
 
 def findfile(repo, hash):
     path, exists = findstorepath(repo, hash)
@@ -260,8 +257,7 @@ def copytostoreabsolute(repo, file, hash
 
 def linktousercache(repo, hash):
     path = usercachepath(repo.ui, hash)
-    if path:
-        link(storepath(repo, hash), path)
+    link(storepath(repo, hash), path)
 
 def getstandinmatcher(repo, rmatcher=None):
     '''Return a match object that applies rmatcher to the standin directory'''


More information about the Mercurial-devel mailing list