Patchwork [9,of,9] check-code: examine magic pattern matching against contents of a file

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Feb. 10, 2016, 1:58 p.m.
Message ID <3e62bb5a87080dea69d2.1455112727@feefifofum>
Download mbox | patch
Permalink /patch/13097/
State Accepted
Delegated to: Martin von Zweigbergk
Headers show

Comments

Katsunori FUJIWARA - Feb. 10, 2016, 1:58 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1455111869 -32400
#      Wed Feb 10 22:44:29 2016 +0900
# Node ID 3e62bb5a87080dea69d291a68456622cbb6d8702
# Parent  f17178eff48f064225d89a7eb351220b6ccd1ef0
check-code: examine magic pattern matching against contents of a file

Before this patch, check-code examines "magic" pattern (e.g.
'^#!.*python') matching against not contents of a file, but name of
it.

This unintentionally omits code checking against Python source file,
of which filename doesn't end with "*.py" or "*.cgi", even though
contents of it starts with "#!/bin/python" or so.

In this change, 'pre' refers contents of file 'f'.
timeless - Feb. 10, 2016, 4:19 p.m.
fwiw, this series looks good to me, and I'm sorry since about half of
it is my fault :/

On Wed, Feb 10, 2016 at 8:58 AM, FUJIWARA Katsunori
<foozy@lares.dti.ne.jp> wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1455111869 -32400
> #      Wed Feb 10 22:44:29 2016 +0900
> # Node ID 3e62bb5a87080dea69d291a68456622cbb6d8702
> # Parent  f17178eff48f064225d89a7eb351220b6ccd1ef0
> check-code: examine magic pattern matching against contents of a file
>
> Before this patch, check-code examines "magic" pattern (e.g.
> '^#!.*python') matching against not contents of a file, but name of
> it.
>
> This unintentionally omits code checking against Python source file,
> of which filename doesn't end with "*.py" or "*.cgi", even though
> contents of it starts with "#!/bin/python" or so.
>
> In this change, 'pre' refers contents of file 'f'.
>
> diff --git a/contrib/check-code.py b/contrib/check-code.py
> --- a/contrib/check-code.py
> +++ b/contrib/check-code.py
> @@ -475,7 +475,7 @@ def checkfile(f, logfunc=_defaultlogger.
>          if debug:
>              print name, f
>          fc = 0
> -        if not (re.match(match, f) or (magic and re.search(magic, f))):
> +        if not (re.match(match, f) or (magic and re.search(magic, pre))):
>              if debug:
>                  print "Skipping %s for %s it doesn't match %s" % (
>                         name, match, f)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Martin von Zweigbergk - Feb. 10, 2016, 10:07 p.m.
On Wed, Feb 10, 2016 at 8:19 AM, timeless <timeless@gmail.com> wrote:
> fwiw, this series looks good to me, and I'm sorry since about half of
> it is my fault :/

Looks good to me too. Pushed to the clowncopter.

Patch

diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -475,7 +475,7 @@  def checkfile(f, logfunc=_defaultlogger.
         if debug:
             print name, f
         fc = 0
-        if not (re.match(match, f) or (magic and re.search(magic, f))):
+        if not (re.match(match, f) or (magic and re.search(magic, pre))):
             if debug:
                 print "Skipping %s for %s it doesn't match %s" % (
                        name, match, f)