{"thread":{"id":"20815","subject":"[JGIT PATCH] fixed error in whitespace handling of RefDatabase#readLine","startedAt":"2009-09-01T21:18:52Z","lastAt":"2009-09-01T23:15:24Z","messageCount":2,"participants":["Mark Struberg","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"122262","messageId":"196796.47610.qm@web27808.mail.ukl.yahoo.com","threadId":"20815","inReplyTo":null,"subject":"[JGIT PATCH] fixed error in whitespace handling of RefDatabase#readLine","fromName":"Mark Struberg","fromEmail":"struberg@yahoo.de","sentAt":"2009-09-01T21:18:52Z","receivedAt":"2009-09-01T21:18:52Z","isPatch":true,"sender":{"key":"struberg@yahoo.de","avatar":"https://gravatar.com/avatar/119742c3e8dbc8db35a92bdff0581aec8d364d415f770e60431cba262daa974f?d=mp&s=160"},"body":"jgit fails with \"cannot checkout; no HEAD advertised by remote\"\nin guessHEAD on some repositories.\n\nJGIT 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.\n\nI 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.)\n\nFixed by subsequently removing all Character.isWhitespaceChar() from the end of the buffer\n\nSigned-off-by: Mark Struberg <struberg@yahoo.de>\n---\n .../src/org/spearce/jgit/lib/RefDatabase.java      |    6 +++++-\n 1 files changed, 5 insertions(+), 1 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java\nindex ba4b654..477dc62 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java\n@@ -500,8 +500,12 @@ private static String readLine(final File file)\n         int n = buf.length;\n         if (n == 0)\n             return null;\n-        if (buf[n - 1] == '\\n')\n+        \n+        // remove trailing whitespaces\n+        while (n > 0 && Character.isWhitespace(buf[n - 1])) {\n             n--;\n+        }\n+        \n         return RawParseUtils.decode(buf, 0, n);\n     }\n \n-- \n1.6.2.5\n\n\n      \n"},{"id":"122267","messageId":"20090901231524.GA1033@spearce.org","threadId":"20815","inReplyTo":"196796.47610.qm@web27808.mail.ukl.yahoo.com","subject":"Re: [JGIT PATCH] fixed error in whitespace handling of RefDatabase#readLine","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-09-01T23:15:24Z","receivedAt":"2009-09-01T23:15:24Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Mark Struberg <struberg@yahoo.de> wrote:\n> jgit fails with \"cannot checkout; no HEAD advertised by remote\"\n> in guessHEAD on some repositories.\n...\n> @@ -500,8 +500,12 @@ private static String readLine(final File file)\n>          int n = buf.length;\n>          if (n == 0)\n\nWhitespace damage here, the patch won't apply as-is.\n\nAlso, please line wrap your commit message.\n\n-- \nShawn.\n"}]}