diff options
Diffstat (limited to 'lib/git')
-rw-r--r-- | lib/git/commit.py | 14 | ||||
-rw-r--r-- | lib/git/repo.py | 35 |
2 files changed, 35 insertions, 14 deletions
diff --git a/lib/git/commit.py b/lib/git/commit.py index c50d9d2d..c9e2ab59 100644 --- a/lib/git/commit.py +++ b/lib/git/commit.py @@ -82,7 +82,7 @@ class Commit(LazyMixin): return self.id[0:7] @classmethod - def count(cls, repo, ref): + def count(cls, repo, ref, path=''): """ Count the number of commits reachable from this ref @@ -92,13 +92,16 @@ class Commit(LazyMixin): ``ref`` is the ref from which to begin (SHA1 or name) + ``path`` + is an optinal path + Returns int """ - return len(repo.git.rev_list(ref, '--').strip().splitlines()) + return len(repo.git.rev_list(ref, '--', path).strip().splitlines()) @classmethod - def find_all(cls, repo, ref, **kwargs): + def find_all(cls, repo, ref, path='', **kwargs): """ Find all commits matching the given criteria. ``repo`` @@ -107,6 +110,9 @@ class Commit(LazyMixin): ``ref`` is the ref from which to begin (SHA1 or name) + ``path`` + is an optinal path + ``options`` is a Hash of optional arguments to git where ``max_count`` is the maximum number of commits to fetch @@ -118,7 +124,7 @@ class Commit(LazyMixin): options = {'pretty': 'raw'} options.update(kwargs) - output = repo.git.rev_list(ref, '--', **options) + output = repo.git.rev_list(ref, '--', path, **options) return cls.list_from_string(repo, output) @classmethod diff --git a/lib/git/repo.py b/lib/git/repo.py index 09215b1e..47f9c2ce 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -100,13 +100,16 @@ class Repo(object): """ return Tag.find_all(self) - def commits(self, start = 'master', max_count = 10, skip = 0): + def commits(self, start = 'master', path = '', max_count = 10, skip = 0): """ A list of Commit objects representing the history of a given ref/commit ``start`` is the branch/commit name (default 'master') + ``path`` + is an optional path + ``max_count`` is the maximum number of commits to return (default 10) @@ -119,9 +122,9 @@ class Repo(object): options = {'max_count': max_count, 'skip': skip} - return Commit.find_all(self, start, **options) + return Commit.find_all(self, start, path, **options) - def commits_between(self, frm, to): + def commits_between(self, frm, to, path = ''): """ The Commits objects that are reachable via ``to`` but not via ``frm`` Commits are returned in chronological order. @@ -132,12 +135,15 @@ class Repo(object): ``to`` is the branch/commit name of the older item + ``path`` + is an optinal path + Returns ``git.Commit[]`` """ - return Commit.find_all(self, "%s..%s" % (frm, to)).reverse() + return Commit.find_all(self, "%s..%s" % (frm, to), path).reverse() - def commits_since(self, start = 'master', since = '1970-01-01'): + def commits_since(self, start = 'master', path = '', since = '1970-01-01'): """ The Commits objects that are newer than the specified date. Commits are returned in chronological order. @@ -145,6 +151,9 @@ class Repo(object): ``start`` is the branch/commit name (default 'master') + ``path`` + is an optinal path + ``since`` is a string represeting a date/time @@ -153,33 +162,39 @@ class Repo(object): """ options = {'since': since} - return Commit.find_all(self, start, **options) + return Commit.find_all(self, start, path, **options) - def commit_count(self, start = 'master'): + def commit_count(self, start = 'master', path = ''): """ The number of commits reachable by the given branch/commit ``start`` is the branch/commit name (default 'master') + ``path`` + is an optinal path + Returns int """ - return Commit.count(self, start) + return Commit.count(self, start, path) - def commit(self, id): + def commit(self, id, path = ''): """ The Commit object for the specified id ``id`` is the SHA1 identifier of the commit + ``path`` + is an optinal path + Returns git.Commit """ options = {'max_count': 1} - commits = Commit.find_all(self, id, **options) + commits = Commit.find_all(self, id, path, **options) if not commits: raise ValueError, 'Invalid identifier %s' % id |