diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-15 10:04:17 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-15 10:04:17 +0200 |
commit | 6226720b0e6a5f7cb9223fc50363def487831315 (patch) | |
tree | 10f70f8e41c91f5bf57f04b616f3e5afdb9f8407 /lib/git/tree.py | |
parent | b0e84a3401c84507dc017d6e4f57a9dfdb31de53 (diff) | |
parent | 4186a2dbbd48fd67ff88075c63bbd3e6c1d8a2df (diff) | |
download | gitpython-6226720b0e6a5f7cb9223fc50363def487831315.tar.gz |
Initial set of improvementes merged into master, including a class hierarchy redesign and performance improvements
Merge commit 'origin/improvements'
* commit 'origin/improvements': (38 commits)
test_performance: module containing benchmarks to get an idea of the achieved throughput
Removed plenty of mocked tree tests as they cannot work anymore with persistent commands that require stdin AND binary data - not even an adapter would help here. These tests will have to be replaced.
tree: now reads tress directly by parsing the binary data, allowing it to safe possibly hundreds of command calls
Refs are now truly dynamic - this costs a little bit of (persistent command) work, but assures refs behave as expected
persistent command signature changed to also return the hexsha from a possible input ref - the objects pointed to by refs are now baked on demand - perhaps it should change to always be re-retrieved using a property as it is relatively fast - this way refs can always be cached
test_blob: removed many redundant tests that would fail now as the mock cannot handle the complexity of the command backend
Implemented git command facility to keep persistent commands for fast object information retrieval
test: Added time-consuming test which could also be a benchmark in fact - currently it cause hundreds of command invocations which is slow
cmd: added option to return the process directly, allowing to read the output directly from the output stream
added Iterable interface to Ref type
renamed find_all to list_all, changed commit to use iterable interface in preparation for command changes
Added base for all iteratable objects
unified name of utils module, recently it was named util and utils in different packages
tree: renamed content_from_string to _from_string to make it private. Removed tests that were testing that method
tree: now behaves like a list with string indexing functionality - using a dict as cache is a problem as the tree is ordered, added blobs, trees and traverse method
test_base: Improved basic object creation as well as set hash tests
repo.active_branch now returns a Head object, not a string
IndexObjects are now checking their slots to raise a proper error message in case someone tries to access an unset path or mode - this information cannot be retrieved afterwards as IndexObject information is kept in the object that pointed at them. To find this information, one would have to search all objects which is not feasible
refs now take repo as first argument and derive from LazyMixin to allow them to dynamically retrieve their objects
renamed from_string and list_from_string to _from_string and _list_from_string to indicate their new status as private method, adjusted all callers respectively
...
Diffstat (limited to 'lib/git/tree.py')
-rw-r--r-- | lib/git/tree.py | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/lib/git/tree.py b/lib/git/tree.py deleted file mode 100644 index cfb0881c..00000000 --- a/lib/git/tree.py +++ /dev/null @@ -1,108 +0,0 @@ -# tree.py -# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors -# -# This module is part of GitPython and is released under -# the BSD License: http://www.opensource.org/licenses/bsd-license.php - -import os -from lazy import LazyMixin -import blob - -class Tree(LazyMixin): - def __init__(self, repo, id, mode=None, name=None): - LazyMixin.__init__(self) - self.repo = repo - self.id = id - self.mode = mode - self.name = name - self._contents = None - - def __bake__(self): - # Ensure the treeish references directly a tree - treeish = self.id - if not treeish.endswith(':'): - treeish = treeish + ':' - - # Read the tree contents. - self._contents = {} - for line in self.repo.git.ls_tree(self.id).splitlines(): - obj = self.content_from_string(self.repo, line) - if obj is not None: - self._contents[obj.name] = obj - - @staticmethod - def content_from_string(repo, text): - """ - Parse a content item and create the appropriate object - - ``repo`` - is the Repo - - ``text`` - is the single line containing the items data in `git ls-tree` format - - Returns - ``git.Blob`` or ``git.Tree`` - """ - try: - mode, typ, id, name = text.expandtabs(1).split(" ", 3) - except: - return None - - if typ == "tree": - return Tree(repo, id=id, mode=mode, name=name) - elif typ == "blob": - return blob.Blob(repo, id=id, mode=mode, name=name) - elif typ == "commit": - return None - else: - raise(TypeError, "Invalid type: %s" % typ) - - def __div__(self, file): - """ - Find the named object in this tree's contents - - Examples:: - - >>> Repo('/path/to/python-git').tree/'lib' - <git.Tree "6cc23ee138be09ff8c28b07162720018b244e95e"> - >>> Repo('/path/to/python-git').tree/'README.txt' - <git.Blob "8b1e02c0fb554eed2ce2ef737a68bb369d7527df"> - - Returns - ``git.Blob`` or ``git.Tree`` or ``None`` if not found - """ - return self.get(file) - - @property - def basename(self): - os.path.basename(self.name) - - def __repr__(self): - return '<git.Tree "%s">' % self.id - - # Implement the basics of the dict protocol: - # directories/trees can be seen as object dicts. - def __getitem__(self, key): - return self._contents[key] - - def __iter__(self): - return iter(self._contents) - - def __len__(self): - return len(self._contents) - - def __contains__(self, key): - return key in self._contents - - def get(self, key): - return self._contents.get(key) - - def items(self): - return self._contents.items() - - def keys(self): - return self._contents.keys() - - def values(self): - return self._contents.values() |