mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-02-23 03:45:47 -05:00
Fix parentCommit invalid memory address or nil pointer dereference. (#33204)
When the parent Commit does not exist on gitea, an error will be reported when opening the Commit details page: invalid memory address or nil pointer dereference.   (cherry picked from commit b7614e2d2f2af246e33b8bd6a38ecfd1babc9ecc)
This commit is contained in:
parent
06dfcc1a45
commit
ae51a90181
2 changed files with 12 additions and 4 deletions
|
@ -64,7 +64,10 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff
|
|||
} else if commit.ParentCount() == 0 {
|
||||
cmd.AddArguments("show").AddDynamicArguments(endCommit).AddDashesAndList(files...)
|
||||
} else {
|
||||
c, _ := commit.Parent(0)
|
||||
c, err := commit.Parent(0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmd.AddArguments("diff", "-M").AddDynamicArguments(c.ID.String(), endCommit).AddDashesAndList(files...)
|
||||
}
|
||||
case RawDiffPatch:
|
||||
|
@ -74,7 +77,10 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff
|
|||
} else if commit.ParentCount() == 0 {
|
||||
cmd.AddArguments("format-patch", "--no-signature", "--stdout", "--root").AddDynamicArguments(endCommit).AddDashesAndList(files...)
|
||||
} else {
|
||||
c, _ := commit.Parent(0)
|
||||
c, err := commit.Parent(0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
query := fmt.Sprintf("%s...%s", endCommit, c.ID.String())
|
||||
cmd.AddArguments("format-patch", "--no-signature", "--stdout").AddDynamicArguments(query).AddDashesAndList(files...)
|
||||
}
|
||||
|
|
|
@ -1117,7 +1117,10 @@ func GetDiff(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, fi
|
|||
} else {
|
||||
actualBeforeCommitID := opts.BeforeCommitID
|
||||
if len(actualBeforeCommitID) == 0 {
|
||||
parentCommit, _ := commit.Parent(0)
|
||||
parentCommit, err := commit.Parent(0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
actualBeforeCommitID = parentCommit.ID.String()
|
||||
}
|
||||
|
||||
|
@ -1126,7 +1129,6 @@ func GetDiff(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, fi
|
|||
AddDynamicArguments(actualBeforeCommitID, opts.AfterCommitID)
|
||||
opts.BeforeCommitID = actualBeforeCommitID
|
||||
|
||||
var err error
|
||||
beforeCommit, err = gitRepo.GetCommit(opts.BeforeCommitID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Add table
Reference in a new issue