aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--git_ref.go2
-rw-r--r--http_handle_repo_index.go1
-rw-r--r--http_handle_repo_log.go2
-rw-r--r--http_handle_repo_raw.go15
-rw-r--r--http_handle_repo_tree.go14
-rw-r--r--http_server.go16
-rw-r--r--templates/repo_index.html.tmpl6
-rw-r--r--templates/repo_log.html.tmpl2
-rw-r--r--templates/repo_raw_dir.html.tmpl6
-rw-r--r--templates/repo_tree_dir.html.tmpl6
-rw-r--r--templates/repo_tree_file.html.tmpl2
11 files changed, 31 insertions, 41 deletions
diff --git a/git_ref.go b/git_ref.go
index 08d757b..46f08e0 100644
--- a/git_ref.go
+++ b/git_ref.go
@@ -16,7 +16,7 @@ var (
func get_ref_hash_from_type_and_name(repo *git.Repository, ref_type, ref_name string) (ref_hash plumbing.Hash, ret_err error) {
switch ref_type {
- case "head":
+ case "":
head, err := repo.Head()
if err != nil {
ret_err = misc.Wrap_one_error(err_getting_head, err)
diff --git a/http_handle_repo_index.go b/http_handle_repo_index.go
index c9c4949..ea1854e 100644
--- a/http_handle_repo_index.go
+++ b/http_handle_repo_index.go
@@ -17,7 +17,6 @@ func handle_repo_index(w http.ResponseWriter, r *http.Request, params map[string
http.Error(w, "Error getting repo HEAD: "+err.Error(), http.StatusInternalServerError)
return
}
- params["ref"] = head.Name().Short()
head_hash := head.Hash()
recent_commits, err := get_recent_commits(repo, head_hash, 3)
if err != nil {
diff --git a/http_handle_repo_log.go b/http_handle_repo_log.go
index 72943be..d4422b7 100644
--- a/http_handle_repo_log.go
+++ b/http_handle_repo_log.go
@@ -8,7 +8,7 @@ import (
// 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"].(string)
+ 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)
if err != nil {
http.Error(w, "Error opening repo: "+err.Error(), http.StatusInternalServerError)
diff --git a/http_handle_repo_raw.go b/http_handle_repo_raw.go
index b134f8d..1d04f6c 100644
--- a/http_handle_repo_raw.go
+++ b/http_handle_repo_raw.go
@@ -1,7 +1,6 @@
package main
import (
- "errors"
"fmt"
"net/http"
"path"
@@ -14,17 +13,7 @@ func handle_repo_raw(w http.ResponseWriter, r *http.Request, params map[string]a
raw_path_spec := params["rest"].(string)
group_name, repo_name, path_spec := params["group_name"].(string), params["repo_name"].(string), strings.TrimSuffix(raw_path_spec, "/")
- ref_type, ref_name, err := get_param_ref_and_type(r)
- if err != nil {
- if errors.Is(err, err_no_ref_spec) {
- ref_type = "head"
- } else {
- http.Error(w, "Error querying ref type: "+err.Error(), http.StatusInternalServerError)
- return
- }
- }
-
- params["ref_type"], params["ref"], params["path_spec"] = ref_type, ref_name, path_spec
+ params["path_spec"] = path_spec
repo, description, err := open_git_repo(r.Context(), group_name, repo_name)
if err != nil {
@@ -33,7 +22,7 @@ func handle_repo_raw(w http.ResponseWriter, r *http.Request, params map[string]a
}
params["repo_description"] = description
- ref_hash, err := get_ref_hash_from_type_and_name(repo, ref_type, ref_name)
+ 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 ref hash: "+err.Error(), http.StatusInternalServerError)
return
diff --git a/http_handle_repo_tree.go b/http_handle_repo_tree.go
index 69bc40f..f5fbaad 100644
--- a/http_handle_repo_tree.go
+++ b/http_handle_repo_tree.go
@@ -2,7 +2,6 @@ package main
import (
"bytes"
- "errors"
"html/template"
"net/http"
"path"
@@ -17,16 +16,7 @@ import (
func handle_repo_tree(w http.ResponseWriter, r *http.Request, params map[string]any) {
raw_path_spec := params["rest"].(string)
group_name, repo_name, path_spec := params["group_name"].(string), params["repo_name"].(string), strings.TrimSuffix(raw_path_spec, "/")
- ref_type, ref_name, err := get_param_ref_and_type(r)
- if err != nil {
- if errors.Is(err, err_no_ref_spec) {
- ref_type = "head"
- } else {
- http.Error(w, "Error querying ref type: "+err.Error(), http.StatusInternalServerError)
- return
- }
- }
- params["ref_type"], params["ref"], params["path_spec"] = ref_type, ref_name, path_spec
+ params["path_spec"] = path_spec
repo, description, err := open_git_repo(r.Context(), group_name, repo_name)
if err != nil {
http.Error(w, "Error opening repo: "+err.Error(), http.StatusInternalServerError)
@@ -34,7 +24,7 @@ func handle_repo_tree(w http.ResponseWriter, r *http.Request, params map[string]
}
params["repo_description"] = description
- ref_hash, err := get_ref_hash_from_type_and_name(repo, ref_type, ref_name)
+ 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 ref hash: "+err.Error(), http.StatusInternalServerError)
return
diff --git a/http_server.go b/http_server.go
index 3804df7..6626ae4 100644
--- a/http_server.go
+++ b/http_server.go
@@ -113,6 +113,15 @@ func (router *http_router_t) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch module_type {
case "repos":
params["repo_name"] = module_name
+ params["ref_type"], params["ref_name"], err = get_param_ref_and_type(r)
+ if err != nil {
+ if errors.Is(err, err_no_ref_spec) {
+ params["ref_type"] = ""
+ } else {
+ http.Error(w, "Error querying ref type: "+err.Error(), http.StatusInternalServerError)
+ return
+ }
+ }
// TODO: subgroups
if non_empty_last_segments_len == separator_index+3 {
if !dir_mode {
@@ -133,15 +142,18 @@ 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+5 {
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 dir_mode {
http.Redirect(w, r, strings.TrimSuffix(r.URL.Path, "/"), http.StatusSeeOther)
return
}
- params["ref"] = segments[separator_index+4]
+ params["ref_name"] = segments[separator_index+4]
handle_repo_log(w, r, params)
case "commit":
if dir_mode {
diff --git a/templates/repo_index.html.tmpl b/templates/repo_index.html.tmpl
index f6615d7..7faea1e 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 }}/">see all</a>)</label></th>
+ <th colspan="3"><label for="toggle-table-recent-commits">Recent Commits (<a href="log/{{ .ref_name }}/">see all</a>)</label></th>
</tr>
</thead>
<tbody>
@@ -60,11 +60,11 @@
<table id="file-tree" class="wide">
<thead>
<tr class="title-row">
- <th colspan="3"><label for="toggle-table-file-tree">/ on {{ .ref }}</label></th>
+ <th colspan="3"><label for="toggle-table-file-tree">/ on {{ .ref_name }}</label></th>
</tr>
</thead>
<tbody>
- {{- $ref := .ref }}
+ {{- $ref := .ref_name }}
{{- range .files }}
<tr>
<td class="file-mode">{{ .Mode }}</td>
diff --git a/templates/repo_log.html.tmpl b/templates/repo_log.html.tmpl
index 0ad6f39..88b978d 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 }}</th>
+ <th colspan="4">Commits on {{ .ref_name }}</th>
</tr>
<tr>
<th scope="col">ID</th>
diff --git a/templates/repo_raw_dir.html.tmpl b/templates/repo_raw_dir.html.tmpl
index dc1a5b6..d306bbf 100644
--- a/templates/repo_raw_dir.html.tmpl
+++ b/templates/repo_raw_dir.html.tmpl
@@ -12,18 +12,18 @@
<thead>
<tr class="title-row">
<th colspan="3">
- (Raw) /{{ .path_spec }}{{ if ne .path_spec "" }}/{{ end }}{{ if .ref }} on {{ .ref }}{{ end }}
+ (Raw) /{{ .path_spec }}{{ if ne .path_spec "" }}/{{ end }}{{ if .ref_name }} on {{ .ref_name }}{{ end }}
</th>
</tr>
</thead>
<tbody>
{{- $path_spec := .path_spec }}
- {{- $ref := .ref }}
+ {{- $ref := .ref_name }}
{{- $ref_type := .ref_type }}
{{- range .files }}
<tr>
<td class="file-mode">{{ .Mode }}</td>
- <td class="file-name"><a href="{{ .Name }}{{ if not .Is_file }}/{{ end }}{{ if $ref }}?{{ $ref_type }}={{ $ref }}{{ end }}">{{ .Name }}</a>{{ if not .Is_file }}/{{ end }}</td>
+ <td class="file-name"><a href="{{ .Name }}{{ if not .Is_file }}/{{ end }}{{ if $ref_type }}?{{ $ref_type }}={{ $ref }}{{ end }}">{{ .Name }}</a>{{ if not .Is_file }}/{{ end }}</td>
<td class="file-size">{{ .Size }}</td>
</tr>
{{- end }}
diff --git a/templates/repo_tree_dir.html.tmpl b/templates/repo_tree_dir.html.tmpl
index 5e56dc9..34559da 100644
--- a/templates/repo_tree_dir.html.tmpl
+++ b/templates/repo_tree_dir.html.tmpl
@@ -12,18 +12,18 @@
<thead>
<tr class="title-row">
<th colspan="3">
- /{{ .path_spec }}{{ if ne .path_spec "" }}/{{ end }}{{ if .ref }} on {{ .ref }}{{ end }}
+ /{{ .path_spec }}{{ if ne .path_spec "" }}/{{ end }}{{ if .ref_name }} on {{ .ref_name }}{{ end }}
</th>
</tr>
</thead>
<tbody>
{{- $path_spec := .path_spec }}
- {{- $ref := .ref }}
+ {{- $ref := .ref_name }}
{{- $ref_type := .ref_type }}
{{- range .files }}
<tr>
<td class="file-mode">{{ .Mode }}</td>
- <td class="file-name"><a href="{{ .Name }}{{ if not .Is_file }}/{{ end }}{{ if $ref }}?{{ $ref_type }}={{ $ref }}{{ end }}">{{ .Name }}</a>{{ if not .Is_file }}/{{ end }}</td>
+ <td class="file-name"><a href="{{ .Name }}{{ if not .Is_file }}/{{ end }}{{ if $ref_type }}?{{ $ref_type }}={{ $ref }}{{ end }}">{{ .Name }}</a>{{ if not .Is_file }}/{{ end }}</td>
<td class="file-size">{{ .Size }}</td>
</tr>
{{- end }}
diff --git a/templates/repo_tree_file.html.tmpl b/templates/repo_tree_file.html.tmpl
index 0bf9164..8eacd28 100644
--- a/templates/repo_tree_file.html.tmpl
+++ b/templates/repo_tree_file.html.tmpl
@@ -10,7 +10,7 @@
{{ template "header" . }}
<div class="padding">
<p>
- /{{ .path_spec }} (<a href="/{{ .group_name }}/:/repos/{{ .repo_name }}/raw/{{ .path_spec }}{{ if .ref }}?{{ .ref_type }}={{ .ref }}{{ end }}">raw</a>)
+ /{{ .path_spec }} (<a href="/{{ .group_name }}/:/repos/{{ .repo_name }}/raw/{{ .path_spec }}{{ if .ref_type }}?{{ .ref_type }}={{ .ref_name }}{{ end }}">raw</a>)
</p>
{{ .file_contents }}
</div>