manifest_xml.py 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. # -*- coding:utf-8 -*-
  2. #
  3. # Copyright (C) 2008 The Android Open Source Project
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. from __future__ import print_function
  17. import itertools
  18. import os
  19. import re
  20. import sys
  21. import xml.dom.minidom
  22. from pyversion import is_python3
  23. if is_python3():
  24. import urllib.parse
  25. else:
  26. import imp
  27. import urlparse
  28. urllib = imp.new_module('urllib')
  29. urllib.parse = urlparse
  30. import gitc_utils
  31. from git_config import GitConfig, IsId
  32. from git_refs import R_HEADS, HEAD
  33. import platform_utils
  34. from project import RemoteSpec, Project, MetaProject
  35. from error import (ManifestParseError, ManifestInvalidPathError,
  36. ManifestInvalidRevisionError)
  37. MANIFEST_FILE_NAME = 'manifest.xml'
  38. LOCAL_MANIFEST_NAME = 'local_manifest.xml'
  39. LOCAL_MANIFESTS_DIR_NAME = 'local_manifests'
  40. # urljoin gets confused if the scheme is not known.
  41. urllib.parse.uses_relative.extend([
  42. 'ssh',
  43. 'git',
  44. 'persistent-https',
  45. 'sso',
  46. 'rpc'])
  47. urllib.parse.uses_netloc.extend([
  48. 'ssh',
  49. 'git',
  50. 'persistent-https',
  51. 'sso',
  52. 'rpc'])
  53. def XmlBool(node, attr, default=None):
  54. """Determine boolean value of |node|'s |attr|.
  55. Invalid values will issue a non-fatal warning.
  56. Args:
  57. node: XML node whose attributes we access.
  58. attr: The attribute to access.
  59. default: If the attribute is not set (value is empty), then use this.
  60. Returns:
  61. True if the attribute is a valid string representing true.
  62. False if the attribute is a valid string representing false.
  63. |default| otherwise.
  64. """
  65. value = node.getAttribute(attr)
  66. s = value.lower()
  67. if s == '':
  68. return default
  69. elif s in {'yes', 'true', '1'}:
  70. return True
  71. elif s in {'no', 'false', '0'}:
  72. return False
  73. else:
  74. print('warning: manifest: %s="%s": ignoring invalid XML boolean' %
  75. (attr, value), file=sys.stderr)
  76. return default
  77. def XmlInt(node, attr, default=None):
  78. """Determine integer value of |node|'s |attr|.
  79. Args:
  80. node: XML node whose attributes we access.
  81. attr: The attribute to access.
  82. default: If the attribute is not set (value is empty), then use this.
  83. Returns:
  84. The number if the attribute is a valid number.
  85. Raises:
  86. ManifestParseError: The number is invalid.
  87. """
  88. value = node.getAttribute(attr)
  89. if not value:
  90. return default
  91. try:
  92. return int(value)
  93. except ValueError:
  94. raise ManifestParseError('manifest: invalid %s="%s" integer' %
  95. (attr, value))
  96. class _Default(object):
  97. """Project defaults within the manifest."""
  98. revisionExpr = None
  99. destBranchExpr = None
  100. upstreamExpr = None
  101. remote = None
  102. sync_j = 1
  103. sync_c = False
  104. sync_s = False
  105. sync_tags = True
  106. def __eq__(self, other):
  107. return self.__dict__ == other.__dict__
  108. def __ne__(self, other):
  109. return self.__dict__ != other.__dict__
  110. class _XmlRemote(object):
  111. def __init__(self,
  112. name,
  113. alias=None,
  114. fetch=None,
  115. pushUrl=None,
  116. manifestUrl=None,
  117. review=None,
  118. revision=None):
  119. self.name = name
  120. self.fetchUrl = fetch
  121. self.pushUrl = pushUrl
  122. self.manifestUrl = manifestUrl
  123. self.remoteAlias = alias
  124. self.reviewUrl = review
  125. self.revision = revision
  126. self.resolvedFetchUrl = self._resolveFetchUrl()
  127. def __eq__(self, other):
  128. return self.__dict__ == other.__dict__
  129. def __ne__(self, other):
  130. return self.__dict__ != other.__dict__
  131. def _resolveFetchUrl(self):
  132. url = self.fetchUrl.rstrip('/')
  133. manifestUrl = self.manifestUrl.rstrip('/')
  134. # urljoin will gets confused over quite a few things. The ones we care
  135. # about here are:
  136. # * no scheme in the base url, like <hostname:port>
  137. # We handle no scheme by replacing it with an obscure protocol, gopher
  138. # and then replacing it with the original when we are done.
  139. if manifestUrl.find(':') != manifestUrl.find('/') - 1:
  140. url = urllib.parse.urljoin('gopher://' + manifestUrl, url)
  141. url = re.sub(r'^gopher://', '', url)
  142. else:
  143. url = urllib.parse.urljoin(manifestUrl, url)
  144. return url
  145. def ToRemoteSpec(self, projectName):
  146. fetchUrl = self.resolvedFetchUrl.rstrip('/')
  147. url = fetchUrl + '/' + projectName
  148. remoteName = self.name
  149. if self.remoteAlias:
  150. remoteName = self.remoteAlias
  151. return RemoteSpec(remoteName,
  152. url=url,
  153. pushUrl=self.pushUrl,
  154. review=self.reviewUrl,
  155. orig_name=self.name,
  156. fetchUrl=self.fetchUrl)
  157. class XmlManifest(object):
  158. """manages the repo configuration file"""
  159. def __init__(self, repodir, manifest_file, local_manifests=None):
  160. """Initialize.
  161. Args:
  162. repodir: Path to the .repo/ dir for holding all internal checkout state.
  163. It must be in the top directory of the repo client checkout.
  164. manifest_file: Full path to the manifest file to parse. This will usually
  165. be |repodir|/|MANIFEST_FILE_NAME|.
  166. local_manifests: Full path to the directory of local override manifests.
  167. This will usually be |repodir|/|LOCAL_MANIFESTS_DIR_NAME|.
  168. """
  169. # TODO(vapier): Move this out of this class.
  170. self.globalConfig = GitConfig.ForUser()
  171. self.repodir = os.path.abspath(repodir)
  172. self.topdir = os.path.dirname(self.repodir)
  173. self.manifestFile = manifest_file
  174. self.local_manifests = local_manifests
  175. self._load_local_manifests = True
  176. self.repoProject = MetaProject(self, 'repo',
  177. gitdir=os.path.join(repodir, 'repo/.git'),
  178. worktree=os.path.join(repodir, 'repo'))
  179. mp = MetaProject(self, 'manifests',
  180. gitdir=os.path.join(repodir, 'manifests.git'),
  181. worktree=os.path.join(repodir, 'manifests'))
  182. self.manifestProject = mp
  183. # This is a bit hacky, but we're in a chicken & egg situation: all the
  184. # normal repo settings live in the manifestProject which we just setup
  185. # above, so we couldn't easily query before that. We assume Project()
  186. # init doesn't care if this changes afterwards.
  187. if os.path.exists(mp.gitdir) and mp.config.GetBoolean('repo.worktree'):
  188. mp.use_git_worktrees = True
  189. self._Unload()
  190. def Override(self, name, load_local_manifests=True):
  191. """Use a different manifest, just for the current instantiation.
  192. """
  193. path = None
  194. # Look for a manifest by path in the filesystem (including the cwd).
  195. if not load_local_manifests:
  196. local_path = os.path.abspath(name)
  197. if os.path.isfile(local_path):
  198. path = local_path
  199. # Look for manifests by name from the manifests repo.
  200. if path is None:
  201. path = os.path.join(self.manifestProject.worktree, name)
  202. if not os.path.isfile(path):
  203. raise ManifestParseError('manifest %s not found' % name)
  204. old = self.manifestFile
  205. try:
  206. self._load_local_manifests = load_local_manifests
  207. self.manifestFile = path
  208. self._Unload()
  209. self._Load()
  210. finally:
  211. self.manifestFile = old
  212. def Link(self, name):
  213. """Update the repo metadata to use a different manifest.
  214. """
  215. self.Override(name)
  216. # Old versions of repo would generate symlinks we need to clean up.
  217. if os.path.lexists(self.manifestFile):
  218. platform_utils.remove(self.manifestFile)
  219. # This file is interpreted as if it existed inside the manifest repo.
  220. # That allows us to use <include> with the relative file name.
  221. with open(self.manifestFile, 'w') as fp:
  222. fp.write("""<?xml version="1.0" encoding="UTF-8"?>
  223. <!--
  224. DO NOT EDIT THIS FILE! It is generated by repo and changes will be discarded.
  225. If you want to use a different manifest, use `repo init -m <file>` instead.
  226. If you want to customize your checkout by overriding manifest settings, use
  227. the local_manifests/ directory instead.
  228. For more information on repo manifests, check out:
  229. https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
  230. -->
  231. <manifest>
  232. <include name="%s" />
  233. </manifest>
  234. """ % (name,))
  235. def _RemoteToXml(self, r, doc, root):
  236. e = doc.createElement('remote')
  237. root.appendChild(e)
  238. e.setAttribute('name', r.name)
  239. e.setAttribute('fetch', r.fetchUrl)
  240. if r.pushUrl is not None:
  241. e.setAttribute('pushurl', r.pushUrl)
  242. if r.remoteAlias is not None:
  243. e.setAttribute('alias', r.remoteAlias)
  244. if r.reviewUrl is not None:
  245. e.setAttribute('review', r.reviewUrl)
  246. if r.revision is not None:
  247. e.setAttribute('revision', r.revision)
  248. def _ParseGroups(self, groups):
  249. return [x for x in re.split(r'[,\s]+', groups) if x]
  250. def ToXml(self, peg_rev=False, peg_rev_upstream=True, peg_rev_dest_branch=True, groups=None):
  251. """Return the current manifest XML."""
  252. mp = self.manifestProject
  253. if groups is None:
  254. groups = mp.config.GetString('manifest.groups')
  255. if groups:
  256. groups = self._ParseGroups(groups)
  257. doc = xml.dom.minidom.Document()
  258. root = doc.createElement('manifest')
  259. doc.appendChild(root)
  260. # Save out the notice. There's a little bit of work here to give it the
  261. # right whitespace, which assumes that the notice is automatically indented
  262. # by 4 by minidom.
  263. if self.notice:
  264. notice_element = root.appendChild(doc.createElement('notice'))
  265. notice_lines = self.notice.splitlines()
  266. indented_notice = ('\n'.join(" " * 4 + line for line in notice_lines))[4:]
  267. notice_element.appendChild(doc.createTextNode(indented_notice))
  268. d = self.default
  269. for r in sorted(self.remotes):
  270. self._RemoteToXml(self.remotes[r], doc, root)
  271. if self.remotes:
  272. root.appendChild(doc.createTextNode(''))
  273. have_default = False
  274. e = doc.createElement('default')
  275. if d.remote:
  276. have_default = True
  277. e.setAttribute('remote', d.remote.name)
  278. if d.revisionExpr:
  279. have_default = True
  280. e.setAttribute('revision', d.revisionExpr)
  281. if d.destBranchExpr:
  282. have_default = True
  283. e.setAttribute('dest-branch', d.destBranchExpr)
  284. if d.upstreamExpr:
  285. have_default = True
  286. e.setAttribute('upstream', d.upstreamExpr)
  287. if d.sync_j > 1:
  288. have_default = True
  289. e.setAttribute('sync-j', '%d' % d.sync_j)
  290. if d.sync_c:
  291. have_default = True
  292. e.setAttribute('sync-c', 'true')
  293. if d.sync_s:
  294. have_default = True
  295. e.setAttribute('sync-s', 'true')
  296. if not d.sync_tags:
  297. have_default = True
  298. e.setAttribute('sync-tags', 'false')
  299. if have_default:
  300. root.appendChild(e)
  301. root.appendChild(doc.createTextNode(''))
  302. if self._manifest_server:
  303. e = doc.createElement('manifest-server')
  304. e.setAttribute('url', self._manifest_server)
  305. root.appendChild(e)
  306. root.appendChild(doc.createTextNode(''))
  307. def output_projects(parent, parent_node, projects):
  308. for project_name in projects:
  309. for project in self._projects[project_name]:
  310. output_project(parent, parent_node, project)
  311. def output_project(parent, parent_node, p):
  312. if not p.MatchesGroups(groups):
  313. return
  314. name = p.name
  315. relpath = p.relpath
  316. if parent:
  317. name = self._UnjoinName(parent.name, name)
  318. relpath = self._UnjoinRelpath(parent.relpath, relpath)
  319. e = doc.createElement('project')
  320. parent_node.appendChild(e)
  321. e.setAttribute('name', name)
  322. if relpath != name:
  323. e.setAttribute('path', relpath)
  324. remoteName = None
  325. if d.remote:
  326. remoteName = d.remote.name
  327. if not d.remote or p.remote.orig_name != remoteName:
  328. remoteName = p.remote.orig_name
  329. e.setAttribute('remote', remoteName)
  330. if peg_rev:
  331. if self.IsMirror:
  332. value = p.bare_git.rev_parse(p.revisionExpr + '^0')
  333. else:
  334. value = p.work_git.rev_parse(HEAD + '^0')
  335. e.setAttribute('revision', value)
  336. if peg_rev_upstream:
  337. if p.upstream:
  338. e.setAttribute('upstream', p.upstream)
  339. elif value != p.revisionExpr:
  340. # Only save the origin if the origin is not a sha1, and the default
  341. # isn't our value
  342. e.setAttribute('upstream', p.revisionExpr)
  343. if peg_rev_dest_branch:
  344. if p.dest_branch:
  345. e.setAttribute('dest-branch', p.dest_branch)
  346. elif value != p.revisionExpr:
  347. e.setAttribute('dest-branch', p.revisionExpr)
  348. else:
  349. revision = self.remotes[p.remote.orig_name].revision or d.revisionExpr
  350. if not revision or revision != p.revisionExpr:
  351. e.setAttribute('revision', p.revisionExpr)
  352. if (p.upstream and (p.upstream != p.revisionExpr or
  353. p.upstream != d.upstreamExpr)):
  354. e.setAttribute('upstream', p.upstream)
  355. if p.dest_branch and p.dest_branch != d.destBranchExpr:
  356. e.setAttribute('dest-branch', p.dest_branch)
  357. for c in p.copyfiles:
  358. ce = doc.createElement('copyfile')
  359. ce.setAttribute('src', c.src)
  360. ce.setAttribute('dest', c.dest)
  361. e.appendChild(ce)
  362. for l in p.linkfiles:
  363. le = doc.createElement('linkfile')
  364. le.setAttribute('src', l.src)
  365. le.setAttribute('dest', l.dest)
  366. e.appendChild(le)
  367. default_groups = ['all', 'name:%s' % p.name, 'path:%s' % p.relpath]
  368. egroups = [g for g in p.groups if g not in default_groups]
  369. if egroups:
  370. e.setAttribute('groups', ','.join(egroups))
  371. for a in p.annotations:
  372. if a.keep == "true":
  373. ae = doc.createElement('annotation')
  374. ae.setAttribute('name', a.name)
  375. ae.setAttribute('value', a.value)
  376. e.appendChild(ae)
  377. if p.sync_c:
  378. e.setAttribute('sync-c', 'true')
  379. if p.sync_s:
  380. e.setAttribute('sync-s', 'true')
  381. if not p.sync_tags:
  382. e.setAttribute('sync-tags', 'false')
  383. if p.clone_depth:
  384. e.setAttribute('clone-depth', str(p.clone_depth))
  385. self._output_manifest_project_extras(p, e)
  386. if p.subprojects:
  387. subprojects = set(subp.name for subp in p.subprojects)
  388. output_projects(p, e, list(sorted(subprojects)))
  389. projects = set(p.name for p in self._paths.values() if not p.parent)
  390. output_projects(None, root, list(sorted(projects)))
  391. if self._repo_hooks_project:
  392. root.appendChild(doc.createTextNode(''))
  393. e = doc.createElement('repo-hooks')
  394. e.setAttribute('in-project', self._repo_hooks_project.name)
  395. e.setAttribute('enabled-list',
  396. ' '.join(self._repo_hooks_project.enabled_repo_hooks))
  397. root.appendChild(e)
  398. return doc
  399. def ToDict(self, **kwargs):
  400. """Return the current manifest as a dictionary."""
  401. # Elements that may only appear once.
  402. SINGLE_ELEMENTS = {
  403. 'notice',
  404. 'default',
  405. 'manifest-server',
  406. 'repo-hooks',
  407. }
  408. # Elements that may be repeated.
  409. MULTI_ELEMENTS = {
  410. 'remote',
  411. 'remove-project',
  412. 'project',
  413. 'extend-project',
  414. 'include',
  415. # These are children of 'project' nodes.
  416. 'annotation',
  417. 'project',
  418. 'copyfile',
  419. 'linkfile',
  420. }
  421. doc = self.ToXml(**kwargs)
  422. ret = {}
  423. def append_children(ret, node):
  424. for child in node.childNodes:
  425. if child.nodeType == xml.dom.Node.ELEMENT_NODE:
  426. attrs = child.attributes
  427. element = dict((attrs.item(i).localName, attrs.item(i).value)
  428. for i in range(attrs.length))
  429. if child.nodeName in SINGLE_ELEMENTS:
  430. ret[child.nodeName] = element
  431. elif child.nodeName in MULTI_ELEMENTS:
  432. ret.setdefault(child.nodeName, []).append(element)
  433. else:
  434. raise ManifestParseError('Unhandled element "%s"' % (child.nodeName,))
  435. append_children(element, child)
  436. append_children(ret, doc.firstChild)
  437. return ret
  438. def Save(self, fd, **kwargs):
  439. """Write the current manifest out to the given file descriptor."""
  440. doc = self.ToXml(**kwargs)
  441. doc.writexml(fd, '', ' ', '\n', 'UTF-8')
  442. def _output_manifest_project_extras(self, p, e):
  443. """Manifests can modify e if they support extra project attributes."""
  444. pass
  445. @property
  446. def paths(self):
  447. self._Load()
  448. return self._paths
  449. @property
  450. def projects(self):
  451. self._Load()
  452. return list(self._paths.values())
  453. @property
  454. def remotes(self):
  455. self._Load()
  456. return self._remotes
  457. @property
  458. def default(self):
  459. self._Load()
  460. return self._default
  461. @property
  462. def repo_hooks_project(self):
  463. self._Load()
  464. return self._repo_hooks_project
  465. @property
  466. def notice(self):
  467. self._Load()
  468. return self._notice
  469. @property
  470. def manifest_server(self):
  471. self._Load()
  472. return self._manifest_server
  473. @property
  474. def CloneBundle(self):
  475. clone_bundle = self.manifestProject.config.GetBoolean('repo.clonebundle')
  476. if clone_bundle is None:
  477. return False if self.manifestProject.config.GetBoolean('repo.partialclone') else True
  478. else:
  479. return clone_bundle
  480. @property
  481. def CloneFilter(self):
  482. if self.manifestProject.config.GetBoolean('repo.partialclone'):
  483. return self.manifestProject.config.GetString('repo.clonefilter')
  484. return None
  485. @property
  486. def IsMirror(self):
  487. return self.manifestProject.config.GetBoolean('repo.mirror')
  488. @property
  489. def UseGitWorktrees(self):
  490. return self.manifestProject.config.GetBoolean('repo.worktree')
  491. @property
  492. def IsArchive(self):
  493. return self.manifestProject.config.GetBoolean('repo.archive')
  494. @property
  495. def HasSubmodules(self):
  496. return self.manifestProject.config.GetBoolean('repo.submodules')
  497. def _Unload(self):
  498. self._loaded = False
  499. self._projects = {}
  500. self._paths = {}
  501. self._remotes = {}
  502. self._default = None
  503. self._repo_hooks_project = None
  504. self._notice = None
  505. self.branch = None
  506. self._manifest_server = None
  507. def _Load(self):
  508. if not self._loaded:
  509. m = self.manifestProject
  510. b = m.GetBranch(m.CurrentBranch).merge
  511. if b is not None and b.startswith(R_HEADS):
  512. b = b[len(R_HEADS):]
  513. self.branch = b
  514. nodes = []
  515. nodes.append(self._ParseManifestXml(self.manifestFile,
  516. self.manifestProject.worktree))
  517. if self._load_local_manifests and self.local_manifests:
  518. try:
  519. for local_file in sorted(platform_utils.listdir(self.local_manifests)):
  520. if local_file.endswith('.xml'):
  521. local = os.path.join(self.local_manifests, local_file)
  522. nodes.append(self._ParseManifestXml(local, self.repodir))
  523. except OSError:
  524. pass
  525. try:
  526. self._ParseManifest(nodes)
  527. except ManifestParseError as e:
  528. # There was a problem parsing, unload ourselves in case they catch
  529. # this error and try again later, we will show the correct error
  530. self._Unload()
  531. raise e
  532. if self.IsMirror:
  533. self._AddMetaProjectMirror(self.repoProject)
  534. self._AddMetaProjectMirror(self.manifestProject)
  535. self._loaded = True
  536. def _ParseManifestXml(self, path, include_root):
  537. try:
  538. root = xml.dom.minidom.parse(path)
  539. except (OSError, xml.parsers.expat.ExpatError) as e:
  540. raise ManifestParseError("error parsing manifest %s: %s" % (path, e))
  541. if not root or not root.childNodes:
  542. raise ManifestParseError("no root node in %s" % (path,))
  543. for manifest in root.childNodes:
  544. if manifest.nodeName == 'manifest':
  545. break
  546. else:
  547. raise ManifestParseError("no <manifest> in %s" % (path,))
  548. nodes = []
  549. for node in manifest.childNodes:
  550. if node.nodeName == 'include':
  551. name = self._reqatt(node, 'name')
  552. fp = os.path.join(include_root, name)
  553. if not os.path.isfile(fp):
  554. raise ManifestParseError("include %s doesn't exist or isn't a file"
  555. % (name,))
  556. try:
  557. nodes.extend(self._ParseManifestXml(fp, include_root))
  558. # should isolate this to the exact exception, but that's
  559. # tricky. actual parsing implementation may vary.
  560. except (KeyboardInterrupt, RuntimeError, SystemExit):
  561. raise
  562. except Exception as e:
  563. raise ManifestParseError(
  564. "failed parsing included manifest %s: %s" % (name, e))
  565. else:
  566. nodes.append(node)
  567. return nodes
  568. def _ParseManifest(self, node_list):
  569. for node in itertools.chain(*node_list):
  570. if node.nodeName == 'remote':
  571. remote = self._ParseRemote(node)
  572. if remote:
  573. if remote.name in self._remotes:
  574. if remote != self._remotes[remote.name]:
  575. raise ManifestParseError(
  576. 'remote %s already exists with different attributes' %
  577. (remote.name))
  578. else:
  579. self._remotes[remote.name] = remote
  580. for node in itertools.chain(*node_list):
  581. if node.nodeName == 'default':
  582. new_default = self._ParseDefault(node)
  583. if self._default is None:
  584. self._default = new_default
  585. elif new_default != self._default:
  586. raise ManifestParseError('duplicate default in %s' %
  587. (self.manifestFile))
  588. if self._default is None:
  589. self._default = _Default()
  590. for node in itertools.chain(*node_list):
  591. if node.nodeName == 'notice':
  592. if self._notice is not None:
  593. raise ManifestParseError(
  594. 'duplicate notice in %s' %
  595. (self.manifestFile))
  596. self._notice = self._ParseNotice(node)
  597. for node in itertools.chain(*node_list):
  598. if node.nodeName == 'manifest-server':
  599. url = self._reqatt(node, 'url')
  600. if self._manifest_server is not None:
  601. raise ManifestParseError(
  602. 'duplicate manifest-server in %s' %
  603. (self.manifestFile))
  604. self._manifest_server = url
  605. def recursively_add_projects(project):
  606. projects = self._projects.setdefault(project.name, [])
  607. if project.relpath is None:
  608. raise ManifestParseError(
  609. 'missing path for %s in %s' %
  610. (project.name, self.manifestFile))
  611. if project.relpath in self._paths:
  612. raise ManifestParseError(
  613. 'duplicate path %s in %s' %
  614. (project.relpath, self.manifestFile))
  615. self._paths[project.relpath] = project
  616. projects.append(project)
  617. for subproject in project.subprojects:
  618. recursively_add_projects(subproject)
  619. for node in itertools.chain(*node_list):
  620. if node.nodeName == 'project':
  621. project = self._ParseProject(node)
  622. recursively_add_projects(project)
  623. if node.nodeName == 'extend-project':
  624. name = self._reqatt(node, 'name')
  625. if name not in self._projects:
  626. raise ManifestParseError('extend-project element specifies non-existent '
  627. 'project: %s' % name)
  628. path = node.getAttribute('path')
  629. groups = node.getAttribute('groups')
  630. if groups:
  631. groups = self._ParseGroups(groups)
  632. revision = node.getAttribute('revision')
  633. remote = node.getAttribute('remote')
  634. if remote:
  635. remote = self._get_remote(node)
  636. for p in self._projects[name]:
  637. if path and p.relpath != path:
  638. continue
  639. if groups:
  640. p.groups.extend(groups)
  641. if revision:
  642. p.revisionExpr = revision
  643. if IsId(revision):
  644. p.revisionId = revision
  645. else:
  646. p.revisionId = None
  647. if remote:
  648. p.remote = remote.ToRemoteSpec(name)
  649. if node.nodeName == 'repo-hooks':
  650. # Get the name of the project and the (space-separated) list of enabled.
  651. repo_hooks_project = self._reqatt(node, 'in-project')
  652. enabled_repo_hooks = self._reqatt(node, 'enabled-list').split()
  653. # Only one project can be the hooks project
  654. if self._repo_hooks_project is not None:
  655. raise ManifestParseError(
  656. 'duplicate repo-hooks in %s' %
  657. (self.manifestFile))
  658. # Store a reference to the Project.
  659. try:
  660. repo_hooks_projects = self._projects[repo_hooks_project]
  661. except KeyError:
  662. raise ManifestParseError(
  663. 'project %s not found for repo-hooks' %
  664. (repo_hooks_project))
  665. if len(repo_hooks_projects) != 1:
  666. raise ManifestParseError(
  667. 'internal error parsing repo-hooks in %s' %
  668. (self.manifestFile))
  669. self._repo_hooks_project = repo_hooks_projects[0]
  670. # Store the enabled hooks in the Project object.
  671. self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks
  672. if node.nodeName == 'remove-project':
  673. name = self._reqatt(node, 'name')
  674. if name not in self._projects:
  675. raise ManifestParseError('remove-project element specifies non-existent '
  676. 'project: %s' % name)
  677. for p in self._projects[name]:
  678. del self._paths[p.relpath]
  679. del self._projects[name]
  680. # If the manifest removes the hooks project, treat it as if it deleted
  681. # the repo-hooks element too.
  682. if self._repo_hooks_project and (self._repo_hooks_project.name == name):
  683. self._repo_hooks_project = None
  684. def _AddMetaProjectMirror(self, m):
  685. name = None
  686. m_url = m.GetRemote(m.remote.name).url
  687. if m_url.endswith('/.git'):
  688. raise ManifestParseError('refusing to mirror %s' % m_url)
  689. if self._default and self._default.remote:
  690. url = self._default.remote.resolvedFetchUrl
  691. if not url.endswith('/'):
  692. url += '/'
  693. if m_url.startswith(url):
  694. remote = self._default.remote
  695. name = m_url[len(url):]
  696. if name is None:
  697. s = m_url.rindex('/') + 1
  698. manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
  699. remote = _XmlRemote('origin', fetch=m_url[:s], manifestUrl=manifestUrl)
  700. name = m_url[s:]
  701. if name.endswith('.git'):
  702. name = name[:-4]
  703. if name not in self._projects:
  704. m.PreSync()
  705. gitdir = os.path.join(self.topdir, '%s.git' % name)
  706. project = Project(manifest=self,
  707. name=name,
  708. remote=remote.ToRemoteSpec(name),
  709. gitdir=gitdir,
  710. objdir=gitdir,
  711. worktree=None,
  712. relpath=name or None,
  713. revisionExpr=m.revisionExpr,
  714. revisionId=None)
  715. self._projects[project.name] = [project]
  716. self._paths[project.relpath] = project
  717. def _ParseRemote(self, node):
  718. """
  719. reads a <remote> element from the manifest file
  720. """
  721. name = self._reqatt(node, 'name')
  722. alias = node.getAttribute('alias')
  723. if alias == '':
  724. alias = None
  725. fetch = self._reqatt(node, 'fetch')
  726. pushUrl = node.getAttribute('pushurl')
  727. if pushUrl == '':
  728. pushUrl = None
  729. review = node.getAttribute('review')
  730. if review == '':
  731. review = None
  732. revision = node.getAttribute('revision')
  733. if revision == '':
  734. revision = None
  735. manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
  736. return _XmlRemote(name, alias, fetch, pushUrl, manifestUrl, review, revision)
  737. def _ParseDefault(self, node):
  738. """
  739. reads a <default> element from the manifest file
  740. """
  741. d = _Default()
  742. d.remote = self._get_remote(node)
  743. d.revisionExpr = node.getAttribute('revision')
  744. if d.revisionExpr == '':
  745. d.revisionExpr = None
  746. d.destBranchExpr = node.getAttribute('dest-branch') or None
  747. d.upstreamExpr = node.getAttribute('upstream') or None
  748. d.sync_j = XmlInt(node, 'sync-j', 1)
  749. if d.sync_j <= 0:
  750. raise ManifestParseError('%s: sync-j must be greater than 0, not "%s"' %
  751. (self.manifestFile, d.sync_j))
  752. d.sync_c = XmlBool(node, 'sync-c', False)
  753. d.sync_s = XmlBool(node, 'sync-s', False)
  754. d.sync_tags = XmlBool(node, 'sync-tags', True)
  755. return d
  756. def _ParseNotice(self, node):
  757. """
  758. reads a <notice> element from the manifest file
  759. The <notice> element is distinct from other tags in the XML in that the
  760. data is conveyed between the start and end tag (it's not an empty-element
  761. tag).
  762. The white space (carriage returns, indentation) for the notice element is
  763. relevant and is parsed in a way that is based on how python docstrings work.
  764. In fact, the code is remarkably similar to here:
  765. http://www.python.org/dev/peps/pep-0257/
  766. """
  767. # Get the data out of the node...
  768. notice = node.childNodes[0].data
  769. # Figure out minimum indentation, skipping the first line (the same line
  770. # as the <notice> tag)...
  771. minIndent = sys.maxsize
  772. lines = notice.splitlines()
  773. for line in lines[1:]:
  774. lstrippedLine = line.lstrip()
  775. if lstrippedLine:
  776. indent = len(line) - len(lstrippedLine)
  777. minIndent = min(indent, minIndent)
  778. # Strip leading / trailing blank lines and also indentation.
  779. cleanLines = [lines[0].strip()]
  780. for line in lines[1:]:
  781. cleanLines.append(line[minIndent:].rstrip())
  782. # Clear completely blank lines from front and back...
  783. while cleanLines and not cleanLines[0]:
  784. del cleanLines[0]
  785. while cleanLines and not cleanLines[-1]:
  786. del cleanLines[-1]
  787. return '\n'.join(cleanLines)
  788. def _JoinName(self, parent_name, name):
  789. return os.path.join(parent_name, name)
  790. def _UnjoinName(self, parent_name, name):
  791. return os.path.relpath(name, parent_name)
  792. def _ParseProject(self, node, parent=None, **extra_proj_attrs):
  793. """
  794. reads a <project> element from the manifest file
  795. """
  796. name = self._reqatt(node, 'name')
  797. if parent:
  798. name = self._JoinName(parent.name, name)
  799. remote = self._get_remote(node)
  800. if remote is None:
  801. remote = self._default.remote
  802. if remote is None:
  803. raise ManifestParseError("no remote for project %s within %s" %
  804. (name, self.manifestFile))
  805. revisionExpr = node.getAttribute('revision') or remote.revision
  806. if not revisionExpr:
  807. revisionExpr = self._default.revisionExpr
  808. if not revisionExpr:
  809. raise ManifestParseError("no revision for project %s within %s" %
  810. (name, self.manifestFile))
  811. path = node.getAttribute('path')
  812. if not path:
  813. path = name
  814. if path.startswith('/'):
  815. raise ManifestParseError("project %s path cannot be absolute in %s" %
  816. (name, self.manifestFile))
  817. rebase = XmlBool(node, 'rebase', True)
  818. sync_c = XmlBool(node, 'sync-c', False)
  819. sync_s = XmlBool(node, 'sync-s', self._default.sync_s)
  820. sync_tags = XmlBool(node, 'sync-tags', self._default.sync_tags)
  821. clone_depth = XmlInt(node, 'clone-depth')
  822. if clone_depth is not None and clone_depth <= 0:
  823. raise ManifestParseError('%s: clone-depth must be greater than 0, not "%s"' %
  824. (self.manifestFile, clone_depth))
  825. dest_branch = node.getAttribute('dest-branch') or self._default.destBranchExpr
  826. upstream = node.getAttribute('upstream') or self._default.upstreamExpr
  827. groups = ''
  828. if node.hasAttribute('groups'):
  829. groups = node.getAttribute('groups')
  830. groups = self._ParseGroups(groups)
  831. if parent is None:
  832. relpath, worktree, gitdir, objdir, use_git_worktrees = \
  833. self.GetProjectPaths(name, path)
  834. else:
  835. use_git_worktrees = False
  836. relpath, worktree, gitdir, objdir = \
  837. self.GetSubprojectPaths(parent, name, path)
  838. default_groups = ['all', 'name:%s' % name, 'path:%s' % relpath]
  839. groups.extend(set(default_groups).difference(groups))
  840. if self.IsMirror and node.hasAttribute('force-path'):
  841. if XmlBool(node, 'force-path', False):
  842. gitdir = os.path.join(self.topdir, '%s.git' % path)
  843. project = Project(manifest=self,
  844. name=name,
  845. remote=remote.ToRemoteSpec(name),
  846. gitdir=gitdir,
  847. objdir=objdir,
  848. worktree=worktree,
  849. relpath=relpath,
  850. revisionExpr=revisionExpr,
  851. revisionId=None,
  852. rebase=rebase,
  853. groups=groups,
  854. sync_c=sync_c,
  855. sync_s=sync_s,
  856. sync_tags=sync_tags,
  857. clone_depth=clone_depth,
  858. upstream=upstream,
  859. parent=parent,
  860. dest_branch=dest_branch,
  861. use_git_worktrees=use_git_worktrees,
  862. **extra_proj_attrs)
  863. for n in node.childNodes:
  864. if n.nodeName == 'copyfile':
  865. self._ParseCopyFile(project, n)
  866. if n.nodeName == 'linkfile':
  867. self._ParseLinkFile(project, n)
  868. if n.nodeName == 'annotation':
  869. self._ParseAnnotation(project, n)
  870. if n.nodeName == 'project':
  871. project.subprojects.append(self._ParseProject(n, parent=project))
  872. return project
  873. def GetProjectPaths(self, name, path):
  874. # The manifest entries might have trailing slashes. Normalize them to avoid
  875. # unexpected filesystem behavior since we do string concatenation below.
  876. path = path.rstrip('/')
  877. name = name.rstrip('/')
  878. use_git_worktrees = False
  879. relpath = path
  880. if self.IsMirror:
  881. worktree = None
  882. gitdir = os.path.join(self.topdir, '%s.git' % name)
  883. objdir = gitdir
  884. else:
  885. worktree = os.path.join(self.topdir, path).replace('\\', '/')
  886. gitdir = os.path.join(self.repodir, 'projects', '%s.git' % path)
  887. # We allow people to mix git worktrees & non-git worktrees for now.
  888. # This allows for in situ migration of repo clients.
  889. if os.path.exists(gitdir) or not self.UseGitWorktrees:
  890. objdir = os.path.join(self.repodir, 'project-objects', '%s.git' % name)
  891. else:
  892. use_git_worktrees = True
  893. gitdir = os.path.join(self.repodir, 'worktrees', '%s.git' % name)
  894. objdir = gitdir
  895. return relpath, worktree, gitdir, objdir, use_git_worktrees
  896. def GetProjectsWithName(self, name):
  897. return self._projects.get(name, [])
  898. def GetSubprojectName(self, parent, submodule_path):
  899. return os.path.join(parent.name, submodule_path)
  900. def _JoinRelpath(self, parent_relpath, relpath):
  901. return os.path.join(parent_relpath, relpath)
  902. def _UnjoinRelpath(self, parent_relpath, relpath):
  903. return os.path.relpath(relpath, parent_relpath)
  904. def GetSubprojectPaths(self, parent, name, path):
  905. # The manifest entries might have trailing slashes. Normalize them to avoid
  906. # unexpected filesystem behavior since we do string concatenation below.
  907. path = path.rstrip('/')
  908. name = name.rstrip('/')
  909. relpath = self._JoinRelpath(parent.relpath, path)
  910. gitdir = os.path.join(parent.gitdir, 'subprojects', '%s.git' % path)
  911. objdir = os.path.join(parent.gitdir, 'subproject-objects', '%s.git' % name)
  912. if self.IsMirror:
  913. worktree = None
  914. else:
  915. worktree = os.path.join(parent.worktree, path).replace('\\', '/')
  916. return relpath, worktree, gitdir, objdir
  917. @staticmethod
  918. def _CheckLocalPath(path, symlink=False):
  919. """Verify |path| is reasonable for use in <copyfile> & <linkfile>."""
  920. if '~' in path:
  921. return '~ not allowed (due to 8.3 filenames on Windows filesystems)'
  922. # Some filesystems (like Apple's HFS+) try to normalize Unicode codepoints
  923. # which means there are alternative names for ".git". Reject paths with
  924. # these in it as there shouldn't be any reasonable need for them here.
  925. # The set of codepoints here was cribbed from jgit's implementation:
  926. # https://eclipse.googlesource.com/jgit/jgit/+/9110037e3e9461ff4dac22fee84ef3694ed57648/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java#884
  927. BAD_CODEPOINTS = {
  928. u'\u200C', # ZERO WIDTH NON-JOINER
  929. u'\u200D', # ZERO WIDTH JOINER
  930. u'\u200E', # LEFT-TO-RIGHT MARK
  931. u'\u200F', # RIGHT-TO-LEFT MARK
  932. u'\u202A', # LEFT-TO-RIGHT EMBEDDING
  933. u'\u202B', # RIGHT-TO-LEFT EMBEDDING
  934. u'\u202C', # POP DIRECTIONAL FORMATTING
  935. u'\u202D', # LEFT-TO-RIGHT OVERRIDE
  936. u'\u202E', # RIGHT-TO-LEFT OVERRIDE
  937. u'\u206A', # INHIBIT SYMMETRIC SWAPPING
  938. u'\u206B', # ACTIVATE SYMMETRIC SWAPPING
  939. u'\u206C', # INHIBIT ARABIC FORM SHAPING
  940. u'\u206D', # ACTIVATE ARABIC FORM SHAPING
  941. u'\u206E', # NATIONAL DIGIT SHAPES
  942. u'\u206F', # NOMINAL DIGIT SHAPES
  943. u'\uFEFF', # ZERO WIDTH NO-BREAK SPACE
  944. }
  945. if BAD_CODEPOINTS & set(path):
  946. # This message is more expansive than reality, but should be fine.
  947. return 'Unicode combining characters not allowed'
  948. # Assume paths might be used on case-insensitive filesystems.
  949. path = path.lower()
  950. # Split up the path by its components. We can't use os.path.sep exclusively
  951. # as some platforms (like Windows) will convert / to \ and that bypasses all
  952. # our constructed logic here. Especially since manifest authors only use
  953. # / in their paths.
  954. resep = re.compile(r'[/%s]' % re.escape(os.path.sep))
  955. parts = resep.split(path)
  956. # Some people use src="." to create stable links to projects. Lets allow
  957. # that but reject all other uses of "." to keep things simple.
  958. if parts != ['.']:
  959. for part in set(parts):
  960. if part in {'.', '..', '.git'} or part.startswith('.repo'):
  961. return 'bad component: %s' % (part,)
  962. if not symlink and resep.match(path[-1]):
  963. return 'dirs not allowed'
  964. # NB: The two abspath checks here are to handle platforms with multiple
  965. # filesystem path styles (e.g. Windows).
  966. norm = os.path.normpath(path)
  967. if (norm == '..' or
  968. (len(norm) >= 3 and norm.startswith('..') and resep.match(norm[0])) or
  969. os.path.isabs(norm) or
  970. norm.startswith('/')):
  971. return 'path cannot be outside'
  972. @classmethod
  973. def _ValidateFilePaths(cls, element, src, dest):
  974. """Verify |src| & |dest| are reasonable for <copyfile> & <linkfile>.
  975. We verify the path independent of any filesystem state as we won't have a
  976. checkout available to compare to. i.e. This is for parsing validation
  977. purposes only.
  978. We'll do full/live sanity checking before we do the actual filesystem
  979. modifications in _CopyFile/_LinkFile/etc...
  980. """
  981. # |dest| is the file we write to or symlink we create.
  982. # It is relative to the top of the repo client checkout.
  983. msg = cls._CheckLocalPath(dest)
  984. if msg:
  985. raise ManifestInvalidPathError(
  986. '<%s> invalid "dest": %s: %s' % (element, dest, msg))
  987. # |src| is the file we read from or path we point to for symlinks.
  988. # It is relative to the top of the git project checkout.
  989. msg = cls._CheckLocalPath(src, symlink=element == 'linkfile')
  990. if msg:
  991. raise ManifestInvalidPathError(
  992. '<%s> invalid "src": %s: %s' % (element, src, msg))
  993. def _ParseCopyFile(self, project, node):
  994. src = self._reqatt(node, 'src')
  995. dest = self._reqatt(node, 'dest')
  996. if not self.IsMirror:
  997. # src is project relative;
  998. # dest is relative to the top of the tree.
  999. # We only validate paths if we actually plan to process them.
  1000. self._ValidateFilePaths('copyfile', src, dest)
  1001. project.AddCopyFile(src, dest, self.topdir)
  1002. def _ParseLinkFile(self, project, node):
  1003. src = self._reqatt(node, 'src')
  1004. dest = self._reqatt(node, 'dest')
  1005. if not self.IsMirror:
  1006. # src is project relative;
  1007. # dest is relative to the top of the tree.
  1008. # We only validate paths if we actually plan to process them.
  1009. self._ValidateFilePaths('linkfile', src, dest)
  1010. project.AddLinkFile(src, dest, self.topdir)
  1011. def _ParseAnnotation(self, project, node):
  1012. name = self._reqatt(node, 'name')
  1013. value = self._reqatt(node, 'value')
  1014. try:
  1015. keep = self._reqatt(node, 'keep').lower()
  1016. except ManifestParseError:
  1017. keep = "true"
  1018. if keep != "true" and keep != "false":
  1019. raise ManifestParseError('optional "keep" attribute must be '
  1020. '"true" or "false"')
  1021. project.AddAnnotation(name, value, keep)
  1022. def _get_remote(self, node):
  1023. name = node.getAttribute('remote')
  1024. if not name:
  1025. return None
  1026. v = self._remotes.get(name)
  1027. if not v:
  1028. raise ManifestParseError("remote %s not defined in %s" %
  1029. (name, self.manifestFile))
  1030. return v
  1031. def _reqatt(self, node, attname):
  1032. """
  1033. reads a required attribute from the node.
  1034. """
  1035. v = node.getAttribute(attname)
  1036. if not v:
  1037. raise ManifestParseError("no %s in <%s> within %s" %
  1038. (attname, node.nodeName, self.manifestFile))
  1039. return v
  1040. def projectsDiff(self, manifest):
  1041. """return the projects differences between two manifests.
  1042. The diff will be from self to given manifest.
  1043. """
  1044. fromProjects = self.paths
  1045. toProjects = manifest.paths
  1046. fromKeys = sorted(fromProjects.keys())
  1047. toKeys = sorted(toProjects.keys())
  1048. diff = {'added': [], 'removed': [], 'changed': [], 'unreachable': []}
  1049. for proj in fromKeys:
  1050. if proj not in toKeys:
  1051. diff['removed'].append(fromProjects[proj])
  1052. else:
  1053. fromProj = fromProjects[proj]
  1054. toProj = toProjects[proj]
  1055. try:
  1056. fromRevId = fromProj.GetCommitRevisionId()
  1057. toRevId = toProj.GetCommitRevisionId()
  1058. except ManifestInvalidRevisionError:
  1059. diff['unreachable'].append((fromProj, toProj))
  1060. else:
  1061. if fromRevId != toRevId:
  1062. diff['changed'].append((fromProj, toProj))
  1063. toKeys.remove(proj)
  1064. for proj in toKeys:
  1065. diff['added'].append(toProjects[proj])
  1066. return diff
  1067. class GitcManifest(XmlManifest):
  1068. """Parser for GitC (git-in-the-cloud) manifests."""
  1069. def _ParseProject(self, node, parent=None):
  1070. """Override _ParseProject and add support for GITC specific attributes."""
  1071. return super(GitcManifest, self)._ParseProject(
  1072. node, parent=parent, old_revision=node.getAttribute('old-revision'))
  1073. def _output_manifest_project_extras(self, p, e):
  1074. """Output GITC Specific Project attributes"""
  1075. if p.old_revision:
  1076. e.setAttribute('old-revision', str(p.old_revision))
  1077. class RepoClient(XmlManifest):
  1078. """Manages a repo client checkout."""
  1079. def __init__(self, repodir, manifest_file=None):
  1080. self.isGitcClient = False
  1081. if os.path.exists(os.path.join(repodir, LOCAL_MANIFEST_NAME)):
  1082. print('error: %s is not supported; put local manifests in `%s` instead' %
  1083. (LOCAL_MANIFEST_NAME, os.path.join(repodir, LOCAL_MANIFESTS_DIR_NAME)),
  1084. file=sys.stderr)
  1085. sys.exit(1)
  1086. if manifest_file is None:
  1087. manifest_file = os.path.join(repodir, MANIFEST_FILE_NAME)
  1088. local_manifests = os.path.abspath(os.path.join(repodir, LOCAL_MANIFESTS_DIR_NAME))
  1089. super(RepoClient, self).__init__(repodir, manifest_file, local_manifests)
  1090. # TODO: Completely separate manifest logic out of the client.
  1091. self.manifest = self
  1092. class GitcClient(RepoClient, GitcManifest):
  1093. """Manages a GitC client checkout."""
  1094. def __init__(self, repodir, gitc_client_name):
  1095. """Initialize the GitcManifest object."""
  1096. self.gitc_client_name = gitc_client_name
  1097. self.gitc_client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(),
  1098. gitc_client_name)
  1099. super(GitcManifest, self).__init__(
  1100. repodir, os.path.join(self.gitc_client_dir, '.manifest'))
  1101. self.isGitcClient = True