/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to commit.py

Require dulwich 0.7.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from dulwich.index import (
22
22
    commit_tree,
23
23
    )
24
 
import os
25
24
import stat
26
25
 
 
26
from bzrlib.errors import (
 
27
    RootMissing,
 
28
    )
27
29
from bzrlib.repository import (
28
30
    CommitBuilder,
29
31
    )
41
43
 
42
44
 
43
45
class GitCommitBuilder(CommitBuilder):
 
46
    """Commit builder for Git repositories."""
 
47
 
 
48
    supports_record_entry_contents = False
44
49
 
45
50
    def __init__(self, *args, **kwargs):
46
51
        super(GitCommitBuilder, self).__init__(*args, **kwargs)
70
75
                blob = Blob()
71
76
                blob.data = workingtree.get_file_text(file_id, path)
72
77
                return blob.id
 
78
        seen_root = False
73
79
        for (file_id, path, changed_content, versioned, parent, name, kind,
74
80
             executable) in iter_changes:
75
81
            if kind[1] in ("directory",):
76
82
                if kind[0] in ("file", "symlink"):
77
83
                    self.record_delete(path[0], file_id)
 
84
                if path[1] == "":
 
85
                    seen_root = True
78
86
                continue
79
87
            if path[1] is None:
80
88
                self.record_delete(path[0], file_id)
87
95
                sha = link_sha1(path[1], file_id)
88
96
            elif kind[1] == "tree-reference":
89
97
                mode = S_IFGITLINK
90
 
                sha = "FIXME"
 
98
                sha = "FIXME" # FIXME
91
99
            else:
92
100
                raise AssertionError("Unknown kind %r" % kind[1])
93
101
            if executable[1]:
95
103
            self._any_changes = True
96
104
            self._blobs[path[1].encode("utf-8")] = (mode, sha)
97
105
            file_sha1 = workingtree.get_file_sha1(file_id, path[1])
98
 
            yield file_id, path[1], (file_sha1, os.lstat(workingtree.abspath(path[1])))
 
106
            _, st = workingtree.get_file_with_stat(file_id, path[1])
 
107
            yield file_id, path[1], (file_sha1, st)
 
108
        if not seen_root and len(self.parents) == 0:
 
109
            raise RootMissing()
99
110
        # Fill in entries that were not changed
100
111
        basis_tree = workingtree.basis_tree()
101
 
        assert basis_tree.get_revision_id() == basis_revid
 
112
        assert basis_tree.get_revision_id() == basis_revid, "expected %r == %r" % (
 
113
            basis_tree.get_revision_id(), basis_revid)
102
114
        for path, entry in basis_tree.iter_entries_by_dir():
103
115
            if entry.kind not in ("file", "symlink"):
104
116
                continue
109
121
                else:
110
122
                    blob.data = basis_tree.get_file_text(entry.file_id)
111
123
                self._blobs[path.encode("utf-8")] = (entry_mode(entry), blob.id)
 
124
        self.new_inventory = None
112
125
 
113
126
    def finish_inventory(self):
114
127
        # eliminate blobs that were removed
132
145
        c.encoding = 'utf-8'
133
146
        c.message = message.encode("utf-8")
134
147
        self.store.add_object(c)
 
148
        assert len(c.id) == 40
135
149
        self._new_revision_id = self.repository.get_mapping().revision_id_foreign_to_bzr(c.id)
136
150
        self.repository.commit_write_group()
137
151
        return self._new_revision_id