[EGIT PATCH 01/11] Fix RawParseUtils.endOfParagraph to work on all corner cases

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We rely on this method to find the end of the "oneline" part of a
commit message, which is then used in displays like the History
view in EGit or in some tooltips.  However a number of weird commit
formats were throwing its parsing off, causing us to split the text
in a way we didn't expect (or want) to split it.

This change resolves the splitting by making sure we don't throw an
IndexOutOfBoundsException from RevCommit.getShortMessage due to the
end of the paragraph coming out before the beginning of it.  This
happened sometimes when the commit message was empty.

We also now properly trim the trailing LFs which end the paragraph,
as these were showing up sometimes as spaces at the end of a short
message string (as we do LF->space conversion prior to returning).

Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx>
---
 .../src/org/spearce/jgit/util/RawParseUtils.java   |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java
index f268ffc..dbc2e83 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java
@@ -422,20 +422,21 @@ public final class RawParseUtils {
 	 * 
 	 * @param b
 	 *            buffer to scan.
-	 * @param ptr
+	 * @param start
 	 *            position in buffer to start the scan at. Most callers will
 	 *            want to pass the first position of the commit message (as
 	 *            found by {@link #commitMessage(byte[], int)}.
 	 * @return position of the LF at the end of the paragraph;
 	 *         <code>b.length</code> if no paragraph end could be located.
 	 */
-	public static final int endOfParagraph(final byte[] b, int ptr) {
+	public static final int endOfParagraph(final byte[] b, final int start) {
+		int ptr = start;
 		final int sz = b.length;
 		while (ptr < sz && b[ptr] != '\n')
 			ptr = next(b, ptr, '\n');
-		if (ptr < sz && b[ptr] == '\n')
-			return ptr - 1;
-		return sz;
+		while (0 < ptr && start < ptr && b[ptr - 1] == '\n')
+			ptr--;
+		return ptr;
 	}
 
 	private RawParseUtils() {
-- 
1.6.0.rc2.219.g1250ab

--
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

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux