code: func getHavesFromRef(
  	ref *plumbing.Reference,
  	remoteRefs map[plumbing.Hash]bool,
  	s storage.Storer,
  	haves map[plumbing.Hash]bool,
  ) error {
  	h := ref.Hash()
  	if haves[h] {
  		return nil
  	}
  
  	// No need to load the commit if we know the remote already
  	// has this hash.
  	if remoteRefs[h] {
  		haves[h] = true
  		return nil
  	}
  
  	commit, err := object.GetCommit(s, h)
  	if err != nil {
  		// Ignore the error if this isn't a commit.
  		haves[ref.Hash()] = true
  		return nil
  	}
  
  	// Until go-git supports proper commit negotiation during an
  	// upload pack request, include up to `maxHavesToVisitPerRef`
  	// commits from the history of each ref.
  	walker := object.NewCommitPreorderIter(commit, haves, nil)
  	toVisit := maxHavesToVisitPerRef
  	return walker.ForEach(func(c *object.Commit) error {
  		haves[c.Hash] = true
  		toVisit--
  		// If toVisit starts out at 0 (indicating there is no
  		// max), then it will be negative here and we won't stop
  		// early.
  		if toVisit == 0 || remoteRefs[c.Hash] {
  			return storer.ErrStop
  		}
  		return nil
  	})
  }
docs: // getHavesFromRef populates the given `haves` map with the given
  // reference, and up to `maxHavesToVisitPerRef` ancestor commits.