diff mbox

[02/10] parser: Add patch_get_filenames()

Message ID 1448712886-3221-3-git-send-email-mchehab@osg.samsung.com
State Accepted
Delegated to: Stephen Finucane
Headers show

Commit Message

Mauro Carvalho Chehab Nov. 28, 2015, 12:14 p.m. UTC
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

The function returns the list of files touched by a patch, after
stripping the leading component of the path name.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 patchwork/parser.py | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

Comments

Stephen Finucane Jan. 6, 2016, 5:12 p.m. UTC | #1
On 28 Nov 10:14, Mauro Carvalho Chehab wrote:
> From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> The function returns the list of files touched by a patch, after
> stripping the leading component of the path name.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> ---
>  patchwork/parser.py | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/patchwork/parser.py b/patchwork/parser.py
> index 13b4466a4b14..2dbbf2b7b667 100644
> --- a/patchwork/parser.py
> +++ b/patchwork/parser.py
> @@ -238,6 +238,34 @@ def extract_tags(content, tags):
>  
>      return counts
>  
> +def patch_get_filenames(str):
> +    # normalise spaces
> +    str = str.replace('\r', '')
> +    str = str.strip() + '\n'
> +
> +    filenames = {}
> +
> +    for line in str.split('\n'):
> +
> +        if len(line) <= 0:
> +            continue
> +
> +        filename_match = _filename_re.match(line)
> +        if not filename_match:
> +            continue
> +
> +        filename = filename_match.group(2)
> +        if filename.startswith('/dev/null'):
> +            continue
> +
> +        filename = '/'.join(filename.split('/')[1:])
> +        filenames[filename] = True
> +
> +    filenames = filenames.keys()
> +    filenames.sort()
> +
> +    return filenames

This function needs unit tests. Other than that I'm happy with this.

Stephen
Stephen Finucane Jan. 19, 2016, 9:19 p.m. UTC | #2
On 06 Jan 17:12, Finucane, Stephen wrote:
> On 28 Nov 10:14, Mauro Carvalho Chehab wrote:
> > From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > 
> > The function returns the list of files touched by a patch, after
> > stripping the leading component of the path name.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > ---
> >  patchwork/parser.py | 34 ++++++++++++++++++++++++++++++++++
> >  1 file changed, 34 insertions(+)
> > 
> > diff --git a/patchwork/parser.py b/patchwork/parser.py
> > index 13b4466a4b14..2dbbf2b7b667 100644
> > --- a/patchwork/parser.py
> > +++ b/patchwork/parser.py
> > @@ -238,6 +238,34 @@ def extract_tags(content, tags):
> >  
> >      return counts
> >  
> > +def patch_get_filenames(str):
> > +    # normalise spaces
> > +    str = str.replace('\r', '')
> > +    str = str.strip() + '\n'
> > +
> > +    filenames = {}
> > +
> > +    for line in str.split('\n'):
> > +
> > +        if len(line) <= 0:
> > +            continue
> > +
> > +        filename_match = _filename_re.match(line)
> > +        if not filename_match:
> > +            continue
> > +
> > +        filename = filename_match.group(2)
> > +        if filename.startswith('/dev/null'):
> > +            continue
> > +
> > +        filename = '/'.join(filename.split('/')[1:])
> > +        filenames[filename] = True
> > +
> > +    filenames = filenames.keys()
> > +    filenames.sort()
> > +
> > +    return filenames
> 
> This function needs unit tests. Other than that I'm happy with this.
> 
> Stephen

Actually, none of this file is explicitly unit tested. That should
probably be fixed but for now the tests added later cover this code.

Merged.
diff mbox

Patch

diff --git a/patchwork/parser.py b/patchwork/parser.py
index 13b4466a4b14..2dbbf2b7b667 100644
--- a/patchwork/parser.py
+++ b/patchwork/parser.py
@@ -238,6 +238,34 @@  def extract_tags(content, tags):
 
     return counts
 
+def patch_get_filenames(str):
+    # normalise spaces
+    str = str.replace('\r', '')
+    str = str.strip() + '\n'
+
+    filenames = {}
+
+    for line in str.split('\n'):
+
+        if len(line) <= 0:
+            continue
+
+        filename_match = _filename_re.match(line)
+        if not filename_match:
+            continue
+
+        filename = filename_match.group(2)
+        if filename.startswith('/dev/null'):
+            continue
+
+        filename = '/'.join(filename.split('/')[1:])
+        filenames[filename] = True
+
+    filenames = filenames.keys()
+    filenames.sort()
+
+    return filenames
+
 def main(args):
     from optparse import OptionParser
 
@@ -248,6 +276,8 @@  def main(args):
             dest = 'print_comment', help = 'print parsed comment')
     parser.add_option('-#', '--hash', action = 'store_true',
             dest = 'print_hash', help = 'print patch hash')
+    parser.add_option('-f', '--filenames', action = 'store_true',
+            dest = 'print_filenames', help = 'print file names')
 
     (options, args) = parser.parse_args()
 
@@ -265,6 +295,10 @@  def main(args):
     if options.print_comment and comment:
         print "Comment: ----\n" + comment
 
+    if options.print_filenames:
+        filenames = patch_get_filenames(content)
+        print "File names: ----\n" + '\n'.join(filenames)
+
 if __name__ == '__main__':
     import sys
     sys.exit(main(sys.argv))