forked from hswaw/hscloud
devtools/depotview: fix stale branches, clone bug
Change-Id: Ia2c680d511e3a8b632414caae3058db20d8231bamaster
parent
5bce7ce9fd
commit
ebaa40894d
|
@ -46,8 +46,10 @@ func New(remote string) *Service {
|
||||||
|
|
||||||
func (s *Service) ensureRepo(ctx context.Context) error {
|
func (s *Service) ensureRepo(ctx context.Context) error {
|
||||||
// Clone repository if necessary.
|
// Clone repository if necessary.
|
||||||
|
// Use background context - we don't want this to get canceled.
|
||||||
if s.repo == nil {
|
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,
|
URL: s.remote,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -55,14 +57,19 @@ func (s *Service) ensureRepo(ctx context.Context) error {
|
||||||
return status.Error(codes.Unavailable, "could not clone repository")
|
return status.Error(codes.Unavailable, "could not clone repository")
|
||||||
}
|
}
|
||||||
s.repo = repo
|
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.
|
// Fetch if necessary.
|
||||||
if time.Since(s.lastFetch) > 10*time.Second {
|
if time.Since(s.lastFetch) > 10*time.Second {
|
||||||
glog.Infof("Fetching...")
|
|
||||||
err := s.repo.FetchContext(ctx, &git.FetchOptions{
|
err := s.repo.FetchContext(ctx, &git.FetchOptions{
|
||||||
RefSpecs: []config.RefSpec{
|
RefSpecs: []config.RefSpec{
|
||||||
config.RefSpec("+refs/heads/*:refs/remotes/origin/*"),
|
config.RefSpec("+refs/heads/*:refs/heads/*"),
|
||||||
config.RefSpec("+refs/changes/*:refs/changes/*"),
|
config.RefSpec("+refs/changes/*:refs/changes/*"),
|
||||||
},
|
},
|
||||||
Force: true,
|
Force: true,
|
||||||
|
|
Loading…
Reference in New Issue