Skip to content

Commit c6943cc

Browse files
authored
Support Force-update in Mirror and improve Tracing in mirror (#12242)
* Remove double indirect in NewColoredIDValue Signed-off-by: Andrew Thornton <[email protected]> * Handle forced-update in mirror.go Signed-off-by: Andrew Thornton <[email protected]> * Add tracing Signed-off-by: Andrew Thornton <[email protected]> * As per @lafriks Signed-off-by: Andrew Thornton <[email protected]>
1 parent 7c0862b commit c6943cc

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

services/mirror/mirror.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,25 @@ func parseRemoteUpdateOutput(output string) []*mirrorSyncResult {
157157
refName: refName,
158158
newCommitID: gitShortEmptySha,
159159
})
160+
case strings.HasPrefix(lines[i], " + "): // Force update
161+
if idx := strings.Index(refName, " "); idx > -1 {
162+
refName = refName[:idx]
163+
}
164+
delimIdx := strings.Index(lines[i][3:], " ")
165+
if delimIdx == -1 {
166+
log.Error("SHA delimiter not found: %q", lines[i])
167+
continue
168+
}
169+
shas := strings.Split(lines[i][3:delimIdx+3], "...")
170+
if len(shas) != 2 {
171+
log.Error("Expect two SHAs but not what found: %q", lines[i])
172+
continue
173+
}
174+
results = append(results, &mirrorSyncResult{
175+
refName: refName,
176+
oldCommitID: shas[0],
177+
newCommitID: shas[1],
178+
})
160179
case strings.HasPrefix(lines[i], " "): // New commits of a reference
161180
delimIdx := strings.Index(lines[i][3:], " ")
162181
if delimIdx == -1 {
@@ -187,6 +206,7 @@ func runSync(m *models.Mirror) ([]*mirrorSyncResult, bool) {
187206
wikiPath := m.Repo.WikiPath()
188207
timeout := time.Duration(setting.Git.Timeout.Mirror) * time.Second
189208

209+
log.Trace("SyncMirrors [repo: %-v]: running git remote update...", m.Repo)
190210
gitArgs := []string{"remote", "update"}
191211
if m.EnablePrune {
192212
gitArgs = append(gitArgs, "--prune")
@@ -228,17 +248,21 @@ func runSync(m *models.Mirror) ([]*mirrorSyncResult, bool) {
228248
log.Error("OpenRepository: %v", err)
229249
return nil, false
230250
}
251+
252+
log.Trace("SyncMirrors [repo: %-v]: syncing releases with tags...", m.Repo)
231253
if err = repo_module.SyncReleasesWithTags(m.Repo, gitRepo); err != nil {
232254
gitRepo.Close()
233255
log.Error("Failed to synchronize tags to releases for repository: %v", err)
234256
}
235257
gitRepo.Close()
236258

259+
log.Trace("SyncMirrors [repo: %-v]: updating size of repository", m.Repo)
237260
if err := m.Repo.UpdateSize(models.DefaultDBContext()); err != nil {
238261
log.Error("Failed to update size for mirror repository: %v", err)
239262
}
240263

241264
if m.Repo.HasWiki() {
265+
log.Trace("SyncMirrors [repo: %-v Wiki]: running git remote update...", m.Repo)
242266
stderrBuilder.Reset()
243267
stdoutBuilder.Reset()
244268
if err := git.NewCommand("remote", "update", "--prune").
@@ -268,8 +292,10 @@ func runSync(m *models.Mirror) ([]*mirrorSyncResult, bool) {
268292
}
269293
return nil, false
270294
}
295+
log.Trace("SyncMirrors [repo: %-v Wiki]: git remote update complete", m.Repo)
271296
}
272297

298+
log.Trace("SyncMirrors [repo: %-v]: invalidating mirror branch caches...", m.Repo)
273299
branches, err := repo_module.GetBranches(m.Repo)
274300
if err != nil {
275301
log.Error("GetBranches: %v", err)
@@ -371,11 +397,13 @@ func syncMirror(repoID string) {
371397

372398
}
373399

400+
log.Trace("SyncMirrors [repo: %-v]: Running Sync", m.Repo)
374401
results, ok := runSync(m)
375402
if !ok {
376403
return
377404
}
378405

406+
log.Trace("SyncMirrors [repo: %-v]: Scheduling next update", m.Repo)
379407
m.ScheduleNextUpdate()
380408
if err = models.UpdateMirror(m); err != nil {
381409
log.Error("UpdateMirror [%s]: %v", repoID, err)
@@ -384,8 +412,9 @@ func syncMirror(repoID string) {
384412

385413
var gitRepo *git.Repository
386414
if len(results) == 0 {
387-
log.Trace("SyncMirrors [repo_id: %d]: no commits fetched", m.RepoID)
415+
log.Trace("SyncMirrors [repo: %-v]: no branches updated", m.Repo)
388416
} else {
417+
log.Trace("SyncMirrors [repo: %-v]: %d branches updated", m.Repo, len(results))
389418
gitRepo, err = git.OpenRepository(m.Repo.RepoPath())
390419
if err != nil {
391420
log.Error("OpenRepository [%d]: %v", m.RepoID, err)
@@ -440,6 +469,7 @@ func syncMirror(repoID string) {
440469

441470
notification.NotifySyncPushCommits(m.Repo.MustOwner(), m.Repo, result.refName, oldCommitID, newCommitID, theCommits)
442471
}
472+
log.Trace("SyncMirrors [repo: %-v]: done notifying updated branches/tags - now updating last commit time", m.Repo)
443473

444474
// Get latest commit date and update to current repository updated time
445475
commitDate, err := git.GetLatestCommitTime(m.Repo.RepoPath())
@@ -452,6 +482,8 @@ func syncMirror(repoID string) {
452482
log.Error("Update repository 'updated_unix' [%d]: %v", m.RepoID, err)
453483
return
454484
}
485+
486+
log.Trace("SyncMirrors [repo: %-v]: Successfully updated", m.Repo)
455487
}
456488

457489
// InitSyncMirrors initializes a go routine to sync the mirrors

0 commit comments

Comments
 (0)