Correct PersonIdent hashCode() and equals() to ignore milliseconds

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>
This commit is contained in:
Shawn O. Pearce 2010-08-20 15:42:52 -07:00
parent 746ebda381
commit cf9537c8ce
1 changed files with 5 additions and 2 deletions

View File

@ -268,7 +268,10 @@ public int getTimeZoneOffset() {
}
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 boolean equals(final Object o) {
final PersonIdent p = (PersonIdent) o;
return getName().equals(p.getName())
&& getEmailAddress().equals(p.getEmailAddress())
&& when == p.when;
&& when / 1000L == p.when / 1000L;
}
return false;
}