aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2013-02-20 18:35:44 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2013-02-20 18:35:44 -0500
commit301df23d9b34c2685639d24d08f13d2492cdb00e (patch)
tree47b4c78318d642015428e475c8a10f729c0d3554 /org.eclipse.jgit/src/org/eclipse
parent5d7b722f6e20232a5e03d76f10c5c9554ab754a9 (diff)
parent3b41fcbd96610dc0fddded2aebc4e3b5c702b4fb (diff)
downloadjgit-301df23d9b34c2685639d24d08f13d2492cdb00e.tar.gz
jgit-301df23d9b34c2685639d24d08f13d2492cdb00e.zip
Merge "Accept Change-Id even if footer contains not well-formed entries" into stable-2.3
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/ChangeIdUtil.java44
1 files changed, 35 insertions, 9 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/ChangeIdUtil.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/ChangeIdUtil.java
index 41bb4cc7eb..7487f0d2b9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/ChangeIdUtil.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/ChangeIdUtil.java
@@ -125,9 +125,14 @@ public class ChangeIdUtil {
private static final Pattern footerPattern = Pattern
.compile("(^[a-zA-Z0-9-]+:(?!//).*$)"); //$NON-NLS-1$
+ private static final Pattern changeIdPattern = Pattern
+ .compile("(^" + CHANGE_ID + " *I[a-f0-9]{40}$)"); //$NON-NLS-1$ //$NON-NLS-2$
+
private static final Pattern includeInFooterPattern = Pattern
.compile("^[ \\[].*$"); //$NON-NLS-1$
+ private static final Pattern trailingWhitespace = Pattern.compile("\\s+$");
+
/**
* Find the right place to insert a Change-Id and return it.
* <p>
@@ -209,8 +214,11 @@ public class ChangeIdUtil {
}
/**
- * Find the index in the String {@code} message} where the Change-Id entry
- * begins
+ * Return the index in the String {@code message} where the Change-Id entry
+ * in the footer begins. If there are more than one entries matching the
+ * pattern, return the index of the last one in the last section. Because of
+ * Bug: 400818 we release the constraint here that a footer must contain
+ * only lines matching {@code footerPattern}.
*
* @param message
* @param delimiter
@@ -221,14 +229,32 @@ public class ChangeIdUtil {
*/
public static int indexOfChangeId(String message, String delimiter) {
String[] lines = message.split(delimiter);
- int footerFirstLine = indexOfFirstFooterLine(lines);
- if (footerFirstLine == lines.length)
- return -1;
+ int indexOfChangeIdLine = 0;
+ boolean inFooter = false;
+ for (int i = lines.length - 1; i >= 0; --i) {
+ if (!inFooter && isEmptyLine(lines[i]))
+ continue;
+ inFooter = true;
+ if (changeIdPattern.matcher(trimRight(lines[i])).matches()) {
+ indexOfChangeIdLine = i;
+ break;
+ } else if (isEmptyLine(lines[i]) || i == 0)
+ return -1;
+ }
+ int indexOfChangeIdLineinString = 0;
+ for (int i = 0; i < indexOfChangeIdLine; ++i)
+ indexOfChangeIdLineinString += lines[i].length()
+ + delimiter.length();
+ return indexOfChangeIdLineinString
+ + lines[indexOfChangeIdLine].indexOf(CHANGE_ID);
+ }
+
+ private static boolean isEmptyLine(String line) {
+ return line.trim().length() == 0;
+ }
- int indexOfFooter = 0;
- for (int i = 0; i < footerFirstLine; ++i)
- indexOfFooter += lines[i].length() + delimiter.length();
- return message.indexOf(CHANGE_ID, indexOfFooter);
+ private static String trimRight(String s) {
+ return trailingWhitespace.matcher(s).replaceAll(""); //$NON-NLS-1$
}
/**