diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificate.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificate.java index 165a93908..413b02b1c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificate.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificate.java @@ -50,6 +50,7 @@ import static org.eclipse.jgit.transport.PushCertificateParser.VERSION; import java.text.MessageFormat; import java.util.List; +import java.util.Objects; import org.eclipse.jgit.internal.JGitText; @@ -216,4 +217,45 @@ public class PushCertificate { } return sb.toString(); } + + @Override + public int hashCode() { + return signature.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof PushCertificate)) { + return false; + } + PushCertificate p = (PushCertificate) o; + return version.equals(p.version) + && pusher.equals(p.pusher) + && Objects.equals(pushee, p.pushee) + && nonceStatus == p.nonceStatus + && signature.equals(p.signature) + && commandsEqual(this, p); + } + + private static boolean commandsEqual(PushCertificate c1, PushCertificate c2) { + if (c1.commands.size() != c2.commands.size()) { + return false; + } + for (int i = 0; i < c1.commands.size(); i++) { + ReceiveCommand cmd1 = c1.commands.get(i); + ReceiveCommand cmd2 = c2.commands.get(i); + if (!cmd1.getOldId().equals(cmd2.getOldId()) + || !cmd1.getNewId().equals(cmd2.getNewId()) + || !cmd1.getRefName().equals(cmd2.getRefName())) { + return false; + } + } + return true; + } + + @Override + public String toString() { + return getClass().getSimpleName() + '[' + + toText() + signature + ']'; + } }