From b728491d77a668f74fa8e5ed84e34976d3c489ad Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Thu, 2 Jul 2026 01:22:14 +0900 Subject: [PATCH] diff view complete..? Signed-off-by: Seongmin Lee --- .../templates/repo/pulls/fragments/diff.html | 158 ++++++++++-------- .../pages/templates/repo/pulls/single.html | 59 ++++--- appview/pulls/pull2.go | 10 +- appview/pulls/router.go | 3 +- input.css | 10 +- 5 files changed, 138 insertions(+), 102 deletions(-) diff --git a/appview/pages/templates/repo/pulls/fragments/diff.html b/appview/pages/templates/repo/pulls/fragments/diff.html index f63ddd64..19e2407a 100644 --- a/appview/pages/templates/repo/pulls/fragments/diff.html +++ b/appview/pages/templates/repo/pulls/fragments/diff.html @@ -1,84 +1,106 @@ {{ define "repo/pulls/fragments/diff" }} -
+ {{ $split := .Split }} +
{{ range .Files }} -
-
{{ .Path }}
- {{ if .Note }} -
{{ .Note }}
- {{ else if .Split }} - {{ range .Hunks }}{{ template "pullDiffSplitHunk" . }}{{ end }} + {{ $ins := 0 }} + {{ $del := 0 }} + {{ range .Hunks }} + {{ if $split }} + {{ range .Rows }} + {{ if eq .Left.Kind "del" }}{{ $del = add $del 1 }}{{ end }} + {{ if eq .Right.Kind "add" }}{{ $ins = add $ins 1 }}{{ end }} + {{ end }} {{ else }} - {{ range .Hunks }}{{ template "pullDiffUnifiedHunk" . }}{{ end }} + {{ range .Lines }} + {{ if eq .Op "-" }}{{ $del = add $del 1 }}{{ end }} + {{ if eq .Op "+" }}{{ $ins = add $ins 1 }}{{ end }} + {{ end }} {{ end }} + {{ end }} + +
+
+ +
+
+ {{ i "chevron-right" "w-4 h-4" }} + + {{ template "repo/fragments/diffStatPill" (dict "Insertions" $ins "Deletions" $del) }} + {{ .Path }} +
+
+
+
+ + {{ if .Note }} +
{{ .Note }}
+ {{ else if $split }} + {{ template "pullDiffSplitTable" . }} + {{ else }} + {{ template "pullDiffUnifiedTable" . }} + {{ end }} +
{{ end }}
{{ end }} -{{ define "pullDiffUnifiedHunk" }} - {{- $lineNrStyle := "min-w-[3.5rem] flex-shrink-0 select-none text-right px-2" -}} - {{- $sepStyle := "border-r border-gray-200 dark:border-gray-700" -}} - {{- $opStyle := "w-5 flex-shrink-0 select-none text-center" -}} - {{- $contentStyle := "px-2 whitespace-pre" -}} - {{- $rowStyle := "inline-flex w-full items-center" -}} - {{- $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" -}} -
- ··· -
- {{- range .Lines -}} - {{- $style := $ctxStyle -}} - {{- if eq .Op "+" -}}{{- $style = $addStyle -}}{{- else if eq .Op "-" -}}{{- $style = $delStyle -}}{{- end -}} - - {{ if ge .Old 0 }}{{ .Old }}{{ end }} - {{ if ge .New 0 }}{{ .New }}{{ end }} - {{ .Op }} - {{ .Content }} - +{{/* pullDiffUnifiedTable renders a DiffFile's hunks as a 3-column unified table. */}} +{{ define "pullDiffUnifiedTable" }} + + + + + + + + {{- range .Hunks -}} + + {{- range .Lines -}} + {{- $cls := "" -}} + {{- if eq .Op "+" -}}{{- $cls = "added" -}}{{- else if eq .Op "-" -}}{{- $cls = "deleted" -}}{{- end -}} + + + + + + {{- end -}} {{- end -}} - - + +
···
{{ if ge .Old 0 }}{{ .Old }}{{ end }}{{ if ge .New 0 }}{{ .New }}{{ end }}{{ .Content }}
{{ end }} -{{ define "pullDiffSplitHunk" }} -
-
- ··· -
- {{- range .Rows -}}{{- template "pullDiffSplitCell" .Left -}}{{- end -}} -
-
-
- ··· -
- {{- range .Rows -}}{{- template "pullDiffSplitCell" .Right -}}{{- end -}} -
-
-
+{{/* pullDiffSplitTable renders a DiffFile's hunks as a 4-column side-by-side table. */}} +{{ define "pullDiffSplitTable" }} + + + + + + + + + {{- range .Hunks -}} + + {{- range .Rows -}} + + {{- template "pullDiffSplitCell" .Left -}} + {{- template "pullDiffSplitCell" .Right -}} + + {{- end -}} + {{- end -}} + +
···
{{ end }} -{{/* pullDiffSplitCell renders one side of a split row. Dot is a DiffCell. */}} +{{/* pullDiffSplitCell renders the num + content s for one side of a split row. + Dot is a DiffCell (Kind ctx|del|add|empty, Num, Content). */}} {{ define "pullDiffSplitCell" }} - {{- $lineNrStyle := "min-w-[3.5rem] flex-shrink-0 select-none text-right px-2 border-r border-gray-200 dark:border-gray-700" -}} - {{- $opStyle := "w-5 flex-shrink-0 select-none text-center" -}} - {{- $contentStyle := "px-2 whitespace-pre" -}} - {{- $rowStyle := "inline-flex w-full items-center" -}} - {{- if eq .Kind "empty" -}} - -   - -   - - {{- else -}} - {{- $style := "bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400" -}} - {{- $op := " " -}} - {{- if eq .Kind "add" -}}{{- $style = "bg-green-100 dark:bg-green-800/30 text-green-700 dark:text-green-400" -}}{{- $op = "+" -}}{{- end -}} - {{- if eq .Kind "del" -}}{{- $style = "bg-red-100 dark:bg-red-800/30 text-red-700 dark:text-red-400" -}}{{- $op = "-" -}}{{- end -}} - - {{ if ge .Num 0 }}{{ .Num }}{{ end }} - {{ $op }} - {{ .Content }} - - {{- end -}} + {{- $cls := "" -}} + {{- $mark := "" -}} + {{- if eq .Kind "del" -}}{{- $cls = "deleted" -}}{{- $mark = "-" -}} + {{- else if eq .Kind "add" -}}{{- $cls = "added" -}}{{- $mark = "+" -}} + {{- else if eq .Kind "empty" -}}{{- $cls = "empty" -}}{{- end -}} + {{ if ge .Num 0 }}{{ .Num }}{{ end }} + {{ .Content }} {{ end }} diff --git a/appview/pages/templates/repo/pulls/single.html b/appview/pages/templates/repo/pulls/single.html index b92d3a54..80facb77 100644 --- a/appview/pages/templates/repo/pulls/single.html +++ b/appview/pages/templates/repo/pulls/single.html @@ -3,6 +3,7 @@ {{ end }} {{ define "mainLayout" }} +{{ template "fragments/resizable" }} {{ $version := .Pull.LatestVersion }}
-
+

{{ .Pull.Title }}

@@ -29,8 +30,8 @@ commits
-
-
+
+
- -
- discussion + + {{ template "resize-grip" (list "resize-discussion" "discussion" "after") }} + +
+
+ {{ range .Comments }} + {{ template "fragments/comment/pullComment" + (dict "LoggedInUser" $.LoggedInUser + "Reactions" (index (asReactionMapMap $.Reactions) .FeedCommentAtUri) + "UserReacted" (index (asReactionStatusMapMap $.UserReacted) .FeedCommentAtUri) + "Comment" .) }} + {{ end }} + discussion +
{{ end }} @@ -86,7 +91,7 @@ {{ define "block" }}
- +
{{ i "chevron-right" "w-4 h-4" }} diff --git a/appview/pulls/pull2.go b/appview/pulls/pull2.go index 0d923dc1..2999ce16 100644 --- a/appview/pulls/pull2.go +++ b/appview/pulls/pull2.go @@ -51,8 +51,8 @@ var pull = &models.Pull2{ Versions: []models.PullVersion{ { SourceRepo: syntax.DID("did:plc:ofcpzigpnwrgtpl3ojrpg3y7"), - Head: "443b2e347c3f77bc9aa2481adb518440f204b870", - Base: "5c97f1cc886344bb8a9eba315a39c0fc14cee51f", + Head: "262439d43001b6e258077d933c6f5a39b9f63abf", + Base: "71588c938e39599b17f7cf879e10644816b8a7f6", }, }, Created: time.Now(), @@ -185,7 +185,7 @@ func (s *Pulls) PullDiff(w http.ResponseWriter, r *http.Request) { } } - var range_ = chi.URLParam(r, "*") + var range_ = chi.URLParam(r, "changeId") base, head, err := parseRevRange(range_) if err != nil { http.Redirect(w, r, @@ -258,6 +258,7 @@ func (s *Pulls) PullDiffFragment(w http.ResponseWriter, r *http.Request) { l := s.logger ctx := r.Context() + _ = l var params pages.PullDiffFragmentParams defer func() { @@ -287,8 +288,7 @@ func (s *Pulls) PullDiffFragment(w http.ResponseWriter, r *http.Request) { // b. fetch each file's base/head blob in parallel and split into lines. g, gctx := errgroup.WithContext(ctx) - for i, f := range files { - l.Debug("diff", "file", i, "diff", f.diff) + for _, f := range files { g.Go(func() error { lhs, rhs := f.diff.GetLhsSrc(), f.diff.GetRhsSrc() // Binary/submodule files have no line content to fetch. diff --git a/appview/pulls/router.go b/appview/pulls/router.go index eb2992ef..15062ea1 100644 --- a/appview/pulls/router.go +++ b/appview/pulls/router.go @@ -19,7 +19,8 @@ func (s *Pulls) Router(mw *middleware.Middleware) http.Handler { r.Post("/", s.NewPull) }) - r.Get("/{pull}/{version}/*", s.PullDiff) + r.Get("/{pull}/{version}", s.PullDiff) + r.Get("/{pull}/{version}/{changeId}", s.PullDiff) // r.Route("/{pull}", func(r chi.Router) { // r.Use(mw.ResolvePull()) diff --git a/input.css b/input.css index 378ce4bd..fced5ada 100644 --- a/input.css +++ b/input.css @@ -307,7 +307,7 @@ } table.diff { - @apply w-full border-collapse font-mono; + @apply border-collapse font-mono table-fixed; } table.diff tr { @apply bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400; @@ -324,9 +324,17 @@ table.diff td.num { @apply min-w-10 text-right select-none align-top whitespace-nowrap; } + table.diff td.content { + @apply whitespace-pre-wrap pl-6 relative; + } table.diff td.content::before { padding: 0 0.5rem; content: attr(data-diff-marker); + position: absolute; + left: 0; + } + table.diff td.content div { + @apply inline; } .prose { -- 2.51.2