private void buildIndex(HashMap<String, String> indexEntries) throws IOException {
dirCache = new DirCache(db.getIndexFile(), db.getFS());
if (indexEntries != null) {
assertTrue(dirCache.lock());
DirCacheEditor editor = dirCache.editor();
for (java.util.Map.Entry<String,String> e : indexEntries.entrySet()) {
writeTrashFile(e.getKey(), e.getValue());
ObjectInserter inserter = db.newObjectInserter();
final ObjectId id = inserter.insert(Constants.OBJ_BLOB,
Constants.encode(e.getValue()));
editor.add(new DirCacheEditor.DeletePath(e.getKey()));
editor.add(new DirCacheEditor.PathEdit(e.getKey()) {
@Override
public void apply(DirCacheEntry ent) {
ent.setFileMode(FileMode.REGULAR_FILE);
ent.setObjectId(id);
ent.setUpdateNeeded(false);
}
});
}
assertTrue(editor.commit());
}
}