Patchwork D8145: lfutil: provide a hint if the largefiles/lfs cache path cannot be determined

login
register
mail settings
Submitter phabricator
Date Feb. 24, 2020, 10:47 p.m.
Message ID <differential-rev-PHID-DREV-w2h4nbe3qsyvljtv6jcf-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45306/
State Superseded
Headers show

Comments

phabricator - Feb. 24, 2020, 10:47 p.m.
mharbison72 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  A coworker hit this error using an LFS repo in a stripped down environment, and
  didn't know how to resolve it.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8145

AFFECTED FILES
  hgext/largefiles/lfutil.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-devel
phabricator - Feb. 24, 2020, 11:37 p.m.
marmoute added a comment.


  Could we get a test for this? To make sure the hint looks fine and that the error code does not crash ?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8145/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8145

To: mharbison72, #hg-reviewers
Cc: marmoute, mercurial-devel
phabricator - Feb. 24, 2020, 11:52 p.m.
mharbison72 added a comment.


  In D8145#121269 <https://phab.mercurial-scm.org/D8145#121269>, @marmoute wrote:
  
  > Could we get a test for this? To make sure the hint looks fine and that the error code does not crash ?
  
  The reason I didn't add a test (or see any changes to existing ones) is because the config property is baked into the config file generated by run-tests.py, so it never hits this path.  But I did test by hand on Windows.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8145/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8145

To: mharbison72, #hg-reviewers
Cc: marmoute, mercurial-devel
phabricator - Feb. 25, 2020, 12:07 a.m.
marmoute added a comment.


  In D8145#121270 <https://phab.mercurial-scm.org/D8145#121270>, @mharbison72 wrote:
  
  > In D8145#121269 <https://phab.mercurial-scm.org/D8145#121269>, @marmoute wrote:
  >
  >> Could we get a test for this? To make sure the hint looks fine and that the error code does not crash ?
  >
  > The reason I didn't add a test (or see any changes to existing ones) is because the config property is baked into the config file generated by run-tests.py, so it never hits this path.  But I did test by hand on Windows.
  
  Could we alter that config in test file to trigger the error in there ?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8145/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8145

To: mharbison72, #hg-reviewers
Cc: marmoute, mercurial-devel
phabricator - Feb. 25, 2020, 8:46 a.m.
marmoute added a comment.
marmoute accepted this revision.


  Thanks for adding the test.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8145/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8145

To: mharbison72, #hg-reviewers, marmoute
Cc: marmoute, mercurial-devel
phabricator - Feb. 25, 2020, 12:49 p.m.
pulkit added a comment.


  test-check-code.t says hi:
  
    --- /home/foobar/repo/pushaccess/tests/test-check-code.t
    +++ /home/foobar/repo/pushaccess/tests/test-check-code.t.err
    @@ -32,6 +32,16 @@
       Skipping i18n/polib.py it has no-che?k-code (glob)
       Skipping mercurial/statprof.py it has no-che?k-code (glob)
       Skipping tests/badserverext.py it has no-che?k-code (glob)
    +  tests/test-lfs-bundle.t:102:
    +   >   $ env -u HOME -u LOCALAPPDATA -u APPDATA HGRCPATH= hg config lfs --debug
    +   don't use 'env -u VAR', use 'unset VAR'
    +  tests/test-lfs-bundle.t:109:
    +   >   $ env -u HOME HGRCPATH= hg config lfs --debug
    +   don't use 'env -u VAR', use 'unset VAR'
    +  tests/test-lfs-bundle.t:116:
    +   >   $ env -u XDG_CACHE_HOME -u HOME HGRCPATH= hg config lfs --debug
    +   don't use 'env -u VAR', use 'unset VAR'
    +  [1]
     
     @commands in debugcommands.py should be in alphabetical order.
     
    
    ERROR: test-check-code.t output changed

REPOSITORY
  rHG Mercurial

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8145/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8145

To: mharbison72, #hg-reviewers, marmoute, pulkit
Cc: marmoute, mercurial-devel

Patch

diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -92,16 +92,30 @@ 
     path = ui.configpath(name, b'usercache')
     if path:
         return path
+
+    hint = None
+
     if pycompat.iswindows:
         appdata = encoding.environ.get(
             b'LOCALAPPDATA', encoding.environ.get(b'APPDATA')
         )
         if appdata:
             return os.path.join(appdata, name)
+
+        hint = _(b"define %s or %s in the environment, or set %s.usercache") % (
+            b"LOCALAPPDATA",
+            b"APPDATA",
+            name,
+        )
     elif pycompat.isdarwin:
         home = encoding.environ.get(b'HOME')
         if home:
             return os.path.join(home, b'Library', b'Caches', name)
+
+        hint = _(b"define %s in the environment, or set %s.usercache") % (
+            b"HOME",
+            name,
+        )
     elif pycompat.isposix:
         path = encoding.environ.get(b'XDG_CACHE_HOME')
         if path:
@@ -109,11 +123,18 @@ 
         home = encoding.environ.get(b'HOME')
         if home:
             return os.path.join(home, b'.cache', name)
+
+        hint = _(b"define %s or %s in the environment, or set %s.usercache") % (
+            b"XDG_CACHE_HOME",
+            b"HOME",
+            name,
+        )
     else:
         raise error.Abort(
             _(b'unknown operating system: %s\n') % pycompat.osname
         )
-    raise error.Abort(_(b'unknown %s usercache location') % name)
+
+    raise error.Abort(_(b'unknown %s usercache location') % name, hint=hint)
 
 
 def inusercache(ui, hash):