summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
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 /org.eclipse.jgit
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
Diffstat (limited to 'org.eclipse.jgit')
-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
10 files changed, 48 insertions, 13 deletions
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) {