summaryrefslogtreecommitdiffstats
path: root/tools/repopick.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/repopick.py')
-rwxr-xr-xtools/repopick.py38
1 files changed, 32 insertions, 6 deletions
diff --git a/tools/repopick.py b/tools/repopick.py
index 7336e78..ace7155 100755
--- a/tools/repopick.py
+++ b/tools/repopick.py
@@ -182,15 +182,28 @@ for change in args.change_number:
print('Fetching from: %s\n' % url)
f = urllib.request.urlopen(url)
d = f.read().decode("utf-8")
-
- # Parse the result
if args.verbose:
print('Result from request:\n' + d)
+
+ # Clean up the result
d = d.split('\n')[1]
+ matchObj = re.match(r'\[\s*\]', d)
+ if matchObj:
+ sys.stderr.write('ERROR: Change number %s was not found on the server\n' % change)
+ sys.exit(1)
d = re.sub(r'\[(.*)\]', r'\1', d)
- data = json.loads(d)
+
+ # Parse the JSON
+ try:
+ data = json.loads(d)
+ except ValueError:
+ sys.stderr.write('ERROR: The response from the server could not be parsed properly\n')
+ if not args.verbose:
+ sys.stderr.write('The malformed response was: %s\n' % d)
+ sys.exit(1)
# Extract information from the JSON response
+ date_fluff = '.000000000'
project_name = data['project']
change_number = data['_number']
current_revision = data['revisions'][data['current_revision']]
@@ -199,10 +212,10 @@ for change in args.change_number:
fetch_ref = current_revision['fetch']['http']['ref']
author_name = current_revision['commit']['author']['name']
author_email = current_revision['commit']['author']['email']
- author_date = current_revision['commit']['author']['date']
+ author_date = current_revision['commit']['author']['date'].replace(date_fluff, '')
committer_name = current_revision['commit']['committer']['name']
committer_email = current_revision['commit']['committer']['email']
- committer_date = current_revision['commit']['committer']['date']
+ committer_date = current_revision['commit']['committer']['date'].replace(date_fluff, '')
subject = current_revision['commit']['subject']
# Get the list of projects that repo knows about
@@ -242,8 +255,21 @@ for change in args.change_number:
print('--> Author: %s <%s> %s' % (author_name, author_email, author_date))
print('--> Committer: %s <%s> %s' % (committer_name, committer_email, committer_date))
+ # Try fetching from GitHub first
+ if args.verbose:
+ print('Trying to fetch the change from GitHub')
+ cmd = 'cd %s && git fetch github %s' % (project_path, fetch_ref)
+ execute_cmd(cmd)
+ # Check if it worked
+ FETCH_HEAD = '%s/.git/FETCH_HEAD' % project_path
+ if os.stat(FETCH_HEAD).st_size == 0:
+ # That didn't work, fetch from Gerrit instead
+ if args.verbose:
+ print('Fetching from GitHub didn\'t work, trying to fetch the change from Gerrit')
+ cmd = 'cd %s && git fetch %s %s' % (project_path, fetch_url, fetch_ref)
+ execute_cmd(cmd)
# Perform the cherry-pick
- cmd = 'cd %s && git fetch %s %s && git cherry-pick FETCH_HEAD' % (project_path, fetch_url, fetch_ref)
+ cmd = 'cd %s && git cherry-pick FETCH_HEAD' % (project_path)
execute_cmd(cmd)
if not args.quiet:
print('')