-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Adds side-by-side diff for images #6784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
5a4401f
b034635
0989146
72913a6
1b1915e
8c74e23
14791f8
1087cb0
a17d536
d8d6249
7565651
5cbcd9d
903b6e0
5b7af2f
e4aaf9c
67ff159
8f2cedf
f03d38d
33f636e
210d036
f963740
172bd4d
d9910df
af9dcc5
99ac70e
2f9bfc7
6834221
72849e2
3af68e8
2507754
83c14fc
561f080
4f97c18
d9e8a4b
de85e46
498b8d2
46bee76
6d0453b
8cbbc7e
978ea10
e4e99a5
69083b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,6 +238,16 @@ func Diff(ctx *context.Context) { | |
ctx.Data["Username"] = userName | ||
ctx.Data["Reponame"] = repoName | ||
ctx.Data["IsImageFile"] = commit.IsImageFile | ||
ctx.Data["ImageInfo"] = commit.ImageInfo | ||
ctx.Data["ImageInfoBase"] = ctx.Data["ImageInfo"] | ||
if commit.ParentCount() > 0 { | ||
parentCommit, err := ctx.Repo.GitRepo.GetCommit(parents[0]) | ||
if err != nil { | ||
ctx.NotFound("GetParentCommit", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
return | ||
} | ||
ctx.Data["ImageInfo"] = parentCommit.ImageInfo | ||
} | ||
ctx.Data["Title"] = commit.Summary() + " · " + base.ShortSha(commitID) | ||
ctx.Data["Commit"] = commit | ||
ctx.Data["Verification"] = models.ParseCommitWithSignature(commit) | ||
|
@@ -246,10 +256,11 @@ func Diff(ctx *context.Context) { | |
ctx.Data["Parents"] = parents | ||
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 | ||
ctx.Data["SourcePath"] = setting.AppSubURL + "/" + path.Join(userName, repoName, "src", "commit", commitID) | ||
ctx.Data["RawPath"] = setting.AppSubURL + "/" + path.Join(userName, repoName, "raw", "commit", commitID) | ||
if commit.ParentCount() > 0 { | ||
ctx.Data["BeforeSourcePath"] = setting.AppSubURL + "/" + path.Join(userName, repoName, "src", "commit", parents[0]) | ||
ctx.Data["BeforeRawPath"] = setting.AppSubURL + "/" + path.Join(userName, repoName, "raw", "commit", parents[0]) | ||
} | ||
ctx.Data["RawPath"] = setting.AppSubURL + "/" + path.Join(userName, repoName, "raw", "commit", commitID) | ||
ctx.Data["BranchName"], err = commit.GetBranchName() | ||
ctx.HTML(200, tplDiff) | ||
} | ||
|
@@ -276,6 +287,12 @@ func CompareDiff(ctx *context.Context) { | |
beforeCommitID := ctx.Params(":before") | ||
afterCommitID := ctx.Params(":after") | ||
|
||
beforeCommit, err := ctx.Repo.GitRepo.GetCommit(beforeCommitID) | ||
if err != nil { | ||
ctx.NotFound("GetCommit", err) | ||
return | ||
} | ||
|
||
commit, err := ctx.Repo.GitRepo.GetCommit(afterCommitID) | ||
if err != nil { | ||
ctx.NotFound("GetCommit", err) | ||
|
@@ -307,6 +324,8 @@ func CompareDiff(ctx *context.Context) { | |
ctx.Data["Username"] = userName | ||
ctx.Data["Reponame"] = repoName | ||
ctx.Data["IsImageFile"] = commit.IsImageFile | ||
ctx.Data["ImageInfo"] = commit.ImageInfo | ||
ctx.Data["ImageInfoBase"] = beforeCommit.ImageInfo | ||
ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitID) + "..." + base.ShortSha(afterCommitID) + " · " + userName + "/" + repoName | ||
ctx.Data["Commit"] = commit | ||
ctx.Data["Diff"] = diff | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -510,16 +510,27 @@ func ViewPullFiles(ctx *context.Context) { | |
ctx.Data["Diff"] = diff | ||
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 | ||
|
||
baseCommit, err := ctx.Repo.GitRepo.GetCommit(startCommitID) | ||
if err != nil { | ||
ctx.ServerError("GetCommit", err) | ||
return | ||
} | ||
commit, err := gitRepo.GetCommit(endCommitID) | ||
if err != nil { | ||
ctx.ServerError("GetCommit", err) | ||
return | ||
} | ||
|
||
ctx.Data["IsImageFile"] = commit.IsImageFile | ||
ctx.Data["ImageInfoBase"] = baseCommit.ImageInfo | ||
ctx.Data["ImageInfo"] = commit.ImageInfo | ||
|
||
baseTarget := path.Join(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) | ||
ctx.Data["SourcePath"] = setting.AppSubURL + "/" + path.Join(headTarget, "src", "commit", endCommitID) | ||
ctx.Data["BeforeSourcePath"] = setting.AppSubURL + "/" + path.Join(headTarget, "src", "commit", startCommitID) | ||
ctx.Data["RawPath"] = setting.AppSubURL + "/" + path.Join(headTarget, "raw", "commit", endCommitID) | ||
ctx.Data["BeforeSourcePath"] = setting.AppSubURL + "/" + path.Join(baseTarget, "src", "commit", startCommitID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that I changed "headTarget" to "baseTarget", as the "before" paths should point to the forked repository. |
||
ctx.Data["BeforeRawPath"] = setting.AppSubURL + "/" + path.Join(baseTarget, "raw", "commit", startCommitID) | ||
saitho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ctx.Data["RequireHighlightJS"] = true | ||
ctx.Data["RequireTribute"] = true | ||
if ctx.Data["Assignees"], err = ctx.Repo.Repository.GetAssignees(); err != nil { | ||
|
@@ -759,7 +770,6 @@ func PrepareCompareDiff( | |
baseBranch, headBranch string) bool { | ||
|
||
var ( | ||
repo = ctx.Repo.Repository | ||
err error | ||
title string | ||
) | ||
|
@@ -789,6 +799,12 @@ func PrepareCompareDiff( | |
ctx.Data["Diff"] = diff | ||
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 | ||
|
||
startCommitID := prInfo.MergeBase | ||
baseCommit, err := ctx.Repo.GitRepo.GetCommit(startCommitID) | ||
if err != nil { | ||
ctx.ServerError("GetCommit", err) | ||
return false | ||
} | ||
headCommit, err := headGitRepo.GetCommit(headCommitID) | ||
if err != nil { | ||
ctx.ServerError("GetCommit", err) | ||
|
@@ -817,11 +833,15 @@ func PrepareCompareDiff( | |
ctx.Data["Username"] = headUser.Name | ||
ctx.Data["Reponame"] = headRepo.Name | ||
ctx.Data["IsImageFile"] = headCommit.IsImageFile | ||
ctx.Data["ImageInfoBase"] = baseCommit.ImageInfo | ||
ctx.Data["ImageInfo"] = headCommit.ImageInfo | ||
|
||
headTarget := path.Join(headUser.Name, repo.Name) | ||
headTarget := path.Join(headUser.Name, headRepo.Name) | ||
baseTarget := path.Join(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) | ||
ctx.Data["SourcePath"] = setting.AppSubURL + "/" + path.Join(headTarget, "src", "commit", headCommitID) | ||
ctx.Data["BeforeSourcePath"] = setting.AppSubURL + "/" + path.Join(headTarget, "src", "commit", prInfo.MergeBase) | ||
ctx.Data["RawPath"] = setting.AppSubURL + "/" + path.Join(headTarget, "raw", "commit", headCommitID) | ||
ctx.Data["BeforeSourcePath"] = setting.AppSubURL + "/" + path.Join(baseTarget, "src", "commit", prInfo.MergeBase) | ||
ctx.Data["BeforeRawPath"] = setting.AppSubURL + "/" + path.Join(baseTarget, "raw", "commit", startCommitID) | ||
return false | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{{ $imagePathOld := printf "%s/%s" .root.BeforeRawPath (EscapePound .file.OldName) }} | ||
{{ $imagePathNew := printf "%s/%s" .root.RawPath (EscapePound .file.Name) }} | ||
|
||
<tr> | ||
<th class="halfwidth center"> | ||
{{.root.i18n.Tr "repo.diff.file_before"}} | ||
</th> | ||
<th class="halfwidth center"> | ||
{{.root.i18n.Tr "repo.diff.file_after"}} | ||
</th> | ||
</tr> | ||
<tr> | ||
<td class="halfwidth center"> | ||
<a href="{{$imagePathOld}}" target="_blank"> | ||
<img src="{{$imagePathOld}}" class="border red" /> | ||
</a> | ||
</td> | ||
<td class="halfwidth center"> | ||
<a href="{{$imagePathNew}}" target="_blank"> | ||
<img src="{{$imagePathNew}}" class="border green" /> | ||
</a> | ||
</td> | ||
</tr> | ||
{{ $imageInfoBase := (call .root.ImageInfoBase .file.OldName) }} | ||
{{ $imageInfoHead := (call .root.ImageInfo .file.Name) }} | ||
{{if and $imageInfoBase $imageInfoHead }} | ||
<tr> | ||
<td class="halfwidth center"> | ||
{{.root.i18n.Tr "repo.diff.file_image_width"}}: <span class="text {{if not (eq $imageInfoBase.Width $imageInfoHead.Width)}}red{{end}}">{{$imageInfoBase.Width}}</span> | ||
| | ||
{{.root.i18n.Tr "repo.diff.file_image_height"}}: <span class="text {{if not (eq $imageInfoBase.Height $imageInfoHead.Height)}}red{{end}}">{{$imageInfoBase.Height}}</span> | ||
</td> | ||
<td class="halfwidth center"> | ||
{{.root.i18n.Tr "repo.diff.file_image_width"}}: <span class="text {{if not (eq $imageInfoBase.Width $imageInfoHead.Width)}}green{{end}}">{{$imageInfoHead.Width}}</span> | ||
| | ||
{{.root.i18n.Tr "repo.diff.file_image_height"}}: <span class="text {{if not (eq $imageInfoBase.Height $imageInfoHead.Height)}}green{{end}}">{{$imageInfoHead.Height}}</span> | ||
</td> | ||
</tr> | ||
{{end}} |
Uh oh!
There was an error while loading. Please reload this page.