浏览代码

Add comparators to ShaFile.

Jelmer Vernooij 9 年之前
父节点
当前提交
959533b2af
共有 1 个文件被更改,包括 15 次插入0 次删除
  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."""