diff options
author | Guido Günther <agx@sigxcpu.org> | 2011-11-20 13:58:14 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2011-11-20 14:31:49 +0100 |
commit | d616dd152f1e30a58db176826d8c5d05612ef5e9 (patch) | |
tree | ce1caf34f71530b6332e51dce2ce0725d61780cd /gbp/git/__init__.py | |
parent | e87e62fc4969cb7d21e5fb07f7da505f48355e05 (diff) |
Move FastImport to separate file
Diffstat (limited to 'gbp/git/__init__.py')
-rw-r--r-- | gbp/git/__init__.py | 67 |
1 files changed, 1 insertions, 66 deletions
diff --git a/gbp/git/__init__.py b/gbp/git/__init__.py index 7c48444..775da63 100644 --- a/gbp/git/__init__.py +++ b/gbp/git/__init__.py @@ -28,6 +28,7 @@ import calendar from gbp.git.modifier import GitModifier from gbp.git.commit import GitCommit from gbp.git.errors import GitError +from gbp.git.fastimport import FastImport class GitRepositoryError(GitError): """Exception thrown by L{GitRepository}""" @@ -1194,72 +1195,6 @@ class GitRepository(object): return None #} - -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 as err: - raise GbpError("Error spawning git fast-import: %s" % err) - except ValueError as 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 build_tag(format, version): """Generate a tag from a given format and a version |