From d7c6aa99c3e9fe109369428158e60b9d4ebf400a Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Tue, 16 Dec 2025 03:52:38 +0000 Subject: [PATCH] appview/pages: unify diff & interdiff templates any object that adheres to the DiffRenderer interface can now be presented as html using the repo/fragments/diff template. --- appview/pages/templates/repo/commit.html | 19 +------------------ appview/pages/templates/repo/compare/compare.html | 20 +------------------- appview/pages/templates/repo/fragments/diff.html | 211 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------- appview/pages/templates/repo/fragments/diffChangedFiles.html | 13 ------------- appview/pages/templates/repo/fragments/interdiff.html | 67 ------------------------------------------------------------------- appview/pages/templates/repo/fragments/interdiffFiles.html | 11 ----------- appview/pages/templates/repo/fragments/splitDiff.html | 2 +- appview/pages/templates/repo/fragments/unifiedDiff.html | 2 +- appview/pages/templates/repo/pulls/interdiff.html | 23 ++--------------------- 9 file(s) changed, 172 insertion(s)(+), 196 deletion(s)(-) diff --git a/appview/pages/templates/repo/commit.html b/appview/pages/templates/repo/commit.html --- a/appview/pages/templates/repo/commit.html +++ b/appview/pages/templates/repo/commit.html @@ -116,16 +116,7 @@ {{ block "content" . }}{{ end }} {{ end }} - {{ block "contentAfterLayout" . }} -
-
- {{ block "contentAfterLeft" . }} {{ end }} -
-
- {{ block "contentAfter" . }}{{ end }} -
-
- {{ end }} + {{ block "contentAfter" . }}{{ end }} {{ end }} @@ -139,11 +130,3 @@ {{ template "repo/fragments/diff" (list .Diff .DiffOpts) }} {{end}} -{{ define "contentAfterLeft" }} -
- {{ template "repo/fragments/diffOpts" .DiffOpts }} -
-
- {{ template "repo/fragments/diffChangedFiles" .Diff }} -
-{{end}} diff --git a/appview/pages/templates/repo/compare/compare.html b/appview/pages/templates/repo/compare/compare.html --- a/appview/pages/templates/repo/compare/compare.html +++ b/appview/pages/templates/repo/compare/compare.html @@ -22,16 +22,7 @@ {{ block "content" . }}{{ end }} {{ end }} - {{ block "contentAfterLayout" . }} -
-
- {{ block "contentAfterLeft" . }} {{ end }} -
-
- {{ block "contentAfter" . }}{{ end }} -
-
- {{ end }} + {{ block "contentAfter" . }}{{ end }} {{ end }} @@ -43,13 +34,4 @@ {{ define "contentAfter" }} {{ template "repo/fragments/diff" (list .Diff .DiffOpts) }} -{{end}} - -{{ define "contentAfterLeft" }} -
- {{ template "repo/fragments/diffOpts" .DiffOpts }} -
-
- {{ template "repo/fragments/diffChangedFiles" .Diff }} -
{{end}} diff --git a/appview/pages/templates/repo/fragments/diff.html b/appview/pages/templates/repo/fragments/diff.html --- a/appview/pages/templates/repo/fragments/diff.html +++ b/appview/pages/templates/repo/fragments/diff.html @@ -1,59 +1,180 @@ {{ define "repo/fragments/diff" }} + + + {{ template "diffTopbar" . }} + {{ block "diffLayout" . }} {{ end }} +{{ end }} + +{{ define "diffTopbar" }} {{ $diff := index . 0 }} {{ $opts := index . 1 }} - {{ $commit := $diff.Commit }} - {{ $diff := $diff.Diff }} - {{ $isSplit := $opts.Split }} - {{ $this := $commit.This }} - {{ $parent := $commit.Parent }} - {{ $last := sub (len $diff) 1 }} + {{ block "filesCheckbox" $ }} {{ end }} + {{ block "subsCheckbox" $ }} {{ end }} + +
+ + {{ template "filesToggle" . }} + + + {{ $stat := $diff.Stats }} + {{ $count := len $diff.ChangedFiles }} + {{ template "repo/fragments/diffStatPill" $stat }} + {{ $count }} changed file{{ if ne $count 1 }}s{{ end }} + + +
+ + + {{ template "collapseToggle" }} + + + {{ template "repo/fragments/diffOpts" $opts }} + + + {{ block "subsToggle" $ }} {{ end }} +
+ +{{ end }} + +{{ define "diffLayout" }} + {{ $diff := index . 0 }} + {{ $opts := index . 1 }} + +
+ + + + +
+ {{ template "diffFiles" (list $diff $opts) }} +
+ +
+{{ end }} + +{{ define "diffFiles" }} + {{ $diff := index . 0 }} + {{ $opts := index . 1 }} + {{ $files := $diff.ChangedFiles }} + {{ $isSplit := $opts.Split }}
- {{ if eq (len $diff) 0 }} + {{ if eq (len $files) 0 }}

