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
This commit is contained in:
Ben Nemec 2015-12-17 16:27:23 +00:00
parent 1a2a999b5a
commit e8566158dd
1 changed files with 16 additions and 6 deletions

View File

@ -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