]> source.dussan.org Git - jgit.git/commitdiff
Correct PersonIdent hashCode() and equals() to ignore milliseconds 63/1363/1
authorShawn O. Pearce <spearce@spearce.org>
Fri, 20 Aug 2010 22:42:52 +0000 (15:42 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Sat, 21 Aug 2010 00:38:52 +0000 (17:38 -0700)
Git doesn't store millisecond accuracy in person identity lines,
so a line that we create in Java and round-trip through a Git object
wouldn't compare as being equal.  Truncate to seconds when comparing
values to ensure the same identity is equal.

Change-Id: Ie4ebde64061f52c612714e89ad34de8ac2694b07
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java

index 0406684ea7cd73b29a70f45a92017ef04fc6e5da..25acee046c6e2b14b7c1082ef69888131f89f2fa 100644 (file)
@@ -268,7 +268,10 @@ public class PersonIdent {
        }
 
        public int hashCode() {
-               return getEmailAddress().hashCode() ^ (int) when;
+               int hc = getEmailAddress().hashCode();
+               hc *= 31;
+               hc += (int) (when / 1000L);
+               return hc;
        }
 
        public boolean equals(final Object o) {
@@ -276,7 +279,7 @@ public class PersonIdent {
                        final PersonIdent p = (PersonIdent) o;
                        return getName().equals(p.getName())
                                        && getEmailAddress().equals(p.getEmailAddress())
-                                       && when == p.when;
+                                       && when / 1000L == p.when / 1000L;
                }
                return false;
        }