Skip to content

Commit 77ac184

Browse files
committed
Improve the implementation of update repository files and replace wiki implementation
1 parent 1995e2c commit 77ac184

File tree

9 files changed

+337
-412
lines changed

9 files changed

+337
-412
lines changed

modules/git/attribute/attribute.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ func (attrs *Attributes) GetLinguistLanguage() optional.Option[string] {
8888
return attrs.Get(LinguistLanguage).ToString()
8989
}
9090

91+
func (attrs *Attributes) MatchLFS() bool {
92+
return attrs.Get(Filter).ToString().Value() == "lfs"
93+
}
94+
9195
func (attrs *Attributes) GetGitlabLanguage() optional.Option[string] {
9296
attrStr := attrs.Get(GitlabLanguage).ToString()
9397
if attrStr.Has() {

routers/api/v1/repo/file.go

Lines changed: 32 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -485,26 +485,18 @@ func ChangeFiles(ctx *context.APIContext) {
485485
Message: apiOpts.Message,
486486
OldBranch: apiOpts.BranchName,
487487
NewBranch: apiOpts.NewBranchName,
488-
Committer: &files_service.IdentityOptions{
489-
GitUserName: apiOpts.Committer.Name,
490-
GitUserEmail: apiOpts.Committer.Email,
488+
Committer: &git.Signature{
489+
Name: apiOpts.Committer.Name,
490+
Email: apiOpts.Committer.Email,
491+
When: apiOpts.Dates.Committer,
491492
},
492-
Author: &files_service.IdentityOptions{
493-
GitUserName: apiOpts.Author.Name,
494-
GitUserEmail: apiOpts.Author.Email,
495-
},
496-
Dates: &files_service.CommitDateOptions{
497-
Author: apiOpts.Dates.Author,
498-
Committer: apiOpts.Dates.Committer,
493+
Author: &git.Signature{
494+
Name: apiOpts.Author.Name,
495+
Email: apiOpts.Author.Email,
496+
When: apiOpts.Dates.Author,
499497
},
500498
Signoff: apiOpts.Signoff,
501499
}
502-
if opts.Dates.Author.IsZero() {
503-
opts.Dates.Author = time.Now()
504-
}
505-
if opts.Dates.Committer.IsZero() {
506-
opts.Dates.Committer = time.Now()
507-
}
508500

509501
if opts.Message == "" {
510502
opts.Message = changeFilesCommitMessage(ctx, files)
@@ -582,26 +574,18 @@ func CreateFile(ctx *context.APIContext) {
582574
Message: apiOpts.Message,
583575
OldBranch: apiOpts.BranchName,
584576
NewBranch: apiOpts.NewBranchName,
585-
Committer: &files_service.IdentityOptions{
586-
GitUserName: apiOpts.Committer.Name,
587-
GitUserEmail: apiOpts.Committer.Email,
577+
Committer: &git.Signature{
578+
Name: apiOpts.Committer.Name,
579+
Email: apiOpts.Committer.Email,
580+
When: apiOpts.Dates.Committer,
588581
},
589-
Author: &files_service.IdentityOptions{
590-
GitUserName: apiOpts.Author.Name,
591-
GitUserEmail: apiOpts.Author.Email,
592-
},
593-
Dates: &files_service.CommitDateOptions{
594-
Author: apiOpts.Dates.Author,
595-
Committer: apiOpts.Dates.Committer,
582+
Author: &git.Signature{
583+
Name: apiOpts.Author.Name,
584+
Email: apiOpts.Author.Email,
585+
When: apiOpts.Dates.Author,
596586
},
597587
Signoff: apiOpts.Signoff,
598588
}
599-
if opts.Dates.Author.IsZero() {
600-
opts.Dates.Author = time.Now()
601-
}
602-
if opts.Dates.Committer.IsZero() {
603-
opts.Dates.Committer = time.Now()
604-
}
605589

606590
if opts.Message == "" {
607591
opts.Message = changeFilesCommitMessage(ctx, opts.Files)
@@ -685,26 +669,18 @@ func UpdateFile(ctx *context.APIContext) {
685669
Message: apiOpts.Message,
686670
OldBranch: apiOpts.BranchName,
687671
NewBranch: apiOpts.NewBranchName,
688-
Committer: &files_service.IdentityOptions{
689-
GitUserName: apiOpts.Committer.Name,
690-
GitUserEmail: apiOpts.Committer.Email,
672+
Committer: &git.Signature{
673+
Name: apiOpts.Committer.Name,
674+
Email: apiOpts.Committer.Email,
675+
When: apiOpts.Dates.Committer,
691676
},
692-
Author: &files_service.IdentityOptions{
693-
GitUserName: apiOpts.Author.Name,
694-
GitUserEmail: apiOpts.Author.Email,
695-
},
696-
Dates: &files_service.CommitDateOptions{
697-
Author: apiOpts.Dates.Author,
698-
Committer: apiOpts.Dates.Committer,
677+
Author: &git.Signature{
678+
Name: apiOpts.Author.Name,
679+
Email: apiOpts.Author.Email,
680+
When: apiOpts.Dates.Author,
699681
},
700682
Signoff: apiOpts.Signoff,
701683
}
702-
if opts.Dates.Author.IsZero() {
703-
opts.Dates.Author = time.Now()
704-
}
705-
if opts.Dates.Committer.IsZero() {
706-
opts.Dates.Committer = time.Now()
707-
}
708684

709685
if opts.Message == "" {
710686
opts.Message = changeFilesCommitMessage(ctx, opts.Files)
@@ -844,26 +820,18 @@ func DeleteFile(ctx *context.APIContext) {
844820
Message: apiOpts.Message,
845821
OldBranch: apiOpts.BranchName,
846822
NewBranch: apiOpts.NewBranchName,
847-
Committer: &files_service.IdentityOptions{
848-
GitUserName: apiOpts.Committer.Name,
849-
GitUserEmail: apiOpts.Committer.Email,
823+
Committer: &git.Signature{
824+
Name: apiOpts.Committer.Name,
825+
Email: apiOpts.Committer.Email,
826+
When: apiOpts.Dates.Committer,
850827
},
851-
Author: &files_service.IdentityOptions{
852-
GitUserName: apiOpts.Author.Name,
853-
GitUserEmail: apiOpts.Author.Email,
854-
},
855-
Dates: &files_service.CommitDateOptions{
856-
Author: apiOpts.Dates.Author,
857-
Committer: apiOpts.Dates.Committer,
828+
Author: &git.Signature{
829+
Name: apiOpts.Author.Name,
830+
Email: apiOpts.Author.Email,
831+
When: apiOpts.Dates.Author,
858832
},
859833
Signoff: apiOpts.Signoff,
860834
}
861-
if opts.Dates.Author.IsZero() {
862-
opts.Dates.Author = time.Now()
863-
}
864-
if opts.Dates.Committer.IsZero() {
865-
opts.Dates.Committer = time.Now()
866-
}
867835

868836
if opts.Message == "" {
869837
opts.Message = changeFilesCommitMessage(ctx, opts.Files)

routers/web/repo/editor.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,15 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b
296296
ContentReader: strings.NewReader(strings.ReplaceAll(form.Content, "\r", "")),
297297
},
298298
},
299-
Signoff: form.Signoff,
300-
Author: gitCommitter,
301-
Committer: gitCommitter,
299+
Signoff: form.Signoff,
300+
Author: &git.Signature{
301+
Name: gitCommitter.GitUserName,
302+
Email: gitCommitter.GitUserEmail,
303+
},
304+
Committer: &git.Signature{
305+
Name: gitCommitter.GitUserName,
306+
Email: gitCommitter.GitUserEmail,
307+
},
302308
}); err != nil {
303309
// This is where we handle all the errors thrown by files_service.ChangeRepoFiles
304310
if git.IsErrNotExist(err) {
@@ -512,10 +518,16 @@ func DeleteFilePost(ctx *context.Context) {
512518
TreePath: ctx.Repo.TreePath,
513519
},
514520
},
515-
Message: message,
516-
Signoff: form.Signoff,
517-
Author: gitCommitter,
518-
Committer: gitCommitter,
521+
Message: message,
522+
Signoff: form.Signoff,
523+
Author: &git.Signature{
524+
Name: gitCommitter.GitUserName,
525+
Email: gitCommitter.GitUserEmail,
526+
},
527+
Committer: &git.Signature{
528+
Name: gitCommitter.GitUserName,
529+
Email: gitCommitter.GitUserEmail,
530+
},
519531
}); err != nil {
520532
// This is where we handle all the errors thrown by repofiles.DeleteRepoFile
521533
if git.IsErrNotExist(err) || files_service.IsErrRepoFileDoesNotExist(err) {

0 commit comments

Comments
 (0)