diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index 168d959494..0dd031550d 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -275,6 +275,7 @@ func Diff(ctx *context.Context) { userName := ctx.Repo.Owner.Name repoName := ctx.Repo.Repository.Name + repoGroup := ctx.Repo.Repository.GroupID commitID := ctx.PathParam("sha") diffBlobExcerptData := &gitdiff.DiffBlobExcerptData{ @@ -360,7 +361,7 @@ func Diff(ctx *context.Context) { } parentCommitID = parentCommit.ID.String() } - setCompareContext(ctx, parentCommit, commit, userName, repoName) + setCompareContext(ctx, parentCommit, commit, userName, repoName, repoGroup) ctx.Data["Title"] = commit.Summary() + " ยท " + base.ShortSha(commitID) ctx.Data["Commit"] = commit ctx.Data["Diff"] = diff diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 285f3968d4..f6cb3f3d0a 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -7,6 +7,7 @@ import ( gocontext "context" "encoding/csv" "errors" + "fmt" "io" "net/http" "net/url" @@ -51,7 +52,7 @@ const ( ) // setCompareContext sets context data. -func setCompareContext(ctx *context.Context, before, head *git.Commit, headOwner, headName string) { +func setCompareContext(ctx *context.Context, before, head *git.Commit, headOwner, headName string, headGID int64) { ctx.Data["BeforeCommit"] = before ctx.Data["HeadCommit"] = head @@ -82,28 +83,36 @@ func setCompareContext(ctx *context.Context, before, head *git.Commit, headOwner return st } - setPathsCompareContext(ctx, before, head, headOwner, headName) + setPathsCompareContext(ctx, before, head, headOwner, headName, headGID) setImageCompareContext(ctx) setCsvCompareContext(ctx) } // SourceCommitURL creates a relative URL for a commit in the given repository -func SourceCommitURL(owner, name string, commit *git.Commit) string { - return setting.AppSubURL + "/" + url.PathEscape(owner) + "/" + url.PathEscape(name) + "/src/commit/" + url.PathEscape(commit.ID.String()) +func SourceCommitURL(owner, name string, gid int64, commit *git.Commit) string { + var groupSegment string + if gid > 0 { + groupSegment = fmt.Sprintf("group/%d/", gid) + } + return setting.AppSubURL + "/" + url.PathEscape(owner) + "/" + groupSegment + url.PathEscape(name) + "/src/commit/" + url.PathEscape(commit.ID.String()) } // RawCommitURL creates a relative URL for the raw commit in the given repository -func RawCommitURL(owner, name string, commit *git.Commit) string { - return setting.AppSubURL + "/" + url.PathEscape(owner) + "/" + url.PathEscape(name) + "/raw/commit/" + url.PathEscape(commit.ID.String()) +func RawCommitURL(owner, name string, gid int64, commit *git.Commit) string { + var groupSegment string + if gid > 0 { + groupSegment = fmt.Sprintf("group/%d/", gid) + } + return setting.AppSubURL + "/" + url.PathEscape(owner) + "/" + groupSegment + url.PathEscape(name) + "/raw/commit/" + url.PathEscape(commit.ID.String()) } // setPathsCompareContext sets context data for source and raw paths -func setPathsCompareContext(ctx *context.Context, base, head *git.Commit, headOwner, headName string) { - ctx.Data["SourcePath"] = SourceCommitURL(headOwner, headName, head) - ctx.Data["RawPath"] = RawCommitURL(headOwner, headName, head) +func setPathsCompareContext(ctx *context.Context, base, head *git.Commit, headOwner, headName string, headGID int64) { + ctx.Data["SourcePath"] = SourceCommitURL(headOwner, headName, headGID, head) + ctx.Data["RawPath"] = RawCommitURL(headOwner, headName, headGID, head) if base != nil { - ctx.Data["BeforeSourcePath"] = SourceCommitURL(headOwner, headName, base) - ctx.Data["BeforeRawPath"] = RawCommitURL(headOwner, headName, base) + ctx.Data["BeforeSourcePath"] = SourceCommitURL(headOwner, headName, headGID, base) + ctx.Data["BeforeRawPath"] = RawCommitURL(headOwner, headName, headGID, base) } } @@ -572,7 +581,7 @@ func PrepareCompareDiff( ctx.Data["Username"] = ci.HeadRepo.OwnerName ctx.Data["Reponame"] = ci.HeadRepo.Name - setCompareContext(ctx, beforeCommit, headCommit, ci.HeadRepo.OwnerName, repo.Name) + setCompareContext(ctx, beforeCommit, headCommit, ci.HeadRepo.OwnerName, repo.Name, repo.GroupID) return false } diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index e312fc9d2a..a83317be60 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -906,7 +906,7 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) { } } - setCompareContext(ctx, beforeCommit, afterCommit, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) + setCompareContext(ctx, beforeCommit, afterCommit, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name, ctx.Repo.Repository.GroupID) assigneeUsers, err := repo_model.GetRepoAssignees(ctx, ctx.Repo.Repository) if err != nil {