From ebaa40894d9482e941d073efff01091d64892f47 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Sun, 12 Apr 2020 14:38:27 +0200 Subject: [PATCH] devtools/depotview: fix stale branches, clone bug Change-Id: Ia2c680d511e3a8b632414caae3058db20d8231ba --- devtools/depotview/service/service.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/devtools/depotview/service/service.go b/devtools/depotview/service/service.go index fad20295..be5e743e 100644 --- a/devtools/depotview/service/service.go +++ b/devtools/depotview/service/service.go @@ -46,8 +46,10 @@ func New(remote string) *Service { func (s *Service) ensureRepo(ctx context.Context) error { // Clone repository if necessary. + // Use background context - we don't want this to get canceled. if s.repo == nil { - repo, err := git.CloneContext(ctx, s.storer, nil, &git.CloneOptions{ + glog.Infof("Cloning %q...", s.remote) + repo, err := git.CloneContext(context.Background(), s.storer, nil, &git.CloneOptions{ URL: s.remote, }) if err != nil { @@ -55,14 +57,19 @@ func (s *Service) ensureRepo(ctx context.Context) error { return status.Error(codes.Unavailable, "could not clone repository") } s.repo = repo + glog.Infof("Clone done.") + } + + // We could've gotten canceled by now. + if err := ctx.Err(); err != nil { + return err } // Fetch if necessary. if time.Since(s.lastFetch) > 10*time.Second { - glog.Infof("Fetching...") err := s.repo.FetchContext(ctx, &git.FetchOptions{ RefSpecs: []config.RefSpec{ - config.RefSpec("+refs/heads/*:refs/remotes/origin/*"), + config.RefSpec("+refs/heads/*:refs/heads/*"), config.RefSpec("+refs/changes/*:refs/changes/*"), }, Force: true,