diff options
author | Runxi Yu <me@runxiyu.org> | 2025-02-14 11:22:17 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-02-14 11:22:17 +0800 |
commit | 21c667435ab5394fe0dd86314c61256ea9b44711 (patch) | |
tree | 13325aebe9a94e909393c14ae60961d8c01673c8 | |
parent | http_server.go: Rename dir_mode to trailing_slash (diff) | |
download | forge-21c667435ab5394fe0dd86314c61256ea9b44711.tar.gz forge-21c667435ab5394fe0dd86314c61256ea9b44711.tar.zst forge-21c667435ab5394fe0dd86314c61256ea9b44711.zip |
repo_index: Allow refspecs
-rw-r--r-- | http_handle_repo_index.go | 11 | ||||
-rw-r--r-- | templates/repo_index.html.tmpl | 5 |
2 files changed, 9 insertions, 7 deletions
diff --git a/http_handle_repo_index.go b/http_handle_repo_index.go index 4eb2c97..daeabca 100644 --- a/http_handle_repo_index.go +++ b/http_handle_repo_index.go @@ -12,19 +12,20 @@ func handle_repo_index(w http.ResponseWriter, r *http.Request, params map[string return } params["repo_description"] = description - head, err := repo.Head() + + 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 HEAD: "+err.Error(), http.StatusInternalServerError) + http.Error(w, "Error getting ref hash: "+err.Error(), http.StatusInternalServerError) return } - head_hash := head.Hash() - recent_commits, err := get_recent_commits(repo, head_hash, 3) + + recent_commits, err := get_recent_commits(repo, ref_hash, 3) if err != nil { http.Error(w, "Error getting recent commits: "+err.Error(), http.StatusInternalServerError) return } params["commits"] = recent_commits - commit_object, err := repo.CommitObject(head_hash) + commit_object, err := repo.CommitObject(ref_hash) if err != nil { http.Error(w, "Error getting commit object: "+err.Error(), http.StatusInternalServerError) return diff --git a/templates/repo_index.html.tmpl b/templates/repo_index.html.tmpl index 7faea1e..80300d2 100644 --- a/templates/repo_index.html.tmpl +++ b/templates/repo_index.html.tmpl @@ -60,15 +60,16 @@ <table id="file-tree" class="wide"> <thead> <tr class="title-row"> - <th colspan="3"><label for="toggle-table-file-tree">/ on {{ .ref_name }}</label></th> + <th colspan="3"><label for="toggle-table-file-tree">/{{ if .ref_name }} on {{ .ref_name }}{{ end }}</label></th> </tr> </thead> <tbody> + {{- $ref_type := .ref_type }} {{- $ref := .ref_name }} {{- range .files }} <tr> <td class="file-mode">{{ .Mode }}</td> - <td class="file-name"><a href="tree/{{ .Name }}">{{ .Name }}</a>{{ if not .Is_file }}/{{ end }}</td> + <td class="file-name"><a href="tree/{{ .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 }} |