* [JGIT PATCH 1/2] fixed error in whitespace handling of RefDatabase#readLine
@ 2009-09-02 18:00 Mark Struberg
2009-09-02 18:00 ` [JGIT PATCH 2/2] improve the handling of empty lines Mark Struberg
0 siblings, 1 reply; 2+ messages in thread
From: Mark Struberg @ 2009-09-02 18:00 UTC (permalink / raw)
To: git, spearce; +Cc: Mark Struberg
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(-)
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [JGIT PATCH 2/2] improve the handling of empty lines
2009-09-02 18:00 [JGIT PATCH 1/2] fixed error in whitespace handling of RefDatabase#readLine Mark Struberg
@ 2009-09-02 18:00 ` Mark Struberg
0 siblings, 0 replies; 2+ messages in thread
From: Mark Struberg @ 2009-09-02 18:00 UTC (permalink / raw)
To: git, spearce; +Cc: Mark Struberg
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-09-02 18:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-02 18:00 [JGIT PATCH 1/2] fixed error in whitespace handling of RefDatabase#readLine Mark Struberg
2009-09-02 18:00 ` [JGIT PATCH 2/2] improve the handling of empty lines Mark Struberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).