[EGIT PATCH 8/9] Handle odd tag formats created by tools such as cvsimport.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



These lack a date and have a message without a newline

Signed-off-by: Robin Rosenberg <robin.rosenberg@xxxxxxxxxx>
---

 .../src/org/spearce/jgit/lib/PersonIdent.java      |   68 +++++++++++++----------
 org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java |    8 +-
 2 files changed, 40 insertions(+), 36 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..50a6a3b 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) {
@@ -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 {
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]