summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColby Ranger <cranger@google.com>2013-10-07 10:25:28 -0700
committerColby Ranger <cranger@google.com>2013-10-07 11:32:54 -0700
commit5218f7b33afc02bcd0029767e867222ddc000b09 (patch)
tree00bd1fcde2c54c1e6b6fa89c8b54b64a718a9eb3
parent7995d87713c1fed181643c2a6cf30ed464917e9a (diff)
downloadjgit-5218f7b33afc02bcd0029767e867222ddc000b09.tar.gz
jgit-5218f7b33afc02bcd0029767e867222ddc000b09.zip
Propagate IOException where possible when getting refs.
Currently, Repository.getAllRefs() and Repository.getTags() silently ignores an IOException and instead returns an empty map. Repository is a public API and as such cannot be changed until the next major revision change. Where possible, update the internal jgit APIs to use the RefDatabase directly, since it propagates the error. Change-Id: I4e4537d8bd0fa772f388262684c5c4ca1929dc4c
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java3
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java4
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java4
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java9
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java6
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java7
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java7
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java11
16 files changed, 72 insertions, 22 deletions
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java
index 52f928548b..446f6a2c8d 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java
@@ -44,6 +44,7 @@
package org.eclipse.jgit.http.server;
import static org.eclipse.jgit.http.server.ServletUtils.getRepository;
+import static org.eclipse.jgit.lib.RefDatabase.ALL;
import java.io.IOException;
import java.io.OutputStreamWriter;
@@ -91,7 +92,7 @@ class InfoRefsServlet extends HttpServlet {
adv.init(db);
adv.setDerefTags(true);
- Map<String, Ref> refs = db.getAllRefs();
+ Map<String, Ref> refs = db.getRefDatabase().getRefs(ALL);
refs.remove(Constants.HEAD);
adv.send(refs);
out.close();
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java
index 969a8e0c08..0307a6073e 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java
@@ -43,6 +43,8 @@
package org.eclipse.jgit.pgm;
+import static org.eclipse.jgit.lib.RefDatabase.ALL;
+
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
@@ -175,7 +177,7 @@ class Branch extends TextBuiltin {
}
private void list() throws Exception {
- Map<String, Ref> refs = db.getAllRefs();
+ Map<String, Ref> refs = db.getRefDatabase().getRefs(ALL);
Ref head = refs.get(Constants.HEAD);
// This can happen if HEAD is stillborn
if (head != null) {
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java
index 674c202273..5530ac5c99 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java
@@ -44,6 +44,8 @@
package org.eclipse.jgit.pgm;
+import static org.eclipse.jgit.lib.RefDatabase.ALL;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -64,7 +66,7 @@ class RevParse extends TextBuiltin {
@Override
protected void run() throws Exception {
if (all) {
- Map<String, Ref> allRefs = db.getAllRefs();
+ Map<String, Ref> allRefs = db.getRefDatabase().getRefs(ALL);
for (final Ref r : allRefs.values())
outw.println(r.getObjectId().name());
} else {
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java
index 4327403690..847bf7fc1a 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java
@@ -47,6 +47,7 @@ import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
+import java.util.Map;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
@@ -55,6 +56,7 @@ import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.pgm.internal.CLIText;
import org.eclipse.jgit.pgm.opt.PathTreeFilterHandler;
import org.eclipse.jgit.revwalk.FollowFilter;
@@ -164,8 +166,10 @@ abstract class RevWalkTextBuiltin extends TextBuiltin {
else if (revLimiter.size() > 1)
walk.setRevFilter(AndRevFilter.create(revLimiter));
- if (all)
- for (Ref a : db.getAllRefs().values()) {
+ if (all) {
+ Map<String, Ref> refs =
+ db.getRefDatabase().getRefs(RefDatabase.ALL);
+ for (Ref a : refs.values()) {
ObjectId oid = a.getPeeledObjectId();
if (oid == null)
oid = a.getObjectId();
@@ -175,6 +179,7 @@ abstract class RevWalkTextBuiltin extends TextBuiltin {
// Ignore all refs which are not commits
}
}
+ }
if (commits.isEmpty()) {
final ObjectId head = db.resolve(Constants.HEAD);
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java
index 203c92d4a5..e9d9df6a19 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java
@@ -45,6 +45,8 @@
package org.eclipse.jgit.pgm;
+import static org.eclipse.jgit.lib.RefDatabase.ALL;
+
import java.io.IOException;
import java.util.Map;
import java.util.SortedMap;
@@ -65,8 +67,8 @@ class ShowRef extends TextBuiltin {
}
}
- private Iterable<Ref> getSortedRefs() {
- Map<String, Ref> all = db.getAllRefs();
+ private Iterable<Ref> getSortedRefs() throws Exception {
+ Map<String, Ref> all = db.getRefDatabase().getRefs(ALL);
if (all instanceof RefMap
|| (all instanceof SortedMap && ((SortedMap) all).comparator() == null))
return all.values();
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java
index df59bbe686..cd0236cc04 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java
@@ -43,6 +43,8 @@
package org.eclipse.jgit.pgm.debug;
+import static org.eclipse.jgit.lib.RefDatabase.ALL;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@@ -114,7 +116,7 @@ class RebuildCommitGraph extends TextBuiltin {
@Override
protected void run() throws Exception {
- if (!really && !db.getAllRefs().isEmpty()) {
+ if (!really && !db.getRefDatabase().getRefs(ALL).isEmpty()) {
System.err.println(
MessageFormat.format(CLIText.get().fatalThisProgramWillDestroyTheRepository
, db.getDirectory().getAbsolutePath(), REALLY));
@@ -241,7 +243,8 @@ class RebuildCommitGraph extends TextBuiltin {
private void deleteAllRefs() throws Exception {
final RevWalk rw = new RevWalk(db);
- for (final Ref r : db.getAllRefs().values()) {
+ Map<String, Ref> refs = db.getRefDatabase().getRefs(ALL);
+ for (final Ref r : refs.values()) {
if (Constants.HEAD.equals(r.getName()))
continue;
final RefUpdate u = db.updateRef(r.getName());
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
index cc5cfdce30..ec85c5abe0 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
@@ -152,7 +152,8 @@ public class DescribeCommand extends GitCommand<String> {
throw new IllegalArgumentException(JGitText.get().targetIsNotSet);
Map<ObjectId, Ref> tags = new HashMap<ObjectId, Ref>();
- for (Ref r : repo.getTags().values()) {
+
+ for (Ref r : repo.getRefDatabase().getRefs(R_TAGS).values()) {
ObjectId key = repo.peel(r).getPeeledObjectId();
if (key == null)
key = r.getObjectId();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java
index 53fc70d02d..51a233458f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java
@@ -42,10 +42,13 @@
*/
package org.eclipse.jgit.api;
+import static org.eclipse.jgit.lib.RefDatabase.ALL;
+
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
@@ -252,7 +255,8 @@ public class LogCommand extends GitCommand<Iterable<RevCommit>> {
* the references could not be accessed
*/
public LogCommand all() throws IOException {
- for (Ref ref : getRepository().getAllRefs().values()) {
+ Map<String, Ref> refs = getRepository().getRefDatabase().getRefs(ALL);
+ for (Ref ref : refs.values()) {
if(!ref.isPeeled())
ref = getRepository().peel(ref);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
index b5ea6b58a5..deb6b7ff43 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
@@ -48,6 +48,7 @@ import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.UN
import static org.eclipse.jgit.internal.storage.pack.PackExt.BITMAP_INDEX;
import static org.eclipse.jgit.internal.storage.pack.PackExt.INDEX;
import static org.eclipse.jgit.internal.storage.pack.PackExt.PACK;
+import static org.eclipse.jgit.lib.RefDatabase.ALL;
import java.io.IOException;
import java.util.ArrayList;
@@ -194,7 +195,7 @@ public class DfsGarbageCollector {
refdb.clearCache();
objdb.clearCache();
- refsBefore = repo.getAllRefs();
+ refsBefore = refdb.getRefs(ALL);
packsBefore = packsToRebuild();
if (packsBefore.isEmpty())
return true;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java
index 364fdeb4a1..d0c470988a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java
@@ -46,6 +46,8 @@
package org.eclipse.jgit.internal.storage.file;
+import static org.eclipse.jgit.lib.RefDatabase.ALL;
+
import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
@@ -382,7 +384,7 @@ public class FileRepository extends Repository {
@Override
public void scanForRepoChanges() throws IOException {
- getAllRefs(); // This will look for changes to refs
+ getRefDatabase().getRefs(ALL); // This will look for changes to refs
detectIndexChanges();
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
index 75307decb1..3e26bc3e62 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
@@ -45,6 +45,7 @@ package org.eclipse.jgit.internal.storage.file;
import static org.eclipse.jgit.internal.storage.pack.PackExt.BITMAP_INDEX;
import static org.eclipse.jgit.internal.storage.pack.PackExt.INDEX;
+import static org.eclipse.jgit.lib.RefDatabase.ALL;
import java.io.File;
import java.io.FileOutputStream;
@@ -457,7 +458,7 @@ public class GC {
* @throws IOException
*/
public void packRefs() throws IOException {
- Collection<Ref> refs = repo.getAllRefs().values();
+ Collection<Ref> refs = repo.getRefDatabase().getRefs(ALL).values();
List<String> refsToBePacked = new ArrayList<String>(refs.size());
pm.beginTask(JGitText.get().packRefs, refs.size());
try {
@@ -574,7 +575,7 @@ public class GC {
* @throws IOException
*/
private Map<String, Ref> getAllRefs() throws IOException {
- Map<String, Ref> ret = repo.getAllRefs();
+ Map<String, Ref> ret = repo.getRefDatabase().getRefs(ALL);
for (Ref ref : repo.getRefDatabase().getAdditionalRefs())
ret.put(ref.getName(), ref);
return ret;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
index f49028e37b..952515deda 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
@@ -45,6 +45,8 @@
package org.eclipse.jgit.transport;
+import static org.eclipse.jgit.lib.RefDatabase.ALL;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -52,6 +54,7 @@ import java.text.MessageFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
+import java.util.Map;
import java.util.Set;
import org.eclipse.jgit.errors.PackProtocolException;
@@ -400,7 +403,8 @@ public abstract class BasePackFetchConnection extends BasePackConnection
private void markReachable(final Set<ObjectId> have, final int maxTime)
throws IOException {
- for (final Ref r : local.getAllRefs().values()) {
+ Map<String, Ref> refs = local.getRefDatabase().getRefs(ALL);
+ for (final Ref r : refs.values()) {
ObjectId id = r.getPeeledObjectId();
if (id == null)
id = r.getObjectId();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java
index f4bfd66186..15ff9d3627 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java
@@ -47,6 +47,8 @@
package org.eclipse.jgit.transport;
+import static org.eclipse.jgit.lib.RefDatabase.ALL;
+
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -242,7 +244,13 @@ class BundleFetchConnection extends BaseFetchConnection {
throw new MissingBundlePrerequisiteException(transport.uri,
missing);
- for (final Ref r : transport.local.getAllRefs().values()) {
+ Map<String, Ref> localRefs;
+ try {
+ localRefs = transport.local.getRefDatabase().getRefs(ALL);
+ } catch (IOException e) {
+ throw new TransportException(transport.uri, e.getMessage(), e);
+ }
+ for (final Ref r : localRefs.values()) {
try {
rw.markStart(rw.parseCommit(r.getObjectId()));
} catch (IOException readError) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
index dd04ce50c2..837bd58d82 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
@@ -46,6 +46,8 @@
package org.eclipse.jgit.transport;
+import static org.eclipse.jgit.lib.RefDatabase.ALL;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -644,8 +646,9 @@ public abstract class Transport {
}
private static Collection<RefSpec> expandPushWildcardsFor(
- final Repository db, final Collection<RefSpec> specs) {
- final Map<String, Ref> localRefs = db.getAllRefs();
+ final Repository db, final Collection<RefSpec> specs)
+ throws IOException {
+ final Map<String, Ref> localRefs = db.getRefDatabase().getRefs(ALL);
final Collection<RefSpec> procRefs = new HashSet<RefSpec>();
for (final RefSpec spec : specs) {
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 2f56775f53..28962b7c42 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
@@ -43,6 +43,8 @@
package org.eclipse.jgit.transport;
+import static org.eclipse.jgit.lib.RefDatabase.ALL;
+
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
@@ -1129,7 +1131,7 @@ public class UploadPack {
new ReachableCommitTipRequestValidator().checkWants(up, wants);
else if (!wants.isEmpty()) {
Set<ObjectId> refIds =
- refIdSet(up.getRepository().getAllRefs().values());
+ refIdSet(up.getRepository().getRefDatabase().getRefs(ALL).values());
for (ObjectId obj : wants) {
if (!refIds.contains(obj))
throw new PackProtocolException(MessageFormat.format(
@@ -1149,7 +1151,7 @@ public class UploadPack {
public void checkWants(UploadPack up, List<ObjectId> wants)
throws PackProtocolException, IOException {
checkNotAdvertisedWants(up.getRevWalk(), wants,
- refIdSet(up.getRepository().getAllRefs().values()));
+ refIdSet(up.getRepository().getRefDatabase().getRefs(ALL).values()));
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
index 972ee2895e..565b457acb 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
@@ -44,6 +44,8 @@
package org.eclipse.jgit.transport;
+import static org.eclipse.jgit.lib.RefDatabase.ALL;
+
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -56,6 +58,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.eclipse.jgit.errors.CompoundException;
@@ -668,7 +671,13 @@ class WalkFetchConnection extends BaseFetchConnection {
}
private void markLocalRefsComplete(final Set<ObjectId> have) throws TransportException {
- for (final Ref r : local.getAllRefs().values()) {
+ Map<String, Ref> refs;
+ try {
+ refs = local.getRefDatabase().getRefs(ALL);
+ } catch (IOException e) {
+ throw new TransportException(e.getMessage(), e);
+ }
+ for (final Ref r : refs.values()) {
try {
markLocalObjComplete(revWalk.parseAny(r.getObjectId()));
} catch (IOException readError) {