git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Shawn O. Pearce <spearce@spearce.org>
Date
Aug 10, 2008, 08:46 UTC
Message-ID
<1218357986-19671-2-git-send-email-spearce@spearce.org>
In-Reply-To
<1218357986-19671-1-git-send-email-spearce@spearce.org>

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@spearce.org>
---
 .../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
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 2 of 15 in “Misc. cleanups and improvements”
  1. 00/11 Misc. cleanups and improvementsShawn O. Pearce, Aug 10, 2008
  2. 01/11 Fix RawParseUtils.endOfParagraph to work on all corner casesShawn O. Pearce, Aug 10, 2008
  3. 02/11 Add test case for the RevCommit parsing codeShawn O. Pearce, Aug 10, 2008
  4. 03/11 Notify AbstractTreeIterator implementations of skipped tree entriesShawn O. Pearce, Aug 10, 2008
  5. 04/11 Allow AbstractTreeIterator subclasses to supply their own path arrayShawn O. Pearce, Aug 10, 2008
  6. 05/11 Allow WorkingTreeIterators to define their prefix path when createdShawn O. Pearce, Aug 10, 2008
  7. 06/11 Add getTree to TreeWalk for locating the current iterator instanceShawn O. Pearce, Aug 10, 2008
  8. 07/11 Allow WorkingTreeIterator to track last modified time for entriesShawn O. Pearce, Aug 10, 2008
  9. 08/11 Expose the current entry's length, last modified in WorkingTreeIteratorShawn O. Pearce, Aug 10, 2008
  10. 09/11 Expose idBuffer,idOffset in AbstractTreeIterator to applicationsShawn O. Pearce, Aug 10, 2008
  11. 10/11 Add a TreeWalk iterator implementation for IContainerShawn O. Pearce, Aug 10, 2008
  12. 11/11 Teach NB how to encode/decode an unsigned 16 bit integerShawn O. Pearce, Aug 10, 2008
  13. Robin RosenbergAug 13, 2008
  14. Shawn O. PearceAug 14, 2008
  15. Robin RosenbergAug 14, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.