From e8566158dd59f0ccdb169809b34a1af656e3ee0d Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Thu, 17 Dec 2015 16:27:23 +0000 Subject: [PATCH] Gerrit 2.11 compatibility Gerrit 2.11 no longer seems to support the sortKey method of skipping changes. Instead is provides a --start option that takes a number of changes to skip. See: https://review.openstack.org/Documentation/cmd-query.html In addition, this required a change to the format of the changes dict. It turns out we were overwriting some changes if two had the same id. This is common in stable branch cherry picks. In order to avoid this, I used a tuple of id, project, branch as the key for the changes dict. This does break compatibility with existing cache files, so a check was added to clear old caches. Both of these changes were required together because otherwise we end up with a smaller number of items in changes than we should have, and the --start argument is incorrect so we start double processing changes, which breaks the loop because it looks like the change was already cached. Change-Id: If5ab46ce3367b3790e0db1d8bb1ed18e39202ad9 --- reviewstats/utils.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/reviewstats/utils.py b/reviewstats/utils.py index 85898e8..3dea93f 100644 --- a/reviewstats/utils.py +++ b/reviewstats/utils.py @@ -145,7 +145,14 @@ def get_changes(projects, ssh_user, ssh_key, only_open=False, stable='', # The cache is in the old list format changes = {} - sortkey = None + if changes: + for k, v in changes.items(): + # The cache is only using the id as a key. We now need both + # id and branch. + if not isinstance(k, tuple): + changes = {} + break + while True: connect_attempts = 3 for attempt in range(connect_attempts): @@ -175,8 +182,8 @@ def get_changes(projects, ssh_user, ssh_key, only_open=False, stable='', cmd += ' status:open' if stable: cmd += ' branch:stable/%s' % stable - if sortkey: - cmd += ' resume_sortkey:%s' % sortkey + if len(changes): + cmd += ' --start %d' % len(changes) else: # Get a small set the first time so we can get to checking # againt the cache sooner @@ -201,14 +208,17 @@ def get_changes(projects, ssh_user, ssh_key, only_open=False, stable='', break else: break - if changes.get(new_change['id'], None) == new_change: + if changes.get((new_change['id'], + new_change['project'], + new_change['branch']), None) == new_change: # Changes are ordered by latest to be updated. As soon # as we hit one that hasn't changed since our cached # version, we're done. end_of_changes = True break - sortkey = new_change['sortKey'] - changes[new_change['id']] = new_change + changes[(new_change['id'], + new_change['project'], + new_change['branch'])] = new_change if end_of_changes: break