Browse Source

Merge "Adds a callAsMap() function to LsRemoteCommand."

tags/v3.5.0.201409071800-rc1
Matthias Sohn 10 years ago
parent
commit
fbef8eb3fa

+ 24
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java View File

import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;


public Collection<Ref> call() throws GitAPIException, public Collection<Ref> call() throws GitAPIException,
InvalidRemoteException, InvalidRemoteException,
org.eclipse.jgit.api.errors.TransportException { 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(); checkCallable();


Transport transport = null; Transport transport = null;
refmap.put(r.getName(), r); refmap.put(r.getName(), r);
break; break;
} }
return refmap.values();
return refmap;
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw new InvalidRemoteException(MessageFormat.format( throw new InvalidRemoteException(MessageFormat.format(
JGitText.get().invalidRemote, remote)); JGitText.get().invalidRemote, remote));

+ 2
- 8
org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java View File

/** A default implementation of {@link RemoteReader} callback. */ /** A default implementation of {@link RemoteReader} callback. */
public static class DefaultRemoteReader implements RemoteReader { public static class DefaultRemoteReader implements RemoteReader {
public ObjectId sha1(String uri, String ref) throws GitAPIException { public ObjectId sha1(String uri, String ref) throws GitAPIException {
Collection<Ref> refs = Git
Map<String, Ref> map = Git
.lsRemoteRepository() .lsRemoteRepository()
.setRemote(uri) .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); Ref r = RefDatabase.findRef(map, ref);
return r != null ? r.getObjectId() : null; return r != null ? r.getObjectId() : null;
} }

Loading…
Cancel
Save