diff options
Diffstat (limited to 'tools/repopick.py')
-rwxr-xr-x | tools/repopick.py | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/tools/repopick.py b/tools/repopick.py index 1840a56..cfbb8a8 100755 --- a/tools/repopick.py +++ b/tools/repopick.py @@ -209,7 +209,8 @@ if __name__ == '__main__': manifest = subprocess.check_output(['repo', 'manifest']) xml_root = ElementTree.fromstring(manifest) projects = xml_root.findall('project') - default_revision = xml_root.findall('default')[0].get('revision').split('/')[-1] + remotes = xml_root.findall('remote') + default_revision = xml_root.findall('default')[0].get('revision') #dump project data into the a list of dicts with the following data: #{project: {path, revision}} @@ -219,10 +220,15 @@ if __name__ == '__main__': path = project.get('path') revision = project.get('revision') if revision is None: - revision = default_revision + for remote in remotes: + if remote.get('name') == project.get('remote'): + revision = remote.get('revision') + if revision is None: + revision = default_revision if not name in project_name_to_data: project_name_to_data[name] = {} + revision = revision.split('refs/heads/')[-1] project_name_to_data[name][revision] = path # get data on requested changes @@ -235,8 +241,14 @@ if __name__ == '__main__': reviews = fetch_query(args.gerrit, args.query) change_numbers = sorted([str(r['number']) for r in reviews]) if args.change_number: - reviews = fetch_query(args.gerrit, ' OR '.join('change:{0}'.format(x.split('/')[0]) for x in args.change_number)) - change_numbers = args.change_number + for c in args.change_number: + if '-' in c: + templist = c.split('-') + for i in range(int(templist[0]), int(templist[1]) + 1): + change_numbers.append(str(i)) + else: + change_numbers.append(c) + reviews = fetch_query(args.gerrit, ' OR '.join('change:{0}'.format(x.split('/')[0]) for x in change_numbers)) # make list of things to actually merge mergables = [] @@ -264,6 +276,7 @@ if __name__ == '__main__': 'subject': review['subject'], 'project': review['project'], 'branch': review['branch'], + 'change_id': review['change_id'], 'change_number': review['number'], 'status': review['status'], 'fetch': None @@ -306,6 +319,31 @@ if __name__ == '__main__': if args.start_branch: subprocess.check_output(['repo', 'start', args.start_branch[0], project_path]) + # Determine the maximum commits to check already picked changes + check_picked_count = 10 + branch_commits_count = int(subprocess.check_output(['git', 'rev-list', '--count', 'HEAD'], cwd=project_path)) + if branch_commits_count <= check_picked_count: + check_picked_count = branch_commits_count - 1 + + # Check if change is already picked to HEAD...HEAD~check_picked_count + found_change = False + for i in range(0, check_picked_count): + if subprocess.call(['git', 'cat-file', '-e', 'HEAD~{0}'.format(i)], cwd=project_path, stderr=open(os.devnull, 'wb')): + continue + output = subprocess.check_output(['git', 'show', '-q', 'HEAD~{0}'.format(i)], cwd=project_path).split() + if 'Change-Id:' in output: + head_change_id = '' + for j,t in enumerate(reversed(output)): + if t == 'Change-Id:': + head_change_id = output[len(output) - j] + break + if head_change_id.strip() == item['change_id']: + print('Skipping {0} - already picked in {1} as HEAD~{2}'.format(item['id'], project_path, i)) + found_change = True + break + if found_change: + continue + # Print out some useful info if not args.quiet: print('--> Subject: "{0}"'.format(item['subject'])) |