summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Sowden <paul@idontsmoke.co.uk>2008-11-19 23:27:36 -0800
committerMichael Trier <mtrier@gmail.com>2008-12-15 14:12:04 -0500
commit9e14356d12226cb140b0e070bd079468b4ab599b (patch)
treee0520e90acb8af1f0efd62cbdbce7061be702d51
parent5bb812243dd1815651281a54c8191fc8e2bc2d82 (diff)
downloadgitpython-9e14356d12226cb140b0e070bd079468b4ab599b.tar.gz
add a path parameter to most commit methods
The path parameter allows you to specify a path to constrain queries by. This changes potentially breaks backwards compatibility for the Repo.commits and Repo.commits_since methods as it moves the positional arguments. (cherry picked from commit cc8a20e78da4864060bd0c9279633009bc10d871)
-rw-r--r--lib/git/commit.py14
-rw-r--r--lib/git/repo.py35
-rw-r--r--test/git/test_commit.py2
-rw-r--r--test/git/test_repo.py8
4 files changed, 40 insertions, 19 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
diff --git a/test/git/test_commit.py b/test/git/test_commit.py
index df9ea039..f6e34dac 100644
--- a/test/git/test_commit.py
+++ b/test/git/test_commit.py
@@ -22,7 +22,7 @@ class TestCommit(object):
assert_equal("tom@mojombo.com", commit.author.email)
assert_true(git.called)
- assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017', '--'), {'pretty': 'raw', 'max_count': 1}))
+ assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017', '--', ''), {'pretty': 'raw', 'max_count': 1}))
@patch_object(Git, '_call_process')
def test_id_abbrev(self, git):
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index 67489b39..e5264a0d 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -48,7 +48,7 @@ class TestRepo(object):
def test_commits(self, git):
git.return_value = fixture('rev_list')
- commits = self.repo.commits('master', 10)
+ commits = self.repo.commits('master', max_count=10)
c = commits[0]
assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id)
@@ -70,7 +70,7 @@ class TestRepo(object):
assert_equal("Merge branch 'site'", c.message)
assert_true(git.called)
- assert_equal(git.call_args, (('rev_list', 'master', '--'), {'skip': 0, 'pretty': 'raw', 'max_count': 10}))
+ assert_equal(git.call_args, (('rev_list', 'master', '--', ''), {'skip': 0, 'pretty': 'raw', 'max_count': 10}))
@patch_object(Git, '_call_process')
def test_commit_count(self, git):
@@ -79,7 +79,7 @@ class TestRepo(object):
assert_equal(655, self.repo.commit_count('master'))
assert_true(git.called)
- assert_equal(git.call_args, (('rev_list', 'master', '--'), {}))
+ assert_equal(git.call_args, (('rev_list', 'master', '--', ''), {}))
@patch_object(Git, '_call_process')
def test_commit(self, git):
@@ -90,7 +90,7 @@ class TestRepo(object):
assert_equal("4c8124ffcf4039d292442eeccabdeca5af5c5017", commit.id)
assert_true(git.called)
- assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017', '--'), {'pretty': 'raw', 'max_count': 1}))
+ assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017', '--', ''), {'pretty': 'raw', 'max_count': 1}))
@patch_object(Git, '_call_process')
def test_tree(self, git):