threads / patch / 20815

patchfixed error in whitespace handling of RefDatabase#readLine

Subject: [JGIT PATCH] fixed error in whitespace handling of RefDatabase#readLine

## tl;dr

2 messages between Sep 1, 2009 and Sep 1, 2009. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Mark Struberg· Sep 1, 2009, 21:18 UTC · lore

jgit fails with "cannot checkout; no HEAD advertised by remote" in guessHEAD on some repositories.

JGIT used to work on my test repo for the maven-scm-providers-git until a few weeks. I tracked it down with git bisect and found commit 72b1f0d334729a49cc52e4762093148be62bea39 to be the bad one.
I glimpsed at the code and it appears that the new code in RefDatabase#readLine is not Windows CR+LF aware. (This hits me although I use Linux because our SVN at apache.org seems to have it stored with CR+LF.)
Fixed by subsequently removing all Character.isWhitespaceChar() from the end of the buffer
Signed-off-by: Mark Struberg <struberg@yahoo.de>
---
 .../src/org/spearce/jgit/lib/RefDatabase.java      |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
Show changes to org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java +5 −1
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 ba4b654..477dc62 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
@@ -500,8 +500,12 @@ private static String readLine(final File file)
         int n = buf.length;
         if (n == 0)
             return null;
-        if (buf[n - 1] == '\n')
+        
+        // remove trailing whitespaces
+        while (n > 0 && Character.isWhitespace(buf[n - 1])) {
             n--;
+        }
+        
         return RawParseUtils.decode(buf, 0, n);
     }
 
-- 
1.6.2.5


      
Shawn O. Pearce· Sep 1, 2009, 23:15 UTC · re: Mark Struberg · lore

Re: [JGIT PATCH] fixed error in whitespace handling of RefDatabase#readLine

Mark Struberg <struberg@yahoo.de> wrote:
> jgit fails with "cannot checkout; no HEAD advertised by remote"
> in guessHEAD on some repositories.
...
> @@ -500,8 +500,12 @@ private static String readLine(final File file)
>          int n = buf.length;
>          if (n == 0)
Whitespace damage here, the patch won't apply as-is.
Also, please line wrap your commit message.
-- 
Shawn.

← back to recent threads