No differences found between the selected revisions.

{{ else }} - {{ range $idx, $hunk := $diff }} - {{ with $hunk }} -
- -
-
- {{ i "chevron-right" "w-4 h-4" }} - - {{ template "repo/fragments/diffStatPill" .Stats }} - -
- {{ if .IsDelete }} - {{ .Name.Old }} - {{ else if (or .IsCopy .IsRename) }} - {{ .Name.Old }} {{ i "arrow-right" "w-4 h-4" }} {{ .Name.New }} - {{ else }} - {{ .Name.New }} - {{ end }} -
-
-
-
- -
- {{ if .IsBinary }} -

- This is a binary file and will not be displayed. -

- {{ else }} - {{ if $isSplit }} - {{- template "repo/fragments/splitDiff" .Split -}} - {{ else }} - {{- template "repo/fragments/unifiedDiff" . -}} - {{ end }} - {{- end -}} -
-
+ {{ range $idx, $file := $files }} + {{ template "diffFile" (list $idx $file $isSplit) }} {{ end }} {{ end }} - {{ end }}
+{{ end }} + +{{ define "diffFile" }} + {{ $idx := index . 0 }} + {{ $file := index . 1 }} + {{ $isSplit := index . 2 }} + {{ with $file }} +
+ +
+
+ {{ i "chevron-right" "w-4 h-4" }} + + {{ template "repo/fragments/diffStatPill" .Stats }} + +
+ {{ $n := .Names }} + {{ if and $n.New $n.Old (ne $n.New $n.Old)}} + {{ $n.Old }} {{ i "arrow-right" "w-4 h-4" }} {{ $n.New }} + {{ else if $n.New }} + {{ $n.New }} + {{ else }} + {{ $n.Old }} + {{ end }} +
+
+
+
+ +
+ {{ $reason := .CanRender }} + {{ if $reason }} +

{{ $reason }}

+ {{ else }} + {{ if $isSplit }} + {{- template "repo/fragments/splitDiff" .Split -}} + {{ else }} + {{- template "repo/fragments/unifiedDiff" . -}} + {{ end }} + {{- end -}} +
+
+ {{ end }} +{{ end }} + +{{ define "filesCheckbox" }} + +{{ end }} + +{{ define "filesToggle" }} + +{{ end }} + +{{ define "collapseToggle" }} + + {{ end }} diff --git a/appview/pages/templates/repo/fragments/diffChangedFiles.html b/appview/pages/templates/repo/fragments/diffChangedFiles.html deleted file mode 100644 --- a/appview/pages/templates/repo/fragments/diffChangedFiles.html +++ /dev/null @@ -1,13 +0,0 @@ -{{ define "repo/fragments/diffChangedFiles" }} - {{ $stat := .Stat }} - {{ $fileTree := fileTree .ChangedFiles }} -
-
-
- Changed files - {{ template "repo/fragments/diffStatPill" $stat }} -
- {{ template "repo/fragments/fileTree" $fileTree }} -
-
-{{ end }} diff --git a/appview/pages/templates/repo/fragments/interdiff.html b/appview/pages/templates/repo/fragments/interdiff.html deleted file mode 100644 --- a/appview/pages/templates/repo/fragments/interdiff.html +++ /dev/null @@ -1,67 +0,0 @@ -{{ define "repo/fragments/interdiff" }} -{{ $repo := index . 0 }} -{{ $x := index . 1 }} -{{ $opts := index . 2 }} -{{ $fileTree := fileTree $x.AffectedFiles }} -{{ $diff := $x.Files }} -{{ $last := sub (len $diff) 1 }} -{{ $isSplit := $opts.Split }} - -
- {{ range $idx, $hunk := $diff }} - {{ with $hunk }} -
- -
-
-
- {{ $markerstyle := "diff-type p-1 mr-1 font-mono text-sm rounded select-none" }} - {{ if .Status.IsOk }} - CHANGED - {{ else if .Status.IsUnchanged }} - UNCHANGED - {{ else if .Status.IsOnlyInOne }} - REVERTED - {{ else if .Status.IsOnlyInTwo }} - NEW - {{ else if .Status.IsRebased }} - REBASED - {{ else }} - ERROR - {{ end }} -
- -
{{ .Name }}
-
- -
-
- -
- {{ if .Status.IsUnchanged }} -

- This file has not been changed. -

- {{ else if .Status.IsRebased }} -

- This patch was likely rebased, as context lines do not match. -

- {{ else if .Status.IsError }} -

