| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 919164d commit bb24f67
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,6 +60,8 @@ Repo | |||
| 60 | 60 | related repositories, i.e. clones, git-rev-list would be sufficient to find | |
| 61 | 61 | commits that would need to be transferred for example. | |
| 62 | 62 | - 'create' method which equals the 'init' method's functionality | |
| 63 | + - 'diff' - it returned a mere string which still had to be parsed | ||
| 64 | + - 'commit_diff' - moved to Commit, Tree and Diff types respectively | ||
| 63 | 65 | * Renamed the following methods: | |
| 64 | 66 | - commits to iter_commits to improve the performance, adjusted signature | |
| 65 | 67 | - init_bare to init, implying less about the options to be used | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,22 +15,12 @@ class Object(LazyMixin): | |||
| 15 | 15 | ||
| 16 | 16 | This Object also serves as a constructor for instances of the correct type:: | |
| 17 | 17 | ||
| 18 | - inst = Object(repo,id) | ||
| 18 | + inst = Object.new(repo,id) | ||
| 19 | 19 | """ | |
| 20 | 20 | TYPES = ("blob", "tree", "commit", "tag") | |
| 21 | 21 | __slots__ = ("repo", "id", "size", "data" ) | |
| 22 | 22 | type = None # to be set by subclass | |
| 23 | 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 | - | ||
| 34 | 24 | def __init__(self, repo, id): | |
| 35 | 25 | """ | |
| 36 | 26 | Initialize an object by identifying it by its id. All keyword arguments | |
@@ -45,7 +35,25 @@ def __init__(self, repo, id): | |||
| 45 | 35 | super(Object,self).__init__() | |
| 46 | 36 | self.repo = repo | |
| 47 | 37 | self.id = id | |
| 48 | - | ||
| 38 | + | ||
| 39 | + @classmethod | ||
| 40 | + def new(cls, repo, id): | ||
| 41 | + """ | ||
| 42 | + Return | ||
| 43 | + New Object instance of a type appropriate to the object type behind | ||
| 44 | + id. The id of the newly created object will be a hexsha even though | ||
| 45 | + the input id may have been a Reference or Rev-Spec | ||
| 46 | + | ||
| 47 | + Note | ||
| 48 | + This cannot be a __new__ method as it would always call __init__ | ||
| 49 | + with the input id which is not necessarily a hexsha. | ||
| 50 | + """ | ||
| 51 | + hexsha, typename, size = repo.git.get_object_header(id) | ||
| 52 | + obj_type = utils.get_object_type_by_name(typename) | ||
| 53 | + inst = obj_type(repo, hexsha) | ||
| 54 | + inst.size = size | ||
| 55 | + return inst | ||
| 56 | + | ||
| 49 | 57 | def _set_self_from_args_(self, args_dict): | |
| 50 | 58 | """ | |
| 51 | 59 | Initialize attributes on self from the given dict that was retrieved | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,7 +72,7 @@ def object(self): | |||
| 72 | 72 | """ | |
| 73 | 73 | # have to be dynamic here as we may be a tag which can point to anything | |
| 74 | 74 | # Our path will be resolved to the hexsha which will be used accordingly | |
| 75 | - return Object(self.repo, self.path) | ||
| 75 | + return Object.new(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 | |
|---|---|---|---|
@@ -106,6 +106,15 @@ def heads(self): | |||
| 106 | 106 | # alias heads | |
| 107 | 107 | branches = heads | |
| 108 | 108 | ||
| 109 | + @property | ||
| 110 | + def head(self): | ||
| 111 | + """ | ||
| 112 | + Return | ||
| 113 | + Head Object, reference pointing to the current head of the repository | ||
| 114 | + """ | ||
| 115 | + return Head(self,'HEAD') | ||
| 116 | + | ||
| 117 | + | ||
| 109 | 118 | @property | |
| 110 | 119 | def tags(self): | |
| 111 | 120 | """ | |
@@ -129,7 +138,7 @@ def commit(self, rev=None): | |||
| 129 | 138 | if rev is None: | |
| 130 | 139 | rev = self.active_branch | |
| 131 | 140 | ||
| 132 | - c = Object(self, rev) | ||
| 141 | + c = Object.new(self, rev) | ||
| 133 | 142 | assert c.type == "commit", "Revision %s did not point to a commit, but to %s" % (rev, c) | |
| 134 | 143 | return c | |
| 135 | 144 | ||
@@ -327,34 +336,7 @@ def active_branch(self): | |||
| 327 | 336 | """ | |
| 328 | 337 | return Head( self, self.git.symbolic_ref('HEAD').strip() ) | |
| 329 | 338 | ||
| 330 | - | ||
| 331 | - def diff(self, a, b, *paths): | ||
| 332 | - """ | ||
| 333 | - The diff from commit ``a`` to commit ``b``, optionally restricted to the given file(s) | ||
| 334 | - | ||
| 335 | - ``a`` | ||
| 336 | - is the base commit | ||
| 337 | - ``b`` | ||
| 338 | - is the other commit | ||
| 339 | - | ||
| 340 | - ``paths`` | ||
| 341 | - is an optional list of file paths on which to restrict the diff | ||
| 342 | 339 | ||
| 343 | - Returns | ||
| 344 | - ``str`` | ||
| 345 | - """ | ||
| 346 | - return self.git.diff(a, b, '--', *paths) | ||
| 347 | - | ||
| 348 | - def commit_diff(self, commit): | ||
| 349 | - """ | ||
| 350 | - The commit diff for the given commit | ||
| 351 | - ``commit`` is the commit name/id | ||
| 352 | - | ||
| 353 | - Returns | ||
| 354 | - ``git.Diff[]`` | ||
| 355 | - """ | ||
| 356 | - return Commit.diff(self, commit) | ||
| 357 | - | ||
| 358 | 340 | def blame(self, rev, file): | |
| 359 | 341 | """ | |
| 360 | 342 | The blame information for the given file at the given revision. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,3 +90,6 @@ def test_get_object_type_by_name(self): | |||
| 90 | 90 | ||
| 91 | 91 | assert_raises( ValueError, get_object_type_by_name, "doesntexist" ) | |
| 92 | 92 | ||
| 93 | + def test_object_resolution(self): | ||
| 94 | + # objects must be resolved to shas so they compare equal | ||
| 95 | + assert self.repo.head.object == self.repo.active_branch.object | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -199,6 +199,9 @@ def test_active_branch(self, git): | |||
| 199 | 199 | assert_equal(self.repo.active_branch.name, 'major-refactoring') | |
| 200 | 200 | assert_equal(git.call_args, (('symbolic_ref', 'HEAD'), {})) | |
| 201 | 201 | ||
| 202 | + def test_head(self): | ||
| 203 | + assert self.repo.head.object == self.repo.active_branch.object | ||
| 204 | + | ||
| 202 | 205 | @patch_object(Git, '_call_process') | |
| 203 | 206 | def test_should_display_blame_information(self, git): | |
| 204 | 207 | git.return_value = fixture('blame') | |
| Back | FazBrowse Home | New Git URL |
0 commit comments