3 # Generate a database of commits and major versions they went into.
5 # This is the painfully slow reworked brute-force version that
6 # takes forever to run, but which hopefully gets the right results
8 # committags [git-args]
10 # This code is part of the LWN git data miner.
12 # Copyright 2007-13 Eklektix, Inc.
13 # Copyright 2007-13 Jonathan Corbet <corbet@lwn.net>
15 # This file may be distributed under the terms of the GNU General
16 # Public License, version 2.
28 p = argparse.ArgumentParser()
31 # -l to load it before running
33 p.add_argument('-d', '--database', help = 'Database name',
34 required = False, default = 'committags.db')
35 p.add_argument('-l', '--load', help = 'Load database at startup',
36 default = False, action = 'store_true')
40 p.add_argument('-g', '--git', help = 'Arguments to git',
45 p.add_argument('-r', '--repository', help = 'Repository location',
54 # Pull in an existing database if requested.
57 DB = pickle.load(open(args.database, 'r'))
60 out = open(args.database, 'w')
63 # Time to fire up git.
65 git = 'git log --pretty=format:%H ' + args.git
67 os.chdir(args.repository)
68 input = os.popen(git, 'r')
71 for line in input.readlines():
74 # If we loaded a database and this commit is already there, we
77 if args.load and DB.has_key(commit):
80 # Figure out which version this one came from.
82 desc = os.popen('git describe --contains --match v\\* ' + commit, 'r')
83 tag = desc.readline().strip()
87 DB[commit] = tag[:dash]
91 # Give them something to watch.
95 print '%6d %s %s\r' % (nc, commit[:8], tag),
98 print '\nFound %d/%d commits' % (nc, len(DB.keys()))