diff mbox series

utils/getdeveloperlib.py: fix developer being reported for unrelated path

Message ID 20211121215713.4167839-1-ricardo.martincoski@gmail.com
State Accepted
Headers show
Series utils/getdeveloperlib.py: fix developer being reported for unrelated path | expand

Commit Message

Ricardo Martincoski Nov. 21, 2021, 9:57 p.m. UTC
Currently, by following the instructions in the manual and querying for
developers for a patch that changes path
package/foobar
the script reports both developers that have these entries in the
DEVELOPERS file:
F:	package/foo/
F:	package/foobar/

Starting from commit "afc112b0e4 utils/getdeveloperlib.py: fix issue
with hasfile()" get-developers script uses os.path.abspath() and
os.path.relpath().
The catch is that those functions return the absolute path and the
relative path without the trailing slash.

When the paths associated to a developer are then compared to the paths
a patch touches, using the string.startswith(), any substring returns
True, leading to developers for package/foo/ being wrongly reported
for package/foobar/ .

Fix this by re-adding the trailing slash after using relpath().

Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Cc: Heiko Thiery <heiko.thiery@gmail.com>
Cc: James Knight <james.d.knight@live.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
NOTICE: this change makes 'get-developers -c' to return more results.
This is expected, since i.e:
fmt has a developer
fmtools has none
jo has a developer
joe has none
openjdk has a developer
openjdk-bin has none
opentyrian has a developer
opentyrian-data has none
board/raspberrypi has a few developers
board/raspberrypi0 has none

Examples of wrong results *before* this patch:

