[PATCH 02/10] parser: Add patch_get_filenames()

Mauro Carvalho Chehab mchehab at osg.samsung.com
Sat Nov 28 23:14:38 AEDT 2015


From: Laurent Pinchart <laurent.pinchart at 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 at ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab at 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
+
 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))
-- 
2.5.0



More information about the Patchwork mailing list