Explorar o código

Add simple lookup function to Tree.

Jelmer Vernooij %!s(int64=16) %!d(string=hai) anos
pai
achega
5b199401b3
Modificáronse 1 ficheiros con 6 adicións e 0 borrados
  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