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

login
register
mail settings
Submitter Matt Harbison
Date Jan. 8, 2018, 4:28 a.m.
Message ID <e9185c88cf15324fc5e9.1515385717@Envy>
Download mbox | patch
Permalink /patch/26604/
State Accepted, archived
Headers show

Comments

Matt Harbison - Jan. 8, 2018, 4:28 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@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
Yuya Nishihara - Jan. 8, 2018, 1:35 p.m.
On Sun, 07 Jan 2018 23:28:37 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@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)

Maybe it's okay to keep the filename in core (or alternatively add a utility
function to get back filename from indexfile path.)

I think we already have cryptic [5:] or [:-2] at several places.

Patch

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):