summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2014-05-24 18:06:13 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2014-05-24 18:06:13 -0400
commitfbef8eb3fa102d493450e4001f5b51a5365f6fec (patch)
tree93d23b3a54bf180fee961e5feb99eefe8aec3d06
parent527f5fc5d019d60fca3c0b8c7269f2a0bca91b69 (diff)
parent30cd891a48a74d29d04e6b81755ed197b4e2147f (diff)
downloadjgit-fbef8eb3fa102d493450e4001f5b51a5365f6fec.tar.gz
jgit-fbef8eb3fa102d493450e4001f5b51a5365f6fec.zip
Merge "Adds a callAsMap() function to LsRemoteCommand."
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java25
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java10
2 files changed, 26 insertions, 9 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java
index 55ca58f9cb..e099a43502 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java
@@ -46,6 +46,7 @@ import java.net.URISyntaxException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -153,6 +154,28 @@ public class LsRemoteCommand extends
public Collection<Ref> call() throws GitAPIException,
InvalidRemoteException,
org.eclipse.jgit.api.errors.TransportException {
+ return execute().values();
+ }
+
+ /**
+ * Same as {@link #call()}, but return Map instead of Collection.
+ *
+ * @return a map from names to references in the remote repository
+ * @throws InvalidRemoteException
+ * when called with an invalid remote uri
+ * @throws org.eclipse.jgit.api.errors.TransportException
+ * for errors that occurs during transport
+ * @since 3.5
+ */
+ public Map<String, Ref> callAsMap() throws GitAPIException,
+ InvalidRemoteException,
+ org.eclipse.jgit.api.errors.TransportException {
+ return Collections.unmodifiableMap(execute());
+ }
+
+ protected Map<String, Ref> execute() throws GitAPIException,
+ InvalidRemoteException,
+ org.eclipse.jgit.api.errors.TransportException {
checkCallable();
Transport transport = null;
@@ -184,7 +207,7 @@ public class LsRemoteCommand extends
refmap.put(r.getName(), r);
break;
}
- return refmap.values();
+ return refmap;
} catch (URISyntaxException e) {
throw new InvalidRemoteException(MessageFormat.format(
JGitText.get().invalidRemote, remote));
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java
index e90abb5fbb..c6a6d8e66c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java
@@ -160,16 +160,10 @@ public class RepoCommand extends GitCommand<RevCommit> {
/** A default implementation of {@link RemoteReader} callback. */
public static class DefaultRemoteReader implements RemoteReader {
public ObjectId sha1(String uri, String ref) throws GitAPIException {
- Collection<Ref> refs = Git
+ Map<String, Ref> map = Git
.lsRemoteRepository()
.setRemote(uri)
- .call();
- // Since LsRemoteCommand.call() only returned Map.values() to us, we
- // have to rebuild the map here.
- Map<String, Ref> map = new HashMap<String, Ref>(refs.size());
- for (Ref r : refs)
- map.put(r.getName(), r);
-
+ .callAsMap();
Ref r = RefDatabase.findRef(map, ref);
return r != null ? r.getObjectId() : null;
}