Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2017-08-22 03:02:31 -0400
committerMatthias Sohn2017-08-26 03:11:02 -0400
commit8cbdf523cd60813f69dddece5393c321e5dbe037 (patch)
treefabfc61c7a97321c20006270e7a4f75fd097a6fe
parentd32ad1cadd4fcbf908d48b20f6b16e96338c89e2 (diff)
downloadjgit-8cbdf523cd60813f69dddece5393c321e5dbe037.tar.gz
jgit-8cbdf523cd60813f69dddece5393c321e5dbe037.tar.xz
jgit-8cbdf523cd60813f69dddece5393c321e5dbe037.zip
Add a getter for a list of RefSpecs to Config
Reading RefSpecs from a Config can be seen as another typed value conversion, so add a getter to Config and to TypedConfigGetter. Use it in RemoteConfig. Doing this allows clients of the JGit library to customize the handling of invalid RefSpecs in git config files by installing a custom TypedConfigGetter. Bug: 517314 Change-Id: I0ebc0f073fabc85c2a693b43f5ba5962d8a795ff Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java18
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java15
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/TypedConfigGetter.java21
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteConfig.java18
4 files changed, 60 insertions, 12 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
index 338216bc6c..6281bcfb3d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
@@ -69,6 +69,7 @@ import org.eclipse.jgit.events.ConfigChangedListener;
import org.eclipse.jgit.events.ListenerHandle;
import org.eclipse.jgit.events.ListenerList;
import org.eclipse.jgit.internal.JGitText;
+import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils;
@@ -447,6 +448,23 @@ public class Config {
}
/**
+ * Parse a list of {@link RefSpec}s from the configuration.
+ *
+ * @param section
+ * section the key is in.
+ * @param subsection
+ * subsection the key is in, or null if not in a subsection.
+ * @param name
+ * the key name.
+ * @return a possibly empty list of {@link RefSpec}s
+ * @since 4.9
+ */
+ public List<RefSpec> getRefSpecs(String section, String subsection,
+ String name) {
+ return typedGetter.getRefSpecs(this, section, subsection, name);
+ }
+
+ /**
* @param section
* section to search for.
* @return set of all subsections of specified section within this
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java
index c77d0dd6db..fd37747601 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java
@@ -44,12 +44,16 @@
package org.eclipse.jgit.lib;
import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Config.ConfigEnum;
+import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.util.StringUtils;
/**
@@ -281,4 +285,15 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter {
MessageFormat.format(JGitText.get().invalidTimeUnitValue2,
section, name, valueString));
}
+
+ @Override
+ public @NonNull List<RefSpec> getRefSpecs(Config config, String section,
+ String subsection, String name) {
+ String[] values = config.getStringList(section, subsection, name);
+ List<RefSpec> result = new ArrayList<>(values.length);
+ for (String spec : values) {
+ result.add(new RefSpec(spec));
+ }
+ return result;
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TypedConfigGetter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TypedConfigGetter.java
index 7c34a03c9c..594edef665 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TypedConfigGetter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TypedConfigGetter.java
@@ -43,8 +43,12 @@
package org.eclipse.jgit.lib;
+import java.util.List;
import java.util.concurrent.TimeUnit;
+import org.eclipse.jgit.annotations.NonNull;
+import org.eclipse.jgit.transport.RefSpec;
+
/**
* Something that knows how to convert plain strings from a git {@link Config}
* to typed values.
@@ -155,4 +159,21 @@ public interface TypedConfigGetter {
long getTimeUnit(Config config, String section, String subsection,
String name, long defaultValue, TimeUnit wantUnit);
+
+ /**
+ * Parse a list of {@link RefSpec}s from a git {@link Config}.
+ *
+ * @param config
+ * to get the list from
+ * @param section
+ * section the key is in.
+ * @param subsection
+ * subsection the key is in, or null if not in a subsection.
+ * @param name
+ * the key name.
+ * @return a possibly empty list of {@link RefSpec}s
+ */
+ @NonNull
+ List<RefSpec> getRefSpecs(Config config, String section, String subsection,
+ String name);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteConfig.java
index a0d81c00f0..5449cf15b3 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteConfig.java
@@ -192,24 +192,18 @@ public class RemoteConfig implements Serializable {
}
}
}
- vlst = rc.getStringList(SECTION, name, KEY_FETCH);
- fetch = new ArrayList<>(vlst.length);
- for (final String s : vlst)
- fetch.add(new RefSpec(s));
-
- vlst = rc.getStringList(SECTION, name, KEY_PUSH);
- push = new ArrayList<>(vlst.length);
- for (final String s : vlst)
- push.add(new RefSpec(s));
-
+ fetch = rc.getRefSpecs(SECTION, name, KEY_FETCH);
+ push = rc.getRefSpecs(SECTION, name, KEY_PUSH);
val = rc.getString(SECTION, name, KEY_UPLOADPACK);
- if (val == null)
+ if (val == null) {
val = DEFAULT_UPLOAD_PACK;
+ }
uploadpack = val;
val = rc.getString(SECTION, name, KEY_RECEIVEPACK);
- if (val == null)
+ if (val == null) {
val = DEFAULT_RECEIVE_PACK;
+ }
receivepack = val;
val = rc.getString(SECTION, name, KEY_TAGOPT);

Back to the top