diff options
-rw-r--r-- | CHANGES | 36 | ||||
-rw-r--r-- | lib/git/blob.py | 16 | ||||
-rw-r--r-- | lib/git/diff.py | 4 | ||||
-rw-r--r-- | lib/git/tree.py | 14 | ||||
-rw-r--r-- | test/git/test_blob.py | 2 | ||||
-rw-r--r-- | test/git/test_commit.py | 20 | ||||
-rw-r--r-- | test/git/test_tree.py | 4 |
7 files changed, 52 insertions, 44 deletions
@@ -1,6 +1,28 @@ ======= CHANGES ======= + +0.1.X +===== +( Future Release ) +General +------- +* See changes in Diff class as your client code needs adjustments to work with it + +Diff +---- +* Members a a_commit and b_commit renamed to a_blob and b_blob - they are populated + with Blob objects if possible +* Members a_path and b_path removed as this information is kept in the blobs + +Blob +---- +* former 'name' member renamed to path as it suits the actual data better + +Tree +---- +* former 'name' member renamed to path as it suits the actual data better + 0.1.6 ===== @@ -49,20 +71,6 @@ Repo * Corrected ``commits_between`` always returning None instead of the reversed list. - -0.1.X -===== -( Future Release ) -General -------- -* See changes in Diff class as your client code needs adjustments to work with it - -Diff ----- -* Members a a_commit and b_commit renamed to a_blob and b_blob - they are populated - with Blob objects if possible -* Members a_path and b_path removed as this information is kept in the blobs - 0.1.5 ===== diff --git a/lib/git/blob.py b/lib/git/blob.py index 82a41f73..dac0888f 100644 --- a/lib/git/blob.py +++ b/lib/git/blob.py @@ -15,7 +15,7 @@ class Blob(object): """A Blob encapsulates a git blob object""" DEFAULT_MIME_TYPE = "text/plain" - def __init__(self, repo, id, mode=None, name=None): + def __init__(self, repo, id, mode=None, path=None): """ Create an unbaked Blob containing just the specified attributes @@ -28,8 +28,8 @@ class Blob(object): ``mode`` is the file mode - ``name`` - is the file name + ``path`` + is the path to the file Returns git.Blob @@ -37,7 +37,7 @@ class Blob(object): self.repo = repo self.id = id self.mode = mode - self.name = name + self.path = path self._size = None self.data_stored = None @@ -83,17 +83,17 @@ class Blob(object): Defaults to 'text/plain' in case the actual file type is unknown. """ guesses = None - if self.name: - guesses = mimetypes.guess_type(self.name) + if self.path: + guesses = mimetypes.guess_type(self.path) return guesses and guesses[0] or self.DEFAULT_MIME_TYPE @property def basename(self): """ Returns - The basename of the Blobs file name + The basename of the Blobs file path """ - return os.path.basename(self.name) + return os.path.basename(self.path) @classmethod def blame(cls, repo, commit, file): diff --git a/lib/git/diff.py b/lib/git/diff.py index 44f55602..db12f1e4 100644 --- a/lib/git/diff.py +++ b/lib/git/diff.py @@ -38,11 +38,11 @@ class Diff(object): if not a_blob or re.search(r'^0{40}$', a_blob): self.a_blob = None else: - self.a_blob = blob.Blob(repo, id=a_blob, mode=a_mode, name=a_path) + self.a_blob = blob.Blob(repo, id=a_blob, mode=a_mode, path=a_path) if not b_blob or re.search(r'^0{40}$', b_blob): self.b_blob = None else: - self.b_blob = blob.Blob(repo, id=b_blob, mode=b_mode, name=b_path) + self.b_blob = blob.Blob(repo, id=b_blob, mode=b_mode, path=b_path) self.a_mode = a_mode self.b_mode = b_mode diff --git a/lib/git/tree.py b/lib/git/tree.py index cfb0881c..1b546f85 100644 --- a/lib/git/tree.py +++ b/lib/git/tree.py @@ -9,12 +9,12 @@ from lazy import LazyMixin import blob class Tree(LazyMixin): - def __init__(self, repo, id, mode=None, name=None): + def __init__(self, repo, id, mode=None, path=None): LazyMixin.__init__(self) self.repo = repo self.id = id self.mode = mode - self.name = name + self.path = path self._contents = None def __bake__(self): @@ -28,7 +28,7 @@ class Tree(LazyMixin): 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 + self._contents[obj.path] = obj @staticmethod def content_from_string(repo, text): @@ -45,14 +45,14 @@ class Tree(LazyMixin): ``git.Blob`` or ``git.Tree`` """ try: - mode, typ, id, name = text.expandtabs(1).split(" ", 3) + mode, typ, id, path = text.expandtabs(1).split(" ", 3) except: return None if typ == "tree": - return Tree(repo, id=id, mode=mode, name=name) + return Tree(repo, id=id, mode=mode, path=path) elif typ == "blob": - return blob.Blob(repo, id=id, mode=mode, name=name) + return blob.Blob(repo, id=id, mode=mode, path=path) elif typ == "commit": return None else: @@ -76,7 +76,7 @@ class Tree(LazyMixin): @property def basename(self): - os.path.basename(self.name) + os.path.basename(self.path) def __repr__(self): return '<git.Tree "%s">' % self.id diff --git a/test/git/test_blob.py b/test/git/test_blob.py index 5bd74ff7..8741fc1d 100644 --- a/test/git/test_blob.py +++ b/test/git/test_blob.py @@ -57,7 +57,7 @@ class TestBlob(object): assert_equal(git.call_args, (('cat_file', 'abc'), {'s': True})) def test_mime_type_should_return_mime_type_for_known_types(self): - blob = Blob(self.repo, **{'id': 'abc', 'name': 'foo.png'}) + blob = Blob(self.repo, **{'id': 'abc', 'path': 'foo.png'}) assert_equal("image/png", blob.mime_type) def test_mime_type_should_return_text_plain_for_unknown_types(self): diff --git a/test/git/test_commit.py b/test/git/test_commit.py index d6bd6120..fb376b02 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -37,8 +37,8 @@ class TestCommit(object): assert_equal(15, len(diffs)) - assert_equal('.gitignore', diffs[0].a_blob.name) - assert_equal('.gitignore', diffs[0].b_blob.name) + assert_equal('.gitignore', diffs[0].a_blob.path) + assert_equal('.gitignore', diffs[0].b_blob.path) assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs[0].a_blob.id) assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diffs[0].b_blob.id) assert_equal('100644', diffs[0].b_blob.mode) @@ -46,7 +46,7 @@ class TestCommit(object): assert_equal(False, diffs[0].deleted_file) assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs[0].diff) - assert_equal('lib/grit/actor.rb', diffs[5].b_blob.name) + assert_equal('lib/grit/actor.rb', diffs[5].b_blob.path) assert_equal(None, diffs[5].a_blob) assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id) assert_equal( None, diffs[5].a_mode ) @@ -89,7 +89,7 @@ class TestCommit(object): diffs = Commit.diff(self.repo, '59ddc32', ['lib']) assert_equal(1, len(diffs)) - assert_equal('lib/grit/diff.rb', diffs[0].a_blob.name) + assert_equal('lib/grit/diff.rb', diffs[0].a_blob.path) assert_true(git.called) assert_equal(git.call_args, (('diff', '-M', '59ddc32', '--', 'lib'), {'full_index': True})) @@ -101,7 +101,7 @@ class TestCommit(object): diffs = Commit.diff(self.repo, '59ddc32', '13d27d5', ['lib']) assert_equal(1, len(diffs)) - assert_equal('lib/grit/commit.rb', diffs[0].a_blob.name) + assert_equal('lib/grit/commit.rb', diffs[0].a_blob.path) assert_true(git.called) assert_equal(git.call_args, (('diff', '-M', '59ddc32', '13d27d5', '--', 'lib'), {'full_index': True})) @@ -115,8 +115,8 @@ class TestCommit(object): assert_equal(15, len(diffs)) - assert_equal('.gitignore', diffs[0].a_blob.name) - assert_equal('.gitignore', diffs[0].b_blob.name) + assert_equal('.gitignore', diffs[0].a_blob.path) + assert_equal('.gitignore', diffs[0].b_blob.path) assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs[0].a_blob.id) assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diffs[0].b_blob.id) assert_equal('100644', diffs[0].b_blob.mode) @@ -124,7 +124,7 @@ class TestCommit(object): assert_equal(False, diffs[0].deleted_file) assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs[0].diff) - assert_equal('lib/grit/actor.rb', diffs[5].b_blob.name) + assert_equal('lib/grit/actor.rb', diffs[5].b_blob.path) assert_equal(None, diffs[5].a_blob) assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id) assert_equal(True, diffs[5].new_file) @@ -145,7 +145,7 @@ class TestCommit(object): assert_equal(10, len(diffs)) - assert_equal('History.txt', diffs[0].b_blob.name) + assert_equal('History.txt', diffs[0].b_blob.path) assert_equal(None, diffs[0].a_blob) assert_equal('100644', diffs[0].b_blob.mode) assert_equal('81d2c27608b352814cbe979a6acd678d30219678', diffs[0].b_blob.id) @@ -153,7 +153,7 @@ class TestCommit(object): assert_equal(False, diffs[0].deleted_file) assert_equal("--- /dev/null\n+++ b/History.txt\n@@ -0,0 +1,5 @@\n+== 1.0.0 / 2007-10-09\n+\n+* 1 major enhancement\n+ * Birthday!\n+", diffs[0].diff) - assert_equal('lib/grit.rb', diffs[5].b_blob.name) + assert_equal('lib/grit.rb', diffs[5].b_blob.path) assert_equal(None, diffs[5].a_blob) assert_equal('32cec87d1e78946a827ddf6a8776be4d81dcf1d1', diffs[5].b_blob.id) assert_equal(True, diffs[5].new_file) diff --git a/test/git/test_tree.py b/test/git/test_tree.py index 947b0ffb..3946a33c 100644 --- a/test/git/test_tree.py +++ b/test/git/test_tree.py @@ -32,7 +32,7 @@ class TestTree(object): assert_equal(Tree, tree.__class__) assert_equal("650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44", tree.id) assert_equal("040000", tree.mode) - assert_equal("test", tree.name) + assert_equal("test", tree.path) def test_content_from_string_tree_should_return_blob(self): text = fixture('ls_tree_b').split("\n")[0] @@ -42,7 +42,7 @@ class TestTree(object): assert_equal(Blob, tree.__class__) assert_equal("aa94e396335d2957ca92606f909e53e7beaf3fbb", tree.id) assert_equal("100644", tree.mode) - assert_equal("grit.rb", tree.name) + assert_equal("grit.rb", tree.path) def test_content_from_string_tree_should_return_commit(self): text = fixture('ls_tree_commit').split("\n")[1] |