headsOf method

  1. @override
Future<Map<String, String?>> headsOf(
  1. Iterable<String> locators
)
override

Groups locators by repository and branch so every open document on one branch is answered from a single snapshot — and, when nothing has moved, from a single conditional request that costs no rate-limit quota.

Implementation

@override
Future<Map<String, String?>> headsOf(Iterable<String> locators) async {
  final byRepo = <String, List<_Request>>{};
  final heads = <String, String?>{};
  for (final locator in locators) {
    final loc = await _locate(locator);
    byRepo.putIfAbsent(loc.repoKey, () => []).add(_Request(locator, loc));
  }
  for (final group in byRepo.values) {
    final snapshot = await _snapshot(group.first.locator);
    for (final request in group) {
      // Keyed by the caller's own string, not by the parsed locator's:
      // resolving the branch rewrites it, and a caller looking its own
      // locator up in the result must find it.
      heads[request.raw] = snapshot?.objectShaFor(request.locator.path);
    }
  }
  return heads;
}