From 3e6a720154b70a9882af14399548e494b1d0089f Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Sat, 17 Dec 2022 22:35:48 +0530 Subject: git, templates: diff view --- git/diff.go | 2 +- go.mod | 6 ++++-- go.sum | 3 +-- routes/routes.go | 1 + static/style.css | 38 ++++++++++++++++++++++++++++++++++ templates/commit.html | 56 ++++++++++++++++++++++++++++++++++++--------------- templates/log.html | 4 ++-- templates/repo.html | 2 +- 8 files changed, 88 insertions(+), 24 deletions(-) diff --git a/git/diff.go b/git/diff.go index f7e5b0e..4b42b9a 100644 --- a/git/diff.go +++ b/git/diff.go @@ -69,9 +69,9 @@ func (g *GitRepo) Diff() (*NiceDiff, error) { nd.Commit.Parent = parent.Hash.String() nd.Commit.Author = c.Author nd.Commit.Message = c.Message - ndiff := Diff{} for _, d := range diffs { + ndiff := Diff{} ndiff.Name.New = d.NewName ndiff.Name.Old = d.OldName diff --git a/go.mod b/go.mod index 4ce85ba..3987517 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/bluekeyes/go-gitdiff v0.7.0 github.com/dustin/go-humanize v1.0.0 github.com/go-git/go-git/v5 v5.5.1 + github.com/sosedoff/gitkit v0.3.0 gopkg.in/yaml.v3 v3.0.0 ) @@ -23,9 +24,8 @@ require ( github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/pjbgf/sha1cd v0.2.3 // indirect - github.com/sergi/go-diff v1.2.0 // indirect + github.com/sergi/go-diff v1.1.0 // indirect github.com/skeema/knownhosts v1.1.0 // indirect - github.com/sosedoff/gitkit v0.3.0 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect golang.org/x/crypto v0.4.0 // indirect golang.org/x/mod v0.7.0 // indirect @@ -34,3 +34,5 @@ require ( golang.org/x/tools v0.4.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect ) + +exclude github.com/sergi/go-diff v1.2.0 diff --git a/go.sum b/go.sum index c6865e9..fe607da 100644 --- a/go.sum +++ b/go.sum @@ -62,9 +62,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= -github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= -github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/skeema/knownhosts v1.1.0 h1:Wvr9V0MxhjRbl3f9nMnKnFfiWTJmtECJ9Njkea3ysW0= github.com/skeema/knownhosts v1.1.0/go.mod h1:sKFq3RD6/TKZkSWn8boUbDC7Qkgcv+8XXijpFO6roag= diff --git a/routes/routes.go b/routes/routes.go index f52e86a..7e2e897 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -188,6 +188,7 @@ func (d *deps) Log(w http.ResponseWriter, r *http.Request) { } commits, err := gr.Commits() + log.Println(len(commits)) if err != nil { d.Write500(w) log.Println(err) diff --git a/static/style.css b/static/style.css index df2c81c..0b0664f 100644 --- a/static/style.css +++ b/static/style.css @@ -146,6 +146,44 @@ a:hover { white-space: pre-wrap; } +.diff { + padding-top: 1rem; +} + +.diff pre { + overflow: scroll; +} + +.diff-stat { + padding: 1rem 0 1rem 0; +} + +.commit-email { + color: var(--gray); +} + +.commit pre { + padding-bottom: 1rem; + white-space: pre-wrap; +} + +.diff-stat ul li { + list-style: none; + padding-left: 0.5em; +} + +.diff-add { + color: green; +} + +.diff-del { + color: red; +} + +.diff-noop { + color: var(--gray); +} + @media (max-width: 600px) { .index { grid-row-gap: 0.8em; diff --git a/templates/commit.html b/templates/commit.html index f7a36b4..b4061aa 100644 --- a/templates/commit.html +++ b/templates/commit.html @@ -9,8 +9,12 @@ {{ template "nav" . }}
-
-

author: {{ .commit.Author.Name }} <{{ .commit.Author.Email}}> on {{ .commit.Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}

+
+
+          {{- .commit.Message -}}
+        
+

{{ .commit.Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}

+

{{ .commit.Author.Name }} {{ .commit.Author.Email}}

commit: {{ .commit.This }} @@ -19,34 +23,54 @@ {{ .commit.Parent }}

-

{{ .stat.FilesChanged }} files changed, +

+
+ {{ .stat.FilesChanged }} files changed, {{ .stat.Insertions }} insertions(+), {{ .stat.Deletions }} deletions(-) -

+
+
+
+

jump to:

+ {{ range .diff }} + + {{ end }} +
+
+ {{ $repo := .name }} + {{ $this := .commit.This }} {{ range .diff }} +
+
{{ if .Name.Old }} -

{{ .Name.Old }} → {{ .Name.New }}

+ {{ .Name.Old }} → + {{ .Name.New }} {{ else }} -

{{.Name.New }}

+ {{ .Name.New }} {{- end -}} +
+
             {{- range .TextFragments -}}
             

{{- .Header -}}

- {{- range .Lines -}} - {{- if eq .Op.String "+" -}} - {{ .String }} - {{- end -}} - {{- if eq .Op.String "-" -}} - {{ .String }} - {{- end -}} - {{- if eq .Op.String " " -}} - {{ .String }} - {{- end -}} + {{- range .Lines -}} + {{- if eq .Op.String "+" -}} + {{ .String }} {{- end -}} + {{- if eq .Op.String "-" -}} + {{ .String }} + {{- end -}} + {{- if eq .Op.String " " -}} + {{ .String }} + {{- end -}} + {{- end -}} {{- end -}}
+
{{ end }}
diff --git a/templates/log.html b/templates/log.html index c4ee9c3..4a0292c 100644 --- a/templates/log.html +++ b/templates/log.html @@ -9,7 +9,7 @@ {{ template "nav" . }}
- {{ $repo := .repo }} + {{ $repo := .name }}
{{ range .commits }}
@@ -17,7 +17,7 @@
{{ .Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}
{{ .Message }}
-
{{ .Author.Name }} {{ .Author.Email }}
+
{{ .Author.Name }} {{ .Author.Email }}
{{ end }}
diff --git a/templates/repo.html b/templates/repo.html index d4e3e46..3b5d2b0 100644 --- a/templates/repo.html +++ b/templates/repo.html @@ -25,7 +25,7 @@
{{ .Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}
{{ .Message }}
-
{{ .Author.Name }} {{ .Author.Email }}
+
{{ .Author.Name }} {{ .Author.Email }}
{{ end }}
-- cgit