diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index aeecc13f4efec..2426a6b3c2b69 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -521,7 +521,7 @@ func CreatePullRequest(ctx *context.APIContext) { BaseBranch: compareResult.BaseRef.ShortName(), HeadRepo: compareResult.HeadRepo, BaseRepo: repo, - MergeBase: compareResult.MergeBase, + MergeBase: compareResult.CompareBase, Type: issues_model.PullRequestGitea, } @@ -1569,7 +1569,7 @@ func GetPullRequestFiles(ctx *context.APIContext) { return } - startCommitID := compareInfo.MergeBase + startCommitID := compareInfo.CompareBase endCommitID := headCommitID maxLines := setting.Git.MaxGitDiffLines diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index c118f41381b37..84b51bba5f4f8 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -96,8 +96,6 @@ func Commits(ctx *context.Context) { } else { ctx.Data["CommitsTagsMap"] = commitsTagsMap } - ctx.Data["Username"] = ctx.Repo.Owner.Name - ctx.Data["Reponame"] = ctx.Repo.Repository.Name ctx.Data["CommitCount"] = commitsCount pager := context.NewPagination(commitsCount, pageSize, page, 5) @@ -163,9 +161,6 @@ func Graph(ctx *context.Context) { ctx.Data["AllRefs"] = gitRefs - ctx.Data["Username"] = ctx.Repo.Owner.Name - ctx.Data["Reponame"] = ctx.Repo.Repository.Name - divOnly := ctx.FormBool("div-only") queryParams := ctx.Req.URL.Query() queryParams.Del("div-only") @@ -209,8 +204,6 @@ func SearchCommits(ctx *context.Context) { if all { ctx.Data["All"] = true } - ctx.Data["Username"] = ctx.Repo.Owner.Name - ctx.Data["Reponame"] = ctx.Repo.Repository.Name ctx.HTML(http.StatusOK, tplCommits) } @@ -248,8 +241,6 @@ func FileHistory(ctx *context.Context) { return } - ctx.Data["Username"] = ctx.Repo.Owner.Name - ctx.Data["Reponame"] = ctx.Repo.Repository.Name ctx.Data["FileTreePath"] = ctx.Repo.TreePath ctx.Data["CommitCount"] = commitsCount @@ -321,7 +312,7 @@ func Diff(ctx *context.Context) { MaxLines: maxLines, MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters, MaxFiles: maxFiles, - WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)), + WhitespaceBehavior: gitdiff.GetWhitespaceFlag(GetWhitespaceBehavior(ctx)), }, files...) if err != nil { ctx.NotFound(err) @@ -346,8 +337,6 @@ func Diff(ctx *context.Context) { ctx.Data["CommitID"] = commitID ctx.Data["AfterCommitID"] = commitID - ctx.Data["Username"] = userName - ctx.Data["Reponame"] = repoName var parentCommit *git.Commit var parentCommitID string diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 174cb1be22261..83451843ceb92 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -190,8 +190,18 @@ func setCsvCompareContext(ctx *context.Context) { } } +type comparePageInfoType struct { + compareInfo *git_service.CompareInfo + nothingToCompare bool + allowCreatePull bool +} + +func newComparePageInfo() *comparePageInfoType { + return &comparePageInfoType{} +} + // parseCompareInfo parse compare info between two commit for preparing comparing references -func parseCompareInfo(ctx *context.Context) (*git_service.CompareInfo, error) { +func (cpi *comparePageInfoType) parseCompareInfo(ctx *context.Context) error { baseRepo := ctx.Repo.Repository fileOnly := ctx.FormBool("file-only") @@ -200,13 +210,13 @@ func parseCompareInfo(ctx *context.Context) (*git_service.CompareInfo, error) { // remove the check when we support compare with carets if compareReq.BaseOriRefSuffix != "" { - return nil, util.NewInvalidArgumentErrorf("unsupported comparison syntax: ref with suffix") + return util.NewInvalidArgumentErrorf("unsupported comparison syntax: ref with suffix") } // 2 get repository and owner for head headOwner, headRepo, err := common.GetHeadOwnerAndRepo(ctx, baseRepo, compareReq) if err != nil { - return nil, err + return err } // 3 permission check @@ -219,10 +229,10 @@ func parseCompareInfo(ctx *context.Context) (*git_service.CompareInfo, error) { // Assert ctx.Doer has permission to read headRepo's codes permHead, err := access_model.GetDoerRepoPermission(ctx, headRepo, ctx.Doer) if err != nil { - return nil, err + return err } if !permHead.CanRead(unit.TypeCode) { - return nil, util.NewNotExistErrorf("") // permission: no error message for end users + return util.NewNotExistErrorf("") // permission: no error message for end users } ctx.Data["CanWriteToHeadRepo"] = permHead.CanWrite(unit.TypeCode) } @@ -233,17 +243,16 @@ func parseCompareInfo(ctx *context.Context) (*git_service.CompareInfo, error) { baseRef := ctx.Repo.GitRepo.UnstableGuessRefByShortName(baseRefName) if baseRef == "" { - return nil, util.NewNotExistErrorf("no base ref: %s", baseRefName) + return util.NewNotExistErrorf("no base ref: %s", baseRefName) } headGitRepo, err := gitrepo.RepositoryFromRequestContextOrOpen(ctx, headRepo) if err != nil { - ctx.ServerError("OpenRepository", err) - return nil, err + return err } headRef := headGitRepo.UnstableGuessRefByShortName(headRefName) if headRef == "" { - return nil, util.NewNotExistErrorf("no head ref: %s", headRefName) + return util.NewNotExistErrorf("no head ref: %s", headRefName) } ctx.Data["BaseName"] = baseRepo.OwnerName @@ -268,7 +277,7 @@ func parseCompareInfo(ctx *context.Context) (*git_service.CompareInfo, error) { if baseRepo.IsFork { err = baseRepo.GetBaseRepo(ctx) if err != nil && !repo_model.IsErrRepoNotExist(err) { - return nil, err + return err } else if err == nil { rootRepo = baseRepo.BaseRepo } @@ -302,7 +311,7 @@ func parseCompareInfo(ctx *context.Context) (*git_service.CompareInfo, error) { if !fileOnly { branches, tags, err := getBranchesAndTagsForRepo(ctx, rootRepo) if err != nil { - return nil, err + return err } ctx.Data["RootRepoBranches"] = branches ctx.Data["RootRepoTags"] = tags @@ -325,7 +334,7 @@ func parseCompareInfo(ctx *context.Context) (*git_service.CompareInfo, error) { if !fileOnly { branches, tags, err := getBranchesAndTagsForRepo(ctx, ownForkRepo) if err != nil { - return nil, err + return err } ctx.Data["OwnForkRepoBranches"] = branches ctx.Data["OwnForkRepoTags"] = tags @@ -335,19 +344,14 @@ func parseCompareInfo(ctx *context.Context) (*git_service.CompareInfo, error) { compareInfo, err := git_service.GetCompareInfo(ctx, baseRepo, headRepo, headGitRepo, baseRef, headRef, compareReq.DirectComparison(), fileOnly) if err != nil { - return nil, err + return err } // Treat as pull request if both references are branches - allowCreatePullRequest := baseRef.IsBranch() && headRef.IsBranch() && permBase.CanReadIssuesOrPulls(true) - allowCreatePullRequest = allowCreatePullRequest && compareInfo.MergeBase != "" - ctx.Data["PageIsComparePull"] = allowCreatePullRequest - if compareReq.DirectComparison() { - ctx.Data["BeforeCommitID"] = compareInfo.BaseCommitID - } else { - ctx.Data["BeforeCommitID"] = compareInfo.MergeBase - } - return &compareInfo, nil + cpi.allowCreatePull = baseRef.IsBranch() && headRef.IsBranch() && permBase.CanReadIssuesOrPulls(true) + cpi.allowCreatePull = cpi.allowCreatePull && compareInfo.CompareBase != "" + cpi.compareInfo = &compareInfo + return nil } // autoTitleFromBranchName humanizes a branch name into a PR title. @@ -414,14 +418,17 @@ func prepareNewPullRequestTitleContent(ci *git_service.CompareInfo, commits []*g } // prepareCompareDiff renders compare diff page. TODO: need to refactor it and other "compare diff" related functions together -func prepareCompareDiff(ctx *context.Context, ci *git_service.CompareInfo, whitespaceBehavior gitcmd.TrustedCmdArgs) (nothingToCompare bool) { - if ci.MergeBase == "" { - return true +func (cpi *comparePageInfoType) prepareCompareDiff(ctx *context.Context, whitespaceBehavior gitcmd.TrustedCmdArgs) { + ci := cpi.compareInfo + if ci.CompareBase == "" { + cpi.nothingToCompare = true + return } repo := ctx.Repo.Repository headCommitID := ci.HeadCommitID ctx.Data["CommitRepoLink"] = ci.HeadRepo.Link() + ctx.Data["BeforeCommitID"] = ci.CompareBase ctx.Data["AfterCommitID"] = headCommitID // follow GitHub's behavior: autofill the form and expand @@ -431,26 +438,18 @@ func prepareCompareDiff(ctx *context.Context, ci *git_service.CompareInfo, white ctx.Data["TitleQuery"] = newPrFormTitle ctx.Data["BodyQuery"] = newPrFormBody - if (headCommitID == ci.MergeBase && !ci.DirectComparison()) || - headCommitID == ci.BaseCommitID { - ctx.Data["IsNothingToCompare"] = true - if unit, err := repo.GetUnit(ctx, unit.TypePullRequests); err == nil { - config := unit.PullRequestsConfig() - - if !config.AutodetectManualMerge { - ctx.Data["AllowEmptyPr"] = !ci.IsSameRef() - return ci.IsSameRef() - } + if headCommitID == ci.CompareBase { + config := repo.MustGetUnit(ctx, unit.TypePullRequests).PullRequestsConfig() + // if auto-detect manual merge, an empty PR will be closed immediately because it is already on base branch + supportEmptyPr := !config.AutodetectManualMerge + acrossRepoPr := !ci.IsSameRef() + ctx.Data["AllowEmptyPr"] = supportEmptyPr && acrossRepoPr - ctx.Data["AllowEmptyPr"] = false - } - return true + cpi.nothingToCompare = true + return } - beforeCommitID := ci.MergeBase - if ci.DirectComparison() { - beforeCommitID = ci.BaseCommitID - } + beforeCommitID := ci.CompareBase maxLines, maxFiles := setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffFiles files := ctx.FormStrings("files") @@ -473,12 +472,12 @@ func prepareCompareDiff(ctx *context.Context, ci *git_service.CompareInfo, white }, ctx.FormStrings("files")...) if err != nil { ctx.ServerError("GetDiff", err) - return false + return } diffShortStat, err := gitdiff.GetDiffShortStat(ctx, ci.HeadRepo, ci.HeadGitRepo, beforeCommitID, headCommitID) if err != nil { ctx.ServerError("GetDiffShortStat", err) - return false + return } ctx.Data["DiffShortStat"] = diffShortStat ctx.Data["Diff"] = diff @@ -493,7 +492,7 @@ func prepareCompareDiff(ctx *context.Context, ci *git_service.CompareInfo, white diffTree, err := gitdiff.GetDiffTree(ctx, ci.HeadGitRepo, false, beforeCommitID, headCommitID) if err != nil { ctx.ServerError("GetDiffTree", err) - return false + return } renderedIconPool := fileicon.NewRenderedIconPool() @@ -506,7 +505,7 @@ func prepareCompareDiff(ctx *context.Context, ci *git_service.CompareInfo, white headCommit, err := ci.HeadGitRepo.GetCommit(headCommitID) if err != nil { ctx.ServerError("GetCommit", err) - return false + return } baseGitRepo := ctx.Repo.GitRepo @@ -514,24 +513,20 @@ func prepareCompareDiff(ctx *context.Context, ci *git_service.CompareInfo, white beforeCommit, err := baseGitRepo.GetCommit(beforeCommitID) if err != nil { ctx.ServerError("GetCommit", err) - return false + return } commits, err := processGitCommits(ctx, ci.Commits) if err != nil { ctx.ServerError("processGitCommits", err) - return false + return } ctx.Data["Commits"] = commits ctx.Data["CommitCount"] = len(commits) ctx.Data["title"], ctx.Data["content"] = prepareNewPullRequestTitleContent(ci, commits, setting.Repository.PullRequest.DefaultTitleSource) - ctx.Data["Username"] = ci.HeadRepo.OwnerName - ctx.Data["Reponame"] = ci.HeadRepo.Name setCompareContext(ctx, beforeCommit, headCommit, ci.HeadRepo.OwnerName, repo.Name) - - return false } func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repository) (branches, tags []string, err error) { @@ -552,10 +547,8 @@ func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repositor // CompareDiff show different from one commit to another commit func CompareDiff(ctx *context.Context) { - ci, err := parseCompareInfo(ctx) - if ctx.Written() { - return - } + comparePageInfo := newComparePageInfo() + err := comparePageInfo.parseCompareInfo(ctx) if errors.Is(err, util.ErrNotExist) || errors.Is(err, util.ErrInvalidArgument) { ctx.NotFound(nil) return @@ -563,13 +556,13 @@ func CompareDiff(ctx *context.Context) { ctx.ServerError("ParseCompareInfo", err) return } - + ci := comparePageInfo.compareInfo ctx.Data["PageIsViewCode"] = true ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes ctx.Data["CompareInfo"] = ci // TODO: need to refactor "prepare compare" related functions together - nothingToCompare := prepareCompareDiff(ctx, ci, gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string))) + comparePageInfo.prepareCompareDiff(ctx, gitdiff.GetWhitespaceFlag(GetWhitespaceBehavior(ctx))) if ctx.Written() { return } @@ -601,21 +594,23 @@ func CompareDiff(ctx *context.Context) { return } - if ci.MergeBase != "" { - prepareCreatePullRequestPage(ctx, ci, nothingToCompare) + if ci.CompareBase != "" { + comparePageInfo.prepareCreatePullRequestPage(ctx) if ctx.Written() { return } } else { ctx.Flash.Error(ctx.Tr("repo.pulls.no_common_history"), true) - ctx.Data["PageIsComparePull"] = false ctx.Data["CommitCount"] = 0 } + ctx.Data["PageIsComparePull"] = comparePageInfo.allowCreatePull + ctx.Data["IsNothingToCompare"] = comparePageInfo.nothingToCompare ctx.HTML(http.StatusOK, tplCompare) } -func prepareCreatePullRequestPage(ctx *context.Context, ci *git_service.CompareInfo, nothingToCompare bool) { - if ctx.Data["PageIsComparePull"] == true { +func (cpi *comparePageInfoType) prepareCreatePullRequestPage(ctx *context.Context) { + ci := cpi.compareInfo + if cpi.allowCreatePull { pr, err := issues_model.GetUnmergedPullRequest(ctx, ci.HeadRepo.ID, ctx.Repo.Repository.ID, ci.HeadRef.ShortName(), ci.BaseRef.ShortName(), issues_model.PullRequestFlowGithub) if err != nil { if !issues_model.IsErrPullRequestNotExist(err) { @@ -633,7 +628,7 @@ func prepareCreatePullRequestPage(ctx *context.Context, ci *git_service.CompareI return } - if !nothingToCompare { + if !cpi.nothingToCompare { // Setup information for new form. pageMetaData := retrieveRepoIssueMetaData(ctx, ctx.Repo.Repository, nil, true) if ctx.Written() { @@ -645,8 +640,8 @@ func prepareCreatePullRequestPage(ctx *context.Context, ci *git_service.CompareI } } } - beforeCommitID := ctx.Data["BeforeCommitID"].(string) - afterCommitID := ctx.Data["AfterCommitID"].(string) + beforeCommitID := cpi.compareInfo.CompareBase + afterCommitID := cpi.compareInfo.HeadCommitID ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitID) + ci.CompareSeparator + base.ShortSha(afterCommitID) diff --git a/routers/web/repo/middlewares.go b/routers/web/repo/middlewares.go index c7c9da498bd90..ee525a0db7acf 100644 --- a/routers/web/repo/middlewares.go +++ b/routers/web/repo/middlewares.go @@ -9,6 +9,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/optional" + "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/gitdiff" @@ -80,6 +81,14 @@ func SetWhitespaceBehavior(ctx *context.Context) { } } +func GetWhitespaceBehavior(ctx *context.Context) string { + behavior, ok := ctx.Data["WhitespaceBehavior"].(string) + if !ok { + setting.PanicInDevOrTesting("WhitespaceBehavior is not set in context data or is not a string") + } + return behavior +} + // SetShowOutdatedComments set the show outdated comments option as context variable func SetShowOutdatedComments(ctx *context.Context) { showOutdatedCommentsValue := ctx.FormString("show-outdated") @@ -95,3 +104,11 @@ func SetShowOutdatedComments(ctx *context.Context) { } ctx.Data["ShowOutdatedComments"], _ = strconv.ParseBool(showOutdatedCommentsValue) } + +func GetShowOutdatedComments(ctx *context.Context) bool { + show, ok := ctx.Data["ShowOutdatedComments"].(bool) + if !ok { + setting.PanicInDevOrTesting("ShowOutdatedComments is not set in context data or is not a bool") + } + return show +} diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 4599a437d42d8..4e30c385b9154 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -544,7 +544,7 @@ func (prInfo *pullRequestViewInfo) prepareViewOpenPullInfo(ctx *context.Context) ctx.Data["PullHeadCommitID"] = prInfo.CompareInfo.HeadCommitID - if prInfo.CompareInfo.HeadCommitID == prInfo.CompareInfo.MergeBase { + if prInfo.CompareInfo.HeadCommitID == prInfo.CompareInfo.CompareBase { ctx.Data["IsNothingToCompare"] = true } @@ -622,9 +622,6 @@ func ViewPullCommits(ctx *context.Context) { return } - ctx.Data["Username"] = ctx.Repo.Owner.Name - ctx.Data["Reponame"] = ctx.Repo.Repository.Name - commits, err := processGitCommits(ctx, prCompareInfo.Commits) if err != nil { ctx.ServerError("processGitCommits", err) @@ -680,7 +677,7 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) { headCommitID := prCompareInfo.HeadCommitID isSingleCommit := beforeCommitID == "" && afterCommitID != "" ctx.Data["IsShowingOnlySingleCommit"] = isSingleCommit - isShowAllCommits := (beforeCommitID == "" || beforeCommitID == prCompareInfo.MergeBase) && (afterCommitID == "" || afterCommitID == headCommitID) + isShowAllCommits := (beforeCommitID == "" || beforeCommitID == prCompareInfo.CompareBase) && (afterCommitID == "" || afterCommitID == headCommitID) ctx.Data["IsShowingAllCommits"] = isShowAllCommits if afterCommitID == "" || afterCommitID == headCommitID { @@ -695,8 +692,8 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) { var beforeCommit *git.Commit var err error if !isSingleCommit { - if beforeCommitID == "" || beforeCommitID == prCompareInfo.MergeBase { - beforeCommitID = prCompareInfo.MergeBase + if beforeCommitID == "" || beforeCommitID == prCompareInfo.CompareBase { + beforeCommitID = prCompareInfo.CompareBase // merge base commit is not in the list of the pull request commits beforeCommit, err = gitRepo.GetCommit(beforeCommitID) if err != nil { @@ -719,7 +716,7 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) { beforeCommitID = beforeCommit.ID.String() } - ctx.Data["MergeBase"] = prCompareInfo.MergeBase + ctx.Data["CompareInfo"] = prCompareInfo ctx.Data["AfterCommitID"] = afterCommitID ctx.Data["BeforeCommitID"] = beforeCommitID @@ -737,7 +734,7 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) { MaxLines: maxLines, MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters, MaxFiles: maxFiles, - WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)), + WhitespaceBehavior: gitdiff.GetWhitespaceFlag(GetWhitespaceBehavior(ctx)), } diff, err := gitdiff.GetDiffForRender(ctx, ctx.Repo.RepoLink, gitRepo, diffOptions, files...) @@ -776,7 +773,7 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) { "numberOfViewedFiles": numViewedFiles, } - if err = diff.LoadComments(ctx, issue, ctx.Doer, ctx.Data["ShowOutdatedComments"].(bool)); err != nil { + if err = diff.LoadComments(ctx, issue, ctx.Doer, GetShowOutdatedComments(ctx)); err != nil { ctx.ServerError("LoadComments", err) return } @@ -1282,11 +1279,8 @@ func PullsNewRedirect(ctx *context.Context) { func CompareAndPullRequestPost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.CreateIssueForm) repo := ctx.Repo.Repository - - ci, err := parseCompareInfo(ctx) - if ctx.Written() { - return - } + comparePageInfo := newComparePageInfo() + err := comparePageInfo.parseCompareInfo(ctx) if errors.Is(err, util.ErrNotExist) { ctx.JSONErrorNotFound() return @@ -1297,7 +1291,8 @@ func CompareAndPullRequestPost(ctx *context.Context) { ctx.ServerError("ParseCompareInfo", err) return } - if ci.MergeBase == "" { + ci := comparePageInfo.compareInfo + if ci.CompareBase == "" { ctx.JSONError(ctx.Tr("repo.pulls.no_common_history")) return } @@ -1358,7 +1353,7 @@ func CompareAndPullRequestPost(ctx *context.Context) { BaseBranch: ci.BaseRef.ShortName(), HeadRepo: ci.HeadRepo, BaseRepo: repo, - MergeBase: ci.MergeBase, + MergeBase: ci.CompareBase, Type: issues_model.PullRequestGitea, AllowMaintainerEdit: form.AllowMaintainerEdit, } diff --git a/routers/web/repo/pull_review.go b/routers/web/repo/pull_review.go index eb8e8fa677e0a..bbcf6630b677c 100644 --- a/routers/web/repo/pull_review.go +++ b/routers/web/repo/pull_review.go @@ -169,7 +169,7 @@ func UpdateResolveConversation(ctx *context.Context) { func renderConversation(ctx *context.Context, comment *issues_model.Comment, origin string) { ctx.Data["PageIsPullFiles"] = origin == "diff" - showOutdatedComments := origin == "timeline" || ctx.Data["ShowOutdatedComments"].(bool) + showOutdatedComments := origin == "timeline" || GetShowOutdatedComments(ctx) comments, err := issues_model.FetchCodeCommentsByLine(ctx, comment.Issue, ctx.Doer, comment.TreePath, comment.Line, showOutdatedComments) if err != nil { ctx.ServerError("FetchCodeCommentsByLine", err) diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go index 39075dbdf6f44..78fb0ca0af089 100644 --- a/routers/web/repo/wiki.go +++ b/routers/web/repo/wiki.go @@ -334,9 +334,6 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) ctx.Data["Title"] = displayName ctx.Data["title"] = displayName - ctx.Data["Username"] = ctx.Repo.Owner.Name - ctx.Data["Reponame"] = ctx.Repo.Repository.Name - // lookup filename in wiki - get page content, gitTree entry , real filename _, entry, pageFilename, noEntry := wikiContentsByName(ctx, commit, pageName) if noEntry { diff --git a/services/git/compare.go b/services/git/compare.go index 40a0eaac08964..6102d2418d9dd 100644 --- a/services/git/compare.go +++ b/services/git/compare.go @@ -16,17 +16,23 @@ import ( // CompareInfo represents needed information for comparing references. type CompareInfo struct { - BaseRepo *repo_model.Repository - BaseRef git.RefName - BaseCommitID string - HeadRepo *repo_model.Repository - HeadGitRepo *git.Repository - HeadRef git.RefName - HeadCommitID string + BaseRepo *repo_model.Repository + BaseRef git.RefName + BaseCommitID string + HeadRepo *repo_model.Repository + HeadGitRepo *git.Repository + HeadRef git.RefName + HeadCommitID string + CompareSeparator string - MergeBase string - Commits []*git.Commit - NumFiles int + + // CompareBase is the left-side commit ID used for comparing + // for "...": it is merge base (empty for no merge base) + // for direct comparison "..": it is base commit ID + CompareBase string + + Commits []*git.Commit + NumFiles int } func (ci *CompareInfo) IsSameRepository() bool { @@ -75,15 +81,15 @@ func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Reposito } if !directComparison { - compareInfo.MergeBase, err = gitrepo.MergeBase(ctx, headRepo, compareInfo.BaseCommitID, compareInfo.HeadCommitID) + compareInfo.CompareBase, err = gitrepo.MergeBase(ctx, headRepo, compareInfo.BaseCommitID, compareInfo.HeadCommitID) if err != nil && !errors.Is(err, util.ErrNotExist) { return compareInfo, fmt.Errorf("MergeBase: %w", err) } } else { - compareInfo.MergeBase = compareInfo.BaseCommitID + compareInfo.CompareBase = compareInfo.BaseCommitID } - if compareInfo.MergeBase == "" { + if compareInfo.CompareBase == "" { return compareInfo, nil } @@ -93,7 +99,7 @@ func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Reposito // which is different from the meaning of "..." in git diff (where it implies diffing from the merge base). // For listing PR commits, we must use merge-base..head to include only the commits introduced by the head branch. // Otherwise, commits newly pushed to the base branch would also be included, which is incorrect. - compareInfo.Commits, err = headGitRepo.ShowPrettyFormatLogToList(ctx, compareInfo.MergeBase+".."+compareInfo.HeadCommitID) + compareInfo.Commits, err = headGitRepo.ShowPrettyFormatLogToList(ctx, compareInfo.CompareBase+".."+compareInfo.HeadCommitID) if err != nil { return compareInfo, fmt.Errorf("ShowPrettyFormatLogToList: %w", err) } diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index ccb9e80f28bd0..463575b84d3e7 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -35,7 +35,7 @@ {{template "repo/diff/whitespace_dropdown" .}} {{template "repo/diff/options_dropdown" .}} {{if .PageIsPullFiles}} -
+
{{/* the following will be replaced by vue component, but this avoids any loading artifacts till the vue component is initialized */}}