# HG changeset patch # User Laurent Charignon # Date 2015-03-13 21:08:30 # Node ID 31edcea517c11a53c608113592523244d6317841 # Parent 01b39149ebb383f084243245450f736d526b9917 record: add comparison methods for recordhunk class diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -893,6 +893,21 @@ class recordhunk(object): self.hunk = hunk self.added, self.removed = self.countchanges(self.hunk) + def __eq__(self, v): + if not isinstance(v, recordhunk): + return False + + return ((v.hunk == self.hunk) and + (v.proc == self.proc) and + (self.fromline == v.fromline) and + (self.header.files() == v.header.files())) + + def __hash__(self): + return hash((tuple(self.hunk), + tuple(self.header.files()), + self.fromline, + self.proc)) + def countchanges(self, hunk): """hunk -> (n+,n-)""" add = len([h for h in hunk if h[0] == '+'])