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
7 # It has been pretty much superseded by inittags, though.
9 # committags [git-args]
11 # This code is part of the LWN git data miner.
13 # Copyright 2007-13 Eklektix, Inc.
14 # Copyright 2007-13 Jonathan Corbet <corbet@lwn.net>
16 # This file may be distributed under the terms of the GNU General
17 # Public License, version 2.
29 p = argparse.ArgumentParser()
32 # -l to load it before running
34 p.add_argument('-d', '--database', help = 'Database name',
35 required = False, default = 'committags.db')
36 p.add_argument('-l', '--load', help = 'Load database at startup',
37 default = False, action = 'store_true')
41 p.add_argument('-g', '--git', help = 'Arguments to git',
46 p.add_argument('-r', '--repository', help = 'Repository location',
55 # Pull in an existing database if requested.
58 DB = pickle.load(open(args.database, 'r'))
61 out = open(args.database, 'w')
64 # Time to fire up git.
66 git = 'git log --pretty=format:%H ' + args.git
68 os.chdir(args.repository)
69 input = os.popen(git, 'r')
72 for line in input.readlines():
75 # If we loaded a database and this commit is already there, we
78 if args.load and DB.has_key(commit):
81 # Figure out which version this one came from.
83 desc = os.popen('git describe --contains --match v\\* ' + commit, 'r')
84 tag = desc.readline().strip()
88 DB[commit] = tag[:dash]
92 # Give them something to watch.
96 print '%6d %s %s \r' % (nc, commit[:8], tag),
99 print '\nFound %d/%d commits' % (nc, len(DB.keys()))