]> source.dussan.org Git - gitea.git/commitdiff
Link to previous commited source file (diff.view_file button) instead of returning...
authorTony Tsang <tony@tcnhk.com>
Fri, 6 Feb 2015 09:02:32 +0000 (17:02 +0800)
committerTony Tsang <tony@tcnhk.com>
Fri, 6 Feb 2015 09:02:32 +0000 (17:02 +0800)
models/git_diff.go
routers/repo/commit.go
templates/repo/diff.tmpl

index 7e91626f1d23d0b5202981fc6de29500951ef852..9d34ed62715c27815621f2a076f3ca20de0d90e9 100644 (file)
@@ -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
index e92ec8c88c8c0b27956306cb0563bca41fa87796..5d354c4b560b4d3c16ef7bf360b896c38a8b6ec2 100644 (file)
@@ -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)
 }
index 3d4a8b1fa7ca80fbdd13e4156ac3f16739b93ff2..443e002d5951eb556e3ea7078b3208c6ea49c1ec 100644 (file)
                     {{$.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)}}