summaryrefslogtreecommitdiffstats
path: root/manifest_xml.py
diff options
context:
space:
mode:
authorFredrik de Groot <fredrik.de.groot@aptiv.com>2023-05-31 16:56:34 +0200
committerMike Frysinger <vapier@google.com>2023-06-21 14:50:16 +0000
commitbe71c2f80fa115e8256211fd0e3116d93cfae93e (patch)
tree39769fb002ec24d520abde60cf6b0614c4c02558 /manifest_xml.py
parent696e0c48a9de4d20f3de65bc014ca2991d16f041 (diff)
downloadgit-repo-be71c2f80fa115e8256211fd0e3116d93cfae93e.tar.gz
manifest: enable remove-project using path
A something.xml that gets included by two different files, that both remove and add same shared project to two different locations, would not work prior to this change. Reason is that remove killed all name keys, even though reuse of same repo in different locations is allowed. Solve by adding optional attrib path to <remove-project name="foo" path="only_this_path" /> and tweak remove-project. Behaves as before without path, and deletes more selectively when remove path is supplied. As secondary feature, a project can now also be removed by only using path, assuming a matching project name can be found. Change-Id: I502d9f949f5d858ddc1503846b170473f76dc8e2 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/375694 Tested-by: Fredrik de Groot <fredrik.de.groot@aptiv.com> Reviewed-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'manifest_xml.py')
-rw-r--r--manifest_xml.py49
1 files changed, 36 insertions, 13 deletions
diff --git a/manifest_xml.py b/manifest_xml.py
index 555bf736..73be1b6e 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -1535,22 +1535,45 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
1535 self._contactinfo = ContactInfo(bugurl) 1535 self._contactinfo = ContactInfo(bugurl)
1536 1536
1537 if node.nodeName == "remove-project": 1537 if node.nodeName == "remove-project":
1538 name = self._reqatt(node, "name") 1538 name = node.getAttribute("name")
1539 path = node.getAttribute("path")
1539 1540
1540 if name in self._projects: 1541 # Name or path needed.
1541 for p in self._projects[name]: 1542 if not name and not path:
1542 del self._paths[p.relpath] 1543 raise ManifestParseError(
1543 del self._projects[name] 1544 "remove-project must have name and/or path"
1544 1545 )
1545 # If the manifest removes the hooks project, treat it as if 1546
1546 # it deleted 1547 removed_project = ""
1547 # the repo-hooks element too. 1548
1548 if repo_hooks_project == name: 1549 # Find and remove projects based on name and/or path.
1549 repo_hooks_project = None 1550 for projname, projects in list(self._projects.items()):
1550 elif not XmlBool(node, "optional", False): 1551 for p in projects:
1552 if name == projname and not path:
1553 del self._paths[p.relpath]
1554 if not removed_project:
1555 del self._projects[name]
1556 removed_project = name
1557 elif path == p.relpath and (
1558 name == projname or not name
1559 ):
1560 self._projects[projname].remove(p)
1561 del self._paths[p.relpath]
1562 removed_project = p.name
1563
1564 # If the manifest removes the hooks project, treat it as if
1565 # it deleted the repo-hooks element too.
1566 if (
1567 removed_project
1568 and removed_project not in self._projects
1569 and repo_hooks_project == removed_project
1570 ):
1571 repo_hooks_project = None
1572
1573 if not removed_project and not XmlBool(node, "optional", False):
1551 raise ManifestParseError( 1574 raise ManifestParseError(
1552 "remove-project element specifies non-existent " 1575 "remove-project element specifies non-existent "
1553 "project: %s" % name 1576 "project: %s" % node.toxml()
1554 ) 1577 )
1555 1578
1556 # Store repo hooks project information. 1579 # Store repo hooks project information.