From 29078ef058f964ba61deceac755915871f4668c6 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 8 May 2013 09:42:38 +0200 Subject: [PATCH] gentree: use git library to speed up --git-revision 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 --- lib/bpgit.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/bpgit.py b/lib/bpgit.py index d61d90a8cbc1..31b7de36b6cd 100644 --- a/lib/bpgit.py +++ b/lib/bpgit.py @@ -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]) -- 2.30.2