From c165c447685d68c2b0b2293a31937a903394f943 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Mon, 12 Dec 2022 17:17:49 +0530 Subject: git, routes: commit diff view --- routes/routes.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'routes/routes.go') 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 + } +} -- cgit