1
# Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
from bzrlib.repository import (
21
from dulwich.objects import (
27
class GitCommitBuilder(CommitBuilder):
29
def __init__(self, *args, **kwargs):
30
super(GitCommitBuilder, self).__init__(*args, **kwargs)
33
def _add_tree(self, path):
34
dirname, basename = osutils.split(path)
35
t = self._add_tree(dirname)
38
# FIXME: Inherit children from the base revision
41
def _change_blob(self, path, value):
42
dirname, basename = osutils.split(path)
43
t = self._add_tree(dirname)
46
def record_delete(self, path, file_id):
47
dirname, basename = osutils.split(path)
48
t = self._add_tree(dirname)
51
def record_iter_changes(self, workingtree, basis_revid, iter_changes):
52
for (file_id, path, changed_content, versioned, parent, name, kind,
53
executable) in iter_changes:
54
if kind[1] in ("directory",):
55
if kind[0] in ("file", "symlink"):
56
self.record_delete(path[0], file_id)
64
self._change_blob(path, (mode, workingtree.index.get_sha1(path)))
65
yield file_id, path, None
67
def commit(self, message)
68
# FIXME: Eliminate any empty trees recursively
69
# Write any tree objects to disk
70
for path in sorted(self._trees.keys(), reverse=True):
71
self.repository._git.object_store.add_object(self._trees[path])
73
root_tree = self._add_tree("")
74
c._tree = root_tree.id
75
c._committer = self._committer
76
c._author = self._revprops.get('author', self._committer)
77
c._commit_timestamp = self._timestamp
78
c._author_timestamp = self._timestamp
79
c._commit_timezone = self._timezone
80
c._author_timezone = self._timezone
81
c._message = message.encode("utf-8")
82
self.repository._git.object_store.add_object(c)