diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-09-06 04:20:09 +0200 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-09-06 04:20:09 +0200 |
commit | c03d75fbd51174d0e7ffdbaf9e9e253438d06cf7 (patch) | |
tree | a54e9fdfb6ff96baf7010d7fd5049a05a16644e2 /modules/repofiles | |
parent | feat: highlight issue references with : (#8101) (diff) | |
download | forgejo-c03d75fbd51174d0e7ffdbaf9e9e253438d06cf7.tar.xz forgejo-c03d75fbd51174d0e7ffdbaf9e9e253438d06cf7.zip |
Move git diff codes from models to services/gitdiff (#7889)
* move git diff codes from models to services/gitdiff
* fix template
* fix test
* fix template
Diffstat (limited to 'modules/repofiles')
-rw-r--r-- | modules/repofiles/diff.go | 3 | ||||
-rw-r--r-- | modules/repofiles/diff_test.go | 9 | ||||
-rw-r--r-- | modules/repofiles/temp_repo.go | 5 |
3 files changed, 10 insertions, 7 deletions
diff --git a/modules/repofiles/diff.go b/modules/repofiles/diff.go index 3b5de5fa6f..c98bbc7684 100644 --- a/modules/repofiles/diff.go +++ b/modules/repofiles/diff.go @@ -8,10 +8,11 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/services/gitdiff" ) // GetDiffPreview produces and returns diff result of a file which is not yet committed. -func GetDiffPreview(repo *models.Repository, branch, treePath, content string) (*models.Diff, error) { +func GetDiffPreview(repo *models.Repository, branch, treePath, content string) (*gitdiff.Diff, error) { if branch == "" { branch = repo.DefaultBranch } diff --git a/modules/repofiles/diff_test.go b/modules/repofiles/diff_test.go index bc7d4ebad6..de5ed1d754 100644 --- a/modules/repofiles/diff_test.go +++ b/modules/repofiles/diff_test.go @@ -9,6 +9,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/test" + "code.gitea.io/gitea/services/gitdiff" "github.com/stretchr/testify/assert" ) @@ -25,10 +26,10 @@ func TestGetDiffPreview(t *testing.T) { treePath := "README.md" content := "# repo1\n\nDescription for repo1\nthis is a new line" - expectedDiff := &models.Diff{ + expectedDiff := &gitdiff.Diff{ TotalAddition: 2, TotalDeletion: 1, - Files: []*models.DiffFile{ + Files: []*gitdiff.DiffFile{ { Name: "README.md", OldName: "README.md", @@ -42,10 +43,10 @@ func TestGetDiffPreview(t *testing.T) { IsLFSFile: false, IsRenamed: false, IsSubmodule: false, - Sections: []*models.DiffSection{ + Sections: []*gitdiff.DiffSection{ { Name: "", - Lines: []*models.DiffLine{ + Lines: []*gitdiff.DiffLine{ { LeftIdx: 0, RightIdx: 0, diff --git a/modules/repofiles/temp_repo.go b/modules/repofiles/temp_repo.go index d640ba80b0..f791c3cb96 100644 --- a/modules/repofiles/temp_repo.go +++ b/modules/repofiles/temp_repo.go @@ -20,6 +20,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/services/gitdiff" ) // TemporaryUploadRepository is a type to wrap our upload repositories as a shallow clone @@ -290,7 +291,7 @@ func (t *TemporaryUploadRepository) Push(doer *models.User, commitHash string, b } // DiffIndex returns a Diff of the current index to the head -func (t *TemporaryUploadRepository) DiffIndex() (diff *models.Diff, err error) { +func (t *TemporaryUploadRepository) DiffIndex() (diff *gitdiff.Diff, err error) { timeout := 5 * time.Minute ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() @@ -313,7 +314,7 @@ func (t *TemporaryUploadRepository) DiffIndex() (diff *models.Diff, err error) { pid := process.GetManager().Add(fmt.Sprintf("diffIndex [repo_path: %s]", t.repo.RepoPath()), cmd) defer process.GetManager().Remove(pid) - diff, err = models.ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, stdout) + diff, err = gitdiff.ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, stdout) if err != nil { return nil, fmt.Errorf("ParsePatch: %v", err) } |