Introduce the method allowing us to parse all configured remotes. Signed-off-by: Marek Zawirski <marek.zawirski@xxxxxxxxx> --- .../src/org/spearce/jgit/lib/RepositoryConfig.java | 21 ++++++++++++++++ .../org/spearce/jgit/transport/RemoteConfig.java | 26 ++++++++++++++++++++ 2 files changed, 47 insertions(+), 0 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java index 048940d..397c294 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java @@ -53,9 +53,11 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import org.spearce.jgit.util.FS; @@ -277,6 +279,25 @@ public class RepositoryConfig { return baseConfig.getStringList(section, subsection, name); return new String[0]; } + + /** + * @param section + * section to search for. + * @return set of all subsections of specified section within this + * configuration and its base configuration; may be empty if no + * subsection exists. + */ + public Set<String> getSubsections(final String section) { + final Set<String> result = new HashSet<String>(); + + for (final Entry e : entries) { + if (section.equals(e.base) && e.extendedBase != null) + result.add(e.extendedBase); + } + if (baseConfig != null) + result.addAll(baseConfig.getSubsections(section)); + return result; + } private String getRawString(final String section, final String subsection, final String name) { diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteConfig.java b/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteConfig.java index bb21511..cde5d43 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteConfig.java +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteConfig.java @@ -73,6 +73,32 @@ public class RemoteConfig { /** Default value for {@link #getReceivePack()} if not specified. */ public static final String DEFAULT_RECEIVE_PACK = "git-receive-pack"; + + /** + * Parse all remote blocks in an existing configuration file, looking for + * remotes configuration. + * + * @param rc + * the existing configuration to get the remote settings from. + * The configuration must already be loaded into memory. + * @return all remotes configurations existing in provided repository + * configuration. Returned configurations are ordered + * lexicographically by names. + * @throws URISyntaxException + * one of the URIs within the remote's configuration is invalid. + */ + public static List<RemoteConfig> getAllRemoteConfigs( + final RepositoryConfig rc) throws URISyntaxException { + final List<String> names = new ArrayList<String>(rc + .getSubsections(SECTION)); + Collections.sort(names); + + final List<RemoteConfig> result = new ArrayList<RemoteConfig>(names + .size()); + for (final String name : names) + result.add(new RemoteConfig(rc, name)); + return result; + } private String name; -- 1.5.6.3 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html