]> xenbits.xensource.com Git - people/larsk/xenproject-org-gitdm.git/commitdiff
Add a couple of lines-per-version utilities
authorJonathan Corbet <corbet@lwn.net>
Tue, 16 Feb 2010 00:32:08 +0000 (17:32 -0700)
committerJonathan Corbet <corbet@lwn.net>
Tue, 16 Feb 2010 00:32:08 +0000 (17:32 -0700)
A couple of quickly-hacked tools which let me determine how much of the
kernel was added in each major version.

Signed-off-by: Jonathan Corbet <corbet@lwn.net>
committags [new file with mode: 0755]
linetags [new file with mode: 0755]

diff --git a/committags b/committags
new file mode 100755 (executable)
index 0000000..f1c8fc3
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+#
+# Generate a database of commits and major versions they went into.
+#
+# committags [git-args]
+#
+import sys
+import re
+import os
+import pickle
+
+git = 'git log --decorate '
+if len(sys.argv) > 1:
+    git += ' '.join(sys.argv[1:])
+input = os.popen(git, 'r')
+
+DB = { }
+Tag = 'None'
+
+tagline = re.compile(r'^commit ([\da-f]+) .*tag: (v2\.6\.\d\d)')
+commit = re.compile(r'^commit ([\da-f]+)')
+
+for line in input.readlines():
+    if not line.startswith('commit'):
+        continue  # This makes it go faster
+    m = tagline.search(line)
+    if m:
+        DB[m.group(1)] = Tag = m.group(2)
+    else:
+        m = commit.search(line)
+        if m:
+            DB[m.group(1)] = Tag
+
+print 'Found %d commits' % (len(DB.keys()))
+out = open('committags.db', 'w')
+pickle.dump(DB, out)
+out.close()
diff --git a/linetags b/linetags
new file mode 100755 (executable)
index 0000000..767e399
--- /dev/null
+++ b/linetags
@@ -0,0 +1,77 @@
+#!/usr/bin/python
+#
+# Find out how many lines were introduced in each major release.
+#
+# linetags <directory>
+#
+import sys, re, os, pickle
+
+CommitLines = { }
+
+commitpat = re.compile(r'^([\da-f][\da-f]+) ')
+
+def GetCommitLines(file):
+    print file
+    blame = os.popen('git blame -p ' + file, 'r')
+    for line in blame.readlines():
+        m = commitpat.search(line)
+        #
+        # All-zero commits mean we got fed a file that git doesn't
+        # know about.  We could throw an exception and abort processing
+        # now, or we can just silently ignore it...
+        #
+        if not m or m.group(1) == '0000000000000000000000000000000000000000':
+            continue
+        try:
+            CommitLines[m.group(1)] += 1
+        except KeyError:
+            CommitLines[m.group(1)] = 1
+    blame.close()
+
+#
+# Try to figure out which tag is the first to contain each commit.
+#
+refpat = re.compile(r'^(v2\.6\.\d\d).*$')
+def CommitToTag(commit):
+    try:
+        return DB[commit]
+    except KeyError:
+        print 'Missing commit %s' % (commit)
+        return 'WTF?'
+
+TagLines = { }
+def MapCommits():
+    print 'Mapping tags...'
+    for commit in CommitLines.keys():
+        tag = CommitToTag(commit)
+        try:
+            TagLines[tag] += CommitLines[commit]
+        except KeyError:
+            TagLines[tag] = CommitLines[commit]
+
+#
+# Here we just plow through all the files.
+#
+if len(sys.argv) != 2:
+    sys.stderr.write('Usage: linetags directory\n')
+    sys.exit(1)
+#
+# Grab the tags/version database.
+#
+dbf = open('committags.db', 'r')
+DB = pickle.load(dbf)
+dbf.close()
+
+out = open('linetags.out', 'w')
+os.chdir(sys.argv[1])
+files = os.popen('/usr/bin/find . -type f', 'r')
+for file in files.readlines():
+    if file.find('.git/') < 0:
+        GetCommitLines(file[:-1])
+MapCommits()
+# print TagLines
+tags = TagLines.keys()
+tags.sort()
+for tag in tags:
+    out.write('%s %d\n' % (tag, TagLines[tag]))
+out.close()