aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-14 11:29:49 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-14 11:31:32 +0800
commit3f44e5773e9edd3044cd5235a36a06d01de13e31 (patch)
tree26fdb7daa55e3b5c9e69aa57592eb7059d365810
parenthttp_handle_repo_*.go: Remove redundant return (diff)
downloadforge-3f44e5773e9edd3044cd5235a36a06d01de13e31.tar.gz
forge-3f44e5773e9edd3044cd5235a36a06d01de13e31.tar.zst
forge-3f44e5773e9edd3044cd5235a36a06d01de13e31.zip
repo_log: Use parameters for refspec
-rw-r--r--http_handle_repo_log.go12
-rw-r--r--http_server.go10
-rw-r--r--templates/repo_index.html.tmpl2
-rw-r--r--templates/repo_log.html.tmpl2
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 @@
<table id="recent-commits" class="wide">
<thead>
<tr class="title-row">
- <th colspan="3"><label for="toggle-table-recent-commits">Recent Commits (<a href="log/{{ .ref_name }}/">see all</a>)</label></th>
+ <th colspan="3"><label for="toggle-table-recent-commits">Recent Commits (<a href="log/{{ if .ref_type }}?{{ .ref_type }}={{ .ref_name }}{{ end }}">see all</a>)</label></th>
</tr>
</thead>
<tbody>
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 @@
<table id="commits" class="wide">
<thead>
<tr class="title-row">
- <th colspan="4">Commits on {{ .ref_name }}</th>
+ <th colspan="4">Commits {{ if .ref_name }} on {{ .ref_name }}{{ end }}</th>
</tr>
<tr>
<th scope="col">ID</th>