From 3f44e5773e9edd3044cd5235a36a06d01de13e31 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Fri, 14 Feb 2025 11:29:49 +0800 Subject: repo_log: Use parameters for refspec --- http_handle_repo_log.go | 12 +++++------- http_server.go | 10 +++------- templates/repo_index.html.tmpl | 2 +- templates/repo_log.html.tmpl | 2 +- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/http_handle_repo_log.go b/http_handle_repo_log.go index b37923b..cbc3284 100644 --- a/http_handle_repo_log.go +++ b/http_handle_repo_log.go @@ -2,25 +2,23 @@ package main import ( "net/http" - - "github.com/go-git/go-git/v5/plumbing" ) // TODO: I probably shouldn't include *all* commits here... func handle_repo_log(w http.ResponseWriter, r *http.Request, params map[string]any) { - group_name, repo_name, ref_name := params["group_name"].(string), params["repo_name"].(string), params["ref_name"].(string) - repo, description, err := open_git_repo(r.Context(), group_name, repo_name) + repo, description, err := open_git_repo(r.Context(), params["group_name"].(string), params["repo_name"].(string)) if err != nil { http.Error(w, "Error opening repo: "+err.Error(), http.StatusInternalServerError) return } params["repo_description"] = description - ref, err := repo.Reference(plumbing.NewBranchReferenceName(ref_name), true) + + ref_hash, err := get_ref_hash_from_type_and_name(repo, params["ref_type"].(string), params["ref_name"].(string)) if err != nil { - http.Error(w, "Error getting repo reference: "+err.Error(), http.StatusInternalServerError) + http.Error(w, "Error getting ref hash: "+err.Error(), http.StatusInternalServerError) return } - ref_hash := ref.Hash() + commits, err := get_recent_commits(repo, ref_hash, -1) if err != nil { http.Error(w, "Error getting recent commits: "+err.Error(), http.StatusInternalServerError) diff --git a/http_server.go b/http_server.go index fc92ef1..16c30d5 100644 --- a/http_server.go +++ b/http_server.go @@ -142,18 +142,14 @@ func (router *http_router_t) ServeHTTP(w http.ResponseWriter, r *http.Request) { params["rest"] = strings.Join(segments[separator_index+4:], "/") handle_repo_raw(w, r, params) case "log": - if non_empty_last_segments_len > separator_index+5 { + if non_empty_last_segments_len > separator_index+4 { http.Error(w, "Too many parameters", http.StatusBadRequest) return - } else if non_empty_last_segments_len < separator_index+5 { - http.Error(w, "Insufficient parameters", http.StatusBadRequest) - return } - if trailing_slash { - http.Redirect(w, r, strings.TrimSuffix(r.URL.Path, "/"), http.StatusSeeOther) + if !trailing_slash { + http.Redirect(w, r, r.URL.Path+"/", http.StatusSeeOther) return } - params["ref_name"] = segments[separator_index+4] handle_repo_log(w, r, params) case "commit": if trailing_slash { diff --git a/templates/repo_index.html.tmpl b/templates/repo_index.html.tmpl index 80300d2..14d2a5d 100644 --- a/templates/repo_index.html.tmpl +++ b/templates/repo_index.html.tmpl @@ -37,7 +37,7 @@ - + diff --git a/templates/repo_log.html.tmpl b/templates/repo_log.html.tmpl index 88b978d..fa29fa5 100644 --- a/templates/repo_log.html.tmpl +++ b/templates/repo_log.html.tmpl @@ -11,7 +11,7 @@
- + -- cgit v1.2.3
Commits on {{ .ref_name }}Commits {{ if .ref_name }} on {{ .ref_name }}{{ end }}
ID