Skip to content

Commit 5feb0dd

Browse files
committed
Update comments
1 parent 8d85006 commit 5feb0dd

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

services/repository/adopt.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,12 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
8888
return nil, fmt.Errorf("getRepositoryByID: %w", err)
8989
}
9090

91-
// 3 - adopt the repository from disk
91+
// 2 - adopt the repository from disk
9292
if err = adoptRepository(ctx, repo, opts.DefaultBranch); err != nil {
9393
return nil, fmt.Errorf("adoptRepository: %w", err)
9494
}
9595

96+
// 3 - Update the git repository
9697
if err = updateGitRepoAfterCreate(ctx, repo); err != nil {
9798
return nil, fmt.Errorf("updateGitRepoAfterCreate: %w", err)
9899
}

services/repository/create.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
272272
return repo, nil
273273
}
274274

275+
// 2 - check whether the repository with the same storage exists
275276
var isExist bool
276277
isExist, err = gitrepo.IsRepositoryExist(ctx, repo)
277278
if err != nil {
@@ -288,29 +289,24 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
288289
return nil, err
289290
}
290291

292+
// 3 - init git repository in storage
291293
if err = initRepository(ctx, doer, repo, opts); err != nil {
292294
return nil, fmt.Errorf("initRepository: %w", err)
293295
}
294296

295-
// Initialize Issue Labels if selected
297+
// 4 - Initialize Issue Labels if selected
296298
if len(opts.IssueLabels) > 0 {
297299
if err = repo_module.InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil {
298300
return nil, fmt.Errorf("InitializeLabels: %w", err)
299301
}
300302
}
301303

304+
// 5 - Update the git repository
302305
if err = updateGitRepoAfterCreate(ctx, repo); err != nil {
303306
return nil, fmt.Errorf("updateGitRepoAfterCreate: %w", err)
304307
}
305308

306-
if needsUpdateStatus {
307-
repo.Status = repo_model.RepositoryReady
308-
if err = repo_model.UpdateRepositoryCols(ctx, repo, "status"); err != nil {
309-
return nil, fmt.Errorf("UpdateRepositoryCols: %w", err)
310-
}
311-
}
312-
313-
// update licenses
309+
// 6 - update licenses
314310
var licenses []string
315311
if len(opts.License) > 0 {
316312
licenses = append(licenses, opts.License)
@@ -326,6 +322,14 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
326322
}
327323
}
328324

325+
// 7 - update repository status to be ready
326+
if needsUpdateStatus {
327+
repo.Status = repo_model.RepositoryReady
328+
if err = repo_model.UpdateRepositoryCols(ctx, repo, "status"); err != nil {
329+
return nil, fmt.Errorf("UpdateRepositoryCols: %w", err)
330+
}
331+
}
332+
329333
return repo, nil
330334
}
331335

services/repository/fork.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
128128
}
129129
}()
130130

131+
// 2 - check whether the repository with the same storage exists
131132
var isExist bool
132133
isExist, err = gitrepo.IsRepositoryExist(ctx, repo)
133134
if err != nil {
@@ -144,7 +145,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
144145
return nil, err
145146
}
146147

147-
// 2 - Clone the repository
148+
// 3 - Clone the repository
148149
cloneCmd := git.NewCommand("clone", "--bare")
149150
if opts.SingleBranch != "" {
150151
cloneCmd.AddArguments("--single-branch", "--branch").AddDynamicArguments(opts.SingleBranch)
@@ -156,17 +157,17 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
156157
return nil, fmt.Errorf("git clone: %w", err)
157158
}
158159

159-
// 3 - Update the repository
160+
// 4 - Update the git repository
160161
if err = updateGitRepoAfterCreate(ctx, repo); err != nil {
161162
return nil, fmt.Errorf("updateGitRepoAfterCreate: %w", err)
162163
}
163164

164-
// 4 - Create hooks
165+
// 5 - Create hooks
165166
if err = gitrepo.CreateDelegateHooks(ctx, repo); err != nil {
166167
return nil, fmt.Errorf("createDelegateHooks: %w", err)
167168
}
168169

169-
// 5 - Sync the repository branches and tags
170+
// 6 - Sync the repository branches and tags
170171
var gitRepo *git.Repository
171172
gitRepo, err = gitrepo.OpenRepository(ctx, repo)
172173
if err != nil {
@@ -181,7 +182,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
181182
return nil, fmt.Errorf("Sync releases from git tags failed: %v", err)
182183
}
183184

184-
// 6 - Update the repository
185+
// 7 - Update the repository
185186
// even if below operations failed, it could be ignored. And they will be retried
186187
if err = repo_module.UpdateRepoSize(ctx, repo); err != nil {
187188
log.Error("Failed to update size for repository: %v", err)
@@ -195,7 +196,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
195196
return nil, err
196197
}
197198

198-
// 7 - update repository status to be ready
199+
// 8 - update repository status to be ready
199200
repo.Status = repo_model.RepositoryReady
200201
if err = repo_model.UpdateRepositoryCols(ctx, repo, "status"); err != nil {
201202
return nil, fmt.Errorf("UpdateRepositoryCols: %w", err)

services/repository/template.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,19 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
121121
return nil, err
122122
}
123123

124-
// 3 - Generate the git repository in storage
125-
// Init git bare new repository.
124+
// 3 -Init git bare new repository.
126125
if err = git.InitRepository(ctx, generateRepo.RepoPath(), true, generateRepo.ObjectFormatName); err != nil {
127126
return nil, fmt.Errorf("git.InitRepository: %w", err)
128127
} else if err = gitrepo.CreateDelegateHooks(ctx, generateRepo); err != nil {
129128
return nil, fmt.Errorf("createDelegateHooks: %w", err)
130129
}
131130

131+
// 4 - Update the git repository
132132
if err = updateGitRepoAfterCreate(ctx, generateRepo); err != nil {
133133
return nil, fmt.Errorf("updateGitRepoAfterCreate: %w", err)
134134
}
135135

136+
// 5 - generate the repository contents according to the template
136137
// Git Content
137138
if opts.GitContent && !templateRepo.IsEmpty {
138139
if err = GenerateGitContent(ctx, templateRepo, generateRepo); err != nil {
@@ -181,7 +182,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
181182
}
182183
}
183184

184-
// 4 - update repository status to be ready
185+
// 6 - update repository status to be ready
185186
generateRepo.Status = repo_model.RepositoryReady
186187
if err = repo_model.UpdateRepositoryCols(ctx, generateRepo, "status"); err != nil {
187188
return nil, fmt.Errorf("UpdateRepositoryCols: %w", err)

0 commit comments

Comments
 (0)