Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview/pages: initial support for split diffs

Signed-off-by: oppiliappan <me@oppi.li>

authored by

oppiliappan and committed by
Tangled
8ff57897 99057e2b

+170 -46
+3
appview/pages/pages.go
··· 527 527 Active string 528 528 EmailToDidOrHandle map[string]string 529 529 Pipeline *db.Pipeline 530 + DiffOpts types.DiffOpts 530 531 531 532 // singular because it's always going to be just one 532 533 VerifiedCommit commitverify.VerifiedCommits ··· 860 859 Round int 861 860 Submission *db.PullSubmission 862 861 OrderedReactionKinds []db.ReactionKind 862 + DiffOpts types.DiffOpts 863 863 } 864 864 865 865 // this name is a mouthful ··· 966 964 Base string 967 965 Head string 968 966 Diff *types.NiceDiff 967 + DiffOpts types.DiffOpts 969 968 970 969 Active string 971 970 }
+1 -1
appview/pages/templates/repo/commit.html
··· 119 119 {{ end }} 120 120 121 121 {{ define "contentAfter" }} 122 - {{ template "repo/fragments/diff" (list .RepoInfo.FullName .Diff) }} 122 + {{ template "repo/fragments/diff" (list .RepoInfo.FullName .Diff .DiffOpts) }} 123 123 {{end}} 124 124 125 125 {{ define "contentAfterLeft" }}
+1 -1
appview/pages/templates/repo/compare/compare.html
··· 50 50 {{ end }} 51 51 52 52 {{ define "contentAfter" }} 53 - {{ template "repo/fragments/diff" (list .RepoInfo.FullName .Diff) }} 53 + {{ template "repo/fragments/diff" (list .RepoInfo.FullName .Diff .DiffOpts) }} 54 54 {{end}} 55 55 56 56 {{ define "contentAfterLeft" }}
+118 -39
appview/pages/templates/repo/fragments/diff.html
··· 1 1 {{ define "repo/fragments/diff" }} 2 2 {{ $repo := index . 0 }} 3 3 {{ $diff := index . 1 }} 4 + {{ $opts := index . 2 }} 5 + 4 6 {{ $commit := $diff.Commit }} 5 7 {{ $diff := $diff.Diff }} 8 + {{ $isSplit := $opts.Split }} 6 9 {{ $this := $commit.This }} 7 10 {{ $parent := $commit.Parent }} 8 11 ··· 88 85 This is a binary file and will not be displayed. 89 86 </p> 90 87 {{ else }} 91 - {{ $name := .Name.New }} 92 - <pre class="overflow-x-auto"><div class="overflow-x-auto"><div class="min-w-full inline-block">{{- range .TextFragments -}}<div class="bg-gray-100 dark:bg-gray-700 text-gray-500 dark:text-gray-400 select-none text-center">&middot;&middot;&middot;</div> 93 - {{- $oldStart := .OldPosition -}} 94 - {{- $newStart := .NewPosition -}} 95 - {{- $lineNrStyle := "min-w-[3.5rem] flex-shrink-0 select-none text-right bg-white dark:bg-gray-800 scroll-mt-10 target:border target:border-amber-500 target:rounded " -}} 96 - {{- $linkStyle := "text-gray-400 dark:text-gray-500 hover:underline" -}} 97 - {{- $lineNrSepStyle1 := "" -}} 98 - {{- $lineNrSepStyle2 := "pr-2" -}} 99 - {{- range .Lines -}} 100 - {{- if eq .Op.String "+" -}} 101 - <div class="bg-green-100 dark:bg-green-800/30 text-green-700 dark:text-green-400 flex min-w-full items-center"> 102 - <div class="{{$lineNrStyle}} {{$lineNrSepStyle1}}"><span aria-hidden="true" class="invisible">{{$newStart}}</span></div> 103 - <div class="{{$lineNrStyle}} {{$lineNrSepStyle2}}" id="{{$name}}-N{{$newStart}}"><a class="{{$linkStyle}}" href="#{{$name}}-N{{$newStart}}">{{ $newStart }}</a></div> 104 - <div class="w-5 flex-shrink-0 select-none text-center">{{ .Op.String }}</div> 105 - <div class="px-2">{{ .Line }}</div> 106 - </div> 107 - {{- $newStart = add64 $newStart 1 -}} 108 - {{- end -}} 109 - {{- if eq .Op.String "-" -}} 110 - <div class="bg-red-100 dark:bg-red-800/30 text-red-700 dark:text-red-400 flex min-w-full items-center"> 111 - <div class="{{$lineNrStyle}} {{$lineNrSepStyle1}}" id="{{$name}}-O{{$oldStart}}"><a class="{{$linkStyle}}" href="#{{$name}}-O{{$oldStart}}">{{ $oldStart }}</a></div> 112 - <div class="{{$lineNrStyle}} {{$lineNrSepStyle2}}"><span aria-hidden="true" class="invisible">{{$oldStart}}</span></div> 113 - <div class="w-5 flex-shrink-0 select-none text-center">{{ .Op.String }}</div> 114 - <div class="px-2">{{ .Line }}</div> 115 - </div> 116 - {{- $oldStart = add64 $oldStart 1 -}} 117 - {{- end -}} 118 - {{- if eq .Op.String " " -}} 119 - <div class="bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400 flex min-w-full items-center"> 120 - <div class="{{$lineNrStyle}} {{$lineNrSepStyle1}}" id="{{$name}}-O{{$oldStart}}"><a class="{{$linkStyle}}" href="#{{$name}}-O{{$oldStart}}">{{ $oldStart }}</a></div> 121 - <div class="{{$lineNrStyle}} {{$lineNrSepStyle2}}" id="{{$name}}-N{{$newStart}}"><a class="{{$linkStyle}}" href="#{{$name}}-N{{$newStart}}">{{ $newStart }}</a></div> 122 - <div class="w-5 flex-shrink-0 select-none text-center">{{ .Op.String }}</div> 123 - <div class="px-2">{{ .Line }}</div> 124 - </div> 125 - {{- $newStart = add64 $newStart 1 -}} 126 - {{- $oldStart = add64 $oldStart 1 -}} 127 - {{- end -}} 128 - {{- end -}} 129 - {{- end -}}</div></div></pre> 88 + {{ if $isSplit }} 89 + {{- template "repo/fragments/splitDiff" .Split -}} 90 + {{ else }} 91 + {{- template "repo/fragments/unifiedDiff" . -}} 92 + {{ end }} 130 93 {{- end -}} 131 94 </div> 132 95 ··· 103 134 </section> 104 135 {{ end }} 105 136 {{ end }} 137 + {{ end }} 138 + 139 + {{ define "unifiedDiffLines" }} 140 + {{ $name := .Name.New }} 141 + <pre class="overflow-x-auto"><div class="overflow-x-auto"><div class="min-w-full inline-block">{{- range .TextFragments -}}<div class="bg-gray-100 dark:bg-gray-700 text-gray-500 dark:text-gray-400 select-none text-center">&middot;&middot;&middot;</div> 142 + {{- $oldStart := .OldPosition -}} 143 + {{- $newStart := .NewPosition -}} 144 + {{- $lineNrStyle := "min-w-[3.5rem] flex-shrink-0 select-none text-right bg-white dark:bg-gray-800 target:bg-yellow-200 target:dark:bg-yellow-600" -}} 145 + {{- $linkStyle := "text-gray-400 dark:text-gray-500 hover:underline" -}} 146 + {{- $lineNrSepStyle1 := "" -}} 147 + {{- $lineNrSepStyle2 := "pr-2 border-r border-gray-200 dark:border-gray-700" -}} 148 + {{- $containerStyle := "flex min-w-full items-center target:border target:rounded-sm target:border-yellow-200 target:dark:border-yellow-700 scroll-mt-20" -}} 149 + {{- $addStyle := "bg-green-100 dark:bg-green-800/30 text-green-700 dark:text-green-400 " -}} 150 + {{- $delStyle := "bg-red-100 dark:bg-red-800/30 text-red-700 dark:text-red-400 " -}} 151 + {{- $ctxStyle := "bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400" -}} 152 + {{- $opStyle := "w-5 flex-shrink-0 select-none text-center" -}} 153 + {{- range .Lines -}} 154 + {{- if eq .Op.String "+" -}} 155 + <div class="{{ $addStyle }} {{ $containerStyle }}" id="{{$name}}-N{{$newStart}}"> 156 + <div class="{{$lineNrStyle}} {{$lineNrSepStyle1}}"><span aria-hidden="true" class="invisible">{{$newStart}}</span></div> 157 + <div class="{{$lineNrStyle}} {{$lineNrSepStyle2}}"><a class="{{$linkStyle}}" href="#{{$name}}-N{{$newStart}}">{{ $newStart }}</a></div> 158 + <div class="{{ $opStyle }}">{{ .Op.String }}</div> 159 + <div class="px-2">{{ .Line }}</div> 160 + </div> 161 + {{- $newStart = add64 $newStart 1 -}} 162 + {{- end -}} 163 + {{- if eq .Op.String "-" -}} 164 + <div class="{{ $delStyle }} {{ $containerStyle }}" id="{{$name}}-O{{$oldStart}}"> 165 + <div class="{{$lineNrStyle}} {{$lineNrSepStyle1}}"><a class="{{$linkStyle}}" href="#{{$name}}-O{{$oldStart}}">{{ $oldStart }}</a></div> 166 + <div class="{{$lineNrStyle}} {{$lineNrSepStyle2}}"><span aria-hidden="true" class="invisible">{{$oldStart}}</span></div> 167 + <div class="{{ $opStyle }}">{{ .Op.String }}</div> 168 + <div class="px-2">{{ .Line }}</div> 169 + </div> 170 + {{- $oldStart = add64 $oldStart 1 -}} 171 + {{- end -}} 172 + {{- if eq .Op.String " " -}} 173 + <div class="{{ $ctxStyle }} {{ $containerStyle }}" id="{{$name}}-O{{$oldStart}}-N{{$newStart}}"> 174 + <div class="{{$lineNrStyle}} {{$lineNrSepStyle1}}"><a class="{{$linkStyle}}" href="#{{$name}}-O{{$oldStart}}-N{{$newStart}}">{{ $oldStart }}</a></div> 175 + <div class="{{$lineNrStyle}} {{$lineNrSepStyle2}}"><a class="{{$linkStyle}}" href="#{{$name}}-O{{$oldStart}}-N{{$newStart}}">{{ $newStart }}</a></div> 176 + <div class="{{ $opStyle }}">{{ .Op.String }}</div> 177 + <div class="px-2">{{ .Line }}</div> 178 + </div> 179 + {{- $newStart = add64 $newStart 1 -}} 180 + {{- $oldStart = add64 $oldStart 1 -}} 181 + {{- end -}} 182 + {{- end -}} 183 + {{- end -}}</div></div></pre> 184 + {{ end }} 185 + 186 + {{ define "splitDiffLines" }} 187 + {{ $name := .Name.New }} 188 + {{- $lineNrStyle := "min-w-[3.5rem] flex-shrink-0 select-none text-right bg-white dark:bg-gray-800" -}} 189 + {{- $linkStyle := "text-gray-400 dark:text-gray-500 hover:underline" -}} 190 + {{- $lineNrSepStyle := "pr-2 border-r border-gray-200 dark:border-gray-700" -}} 191 + {{- $containerStyle := "flex min-w-full items-center target:border target:rounded-sm target:border-yellow-200 target:dark:border-yellow-700 scroll-mt-20" -}} 192 + {{- $emptyStyle := "bg-gray-200/30 dark:bg-gray-700/30" -}} 193 + {{- $addStyle := "bg-green-100 dark:bg-green-800/30 text-green-700 dark:text-green-400" -}} 194 + {{- $delStyle := "bg-red-100 dark:bg-red-800/30 text-red-700 dark:text-red-400 " -}} 195 + {{- $ctxStyle := "bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400" -}} 196 + {{- $opStyle := "w-5 flex-shrink-0 select-none text-center" -}} 197 + <div class="grid grid-cols-2 divide-x divide-gray-200 dark:divide-gray-700"> 198 + <pre class="overflow-x-auto col-span-1"><div class="overflow-x-auto"><div class="min-w-full inline-block">{{- range .TextFragments -}}<div class="bg-gray-100 dark:bg-gray-700 text-gray-500 dark:text-gray-400 select-none text-center">&middot;&middot;&middot;</div> 199 + {{- range .LeftLines -}} 200 + {{- if .IsEmpty -}} 201 + <div class="{{ $emptyStyle }} {{ $containerStyle }}"> 202 + <div class="{{$lineNrStyle}} {{$lineNrSepStyle}}"><span aria-hidden="true" class="invisible">{{.LineNumber}}</span></div> 203 + <div class="{{ $opStyle }}"><span aria-hidden="true" class="invisible">{{ .Op.String }}</span></div> 204 + <div class="px-2 invisible" aria-hidden="true">{{ .Content }}</div> 205 + </div> 206 + {{- else if eq .Op.String "-" -}} 207 + <div class="{{ $delStyle }} {{ $containerStyle }}" id="{{$name}}-O{{.LineNumber}}"> 208 + <div class="{{ $lineNrStyle }} {{ $lineNrSepStyle }}"><a class="{{$linkStyle}}" href="#{{$name}}-O{{.LineNumber}}">{{ .LineNumber }}</a></div> 209 + <div class="{{ $opStyle }}">{{ .Op.String }}</div> 210 + <div class="px-2">{{ .Content }}</div> 211 + </div> 212 + {{- else if eq .Op.String " " -}} 213 + <div class="{{ $ctxStyle }} {{ $containerStyle }}" id="{{$name}}-O{{.LineNumber}}"> 214 + <div class="{{ $lineNrStyle }} {{ $lineNrSepStyle }}"><a class="{{$linkStyle}}" href="#{{$name}}-O{{.LineNumber}}">{{ .LineNumber }}</a></div> 215 + <div class="{{ $opStyle }}">{{ .Op.String }}</div> 216 + <div class="px-2">{{ .Content }}</div> 217 + </div> 218 + {{- end -}} 219 + {{- end -}} 220 + {{- end -}}</div></div></pre> 221 + 222 + <pre class="overflow-x-auto col-span-1"><div class="overflow-x-auto"><div class="min-w-full inline-block">{{- range .TextFragments -}}<div class="bg-gray-100 dark:bg-gray-700 text-gray-500 dark:text-gray-400 select-none text-center">&middot;&middot;&middot;</div> 223 + {{- range .RightLines -}} 224 + {{- if .IsEmpty -}} 225 + <div class="{{ $emptyStyle }} {{ $containerStyle }}"> 226 + <div class="{{$lineNrStyle}} {{$lineNrSepStyle}}"><span aria-hidden="true" class="invisible">{{.LineNumber}}</span></div> 227 + <div class="{{ $opStyle }}"><span aria-hidden="true" class="invisible">{{ .Op.String }}</span></div> 228 + <div class="px-2 invisible" aria-hidden="true">{{ .Content }}</div> 229 + </div> 230 + {{- else if eq .Op.String "+" -}} 231 + <div class="{{ $addStyle }} {{ $containerStyle }}" id="{{$name}}-N{{.LineNumber}}"> 232 + <div class="{{$lineNrStyle}} {{$lineNrSepStyle}}"><a class="{{$linkStyle}}" href="#{{$name}}-N{{.LineNumber}}">{{ .LineNumber }}</a></div> 233 + <div class="{{ $opStyle }}">{{ .Op.String }}</div> 234 + <div class="px-2" >{{ .Content }}</div> 235 + </div> 236 + {{- else if eq .Op.String " " -}} 237 + <div class="{{ $ctxStyle }} {{ $containerStyle }}" id="{{$name}}-N{{.LineNumber}}"> 238 + <div class="{{$lineNrStyle}} {{$lineNrSepStyle}}"><a class="{{$linkStyle}}" href="#{{$name}}-N{{.LineNumber}}">{{ .LineNumber }}</a></div> 239 + <div class="{{ $opStyle }}">{{ .Op.String }}</div> 240 + <div class="px-2">{{ .Content }}</div> 241 + </div> 242 + {{- end -}} 243 + {{- end -}} 244 + {{- end -}}</div></div></pre> 245 + </div> 106 246 {{ end }} 107 247 108 248 {{ define "statPill" }} ··· 226 148 {{ end }} 227 149 </div> 228 150 {{ end }} 151 +
+1 -1
appview/pages/templates/repo/fragments/diffChangedFiles.html
··· 2 2 {{ $stat := .Stat }} 3 3 {{ $fileTree := fileTree .ChangedFiles }} 4 4 <div class="col-span-1 md:col-span-2 mt-4"> 5 - <section class="sticky top-0 overflow-x-auto px-6 py-4 border border-gray-200 dark:border-gray-700 w-full mx-auto rounded bg-white dark:bg-gray-800 drop-shadow-sm"> 5 + <section class="sticky top-0 overflow-x-auto text-sm px-6 py-2 border border-gray-200 dark:border-gray-700 w-full mx-auto md:min-h-screen rounded bg-white dark:bg-gray-800 drop-shadow-sm"> 6 6 <div class="diff-stat"> 7 7 <div class="flex gap-2 items-center"> 8 8 <strong class="text-sm uppercase dark:text-gray-200">Changed files</strong>
+1 -1
appview/pages/templates/repo/fragments/interdiffFiles.html
··· 1 1 {{ define "repo/fragments/interdiffFiles" }} 2 2 {{ $fileTree := fileTree .AffectedFiles }} 3 - <section class="mt-4 p-6 border border-gray-200 dark:border-gray-700 w-full mx-auto rounded bg-white dark:bg-gray-800 drop-shadow-sm"> 3 + <section class="mt-4 px-6 py-2 border border-gray-200 dark:border-gray-700 w-full mx-auto rounded bg-white dark:bg-gray-800 drop-shadow-sm md:min-h-screen text-sm"> 4 4 <div class="diff-stat"> 5 5 <div class="flex gap-2 items-center"> 6 6 <strong class="text-sm uppercase dark:text-gray-200">files</strong>
+1 -1
appview/pages/templates/repo/pulls/patch.html
··· 74 74 {{ end }} 75 75 76 76 {{ define "contentAfter" }} 77 - {{ template "repo/fragments/diff" (list .RepoInfo.FullName .Diff) }} 77 + {{ template "repo/fragments/diff" (list .RepoInfo.FullName .Diff .DiffOpts) }} 78 78 {{end}} 79 79 80 80 {{ define "contentAfterLeft" }}
-1
appview/pages/templates/repo/pulls/pull.html
··· 179 179 {{ end }} 180 180 </div> 181 181 </details> 182 - <hr class="md:hidden border-t border-gray-300 dark:border-gray-600"/> 183 182 {{ end }} 184 183 {{ end }} 185 184 {{ end }}
+6
appview/pulls/pulls.go
··· 355 355 return 356 356 } 357 357 358 + var diffOpts types.DiffOpts 359 + if d := r.URL.Query().Get("diff"); d == "split" { 360 + diffOpts.Split = true 361 + } 362 + 358 363 pull, ok := r.Context().Value("pull").(*db.Pull) 359 364 if !ok { 360 365 log.Println("failed to get pull") ··· 400 395 Round: roundIdInt, 401 396 Submission: pull.Submissions[roundIdInt], 402 397 Diff: &diff, 398 + DiffOpts: diffOpts, 403 399 }) 404 400 405 401 }
+12 -1
appview/repo/repo.go
··· 268 268 protocol = "https" 269 269 } 270 270 271 + var diffOpts types.DiffOpts 272 + if d := r.URL.Query().Get("diff"); d == "split" { 273 + diffOpts.Split = true 274 + } 275 + 271 276 if !plumbing.IsHash(ref) { 272 277 rp.pages.Error404(w) 273 278 return ··· 326 321 EmailToDidOrHandle: emailToDidOrHandle(rp, emailToDidMap), 327 322 VerifiedCommit: vc, 328 323 Pipeline: pipeline, 324 + DiffOpts: diffOpts, 329 325 }) 330 - return 331 326 } 332 327 333 328 func (rp *Repo) RepoTree(w http.ResponseWriter, r *http.Request) { ··· 1274 1269 return 1275 1270 } 1276 1271 1272 + var diffOpts types.DiffOpts 1273 + if d := r.URL.Query().Get("diff"); d == "split" { 1274 + diffOpts.Split = true 1275 + } 1276 + 1277 1277 // if user is navigating to one of 1278 1278 // /compare/{base}/{head} 1279 1279 // /compare/{base}...{head} ··· 1341 1331 Base: base, 1342 1332 Head: head, 1343 1333 Diff: &diff, 1334 + DiffOpts: diffOpts, 1344 1335 }) 1345 1336 1346 1337 }
+26
types/diff.go
··· 5 5 "github.com/go-git/go-git/v5/plumbing/object" 6 6 ) 7 7 8 + type DiffOpts struct { 9 + Split bool `json:"split"` 10 + } 11 + 8 12 type TextFragment struct { 9 13 Header string `json:"comment"` 10 14 Lines []gitdiff.Line `json:"lines"` ··· 80 76 } 81 77 82 78 return files 79 + } 80 + 81 + // used by html elements as a unique ID for hrefs 82 + func (d *Diff) Id() string { 83 + return d.Name.New 84 + } 85 + 86 + func (d *Diff) Split() *SplitDiff { 87 + fragments := make([]SplitFragment, len(d.TextFragments)) 88 + for i, fragment := range d.TextFragments { 89 + leftLines, rightLines := SeparateLines(&fragment) 90 + fragments[i] = SplitFragment{ 91 + Header: fragment.Header(), 92 + LeftLines: leftLines, 93 + RightLines: rightLines, 94 + } 95 + } 96 + 97 + return &SplitDiff{ 98 + Name: d.Id(), 99 + TextFragments: fragments, 100 + } 83 101 }