summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Corbet <corbet@lwn.net>2013-08-02 14:36:41 -0600
committerJonathan Corbet <corbet@lwn.net>2013-08-02 14:36:41 -0600
commit275d0baaad7cdf98b0f55b46d9619e15b21c2f53 (patch)
treeb0415e6548d67c0c0fdeac4b56b970505ecdf2b5
parente074f11a64de7a067bbee4fd9eb18407f7482d7e (diff)
Rewrite committags
I'm tired of trying to be fast and clever. This version is dumb and heartbreakingly slow - but it works.
-rwxr-xr-xcommittags97
1 files changed, 76 insertions, 21 deletions
diff --git a/committags b/committags
index 39a532d..0ddd36f 100755
--- a/committags
+++ b/committags
@@ -1,13 +1,16 @@
-#!/usr/bin/python
+#!/usr/bin/pypy
#
# Generate a database of commits and major versions they went into.
#
+# This is the painfully slow reworked brute-force version that
+# takes forever to run, but which hopefully gets the right results
+#
# committags [git-args]
#
# This code is part of the LWN git data miner.
#
-# Copyright 2007-11 Eklektix, Inc.
-# Copyright 2007-11 Jonathan Corbet <corbet@lwn.net>
+# Copyright 2007-13 Eklektix, Inc.
+# Copyright 2007-13 Jonathan Corbet <corbet@lwn.net>
#
# This file may be distributed under the terms of the GNU General
# Public License, version 2.
@@ -16,30 +19,82 @@ import sys
import re
import os
import pickle
+import argparse
+
+#
+# Arg parsing stuff.
+#
+def setupargs():
+ p = argparse.ArgumentParser()
+ #
+ # -d for the database
+ # -l to load it before running
+ #
+ p.add_argument('-d', '--database', help = 'Database name',
+ required = False, default = 'committags.db')
+ p.add_argument('-l', '--load', help = 'Load database at startup',
+ default = False, action = 'store_true')
+ #
+ # Args for git?
+ #
+ p.add_argument('-g', '--git', help = 'Arguments to git',
+ default = '')
+ #
+ # Where's the repo?
+ #
+ p.add_argument('-r', '--repository', help = 'Repository location',
+ default = '')
+ return p
-git = 'git log --decorate '
-if len(sys.argv) > 1:
- git += ' '.join(sys.argv[1:])
-input = os.popen(git, 'r')
-DB = { }
-Tag = 'None'
+p = setupargs()
+args = p.parse_args()
-tagline = re.compile(r'^commit ([\da-f]+) .*tag: (v2\.6\.\d\d)')
-commit = re.compile(r'^commit ([\da-f]+)')
+#
+# Pull in an existing database if requested.
+#
+if args.load:
+ DB = pickle.load(open(args.database, 'r'))
+else:
+ DB = { }
+out = open(args.database, 'w')
+
+#
+# Time to fire up git.
+#
+git = 'git log --pretty=format:%H ' + args.git
+if args.repository:
+ os.chdir(args.repository)
+input = os.popen(git, 'r')
+nc = 0
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)
+ commit = line.strip()
+ #
+ # If we loaded a database and this commit is already there, we
+ # can quit.
+ #
+ if args.load and DB.has_key(commit):
+ break
+ #
+ # Figure out which version this one came from.
+ #
+ desc = os.popen('git describe --contains --match v\\* ' + commit, 'r')
+ tag = desc.readline().strip()
+ desc.close()
+ dash = tag.find('-')
+ if dash > 0:
+ DB[commit] = tag[:dash]
else:
- m = commit.search(line)
- if m:
- DB[m.group(1)] = Tag
+ DB[commit] = tag
+ #
+ # Give them something to watch.
+ #
+ nc += 1
+ if (nc % 25) == 0:
+ print '%6d %s %s\r' % (nc, commit[:8], tag),
+ sys.stdout.flush()
-print 'Found %d commits' % (len(DB.keys()))
-out = open('committags.db', 'w')
+print '\nFound %d/%d commits' % (nc, len(DB.keys()))
pickle.dump(DB, out)
out.close()