From f9ca26405c53a6ad829e1bcf4f60c5a6bb4ae4d9 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Tue, 27 Dec 2011 18:09:11 +0100 Subject: GitRepository: Add num option to git_commits to limit number of returned commits and fix path option to also accept a list of paths instead of a string. --- gbp/git/repository.py | 18 ++++++++++++++---- gbp/scripts/dch.py | 7 +++---- gbp/scripts/pq.py | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'gbp') diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 7ad1950..aca9cdb 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 4a49f61..ed6a3aa 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 1852973..dafb697 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: -- cgit v1.2.3