Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions modules/git/repo_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import (

// CompareInfo represents needed information for comparing references.
type CompareInfo struct {
MergeBase string
Commits *list.List
NumFiles int
MergeBase string
BaseCommitID string
HeadCommitID string
Commits *list.List
NumFiles int
}

// GetMergeBase checks and returns merge base of two branches and the reference used as base.
Expand Down Expand Up @@ -66,8 +68,18 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string)
}

compareInfo := new(CompareInfo)

compareInfo.HeadCommitID, err = GetFullCommitID(repo.Path, headBranch)
if err != nil {
compareInfo.HeadCommitID = headBranch
}

compareInfo.MergeBase, remoteBranch, err = repo.GetMergeBase(tmpRemote, baseBranch, headBranch)
if err == nil {
compareInfo.BaseCommitID, err = GetFullCommitID(repo.Path, remoteBranch)
if err != nil {
compareInfo.BaseCommitID = remoteBranch
}
// We have a common base - therefore we know that ... should work
logs, err := NewCommand("log", compareInfo.MergeBase+"..."+headBranch, prettyLogFormat).RunInDirBytes(repo.Path)
if err != nil {
Expand All @@ -83,6 +95,7 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string)
if err != nil {
compareInfo.MergeBase = remoteBranch
}
compareInfo.BaseCommitID = compareInfo.MergeBase
}

// Count number of changed files.
Expand Down
26 changes: 2 additions & 24 deletions routers/repo/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,18 +423,7 @@ func PrepareCompareDiff(
// Get diff information.
ctx.Data["CommitRepoLink"] = headRepo.Link()

headCommitID := headBranch
if ctx.Data["HeadIsCommit"] == false {
if ctx.Data["HeadIsTag"] == true {
headCommitID, err = headGitRepo.GetTagCommitID(headBranch)
} else {
headCommitID, err = headGitRepo.GetBranchCommitID(headBranch)
}
if err != nil {
ctx.ServerError("GetRefCommitID", err)
return false
}
}
headCommitID := compareInfo.HeadCommitID

ctx.Data["AfterCommitID"] = headCommitID

Expand All @@ -460,18 +449,7 @@ func PrepareCompareDiff(
}

baseGitRepo := ctx.Repo.GitRepo
baseCommitID := baseBranch
if ctx.Data["BaseIsCommit"] == false {
if ctx.Data["BaseIsTag"] == true {
baseCommitID, err = baseGitRepo.GetTagCommitID(baseBranch)
} else {
baseCommitID, err = baseGitRepo.GetBranchCommitID(baseBranch)
}
if err != nil {
ctx.ServerError("GetRefCommitID", err)
return false
}
}
baseCommitID := compareInfo.BaseCommitID

baseCommit, err := baseGitRepo.GetCommit(baseCommitID)
if err != nil {
Expand Down