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

[JGIT PATCH 2/2] improve the handling of empty lines

From
Mark Struberg <struberg@yahoo.de>
Date
Sep 2, 2009, 18:00 UTC
Message-ID
<1251914428-1687-2-git-send-email-struberg@yahoo.de>
In-Reply-To
<1251914428-1687-1-git-send-email-struberg@yahoo.de>

Move the 'empty-line' check in RefDatabase#readLine down a bit after we removed all the whitespaces. This way we consistently return null regardless if the line is empty or if it does only contain whitespaces.

Signed-off-by: Mark Struberg <struberg@yahoo.de>
---
 .../src/org/spearce/jgit/lib/RefDatabase.java      |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
index 477dc62..acc835b 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
@@ -498,14 +498,15 @@ private static String readLine(final File file)
 			throws FileNotFoundException, IOException {
 		final byte[] buf = NB.readFully(file, 4096);
 		int n = buf.length;
-		if (n == 0)
-			return null;
 		
 		// remove trailing whitespaces
 		while (n > 0 && Character.isWhitespace(buf[n - 1])) {
 			n--;
 		}
-		
+
+		if (n == 0)
+			return null;
+
 		return RawParseUtils.decode(buf, 0, n);
 	}
 
-- 
1.6.2.5
Previous: Mark Struberg
Message 2 of 2 in “fixed error in whitespace handling of RefDatabase#readLine”
  1. 1/2 fixed error in whitespace handling of RefDatabase#readLineMark Struberg, Sep 2, 2009
  2. 2/2 improve the handling of empty linesMark Struberg, Sep 2, 2009

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.