Merge changes Iff3cdebe,I9d1add4f am: 40e23904e3 am: 8e297e0ad6 am: e139706c90

Original change: https://android-review.googlesource.com/c/platform/development/+/2530760

Change-Id: I0656f355424b58339b0554f608ddb9b26e40bede
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Junghoon Jang
2023-04-17 06:43:41 +00:00
committed by Automerger Merge Worker

View File

@@ -90,6 +90,7 @@ class ChangeList(object):
self.project = project
self.number = change_list['_number']
self.branch = change_list['branch']
self.fetch = fetch
@@ -129,6 +130,28 @@ def find_repo_top(curdir):
raise ValueError('.repo dir not found')
class ProjectNameDirDict:
"""A dict which maps project name and revision to the source path."""
def __init__(self):
self._dirs = dict()
def add_directory(self, name, revision, path):
"""Maps project name and revision to path."""
self._dirs[name] = path or name
if revision:
self._dirs[(name, revision)] = path or name
def find_directory(self, name, revision, default_result=None):
"""Finds corresponding path of project name and revision."""
if (name, revision) in self._dirs:
return self._dirs[(name, revision)]
if default_result is None:
return self._dirs[name]
return self._dirs.get(name, default_result)
def build_project_name_dir_dict(manifest_name):
"""Build the mapping from Gerrit project name to source tree project
directory path."""
@@ -138,14 +161,12 @@ def build_project_name_dir_dict(manifest_name):
raw_manifest_xml = run(manifest_cmd, stdout=PIPE, check=True).stdout
manifest_xml = xml.dom.minidom.parseString(raw_manifest_xml)
project_dirs = {}
project_dirs = ProjectNameDirDict()
for project in manifest_xml.getElementsByTagName('project'):
name = project.getAttribute('name')
path = project.getAttribute('path')
if path:
project_dirs[name] = path
else:
project_dirs[name] = name
revision = project.getAttribute('revision')
project_dirs.add_directory(name, revision, path)
return project_dirs
@@ -269,7 +290,8 @@ def _main_bash(args):
print(_sh_quote_command(['pushd', repo_top]))
for changes in change_list_groups:
for change in changes:
project_dir = project_dirs.get(change.project, change.project)
project_dir = project_dirs.find_directory(
change.project, change.branch, change.project)
cmds = []
cmds.append(['pushd', project_dir])
cmds.extend(build_pull_commands(
@@ -291,7 +313,7 @@ def _do_pull_change_lists_for_project(task):
for i, change in enumerate(changes):
try:
cwd = project_dirs[change.project]
cwd = project_dirs.find_directory(change.project, change.branch)
except KeyError:
err_msg = 'error: project "{}" cannot be found in manifest.xml\n'
err_msg = err_msg.format(change.project).encode('utf-8')
@@ -387,6 +409,9 @@ def _parse_args():
parser.add_argument('-j', '--parallel', default=1, type=int,
help='Number of parallel running commands')
parser.add_argument('--current-branch', action='store_true',
help='Pull commits to the current branch')
return parser.parse_args()
@@ -399,7 +424,7 @@ def _get_change_lists_from_args(args):
def _get_local_branch_name_from_args(args):
"""Get the local branch name from args."""
if not args.branch and not _confirm(
if not args.branch and not args.current_branch and not _confirm(
'Do you want to continue without local branch name?', False):
print('error: `-b` or `--branch` must be specified', file=sys.stderr)
sys.exit(1)