| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -336,8 +336,9 @@ def _parse_object_header(self, header_line): | |||
| 336 | 336 | """ | |
| 337 | 337 | tokens = header_line.split() | |
| 338 | 338 | if len(tokens) != 3: | |
| 339 | - raise ValueError( "SHA named %s could not be resolved" % tokens[0] ) | ||
| 340 | - | ||
| 339 | + raise ValueError("SHA named %s could not be resolved" % tokens[0] ) | ||
| 340 | + if len(tokens[0]) != 40: | ||
| 341 | + raise ValueError("Failed to parse header: %r" % header_line) | ||
| 341 | 342 | return (tokens[0], tokens[1], int(tokens[2])) | |
| 342 | 343 | ||
| 343 | 344 | def __prepare_ref(self, ref): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -226,7 +226,7 @@ def __getitem__(self,item): | |||
| 226 | 226 | if isinstance(item, basestring): | |
| 227 | 227 | # compatability | |
| 228 | 228 | for obj in self._cache: | |
| 229 | - if obj.path == item: | ||
| 229 | + if obj.name == item: | ||
| 230 | 230 | return obj | |
| 231 | 231 | # END for each obj | |
| 232 | 232 | raise KeyError( "Blob or Tree named %s not found" % item ) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -349,12 +349,12 @@ def iter_trees(self, *args, **kwargs): | |||
| 349 | 349 | """ | |
| 350 | 350 | return ( c.tree for c in self.iter_commits(*args, **kwargs) ) | |
| 351 | 351 | ||
| 352 | - def tree(self, ref=None): | ||
| 352 | + def tree(self, rev=None): | ||
| 353 | 353 | """ | |
| 354 | - The Tree object for the given treeish reference | ||
| 354 | + The Tree object for the given treeish revision | ||
| 355 | 355 | ||
| 356 | - ``ref`` | ||
| 357 | - is a Ref instance defaulting to the active_branch if None. | ||
| 356 | + ``rev`` | ||
| 357 | + is a revision pointing to a Treeish ( being a commit or tree ) | ||
| 358 | 358 | ||
| 359 | 359 | Examples:: | |
| 360 | 360 | ||
@@ -364,32 +364,19 @@ def tree(self, ref=None): | |||
| 364 | 364 | ``git.Tree`` | |
| 365 | 365 | ||
| 366 | 366 | NOTE | |
| 367 | - A ref is requried here to assure you point to a commit or tag. Otherwise | ||
| 368 | - it is not garantueed that you point to the root-level tree. | ||
| 369 | - | ||
| 370 | 367 | If you need a non-root level tree, find it by iterating the root tree. Otherwise | |
| 371 | 368 | it cannot know about its path relative to the repository root and subsequent | |
| 372 | 369 | operations might have unexpected results. | |
| 373 | 370 | """ | |
| 374 | - if ref is None: | ||
| 375 | - ref = self.active_branch | ||
| 376 | - if not isinstance(ref, Reference): | ||
| 377 | - raise ValueError( "Reference required, got %r" % ref ) | ||
| 378 | - | ||
| 379 | - | ||
| 380 | - # As we are directly reading object information, we must make sure | ||
| 381 | - # we truly point to a tree object. We resolve the ref to a sha in all cases | ||
| 382 | - # to assure the returned tree can be compared properly. Except for | ||
| 383 | - # heads, ids should always be hexshas | ||
| 384 | - hexsha, typename, size = self.git.get_object_header( ref ) | ||
| 385 | - if typename != "tree": | ||
| 386 | - # will raise if this is not a valid tree | ||
| 387 | - hexsha, typename, size = self.git.get_object_header( str(ref)+'^{tree}' ) | ||
| 388 | - # END tree handling | ||
| 389 | - ref = hexsha | ||
| 390 | - | ||
| 391 | - # the root has an empty relative path and the default mode | ||
| 392 | - return Tree(self, ref, 0, '') | ||
| 371 | + if rev is None: | ||
| 372 | + rev = self.active_branch | ||
| 373 | + | ||
| 374 | + c = Object.new(self, rev) | ||
| 375 | + if c.type == "commit": | ||
| 376 | + return c.tree | ||
| 377 | + elif c.type == "tree": | ||
| 378 | + return c | ||
| 379 | + raise ValueError( "Revision %s did not point to a treeish, but to %s" % (rev, c)) | ||
| 393 | 380 | ||
| 394 | 381 | def iter_commits(self, rev=None, paths='', **kwargs): | |
| 395 | 382 | """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,6 +38,14 @@ def test_heads_should_populate_head_data(self): | |||
| 38 | 38 | ||
| 39 | 39 | assert isinstance(self.rorepo.heads.master, Head) | |
| 40 | 40 | assert isinstance(self.rorepo.heads['master'], Head) | |
| 41 | + | ||
| 42 | + def test_tree_from_revision(self): | ||
| 43 | + tree = self.rorepo.tree('0.1.6') | ||
| 44 | + assert tree.type == "tree" | ||
| 45 | + assert self.rorepo.tree(tree) == tree | ||
| 46 | + | ||
| 47 | + # try from invalid revision that does not exist | ||
| 48 | + self.failUnlessRaises(ValueError, self.rorepo.tree, 'hello world') | ||
| 41 | 49 | ||
| 42 | 50 | @patch_object(Git, '_call_process') | |
| 43 | 51 | def test_commits(self, git): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ def setUp(self): | |||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | 18 | def test_traverse(self): | |
| 19 | - root = self.repo.tree() | ||
| 19 | + root = self.repo.tree('0.1.6') | ||
| 20 | 20 | num_recursive = 0 | |
| 21 | 21 | all_items = list() | |
| 22 | 22 | for obj in root.traverse(): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments