summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGabriele M <moto.falcon.git@gmail.com>2018-03-31 14:30:15 +0200
committerTim Schumacher <timschumi@gmx.de>2018-07-07 18:48:28 +0200
commit5918abd7ab3030f893b60687f972161422627dad (patch)
tree0e3548eca14fc47a6c6f1f34ea56e2298b7ae00f /tools
parenta465d0356c106fe398f35418a738b4a22324b1bd (diff)
downloadbuild-5918abd7ab3030f893b60687f972161422627dad.tar.gz
build-5918abd7ab3030f893b60687f972161422627dad.tar.bz2
build-5918abd7ab3030f893b60687f972161422627dad.zip
repopick: Try to keep the changes sorted
Sort the changes according to their parent first and then according to their number. Change-Id: Iebdb8789728b2ccd528e19437e162129eb27973c
Diffstat (limited to 'tools')
-rwxr-xr-xtools/repopick.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/tools/repopick.py b/tools/repopick.py
index 9bb39aadd..d841a5997 100755
--- a/tools/repopick.py
+++ b/tools/repopick.py
@@ -29,6 +29,7 @@ import subprocess
import re
import argparse
import textwrap
+from functools import cmp_to_key
from xml.etree import ElementTree
try:
@@ -102,7 +103,7 @@ def fetch_query_via_ssh(remote_url, query):
def fetch_query_via_http(remote_url, query):
"""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:])
@@ -235,12 +236,25 @@ if __name__ == '__main__':
# 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])
+ 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])
+ change_numbers = [str(r['number']) for r in sorted(reviews, key=cmp_to_key(cmp_reviews))]
if args.change_number:
for c in args.change_number:
if '-' in c: