From e347064abe3ce4c90fbad23d36e5d61a149e2389 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Fri, 14 Feb 2025 08:48:07 +0800 Subject: http_*: Refactor to reduce duplication --- http_handle_repo_tree.go | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'http_handle_repo_tree.go') 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 -- cgit v1.2.3