* Re: [PATCH] Handle odd tag formats created by tools such as cvsimport.
@ 2007-02-28 23:00 Robin Rosenberg
0 siblings, 0 replies; only message in thread
From: Robin Rosenberg @ 2007-02-28 23:00 UTC (permalink / raw)
To: git
These lack a date and have a message without a newline
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
When time is missing we shouldn't compare it. I didn't run the tests before
submitting.
-- robin
.../src/org/spearce/jgit/lib/PersonIdent.java | 70 ++++++++++++-----------
org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java | 8 +-
2 files changed, 41 insertions(+), 37 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PersonIdent.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PersonIdent.java
index bfcb34d..a566ff9 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/PersonIdent.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PersonIdent.java
@@ -24,7 +24,7 @@ public class PersonIdent {
private final String emailAddress;
- private final long when;
+ private final Long when;
private final int tzOffset;
@@ -43,7 +43,7 @@ public class PersonIdent {
public PersonIdent(final PersonIdent pi, final Date aWhen) {
name = pi.getName();
emailAddress = pi.getEmailAddress();
- when = aWhen.getTime();
+ when = new Long(aWhen.getTime());
tzOffset = pi.tzOffset;
}
@@ -51,22 +51,22 @@ public class PersonIdent {
final Date aWhen, final TimeZone aTZ) {
name = aName;
emailAddress = aEmailAddress;
- when = aWhen.getTime();
- tzOffset = aTZ.getOffset(when) / (60 * 1000);
+ when = new Long(aWhen.getTime());
+ tzOffset = aTZ.getOffset(when.longValue()) / (60 * 1000);
}
public PersonIdent(final String aName, final String aEmailAddress,
final long aWhen, final int aTZ) {
name = aName;
emailAddress = aEmailAddress;
- when = aWhen;
+ when = new Long(aWhen);
tzOffset = aTZ;
}
public PersonIdent(final PersonIdent pi, final long aWhen, final int aTZ) {
name = pi.getName();
emailAddress = pi.getEmailAddress();
- when = aWhen;
+ when = new Long(aWhen);
tzOffset = aTZ;
}
@@ -83,22 +83,23 @@ public class PersonIdent {
}
final int sp = in.indexOf(' ', gt + 2);
if (sp == -1) {
- throw new IllegalArgumentException("Malformed PersonIdent string"
- + " (no time zone found): " + in);
- }
- final String tzHoursStr = in.substring(sp + 1, sp + 4).trim();
- final int tzHours;
- if (tzHoursStr.charAt(0) == '+') {
- tzHours = Integer.parseInt(tzHoursStr.substring(1));
+ when = null;
+ tzOffset = -1;
} else {
- tzHours = Integer.parseInt(tzHoursStr);
+ final String tzHoursStr = in.substring(sp + 1, sp + 4).trim();
+ final int tzHours;
+ if (tzHoursStr.charAt(0) == '+') {
+ tzHours = Integer.parseInt(tzHoursStr.substring(1));
+ } else {
+ tzHours = Integer.parseInt(tzHoursStr);
+ }
+ final int tzMins = Integer.parseInt(in.substring(sp + 4).trim());
+ when = new Long(Long.parseLong(in.substring(gt + 1, sp).trim()) * 1000);
+ tzOffset = tzHours * 60 + tzMins;
}
- final int tzMins = Integer.parseInt(in.substring(sp + 4).trim());
name = in.substring(0, lt).trim();
emailAddress = in.substring(lt + 1, gt).trim();
- when = Long.parseLong(in.substring(gt + 1, sp).trim()) * 1000;
- tzOffset = tzHours * 60 + tzMins;
}
public String getName() {
@@ -110,11 +111,13 @@ public class PersonIdent {
}
public Date getWhen() {
- return new Date(when);
+ if (when != null)
+ return new Date(when.longValue());
+ return null;
}
public int hashCode() {
- return getEmailAddress().hashCode() ^ ((int) when);
+ return getEmailAddress().hashCode() ^ (when.intValue());
}
public boolean equals(final Object o) {
@@ -122,7 +125,7 @@ public class PersonIdent {
final PersonIdent p = (PersonIdent) o;
return getName().equals(p.getName())
&& getEmailAddress().equals(p.getEmailAddress())
- && when == p.when;
+ && (when == p.when || when!=null && when.equals(p.when));
}
return false;
}
@@ -148,18 +151,19 @@ public class PersonIdent {
r.append(" <");
r.append(getEmailAddress());
r.append("> ");
- r.append(when / 1000);
- r.append(' ');
- r.append(sign);
- if (offsetHours < 10) {
- r.append('0');
- }
- r.append(offsetHours);
- if (offsetMins < 10) {
- r.append('0');
+ if (when != null) {
+ r.append(when.longValue() / 1000);
+ r.append(' ');
+ r.append(sign);
+ if (offsetHours < 10) {
+ r.append('0');
+ }
+ r.append(offsetHours);
+ if (offsetMins < 10) {
+ r.append('0');
+ }
+ r.append(offsetMins);
}
- r.append(offsetMins);
-
return r.toString();
}
@@ -176,7 +180,9 @@ public class PersonIdent {
r.append(", ");
r.append(getEmailAddress());
r.append(", ");
- r.append(new Date(when + minutes * 60));
+ if (when != null) {
+ r.append(new Date(when.longValue() + minutes * 60));
+ }
r.append("]");
return r.toString();
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java
index d9e6990..cd59ee9 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java
@@ -94,11 +94,7 @@ public class Tag {
}
tagger = new PersonIdent(n.substring("tagger ".length()));
- n = br.readLine();
- if (n == null || !n.equals("")) {
- throw new CorruptObjectException(tagId,
- "malformed header");
- }
+ // Message should start with an empty line, but
StringBuffer tempMessage = new StringBuffer();
char[] readBuf = new char[2048];
int readLen;
@@ -106,6 +102,8 @@ public class Tag {
tempMessage.append(readBuf, 0, readLen);
}
message = tempMessage.toString();
+ if (message.startsWith("\n"))
+ message = message.substring(1);
} catch (IOException e) {
e.printStackTrace();
} finally {
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2007-02-28 22:58 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-28 23:00 [PATCH] Handle odd tag formats created by tools such as cvsimport Robin Rosenberg
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).