private void ApplyEdits()
{
_edits.Sort(EditComparison);
int maxIdx = Cache.getEntryCount();
int lastIdx = 0;
foreach (PathEdit e in _edits)
{
int eIdx = Cache.findEntry(e.Path, e.Path.Length);
bool missing = eIdx < 0;
if (eIdx < 0)
{
eIdx = -(eIdx + 1);
}
int cnt = Math.Min(eIdx, maxIdx) - lastIdx;
if (cnt > 0)
{
FastKeep(lastIdx, cnt);
}
lastIdx = missing ? eIdx : Cache.nextEntry(eIdx);
if (e is DeletePath)
{
continue;
}
if (e is DeleteTree)
{
lastIdx = Cache.nextEntry(e.Path, e.Path.Length, eIdx);
continue;
}
DirCacheEntry ent;
if (missing)
{
ent = new DirCacheEntry(e.Path);
e.Apply(ent);
if (ent.getRawMode() == 0)
{
throw new ArgumentException("FileMode not set"
+ " for path " + ent.getPathString());
}
}
else
{
ent = Cache.getEntry(eIdx);
e.Apply(ent);
}
FastAdd(ent);
}
int count = maxIdx - lastIdx;
if (count > 0)
{
FastKeep(lastIdx, count);
}
}