mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 01:14:10 -05:00
Merge pull request #911 from TonyTsangHK/dev
Link to previous commited source file (diff.view_file button) instead of returning 404 for deleted files.
This commit is contained in:
commit
6ed96b7a20
3 changed files with 16 additions and 0 deletions
|
@ -60,6 +60,8 @@ type DiffFile struct {
|
||||||
Index int
|
Index int
|
||||||
Addition, Deletion int
|
Addition, Deletion int
|
||||||
Type int
|
Type int
|
||||||
|
IsCreated bool
|
||||||
|
IsDeleted bool
|
||||||
IsBin bool
|
IsBin bool
|
||||||
Sections []*DiffSection
|
Sections []*DiffSection
|
||||||
}
|
}
|
||||||
|
@ -181,10 +183,16 @@ func ParsePatch(pid int64, maxlines int, cmd *exec.Cmd, reader io.Reader) (*Diff
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(scanner.Text(), "new file"):
|
case strings.HasPrefix(scanner.Text(), "new file"):
|
||||||
curFile.Type = DIFF_FILE_ADD
|
curFile.Type = DIFF_FILE_ADD
|
||||||
|
curFile.IsDeleted = false
|
||||||
|
curFile.IsCreated = true
|
||||||
case strings.HasPrefix(scanner.Text(), "deleted"):
|
case strings.HasPrefix(scanner.Text(), "deleted"):
|
||||||
curFile.Type = DIFF_FILE_DEL
|
curFile.Type = DIFF_FILE_DEL
|
||||||
|
curFile.IsCreated = false
|
||||||
|
curFile.IsDeleted = true
|
||||||
case strings.HasPrefix(scanner.Text(), "index"):
|
case strings.HasPrefix(scanner.Text(), "index"):
|
||||||
curFile.Type = DIFF_FILE_CHANGE
|
curFile.Type = DIFF_FILE_CHANGE
|
||||||
|
curFile.IsCreated = false
|
||||||
|
curFile.IsDeleted = false
|
||||||
}
|
}
|
||||||
if curFile.Type > 0 {
|
if curFile.Type > 0 {
|
||||||
break
|
break
|
||||||
|
|
|
@ -253,6 +253,9 @@ func Diff(ctx *middleware.Context) {
|
||||||
ctx.Data["Parents"] = parents
|
ctx.Data["Parents"] = parents
|
||||||
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
|
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
|
||||||
ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", commitId)
|
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.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", commitId)
|
||||||
ctx.HTML(200, DIFF)
|
ctx.HTML(200, DIFF)
|
||||||
}
|
}
|
||||||
|
@ -316,6 +319,7 @@ func CompareDiff(ctx *middleware.Context) {
|
||||||
ctx.Data["Diff"] = diff
|
ctx.Data["Diff"] = diff
|
||||||
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
|
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
|
||||||
ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", afterCommitId)
|
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.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", afterCommitId)
|
||||||
ctx.HTML(200, DIFF)
|
ctx.HTML(200, DIFF)
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,11 @@
|
||||||
{{$.i18n.Tr "repo.diff.bin"}}
|
{{$.i18n.Tr "repo.diff.bin"}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</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>
|
<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>
|
<span class="file">{{$file.Name}}</span>
|
||||||
</div>
|
</div>
|
||||||
{{$isImage := (call $.IsImageFile $file.Name)}}
|
{{$isImage := (call $.IsImageFile $file.Name)}}
|
||||||
|
|
Loading…
Reference in a new issue