Browse Source

Add comparators to ShaFile.

Jelmer Vernooij 10 năm trước cách đây
mục cha
commit
959533b2af
1 tập tin đã thay đổi với 15 bổ sung0 xóa
  1. 15 0
      dulwich/objects.py

+ 15 - 0
dulwich/objects.py

@@ -519,6 +519,21 @@ class ShaFile(object):
         """
         return isinstance(other, ShaFile) and self.id == other.id
 
+    def __lt__(self, other):
+        if not isinstance(other, ShaFile):
+            raise TypeError
+        return self.id < other.id
+
+    def __le__(self, other):
+        if not isinstance(other, ShaFile):
+            raise TypeError
+        return self.id <= other.id
+
+    def __cmp__(self, other):
+        if not isinstance(other, ShaFile):
+            raise TypeError
+        return cmp(self.id, other.id)
+
 
 class Blob(ShaFile):
     """A Git Blob object."""