Skip to content

Commit 29f6a3f

Browse files
committed
Fix branch commits ount in pull mirror
1 parent 84f5a2d commit 29f6a3f

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

models/git/branch_list.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,21 @@ func FindCommitsCountOutdatedBranches(ctx context.Context, startID, limit int64)
163163
}
164164
return branches, nil
165165
}
166+
167+
func FindRepoCommitsCountOutdatedBranches(ctx context.Context, repoID, startID, limit int64) (BranchList, error) {
168+
var branches BranchList
169+
if err := db.GetEngine(ctx).
170+
Join("INNER", "repository", "branch.repo_id = repository.id").
171+
Where("branch.repo_id = ?", repoID).
172+
And("repository.is_empty = ?", false).
173+
And("id > ?", startID).
174+
And(
175+
builder.Expr("commit_count_id IS NULL").
176+
Or(builder.Expr("commit_id <> commit_count_id")),
177+
).
178+
Asc("id").
179+
Limit(int(limit)).Find(&branches); err != nil {
180+
return nil, err
181+
}
182+
return branches, nil
183+
}

services/mirror/mirror_pull.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
410410
log.Trace("SyncMirrors [repo: %-v Wiki]: git remote update complete", m.Repo)
411411
}
412412

413+
repo_service.SyncRepoBranchesCommitsCount(ctx, m.Repo)
414+
413415
m.UpdatedUnix = timeutil.TimeStampNow()
414416
return parseRemoteUpdateOutput(output, m.GetRemoteName()), true
415417
}

services/repository/branch.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,36 @@ func GetBranchDivergingInfo(ctx reqctx.RequestContext, baseRepo *repo_model.Repo
737737
return info, nil
738738
}
739739

740+
func SyncRepoBranchesCommitsCount(ctx context.Context, repo *repo_model.Repository) error {
741+
startID := int64(0)
742+
for {
743+
select {
744+
case <-ctx.Done():
745+
return nil
746+
default:
747+
}
748+
749+
// search all branches commits count are not synced
750+
branches, err := git_model.FindRepoCommitsCountOutdatedBranches(ctx, repo.ID, startID, 100)
751+
if err != nil {
752+
return err
753+
}
754+
if len(branches) == 0 {
755+
return nil
756+
}
757+
758+
for _, branch := range branches {
759+
branch.Repo = repo
760+
if branch.ID > startID {
761+
startID = branch.ID
762+
}
763+
if err := syncBranchCommitsCount(ctx, branch); err != nil {
764+
log.Error("syncBranchCommitsCount: %v", err)
765+
}
766+
}
767+
}
768+
}
769+
740770
func SyncBranchCommitsCount(ctx context.Context) error {
741771
startID := int64(0)
742772
for {

0 commit comments

Comments
 (0)