Senthil Kumaran S <senthil@collab.net> writes:
> I am attaching a patch along with this mail, which is a new version of
> gnuify-changelog in python which accepts COMMITTERS file as input and
> generates GNU style ChangeLog file from svn log.
>
> PS: This patch is a modified version of gnuify-changelog.pl in python.
Thanks! May I suggest some changes:
1. Make it take the COMMITTERS file as an -C option argument, like
http://svn.collab.net/repos/svn/trunk/tools/dev/contribulyze.py
does.
2. Use the "if __name__ == '__main__':" convention, as the above
script does, so the new script can be used as a module later.
3. You may wish to see process_committers() in the other script as
an example of how to do things in an object-creating way (instead
of creating two separate dicts). I'm not sure it's time to
create a library for processing COMMITTERS-style files, but at
least the two scripts can share code and refer to each other, for
the time being.
2. When you resubmit, just attach the whole script, either inline or
as a text/plain attachment, instead of using a diff. Diffs are
good for showing differences, but when it's a whole new file,
it's better just to show the file.
Best,
-Karl
> Index: tools/dev/gnuify-changelog.py
> ===================================================================
> --- tools/dev/gnuify-changelog.py (revision 0)
> +++ tools/dev/gnuify-changelog.py (revision 0)
> @@ -0,0 +1,125 @@
> +#!/usr/bin/env python
> +# ====================================================================
> +# Copyright (c) 2000-2007 CollabNet. All rights reserved.
> +#
> +# This software is licensed as described in the file COPYING, which
> +# you should have received as part of this distribution. The terms
> +# are also available at http://subversion.tigris.org/license-1.html.
> +# If newer versions of this license are posted there, you may use a
> +# newer version instead, at your option.
> +#
> +# This software consists of voluntary contributions made by many
> +# individuals. For exact contribution history, see the revision
> +# history and logs, available at http://subversion.tigris.org/.
> +# ====================================================================
> +
> +"""
> +gnuify-changelog.py: a script to munge the output of 'svn log' into something
> + approaching the style of a GNU ChangeLog.
> +
> +Usage:
> +To use this script, just give COMMITTERS file as input to the script, please
> +have a look at the COMMITTERS file of subversion project to create a similar
> +one for people who work on your project. Go to the top level
> +of your working copy, and run:
> +
> +$ svn log | /path/to/gnuify-changelog.py /path/to/COMMITTERS > ChangeLog
> +"""
> +
> +import re
> +import sys
> +
> +if len(sys.argv) != 2:
> + print """
> +Usage: svn log | /path/to/gnuify-changelog.py /path/to/COMMITTERS > ChangeLog
> + """
> + sys.exit(1)
> +
> +# Build the name and email dictionaries with the COMMITTERS file
> +name_dict = {}
> +email_dict = {}
> +
> +fcptr = open (sys.argv[1], 'r')
> +author_lines = fcptr.readlines()
> +p1 = re.compile (r'.*(<.*>).*', re.S)
> +p2 = re.compile (r'(.*)\s\s\s(.*)(<.*?>).*', re.S)
> +
> +for x in author_lines:
> + m1 = p1.match(x)
> + if m1:
> + m2 = p2.match(x)
> + name_dict[m2.group(1).strip()] = m2.group(2).strip()
> + email_dict[m2.group(1).strip()] = m2.group(3).strip()
> +fcptr.close()
> +
> +# Read the entries from stdin
> +entries = sys.stdin.readlines()
> +
> +parse_next_line = 0
> +this_line_empty = 0
> +last_line_empty = 0
> +last_rev = ""
> +
> +# Pattern to identify the starting and ending of a svn log entry
> +p = re.compile (r'(^-+$)',re.S)
> +
> +for x in entries:
> + # Axe windows style line endings, since we should try to be consistent, and
> + # the repos has both styles in its log entries
> + x = re.sub (r'\r\n', r'\n', x)
> +
> + # Remove trailing new line since it is added by default
> + x = re.sub (r'\n+$', r'', x)
> +
> + # Remove trailing whitespace
> + x = re.sub (r'\s+$', r'\n', x)
> +
> + if x == '\n':
> + this_line_empty = 1
> + else:
> + this_line_empty = 0
> +
> + # Avoid duplicate empty lines
> + if this_line_empty and last_line_empty:
> + continue
> +
> + m = p.match(x)
> + # Don't fail on valid dash-only lines
> + if m and len(x) >= 72:
> + # We're at the start of a log entry, so we need to parse the next line
> + parse_next_line = 1
> +
> + # Check to see if the final line of the commit message was blank,
> + # if not insert one
> + if last_rev != "" and (not last_line_empty):
> + print "\n"
> +
> + elif parse_next_line:
> + # Transform from svn style to GNU style
> + parse_next_line = 0
> + s = x.split('|')
> + date = s[2].split(' ')
> + try:
> + # Populate name and email from our dictionaries
> + if name_dict[s[1].strip()] and email_dict[s[1].strip()]:
> + print date[1], " "+name_dict[s[1].strip()],\
> + " "+email_dict[s[1].strip()]
> + else:
> + print d[1], " "+s[1]
> + except:
> + # Use alias if we can't resolve to name, email
> + print date[1], " "+s[1]
> + pass
> +
> + elif this_line_empty:
> + print "\n"
> + else:
> + print "\t"+x
> + last_line_empty = this_line_empty
> +
> +# As a HERE doc so it also sets the final changelog's coding
> +print """
> +;; Local Variables:
> +;; coding: utf-8
> +;; End:
> +"""
>
> Property changes on: tools/dev/gnuify-changelog.py
> ___________________________________________________________________
> Name: svn:executable
> + *
>
>
> [[[
> Accept COMMITTERS file in gnuify-changelog.
>
> New version of gnuify-changelog in python which accepts COMMITTERS file as
> input and generates the gnuified ChangeLog file.
>
> * tools/dev/gnuify-changelog.py: New version in python.
>
> Patch by: Senthil Kumaran <senthil@collab.net>
> ]]]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: dev-help@subversion.tigris.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Jul 31 00:40:13 2007