diff options
author | vnkmpf <tz@zztt.eu> | 2021-02-13 05:35:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-13 05:35:43 +0100 |
commit | 487f2ee41cb06f0173b8bf12bd6a78408c75fabf (patch) | |
tree | ac62859884ed23f05d6e15bbc25bea6f0b374554 /services/gitdiff | |
parent | a3cc842e15eb5ed42c3125410d9c774314a286a5 (diff) | |
download | gitea-487f2ee41cb06f0173b8bf12bd6a78408c75fabf.tar.gz gitea-487f2ee41cb06f0173b8bf12bd6a78408c75fabf.zip |
Whitespace in commits (#14650)
* Add whitespace to commit view
* Add whitespace to /compare/a...b
* Move repeated whitespaceFlags to gitdiff
* Add whitespace for wiki pages
Diffstat (limited to 'services/gitdiff')
-rw-r--r-- | services/gitdiff/gitdiff.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index 81b92f7168..d706dc99c9 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -967,7 +967,13 @@ func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID // GetDiffCommit builds a Diff representing the given commitID. func GetDiffCommit(repoPath, commitID string, maxLines, maxLineCharacters, maxFiles int) (*Diff, error) { - return GetDiffRange(repoPath, "", commitID, maxLines, maxLineCharacters, maxFiles) + return GetDiffRangeWithWhitespaceBehavior(repoPath, "", commitID, maxLines, maxLineCharacters, maxFiles, "") +} + +// GetDiffCommitWithWhitespaceBehavior builds a Diff representing the given commitID. +// The whitespaceBehavior is either an empty string or a git flag +func GetDiffCommitWithWhitespaceBehavior(repoPath, commitID string, maxLines, maxLineCharacters, maxFiles int, whitespaceBehavior string) (*Diff, error) { + return GetDiffRangeWithWhitespaceBehavior(repoPath, "", commitID, maxLines, maxLineCharacters, maxFiles, whitespaceBehavior) } // CommentAsDiff returns c.Patch as *Diff @@ -995,3 +1001,14 @@ func CommentMustAsDiff(c *models.Comment) *Diff { } return diff } + +// GetWhitespaceFlag returns git diff flag for treating whitespaces +func GetWhitespaceFlag(whiteSpaceBehavior string) string { + whitespaceFlags := map[string]string{ + "ignore-all": "-w", + "ignore-change": "-b", + "ignore-eol": "--ignore-space-at-eol", + "": ""} + + return whitespaceFlags[whiteSpaceBehavior] +} |