repopick: Try to keep the changes sorted
Sort the changes according to their parent first and then according
to their number.
Change-Id: I1d258989a119d50411f6f249683b2e7d636d6c6d
diff --git a/build/tools/repopick.py b/build/tools/repopick.py
index c6f7fc7..6f4137e 100644
--- a/build/tools/repopick.py
+++ b/build/tools/repopick.py
@@ -28,6 +28,7 @@
import re
import argparse
import textwrap
+from functools import cmp_to_key
from xml.etree import ElementTree
try:
@@ -112,17 +113,17 @@
auth = requests.auth.HTTPBasicAuth(username=parts[1], password=parts[2])
statusCode = '-1'
if auth:
- url = '{0}/a/changes/?q={1}&o=CURRENT_REVISION&o=ALL_REVISIONS'.format(remote_url, query)
+ url = '{0}/a/changes/?q={1}&o=CURRENT_REVISION&o=ALL_REVISIONS&o=ALL_COMMITS'.format(remote_url, query)
data = requests.get(url, auth=auth)
statusCode = str(data.status_code)
if statusCode != '200':
#They didn't get good authorization or data, Let's try the old way
- url = '{0}/changes/?q={1}&o=CURRENT_REVISION&o=ALL_REVISIONS'.format(remote_url, query)
+ url = '{0}/changes/?q={1}&o=CURRENT_REVISION&o=ALL_REVISIONS&o=ALL_COMMITS'.format(remote_url, query)
data = requests.get(url)
reviews = json.loads(data.text[5:])
else:
"""Given a query, fetch the change numbers via http"""
- url = '{0}/changes/?q={1}&o=CURRENT_REVISION&o=ALL_REVISIONS'.format(remote_url, query)
+ url = '{0}/changes/?q={1}&o=CURRENT_REVISION&o=ALL_REVISIONS&o=ALL_COMMITS'.format(remote_url, query)
data = urllib.request.urlopen(url).read().decode('utf-8')
reviews = json.loads(data[5:])
@@ -257,12 +258,25 @@
# get data on requested changes
reviews = []
change_numbers = []
+
+ def cmp_reviews(review_a, review_b):
+ current_a = review_a['current_revision']
+ parents_a = [r['commit'] for r in review_a['revisions'][current_a]['commit']['parents']]
+ current_b = review_b['current_revision']
+ parents_b = [r['commit'] for r in review_b['revisions'][current_b]['commit']['parents']]
+ if current_a in parents_b:
+ return -1
+ elif current_b in parents_a:
+ return 1
+ else:
+ return cmp(review_a['number'], review_b['number'])
+
if args.topic:
reviews = fetch_query(args.gerrit, 'topic:{0}'.format(args.topic))
- change_numbers = sorted([str(r['number']) for r in reviews], key=int)
+ change_numbers = [str(r['number']) for r in sorted(reviews, key=cmp_to_key(cmp_reviews))]
if args.query:
reviews = fetch_query(args.gerrit, args.query)
- change_numbers = sorted([str(r['number']) for r in reviews], key=int)
+ change_numbers = [str(r['number']) for r in sorted(reviews, key=cmp_to_key(cmp_reviews))]
if args.change_number:
change_url_re = re.compile('https?://.+?/([0-9]+(?:/[0-9]+)?)/?')
for c in args.change_number: