repopick: Try to keep the changes sorted
Sort the changes according to their parent first and then according to their number. Change-Id: Iebdb8789728b2ccd528e19437e162129eb27973c
This commit is contained in:
@@ -29,6 +29,7 @@ import subprocess
|
|||||||
import re
|
import re
|
||||||
import argparse
|
import argparse
|
||||||
import textwrap
|
import textwrap
|
||||||
|
from functools import cmp_to_key
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -113,17 +114,17 @@ def fetch_query_via_http(remote_url, query):
|
|||||||
auth = requests.auth.HTTPBasicAuth(username=parts[1], password=parts[2])
|
auth = requests.auth.HTTPBasicAuth(username=parts[1], password=parts[2])
|
||||||
statusCode = '-1'
|
statusCode = '-1'
|
||||||
if auth:
|
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)
|
data = requests.get(url, auth=auth)
|
||||||
statusCode = str(data.status_code)
|
statusCode = str(data.status_code)
|
||||||
if statusCode != '200':
|
if statusCode != '200':
|
||||||
#They didn't get good authorization or data, Let's try the old way
|
#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)
|
data = requests.get(url)
|
||||||
reviews = json.loads(data.text[5:])
|
reviews = json.loads(data.text[5:])
|
||||||
else:
|
else:
|
||||||
"""Given a query, fetch the change numbers via http"""
|
"""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')
|
data = urllib.request.urlopen(url).read().decode('utf-8')
|
||||||
reviews = json.loads(data[5:])
|
reviews = json.loads(data[5:])
|
||||||
|
|
||||||
@@ -258,12 +259,25 @@ if __name__ == '__main__':
|
|||||||
# get data on requested changes
|
# get data on requested changes
|
||||||
reviews = []
|
reviews = []
|
||||||
change_numbers = []
|
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:
|
if args.topic:
|
||||||
reviews = fetch_query(args.gerrit, 'topic:{0}'.format(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:
|
if args.query:
|
||||||
reviews = fetch_query(args.gerrit, 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:
|
if args.change_number:
|
||||||
for c in args.change_number:
|
for c in args.change_number:
|
||||||
if '-' in c:
|
if '-' in c:
|
||||||
|
|||||||
Reference in New Issue
Block a user