summaryrefslogtreecommitdiffstats
path: root/models/repo/repo.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/repo/repo.go')
-rw-r--r--models/repo/repo.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/models/repo/repo.go b/models/repo/repo.go
index b7c02057c2..3d1f2dcfa8 100644
--- a/models/repo/repo.go
+++ b/models/repo/repo.go
@@ -528,6 +528,18 @@ func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) strin
return fmt.Sprintf("%s/%s/compare/%s...%s", url.PathEscape(repo.OwnerName), url.PathEscape(repo.Name), util.PathEscapeSegments(oldCommitID), util.PathEscapeSegments(newCommitID))
}
+func (repo *Repository) ComposeBranchCompareURL(baseRepo *Repository, branchName string) string {
+ if baseRepo == nil {
+ baseRepo = repo
+ }
+ var cmpBranchEscaped string
+ if repo.ID != baseRepo.ID {
+ cmpBranchEscaped = fmt.Sprintf("%s/%s:", url.PathEscape(repo.OwnerName), url.PathEscape(repo.Name))
+ }
+ cmpBranchEscaped = fmt.Sprintf("%s%s", cmpBranchEscaped, util.PathEscapeSegments(branchName))
+ return fmt.Sprintf("%s/compare/%s...%s", baseRepo.Link(), util.PathEscapeSegments(baseRepo.DefaultBranch), cmpBranchEscaped)
+}
+
// IsOwnedBy returns true when user owns this repository
func (repo *Repository) IsOwnedBy(userID int64) bool {
return repo.OwnerID == userID