Index: gerrit_util.py |
diff --git a/gerrit_util.py b/gerrit_util.py |
index 7c44f03107468de934940bd1bf7646630818c53f..0a677b02e774786fb591d47ca4b8e0d101a0052b 100755 |
--- a/gerrit_util.py |
+++ b/gerrit_util.py |
@@ -180,6 +180,42 @@ def QueryChanges(host, param_dict, first_param=None, limit=None, o_params=None, |
return ReadHttpJsonResponse(CreateHttpConn(host, path), ignore_404=False) |
+def QueryAllChanges(host, param_dict, first_param=None, limit=500, |
+ o_params=None, sortkey=None): |
+ """ |
+ Queries a gerrit-on-borg server for all the changes matching the query terms. |
+ |
+ A single query to gerrit-on-borg is limited on the number of results by the |
+ limit parameter on the request (see QueryChanges) and the server maximum |
+ limit. This function uses the "_more_changes" and "_sortkey" attributes on |
+ the returned changes to iterate all of them making multiple queries to the |
+ server, regardless the query limit. |
+ |
+ Args: |
+ param_dict: A dictionary of search parameters, as documented here: |
+ http://gerrit-documentation.googlecode.com/svn/Documentation/2.6/user-search.html |
+ first_param: A change identifier. |
+ limit: Maximum number of requested changes per query. |
+ o_params: A list of additional output specifiers, as documented here: |
+ https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes |
+ sortkey: The value of the "_sortkey" attribute where starts from. None to |
+ start from the first change. |
+ |
+ Returns: |
+ A generator object to the list of returned changes, possibly unbound. |
+ """ |
+ more_changes = True |
+ while more_changes: |
+ page = QueryChanges(host, param_dict, first_param, limit, o_params, sortkey) |
+ for cl in page: |
+ yield cl |
+ |
+ more_changes = [cl for cl in page if '_more_changes' in cl] |
+ sortkey = None |
+ if more_changes: |
+ sortkey = more_changes[0]['_sortkey'] |
+ |
+ |
def MultiQueryChanges(host, param_dict, change_list, limit=None, o_params=None, |
sortkey=None): |
"""Initiate a query composed of multiple sets of query parameters.""" |