diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2017-09-05 11:09:27 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2017-09-07 18:47:45 -0400 |
commit | c27f36dfc79d4127f41c4875d0c1374dbd487d4f (patch) | |
tree | 291db7cd2e00574cac69f570b6a3c7703d140c1d /org.eclipse.jgit | |
parent | bb09e093449b96fbec13b21577a1c9781e6ca45b (diff) | |
download | jgit-c27f36dfc79d4127f41c4875d0c1374dbd487d4f.tar.gz jgit-c27f36dfc79d4127f41c4875d0c1374dbd487d4f.zip |
Fix missing RefsChangedEvent when packed refs are used
With atomic ref updates using packed refs, JGit did not fire a
RefsChangedEvent. This resulted in a user-visible regression in
EGit: the UI would not update after a "Fetch from upstream...".
Presumably it would also make Gerrit miss out on ref changes?
Strengthen the BatchRefUpdateTest by also asserting the expected
number of RefsChangedEvents, and ensure modCnt is incremented in
RefDirectory.commitPackedRefs() when refs really changed (as opposed
to some internal housekeeping operation, such as packing loose refs).
Bug: 521296
Change-Id: Ia985bda1d99f45a5f89c8020ca4845e7a66e743e
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java | 3 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java | 14 |
2 files changed, 12 insertions, 5 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java index b661ae78cf..4309089b72 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java @@ -194,7 +194,8 @@ class PackedBatchRefUpdate extends BatchRefUpdate { return; } // commitPackedRefs removes lock file (by renaming over real file). - refdb.commitPackedRefs(packedRefsLock, newRefs, oldPackedList); + refdb.commitPackedRefs(packedRefsLock, newRefs, oldPackedList, + true); } finally { try { unlockAll(locks); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index ecf7ef942e..59f4e50f91 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -633,8 +633,9 @@ public class RefDirectory extends RefDatabase { try { PackedRefList cur = readPackedRefs(); int idx = cur.find(name); - if (0 <= idx) - commitPackedRefs(lck, cur.remove(idx), packed); + if (0 <= idx) { + commitPackedRefs(lck, cur.remove(idx), packed, true); + } } finally { lck.unlock(); } @@ -733,7 +734,8 @@ public class RefDirectory extends RefDatabase { } // The new content for packed-refs is collected. Persist it. - PackedRefList result = commitPackedRefs(lck, cur, packed); + PackedRefList result = commitPackedRefs(lck, cur, packed, + false); // Now delete the loose refs which are now packed for (String refName : refs) { @@ -988,7 +990,8 @@ public class RefDirectory extends RefDatabase { } PackedRefList commitPackedRefs(final LockFile lck, final RefList<Ref> refs, - final PackedRefList oldPackedList) throws IOException { + final PackedRefList oldPackedList, boolean changed) + throws IOException { // Can't just return packedRefs.get() from this method; it might have been // updated again after writePackedRefs() returns. AtomicReference<PackedRefList> result = new AtomicReference<>(); @@ -1031,6 +1034,9 @@ public class RefDirectory extends RefDatabase { throw new ObjectWritingException( MessageFormat.format(JGitText.get().unableToWrite, name)); } + if (changed) { + modCnt.incrementAndGet(); + } result.set(newPackedList); } }.writePackedRefs(); |