aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author无闻 <u@gogs.io>2015-02-09 00:31:16 -0500
committer无闻 <u@gogs.io>2015-02-09 00:31:16 -0500
commit6ed96b7a20b8b53ef958808cc414d59b72b7fa5c (patch)
tree64c3ba8f297586d36a8b963273ed05ed5305ec17
parent3cc04682c5ad3296df3fc1b4209ee8b669da410e (diff)
parentfc6d80d619d960b340bf1ebc7131add86985e725 (diff)
downloadgitea-6ed96b7a20b8b53ef958808cc414d59b72b7fa5c.tar.gz
gitea-6ed96b7a20b8b53ef958808cc414d59b72b7fa5c.zip
Merge pull request #911 from TonyTsangHK/dev
Link to previous commited source file (diff.view_file button) instead of returning 404 for deleted files.
-rw-r--r--models/git_diff.go8
-rw-r--r--routers/repo/commit.go4
-rw-r--r--templates/repo/diff.tmpl4
3 files changed, 16 insertions, 0 deletions
diff --git a/models/git_diff.go b/models/git_diff.go
index 7e91626f1d..9d34ed6271 100644
--- a/models/git_diff.go
+++ b/models/git_diff.go
@@ -60,6 +60,8 @@ type DiffFile struct {
Index int
Addition, Deletion int
Type int
+ IsCreated bool
+ IsDeleted bool
IsBin bool
Sections []*DiffSection
}
@@ -181,10 +183,16 @@ func ParsePatch(pid int64, maxlines int, cmd *exec.Cmd, reader io.Reader) (*Diff
switch {
case strings.HasPrefix(scanner.Text(), "new file"):
curFile.Type = DIFF_FILE_ADD
+ curFile.IsDeleted = false
+ curFile.IsCreated = true
case strings.HasPrefix(scanner.Text(), "deleted"):
curFile.Type = DIFF_FILE_DEL
+ curFile.IsCreated = false
+ curFile.IsDeleted = true
case strings.HasPrefix(scanner.Text(), "index"):
curFile.Type = DIFF_FILE_CHANGE
+ curFile.IsCreated = false
+ curFile.IsDeleted = false
}
if curFile.Type > 0 {
break
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index e92ec8c88c..5d354c4b56 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -253,6 +253,9 @@ func Diff(ctx *middleware.Context) {
ctx.Data["Parents"] = parents
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", commitId)
+ if (commit.ParentCount() > 0) {
+ ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", parents[0])
+ }
ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", commitId)
ctx.HTML(200, DIFF)
}
@@ -316,6 +319,7 @@ func CompareDiff(ctx *middleware.Context) {
ctx.Data["Diff"] = diff
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", afterCommitId)
+ ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", beforeCommitId)
ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", afterCommitId)
ctx.HTML(200, DIFF)
}
diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl
index 3d4a8b1fa7..443e002d59 100644
--- a/templates/repo/diff.tmpl
+++ b/templates/repo/diff.tmpl
@@ -89,7 +89,11 @@
{{$.i18n.Tr "repo.diff.bin"}}
{{end}}
</div>
+ {{if $file.IsDeleted}}
+ <a class="btn btn-gray btn-header btn-radius text-black pull-right" rel="nofollow" href="{{$.BeforeSourcePath}}/{{.Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
+ {{else}}
<a class="btn btn-gray btn-header btn-radius text-black pull-right" rel="nofollow" href="{{$.SourcePath}}/{{.Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
+ {{end}}
<span class="file">{{$file.Name}}</span>
</div>
{{$isImage := (call $.IsImageFile $file.Name)}}