-
Notifications
You must be signed in to change notification settings - Fork 3
/
diff.go
63 lines (51 loc) · 1.29 KB
/
diff.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package server
import (
"net/http"
"github.com/knoebber/dotfile/db"
"github.com/knoebber/dotfile/dotfile"
)
// Loads a diff: ?on VS ?against.
func loadDiff(w http.ResponseWriter, r *http.Request, p *Page) (done bool) {
// TODO add line numbers to diff template
alias := p.Vars["alias"]
username := p.Vars["username"]
on := r.URL.Query().Get("on")
against := r.URL.Query().Get("against")
commits, err := db.CommitList(db.Connection, username, alias, p.Timezone())
if err != nil {
return p.setError(w, err)
}
for i, c := range commits {
if c.Message == "" {
commits[i].Message = c.DateString
}
if on != "" {
continue
}
// Set 'on' to the commit before against.
if c.Hash == against && i != len(commits)-1 {
on = commits[i+1].Hash
}
}
p.Data["commits"] = commits
p.Data["alias"] = alias
p.Data["against"] = against
p.Data["on"] = on
if on == "" || against == "" {
return
}
content := &db.FileContent{Connection: db.Connection, Username: username, Alias: alias}
diff, err := dotfile.DiffPrettyHTML(content, on, against)
if err != nil {
return p.setError(w, err)
}
p.Data["diff"] = diff
return
}
func diffHandler() http.HandlerFunc {
return createHandler(&pageDescription{
templateName: "diff.tmpl",
title: "diff",
loadData: loadDiff,
})
}