浏览代码

Add simple lookup function to Tree.

Jelmer Vernooij 16 年之前
父节点
当前提交
5b199401b3
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      dulwich/objects.py

+ 6 - 0
dulwich/objects.py

@@ -344,6 +344,12 @@ class Tree(ShaFile):
         """Return a list of tuples describing the tree entries"""
         return self._entries
 
+    def __getitem__(self, name):
+        for mode, entry, hexsha in self.entries():
+            if entry == name:
+                return mode, hexsha
+        raise KeyError(name)
+
     def _parse_text(self):
         """Grab the entries in the tree"""
         count = 0