Browse Source

Short-circuit writing packed-refs if no refs were packed

Change-Id: Id691905599b242e48f590138a96e0c86132308fd
stable-4.9
Dave Borowitz 8 years ago
parent
commit
e08fa5afcd
  1. 28
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

28
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

@ -647,16 +647,32 @@ public class RefDirectory extends RefDatabase {
RefList<Ref> cur = readPackedRefs(); RefList<Ref> cur = readPackedRefs();
// Iterate over all refs to be packed // Iterate over all refs to be packed
boolean dirty = false;
for (String refName : refs) { for (String refName : refs) {
Ref ref = readRef(refName, cur); Ref oldRef = readRef(refName, cur);
if (ref.isSymbolic()) if (oldRef.isSymbolic()) {
continue; // can't pack symbolic refs continue; // can't pack symbolic refs
}
// Add/Update it to packed-refs // Add/Update it to packed-refs
Ref newRef = peeledPackedRef(oldRef);
if (newRef == oldRef) {
// No-op; peeledPackedRef returns the input ref only if it's already
// packed, and readRef returns a packed ref only if there is no loose
// ref.
continue;
}
dirty = true;
int idx = cur.find(refName); int idx = cur.find(refName);
if (idx >= 0) if (idx >= 0) {
cur = cur.set(idx, peeledPackedRef(ref)); cur = cur.set(idx, newRef);
else } else {
cur = cur.add(idx, peeledPackedRef(ref)); cur = cur.add(idx, newRef);
}
}
if (!dirty) {
// All requested refs were already packed accurately
return;
} }
// The new content for packed-refs is collected. Persist it. // The new content for packed-refs is collected. Persist it.

Loading…
Cancel
Save