38
39
def __init__(self, *args, **kwargs):
39
40
super(GitCommitBuilder, self).__init__(*args, **kwargs)
42
def _new_tree(self, path):
44
# FIXME: Inherit children from the base revision
45
self._trees[path] = newtree
48
def _add_tree(self, path):
49
if path in self._trees:
50
return self._trees[path]
52
return self._new_tree("")
53
dirname, basename = osutils.split(path)
54
t = self._add_tree(dirname)
55
assert isinstance(basename, str)
57
newtree = self._new_tree(path)
58
t[basename] = (stat.S_IFDIR, newtree.id)
61
return self.repository._git.object_store[t[basename][1]]
63
def _change_blob(self, path, value):
64
assert isinstance(path, str)
65
dirname, basename = osutils.split(path)
66
t = self._add_tree(dirname)
69
43
def record_delete(self, path, file_id):
70
dirname, basename = osutils.split(path)
71
t = self._add_tree(dirname)
44
self._blobs[path] = None
74
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)
75
61
for (file_id, path, changed_content, versioned, parent, name, kind,
76
62
executable) in iter_changes:
77
63
if kind[1] in ("directory",):
82
68
mode = stat.S_IFREG
69
sha = text_sha1(path[1], file_id)
84
71
mode = stat.S_IFLNK
72
sha = link_sha1(path[1], file_id)
87
self._change_blob(path[1].encode("utf-8"), (mode, workingtree.index.get_sha1(path[1].encode("utf-8"))))
75
self._blobs[path[1].encode("utf-8")] = (mode, sha))
88
76
yield file_id, path, (None, None)
77
# FIXME: Import all blobs not set yet, and eliminate blobs set to None
90
79
def commit(self, message):
91
# FIXME: Eliminate any empty trees recursively
92
# Write any tree objects to disk
93
for path in sorted(self._trees.keys(), reverse=True):
94
self.repository._git.object_store.add_object(self._trees[path])
96
root_tree = self._add_tree("")
81
c.tree = commit_tree(self.repository._git.object_store, self._blobs)
98
82
c.committer = self._committer
99
83
c.author = self._revprops.get('author', self._committer)
100
84
c.commit_timestamp = self._timestamp