[PATCH 1 of 2] lfs: capture the file name when creating a filelog

Matt Harbison mharbison72 at gmail.com
Mon Jan 8 04:28:37 UTC 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1515355319 18000
#      Sun Jan 07 15:01:59 2018 -0500
# Node ID e9185c88cf15324fc5e9b590dbb415f07f6d4f18
# Parent  a774180955300dc73a9cabdc23238813faa61e3e
lfs: capture the file name when creating a filelog

This will be useful when matching file names, as well as when they need to be
displayed on error.  The code is from Jun Wu's larger series that matches on
more than just the size[1].

[1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-December/109388.html

diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py
--- a/hgext/lfs/__init__.py
+++ b/hgext/lfs/__init__.py
@@ -143,6 +143,7 @@
 def wrapfilelog(filelog):
     wrapfunction = extensions.wrapfunction
 
+    wrapfunction(filelog, '__init__', wrapper.fileloginit)
     wrapfunction(filelog, 'addrevision', wrapper.filelogaddrevision)
     wrapfunction(filelog, 'renamed', wrapper.filelogrenamed)
     wrapfunction(filelog, 'size', wrapper.filelogsize)
diff --git a/hgext/lfs/wrapper.py b/hgext/lfs/wrapper.py
--- a/hgext/lfs/wrapper.py
+++ b/hgext/lfs/wrapper.py
@@ -120,6 +120,11 @@
     flags = rlog.flags(rev)
     return bool(flags & revlog.REVIDX_EXTSTORED)
 
+def fileloginit(orig, self, opener, path, *args, **kwargs):
+    # record filename so it can be displayed or used for matching
+    self.filename = path
+    orig(self, opener, path, *args, **kwargs)
+
 def filelogaddrevision(orig, self, text, transaction, link, p1, p2,
                        cachedelta=None, node=None,
                        flags=revlog.REVIDX_DEFAULT_FLAGS, **kwds):


More information about the Mercurial-devel mailing list