Patchwork [2,of,8] localrepo: debug log of filter name when filtering through a function

login
register
mail settings
Submitter Mads Kiilerich
Date Oct. 14, 2019, 12:13 a.m.
Message ID <2b91375a812ce3c694ef.1571012016@xps>
Download mbox | patch
Permalink /patch/42303/
State Accepted
Headers show

Comments

Mads Kiilerich - Oct. 14, 2019, 12:13 a.m.
# HG changeset patch
# User Mads Kiilerich <mads@kiilerich.com>
# Date 1570970400 -7200
#      Sun Oct 13 14:40:00 2019 +0200
# Node ID 2b91375a812ce3c694efa35a98a1777709387962
# Parent  57f88532f7005eeb13cb06418ae3a3b156085adf
localrepo: debug log of filter name when filtering through a function
Yuya Nishihara - Oct. 14, 2019, 4:12 a.m.
On Mon, 14 Oct 2019 02:13:36 +0200, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <mads@kiilerich.com>
> # Date 1570970400 -7200
> #      Sun Oct 13 14:40:00 2019 +0200
> # Node ID 2b91375a812ce3c694efa35a98a1777709387962
> # Parent  57f88532f7005eeb13cb06418ae3a3b156085adf
> localrepo: debug log of filter name when filtering through a function

> @@ -1907,7 +1909,8 @@ class localrepository(object):
>      def _filter(self, filterpats, filename, data):
>          for mf, fn, cmd in filterpats:
>              if mf(filename):
> -                self.ui.debug(b"filtering %s through %s\n" % (filename, cmd))
> +                self.ui.debug(b"filtering %s through %s\n" %
> +                              (filename, cmd or pycompat.bytestr(fn.__name__)))

Nit: changed pycompat.bytestr() to pycompat.sysbytes() in flight.
Function names should be ascii in general, but that isn't guaranteed.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1896,10 +1896,12 @@  class localrepository(object):
                         break
                 if not fn:
                     fn = lambda s, c, **kwargs: procutil.filter(s, c)
+                    fn.__name__ = 'commandfilter'
                 # Wrap old filters not supporting keyword arguments
                 if not pycompat.getargspec(fn)[2]:
                     oldfn = fn
                     fn = lambda s, c, **kwargs: oldfn(s, c)
+                    fn.__name__ = 'compat-' + oldfn.__name__
                 l.append((mf, fn, params))
             self._filterpats[filter] = l
         return self._filterpats[filter]
@@ -1907,7 +1909,8 @@  class localrepository(object):
     def _filter(self, filterpats, filename, data):
         for mf, fn, cmd in filterpats:
             if mf(filename):
-                self.ui.debug(b"filtering %s through %s\n" % (filename, cmd))
+                self.ui.debug(b"filtering %s through %s\n" %
+                              (filename, cmd or pycompat.bytestr(fn.__name__)))
                 data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
                 break
 
diff --git a/tests/test-eol-update.t b/tests/test-eol-update.t
--- a/tests/test-eol-update.t
+++ b/tests/test-eol-update.t
@@ -187,21 +187,21 @@  from tip ... which evidently is wrong:
   calling hook preupdate.eol: hgext.eol.preupdate
    .hgeol: remote created -> g
   getting .hgeol
-  filtering .hgeol through 
+  filtering .hgeol through compat-isbinary
    a.txt: remote created -> g
   getting a.txt
-  filtering a.txt through 
+  filtering a.txt through tolf
    f: remote created -> g
   getting f
-  filtering f through 
+  filtering f through tolf
   3 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg st
   M f
   $ touch .hgeol *  # ensure consistent dirtyness checks ignoring dirstate
   $ hg up -C -r 0 -v --debug
   eol: detected change in .hgeol
-  filtering .hgeol through 
-  filtering a.txt through 
+  filtering .hgeol through compat-isbinary
+  filtering a.txt through tolf
   resolving manifests
    branchmerge: False, force: True, partial: False
    ancestor: 15cbdf8ca3db+, local: 15cbdf8ca3db+, remote: 15cbdf8ca3db
@@ -263,20 +263,20 @@  for f in revision 0, and it thus ends up
   calling hook preupdate.eol: hgext.eol.preupdate
    .hgeol: remote is newer -> g
   getting .hgeol
-  filtering .hgeol through 
+  filtering .hgeol through compat-isbinary
    a.txt: remote is newer -> g
   getting a.txt
-  filtering a.txt through 
+  filtering a.txt through tolf
    f: remote is newer -> g
   getting f
-  filtering f through 
+  filtering f through tolf
   3 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
   $ touch .hgeol *
   $ hg st --debug
   eol: detected change in .hgeol
-  filtering .hgeol through 
-  filtering a.txt through 
+  filtering .hgeol through compat-isbinary
+  filtering a.txt through tolf
   M f
   $ hg diff
   diff --git a/f b/f
@@ -291,8 +291,8 @@  Workaround: Update again - this will rea
   $ touch .hgeol *
   $ hg up -C -r 0 -v --debug
   eol: detected change in .hgeol
-  filtering .hgeol through 
-  filtering a.txt through 
+  filtering .hgeol through compat-isbinary
+  filtering a.txt through tolf
   resolving manifests
    branchmerge: False, force: True, partial: False
    ancestor: 15cbdf8ca3db+, local: 15cbdf8ca3db+, remote: 15cbdf8ca3db
@@ -304,8 +304,8 @@  Workaround: Update again - this will rea
   $ touch .hgeol *
   $ hg st --debug
   eol: detected change in .hgeol
-  filtering .hgeol through 
-  filtering a.txt through 
+  filtering .hgeol through compat-isbinary
+  filtering a.txt through tolf
 
   $ cd ..