code: func getMetadataImpl(c context.Context, prefix string) ([]*api.PrefixMetadata, []*packageACL, error) {
  	prefix, err := common.ValidatePackagePrefix(prefix)
  	if err != nil {
  		return nil, nil, errors.Annotate(err, "bad prefix given to GetMetadata").Err()
  	}
  
  	// Grab all subprefixes, i.e. ["a", "a/b", "a/b/c"]
  	var pfxs []string
  	for i, ch := range prefix {
  		if ch == '/' {
  			pfxs = append(pfxs, prefix[:i])
  		}
  	}
  	pfxs = append(pfxs, prefix)
  
  	// Start with the root metadata.
  	out := make([]*api.PrefixMetadata, 0, len(pfxs)+1)
  	out = append(out, rootMetadata())
  
  	// And finish with it if nothing else is requested.
  	if len(pfxs) == 0 {
  		return out, nil, nil
  	}
  
  	// Prepare the keys.
  	ents := make([]*packageACL, 0, len(pfxs)*len(legacyRoles))
  	for _, p := range pfxs {
  		ents = prefixACLs(c, p, ents)
  	}
  
  	// Fetch everything. ErrNoSuchEntity errors are fine, everything else is not.
  	if err = datastore.Get(c, ents); isInternalDSError(err) {
  		return nil, nil, errors.Annotate(err, "datastore error when fetching PackageACL").Tag(transient.Tag).Err()
  	}
  
  	// Combine the result into a bunch of PrefixMetadata structs.
  	legLen := len(legacyRoles)
  	for i, pfx := range pfxs {
  		if md := mergeIntoPrefixMetadata(c, pfx, ents[i*legLen:(i+1)*legLen]); md != nil {
  			out = append(out, md)
  		}
  	}
  	return out, ents, nil
  }
docs: // getMetadataImpl implements GetMetadata.
  //
  // As a bonus it returns all packageACL entities it fetched. This is used by
  // VisitMetadata to avoid unnecessary refetches.