--- /dev/null Sat May 9 16:08:44 2009 +++ new/usr/src/tools/scripts/git-active.py Sat May 9 16:08:44 2009 @@ -0,0 +1,123 @@ +#! /usr/bin/python +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 +# as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +# +# Copyright 2009 Grigale, Inc. All rights reserved. +# Use is subject to license terms. +# + +''' +Create a wx-style active list on stdout based on a Git +workspace in support of webrev's Git support. +''' + +# +# NB: This assumes the normal onbld directory structure +# +import os +import sys +import optparse +import subprocess + +def execCmd(cmd): + '''Executes external command''' + + p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + (out, err) = p.communicate() + + if out == None: + out = "" + + return (p.returncode, out.splitlines(), err.splitlines()) + +def usage(): + sys.stderr.write("usage: %s [-p parent] -w workspace\n" % + os.path.basename(__file__)) + sys.exit(2) + +def main(argv): + + parser = optparse.OptionParser(version='%prog 1.0') + parser.add_option("-p", dest="parentpath", default="", help="parent repo") + parser.add_option("-w", dest="wspath", default="", help="workspace") + parser.add_option("-o", dest="outputfile", help="output file") + parser.disable_interspersed_args() + + (options, args) = parser.parse_args() + + if not options.wspath: + usage() + + fh = None + if options.outputfile: + try: + fh = open(options.outputfile, 'w') + except EnvironmentError, e: + sys.stderr.write("could not open output file: %s\n" % e) + sys.exit(1) + else: + fh = sys.stdout + + cmd = ["git", "--git-dir=%s" % options.wspath, "log", "--name-only", + "--parents", "--reverse", "--pretty=short", "master.."] + (rc, out, err) = execCmd(cmd) + + #print rc, out, err + + if "commit" in out[0]: + parent = out[0].split()[2] + + files = {} + comment = None + for i in out: + if "commit" in i: + comment = None + continue + if i == "" or i.startswith("Author"): + continue + if i.startswith(" "): + comment = i.strip() + continue + if comment: + if i not in files: + files[i] = [] + files[i].append(comment) + + fh.write("GIT_PARENT=%s\n" % parent) + + for file in files: + #if entry.is_renamed(): + # fh.write("%s %s\n" % (entry.name, entry.parentname)) + #else: + # fh.write("%s\n" % entry.name) + fh.write("%s\n\n" % file) + fh.write("%s\n\n" % '\n'.join(files[file])) + +#try: +# Version.check_version() +#except Version.VersionMismatch, e: +# sys.stderr.write("Error: %s\n" % e) +# sys.exit(1) + +if __name__ == '__main__': + try: + main(sys.argv[1:]) + except KeyboardInterrupt: + sys.exit(1) +# except util.Abort, msg: +# sys.stderr.write("Abort: %s\n" % msg) +# sys.exit(1)