git, templates: diff view
This commit is contained in:
parent
5091695e75
commit
3e6a720154
|
@ -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
|
||||
|
||||
|
|
6
go.mod
6
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
|
||||
|
|
3
go.sum
3
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=
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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>
|
||||
<span class="diff-add">{{ .String }}</span>
|
||||
{{- end -}}
|
||||
{{- if eq .Op.String "-" -}}
|
||||
<span style="color: red">{{ .String }}</span>
|
||||
<span class="diff-del">{{ .String }}</span>
|
||||
{{- end -}}
|
||||
{{- if eq .Op.String " " -}}
|
||||
<span style="color: gray">{{ .String }}</span>
|
||||
<span class="diff-noop">{{ .String }}</span>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
</pre>
|
||||
</div>
|
||||
{{ end }}
|
||||
</section>
|
||||
</main>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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">
|
||||
|
|
Loading…
Reference in New Issue