/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:
21
21
from cStringIO import (
22
22
    StringIO,
23
23
    )
24
 
from dulwich.index import (
25
 
    Index,
26
 
    )
 
24
import errno
27
25
from dulwich.objects import (
28
26
    Blob,
29
27
    )
33
31
from bzrlib import (
34
32
    errors,
35
33
    ignores,
36
 
    inventory,
37
34
    lockable_files,
38
35
    lockdir,
39
36
    osutils,
44
41
    )
45
42
from bzrlib.decorators import (
46
43
    needs_read_lock,
47
 
    needs_write_lock,
48
44
    )
49
45
 
50
46
 
51
47
from bzrlib.plugins.git.inventory import (
52
48
    GitIndexInventory,
53
49
    )
 
50
from bzrlib.plugins.git.tree import (
 
51
    changes_from_git_changes,
 
52
    tree_delta_from_git_changes,
 
53
    )
54
54
 
55
55
 
56
56
IGNORE_FILENAME = ".gitignore"
82
82
        self.views = self._make_views()
83
83
        self._detect_case_handling()
84
84
 
 
85
    def extras(self):
 
86
        """Yield all unversioned files in this WorkingTree.
 
87
        """
 
88
        for (dirpath, dirnames, filenames) in os.walk(self.basedir):
 
89
            if self.bzrdir.is_control_filename(dirpath[len(self.basedir):].strip("/")):
 
90
                continue
 
91
            for filename in filenames:
 
92
                relpath = os.path.join(dirpath[len(self.basedir):].strip("/"), filename)
 
93
                if not relpath in self.index:
 
94
                    yield relpath
 
95
 
 
96
 
85
97
    def unlock(self):
86
98
        # non-implementation specific cleanup
87
99
        self._cleanup()
108
120
                except (errors.NoSuchFile, IOError):
109
121
                    # TODO: Rather than come up with something here, use the old index
110
122
                    file = StringIO()
111
 
                    stat_val = (0, 0, 0, 0, stat.S_IFREG | 0644, 0, 0, 0, 0, 0)
 
123
                    from posix import stat_result
 
124
                    stat_val = stat_result((stat.S_IFREG | 0644, 0, 0, 0, 0, 0, 0, 0, 0, 0))
112
125
                blob.set_raw_string(file.read())
113
126
            elif entry.kind == "symlink":
114
127
                blob = Blob()
117
130
                except (errors.NoSuchFile, OSError):
118
131
                    # TODO: Rather than come up with something here, use the 
119
132
                    # old index
120
 
                    stat_val = (0, 0, 0, 0, stat.S_IFLNK, 0, 0, 0, 0, 0)
 
133
                    from posix import stat_result
 
134
                    stat_val = stat_result((stat.S_IFLNK, 0, 0, 0, 0, 0, 0, 0, 0, 0))
121
135
                blob.set_raw_string(entry.symlink_target)
 
136
            else:
 
137
                raise AssertionError("unknown kind '%s'" % entry.kind)
122
138
            # Add object to the repository if it didn't exist yet
123
139
            if not blob.id in self.repository._git.object_store:
124
140
                self.repository._git.object_store.add_object(blob)
165
181
    def get_file_sha1(self, file_id, path=None, stat_value=None):
166
182
        if not path:
167
183
            path = self._inventory.id2path(file_id)
168
 
        return osutils.sha_file_by_name(self.abspath(path).encode(osutils._fs_enc))
169
 
 
170
 
    def iter_changes(self, from_tree, include_unchanged=False,
171
 
                     specific_files=None, pb=None, extra_trees=None,
172
 
                     require_versioned=True, want_unversioned=False):
173
 
 
174
 
        intertree = tree.InterTree.get(from_tree, self)
175
 
        return intertree.iter_changes(include_unchanged, specific_files, pb,
176
 
            extra_trees, require_versioned, want_unversioned=want_unversioned)
 
184
        try:
 
185
            return osutils.sha_file_by_name(self.abspath(path).encode(osutils._fs_enc))
 
186
        except OSError, (num, msg):
 
187
            if num in (errno.EISDIR, errno.ENOENT):
 
188
                return None
 
189
            raise
 
190
 
 
191
    def revision_tree(self, revid):
 
192
        return self.repository.revision_tree(revid)
 
193
 
 
194
    @needs_read_lock
 
195
    def conflicts(self):
 
196
        # FIXME:
 
197
        return []
177
198
 
178
199
 
179
200
class GitWorkingTreeFormat(workingtree.WorkingTreeFormat):
180
201
 
 
202
    @property
 
203
    def _matchingbzrdir(self):
 
204
        from bzrlib.plugins.git import LocalGitBzrDirFormat
 
205
        return LocalGitBzrDirFormat()
 
206
 
181
207
    def get_format_description(self):
182
208
        return "Git Working Tree"
 
209
 
 
210
 
 
211
class InterIndexGitTree(tree.InterTree):
 
212
    """InterTree that works between a Git revision tree and an index."""
 
213
 
 
214
    def __init__(self, source, target):
 
215
        super(InterIndexGitTree, self).__init__(source, target)
 
216
        self._index = target.index
 
217
 
 
218
    @classmethod
 
219
    def is_compatible(cls, source, target):
 
220
        from bzrlib.plugins.git.repository import GitRevisionTree
 
221
        return (isinstance(source, GitRevisionTree) and 
 
222
                isinstance(target, GitWorkingTree))
 
223
 
 
224
    def compare(self, want_unchanged=False, specific_files=None,
 
225
                extra_trees=None, require_versioned=False, include_root=False,
 
226
                want_unversioned=False):
 
227
        changes = self._index.changes_from_tree(
 
228
            self.source._repository._git.object_store, self.source.tree, 
 
229
            want_unchanged=want_unchanged)
 
230
        ret = tree_delta_from_git_changes(changes, self.target.mapping, 
 
231
            specific_file=specific_files, require_versioned=require_versioned)
 
232
        if want_unversioned:
 
233
            for e in self.target.extras():
 
234
                ret.unversioned.append((e, None, osutils.file_kind(self.target.abspath(e))))
 
235
        return ret
 
236
 
 
237
    def iter_changes(self, include_unchanged=False, specific_files=None,
 
238
        pb=None, extra_trees=[], require_versioned=True, want_unversioned=False):
 
239
        changes = self._index.changes_from_tree(
 
240
            self.source._repository._git.object_store, self.source.tree, 
 
241
            want_unchanged=include_unchanged)
 
242
        # FIXME: Handle want_unversioned
 
243
        return changes_from_git_changes(changes, self.target.mapping, 
 
244
            specific_file=specific_files)
 
245
 
 
246
tree.InterTree.register_optimiser(InterIndexGitTree)