@@ -22,27 +22,27 @@ import (
22
22
)
23
23
24
24
const (
25
- mirrorUpdate = "mirror_update"
25
+ updateCronName = "mirror_update"
26
26
)
27
27
28
- // MirrorQueue holds an UniqueQueue object of the mirror
29
- var MirrorQueue = sync .NewUniqueQueue (setting .Repository .MirrorQueueLength )
28
+ // Queue holds an UniqueQueue object of the mirror
29
+ var Queue = sync .NewUniqueQueue (setting .Repository .MirrorQueueLength )
30
30
31
31
// gitShortEmptySha Git short empty SHA
32
32
const gitShortEmptySha = "0000000"
33
33
34
- // mirrorSyncResult contains information of a updated reference.
34
+ // syncResult contains information of a updated reference.
35
35
// If the oldCommitID is "0000000", it means a new reference, the value of newCommitID is empty.
36
36
// If the newCommitID is "0000000", it means the reference is deleted, the value of oldCommitID is empty.
37
- type mirrorSyncResult struct {
37
+ type syncResult struct {
38
38
refName string
39
39
oldCommitID string
40
40
newCommitID string
41
41
}
42
42
43
43
// parseRemoteUpdateOutput detects create, update and delete operations of references from upstream.
44
- func parseRemoteUpdateOutput (output string ) []* mirrorSyncResult {
45
- results := make ([]* mirrorSyncResult , 0 , 3 )
44
+ func parseRemoteUpdateOutput (output string ) []* syncResult {
45
+ results := make ([]* syncResult , 0 , 3 )
46
46
lines := strings .Split (output , "\n " )
47
47
for i := range lines {
48
48
// Make sure reference name is presented before continue
@@ -55,12 +55,12 @@ func parseRemoteUpdateOutput(output string) []*mirrorSyncResult {
55
55
56
56
switch {
57
57
case strings .HasPrefix (lines [i ], " * " ): // New reference
58
- results = append (results , & mirrorSyncResult {
58
+ results = append (results , & syncResult {
59
59
refName : refName ,
60
60
oldCommitID : gitShortEmptySha ,
61
61
})
62
62
case strings .HasPrefix (lines [i ], " - " ): // Delete reference
63
- results = append (results , & mirrorSyncResult {
63
+ results = append (results , & syncResult {
64
64
refName : refName ,
65
65
newCommitID : gitShortEmptySha ,
66
66
})
@@ -75,7 +75,7 @@ func parseRemoteUpdateOutput(output string) []*mirrorSyncResult {
75
75
log .Error (2 , "Expect two SHAs but not what found: %q" , lines [i ])
76
76
continue
77
77
}
78
- results = append (results , & mirrorSyncResult {
78
+ results = append (results , & syncResult {
79
79
refName : refName ,
80
80
oldCommitID : shas [0 ],
81
81
newCommitID : shas [1 ],
@@ -109,7 +109,7 @@ func sanitizeOutput(output, repoPath string) (string, error) {
109
109
}
110
110
111
111
// runSync returns true if sync finished without error.
112
- func runSync (m * models.Mirror ) ([]* mirrorSyncResult , bool ) {
112
+ func runSync (m * models.Mirror ) ([]* syncResult , bool ) {
113
113
repoPath := m .Repo .RepoPath ()
114
114
wikiPath := m .Repo .UncycloPath ()
115
115
timeout := time .Duration (setting .Git .Timeout .Mirror ) * time .Second
@@ -186,12 +186,12 @@ func runSync(m *models.Mirror) ([]*mirrorSyncResult, bool) {
186
186
return parseRemoteUpdateOutput (output ), true
187
187
}
188
188
189
- // MirrorUpdate checks and updates mirror repositories.
190
- func MirrorUpdate () {
191
- if ! models .TaskStartIfNotRunning (mirrorUpdate ) {
189
+ // Update checks and updates mirror repositories.
190
+ func Update () {
191
+ if ! models .TaskStartIfNotRunning (updateCronName ) {
192
192
return
193
193
}
194
- defer models .TaskStop (mirrorUpdate )
194
+ defer models .TaskStop (updateCronName )
195
195
196
196
log .Trace ("Doing: MirrorUpdate" )
197
197
@@ -202,7 +202,7 @@ func MirrorUpdate() {
202
202
return nil
203
203
}
204
204
205
- MirrorQueue .Add (m .RepoID )
205
+ Queue .Add (m .RepoID )
206
206
return nil
207
207
}); err != nil {
208
208
log .Error (4 , "MirrorUpdate: %v" , err )
@@ -213,9 +213,9 @@ func MirrorUpdate() {
213
213
// TODO: sync more mirrors at same time.
214
214
func SyncMirrors () {
215
215
// Start listening on new sync requests.
216
- for repoID := range MirrorQueue .Queue () {
216
+ for repoID := range Queue .Queue () {
217
217
log .Trace ("SyncMirrors [repo_id: %v]" , repoID )
218
- MirrorQueue .Remove (repoID )
218
+ Queue .Remove (repoID )
219
219
220
220
m , err := models .GetMirrorByRepoID (com .StrTo (repoID ).MustInt64 ())
221
221
if err != nil {
@@ -253,15 +253,15 @@ func SyncMirrors() {
253
253
254
254
// Create reference
255
255
if result .oldCommitID == gitShortEmptySha {
256
- if err = MirrorSyncCreateAction (m .Repo , result .refName ); err != nil {
256
+ if err = SyncCreateAction (m .Repo , result .refName ); err != nil {
257
257
log .Error (2 , "MirrorSyncCreateAction [repo_id: %d]: %v" , m .RepoID , err )
258
258
}
259
259
continue
260
260
}
261
261
262
262
// Delete reference
263
263
if result .newCommitID == gitShortEmptySha {
264
- if err = MirrorSyncDeleteAction (m .Repo , result .refName ); err != nil {
264
+ if err = SyncDeleteAction (m .Repo , result .refName ); err != nil {
265
265
log .Error (2 , "MirrorSyncDeleteAction [repo_id: %d]: %v" , m .RepoID , err )
266
266
}
267
267
continue
@@ -283,7 +283,7 @@ func SyncMirrors() {
283
283
log .Error (2 , "CommitsBetweenIDs [repo_id: %d, new_commit_id: %s, old_commit_id: %s]: %v" , m .RepoID , newCommitID , oldCommitID , err )
284
284
continue
285
285
}
286
- if err = MirrorSyncPushAction (m .Repo , MirrorSyncPushActionOptions {
286
+ if err = SyncPushAction (m .Repo , SyncPushActionOptions {
287
287
RefName : result .refName ,
288
288
OldCommitID : oldCommitID ,
289
289
NewCommitID : newCommitID ,
0 commit comments