$ ./utils/get-developers -p stress-ng
Romain Naour <romain.naour@gmail.com>
$ ./utils/get-developers -p stress
Arnout Vandecappelle <arnout@mind.be>
$ ./utils/get-developers outgoing/*-stress-ng-*.patch
git send-email --to buildroot@buildroot.org --cc "Romain Naour
<romain.naour@gmail.com>" --cc "Arnout Vandecappelle <arnout@mind.be>"

$ ./utils/get-developers -p atop
Ricardo Martincoski <ricardo.martincoski@datacom.com.br>
$ ./utils/get-developers -p at
Giulio Benetti <giulio.benetti@benettiengineering.com>
$ ./utils/get-developers outgoing/*-atop-*.patch
git send-email --to buildroot@buildroot.org --cc "Ricardo Martincoski
<ricardo.martincoski@datacom.com.br>" --cc "Giulio Benetti
<giulio.benetti@benettiengineering.com>"
---
 utils/getdeveloperlib.py | 2 ++
 1 file changed, 2 insertions(+)

Comments

Arnout Vandecappelle Dec. 11, 2021, 8:41 p.m. UTC | #1
On 21/11/2021 22:57, Ricardo Martincoski wrote:
> Currently, by following the instructions in the manual and querying for
> developers for a patch that changes path
> package/foobar
> the script reports both developers that have these entries in the
> DEVELOPERS file:
> F:	package/foo/
> F:	package/foobar/
> 
> Starting from commit "afc112b0e4 utils/getdeveloperlib.py: fix issue
> with hasfile()" get-developers script uses os.path.abspath() and
> os.path.relpath().
> The catch is that those functions return the absolute path and the
> relative path without the trailing slash.
> 
> When the paths associated to a developer are then compared to the paths
> a patch touches, using the string.startswith(), any substring returns
> True, leading to developers for package/foo/ being wrongly reported
> for package/foobar/ .
> 
> Fix this by re-adding the trailing slash after using relpath().
> 
> Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
> Cc: Heiko Thiery <heiko.thiery@gmail.com>
> Cc: James Knight <james.d.knight@live.com>
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>

  Applied to master, thanks.

  Regards,
  Arnout

> ---
> NOTICE: this change makes 'get-developers -c' to return more results.
> This is expected, since i.e:
> fmt has a developer
> fmtools has none
> jo has a developer
> joe has none
> openjdk has a developer
> openjdk-bin has none
> opentyrian has a developer
> opentyrian-data has none
> board/raspberrypi has a few developers
> board/raspberrypi0 has none
> 
> Examples of wrong results *before* this patch:
> 
> $ ./utils/get-developers -p stress-ng
> Romain Naour <romain.naour@gmail.com>
> $ ./utils/get-developers -p stress
> Arnout Vandecappelle <arnout@mind.be>
> $ ./utils/get-developers outgoing/*-stress-ng-*.patch
> git send-email --to buildroot@buildroot.org --cc "Romain Naour
> <romain.naour@gmail.com>" --cc "Arnout Vandecappelle <arnout@mind.be>"
> 
> $ ./utils/get-developers -p atop
> Ricardo Martincoski <ricardo.martincoski@datacom.com.br>
> $ ./utils/get-developers -p at
> Giulio Benetti <giulio.benetti@benettiengineering.com>
> $ ./utils/get-developers outgoing/*-atop-*.patch
> git send-email --to buildroot@buildroot.org --cc "Ricardo Martincoski
> <ricardo.martincoski@datacom.com.br>" --cc "Giulio Benetti
> <giulio.benetti@benettiengineering.com>"
> ---
>   utils/getdeveloperlib.py | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/utils/getdeveloperlib.py b/utils/getdeveloperlib.py
> index f2b36862e3..c05e1f888b 100644
> --- a/utils/getdeveloperlib.py
> +++ b/utils/getdeveloperlib.py
> @@ -247,18 +247,20 @@ def parse_developers():
>               elif line.startswith("F:"):
>                   fname = line[2:].strip()
>                   dev_files = glob.glob(os.path.join(brpath, fname))
>                   if len(dev_files) == 0:
>                       print("WARNING: '%s' doesn't match any file" % fname,
>                             file=sys.stderr)
>                   for f in dev_files:
>                       dev_file = os.path.relpath(f, brpath)
>                       dev_file = dev_file.replace(os.sep, '/')  # force unix sep
> +                    if f[-1] == '/':  # relpath removes the trailing /
> +                        dev_file = dev_file + '/'
>                       files.append(dev_file)
>               elif line == "":
>                   if not name:
>                       continue
>                   developers.append(Developer(name, files))
>                   files = []
>                   name = None
>               else:
>                   print("Syntax error in DEVELOPERS file, line %d: '%s'" % (linen, line),
>
Peter Korsgaard Jan. 14, 2022, 4:37 p.m. UTC | #2
>>>>> "Ricardo" == Ricardo Martincoski <ricardo.martincoski@gmail.com> writes:

 > Currently, by following the instructions in the manual and querying for
 > developers for a patch that changes path
 > package/foobar
 > the script reports both developers that have these entries in the
 > DEVELOPERS file:
 > F:	package/foo/
 > F:	package/foobar/

 > Starting from commit "afc112b0e4 utils/getdeveloperlib.py: fix issue
 > with hasfile()" get-developers script uses os.path.abspath() and
 > os.path.relpath().
 > The catch is that those functions return the absolute path and the
 > relative path without the trailing slash.

 > When the paths associated to a developer are then compared to the paths
 > a patch touches, using the string.startswith(), any substring returns
 > True, leading to developers for package/foo/ being wrongly reported
 > for package/foobar/ .

 > Fix this by re-adding the trailing slash after using relpath().

 > Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
 > Cc: Heiko Thiery <heiko.thiery@gmail.com>
 > Cc: James Knight <james.d.knight@live.com>
 > Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>

Committed to 2021.02.x and 2021.11.x, thanks.
diff mbox series

Patch

diff --git a/utils/getdeveloperlib.py b/utils/getdeveloperlib.py
index f2b36862e3..c05e1f888b 100644
--- a/utils/getdeveloperlib.py
+++ b/utils/getdeveloperlib.py
@@ -247,18 +247,20 @@  def parse_developers():
             elif line.startswith("F:"):
                 fname = line[2:].strip()
                 dev_files = glob.glob(os.path.join(brpath, fname))
                 if len(dev_files) == 0:
                     print("WARNING: '%s' doesn't match any file" % fname,
                           file=sys.stderr)
                 for f in dev_files:
                     dev_file = os.path.relpath(f, brpath)
                     dev_file = dev_file.replace(os.sep, '/')  # force unix sep
+                    if f[-1] == '/':  # relpath removes the trailing /
+                        dev_file = dev_file + '/'
                     files.append(dev_file)
             elif line == "":
                 if not name:
                     continue
                 developers.append(Developer(name, files))
                 files = []
                 name = None
             else:
                 print("Syntax error in DEVELOPERS file, line %d: '%s'" % (linen, line),