python support: rename git library to bpgit
authorJohannes Berg <johannes.berg@intel.com>
Wed, 8 May 2013 07:40:50 +0000 (09:40 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 8 May 2013 07:45:01 +0000 (09:45 +0200)
There's a python git library, and our name conflicts
with it since it's also just called "git". I want to
use the python library (optionally) to speed up the
git accesses so this is now relevant.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
devel/git-tracker.py
gentree.py
lib/bpgit.py [new file with mode: 0644]
lib/git.py [deleted file]

index 9edc95cfb3b962528fdfbe3661c696cbb7dc6d6f..b74105abf8848ddac8369f422421121474ae9046 100755 (executable)
@@ -20,7 +20,8 @@ source_dir = os.path.dirname(source_dir)
 # add parent directory to path to get to lib/
 sys.path.append(source_dir)
 # import libraries we need
-from lib import git, tempdir
+from lib import tempdir
+from lib import bpgit as git
 import gentree
 
 # you can increase this if you really want ...
index afe3645f59f909bf25c6f3c28433ea1e388e5e97..04ce0e3676e1d1749b339dca22fc47c41e28031f 100755 (executable)
@@ -9,8 +9,8 @@ import argparse, sys, os, errno, shutil, re, subprocess
 source_dir = os.path.abspath(os.path.dirname(__file__))
 sys.path.append(source_dir)
 # and import libraries we have
-from lib import kconfig, git, patch, make
-
+from lib import kconfig, patch, make
+from lib import bpgit as git
 
 def read_copy_list(copyfile):
     """
diff --git a/lib/bpgit.py b/lib/bpgit.py
new file mode 100644 (file)
index 0000000..d61d90a
--- /dev/null
@@ -0,0 +1,228 @@
+import subprocess, re, os, tempfile
+
+class GitError(Exception):
+    pass
+class SHAError(GitError):
+    pass
+class ExecutionError(GitError):
+    def __init__(self, errcode):
+        self.error_code = errcode
+
+def _check(process):
+    if process.returncode != 0:
+        raise ExecutionError(process.returncode)
+
+_sha_re = re.compile('^[0-9a-fA-F]*$')
+
+def rev_parse(rev='HEAD', tree=None):
+    process = subprocess.Popen(['git', 'rev-parse', rev],
+                               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+                               close_fds=True, universal_newlines=True, cwd=tree)
+    stdout = process.communicate()[0]
+    process.wait()
+    _check(process)
+
+    sha = stdout.strip()
+    if not _sha_re.match(sha):
+        raise SHAError()
+    return sha
+
+def describe(rev='HEAD', tree=None):
+    process = subprocess.Popen(['git', 'describe', '--always', '--long', rev],
+                               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+                               close_fds=True, universal_newlines=True, cwd=tree)
+    stdout = process.communicate()[0]
+    process.wait()
+    _check(process)
+
+    return stdout.strip()
+
+def init(tree=None):
+    process = subprocess.Popen(['git', 'init'],
+                               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+                               close_fds=True, universal_newlines=True, cwd=tree)
+    stdout = process.communicate()[0]
+    process.wait()
+    _check(process)
+
+def add(path, tree=None):
+    process = subprocess.Popen(['git', 'add', path],
+                               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+                               close_fds=True, universal_newlines=True, cwd=tree)
+    stdout = process.communicate()[0]
+    process.wait()
+    _check(process)
+
+def commit_all(message, tree=None):
+    add('.', tree=tree)
+    process = subprocess.Popen(['git', 'commit', '--allow-empty', '-a', '-m', message],
+                               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+                               close_fds=True, universal_newlines=True, cwd=tree)
+    stdout = process.communicate()[0]
+    process.wait()
+    _check(process)
+
+def ls_tree(rev, files, tree=None):
+    process = subprocess.Popen(['git', 'ls-tree', '-z', '-r', rev, '--', ] + list(files),
+                               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+                               close_fds=True, universal_newlines=True, cwd=tree)
+    stdout = process.communicate()[0]
+    files = stdout.split('\0')
+    ret = []
+    for f in files:
+        if not f:
+            continue
+        meta, f = f.split('\t', 1)
+        meta = meta.split()
+        meta.append(f)
+        ret.append(meta)
+    process.wait()
+    _check(process)
+    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)
+
+def clone(gittree, outputdir, options=[]):
+    process = subprocess.Popen(['git', 'clone'] + options + [gittree, outputdir])
+    process.wait()
+    _check(process)
+
+def set_origin(giturl, gitdir):
+    process = subprocess.Popen(['git', 'remote', 'rm', 'origin'],
+                               close_fds=True, universal_newlines=True, cwd=gitdir)
+    process.wait()
+
+    process = subprocess.Popen(['git', 'remote', 'add', 'origin', giturl],
+                               close_fds=True, universal_newlines=True, cwd=gitdir)
+    process.wait()
+    _check(process)
+
+def remote_update(gitdir):
+    process = subprocess.Popen(['git', 'remote', 'update'],
+                               close_fds=True, universal_newlines=True, cwd=gitdir)
+    process.wait()
+    _check(process)
+
+def shortlog(from_commit, to_commit, tree=None):
+    process = subprocess.Popen(['git', 'shortlog', from_commit + '..' + to_commit],
+                               stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+                               close_fds=True, universal_newlines=True,
+                               cwd=tree)
+    stdout = process.communicate()[0]
+    process.wait()
+    _check(process)
+    return stdout
+
+def commit_env_vars(commitid, tree=None):
+    process = subprocess.Popen(['git', 'show', '--name-only',
+                                '--format=format:GIT_AUTHOR_NAME=%an%nGIT_AUTHOR_EMAIL=%ae%nGIT_AUTHOR_DATE=%aD%x00',
+                                commitid],
+                                stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+                                close_fds=True, universal_newlines=True,
+                                cwd=tree)
+    stdout = process.communicate()[0]
+    process.wait()
+    _check(process)
+    data = stdout.split('\x00')[0]
+    vals = data.split('\n')
+    d = {}
+    for k, v in map(lambda x: x.split('=', 1), vals):
+        d[k] = v
+    return d
+
+def commit_message(commitid, tree=None):
+    process = subprocess.Popen(['git', 'show', '--name-only',
+                                '--format=format:%s%n%n%b%x00', commitid],
+                                stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+                                close_fds=True, universal_newlines=True,
+                                cwd=tree)
+    stdout = process.communicate()[0]
+    process.wait()
+    _check(process)
+    return stdout.split('\x00')[0]
+
+def remove_config(cfg, tree=None):
+    process = subprocess.Popen(['git', 'config', '--unset-all', cfg],
+                               close_fds=True, universal_newlines=True, cwd=tree)
+    process.wait()
+    _check(process)
+
+def ls_remote(branch, tree=None, remote='origin'):
+    process = subprocess.Popen(['git', 'ls-remote', '--exit-code', remote, 'refs/heads/' + branch],
+                               stdout=subprocess.PIPE,
+                               close_fds=True, universal_newlines=True, cwd=tree)
+    stdout = process.communicate()[0]
+    process.wait()
+    _check(process)
+    sha = stdout.split()[0]
+    if not _sha_re.match(sha):
+        raise SHAError()
+    return sha
+
+def add(fn, tree=None):
+    process = subprocess.Popen(['git', 'add', fn], cwd=tree,
+                               close_fds=True, universal_newlines=True)
+    process.wait()
+    _check(process)
+
+def commit(msg, tree=None, env = {}, opts=[]):
+    stdin = tempfile.NamedTemporaryFile(mode='wr')
+    stdin.write(msg)
+    stdin.seek(0)
+    process = subprocess.Popen(['git', 'commit', '--file=-'] + opts,
+                               stdin=stdin.file, universal_newlines=True, env=env,
+                               cwd=tree)
+    process.wait()
+    _check(process)
+
+def push(opts=[], tree=None):
+    process = subprocess.Popen(['git', 'push'] + opts,
+                               close_fds=True, universal_newlines=True, cwd=tree)
+    process.wait()
+    _check(process)
+
+def log_commits(from_commit, to_commit, tree=None):
+    process = subprocess.Popen(['git', 'log', '--first-parent', '--format=format:%H',
+                                from_commit + '..' + to_commit],
+                               stdout=subprocess.PIPE,
+                               close_fds=True, universal_newlines=True,
+                               cwd=tree)
+    stdout = process.communicate()[0]
+    process.wait()
+    _check(process)
+    vals = stdout.split()
+    vals.reverse()
+    return vals
+
+def commit_env_vars(commitid, tree=None):
+    process = subprocess.Popen(['git', 'show', '--name-only',
+                                '--format=format:GIT_AUTHOR_NAME=%an%nGIT_AUTHOR_EMAIL=%ae%nGIT_AUTHOR_DATE=%aD%x00',
+                                commitid],
+                                stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+                                close_fds=True, universal_newlines=True,
+                                cwd=tree)
+    stdout = process.communicate()[0]
+    process.wait()
+    _check(process)
+    data = stdout.split('\x00')[0]
+    vals = data.split('\n')
+    d = {}
+    for k, v in map(lambda x: x.split('=', 1), vals):
+        d[k] = v
+    return d
+
+def rm(opts=[], tree=None):
+    process = subprocess.Popen(['git', 'rm'] + opts,
+                               close_fds=True, universal_newlines=True, cwd=tree)
+    process.wait()
+    _check(process)
+
+def reset(opts=[], tree=None):
+    process = subprocess.Popen(['git', 'reset'] + opts,
+                               close_fds=True, universal_newlines=True, cwd=tree)
+    process.wait()
+    _check(process)
diff --git a/lib/git.py b/lib/git.py
deleted file mode 100644 (file)
index d61d90a..0000000
+++ /dev/null
@@ -1,228 +0,0 @@
-import subprocess, re, os, tempfile
-
-class GitError(Exception):
-    pass
-class SHAError(GitError):
-    pass
-class ExecutionError(GitError):
-    def __init__(self, errcode):
-        self.error_code = errcode
-
-def _check(process):
-    if process.returncode != 0:
-        raise ExecutionError(process.returncode)
-
-_sha_re = re.compile('^[0-9a-fA-F]*$')
-
-def rev_parse(rev='HEAD', tree=None):
-    process = subprocess.Popen(['git', 'rev-parse', rev],
-                               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
-                               close_fds=True, universal_newlines=True, cwd=tree)
-    stdout = process.communicate()[0]
-    process.wait()
-    _check(process)
-
-    sha = stdout.strip()
-    if not _sha_re.match(sha):
-        raise SHAError()
-    return sha
-
-def describe(rev='HEAD', tree=None):
-    process = subprocess.Popen(['git', 'describe', '--always', '--long', rev],
-                               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
-                               close_fds=True, universal_newlines=True, cwd=tree)
-    stdout = process.communicate()[0]
-    process.wait()
-    _check(process)
-
-    return stdout.strip()
-
-def init(tree=None):
-    process = subprocess.Popen(['git', 'init'],
-                               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
-                               close_fds=True, universal_newlines=True, cwd=tree)
-    stdout = process.communicate()[0]
-    process.wait()
-    _check(process)
-
-def add(path, tree=None):
-    process = subprocess.Popen(['git', 'add', path],
-                               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
-                               close_fds=True, universal_newlines=True, cwd=tree)
-    stdout = process.communicate()[0]
-    process.wait()
-    _check(process)
-
-def commit_all(message, tree=None):
-    add('.', tree=tree)
-    process = subprocess.Popen(['git', 'commit', '--allow-empty', '-a', '-m', message],
-                               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
-                               close_fds=True, universal_newlines=True, cwd=tree)
-    stdout = process.communicate()[0]
-    process.wait()
-    _check(process)
-
-def ls_tree(rev, files, tree=None):
-    process = subprocess.Popen(['git', 'ls-tree', '-z', '-r', rev, '--', ] + list(files),
-                               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
-                               close_fds=True, universal_newlines=True, cwd=tree)
-    stdout = process.communicate()[0]
-    files = stdout.split('\0')
-    ret = []
-    for f in files:
-        if not f:
-            continue
-        meta, f = f.split('\t', 1)
-        meta = meta.split()
-        meta.append(f)
-        ret.append(meta)
-    process.wait()
-    _check(process)
-    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)
-
-def clone(gittree, outputdir, options=[]):
-    process = subprocess.Popen(['git', 'clone'] + options + [gittree, outputdir])
-    process.wait()
-    _check(process)
-
-def set_origin(giturl, gitdir):
-    process = subprocess.Popen(['git', 'remote', 'rm', 'origin'],
-                               close_fds=True, universal_newlines=True, cwd=gitdir)
-    process.wait()
-
-    process = subprocess.Popen(['git', 'remote', 'add', 'origin', giturl],
-                               close_fds=True, universal_newlines=True, cwd=gitdir)
-    process.wait()
-    _check(process)
-
-def remote_update(gitdir):
-    process = subprocess.Popen(['git', 'remote', 'update'],
-                               close_fds=True, universal_newlines=True, cwd=gitdir)
-    process.wait()
-    _check(process)
-
-def shortlog(from_commit, to_commit, tree=None):
-    process = subprocess.Popen(['git', 'shortlog', from_commit + '..' + to_commit],
-                               stdout=subprocess.PIPE, stderr=subprocess.PIPE,
-                               close_fds=True, universal_newlines=True,
-                               cwd=tree)
-    stdout = process.communicate()[0]
-    process.wait()
-    _check(process)
-    return stdout
-
-def commit_env_vars(commitid, tree=None):
-    process = subprocess.Popen(['git', 'show', '--name-only',
-                                '--format=format:GIT_AUTHOR_NAME=%an%nGIT_AUTHOR_EMAIL=%ae%nGIT_AUTHOR_DATE=%aD%x00',
-                                commitid],
-                                stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
-                                close_fds=True, universal_newlines=True,
-                                cwd=tree)
-    stdout = process.communicate()[0]
-    process.wait()
-    _check(process)
-    data = stdout.split('\x00')[0]
-    vals = data.split('\n')
-    d = {}
-    for k, v in map(lambda x: x.split('=', 1), vals):
-        d[k] = v
-    return d
-
-def commit_message(commitid, tree=None):
-    process = subprocess.Popen(['git', 'show', '--name-only',
-                                '--format=format:%s%n%n%b%x00', commitid],
-                                stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
-                                close_fds=True, universal_newlines=True,
-                                cwd=tree)
-    stdout = process.communicate()[0]
-    process.wait()
-    _check(process)
-    return stdout.split('\x00')[0]
-
-def remove_config(cfg, tree=None):
-    process = subprocess.Popen(['git', 'config', '--unset-all', cfg],
-                               close_fds=True, universal_newlines=True, cwd=tree)
-    process.wait()
-    _check(process)
-
-def ls_remote(branch, tree=None, remote='origin'):
-    process = subprocess.Popen(['git', 'ls-remote', '--exit-code', remote, 'refs/heads/' + branch],
-                               stdout=subprocess.PIPE,
-                               close_fds=True, universal_newlines=True, cwd=tree)
-    stdout = process.communicate()[0]
-    process.wait()
-    _check(process)
-    sha = stdout.split()[0]
-    if not _sha_re.match(sha):
-        raise SHAError()
-    return sha
-
-def add(fn, tree=None):
-    process = subprocess.Popen(['git', 'add', fn], cwd=tree,
-                               close_fds=True, universal_newlines=True)
-    process.wait()
-    _check(process)
-
-def commit(msg, tree=None, env = {}, opts=[]):
-    stdin = tempfile.NamedTemporaryFile(mode='wr')
-    stdin.write(msg)
-    stdin.seek(0)
-    process = subprocess.Popen(['git', 'commit', '--file=-'] + opts,
-                               stdin=stdin.file, universal_newlines=True, env=env,
-                               cwd=tree)
-    process.wait()
-    _check(process)
-
-def push(opts=[], tree=None):
-    process = subprocess.Popen(['git', 'push'] + opts,
-                               close_fds=True, universal_newlines=True, cwd=tree)
-    process.wait()
-    _check(process)
-
-def log_commits(from_commit, to_commit, tree=None):
-    process = subprocess.Popen(['git', 'log', '--first-parent', '--format=format:%H',
-                                from_commit + '..' + to_commit],
-                               stdout=subprocess.PIPE,
-                               close_fds=True, universal_newlines=True,
-                               cwd=tree)
-    stdout = process.communicate()[0]
-    process.wait()
-    _check(process)
-    vals = stdout.split()
-    vals.reverse()
-    return vals
-
-def commit_env_vars(commitid, tree=None):
-    process = subprocess.Popen(['git', 'show', '--name-only',
-                                '--format=format:GIT_AUTHOR_NAME=%an%nGIT_AUTHOR_EMAIL=%ae%nGIT_AUTHOR_DATE=%aD%x00',
-                                commitid],
-                                stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
-                                close_fds=True, universal_newlines=True,
-                                cwd=tree)
-    stdout = process.communicate()[0]
-    process.wait()
-    _check(process)
-    data = stdout.split('\x00')[0]
-    vals = data.split('\n')
-    d = {}
-    for k, v in map(lambda x: x.split('=', 1), vals):
-        d[k] = v
-    return d
-
-def rm(opts=[], tree=None):
-    process = subprocess.Popen(['git', 'rm'] + opts,
-                               close_fds=True, universal_newlines=True, cwd=tree)
-    process.wait()
-    _check(process)
-
-def reset(opts=[], tree=None):
-    process = subprocess.Popen(['git', 'reset'] + opts,
-                               close_fds=True, universal_newlines=True, cwd=tree)
-    process.wait()
-    _check(process)