aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gbp/git/repository.py18
-rw-r--r--gbp/scripts/dch.py7
-rw-r--r--gbp/scripts/pq.py2
-rw-r--r--tests/test_GitRepository.py19
4 files changed, 37 insertions, 9 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index 7ad19506..aca9cdb9 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -879,15 +879,20 @@ class GitRepository(object):
#{ Commit Information
- def get_commits(self, since=None, until=None, paths=None, options=None,
- first_parent=False):
+ def get_commits(self, since=None, until=None, paths=None, num=0,
+ first_parent=False, options=None):
"""
Get commits from since to until touching paths
@param since: commit to start from
+ @type since: C{str}
@param until: last commit to get
+ @type until: C{str}
@param paths: only list commits touching paths
- @param options: list of options passed to git log
+ @type paths: C{list} of C{str}
+ @param num: maximum number of commits to fetch
+ @type num: C{int}
+ @param options: list of additional options passed to git log
@type options: C{list} of C{str}ings
@param first_parent: only follow first parent when seeing a
merge commit
@@ -899,6 +904,9 @@ class GitRepository(object):
if options:
args += options
+ if num:
+ args += [ '-%d' % num ]
+
if first_parent:
args += [ "--first-parent" ]
@@ -906,7 +914,9 @@ class GitRepository(object):
args += ['%s..%s' % (since, until)]
if paths:
- args += [ "--", paths ]
+ if isinstance(paths, basestring):
+ paths = [ paths ]
+ args += [ "--" ] + paths
commits, ret = self.__git_getoutput('log', args)
if ret:
diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py
index 4a49f61c..ed6a3aaf 100644
--- a/gbp/scripts/dch.py
+++ b/gbp/scripts/dch.py
@@ -261,11 +261,11 @@ def guess_snapshot_commit(cp, repo, options):
# If the current topmost changelog entry has already been tagged rely on
# the version information only. The upper level relies then on the version
# info anyway:
- if repo.find_version(options.debian_tag, cp['Version']):
+ if repo.find_version(options.debian_tag, cp.version):
return None
# If we didn't find a snapshot header we look at the point the changelog
# was last touched.
- last = repo.get_commits(paths="debian/changelog", options=["-1"])
+ last = repo.get_commits(paths="debian/changelog", num=1)
if last:
gbp.log.info("Changelog last touched at '%s'" % last[0])
return last[0]
@@ -427,8 +427,7 @@ def main(argv):
if args:
gbp.log.info("Only looking for changes on '%s'" % " ".join(args))
- commits = repo.get_commits(since=since, until=until,
- paths=" ".join(args),
+ commits = repo.get_commits(since=since, until=until, paths=args,
options=options.git_log.split(" "))
commits.reverse()
diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py
index 1852973d..dafb6973 100644
--- a/gbp/scripts/pq.py
+++ b/gbp/scripts/pq.py
@@ -215,7 +215,7 @@ def import_quilt_patches(repo, branch, series, tries, force):
raise GbpError, ("Patch queue branch '%s'. already exists. Try 'rebase' instead."
% pq_branch)
- commits = repo.get_commits(options=['-%d' % tries], first_parent=True)
+ commits = repo.get_commits(num=tries, first_parent=True)
# If we go back in history we have to safe our pq so we always try to apply
# the latest one
if len(commits) > 1:
diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py
index 6bf40ee8..8ba75e17 100644
--- a/tests/test_GitRepository.py
+++ b/tests/test_GitRepository.py
@@ -255,6 +255,25 @@ def test_list_files():
[]
"""
+def test_get_commits():
+ """
+ Test listing commits
+
+ Methods tested:
+ - L{gbp.git.GitRepository.get_commits}
+
+ >>> import gbp.git
+ >>> repo = gbp.git.GitRepository(repo_dir)
+ >>> commits = repo.get_commits()
+ >>> type(commits) == list and len(commits) == 2
+ True
+ >>> len(repo.get_commits(num=1)) == 1
+ True
+ >>> repo.get_commits(paths=['foo', 'bar'])
+ []
+ >>> repo.get_commits(paths=['testfile']) == commits
+ True
+ """
def test_mirror_clone():
"""