diff --git a/org.eclipse.jgit/.settings/.api_filters b/org.eclipse.jgit/.settings/.api_filters index 792a0c91c..88a712e7b 100644 --- a/org.eclipse.jgit/.settings/.api_filters +++ b/org.eclipse.jgit/.settings/.api_filters @@ -9,6 +9,20 @@ + + + + + + + + + + + + + + diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties index 31579c98a..6e0d8f562 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties @@ -354,6 +354,8 @@ initFailedNonBareRepoSameDirs=When initializing a non-bare repo with directory { inMemoryBufferLimitExceeded=In-memory buffer limit exceeded inputDidntMatchLength=Input did not match supplied length. {0} bytes are missing. inputStreamMustSupportMark=InputStream must support mark() +integerValueNotInRange=Integer value {0}.{1} = {2} not in range {3}..{4} +integerValueNotInRangeSubSection=Integer value {0}.{1}.{2} = {3} not in range {4}..{5} integerValueOutOfRange=Integer value {0}.{1} out of range internalRevisionError=internal revision error internalServerError=internal server error diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java index 58615b44d..9623346b0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java @@ -382,6 +382,8 @@ public static JGitText get() { /***/ public String inMemoryBufferLimitExceeded; /***/ public String inputDidntMatchLength; /***/ public String inputStreamMustSupportMark; + /***/ public String integerValueNotInRange; + /***/ public String integerValueNotInRangeSubSection; /***/ public String integerValueOutOfRange; /***/ public String internalRevisionError; /***/ public String internalServerError; 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 9f96bce25..86409403b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java @@ -118,6 +118,26 @@ public int getInt(Config config, String section, String subsection, .format(JGitText.get().integerValueOutOfRange, section, name)); } + /** {@inheritDoc} */ + @Override + public int getIntInRange(Config config, String section, String subsection, + String name, int minValue, int maxValue, int defaultValue) { + int val = getInt(config, section, subsection, name, defaultValue); + if ((val >= minValue && val <= maxValue) || val == UNSET_INT) { + return val; + } + if (subsection == null) { + throw new IllegalArgumentException(MessageFormat.format( + JGitText.get().integerValueNotInRange, section, name, + Integer.valueOf(val), Integer.valueOf(minValue), + Integer.valueOf(maxValue))); + } + throw new IllegalArgumentException(MessageFormat.format( + JGitText.get().integerValueNotInRangeSubSection, section, + subsection, name, Integer.valueOf(val), + Integer.valueOf(minValue), Integer.valueOf(maxValue))); + } + /** {@inheritDoc} */ @Override public long getLong(Config config, String section, String subsection, 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 0f2f6cff8..c4eb8f10d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TypedConfigGetter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TypedConfigGetter.java @@ -28,6 +28,13 @@ */ public interface TypedConfigGetter { + /** + * Use {@code Integer#MIN_VALUE} as unset int value + * + * @since 6.1 + */ + public static final int UNSET_INT = Integer.MIN_VALUE; + /** * Get a boolean value from a git {@link Config}. * @@ -86,6 +93,32 @@ > T getEnum(Config config, T[] all, String section, int getInt(Config config, String section, String subsection, String name, int defaultValue); + /** + * Obtain an integer value from a git {@link Config} which must be in given + * range. + * + * @param config + * to get the value from + * @param section + * section the key is grouped within. + * @param subsection + * subsection name, such a remote or branch name. + * @param name + * name of the key to get. + * @param minValue + * minimal value + * @param maxValue + * maximum value + * @param defaultValue + * default value to return if no value was present. Use + * {@code #UNSET_INT} to set the default to unset. + * @return an integer value from the configuration, or defaultValue. + * {@code #UNSET_INT} if unset. + * @since 6.1 + */ + int getIntInRange(Config config, String section, String subsection, + String name, int minValue, int maxValue, int defaultValue); + /** * Obtain a long value from a git {@link Config}. *