1
0
Fork 0

manifest: Improve diagnostic on base-rev mismatch errors

* Improve formatting of message, making it more clear which
  revision belongs to which element.
* Include a trail of where the element was defined. In larger projects,
  with multiple includes and multiple alternative default-xmls it is not
  always immediately obvious which files that are included and in which
  order, without much manual traversing of the xml files.
  This will also make it clear if the parent definition is already
  an <extend-project>, in the rare event of chaining multiple
  <extend-project>.
* Ensure formatting persists when passed into ManifestParseError.
  Previously the raw list was passed as second argument
  which caused newlines to be printed like raw "\n".

Example new message:
    extend-project mismatch for name 'platform/bionic'
        ├──Mismatching base-rev="64078752f5cc0c5fe33e1e9cc49b0736aa2f93e8" (included via ../manifest.xml -> default.xml -> project_a.xml -> project_a_aosp_patches.xml)
        └──Previous definition: <project ... revision="a93577f6224a53c0987e0deb3d6101c22ce83018" /> (included via ../manifest.xml -> -> default.xml -> aosp.xml)

Example old message:
    ('revision base check failed, rebase patches and update base revs for: ', ['extend-project name platform/bionic mismatch base 64078752f5cc0c5fe33e1e9cc49b0736aa2f93e8 vs revision a93577f6224a53c0987e0deb3d6101c22ce83018'])

Change-Id: I7f0105a01445fdced916186a88f221d7097ef769
This commit is contained in:
Erik Elmeke 2025-04-22 12:20:22 +02:00
parent 04faf99604
commit 7ed1af855a
2 changed files with 18 additions and 16 deletions

View file

@ -1372,6 +1372,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
nodes: List[Element] = []
for elemtype, node, path, children in tree:
chain = [*include_chain, path]
if elemtype == "include":
include_groups = ""
if parent_groups:
@ -1381,7 +1382,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
node.getAttribute("groups") + "," + include_groups
)
nodes.extend(self._FlattenIncludes(
children, include_groups, parent_node=node, include_chain=[*copy(include_chain), path]
children, include_groups, parent_node=node, include_chain=chain
))
else:
if parent_groups and node.nodeName == "project":
@ -1399,7 +1400,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
node.setAttribute(
"revision", parent_node.getAttribute("revision")
)
node.includechain = include_chain
node.includechain = chain
nodes.append(node)
return nodes
@ -1611,12 +1612,14 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
if revision:
if base_revision:
if p.revisionExpr != base_revision:
prev_includechain = " -> ".join(p.prev_definition.includechain)
curr_includechain = " -> ".join(node.includechain)
failed_revision_changes.append(
"extend-project name %s mismatch base "
"%s vs revision %s"
% (name, base_revision, p.revisionExpr)
f"extend-project mismatch for name '{name}'\n"
f' ├──Mismatching base-rev="{base_revision}" (included via {curr_includechain})\n'
f' └──Previous definition: <{p.prev_definition.nodeName} ... revision="{p.revisionExpr}" /> (included via {prev_includechain})'
)
p.SetRevision(revision)
p.SetRevision(revision, prev_definition=node)
if remote_name:
p.remote = remote.ToRemoteSpec(name)
@ -1720,14 +1723,12 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
):
if base_revision:
if p.revisionExpr != base_revision:
prev_includechain = " -> ".join(p.prev_definition.includechain)
curr_includechain = " -> ".join(node.includechain)
failed_revision_changes.append(
"remove-project path %s mismatch base "
"%s vs revision %s"
% (
p.relpath,
base_revision,
p.revisionExpr,
)
f"remove-project mismatch for name '{name}'\n"
f' ├──Mismatching base-rev="{base_revision}" (included via {curr_includechain})\n'
f' └──Previous definition: <{p.prev_definition.nodeName} ... revision="{p.revisionExpr}" /> (included via {prev_includechain})'
)
self._projects[projname].remove(p)
del self._paths[p.relpath]
@ -1751,8 +1752,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
if failed_revision_changes:
raise ManifestParseError(
"revision base check failed, rebase patches and update "
"base revs for: ",
failed_revision_changes,
"base-rev for:\n" + "\n".join(failed_revision_changes),
)
# Store repo hooks project information.
@ -2087,6 +2087,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
use_git_worktrees=use_git_worktrees,
**extra_proj_attrs,
)
project.prev_definition = node
for n in node.childNodes:
if n.nodeName == "copyfile":

View file

@ -658,13 +658,14 @@ class Project:
return self.relpath
return os.path.join(self.manifest.path_prefix, self.relpath)
def SetRevision(self, revisionExpr, revisionId=None):
def SetRevision(self, revisionExpr, revisionId=None, prev_definition=None):
"""Set revisionId based on revision expression and id"""
self.revisionExpr = revisionExpr
if revisionId is None and revisionExpr and IsId(revisionExpr):
self.revisionId = self.revisionExpr
else:
self.revisionId = revisionId
self.prev_definition = prev_definition
def UpdatePaths(self, relpath, worktree, gitdir, objdir):
"""Update paths used by this project"""