summaryrefslogtreecommitdiff
path: root/lib/git
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-19 22:49:52 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-19 22:59:15 +0200
commit0b3ecf2dcace76b65765ddf1901504b0b4861b08 (patch)
tree04fad7e2ac3f85afe7fe28a5e6907b8a88abfaba /lib/git
parent11b1f6edc164e2084e3ff034d3b65306c461a0be (diff)
downloadgitpython-0b3ecf2dcace76b65765ddf1901504b0b4861b08.tar.gz
commit.count: is an instance method now
repo: added head , tag and iter_trees methods for completeness changes: headlines now sorted chronologically
Diffstat (limited to 'lib/git')
-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
4 files changed, 43 insertions, 29 deletions
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):
"""