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_raw.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'http_handle_repo_raw.go') 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 -- cgit v1.2.3