3 # Find out how many lines were introduced in each major release.
7 # This code is part of the LWN git data miner.
9 # Copyright 2007-11 Eklektix, Inc.
10 # Copyright 2007-11 Jonathan Corbet <corbet@lwn.net>
12 # This file may be distributed under the terms of the GNU General
13 # Public License, version 2.
15 import sys, re, os, pickle
19 commitpat = re.compile(r'^([\da-f][\da-f]+) ')
21 def GetCommitLines(file):
23 blame = os.popen('git blame -p ' + file, 'r')
24 for line in blame.readlines():
25 m = commitpat.search(line)
27 # All-zero commits mean we got fed a file that git doesn't
28 # know about. We could throw an exception and abort processing
29 # now, or we can just silently ignore it...
31 if not m or m.group(1) == '0000000000000000000000000000000000000000':
34 CommitLines[m.group(1)] += 1
36 CommitLines[m.group(1)] = 1
40 # Try to figure out which tag is the first to contain each commit.
42 refpat = re.compile(r'^(v2\.6\.\d\d).*$')
43 def CommitToTag(commit):
47 print 'Missing commit %s' % (commit)
52 print 'Mapping tags...'
53 for commit in CommitLines.keys():
54 tag = CommitToTag(commit)
56 TagLines[tag] += CommitLines[commit]
58 TagLines[tag] = CommitLines[commit]
61 # Here we just plow through all the files.
63 if len(sys.argv) != 2:
64 sys.stderr.write('Usage: linetags directory\n')
67 # Grab the tags/version database.
69 dbf = open('committags.db', 'r')
73 out = open('linetags.out', 'w')
75 files = os.popen('/usr/bin/find . -type f', 'r')
76 for file in files.readlines():
77 if file.find('.git/') < 0:
78 GetCommitLines(file[:-1])
81 tags = TagLines.keys()
84 out.write('%s %d\n' % (tag, TagLines[tag]))