{"thread":{"id":"7026","subject":"Re: [PATCH] Handle odd tag formats created by tools such as cvsimport.","startedAt":"2007-02-28T23:00:07Z","lastAt":"2007-02-28T23:00:07Z","messageCount":1,"participants":["Robin Rosenberg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"35903","messageId":"20070228225853.14043.66933.stgit@lathund.dewire.com","threadId":"7026","inReplyTo":null,"subject":"Re: [PATCH] Handle odd tag formats created by tools such as cvsimport.","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2007-02-28T23:00:07Z","receivedAt":"2007-02-28T23:00:07Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"These lack a date and have a message without a newline\n\nSigned-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n\nWhen time is missing we shouldn't compare it. I didn't run the tests before\nsubmitting.\n\n-- robin\n\n .../src/org/spearce/jgit/lib/PersonIdent.java      |   70 ++++++++++++-----------\n org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java |    8 +-\n 2 files changed, 41 insertions(+), 37 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PersonIdent.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PersonIdent.java\nindex bfcb34d..a566ff9 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/PersonIdent.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PersonIdent.java\n@@ -24,7 +24,7 @@ public class PersonIdent {\n \n \tprivate final String emailAddress;\n \n-\tprivate final long when;\n+\tprivate final Long when;\n \n \tprivate final int tzOffset;\n \n@@ -43,7 +43,7 @@ public class PersonIdent {\n \tpublic PersonIdent(final PersonIdent pi, final Date aWhen) {\n \t\tname = pi.getName();\n \t\temailAddress = pi.getEmailAddress();\n-\t\twhen = aWhen.getTime();\n+\t\twhen = new Long(aWhen.getTime());\n \t\ttzOffset = pi.tzOffset;\n \t}\n \n@@ -51,22 +51,22 @@ public class PersonIdent {\n \t\t\tfinal Date aWhen, final TimeZone aTZ) {\n \t\tname = aName;\n \t\temailAddress = aEmailAddress;\n-\t\twhen = aWhen.getTime();\n-\t\ttzOffset = aTZ.getOffset(when) / (60 * 1000);\n+\t\twhen = new Long(aWhen.getTime());\n+\t\ttzOffset = aTZ.getOffset(when.longValue()) / (60 * 1000);\n \t}\n \n \tpublic PersonIdent(final String aName, final String aEmailAddress,\n \t\t\tfinal long aWhen, final int aTZ) {\n \t\tname = aName;\n \t\temailAddress = aEmailAddress;\n-\t\twhen = aWhen;\n+\t\twhen = new Long(aWhen);\n \t\ttzOffset = aTZ;\n \t}\n \n \tpublic PersonIdent(final PersonIdent pi, final long aWhen, final int aTZ) {\n \t\tname = pi.getName();\n \t\temailAddress = pi.getEmailAddress();\n-\t\twhen = aWhen;\n+\t\twhen = new Long(aWhen);\n \t\ttzOffset = aTZ;\n \t}\n \n@@ -83,22 +83,23 @@ public class PersonIdent {\n \t\t}\n \t\tfinal int sp = in.indexOf(' ', gt + 2);\n \t\tif (sp == -1) {\n-\t\t\tthrow new IllegalArgumentException(\"Malformed PersonIdent string\"\n-\t\t\t\t\t+ \" (no time zone found): \" + in);\n-\t\t}\n-\t\tfinal String tzHoursStr = in.substring(sp + 1, sp + 4).trim();\n-\t\tfinal int tzHours;\n-\t\tif (tzHoursStr.charAt(0) == '+') {\n-\t\t\ttzHours = Integer.parseInt(tzHoursStr.substring(1));\n+\t\t\twhen = null;\n+\t\t\ttzOffset = -1;\n \t\t} else {\n-\t\t\ttzHours = Integer.parseInt(tzHoursStr);\n+\t\t\tfinal String tzHoursStr = in.substring(sp + 1, sp + 4).trim();\n+\t\t\tfinal int tzHours;\n+\t\t\tif (tzHoursStr.charAt(0) == '+') {\n+\t\t\t\ttzHours = Integer.parseInt(tzHoursStr.substring(1));\n+\t\t\t} else {\n+\t\t\t\ttzHours = Integer.parseInt(tzHoursStr);\n+\t\t\t}\n+\t\t\tfinal int tzMins = Integer.parseInt(in.substring(sp + 4).trim());\n+\t\t\twhen = new Long(Long.parseLong(in.substring(gt + 1, sp).trim()) * 1000);\n+\t\t\ttzOffset = tzHours * 60 + tzMins;\n \t\t}\n-\t\tfinal int tzMins = Integer.parseInt(in.substring(sp + 4).trim());\n \n \t\tname = in.substring(0, lt).trim();\n \t\temailAddress = in.substring(lt + 1, gt).trim();\n-\t\twhen = Long.parseLong(in.substring(gt + 1, sp).trim()) * 1000;\n-\t\ttzOffset = tzHours * 60 + tzMins;\n \t}\n \n \tpublic String getName() {\n@@ -110,11 +111,13 @@ public class PersonIdent {\n \t}\n \n \tpublic Date getWhen() {\n-\t\treturn new Date(when);\n+\t\tif (when != null)\n+\t\t\treturn new Date(when.longValue());\n+\t\treturn null;\n \t}\n \n \tpublic int hashCode() {\n-\t\treturn getEmailAddress().hashCode() ^ ((int) when);\n+\t\treturn getEmailAddress().hashCode() ^ (when.intValue());\n \t}\n \n \tpublic boolean equals(final Object o) {\n@@ -122,7 +125,7 @@ public class PersonIdent {\n \t\t\tfinal PersonIdent p = (PersonIdent) o;\n \t\t\treturn getName().equals(p.getName())\n \t\t\t\t\t&& getEmailAddress().equals(p.getEmailAddress())\n-\t\t\t\t\t&& when == p.when;\n+\t\t\t\t\t&& (when == p.when || when!=null && when.equals(p.when));\n \t\t}\n \t\treturn false;\n \t}\n@@ -148,18 +151,19 @@ public class PersonIdent {\n \t\tr.append(\" <\");\n \t\tr.append(getEmailAddress());\n \t\tr.append(\"> \");\n-\t\tr.append(when / 1000);\n-\t\tr.append(' ');\n-\t\tr.append(sign);\n-\t\tif (offsetHours < 10) {\n-\t\t\tr.append('0');\n-\t\t}\n-\t\tr.append(offsetHours);\n-\t\tif (offsetMins < 10) {\n-\t\t\tr.append('0');\n+\t\tif (when != null) {\n+\t\t\tr.append(when.longValue() / 1000);\n+\t\t\tr.append(' ');\n+\t\t\tr.append(sign);\n+\t\t\tif (offsetHours < 10) {\n+\t\t\t\tr.append('0');\n+\t\t\t}\n+\t\t\tr.append(offsetHours);\n+\t\t\tif (offsetMins < 10) {\n+\t\t\t\tr.append('0');\n+\t\t\t}\n+\t\t\tr.append(offsetMins);\n \t\t}\n-\t\tr.append(offsetMins);\n-\n \t\treturn r.toString();\n \t}\n \n@@ -176,7 +180,9 @@ public class PersonIdent {\n \t\tr.append(\", \");\n \t\tr.append(getEmailAddress());\n \t\tr.append(\", \");\n-\t\tr.append(new Date(when + minutes * 60));\n+\t\tif (when != null) {\n+\t\t\tr.append(new Date(when.longValue() + minutes * 60));\n+\t\t}\n \t\tr.append(\"]\");\n \n \t\treturn r.toString();\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java\nindex d9e6990..cd59ee9 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java\n@@ -94,11 +94,7 @@ public class Tag {\n \t\t\t\t}\n \t\t\t\ttagger = new PersonIdent(n.substring(\"tagger \".length()));\n \n-\t\t\t\tn = br.readLine();\n-\t\t\t\tif (n == null || !n.equals(\"\")) {\n-\t\t\t\t\tthrow new CorruptObjectException(tagId,\n-\t\t\t\t\t\t\t\"malformed header\");\n-\t\t\t\t}\n+\t\t\t\t// Message should start with an empty line, but\n \t\t\t\tStringBuffer tempMessage = new StringBuffer();\n \t\t\t\tchar[] readBuf = new char[2048];\n \t\t\t\tint readLen;\n@@ -106,6 +102,8 @@ public class Tag {\n \t\t\t\t\ttempMessage.append(readBuf, 0, readLen);\n \t\t\t\t}\n \t\t\t\tmessage = tempMessage.toString();\n+\t\t\t\tif (message.startsWith(\"\\n\"))\n+\t\t\t\t\tmessage = message.substring(1);\n \t\t\t} catch (IOException e) {\n \t\t\t\te.printStackTrace();\n \t\t\t} finally {\n"}]}