summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES81
-rw-r--r--lib/git/objects/commit.py13
-rw-r--r--lib/git/refs.py6
-rw-r--r--lib/git/remote.py6
-rw-r--r--lib/git/repo.py47
-rw-r--r--test/git/test_commit.py2
-rw-r--r--test/git/test_repo.py13
7 files changed, 103 insertions, 65 deletions
diff --git a/CHANGES b/CHANGES
index 666fa3bb..8e4d0492 100644
--- a/CHANGES
+++ b/CHANGES
@@ -45,6 +45,40 @@ objects Package
not affect you though unless you explicitly imported individual objects. If you just
used the git package, names did not change.
+Blob
+----
+* former 'name' member renamed to path as it suits the actual data better
+
+Commit
+------
+* 'count' method is not an instance method to increase its ease of use
+
+Config
+------
+* The git configuration can now be read and manipulated directly from within python
+ using the GitConfigParser
+* Repo.config_reader returns a read-only parser
+* Repo.config_writer returns a read-write parser
+
+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
+* Diffs are now returned as DiffIndex allowing to more quickly find the kind of
+ diffs you are interested in
+
+Diffing
+-------
+* Commit and Tree objects now support diffing natively with a common interface to
+ compare agains other Commits or Trees, against the working tree or against the index.
+
+Refs
+----
+* Will dynmically retrieve their object at the time of query to assure the information
+ is actual. Recently objects would be cached, hence ref object not be safely kept
+ persistent.
+
Repo
----
* Moved blame method from Blob to repo as it appeared to belong there much more.
@@ -73,24 +107,19 @@ Repo
- archive_tar_gz and archive_tar and replaced by archive method with different signature
* 'commits' method has no max-count of returned commits anymore, it now behaves
like git-rev-list
-* 'untracked_files' property added, returning all currently untracked files
-
-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
-* Diffs are now returned as DiffIndex allowing to more quickly find the kind of
- diffs you are interested in
+* The following methods and properties were added
+ - 'untracked_files' property, returning all currently untracked files
+ - 'head', creates a head object
+ - 'tag', creates a tag object
+ - 'iter_trees' method
+ - 'config_reader' property
+ - 'config_writer' property
-Diffing
--------
-* Commit and Tree objects now support diffing natively with a common interface to
- compare agains other Commits or Trees, against the working tree or against the index.
-
-Blob
-----
-* former 'name' member renamed to path as it suits the actual data better
+Remote
+------
+* Added Remote object allowing easy access to remotes
+* Repo.remotes lists all remotes
+* Repo.remote returns a remote of the specified name if it exists
Tree
----
@@ -102,24 +131,6 @@ Tree
* now mimics behaviour of a read-only list instead of a dict to maintain order.
* content_from_string method is now private and not part of the public API anymore
-Refs
-----
-* Will dynmically retrieve their object at the time of query to assure the information
- is actual. Recently objects would be cached, hence ref object not be safely kept
- persistent.
-
-Remote
-------
-* Added Remote object allowing easy access to remotes
-* Repo.remotes lists all remotes
-* Repo.remote returns a remote of the specified name if it exists
-
-Config
-------
-* The git configuration can now be read and manipulated directly from within python
- using the GitConfigParser
-* Repo.config_reader returns a read-only parser
-* Repo.config_writer returns a read-write parser
0.1.6
=====
diff --git a/lib/git/objects/commit.py b/lib/git/objects/commit.py
index 181cbb52..a68a7bed 100644
--- a/lib/git/objects/commit.py
+++ b/lib/git/objects/commit.py
@@ -101,16 +101,9 @@ class Commit(base.Object, Iterable, diff.Diffable):
"""
return self.message.split('\n', 1)[0]
- @classmethod
- def count(cls, repo, rev, paths='', **kwargs):
+ def count(self, paths='', **kwargs):
"""
- Count the number of commits reachable from this revision
-
- ``repo``
- is the Repo
-
- ``rev``
- revision specifier, see git-rev-parse for viable options
+ Count the number of commits reachable from this commit
``paths``
is an optinal path or a list of paths restricting the return value
@@ -121,7 +114,7 @@ class Commit(base.Object, Iterable, diff.Diffable):
Returns
int
"""
- return len(repo.git.rev_list(rev, '--', paths, **kwargs).strip().splitlines())
+ return len(self.repo.git.rev_list(self.id, '--', paths, **kwargs).strip().splitlines())
@classmethod
def iter_items(cls, repo, rev, paths='', **kwargs):
diff --git a/lib/git/refs.py b/lib/git/refs.py
index 618babc2..3428915e 100644
--- a/lib/git/refs.py
+++ b/lib/git/refs.py
@@ -174,7 +174,7 @@ class Head(Reference):
return self.object
-class TagRef(Reference):
+class TagReference(Head):
"""
Class representing a lightweight tag reference which either points to a commit
or to a tag object. In the latter case additional information, like the signature
@@ -219,9 +219,9 @@ class TagRef(Reference):
# provide an alias
-Tag = TagRef
+Tag = TagReference
-class RemoteRef(Head):
+class RemoteReference(Head):
"""
Represents a reference pointing to a remote head.
"""
diff --git a/lib/git/remote.py b/lib/git/remote.py
index 24efd900..da37414e 100644
--- a/lib/git/remote.py
+++ b/lib/git/remote.py
@@ -8,7 +8,7 @@ Module implementing a remote object allowing easy access to git remotes
"""
from git.utils import LazyMixin, Iterable
-from refs import RemoteRef
+from refs import RemoteReference
class _SectionConstraint(object):
"""
@@ -105,7 +105,7 @@ class Remote(LazyMixin, Iterable):
# parse them using refs, as their query can be faster as it is
# purely based on the file system
seen_remotes = set()
- for ref in RemoteRef.iter_items(repo):
+ for ref in RemoteReference.iter_items(repo):
remote_name = ref.remote_name
if remote_name in seen_remotes:
continue
@@ -121,7 +121,7 @@ class Remote(LazyMixin, Iterable):
List of RemoteRef objects
"""
out_refs = list()
- for ref in RemoteRef.list_items(self.repo):
+ for ref in RemoteReference.list_items(self.repo):
if ref.remote_name == self.name:
out_refs.append(ref)
# END if names match
diff --git a/lib/git/repo.py b/lib/git/repo.py
index 0a8592ab..c5b3d79b 100644
--- a/lib/git/repo.py
+++ b/lib/git/repo.py
@@ -108,6 +108,20 @@ class Repo(object):
``git.Head[]``
"""
return Head.list_items(self)
+
+ # alias heads
+ branches = heads
+
+ @property
+ def head(self,path="HEAD"):
+ """
+ Return
+ Head Object, reference pointing to commit
+
+ ``path``
+ path to the head or its name, i.e. master or heads/master
+ """
+ return Head(self,path)
@property
def remotes(self):
@@ -130,18 +144,6 @@ class Repo(object):
# END for each existing remote
raise ValueError( "Remote named %s does not exist" % name )
- # alias heads
- branches = heads
-
- @property
- def head(self):
- """
- Return
- Head Object, reference pointing to the current head of the repository
- """
- return Head(self,'HEAD')
-
-
@property
def tags(self):
"""
@@ -150,7 +152,17 @@ class Repo(object):
Returns
``git.Tag[]``
"""
- return Tag.list_items(self)
+ return TagReference.list_items(self)
+
+ def tag(self,path):
+ """
+ Return
+ TagReference Object, reference pointing to a Commit or Tag
+
+ ``path``
+ path to the tag reference, i.e. 0.1.5 or tags/0.1.5
+ """
+ return TagReference(self, path)
def _get_config_path(self, config_level ):
# we do not support an absolute path of the gitconfig on windows ,
@@ -214,6 +226,15 @@ class Repo(object):
c = Object.new(self, rev)
assert c.type == "commit", "Revision %s did not point to a commit, but to %s" % (rev, c)
return c
+
+ def iter_trees(self, *args, **kwargs):
+ """
+ Returns
+ Iterator yielding Tree objects
+
+ Note: Takes all arguments known to iter_commits method
+ """
+ return ( c.tree for c in self.iter_commits(*args, **kwargs) )
def tree(self, ref=None):
"""
diff --git a/test/git/test_commit.py b/test/git/test_commit.py
index c8bca564..abe16dfb 100644
--- a/test/git/test_commit.py
+++ b/test/git/test_commit.py
@@ -66,7 +66,7 @@ class TestCommit(object):
assert_equal(sha1, commit.id)
def test_count(self):
- assert Commit.count( self.repo, '0.1.5' ) == 141
+ assert self.repo.tag('0.1.5').commit.count( ) == 141
def test_str(self):
commit = Commit(self.repo, id='abc')
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index 0d8a473d..197a29cb 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -67,6 +67,16 @@ class TestRepo(TestCase):
assert_true(git.called)
+ def test_trees(self):
+ mc = 30
+ num_trees = 0
+ for tree in self.repo.iter_trees('0.1.5', max_count=mc):
+ num_trees += 1
+ assert isinstance(tree, Tree)
+ # END for each tree
+ assert num_trees == mc
+
+
@patch_object(Repo, '__init__')
@patch_object(Git, '_call_process')
def test_init(self, git, repo):
@@ -170,6 +180,9 @@ class TestRepo(TestCase):
def test_head(self):
assert self.repo.head.object == self.repo.active_branch.object
+ def test_tag(self):
+ assert self.repo.tag('0.1.5').commit
+
@patch_object(Git, '_call_process')
def test_should_display_blame_information(self, git):
git.return_value = fixture('blame')