summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/git/cmd.py18
-rw-r--r--lib/git/objects/commit.py22
-rw-r--r--lib/git/repo.py76
3 files changed, 51 insertions, 65 deletions
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):
"""