92
92
self._rules_searcher = None
93
93
self._detect_case_handling()
95
def _index_add_entry(self, path, file_id, kind):
96
if kind == "directory":
97
# Git indexes don't contain directories
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
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":
112
stat_val = os.lstat(self.abspath(path))
113
except (errors.NoSuchFile, OSError):
114
# TODO: Rather than come up with something here, use the
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"))
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
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)
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)
95
135
def get_root_id(self):
96
136
return self.mapping.generate_file_id("")
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
125
if entry.kind == "file":
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
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":
138
stat_val = os.lstat(self.abspath(path))
139
except (errors.NoSuchFile, OSError):
140
# TODO: Rather than come up with something here, use the
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"))
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
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)
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
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)
166
175
def id2path(self, file_id):
168
return self._bzr_inventory.id2path(file_id)
176
if type(file_id) != str:
178
path = self._fileid_map.lookup_path(file_id)
179
if path in self.index:
181
raise errors.NoSuchId(None, file_id)
170
183
def get_ignore_list(self):
171
184
ignoreset = getattr(self, '_ignoreset', None)
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)
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
208
220
def get_file_sha1(self, file_id, path=None, stat_value=None):
210
path = self._inventory.id2path(file_id)
222
path = self.id2path(file_id)
212
224
return osutils.sha_file_by_name(self.abspath(path).encode(osutils._fs_enc))
213
225
except OSError, (num, msg):