/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 workingtree.py

Fix support for older versions of Dulwich.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from dulwich.objects import (
26
26
    Blob,
27
27
    )
28
 
from dulwich.protocol import (
29
 
    ZERO_SHA,
30
 
    )
31
28
import os
32
29
import stat
33
30
 
39
36
    osutils,
40
37
    transport,
41
38
    tree,
 
39
    urlutils,
42
40
    workingtree,
43
41
    )
44
42
from bzrlib.decorators import (
53
51
    changes_from_git_changes,
54
52
    tree_delta_from_git_changes,
55
53
    )
56
 
from bzrlib.plugins.git.mapping import (
57
 
    GitFileIdMap,
58
 
    )
 
54
 
59
55
 
60
56
IGNORE_FILENAME = ".gitignore"
61
57
 
63
59
class GitWorkingTree(workingtree.WorkingTree):
64
60
    """A Git working tree."""
65
61
 
66
 
    def __init__(self, bzrdir, repo, branch, index):
 
62
    def __init__(self, bzrdir, repo, branch):
67
63
        self.basedir = bzrdir.root_transport.local_abspath('.')
68
64
        self.bzrdir = bzrdir
69
65
        self.repository = repo
71
67
        self._branch = branch
72
68
        self._transport = bzrdir.transport
73
69
 
74
 
        self.controldir = self.bzrdir.transport.local_abspath('bzr')
 
70
        self.controldir = urlutils.join(self.repository._git._controldir, 'bzr')
75
71
 
76
72
        try:
77
73
            os.makedirs(self.controldir)
82
78
        self._control_files = lockable_files.LockableFiles(
83
79
            transport.get_transport(self.controldir), 'lock', lockdir.LockDir)
84
80
        self._format = GitWorkingTreeFormat()
85
 
        self.index = index
 
81
        self.index = self.repository._git.open_index()
86
82
        self.views = self._make_views()
87
83
        self._detect_case_handling()
88
84
 
150
146
        # TODO: Maybe this should only write on dirty ?
151
147
        if self._control_files._lock_mode != 'w':
152
148
            raise errors.NotWriteLocked(self)
153
 
        self._rewrite_index()
 
149
        self._rewrite_index()           
154
150
        self.index.write()
155
151
        self._inventory_is_modified = False
156
152
 
176
172
 
177
173
    def _reset_data(self):
178
174
        self._inventory_is_modified = False
179
 
        try:
180
 
            head = self.repository._git.head()
181
 
        except KeyError, name:
182
 
            raise errors.NotBranchError("branch %s at %s" % (name, self.repository.base))
183
 
        basis_inv = self.repository.get_inventory(self.branch.lookup_foreign_revision_id(head))
184
 
        store = self.repository._git.object_store
185
 
        if head == ZERO_SHA:
186
 
            fileid_map = GitFileIdMap({}, self.mapping)
187
 
            basis_inv = None
188
 
        else:
189
 
            fileid_map = self.mapping.get_fileid_map(store.__getitem__,
190
 
                store[head].tree)
191
 
        result = GitIndexInventory(basis_inv, fileid_map, self.index, store)
 
175
        basis_inv = self.repository.get_inventory(self.mapping.revision_id_foreign_to_bzr(self.repository._git.head()))
 
176
        result = GitIndexInventory(basis_inv, self.mapping, self.index,
 
177
            self.repository._git.object_store)
192
178
        self._set_inventory(result, dirty=False)
193
179
 
194
180
    @needs_read_lock
215
201
 
216
202
    @property
217
203
    def _matchingbzrdir(self):
218
 
        from bzrlib.plugins.git import LocalGitControlDirFormat
219
 
        return LocalGitControlDirFormat()
 
204
        from bzrlib.plugins.git import LocalGitBzrDirFormat
 
205
        return LocalGitBzrDirFormat()
220
206
 
221
207
    def get_format_description(self):
222
208
        return "Git Working Tree"
241
227
        changes = self._index.changes_from_tree(
242
228
            self.source._repository._git.object_store, self.source.tree, 
243
229
            want_unchanged=want_unchanged)
244
 
        source_fileid_map = self.source.mapping.get_fileid_map(
245
 
            self.source._repository._git.object_store.__getitem__,
246
 
            self.source.tree)
247
 
        if self.target.mapping.BZR_FILE_IDS_FILE is not None:
248
 
            file_id = self.target.path2id(
249
 
                self.target.mapping.BZR_FILE_IDS_FILE)
250
 
            if file_id is None:
251
 
                target_fileid_map = {}
252
 
            else:
253
 
                target_fileid_map = self.target.mapping.import_fileid_map(Blob.from_string(self.target.get_file_text(file_id)))
254
 
        else:
255
 
            target_fileid_map = {}
256
 
        target_fileid_map = GitFileIdMap(target_fileid_map, self.target.mapping)
257
 
        ret = tree_delta_from_git_changes(changes, self.target.mapping,
258
 
            (source_fileid_map, target_fileid_map),
 
230
        ret = tree_delta_from_git_changes(changes, self.target.mapping, 
259
231
            specific_file=specific_files, require_versioned=require_versioned)
260
232
        if want_unversioned:
261
233
            for e in self.target.extras():