aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorMike Edgar <adgar@google.com>2016-04-12 22:23:08 -0400
committerMike Edgar <adgar@google.com>2016-04-14 20:41:53 -0400
commit4812fdab61c1ac61863247574be03425ba3bc674 (patch)
tree2b1ab5157935407b0a6ed3c4b4317a39b80cbe06 /org.eclipse.jgit
parent32a5993227b5f43cb32becdf14d3efb6e88fa847 (diff)
downloadjgit-4812fdab61c1ac61863247574be03425ba3bc674.tar.gz
jgit-4812fdab61c1ac61863247574be03425ba3bc674.zip
Make UploadPack observe exceptions reading refs
Now if refs are unreadable when serving an upload pack the handler will fail due to the actual underlying failure. Previously all wants would be rejected as invalid because Repository.getAllRefs() returned an empty map. Testing this required a new subclass of InMemoryRepository so that an IOException could be injected at the correct time. Signed-off-by: Michael Edgar <adgar@google.com> Change-Id: Iac708b1db9d0ccce08c4ef5ace599ea0b57afdc0
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/META-INF/MANIFEST.MF5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/InMemoryRepository.java13
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java19
3 files changed, 25 insertions, 12 deletions
diff --git a/org.eclipse.jgit/META-INF/MANIFEST.MF b/org.eclipse.jgit/META-INF/MANIFEST.MF
index 51bee1afff..a3d1a92f51 100644
--- a/org.eclipse.jgit/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit/META-INF/MANIFEST.MF
@@ -60,7 +60,10 @@ Export-Package: org.eclipse.jgit.annotations;version="4.4.0",
org.eclipse.jgit.ignore.internal;version="4.4.0";x-friends:="org.eclipse.jgit.test",
org.eclipse.jgit.internal;version="4.4.0";x-friends:="org.eclipse.jgit.test,org.eclipse.jgit.http.test",
org.eclipse.jgit.internal.ketch;version="4.4.0";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm",
- org.eclipse.jgit.internal.storage.dfs;version="4.4.0";x-friends:="org.eclipse.jgit.test,org.eclipse.jgit.http.server",
+ org.eclipse.jgit.internal.storage.dfs;version="4.4.0";
+ x-friends:="org.eclipse.jgit.test,
+ org.eclipse.jgit.http.server,
+ org.eclipse.jgit.http.test",
org.eclipse.jgit.internal.storage.file;version="4.4.0";
x-friends:="org.eclipse.jgit.test,
org.eclipse.jgit.junit,
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/InMemoryRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/InMemoryRepository.java
index b312835bb3..ccf1b42b3d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/InMemoryRepository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/InMemoryRepository.java
@@ -252,11 +252,20 @@ public class InMemoryRepository extends DfsRepository {
}
}
- private class MemRefDatabase extends DfsRefDatabase {
+ /**
+ * A ref database storing all refs in-memory.
+ * <p>
+ * This class is protected (and not private) to facilitate testing using
+ * subclasses of InMemoryRepository.
+ */
+ protected class MemRefDatabase extends DfsRefDatabase {
private final ConcurrentMap<String, Ref> refs = new ConcurrentHashMap<String, Ref>();
private final ReadWriteLock lock = new ReentrantReadWriteLock(true /* fair */);
- MemRefDatabase() {
+ /**
+ * Initialize a new in-memory ref database.
+ */
+ protected MemRefDatabase() {
super(InMemoryRepository.this);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
index 8b642bb980..e49ee87b73 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
@@ -82,6 +82,7 @@ import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.AsyncRevObjectQueue;
import org.eclipse.jgit.revwalk.DepthWalk;
@@ -704,22 +705,22 @@ public class UploadPack {
return statistics;
}
- private Map<String, Ref> getAdvertisedOrDefaultRefs() {
+ private Map<String, Ref> getAdvertisedOrDefaultRefs() throws IOException {
if (refs == null)
- setAdvertisedRefs(null);
+ setAdvertisedRefs(db.getRefDatabase().getRefs(RefDatabase.ALL));
return refs;
}
private void service() throws IOException {
- if (biDirectionalPipe)
- sendAdvertisedRefs(new PacketLineOutRefAdvertiser(pckOut));
- else if (requestValidator instanceof AnyRequestValidator)
- advertised = Collections.emptySet();
- else
- advertised = refIdSet(getAdvertisedOrDefaultRefs().values());
-
boolean sendPack;
try {
+ if (biDirectionalPipe)
+ sendAdvertisedRefs(new PacketLineOutRefAdvertiser(pckOut));
+ else if (requestValidator instanceof AnyRequestValidator)
+ advertised = Collections.emptySet();
+ else
+ advertised = refIdSet(getAdvertisedOrDefaultRefs().values());
+
recvWants();
if (wantIds.isEmpty()) {
preUploadHook.onBeginNegotiateRound(this, wantIds, 0);