summaryrefslogtreecommitdiffstats
path: root/tools/repopick.py
diff options
context:
space:
mode:
authorChirayu Desai <cdesai@cyanogenmod.org>2013-06-16 09:47:05 +0530
committerAdnan Begovic <adnan@cyngn.com>2015-10-06 16:12:16 -0700
commit17d69aa797a7ea3c92d0aeeee0334371a1abf0b6 (patch)
tree625a91c9e020dc49985cb7f69ae64d47b7650a7a /tools/repopick.py
parent73939be5244d119eab4d3db54f0c668073916e25 (diff)
downloadbuild-17d69aa797a7ea3c92d0aeeee0334371a1abf0b6.zip
build-17d69aa797a7ea3c92d0aeeee0334371a1abf0b6.tar.gz
build-17d69aa797a7ea3c92d0aeeee0334371a1abf0b6.tar.bz2
repopick: let's be nice to our servers :)
* Prefer fetching changes from GitHub, and if that fails, silently fall-back to Gerrit. Change-Id: Ibf68d4b69a7e8dbee2adb8f7f4250340b8be629c
Diffstat (limited to 'tools/repopick.py')
-rwxr-xr-xtools/repopick.py59
1 files changed, 35 insertions, 24 deletions
diff --git a/tools/repopick.py b/tools/repopick.py
index 6ed0d7e..8c18ecb 100755
--- a/tools/repopick.py
+++ b/tools/repopick.py
@@ -156,7 +156,6 @@ if args.abandon_first:
local_branches = re.split('\s*,\s*', matchObj.group(1))
if any(args.start_branch[0] in s for s in local_branches):
needs_abandon = True
- break
if needs_abandon:
# Perform the abandon only if the branch already exists
@@ -167,6 +166,18 @@ if args.abandon_first:
if not args.quiet:
print('')
+# Get the list of projects that repo knows about
+# - convert the project name to a project path
+project_name_to_path = {}
+plist = subprocess.Popen([repo_bin,"list"], stdout=subprocess.PIPE)
+project_path = None
+while(True):
+ pline = plist.stdout.readline().rstrip()
+ if not pline:
+ break
+ ppaths = re.split('\s*:\s*', pline.decode())
+ project_name_to_path[ppaths[1]] = ppaths[0]
+
# Iterate through the requested change numbers
for change in args.change_number:
if not args.quiet:
@@ -218,30 +229,17 @@ for change in args.change_number:
committer_date = current_revision['commit']['committer']['date'].replace(date_fluff, '')
subject = current_revision['commit']['subject']
- # Get the list of projects that repo knows about
- # - convert the project name to a project path
- plist = subprocess.Popen([repo_bin,"list"], stdout=subprocess.PIPE)
- while(True):
- pline = plist.stdout.readline().rstrip()
- if not pline:
- break
- ppaths = re.split('\s*:\s*', pline.decode())
- if ppaths[1] == project_name:
- project_path = ppaths[0]
- break
- if 'project_path' not in locals():
- sys.stderr.write('ERROR: Could not determine the project path for project %s\n' % project_name)
+ # Convert the project name to a project path
+ # - check that the project path exists
+ if project_name in project_name_to_path:
+ project_path = project_name_to_path[project_name];
+ elif args.ignore_missing:
+ print('WARNING: Skipping %d since there is no project directory for: %s\n' % (change_number, project_name))
+ continue;
+ else:
+ sys.stderr.write('ERROR: For %d, could not determine the project path for project %s\n' % (change_number, project_name))
sys.exit(1)
- # Check that the project path exists
- if not os.path.isdir(project_path):
- if args.ignore_missing:
- print('WARNING: Skipping %d since there is no project directory: %s\n' % (change_number, project_path))
- continue;
- else:
- sys.stderr.write('ERROR: For %d, there is no project directory: %s\n' % (change_number, project_path))
- sys.exit(1)
-
# If --start-branch is given, create the branch (more than once per path is okay; repo ignores gracefully)
if args.start_branch:
cmd = '%s start %s %s' % (repo_bin, args.start_branch[0], project_path)
@@ -255,8 +253,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('')