{"thread":{"id":"20827","subject":"[JGIT PATCH 2/2] improve the handling of empty lines","startedAt":"2009-09-02T18:00:27Z","lastAt":"2009-09-02T18:00:28Z","messageCount":2,"participants":["Mark Struberg"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"122326","messageId":"1251914428-1687-1-git-send-email-struberg@yahoo.de","threadId":"20827","inReplyTo":null,"subject":"[JGIT PATCH 1/2] fixed error in whitespace handling of RefDatabase#readLine","fromName":"Mark Struberg","fromEmail":"struberg@yahoo.de","sentAt":"2009-09-02T18:00:27Z","receivedAt":"2009-09-02T18:00:27Z","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. \nI tracked it down with git bisect and found commit \n72b1f0d334729a49cc52e4762093148be62bea39 to be the bad one.\n\nI glimpsed at the code and it appears that the new code in \nRefDatabase#readLine is not Windows CR+LF aware. \n(This hits me although I use Linux because our SVN at \napache.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 \t\tint n = buf.length;\n \t\tif (n == 0)\n \t\t\treturn null;\n-\t\tif (buf[n - 1] == '\\n')\n+\t\t\n+\t\t// remove trailing whitespaces\n+\t\twhile (n > 0 && Character.isWhitespace(buf[n - 1])) {\n \t\t\tn--;\n+\t\t}\n+\t\t\n \t\treturn RawParseUtils.decode(buf, 0, n);\n \t}\n \n-- \n1.6.2.5\n"},{"id":"122325","messageId":"1251914428-1687-2-git-send-email-struberg@yahoo.de","threadId":"20827","inReplyTo":"1251914428-1687-1-git-send-email-struberg@yahoo.de","subject":"[JGIT PATCH 2/2] improve the handling of empty lines","fromName":"Mark Struberg","fromEmail":"struberg@yahoo.de","sentAt":"2009-09-02T18:00:28Z","receivedAt":"2009-09-02T18:00:28Z","isPatch":true,"sender":{"key":"struberg@yahoo.de","avatar":"https://gravatar.com/avatar/119742c3e8dbc8db35a92bdff0581aec8d364d415f770e60431cba262daa974f?d=mp&s=160"},"body":"Move the 'empty-line' check in RefDatabase#readLine down a bit after we removed all the whitespaces.\nThis way we consistently return null regardless if the line \nis empty or if it does only contain whitespaces.\n\nSigned-off-by: Mark Struberg <struberg@yahoo.de>\n---\n .../src/org/spearce/jgit/lib/RefDatabase.java      |    7 ++++---\n 1 files changed, 4 insertions(+), 3 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 477dc62..acc835b 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@@ -498,14 +498,15 @@ private static String readLine(final File file)\n \t\t\tthrows FileNotFoundException, IOException {\n \t\tfinal byte[] buf = NB.readFully(file, 4096);\n \t\tint n = buf.length;\n-\t\tif (n == 0)\n-\t\t\treturn null;\n \t\t\n \t\t// remove trailing whitespaces\n \t\twhile (n > 0 && Character.isWhitespace(buf[n - 1])) {\n \t\t\tn--;\n \t\t}\n-\t\t\n+\n+\t\tif (n == 0)\n+\t\t\treturn null;\n+\n \t\treturn RawParseUtils.decode(buf, 0, n);\n \t}\n \n-- \n1.6.2.5\n"}]}