[PATCH 1 of 3 RFC] lfs: add a function to get the user visible filename for a revlog

Matt Harbison mharbison72 at gmail.com
Fri Dec 29 21:43:22 UTC 2017


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1514408916 18000
#      Wed Dec 27 16:08:36 2017 -0500
# Node ID 3bd34c256588b974f8bc2064bf1873a81f2326b9
# Parent  95a9be56c3bb614fc1334a4cc8ec669f9eb7bc5a
lfs: add a function to get the user visible filename for a revlog

This improves an error message, and will be useful for matching on more
attributes than just the file size.

I don't see any instances where a revlog is created without an index file, but
kept the safe access anyway.  On that note, the previous code unconditionally
set 'p.filename'.  That potentially made the attribute None, and would be
printed as such in _gitlfsremote._checkforservererror() instead of "unknown".

The test modified here apparently only runs within Facebook, but a print
statement confirmed the name change.

diff --git a/hgext/lfs/wrapper.py b/hgext/lfs/wrapper.py
--- a/hgext/lfs/wrapper.py
+++ b/hgext/lfs/wrapper.py
@@ -49,6 +49,16 @@
 def bypasscheckhash(self, text):
     return False
 
+def _getfilename(revlog):
+    """Return the user-visible file name, given the indexfile name."""
+    filename = getattr(revlog, 'indexfile', None)
+    if not filename:
+        return None
+
+    prefixlen = len("data/")
+    suffixlen = len(".i")
+    return filename[prefixlen:-suffixlen]
+
 def readfromstore(self, text):
     """Read filelog content from local blobstore transform for flagprocessor.
 
@@ -60,7 +70,9 @@
     oid = p.oid()
     store = self.opener.lfslocalblobstore
     if not store.has(oid):
-        p.filename = getattr(self, 'indexfile', None)
+        filename = _getfilename(self)
+        if filename:
+            p.filename = filename
         self.opener.lfsremoteblobstore.readbatch([p], store)
 
     # The caller will validate the content
diff --git a/tests/test-lfs-test-server.t b/tests/test-lfs-test-server.t
--- a/tests/test-lfs-test-server.t
+++ b/tests/test-lfs-test-server.t
@@ -182,7 +182,7 @@
   $ rm -rf `hg config lfs.usercache`
   $ hg --config 'lfs.url=https://dewey-lfs.vip.facebook.com/lfs' clone test test2
   updating to branch default
-  abort: LFS server error. Remote object for file data/a.i not found:(.*)! (re)
+  abort: LFS server error. Remote object for file a not found:(.*)! (re)
   [255]
 
   $ $PYTHON $RUNTESTDIR/killdaemons.py $DAEMON_PIDS


More information about the Mercurial-devel mailing list