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 |
||
0.200.405
by Jelmer Vernooij
More work on commit. |
17 |
|
18 |
"""Support for committing in native Git working trees."""
|
|
19 |
||
20 |
||
0.200.459
by Jelmer Vernooij
Use new commit_tree function from dulwich. |
21 |
from dulwich.index import ( |
22 |
commit_tree, |
|
23 |
)
|
|
0.200.405
by Jelmer Vernooij
More work on commit. |
24 |
import stat |
25 |
||
0.200.387
by Jelmer Vernooij
Initial work on supporting commit in git trees. |
26 |
from bzrlib.repository import ( |
27 |
CommitBuilder, |
|
28 |
)
|
|
29 |
||
30 |
from dulwich.objects import ( |
|
0.200.459
by Jelmer Vernooij
Use new commit_tree function from dulwich. |
31 |
Blob, |
0.200.387
by Jelmer Vernooij
Initial work on supporting commit in git trees. |
32 |
Commit, |
33 |
Tree, |
|
34 |
)
|
|
35 |
||
36 |
||
37 |
class GitCommitBuilder(CommitBuilder): |
|
38 |
||
39 |
def __init__(self, *args, **kwargs): |
|
40 |
super(GitCommitBuilder, self).__init__(*args, **kwargs) |
|
0.200.459
by Jelmer Vernooij
Use new commit_tree function from dulwich. |
41 |
self._blobs = {} |
0.200.387
by Jelmer Vernooij
Initial work on supporting commit in git trees. |
42 |
|
43 |
def record_delete(self, path, file_id): |
|
0.200.459
by Jelmer Vernooij
Use new commit_tree function from dulwich. |
44 |
self._blobs[path] = None |
0.200.387
by Jelmer Vernooij
Initial work on supporting commit in git trees. |
45 |
|
46 |
def record_iter_changes(self, workingtree, basis_revid, iter_changes): |
|
0.200.459
by Jelmer Vernooij
Use new commit_tree function from dulwich. |
47 |
index = getattr(workingtree, "index", None) |
48 |
if index is not None: |
|
49 |
def index_sha1(path, file_id): |
|
50 |
return index.get_sha1(path.encode("utf-8")) |
|
51 |
text_sha1 = link_sha1 = index_sha1 |
|
52 |
else: |
|
53 |
def link_sha1(path, file_id): |
|
54 |
blob = Blob() |
|
55 |
blob.data = workingtree.get_symlink_target(file_id) |
|
56 |
return blob.id |
|
57 |
def text_sha1(path, file_id): |
|
58 |
blob = Blob() |
|
59 |
blob.data = workingtree.get_file_text(file_id, path) |
|
60 |
return blob.id |
|
0.200.387
by Jelmer Vernooij
Initial work on supporting commit in git trees. |
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) |
|
66 |
continue
|
|
0.200.460
by Jelmer Vernooij
Somewhat fix commit in git working trees. |
67 |
if path[1] is None: |
68 |
self.record_delete(path[0], file_id) |
|
69 |
continue
|
|
0.200.387
by Jelmer Vernooij
Initial work on supporting commit in git trees. |
70 |
if kind == "file": |
71 |
mode = stat.S_IFREG |
|
0.200.459
by Jelmer Vernooij
Use new commit_tree function from dulwich. |
72 |
sha = text_sha1(path[1], file_id) |
0.200.387
by Jelmer Vernooij
Initial work on supporting commit in git trees. |
73 |
else: |
74 |
mode = stat.S_IFLNK |
|
0.200.459
by Jelmer Vernooij
Use new commit_tree function from dulwich. |
75 |
sha = link_sha1(path[1], file_id) |
0.200.387
by Jelmer Vernooij
Initial work on supporting commit in git trees. |
76 |
if executable: |
77 |
mode |= 0111 |
|
0.200.460
by Jelmer Vernooij
Somewhat fix commit in git working trees. |
78 |
self._blobs[path[1].encode("utf-8")] = (mode, sha) |
0.200.405
by Jelmer Vernooij
More work on commit. |
79 |
yield file_id, path, (None, None) |
0.200.459
by Jelmer Vernooij
Use new commit_tree function from dulwich. |
80 |
# FIXME: Import all blobs not set yet, and eliminate blobs set to None
|
0.200.387
by Jelmer Vernooij
Initial work on supporting commit in git trees. |
81 |
|
0.200.391
by Jelmer Vernooij
Fix syntax error. |
82 |
def commit(self, message): |
0.200.387
by Jelmer Vernooij
Initial work on supporting commit in git trees. |
83 |
c = Commit() |
0.200.459
by Jelmer Vernooij
Use new commit_tree function from dulwich. |
84 |
c.tree = commit_tree(self.repository._git.object_store, self._blobs) |
0.200.416
by Jelmer Vernooij
Use public properties to set git objects values. |
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") |
|
0.200.387
by Jelmer Vernooij
Initial work on supporting commit in git trees. |
92 |
self.repository._git.object_store.add_object(c) |
0.200.459
by Jelmer Vernooij
Use new commit_tree function from dulwich. |
93 |
return self.repository.mapping.revision_id_foreign_to_bzr(c.id) |