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
18
"""Support for committing in native Git working trees."""
21
from dulwich.index import (
26
from bzrlib.repository import (
30
from dulwich.objects import (
37
class GitCommitBuilder(CommitBuilder):
39
def __init__(self, *args, **kwargs):
40
super(GitCommitBuilder, self).__init__(*args, **kwargs)
43
def record_delete(self, path, file_id):
44
self._blobs[path] = None
46
def record_iter_changes(self, workingtree, basis_revid, iter_changes):
47
index = getattr(workingtree, "index", None)
49
def index_sha1(path, file_id):
50
return index.get_sha1(path.encode("utf-8"))
51
text_sha1 = link_sha1 = index_sha1
53
def link_sha1(path, file_id):
55
blob.data = workingtree.get_symlink_target(file_id)
57
def text_sha1(path, file_id):
59
blob.data = workingtree.get_file_text(file_id, path)
61
for (file_id, path, changed_content, versioned, parent, name, kind,
62
executable) in iter_changes:
63
if kind[1] in ("directory",):
64
if kind[0] in ("file", "symlink"):
65
self.record_delete(path[0], file_id)
68
self.record_delete(path[0], file_id)
72
sha = text_sha1(path[1], file_id)
75
sha = link_sha1(path[1], file_id)
78
self._blobs[path[1].encode("utf-8")] = (mode, sha)
79
yield file_id, path, (None, None)
80
# FIXME: Import all blobs not set yet, and eliminate blobs set to None
82
def commit(self, message):
84
c.tree = commit_tree(self.repository._git.object_store, self._blobs)
85
c.committer = self._committer
86
c.author = self._revprops.get('author', self._committer)
87
c.commit_timestamp = self._timestamp
88
c.author_timestamp = self._timestamp
89
c.commit_timezone = self._timezone
90
c.author_timezone = self._timezone
91
c.message = message.encode("utf-8")
92
self.repository._git.object_store.add_object(c)
93
return self.repository.mapping.revision_id_foreign_to_bzr(c.id)