code: func (r *Repository) createNewObjectPack(cfg *RepackConfig) (h plumbing.Hash, err error) {
  	ow := newObjectWalker(r.Storer)
  	err = ow.walkAllRefs()
  	if err != nil {
  		return h, err
  	}
  	objs := make([]plumbing.Hash, 0, len(ow.seen))
  	for h := range ow.seen {
  		objs = append(objs, h)
  	}
  	pfw, ok := r.Storer.(storer.PackfileWriter)
  	if !ok {
  		return h, fmt.Errorf("Repository storer is not a storer.PackfileWriter")
  	}
  	wc, err := pfw.PackfileWriter()
  	if err != nil {
  		return h, err
  	}
  	defer ioutil.CheckClose(wc, &err)
  	scfg, err := r.Storer.Config()
  	if err != nil {
  		return h, err
  	}
  	enc := packfile.NewEncoder(wc, r.Storer, cfg.UseRefDeltas)
  	h, err = enc.Encode(objs, scfg.Pack.Window)
  	if err != nil {
  		return h, err
  	}
  
  	// Delete the packed, loose objects.
  	if los, ok := r.Storer.(storer.LooseObjectStorer); ok {
  		err = los.ForEachObjectHash(func(hash plumbing.Hash) error {
  			if ow.isSeen(hash) {
  				err = los.DeleteLooseObject(hash)
  				if err != nil {
  					return err
  				}
  			}
  			return nil
  		})
  		if err != nil {
  			return h, err
  		}
  	}
  
  	return h, err
  }
docs: // createNewObjectPack is a helper for RepackObjects taking care
  // of creating a new pack. It is used so the the PackfileWriter
  // deferred close has the right scope.