mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-06 11:24:38 +00:00
enhance!: raise minimum git version to 2.34 (#39565)
Raise the minimum git version to 2.34, the version in Ubuntu 22.04, Debian 12 and RHEL 8 ship newer, and remove the fallbacks it makes obsolete. - Always enable AGit - Use `diff --skip-to` and `apply -3` unconditionally - Set the default branch of new repos and wikis via `git init --initial-branch` - Detect rebase conflicts via `REBASE_HEAD`
This commit is contained in:
@@ -702,8 +702,8 @@ const cmdDiffHead = "diff --git "
|
||||
var defaultDiffLineBufferSize = 8 * 1024
|
||||
|
||||
// ParsePatch builds a Diff object by parsing git diff output
|
||||
func ParsePatch(ctx context.Context, maxLines, maxLineCharacters, maxFiles int, reader io.Reader, skipToFile string) (_ *Diff, retErr error) {
|
||||
log.Debug("ParsePatch(%d, %d, %d, ..., %s)", maxLines, maxLineCharacters, maxFiles, skipToFile)
|
||||
func ParsePatch(ctx context.Context, maxLines, maxLineCharacters, maxFiles int, reader io.Reader) (_ *Diff, retErr error) {
|
||||
log.Debug("ParsePatch(%d, %d, %d, ...)", maxLines, maxLineCharacters, maxFiles)
|
||||
|
||||
diff := &Diff{Files: make([]*DiffFile, 0)}
|
||||
readerSize := max(maxLineCharacters, defaultDiffLineBufferSize)
|
||||
@@ -714,9 +714,8 @@ func ParsePatch(ctx context.Context, maxLines, maxLineCharacters, maxFiles int,
|
||||
return diff, util.Iif(err == io.EOF, nil, err)
|
||||
}
|
||||
|
||||
skipping := skipToFile != ""
|
||||
for {
|
||||
nextLine, err := diff.parseOneDiffFile(ctx, maxLines, maxLineCharacters, maxFiles, &skipping, input, skipToFile, line)
|
||||
nextLine, err := diff.parseOneDiffFile(ctx, maxLines, maxLineCharacters, maxFiles, input, line)
|
||||
if nextLine == "" || err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
@@ -729,7 +728,7 @@ func ParsePatch(ctx context.Context, maxLines, maxLineCharacters, maxFiles int,
|
||||
return diff, nil
|
||||
}
|
||||
|
||||
func (diff *Diff) parseOneDiffFile(ctx context.Context, maxLines, maxLineCharacters, maxFiles int, skipping *bool, input *bufio.Reader, skipToFile, startLine string) (nextLine string, err error) {
|
||||
func (diff *Diff) parseOneDiffFile(ctx context.Context, maxLines, maxLineCharacters, maxFiles int, input *bufio.Reader, startLine string) (nextLine string, err error) {
|
||||
line := startLine
|
||||
|
||||
extractGitDiffHead := func(s, p string) string {
|
||||
@@ -751,13 +750,6 @@ func (diff *Diff) parseOneDiffFile(ctx context.Context, maxLines, maxLineCharact
|
||||
}
|
||||
|
||||
curFile := createDiffFile(line)
|
||||
if *skipping {
|
||||
if curFile.Name != skipToFile {
|
||||
return skipToNextDiffHead(input)
|
||||
}
|
||||
*skipping = false
|
||||
}
|
||||
|
||||
diff.Files = append(diff.Files, curFile)
|
||||
|
||||
// 2. It is followed by one or more extended header lines:
|
||||
@@ -962,18 +954,6 @@ func (diff *Diff) postProcessFiles() {
|
||||
}
|
||||
}
|
||||
|
||||
func skipToNextDiffHead(input *bufio.Reader) (line string, err error) {
|
||||
for {
|
||||
lineBytes, _, err := readGitDiffLineWithDiscard(input)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if bytes.HasPrefix(lineBytes, []byte(cmdDiffHead)) {
|
||||
return string(lineBytes), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func newDiffSectionForDiffFile(curFile *DiffFile) *DiffSection {
|
||||
return &DiffSection{
|
||||
language: &curFile.language,
|
||||
@@ -1347,13 +1327,8 @@ func getDiffBasic(ctx context.Context, gitRepo *git.Repository, opts *DiffOption
|
||||
AddArguments(opts.WhitespaceBehavior...).
|
||||
AddOptionFormat("--find-renames=%s", setting.Git.DiffRenameSimilarityThreshold)
|
||||
|
||||
// In git 2.31, git diff learned --skip-to which we can use to shortcut skip to file
|
||||
// so if we are using at least this version of git we don't have to tell ParsePatch to do
|
||||
// the skipping for us
|
||||
parsePatchSkipToFile := opts.SkipTo
|
||||
if opts.SkipTo != "" && git.DefaultFeatures().CheckVersionAtLeast("2.31") {
|
||||
if opts.SkipTo != "" {
|
||||
cmdDiff.AddOptionFormat("--skip-to=%s", opts.SkipTo)
|
||||
parsePatchSkipToFile = ""
|
||||
}
|
||||
|
||||
cmdDiff.AddDynamicArguments(beforeCommitID.String(), opts.AfterCommitID)
|
||||
@@ -1372,7 +1347,7 @@ func getDiffBasic(ctx context.Context, gitRepo *git.Repository, opts *DiffOption
|
||||
}
|
||||
}()
|
||||
|
||||
diff, err := ParsePatch(cmdCtx, opts.MaxLines, opts.MaxLineCharacters, opts.MaxFiles, reader, parsePatchSkipToFile)
|
||||
diff, err := ParsePatch(cmdCtx, opts.MaxLines, opts.MaxLineCharacters, opts.MaxFiles, reader)
|
||||
// Ensure the git process is killed if it didn't exit already
|
||||
cmdCancel()
|
||||
if err != nil {
|
||||
@@ -1605,7 +1580,7 @@ func SyncUserSpecificDiff(ctx context.Context, userID int64, pull *issues_model.
|
||||
// CommentAsDiff returns c.Patch as *Diff
|
||||
func CommentAsDiff(ctx context.Context, c *issues_model.Comment) (*Diff, error) {
|
||||
diff, err := ParsePatch(ctx, setting.Git.MaxGitDiffLines,
|
||||
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(c.Patch), "")
|
||||
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(c.Patch))
|
||||
if err != nil {
|
||||
log.Error("Unable to parse patch: %v", err)
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user