modCnt.incrementAndGet();
fireRefsChanged();
}
void delete(RefDirectoryUpdate update) throws IOException {
Ref dst = update.getRef().getLeaf();
String name = dst.getName();
// Write the packed-refs file using an atomic update. We might
// wind up reading it twice, before and after the lock, to ensure
// we don't miss an edit made externally.
final PackedRefList packed = getPackedRefs();
if (packed.contains(name)) {
LockFile lck = new LockFile(packedRefsFile,
update.getRepository().getFS());
if (!lck.lock())
throw new IOException(MessageFormat.format(
JGitText.get().cannotLockFile, packedRefsFile));
try {
PackedRefList cur = readPackedRefs();
int idx = cur.find(name);
if (0 <= idx)
commitPackedRefs(lck, cur.remove(idx), packed);
} finally {
lck.unlock();
}
}
RefList<LooseRef> curLoose, newLoose;
do {
curLoose = looseRefs.get();
int idx = curLoose.find(name);
if (idx < 0)
break;
newLoose = curLoose.remove(idx);
} while (!looseRefs.compareAndSet(curLoose, newLoose));
int levels = levelsIn(name) - 2;
delete(logFor(name), levels);
if (dst.getStorage().isLoose()) {
update.unlock();
delete(fileFor(name), levels);
}
modCnt.incrementAndGet();