load static method
The set of root, read from manifestPath (default
<root>/repos.yaml). Throws ReposManifestException for an invalid
manifest and FileSystemException when it cannot be read.
Implementation
static RepoSet load({
required String root,
String? manifestPath,
String? host,
}) {
final rootPath = p.normalize(p.absolute(root));
final file = manifestPath ?? p.join(rootPath, kReposManifestFile);
final manifest = ReposManifest.parse(File(file).readAsStringSync());
final hostId = host ?? reposHostId(rootPath);
final quests = _QuestRepos.read(rootPath);
final byPath = {for (final e in manifest.entries) e.path: e};
final unmanaged = manifest.unmanaged.toSet();
final members = <RepoSetMember>[];
final seen = <String>{};
RepoSetMember classify(String rel, {required bool toolOwned}) {
final abs = rel.isEmpty
? rootPath
: p.join(rootPath, p.joinAll(rel.split('/')));
if (rel.isEmpty) {
return RepoSetMember(
path: abs,
relPath: '',
repoClass: RepoClass.entry,
isRoot: true,
expectedBranch: manifest.rootBranch,
url: manifest.rootUrl,
);
}
if (toolOwned) {
return RepoSetMember(
path: abs,
relPath: rel,
repoClass: RepoClass.toolOwned,
);
}
final entry = byPath[rel];
if (entry != null) {
return RepoSetMember(
path: abs,
relPath: rel,
repoClass: RepoClass.entry,
entry: entry,
expectedBranch: entry.branch,
url: entry.url,
);
}
if (rel.startsWith('$kQuestsFolder/')) {
final id = rel.substring(kQuestsFolder.length + 1).split('/').first;
final quest = quests[id];
return RepoSetMember(
path: abs,
relPath: rel,
repoClass: RepoClass.questClone,
expectedBranch: quest?.branch,
url: quest?.url,
);
}
if (unmanaged.contains(rel)) {
return RepoSetMember(
path: abs,
relPath: rel,
repoClass: RepoClass.unmanaged,
);
}
return RepoSetMember(
path: abs,
relPath: rel,
repoClass: RepoClass.unknown,
);
}
void add(String rel, {bool toolOwned = false}) {
if (seen.add(rel)) members.add(classify(rel, toolOwned: toolOwned));
}
if (_isClone(rootPath)) add('');
_walk(rootPath, '', unmanaged, add);
for (final entry in manifest.entries) {
if (seen.contains(entry.path) || !entry.isForHost(hostId)) continue;
seen.add(entry.path);
members.add(
RepoSetMember(
path: p.join(rootPath, p.joinAll(entry.path.split('/'))),
relPath: entry.path,
repoClass: RepoClass.missing,
entry: entry,
expectedBranch: entry.branch,
url: entry.url,
),
);
}
members.sort((a, b) => a.relPath.compareTo(b.relPath));
return RepoSet._(rootPath, file, manifest, hostId, members);
}