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

mail settings
Submitter Matt Harbison
Date Dec. 29, 2017, 9:43 p.m.
Message ID <3bd34c256588b974f8bc.1514583802@Envy>
Download mbox | patch
Permalink /patch/26498/
State RFC, archived
Headers show


Matt Harbison - Dec. 29, 2017, 9:43 p.m.
# HG changeset patch
# User Matt Harbison <>
# 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/ b/hgext/lfs/
--- a/hgext/lfs/
+++ b/hgext/lfs/
@@ -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=' 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)