gentree: use git library to speed up --git-revision
authorJohannes Berg <johannes.berg@intel.com>
Wed, 8 May 2013 07:42:38 +0000 (09:42 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 8 May 2013 07:45:51 +0000 (09:45 +0200)
If the git library is available (on many distros, just
install python-git or similar) then use it to read the
git blobs from disk if --git-revision is used.

On my system (with an SSD) this speeds up the entire
backport generation process significantly (when using
--git-revision):

before:
real 0m39.280s
user 0m13.464s
sys 0m16.644s

after:
real 0m22.554s
user 0m16.404s
sys 0m5.724s

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
lib/bpgit.py

index d61d90a8cbc1f0f9418431cd4365d6069236efd5..31b7de36b6cd23921674e5b88d989020d231d094 100644 (file)
@@ -81,10 +81,16 @@ def ls_tree(rev, files, tree=None):
     return ret
 
 def get_blob(blob, outf, tree=None):
-    process = subprocess.Popen(['git', 'show', blob],
-                               stdout=outf, close_fds=True, cwd=tree)
-    process.wait()
-    _check(process)
+    try:
+        import git, gitdb
+        r = git.Repo(path=tree)
+        b = r.rev_parse(blob + '^{blob}')
+        b.stream_data(outf)
+    except ImportError:
+        process = subprocess.Popen(['git', 'show', blob],
+                                   stdout=outf, close_fds=True, cwd=tree)
+        process.wait()
+        _check(process)
 
 def clone(gittree, outputdir, options=[]):
     process = subprocess.Popen(['git', 'clone'] + options + [gittree, outputdir])