- Failed to calculate interdiff for this file. -

- {{ else }} - {{ if $isSplit }} - {{- template "repo/fragments/splitDiff" .Split -}} - {{ else }} - {{- template "repo/fragments/unifiedDiff" . -}} - {{ end }} - {{- end -}} -
- -
- {{ end }} - {{ end }} -
-{{ end }} - diff --git a/appview/pages/templates/repo/fragments/interdiffFiles.html b/appview/pages/templates/repo/fragments/interdiffFiles.html deleted file mode 100644 --- a/appview/pages/templates/repo/fragments/interdiffFiles.html +++ /dev/null @@ -1,11 +0,0 @@ -{{ define "repo/fragments/interdiffFiles" }} -{{ $fileTree := fileTree .AffectedFiles }} -
-
-
- files -
- {{ template "repo/fragments/fileTree" $fileTree }} -
-
-{{ end }} diff --git a/appview/pages/templates/repo/fragments/splitDiff.html b/appview/pages/templates/repo/fragments/splitDiff.html --- a/appview/pages/templates/repo/fragments/splitDiff.html +++ b/appview/pages/templates/repo/fragments/splitDiff.html @@ -3,7 +3,7 @@ {{- $lineNrStyle := "min-w-[3.5rem] flex-shrink-0 select-none text-right bg-white dark:bg-gray-800" -}} {{- $linkStyle := "text-gray-400 dark:text-gray-500 hover:underline" -}} {{- $lineNrSepStyle := "pr-2 border-r border-gray-200 dark:border-gray-700" -}} -{{- $containerStyle := "inline-flex w-full items-center target:border target:rounded-sm target:border-yellow-200 target:dark:border-yellow-700 scroll-mt-20" -}} +{{- $containerStyle := "inline-flex w-full items-center target:bg-yellow-200 target:dark:bg-yellow-700 scroll-mt-48" -}} {{- $emptyStyle := "bg-gray-200/30 dark:bg-gray-700/30" -}} {{- $addStyle := "bg-green-100 dark:bg-green-800/30 text-green-700 dark:text-green-400" -}} {{- $delStyle := "bg-red-100 dark:bg-red-800/30 text-red-700 dark:text-red-400 " -}} diff --git a/appview/pages/templates/repo/fragments/unifiedDiff.html b/appview/pages/templates/repo/fragments/unifiedDiff.html --- a/appview/pages/templates/repo/fragments/unifiedDiff.html +++ b/appview/pages/templates/repo/fragments/unifiedDiff.html @@ -7,7 +7,7 @@ {{- $linkStyle := "text-gray-400 dark:text-gray-500 hover:underline" -}} {{- $lineNrSepStyle1 := "" -}} {{- $lineNrSepStyle2 := "pr-2 border-r border-gray-200 dark:border-gray-700" -}} - {{- $containerStyle := "inline-flex w-full items-center target:border target:rounded-sm target:border-yellow-200 target:dark:border-yellow-700 scroll-mt-20" -}} + {{- $containerStyle := "inline-flex w-full items-center target:bg-yellow-200 target:dark:bg-yellow-700 scroll-mt-48" -}} {{- $addStyle := "bg-green-100 dark:bg-green-800/30 text-green-700 dark:text-green-400 " -}} {{- $delStyle := "bg-red-100 dark:bg-red-800/30 text-red-700 dark:text-red-400 " -}} {{- $ctxStyle := "bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400" -}} diff --git a/appview/pages/templates/repo/pulls/interdiff.html b/appview/pages/templates/repo/pulls/interdiff.html --- a/appview/pages/templates/repo/pulls/interdiff.html +++ b/appview/pages/templates/repo/pulls/interdiff.html @@ -25,7 +25,6 @@ {{ template "repo/pulls/fragments/pullHeader" . }} - {{ end }} {{ define "mainLayout" }} @@ -34,28 +33,10 @@ {{ block "content" . }}{{ end }} {{ end }} - {{ block "contentAfterLayout" . }} -
-
- {{ block "contentAfterLeft" . }} {{ end }} -
-
- {{ block "contentAfter" . }}{{ end }} -
-
- {{ end }} + {{ block "contentAfter" . }}{{ end }} {{ end }} {{ define "contentAfter" }} - {{ template "repo/fragments/interdiff" (list .RepoInfo.FullName .Interdiff .DiffOpts) }} -{{end}} - -{{ define "contentAfterLeft" }} -
- {{ template "repo/fragments/diffOpts" .DiffOpts }} -
-
- {{ template "repo/fragments/interdiffFiles" .Interdiff }} -
+ {{ template "repo/fragments/diff" (list .Interdiff .DiffOpts) }} {{end}} -- tangled.sh