/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

  • Committer: Jelmer Vernooij
  • Date: 2011-04-15 12:09:28 UTC
  • mto: (0.200.1189 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20110415120928-89ugek8lk992pla1
Implement GitWorkingTree.{_add,__iter__,id2path}.

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
        self._rules_searcher = None
93
93
        self._detect_case_handling()
94
94
 
 
95
    def _index_add_entry(self, path, file_id, kind):
 
96
        if kind == "directory":
 
97
            # Git indexes don't contain directories
 
98
            return
 
99
        if kind == "file":
 
100
            blob = Blob()
 
101
            try:
 
102
                file, stat_val = self.get_file_with_stat(file_id, path)
 
103
            except (errors.NoSuchFile, IOError):
 
104
                # TODO: Rather than come up with something here, use the old index
 
105
                file = StringIO()
 
106
                from posix import stat_result
 
107
                stat_val = stat_result((stat.S_IFREG | 0644, 0, 0, 0, 0, 0, 0, 0, 0, 0))
 
108
            blob.set_raw_string(file.read())
 
109
        elif kind == "symlink":
 
110
            blob = Blob()
 
111
            try:
 
112
                stat_val = os.lstat(self.abspath(path))
 
113
            except (errors.NoSuchFile, OSError):
 
114
                # TODO: Rather than come up with something here, use the 
 
115
                # old index
 
116
                from posix import stat_result
 
117
                stat_val = stat_result((stat.S_IFLNK, 0, 0, 0, 0, 0, 0, 0, 0, 0))
 
118
            blob.set_raw_string(self.get_symlink_target(file_id).encode("utf-8"))
 
119
        else:
 
120
            raise AssertionError("unknown kind '%s'" % kind)
 
121
        # Add object to the repository if it didn't exist yet
 
122
        if not blob.id in self.repository._git.object_store:
 
123
            self.repository._git.object_store.add_object(blob)
 
124
        # Add an entry to the index or update the existing entry
 
125
        flags = 0 # FIXME
 
126
        self.index[path.encode("utf-8")] = (stat_val.st_ctime,
 
127
                stat_val.st_mtime, stat_val.st_dev, stat_val.st_ino,
 
128
                stat_val.st_mode, stat_val.st_uid, stat_val.st_gid,
 
129
                stat_val.st_size, blob.id, flags)
 
130
 
 
131
    def _add(self, files, ids, kinds):
 
132
        for (path, file_id, kind) in zip(files, ids, kinds):
 
133
            self._index_add_entry(path, file_id, kind)
 
134
 
95
135
    def get_root_id(self):
96
136
        return self.mapping.generate_file_id("")
97
137
 
119
159
    def _rewrite_index(self):
120
160
        self.index.clear()
121
161
        for path, entry in self._inventory.iter_entries():
122
 
            if entry.kind == "directory":
123
 
                # Git indexes don't contain directories
124
 
                continue
125
 
            if entry.kind == "file":
126
 
                blob = Blob()
127
 
                try:
128
 
                    file, stat_val = self.get_file_with_stat(entry.file_id, path)
129
 
                except (errors.NoSuchFile, IOError):
130
 
                    # TODO: Rather than come up with something here, use the old index
131
 
                    file = StringIO()
132
 
                    from posix import stat_result
133
 
                    stat_val = stat_result((stat.S_IFREG | 0644, 0, 0, 0, 0, 0, 0, 0, 0, 0))
134
 
                blob.set_raw_string(file.read())
135
 
            elif entry.kind == "symlink":
136
 
                blob = Blob()
137
 
                try:
138
 
                    stat_val = os.lstat(self.abspath(path))
139
 
                except (errors.NoSuchFile, OSError):
140
 
                    # TODO: Rather than come up with something here, use the 
141
 
                    # old index
142
 
                    from posix import stat_result
143
 
                    stat_val = stat_result((stat.S_IFLNK, 0, 0, 0, 0, 0, 0, 0, 0, 0))
144
 
                blob.set_raw_string(self.get_symlink_target(entry.file_id).encode("utf-8"))
145
 
            else:
146
 
                raise AssertionError("unknown kind '%s'" % entry.kind)
147
 
            # Add object to the repository if it didn't exist yet
148
 
            if not blob.id in self.repository._git.object_store:
149
 
                self.repository._git.object_store.add_object(blob)
150
 
            # Add an entry to the index or update the existing entry
151
 
            flags = 0 # FIXME
152
 
            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)
 
162
            self._index_add_entry(path, entry.file_id, entry.kind)
153
163
 
154
164
    def flush(self):
155
165
        # TODO: Maybe this should only write on dirty ?
157
167
            raise errors.NotWriteLocked(self)
158
168
        self._rewrite_index()
159
169
        self.index.write()
160
 
        self._inventory_is_modified = False
161
170
 
162
171
    def __iter__(self):
163
 
        # FIXME: Custom implementation that doesn't require working tree
164
 
        return iter(self._bzr_inventory)
 
172
        for path in self.index:
 
173
            yield self._fileid_map.lookup_file_id(path)
165
174
 
166
175
    def id2path(self, file_id):
167
 
        # FIXME
168
 
        return self._bzr_inventory.id2path(file_id)
 
176
        if type(file_id) != str:
 
177
            raise AssertionError
 
178
        path = self._fileid_map.lookup_path(file_id)
 
179
        if path in self.index:
 
180
            return path
 
181
        raise errors.NoSuchId(None, file_id)
169
182
 
170
183
    def get_ignore_list(self):
171
184
        ignoreset = getattr(self, '_ignoreset', None)
188
201
        self._change_last_revision(revid)
189
202
 
190
203
    def _reset_data(self):
191
 
        self._inventory_is_modified = False
192
204
        try:
193
205
            head = self.repository._git.head()
194
206
        except KeyError, name:
196
208
        basis_inv = self.repository.get_inventory(self.branch.lookup_foreign_revision_id(head))
197
209
        store = self.repository._git.object_store
198
210
        if head == ZERO_SHA:
199
 
            fileid_map = GitFileIdMap({}, self.mapping)
 
211
            self._fileid_map = GitFileIdMap({}, self.mapping)
200
212
            basis_inv = None
201
213
        else:
202
 
            fileid_map = self.mapping.get_fileid_map(store.__getitem__,
 
214
            self._fileid_map = self.mapping.get_fileid_map(store.__getitem__,
203
215
                store[head].tree)
204
 
        result = GitIndexInventory(basis_inv, fileid_map, self.index, store)
 
216
        result = GitIndexInventory(basis_inv, self._fileid_map, self.index, store)
205
217
        self._bzr_inventory = result
206
218
 
207
219
    @needs_read_lock
208
220
    def get_file_sha1(self, file_id, path=None, stat_value=None):
209
221
        if not path:
210
 
            path = self._inventory.id2path(file_id)
 
222
            path = self.id2path(file_id)
211
223
        try:
212
224
            return osutils.sha_file_by_name(self.abspath(path).encode(osutils._fs_enc))
213
225
        except OSError, (num, msg):