summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2009-10-24 21:10:31 +0200
committerGuido Günther <agx@sigxcpu.org>2009-10-24 21:10:31 +0200
commit5bf8201a3a296af8e8439592c07ff43c13a88d74 (patch)
tree580f0bb3e23a87b5005620b8de75665192935842
parent38fcab2fd4fd674026e222bf14df4146863ac8a8 (diff)
downloadgit-buildpackage-5bf8201a3a296af8e8439592c07ff43c13a88d74.tar.gz
git-buildpackage-5bf8201a3a296af8e8439592c07ff43c13a88d74.tar.bz2
git-buildpackage-5bf8201a3a296af8e8439592c07ff43c13a88d74.zip
move FastImport into gbp/git.py
-rw-r--r--gbp/git.py67
-rwxr-xr-xgit-import-orig67
2 files changed, 67 insertions, 67 deletions
diff --git a/gbp/git.py b/gbp/git.py
index 6533b456..60914885 100644
--- a/gbp/git.py
+++ b/gbp/git.py
@@ -1,7 +1,7 @@
# vim: set fileencoding=utf-8 :
#
# (C) 2006,2007,2008 Guido Guenther <agx@sigxcpu.org>
-"""provides some git repository related helpers"""
+"""provides git repository related helpers"""
import subprocess
import os.path
@@ -222,6 +222,71 @@ class GitRepository(object):
return (name, email)
+class FastImport(object):
+ """Invoke git-fast-import"""
+ _bufsize = 1024
+
+ m_regular = 644
+ m_exec = 755
+ m_symlink = 120000
+
+ def __init__(self):
+ try:
+ self._fi = subprocess.Popen([ 'git', 'fast-import', '--quiet'], stdin=subprocess.PIPE)
+ self._out = self._fi.stdin
+ except OSError, err:
+ raise GbpError, "Error spawning git fast-import: %s", err
+ except ValueError, err:
+ raise GbpError, "Invalid argument when spawning git fast-import: %s", err
+
+ def _do_data(self, fd, size):
+ self._out.write("data %s\n" % size)
+ while True:
+ data = fd.read(self._bufsize)
+ self._out.write(data)
+ if len(data) != self._bufsize:
+ break
+ self._out.write("\n")
+
+ def _do_file(self, filename, mode, fd, size):
+ name = "/".join(filename.split('/')[1:])
+ self._out.write("M %d inline %s\n" % (mode, name))
+ self._do_data(fd, size)
+
+ def add_file(self, filename, fd, size):
+ self._do_file(filename, self.m_regular, fd, size)
+
+ def add_executable(self, filename, fd, size):
+ self._do_file(filename, self.m_exec, fd, size)
+
+ def add_symlink(self, filename, linkname):
+ name = "/".join(filename.split('/')[1:])
+ self._out.write("M %d inline %s\n" % (self.m_symlink, name))
+ self._out.write("data %s\n" % len(linkname))
+ self._out.write("%s\n" % linkname)
+
+ def start_commit(self, branch, committer, email, time, msg):
+ length = len(msg)
+ self._out.write("""commit refs/heads/%(branch)s
+committer %(committer)s <%(email)s> %(time)s
+data %(length)s
+%(msg)s
+from refs/heads/%(branch)s^0
+""" % locals())
+
+ def do_deleteall(self):
+ self._out.write("deleteall\n")
+
+ def close(self):
+ if self._out:
+ self._out.close()
+ if self._fi:
+ self._fi.wait()
+
+ def __del__(self):
+ self.close()
+
+
def create_repo(path):
"""create a repository at path"""
abspath = os.path.abspath(path)
diff --git a/git-import-orig b/git-import-orig
index dc8d7e2c..632edbf9 100755
--- a/git-import-orig
+++ b/git-import-orig
@@ -31,75 +31,10 @@ import gbp.command_wrappers as gbpc
from gbp.deb import (parse_changelog, unpack_orig, repack_orig,
NoChangelogError, has_epoch, tar_toplevel,
guess_upstream_version)
-from gbp.git import (GitRepositoryError, GitRepository, build_tag)
+from gbp.git import (FastImport, GitRepositoryError, GitRepository, build_tag)
from gbp.config import GbpOptionParser, GbpOptionGroup
from gbp.errors import (GbpError, GbpNothingImported)
-class FastImport(object):
- """Invoke git-fast-import"""
- _bufsize = 1024
-
- m_regular = 644
- m_exec = 755
- m_symlink = 120000
-
- def __init__(self):
- try:
- self._fi = subprocess.Popen([ 'git', 'fast-import', '--quiet'], stdin=subprocess.PIPE)
- self._out = self._fi.stdin
- except OSError, err:
- raise GbpError, "Error spawning git fast-import: %s", err
- except ValueError, err:
- raise GbpError, "Invalid argument when spawning git fast-import: %s", err
-
- def _do_data(self, fd, size):
- self._out.write("data %s\n" % size)
- while True:
- data = fd.read(self._bufsize)
- self._out.write(data)
- if len(data) != self._bufsize:
- break
- self._out.write("\n")
-
- def _do_file(self, filename, mode, fd, size):
- name = "/".join(filename.split('/')[1:])
- self._out.write("M %d inline %s\n" % (mode, name))
- self._do_data(fd, size)
-
- def add_file(self, filename, fd, size):
- self._do_file(filename, self.m_regular, fd, size)
-
- def add_executable(self, filename, fd, size):
- self._do_file(filename, self.m_exec, fd, size)
-
- def add_symlink(self, filename, linkname):
- name = "/".join(filename.split('/')[1:])
- self._out.write("M %d inline %s\n" % (self.m_symlink, name))
- self._out.write("data %s\n" % len(linkname))
- self._out.write("%s\n" % linkname)
-
- def start_commit(self, branch, committer, email, time, msg):
- length = len(msg)
- self._out.write("""commit refs/heads/%(branch)s
-committer %(committer)s <%(email)s> %(time)s
-data %(length)s
-%(msg)s
-from refs/heads/%(branch)s^0
-""" % locals())
-
- def do_deleteall(self):
- self._out.write("deleteall\n")
-
- def close(self):
- if self._out:
- self._out.close()
- if self._fi:
- self._fi.wait()
-
- def __del__(self):
- self.close()
-
-
def cleanup_tmp_tree(tree):
"""remove a tree of temporary files"""
try: