summaryrefslogtreecommitdiffstats
path: root/tools/repopick.py
diff options
context:
space:
mode:
authorIan Roy <ian.t.roy@gmail.com>2014-12-10 18:53:46 -0500
committerAdnan Begovic <adnan@cyngn.com>2015-10-06 17:52:24 -0700
commit86b1255cb86aa8a06c5d4d1acd14b24195f0f08b (patch)
tree608ccf79d3cc0000c0a70e429cee39eb9e2a2c48 /tools/repopick.py
parent3f841b80284f6173dddde1b54ebbfbee37cf002a (diff)
downloadbuild-86b1255cb86aa8a06c5d4d1acd14b24195f0f08b.zip
build-86b1255cb86aa8a06c5d4d1acd14b24195f0f08b.tar.gz
build-86b1255cb86aa8a06c5d4d1acd14b24195f0f08b.tar.bz2
Allow repopick to cherry-pick a specific patch set
Use 'repopick 123456/9' where '123456' is the change number and '9' is the desired patchset. Change-Id: I2d9f6939fbde50b2a6057b75d2e7f722be5a3e21
Diffstat (limited to 'tools/repopick.py')
-rwxr-xr-xtools/repopick.py53
1 files changed, 45 insertions, 8 deletions
diff --git a/tools/repopick.py b/tools/repopick.py
index 13be690..3dbe751 100755
--- a/tools/repopick.py
+++ b/tools/repopick.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright (C) 2013 The CyanogenMod Project
+# Copyright (C) 2013-14 The CyanogenMod Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@ parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpForm
The --abandon-first argument, when used in conjuction with the
--start-branch option, will cause repopick to abandon the specified
branch in all repos first before performing any cherry picks.'''))
-parser.add_argument('change_number', nargs='*', help='change number to cherry pick')
+parser.add_argument('change_number', nargs='*', help='change number to cherry pick. Use {change number}/{patchset number} to get a specific revision.')
parser.add_argument('-i', '--ignore-missing', action='store_true', help='do not error out if a patch applies to a missing directory')
parser.add_argument('-s', '--start-branch', nargs=1, help='start the specified branch before cherry picking')
parser.add_argument('-a', '--abandon-first', action='store_true', help='before cherry picking, abandon the branch specified in --start-branch')
@@ -227,16 +227,32 @@ for change in args.change_number:
args.change_number = changelist
# Iterate through the requested change numbers
-for change in args.change_number:
+for changeps in args.change_number:
+
+ if '/' in changeps:
+ change = changeps.split('/')[0]
+ patchset = changeps.split('/')[1]
+ else:
+ change = changeps
+ patchset = ''
+
if not args.quiet:
- print('Applying change number %s ...' % change)
+ if len(patchset) == 0:
+ print('Applying change number %s ...' % change)
+ else:
+ print('Applying change number {change}/{patchset} ...'.format(change=change, patchset=patchset))
+
+ if len(patchset) == 0:
+ query_revision = 'CURRENT_REVISION'
+ else:
+ query_revision = 'ALL_REVISIONS'
# Fetch information about the change from Gerrit's REST API
#
# gerrit returns two lines, a magic string and then valid JSON:
# )]}'
# [ ... valid JSON ... ]
- url = 'http://review.cyanogenmod.org/changes/?q=%s&o=CURRENT_REVISION&o=CURRENT_COMMIT&pp=0' % change
+ url = 'http://review.cyanogenmod.org/changes/?q={change}&o={query_revision}&o=CURRENT_COMMIT&pp=0'.format(change=change, query_revision=query_revision)
if args.verbose:
print('Fetching from: %s\n' % url)
f = urllib.request.urlopen(url)
@@ -267,10 +283,31 @@ for change in args.change_number:
project_branch = data['branch']
change_number = data['_number']
status = data['status']
+ patchsetfound = False
+
+ if len(patchset) > 0:
+ try:
+ for revision in data['revisions']:
+ if (int(data['revisions'][revision]['_number']) == int(patchset)) and not patchsetfound:
+ target_revision = data['revisions'][revision]
+ if args.verbose:
+ print('Using found patch set {patchset} ...'.format(patchset=patchset))
+ patchsetfound = True
+ break
+ if not patchsetfound:
+ print('ERROR: The patch set could not be found, using CURRENT_REVISION instead.')
+ except:
+ print('ERROR: The patch set could not be found, using CURRENT_REVISION instead.')
+ patchsetfound = False
+
+ if not patchsetfound:
+ target_revision = data['revisions'][data['current_revision']]
+
current_revision = data['revisions'][data['current_revision']]
- patch_number = current_revision['_number']
- fetch_url = current_revision['fetch']['anonymous http']['url']
- fetch_ref = current_revision['fetch']['anonymous http']['ref']
+
+ patch_number = target_revision['_number']
+ fetch_url = target_revision['fetch']['anonymous http']['url']
+ fetch_ref = target_revision['fetch']['anonymous http']['ref']
author_name = current_revision['commit']['author']['name']
author_email = current_revision['commit']['author']['email']
author_date = current_revision['commit']['author']['date'].replace(date_fluff, '')