bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.387
by Jelmer Vernooij
Initial work on supporting commit in git trees. |
1 |
# Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org>
|
2 |
#
|
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
16 |
||
17 |
from bzrlib.repository import ( |
|
18 |
CommitBuilder, |
|
19 |
)
|
|
20 |
||
21 |
from dulwich.objects import ( |
|
22 |
Commit, |
|
23 |
Tree, |
|
24 |
)
|
|
25 |
||
26 |
||
27 |
class GitCommitBuilder(CommitBuilder): |
|
28 |
||
29 |
def __init__(self, *args, **kwargs): |
|
30 |
super(GitCommitBuilder, self).__init__(*args, **kwargs) |
|
31 |
self._trees = {} |
|
32 |
||
33 |
def _add_tree(self, path): |
|
34 |
dirname, basename = osutils.split(path) |
|
35 |
t = self._add_tree(dirname) |
|
36 |
if not basename in t: |
|
37 |
t[basename] = Tree() |
|
38 |
# FIXME: Inherit children from the base revision
|
|
39 |
return t[basename] |
|
40 |
||
41 |
def _change_blob(self, path, value): |
|
42 |
dirname, basename = osutils.split(path) |
|
43 |
t = self._add_tree(dirname) |
|
44 |
t[basename] = value |
|
45 |
||
46 |
def record_delete(self, path, file_id): |
|
47 |
dirname, basename = osutils.split(path) |
|
48 |
t = self._add_tree(dirname) |
|
49 |
del t[basename] |
|
50 |
||
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) |
|
57 |
continue
|
|
58 |
if kind == "file": |
|
59 |
mode = stat.S_IFREG |
|
60 |
else: |
|
61 |
mode = stat.S_IFLNK |
|
62 |
if executable: |
|
63 |
mode |= 0111 |
|
64 |
self._change_blob(path, (mode, workingtree.index.get_sha1(path))) |
|
65 |
yield file_id, path, None |
|
66 |
||
0.200.391
by Jelmer Vernooij
Fix syntax error. |
67 |
def commit(self, message): |
0.200.387
by Jelmer Vernooij
Initial work on supporting commit in git trees. |
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]) |
|
72 |
c = Commit() |
|
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) |