Propagate IOException when reading refs.

Currently, Repository.getAllRefs() and Repository.getTags() silently
ignores an IOException and instead returns an empty map. Repository
is a public API in JGit and as such cannot be changed until the next
major revision change. Until then, update all call sites to use the
RefDatabase directly, since it propagates the error.

Change-Id: Ia3894a40fbc99482cbb4e1d6b3e4b69e5ddacba2
This commit is contained in:
Colby Ranger
2013-10-07 12:04:23 -07:00
parent 9c7aeb008f
commit 9e85d51493
15 changed files with 107 additions and 37 deletions

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.git;
import static org.eclipse.jgit.lib.RefDatabase.ALL;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gerrit.reviewdb.client.Change;
@@ -30,6 +32,7 @@ import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.transport.AdvertiseRefsHook;
import org.eclipse.jgit.transport.BaseReceivePack;
import org.eclipse.jgit.transport.ServiceMayNotContinueException;
import org.eclipse.jgit.transport.UploadPack;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,10 +62,18 @@ public class ReceiveCommitsAdvertiseRefsHook implements AdvertiseRefsHook {
}
@Override
public void advertiseRefs(BaseReceivePack rp) {
public void advertiseRefs(BaseReceivePack rp)
throws ServiceMayNotContinueException {
Map<String, Ref> oldRefs = rp.getAdvertisedRefs();
if (oldRefs == null) {
oldRefs = rp.getRepository().getAllRefs();
try {
oldRefs = rp.getRepository().getRefDatabase().getRefs(ALL);
} catch (IOException e) {
ServiceMayNotContinueException ex =
new ServiceMayNotContinueException(e.getMessage());
ex.initCause(e);
throw ex;
}
}
Map<String, Ref> r = Maps.newHashMapWithExpectedSize(oldRefs.size());
for (Map.Entry<String, Ref> e : oldRefs.entrySet()) {