| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,17 +5,32 @@ | |||
| 5 | 5 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php | |
| 6 | 6 | import os | |
| 7 | 7 | from git.utils import LazyMixin | |
| 8 | + import utils | ||
| 8 | 9 | ||
| 9 | 10 | _assertion_msg_format = "Created object %r whose python type %r disagrees with the acutal git object type %r" | |
| 10 | 11 | ||
| 11 | 12 | class Object(LazyMixin): | |
| 12 | 13 | """ | |
| 13 | 14 | Implements an Object which may be Blobs, Trees, Commits and Tags | |
| 15 | + | ||
| 16 | + This Object also serves as a constructor for instances of the correct type:: | ||
| 17 | + | ||
| 18 | + inst = Object(repo,id) | ||
| 14 | 19 | """ | |
| 15 | 20 | TYPES = ("blob", "tree", "commit", "tag") | |
| 16 | 21 | __slots__ = ("repo", "id", "size", "data" ) | |
| 17 | 22 | type = None # to be set by subclass | |
| 18 | 23 | ||
| 24 | + def __new__(cls, repo, id, *args, **kwargs): | ||
| 25 | + if cls is Object: | ||
| 26 | + hexsha, typename, size = repo.git.get_object_header(id) | ||
| 27 | + obj_type = utils.get_object_type_by_name(typename) | ||
| 28 | + inst = super(Object,cls).__new__(obj_type, repo, hexsha, *args, **kwargs) | ||
| 29 | + inst.size = size | ||
| 30 | + return inst | ||
| 31 | + else: | ||
| 32 | + return super(Object,cls).__new__(cls, repo, id, *args, **kwargs) | ||
| 33 | + | ||
| 19 | 34 | def __init__(self, repo, id): | |
| 20 | 35 | """ | |
| 21 | 36 | Initialize an object by identifying it by its id. All keyword arguments | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,6 @@ | |||
| 7 | 7 | Module for general utility functions | |
| 8 | 8 | """ | |
| 9 | 9 | import re | |
| 10 | - import commit, tag, blob, tree | ||
| 11 | 10 | from git.actor import Actor | |
| 12 | 11 | ||
| 13 | 12 | def get_object_type_by_name(object_type_name): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -71,8 +71,8 @@ def object(self): | |||
| 71 | 71 | always point to the actual object as it gets re-created on each query | |
| 72 | 72 | """ | |
| 73 | 73 | # have to be dynamic here as we may be a tag which can point to anything | |
| 74 | - hexsha, typename, size = self.repo.git.get_object_header(self.path) | ||
| 75 | - return get_object_type_by_name(typename)(self.repo, hexsha) | ||
| 74 | + # Our path will be resolved to the hexsha which will be used accordingly | ||
| 75 | + return Object(self.repo, self.path) | ||
| 76 | 76 | ||
| 77 | 77 | @classmethod | |
| 78 | 78 | def iter_items(cls, repo, common_path = "refs", **kwargs): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -129,10 +129,8 @@ def commit(self, rev=None): | |||
| 129 | 129 | if rev is None: | |
| 130 | 130 | rev = self.active_branch | |
| 131 | 131 | ||
| 132 | - # NOTE: currently we are not checking wheter rev really points to a commit | ||
| 133 | - # If not, the system will barf on access of the object, but we don't do that | ||
| 134 | - # here to safe cycles | ||
| 135 | - c = Commit(self, rev) | ||
| 132 | + c = Object(self, rev) | ||
| 133 | + assert c.type == "commit", "Revision %s did not point to a commit, but to %s" % (rev, c) | ||
| 136 | 134 | return c | |
| 137 | 135 | ||
| 138 | 136 | def tree(self, ref=None): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,14 +65,6 @@ def test_commits(self, git): | |||
| 65 | 65 | ||
| 66 | 66 | assert_true(git.called) | |
| 67 | 67 | ||
| 68 | - @patch_object(Git, '_call_process') | ||
| 69 | - def test_commit(self, git): | ||
| 70 | - git.return_value = ListProcessAdapter(fixture('rev_list_single')) | ||
| 71 | - | ||
| 72 | - commit = self.repo.commit('4c8124ffcf4039d292442eeccabdeca5af5c5017') | ||
| 73 | - | ||
| 74 | - assert_equal("4c8124ffcf4039d292442eeccabdeca5af5c5017", commit.id) | ||
| 75 | - | ||
| 76 | 68 | @patch_object(Repo, '__init__') | |
| 77 | 69 | @patch_object(Git, '_call_process') | |
| 78 | 70 | def test_init_bare(self, git, repo): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments