summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-15 12:09:16 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-15 12:09:29 +0200
commit2da2b90e6930023ec5739ae0b714bbdb30874583 (patch)
tree506303c27732783c4a06cfd4fe8cf62d63bd42e7
parent58d692e2a1d7e3894dbed68efbcf7166d6ec3fb7 (diff)
downloadgitpython-2da2b90e6930023ec5739ae0b714bbdb30874583.tar.gz
repo: removed a few methods because of redundancy or because it will be obsolete once the interface overhaul is finished. This commit is just intermediate
-rw-r--r--CHANGES6
-rw-r--r--lib/git/cmd.py18
-rw-r--r--lib/git/objects/commit.py22
-rw-r--r--lib/git/repo.py76
-rw-r--r--test/git/test_commit.py3
-rw-r--r--test/git/test_repo.py9
6 files changed, 59 insertions, 75 deletions
diff --git a/CHANGES b/CHANGES
index 456423d4..04d9b4c9 100644
--- a/CHANGES
+++ b/CHANGES
@@ -44,9 +44,13 @@ Repo
of the active branch.
* tree method now requires a Ref instance as input and defaults to the active_branche
instead of master
-* Removed 'log' method as it as effectively the same as the 'commits' method
+* Removed the following methods:
+ - 'log' method as it as effectively the same as the 'commits' method
+ - 'commits_since' as it is just a flag given to rev-list in Commit.iter_items
+ - 'commit_count' as it was just a redirection to the respective commit method
* 'commits' method has no max-count of returned commits anymore, it now behaves
like git-rev-list
+
Diff
----
diff --git a/lib/git/cmd.py b/lib/git/cmd.py
index 2965eb8b..ef7a9c6c 100644
--- a/lib/git/cmd.py
+++ b/lib/git/cmd.py
@@ -223,6 +223,21 @@ class Git(object):
args.append("--%s=%s" % (dashify(k), v))
return args
+ @classmethod
+ def __unpack_args(cls, arg_list):
+ if not isinstance(arg_list, (list,tuple)):
+ return [ str(arg_list) ]
+
+ outlist = list()
+ for arg in arg_list:
+ if isinstance(arg_list, (list, tuple)):
+ outlist.extend(cls.__unpack_args( arg ))
+ # END recursion
+ else:
+ outlist.append(str(arg))
+ # END for each arg
+ return outlist
+
def _call_process(self, method, *args, **kwargs):
"""
Run the given git command with the specified arguments and return
@@ -258,7 +273,8 @@ class Git(object):
# Prepare the argument list
opt_args = self.transform_kwargs(**kwargs)
- ext_args = map(str, args)
+
+ ext_args = self.__unpack_args(args)
args = opt_args + ext_args
call = ["git", dashify(method)]
diff --git a/lib/git/objects/commit.py b/lib/git/objects/commit.py
index edbe8ed7..14839e12 100644
--- a/lib/git/objects/commit.py
+++ b/lib/git/objects/commit.py
@@ -102,7 +102,7 @@ class Commit(base.Object, Iterable):
return self.message.split('\n', 1)[0]
@classmethod
- def count(cls, repo, ref, path=''):
+ def count(cls, repo, ref, paths=''):
"""
Count the number of commits reachable from this ref
@@ -112,16 +112,17 @@ class Commit(base.Object, Iterable):
``ref``
is the ref from which to begin (SHA1 or name)
- ``path``
- is an optinal path
+ ``paths``
+ is an optinal path or a list of paths restricting the return value
+ to commits actually containing the paths
Returns
int
"""
- return len(repo.git.rev_list(ref, '--', path).strip().splitlines())
+ return len(repo.git.rev_list(ref, '--', paths).strip().splitlines())
@classmethod
- def iter_items(cls, repo, ref, path='', **kwargs):
+ def iter_items(cls, repo, ref, paths='', **kwargs):
"""
Find all commits matching the given criteria.
@@ -131,14 +132,15 @@ class Commit(base.Object, Iterable):
``ref``
is the ref from which to begin (SHA1, Head or name)
- ``path``
- is an optinal path, if set only Commits that include the path
- will be considered
+ ``paths``
+ is an optinal path or list of paths, if set only Commits that include the path
+ or paths will be considered
``kwargs``
- optional keyword arguments to git where
+ optional keyword arguments to git rev-list where
``max_count`` is the maximum number of commits to fetch
``skip`` is the number of commits to skip
+ ``since`` all commits since i.e. '1970-01-01'
Returns
iterator yielding Commit items
@@ -147,7 +149,7 @@ class Commit(base.Object, Iterable):
options.update(kwargs)
# the test system might confront us with string values -
- proc = repo.git.rev_list(ref, '--', path, **options)
+ proc = repo.git.rev_list(ref, '--', paths, **options)
return cls._iter_from_process_or_stream(repo, proc)
@classmethod
diff --git a/lib/git/repo.py b/lib/git/repo.py
index 1640fd32..40c71fd8 100644
--- a/lib/git/repo.py
+++ b/lib/git/repo.py
@@ -116,9 +116,12 @@ class Repo(object):
"""
return Tag.list_items(self)
- def blame(self, commit, file):
+ def blame(self, ref, file):
"""
- The blame information for the given file at the given commit
+ The blame information for the given file at the given ref.
+
+ ``ref``
+ Ref object or Commit
Returns
list: [git.Commit, list: [<line>]]
@@ -126,7 +129,7 @@ class Repo(object):
changed within the given commit. The Commit objects will be given in order
of appearance.
"""
- data = self.git.blame(commit, '--', file, p=True)
+ data = self.git.blame(ref, '--', file, p=True)
commits = {}
blames = []
info = None
@@ -196,17 +199,17 @@ class Repo(object):
# END distinguish hexsha vs other information
return blames
- def commits(self, start=None, path='', max_count=None, skip=0):
+ def commits(self, start=None, paths='', max_count=None, skip=0):
"""
A list of Commit objects representing the history of a given ref/commit
``start``
- is a ref to start the commits from. If start is None,
+ is a Ref or Commit to start the commits from. If start is None,
the active branch will be used
- ``path``
- is an optional path to limit the returned commits to
- Commits that do not contain that path will not be returned.
+ ``paths``
+ is an optional path or a list of paths to limit the returned commits to
+ Commits that do not contain that path or the paths will not be returned.
``max_count``
is the maximum number of commits to return (default None)
@@ -225,63 +228,27 @@ class Repo(object):
options.pop('max_count')
if start is None:
start = self.active_branch
- return Commit.list_items(self, start, path, **options)
+
+ return Commit.list_items(self, start, paths, **options)
- def commits_between(self, frm, to):
+ def commits_between(self, frm, to, *args, **kwargs):
"""
The Commits objects that are reachable via ``to`` but not via ``frm``
Commits are returned in chronological order.
``from``
- is the branch/commit name of the younger item
+ is the Ref/Commit name of the younger item
``to``
- is the branch/commit name of the older item
+ is the Ref/Commit name of the older item
Returns
``git.Commit[]``
"""
return reversed(Commit.list_items(self, "%s..%s" % (frm, to)))
- 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.
-
- ``start``
- is the branch/commit name (default 'master')
-
- ``path``
- is an optinal path to limit the returned commits to.
-
-
- ``since``
- is a string represeting a date/time
-
- Returns
- ``git.Commit[]``
- """
- options = {'since': since}
-
- return Commit.list_items(self, start, path, **options)
- 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 optional path
- Commits that do not contain the path will not contribute to the count.
-
- Returns
- ``int``
- """
- return Commit.count(self, start, path)
-
- def commit(self, id=None, path = ''):
+ def commit(self, id=None, paths = ''):
"""
The Commit object for the specified id
@@ -290,8 +257,9 @@ class Repo(object):
if None, it defaults to the active branch
- ``path``
- is an optional path, if set the returned commit must contain the path.
+ ``paths``
+ is an optional path or a list of paths,
+ if set the returned commit must contain the path or paths
Returns
``git.Commit``
@@ -300,7 +268,7 @@ class Repo(object):
id = self.active_branch
options = {'max_count': 1}
- commits = Commit.list_items(self, id, path, **options)
+ commits = Commit.list_items(self, id, paths, **options)
if not commits:
raise ValueError, "Invalid identifier %s, or given path '%s' too restrictive" % ( id, path )
@@ -317,7 +285,7 @@ class Repo(object):
other_repo_refs = other_repo.git.rev_list(other_ref, '--').strip().splitlines()
diff_refs = list(set(other_repo_refs) - set(repo_refs))
- return map(lambda ref: Commit.list_items(other_repo, ref, max_count=1)[0], diff_refs)
+ return map(lambda ref: Commit(other_repo, ref ), diff_refs)
def tree(self, treeish=None):
"""
diff --git a/test/git/test_commit.py b/test/git/test_commit.py
index a95fb675..46aff635 100644
--- a/test/git/test_commit.py
+++ b/test/git/test_commit.py
@@ -215,6 +215,9 @@ class TestCommit(object):
for sha1, commit in zip(expected_ids, commits):
assert_equal(sha1, commit.id)
+ def test_count(self):
+ assert Commit.count( self.repo, '0.1.5' ) == 141
+
def test_str(self):
commit = Commit(self.repo, id='abc')
assert_equal ("abc", str(commit))
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index 918e4769..24a13ed1 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -66,15 +66,6 @@ class TestRepo(object):
assert_true(git.called)
@patch_object(Git, '_call_process')
- def test_commit_count(self, git):
- git.return_value = fixture('rev_list_count')
-
- assert_equal(655, self.repo.commit_count('master'))
-
- assert_true(git.called)
- assert_equal(git.call_args, (('rev_list', 'master', '--', ''), {}))
-
- @patch_object(Git, '_call_process')
def test_commit(self, git):
git.return_value = ListProcessAdapter(fixture('rev_list_single'))