git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: git@vger.kernel.org
Subject: Re: [PATCH] Handle odd tag formats created by tools such as cvsimport.
Date: Thu, 01 Mar 2007 00:00:07 +0100	[thread overview]
Message-ID: <20070228225853.14043.66933.stgit@lathund.dewire.com> (raw)
In-Reply-To: <20070228222647.12021.99818.stgit@lathund.dewire.com

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 {

                 reply	other threads:[~2007-02-28 22:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070228225853.14043.66933.stgit@lathund.dewire.com \
    --to=robin.rosenberg@dewire.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).