/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

Simply refer to bzr's docs in HACKING.

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,
40
37
    transport,
 
38
    tree,
41
39
    urlutils,
42
40
    workingtree,
43
41
    )
44
42
from bzrlib.decorators import (
45
43
    needs_read_lock,
46
 
    needs_write_lock,
47
44
    )
48
45
 
49
46
 
50
47
from bzrlib.plugins.git.inventory import (
51
48
    GitIndexInventory,
52
49
    )
 
50
from bzrlib.plugins.git.tree import (
 
51
    changes_from_git_changes,
 
52
    tree_delta_from_git_changes,
 
53
    )
53
54
 
54
55
 
55
56
IGNORE_FILENAME = ".gitignore"
81
82
        self.views = self._make_views()
82
83
        self._detect_case_handling()
83
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
 
84
97
    def unlock(self):
85
98
        # non-implementation specific cleanup
86
99
        self._cleanup()
107
120
                except (errors.NoSuchFile, IOError):
108
121
                    # TODO: Rather than come up with something here, use the old index
109
122
                    file = StringIO()
110
 
                    stat_val = (0, 0, 0, 0, stat.S_IFREG | 0644, 0, 0, 0, 0, 0)
111
 
                blob._text = file.read()
 
123
                    from posix import stat_result
 
124
                    stat_val = stat_result((stat.S_IFREG | 0644, 0, 0, 0, 0, 0, 0, 0, 0, 0))
 
125
                blob.set_raw_string(file.read())
112
126
            elif entry.kind == "symlink":
113
127
                blob = Blob()
114
 
                stat_val = os.stat(self.abspath(path))
115
 
                blob._text = entry.symlink_target
 
128
                try:
 
129
                    stat_val = os.lstat(self.abspath(path))
 
130
                except (errors.NoSuchFile, OSError):
 
131
                    # TODO: Rather than come up with something here, use the 
 
132
                    # old index
 
133
                    from posix import stat_result
 
134
                    stat_val = stat_result((stat.S_IFLNK, 0, 0, 0, 0, 0, 0, 0, 0, 0))
 
135
                blob.set_raw_string(entry.symlink_target)
116
136
            # Add object to the repository if it didn't exist yet
117
137
            if not blob.id in self.repository._git.object_store:
118
138
                self.repository._git.object_store.add_object(blob)
119
139
            # Add an entry to the index or update the existing entry
120
 
            (mode, ino, dev, links, uid, gid, size, atime, mtime, ctime) = stat_val
121
 
            flags = 0
122
 
            self.index[path.encode("utf-8")] = (ctime, mtime, ino, dev, mode, uid, gid, size, blob.id, flags)
 
140
            flags = 0 # FIXME
 
141
            self.index[path.encode("utf-8")] = (stat_val.st_ctime, stat_val.st_mtime, stat_val.st_dev, stat_val.st_ino, stat_val.st_mode, stat_val.st_uid, stat_val.st_gid, stat_val.st_size, blob.id, flags)
123
142
 
124
143
    def flush(self):
125
144
        # TODO: Maybe this should only write on dirty ?
146
165
        self._ignoreset = ignore_globs
147
166
        return ignore_globs
148
167
 
 
168
    def set_last_revision(self, revid):
 
169
        self._change_last_revision(revid)
 
170
 
149
171
    def _reset_data(self):
150
172
        self._inventory_is_modified = False
151
173
        basis_inv = self.repository.get_inventory(self.mapping.revision_id_foreign_to_bzr(self.repository._git.head()))
152
 
        result = GitIndexInventory(basis_inv, self.mapping, self.index)
 
174
        result = GitIndexInventory(basis_inv, self.mapping, self.index,
 
175
            self.repository._git.object_store)
153
176
        self._set_inventory(result, dirty=False)
154
177
 
155
178
    @needs_read_lock
156
179
    def get_file_sha1(self, file_id, path=None, stat_value=None):
157
180
        if not path:
158
181
            path = self._inventory.id2path(file_id)
159
 
        return osutils.sha_file_by_name(self.abspath(path).encode(osutils._fs_enc))
 
182
        try:
 
183
            return osutils.sha_file_by_name(self.abspath(path).encode(osutils._fs_enc))
 
184
        except OSError, (num, msg):
 
185
            if num in (errno.EISDIR, errno.ENOENT):
 
186
                return None
 
187
            raise
 
188
 
 
189
    def revision_tree(self, revid):
 
190
        return self.repository.revision_tree(revid)
 
191
 
 
192
    @needs_read_lock
 
193
    def conflicts(self):
 
194
        # FIXME:
 
195
        return []
160
196
 
161
197
 
162
198
class GitWorkingTreeFormat(workingtree.WorkingTreeFormat):
163
199
 
164
200
    def get_format_description(self):
165
201
        return "Git Working Tree"
 
202
 
 
203
 
 
204
class InterIndexGitTree(tree.InterTree):
 
205
    """InterTree that works between a Git revision tree and an index."""
 
206
 
 
207
    def __init__(self, source, target):
 
208
        super(InterIndexGitTree, self).__init__(source, target)
 
209
        self._index = target.index
 
210
 
 
211
    @classmethod
 
212
    def is_compatible(cls, source, target):
 
213
        from bzrlib.plugins.git.repository import GitRevisionTree
 
214
        return (isinstance(source, GitRevisionTree) and 
 
215
                isinstance(target, GitWorkingTree))
 
216
 
 
217
    def compare(self, want_unchanged=False, specific_files=None,
 
218
                extra_trees=None, require_versioned=False, include_root=False,
 
219
                want_unversioned=False):
 
220
        changes = self._index.changes_from_tree(
 
221
            self.source._repository._git.object_store, self.source.tree, 
 
222
            want_unchanged=want_unchanged)
 
223
        ret = tree_delta_from_git_changes(changes, self.target.mapping, 
 
224
            specific_file=specific_files, require_versioned=require_versioned)
 
225
        if want_unversioned:
 
226
            for e in self.target.extras():
 
227
                ret.unversioned.append((e, None, osutils.file_kind(self.target.abspath(e))))
 
228
        return ret
 
229
 
 
230
    def iter_changes(self, include_unchanged=False, specific_files=None,
 
231
        pb=None, extra_trees=[], require_versioned=True, want_unversioned=False):
 
232
        changes = self._index.changes_from_tree(
 
233
            self.source._repository._git.object_store, self.source.tree, 
 
234
            want_unchanged=include_unchanged)
 
235
        # FIXME: Handle want_unversioned
 
236
        return changes_from_git_changes(changes, self.target.mapping, 
 
237
            specific_file=specific_files)
 
238
 
 
239
tree.InterTree.register_optimiser(InterIndexGitTree)