mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Use git diff-tree
for DiffFileTree
on diff pages (#33514)
Modify Diff View FileTree to show all files ## Changes * removes Show Status button on diff * uses `git diff-tree` to generate the file tree for the diff * doesn't reload the diff tree each time we load more files in the preview * selecting and unloaded file will keep loading until that file is loaded * removes `DiffFileList.vue` and "Show Stats" in diff options ## Open Questions * selecting and unloaded file will keep loading until that file is loaded. Is this behaviour okay? It matches what github does. ### Demo In this demo I set `git.MAX_GIT_DIFF_FILES=1` in my `app.ini` to demonstrate a worst case example. In most cases the behaviour isn't nearly as jarring as we load a bunch of files at a time. https://github.com/user-attachments/assets/72f29663-d6fc-472d-94fa-7fb5950c2836 --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -761,6 +761,7 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
|
||||
|
||||
var methodWithError string
|
||||
var diff *gitdiff.Diff
|
||||
shouldGetUserSpecificDiff := false
|
||||
|
||||
// if we're not logged in or only a single commit (or commit range) is shown we
|
||||
// have to load only the diff and not get the viewed information
|
||||
@@ -772,6 +773,7 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
|
||||
} else {
|
||||
diff, err = gitdiff.SyncAndGetUserSpecificDiff(ctx, ctx.Doer.ID, pull, gitRepo, diffOptions, files...)
|
||||
methodWithError = "SyncAndGetUserSpecificDiff"
|
||||
shouldGetUserSpecificDiff = true
|
||||
}
|
||||
if err != nil {
|
||||
ctx.ServerError(methodWithError, err)
|
||||
@@ -816,6 +818,27 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
|
||||
}
|
||||
}
|
||||
|
||||
if !fileOnly {
|
||||
// note: use mergeBase is set to false because we already have the merge base from the pull request info
|
||||
diffTree, err := gitdiff.GetDiffTree(ctx, gitRepo, false, pull.MergeBase, headCommitID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetDiffTree", err)
|
||||
return
|
||||
}
|
||||
|
||||
filesViewedState := make(map[string]pull_model.ViewedState)
|
||||
if shouldGetUserSpecificDiff {
|
||||
// This sort of sucks because we already fetch this when getting the diff
|
||||
review, err := pull_model.GetNewestReviewState(ctx, ctx.Doer.ID, issue.ID)
|
||||
if err == nil && review != nil && review.UpdatedFiles != nil {
|
||||
// If there wasn't an error and we have a review with updated files, use that
|
||||
filesViewedState = review.UpdatedFiles
|
||||
}
|
||||
}
|
||||
|
||||
ctx.PageData["DiffFiles"] = transformDiffTreeForUI(diffTree, filesViewedState)
|
||||
}
|
||||
|
||||
ctx.Data["Diff"] = diff
|
||||
ctx.Data["DiffNotAvailable"] = diff.NumFiles == 0
|
||||
|
||||
|
Reference in New Issue
Block a user