repo-pull: Consider branch of repo
In the case of one source tree containing multiple repos with the same project, but different branches, the script won't sync them properly. To fix it, make it consider the branch along with the project. Test: Tested syncing well in the directory which contains multiple repos with the same project, but different branches. Change-Id: I9d1add4ffe85f80f8f9d6a3ae2c046473d7c4631 Signed-off-by: Junghoon Jang <junghoonjang@google.com>
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user