diff options
author | Anirudh Oppiliappan <x@icyphox.sh> | 2022-12-17 22:35:48 +0530 |
---|---|---|
committer | Anirudh Oppiliappan <x@icyphox.sh> | 2022-12-17 22:35:48 +0530 |
commit | 3e6a720154b70a9882af14399548e494b1d0089f (patch) | |
tree | 6926af0c380ce3eb303af05d664a78962083d546 | |
parent | 5091695e75b2db30b8926d8aa17164c84031bc77 (diff) | |
download | legit-3e6a720154b70a9882af14399548e494b1d0089f.tar.gz legit-3e6a720154b70a9882af14399548e494b1d0089f.tar.bz2 legit-3e6a720154b70a9882af14399548e494b1d0089f.zip |
git, templates: diff view
-rw-r--r-- | git/diff.go | 2 | ||||
-rw-r--r-- | go.mod | 6 | ||||
-rw-r--r-- | go.sum | 3 | ||||
-rw-r--r-- | routes/routes.go | 1 | ||||
-rw-r--r-- | static/style.css | 38 | ||||
-rw-r--r-- | templates/commit.html | 56 | ||||
-rw-r--r-- | templates/log.html | 4 | ||||
-rw-r--r-- | 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 @@ -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 @@ -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 @@ <body> {{ template "nav" . }} <main> - <section> - <p>author: {{ .commit.Author.Name }} <{{ .commit.Author.Email}}> on {{ .commit.Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</p> + <section class="commit"> + <pre> + {{- .commit.Message -}} + </pre> + <p>{{ .commit.Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</p> + <p>{{ .commit.Author.Name }} <span class="commit-email">{{ .commit.Author.Email}}</span></p> <p>commit: <a href="/{{ .name }}/commit/{{ .commit.This }}"> {{ .commit.This }} </a> @@ -19,34 +23,54 @@ {{ .commit.Parent }} </a> </p> - <p>{{ .stat.FilesChanged }} files changed, + <div class="diff-stat"> + <div> + {{ .stat.FilesChanged }} files changed, {{ .stat.Insertions }} insertions(+), {{ .stat.Deletions }} deletions(-) - </p> + </div> + <div> + <br> + <p>jump to:</p> + {{ range .diff }} + <ul> + <li><a href="#{{ .Name.New }}">{{ .Name.New }}</a></li> + </ul> + {{ end }} + </div> + </div> </section> <section> + {{ $repo := .name }} + {{ $this := .commit.This }} {{ range .diff }} + <div class="diff"> + <div id="{{ .Name.New }}"> {{ if .Name.Old }} - <p>{{ .Name.Old }} → {{ .Name.New }}</p> + <a href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.Old }}">{{ .Name.Old }}</a> → + <a href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}">{{ .Name.New }}</a> {{ else }} - <p>{{.Name.New }}</p> + <a href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}">{{ .Name.New }}</a> {{- end -}} + </div> + <pre> {{- range .TextFragments -}} <p>{{- .Header -}}</p> - {{- range .Lines -}} - {{- if eq .Op.String "+" -}} - <span style="color: green">{{ .String }}</span> - {{- end -}} - {{- if eq .Op.String "-" -}} - <span style="color: red">{{ .String }}</span> - {{- end -}} - {{- if eq .Op.String " " -}} - <span style="color: gray">{{ .String }}</span> - {{- end -}} + {{- range .Lines -}} + {{- if eq .Op.String "+" -}} + <span class="diff-add">{{ .String }}</span> {{- end -}} + {{- if eq .Op.String "-" -}} + <span class="diff-del">{{ .String }}</span> + {{- end -}} + {{- if eq .Op.String " " -}} + <span class="diff-noop">{{ .String }}</span> + {{- end -}} + {{- end -}} {{- end -}} </pre> + </div> {{ end }} </section> </main> 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 @@ <body> {{ template "nav" . }} <main> - {{ $repo := .repo }} + {{ $repo := .name }} <div class="log"> {{ range .commits }} <div> @@ -17,7 +17,7 @@ <div>{{ .Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</div> <pre>{{ .Message }}</pre> </div> - <div class="commit-info">{{ .Author.Name }} <span style="color: var(--gray);">{{ .Author.Email }}</span></div> + <div class="commit-info">{{ .Author.Name }} <span class="commit-email">{{ .Author.Email }}</span></div> {{ end }} </div> </main> 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 @@ <div>{{ .Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</div> <pre>{{ .Message }}</pre> </div> - <div class="commit-info">{{ .Author.Name }} <span style="color: var(--gray);">{{ .Author.Email }}</span></div> + <div class="commit-info">{{ .Author.Name }} <span class="commit-email">{{ .Author.Email }}</span></div> {{ end }} </div> <article class="readme"> |