diff options
author | Anirudh Oppiliappan <x@icyphox.sh> | 2022-12-12 17:17:49 +0530 |
---|---|---|
committer | Anirudh Oppiliappan <x@icyphox.sh> | 2022-12-12 17:17:49 +0530 |
commit | c165c447685d68c2b0b2293a31937a903394f943 (patch) | |
tree | b2aa9f24cb263a2cc72c3167ec7233139e192c3a /routes | |
parent | ce71721c6dc80db8af63f2098a1548308e2621b2 (diff) | |
download | legit-c165c447685d68c2b0b2293a31937a903394f943.tar.gz legit-c165c447685d68c2b0b2293a31937a903394f943.tar.bz2 legit-c165c447685d68c2b0b2293a31937a903394f943.zip |
git, routes: commit diff view
Diffstat (limited to 'routes')
-rw-r--r-- | routes/handler.go | 1 | ||||
-rw-r--r-- | routes/routes.go | 36 |
2 files changed, 37 insertions, 0 deletions
diff --git a/routes/handler.go b/routes/handler.go index 5a1cff4..2625b43 100644 --- a/routes/handler.go +++ b/routes/handler.go @@ -12,5 +12,6 @@ func Handlers(c *config.Config) *flow.Mux { mux.HandleFunc("/:name/tree/:ref/...", d.RepoTree, "GET") mux.HandleFunc("/:name/blob/:ref/...", d.FileContent, "GET") mux.HandleFunc("/:name/log/:ref", d.Log, "GET") + mux.HandleFunc("/:name/commit/:ref", d.Diff, "GET") return mux } diff --git a/routes/routes.go b/routes/routes.go index f1eef06..f7a36c6 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -127,3 +127,39 @@ func (d *deps) Log(w http.ResponseWriter, r *http.Request) { return } } + +func (d *deps) Diff(w http.ResponseWriter, r *http.Request) { + name := flow.Param(r.Context(), "name") + ref := flow.Param(r.Context(), "ref") + + path := filepath.Join(d.c.Git.ScanPath, name+".git") + gr, err := git.Open(path, ref) + if err != nil { + Write404(w, *d.c) + return + } + + diff, err := gr.Diff() + if err != nil { + Write500(w, *d.c) + log.Println(err) + return + } + + tpath := filepath.Join(d.c.Template.Dir, "*") + t := template.Must(template.ParseGlob(tpath)) + + data := make(map[string]interface{}) + + data["commit"] = diff.Commit + data["stat"] = diff.Stat + data["diff"] = diff.Diff + data["meta"] = d.c.Meta + data["name"] = name + data["ref"] = ref + + if err := t.ExecuteTemplate(w, "commit", data); err != nil { + log.Println(err) + return + } +} |