mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <ukleinek@strlen.de>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>,
	Ben Dooks <ben-linux@fluff.org>,
	linux-kernel@vger.kernel.org, Pavel Machek <pavel@suse.cz>,
	Randy Dunlap <rdunlap@xenotime.net>,
	Joe Perches <joe@perches.com>
Subject: [PATCH] [RFC] Add a script that searched per-file maintainers for a patch.
Date: Wed,  1 Oct 2008 14:25:54 +0200	[thread overview]
Message-ID: <1222863954-13701-1-git-send-email-ukleinek@strlen.de> (raw)
In-Reply-To: <20080929175625.GA3676@ucw.cz>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4246 bytes --]

I assume currently there are no files that have the maintainers noted in
a source file in a way that is understandable by the script, but for
testing you can use scripts/genpatchcc.py itself.  It is meant to be
used with git-send-email --cc-cmd=...

Currently the format to specify a maintainer is

	/*
	 * TOPIC
	 * P: M. Aintainer <ma@intai.ner>
	 * L: some-list@vger.kernel.org
	 */

similar to the format of the MAINTAINERS file.  This has to be specified
in the first comment of a file starting at the file's start.  #-like
comments are supported, too.

---
To test it, apply the patch, and modify scripts/genpatchcc.py.  Then you
can run:

	git diff | scripts/genpatchcc.py

I havn't tested it yet with git-send-email and there are several things
to improve as noted in the comments of the script (and probably more).
And of course some documentation is missing.

Please consider it as a first draft and feel free to comment.

Best regards
Uwe
---
 scripts/genpatchcc.py |   95 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 95 insertions(+), 0 deletions(-)
 create mode 100755 scripts/genpatchcc.py

diff --git a/scripts/genpatchcc.py b/scripts/genpatchcc.py
new file mode 100755
index 0000000..6a757ed
--- /dev/null
+++ b/scripts/genpatchcc.py
@@ -0,0 +1,95 @@
+#! /usr/bin/env python
+# vim: set fileencoding=utf-8
+# (c) Uwe Kleine-König <ukleinek@strlen.de>
+# GPLv2
+#
+# GENPATCHCC
+# P: Uwe Kleine-König <ukleinek@strlen.de>
+
+# wishlist:
+# - support for per-directory '.maintainers' file
+#   when should it be used?  Assume a/b/c/d/file was changed.  The following
+#   files could be used:
+#    * a/b/c/d/.maintainers
+#    * a/b/c/.maintainers
+#    * a/b/.maintainers
+#    * a/.maintainers
+#    * .maintainers
+#   maybe only use the first that exists?  only if the changed file doesn't
+#   have an entry?
+# - (?) option to specify the srcdir
+# - (?) parse the patch if the maintainer entry is changed, use both, old and new version
+# - (?) extract git sha1 sums and parse the objects
+
+import fileinput
+import re
+
+def filename(name):
+    if name[0] == '"':
+        raise NotImplementedError, 'please teach me how to unquote a filename'
+
+    # assume -p1
+    return name[name.index('/') + 1:]
+
+re_changedfile = re.compile(r'(?:---|\+\+\+)\s(?P<file>".*?[^\\]"|[][-^A-Za-z0-9_ !#$%&\'()*+,./:;<=>@?{}~]+)')
+
+changed_files = set()
+
+for line in fileinput.input():
+    mo = re_changedfile.match(line)
+    if mo:
+        changed_files.add(filename(mo.group('file')))
+
+def extract_maintainers(file, compre_dict, dowhile=None):
+    next = ('start', 'topic')
+    anyfield = ('person', 'ml', 'otherfield')
+    next_dict = dict(start=('topic',), topic=anyfield, person=anyfield, ml=anyfield, otherfield=anyfield)
+
+    for line in file:
+        if dowhile is not None:
+            mo = dowhile.match(line)
+            if not mo:
+                break
+
+        for possnext in next:
+            mo = compre_dict[possnext].match(line)
+            if mo:
+                for v in mo.groupdict().itervalues():
+                    print v
+                next = next_dict[possnext]
+                break
+        else:
+            mo = compre_dict['start'].match(line)
+            if mo:
+                next = next_dict['start']
+            else:
+                next = ('start',)
+
+re_dict = dict(start=r'$',
+        topic=r'\S[^:].*',
+        person=r'P:\s*(?P<person>.*)',
+        ml=r'L:\s*(?P<ml>.*)',
+        otherfield=r'(?![PL])[A-Z]:')
+
+re_comment = r'\s*(?:#|/?\*)'
+
+compre_dict = dict((key, re.compile(value)) for key, value in re_dict.iteritems())
+compre_commented_dict = dict((key, re.compile(re_comment + r'\s*' + value)) for key, value in re_dict.iteritems())
+compre_comment = re.compile(re_comment)
+
+mailto_person = set()
+mailto_ml = set()
+
+for file in changed_files:
+    # MAINTAINERS [cw]ould result in many false matches, skip it
+    # alternatively print someone?  who?
+    if file == 'MAINTAINERS':
+        continue
+
+    try:
+        of = open(file)
+    except:
+        # TODO: try harder (e.g. is the patch really -p1?)
+        continue
+
+    extract_maintainers(of, compre_commented_dict, compre_comment)
-- 
1.5.6.5


      parent reply	other threads:[~2008-10-01 12:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-07 14:54 [RFC] List of maintainers (draft #3) Denis Vlasenko
2008-09-22  8:12 ` Uwe Kleine-König
2008-09-22  9:12   ` Ben Dooks
2008-09-22  9:23     ` Pekka Enberg
2008-09-22 16:40       ` H. Peter Anvin
2008-09-22 19:42         ` Uwe Kleine-König
2008-09-23  5:10           ` Joe Perches
2008-09-29 17:56         ` Pavel Machek
2008-10-01  0:10           ` Randy Dunlap
2008-10-01  0:09             ` Joe Perches
2008-10-01  0:35               ` Randy Dunlap
2008-10-01 13:36                 ` Pavel Machek
2008-10-01 15:41                   ` Randy Dunlap
2008-10-01 12:25           ` Uwe Kleine-König [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1222863954-13701-1-git-send-email-ukleinek@strlen.de \
    --to=ukleinek@strlen.de \
    --cc=ben-linux@fluff.org \
    --cc=hpa@zytor.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@suse.cz \
    --cc=penberg@cs.helsinki.fi \
    --cc=rdunlap@xenotime.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®