diff options
-rw-r--r-- | http_handle_repo_commit.go | 10 | ||||
-rw-r--r-- | http_handle_repo_index.go | 10 | ||||
-rw-r--r-- | http_handle_repo_log.go | 9 | ||||
-rw-r--r-- | http_handle_repo_raw.go | 11 | ||||
-rw-r--r-- | http_handle_repo_tree.go | 9 | ||||
-rw-r--r-- | http_server.go | 40 |
6 files changed, 42 insertions, 47 deletions
diff --git a/http_handle_repo_commit.go b/http_handle_repo_commit.go index f6b73d5..11f16e4 100644 --- a/http_handle_repo_commit.go +++ b/http_handle_repo_commit.go @@ -5,6 +5,7 @@ import ( "net/http" "strings" + "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/filemode" "github.com/go-git/go-git/v5/plumbing/format/diff" @@ -25,13 +26,8 @@ type usable_chunk struct { } func handle_repo_commit(w http.ResponseWriter, r *http.Request, params map[string]any) { - group_name, repo_name, commit_id_specified_string := params["group_name"].(string), params["repo_name"].(string), params["commit_id"].(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) - return - } - params["repo_description"] = description + repo, commit_id_specified_string := params["repo"].(*git.Repository), params["commit_id"].(string) + commit_id_specified_string_without_suffix := strings.TrimSuffix(commit_id_specified_string, ".patch") commit_id := plumbing.NewHash(commit_id_specified_string_without_suffix) commit_object, err := repo.CommitObject(commit_id) diff --git a/http_handle_repo_index.go b/http_handle_repo_index.go index 448373e..cd41f50 100644 --- a/http_handle_repo_index.go +++ b/http_handle_repo_index.go @@ -2,16 +2,12 @@ package main import ( "net/http" + + "github.com/go-git/go-git/v5" ) func handle_repo_index(w http.ResponseWriter, r *http.Request, params map[string]any) { - group_name, repo_name := params["group_name"].(string), params["repo_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) - return - } - params["repo_description"] = description + repo, repo_name, group_name := params["repo"].(*git.Repository), params["repo_name"].(string), params["group_name"].(string) ref_hash, err := get_ref_hash_from_type_and_name(repo, params["ref_type"].(string), params["ref_name"].(string)) if err != nil { diff --git a/http_handle_repo_log.go b/http_handle_repo_log.go index cbc3284..f2c96b4 100644 --- a/http_handle_repo_log.go +++ b/http_handle_repo_log.go @@ -2,16 +2,13 @@ package main import ( "net/http" + + "github.com/go-git/go-git/v5" ) // TODO: I probably shouldn't include *all* commits here... func handle_repo_log(w http.ResponseWriter, r *http.Request, params map[string]any) { - 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 + repo := params["repo"].(*git.Repository) ref_hash, err := get_ref_hash_from_type_and_name(repo, params["ref_type"].(string), params["ref_name"].(string)) if err != nil { diff --git a/http_handle_repo_raw.go b/http_handle_repo_raw.go index d525df7..6c4550c 100644 --- a/http_handle_repo_raw.go +++ b/http_handle_repo_raw.go @@ -6,22 +6,15 @@ import ( "path" "strings" + "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing/object" ) func handle_repo_raw(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, "/") - + repo, path_spec := params["repo"].(*git.Repository), strings.TrimSuffix(raw_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) - return - } - params["repo_description"] = description - 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) diff --git a/http_handle_repo_tree.go b/http_handle_repo_tree.go index 5378384..10dc2a1 100644 --- a/http_handle_repo_tree.go +++ b/http_handle_repo_tree.go @@ -10,19 +10,14 @@ import ( chroma_formatters_html "github.com/alecthomas/chroma/v2/formatters/html" chroma_lexers "github.com/alecthomas/chroma/v2/lexers" chroma_styles "github.com/alecthomas/chroma/v2/styles" + "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing/object" ) 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, "/") + repo, path_spec := params["repo"].(*git.Repository), strings.TrimSuffix(raw_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) - return - } - params["repo_description"] = description ref_hash, err := get_ref_hash_from_type_and_name(repo, params["ref_type"].(string), params["ref_name"].(string)) if err != nil { diff --git a/http_server.go b/http_server.go index d253dd8..0cc6a8b 100644 --- a/http_server.go +++ b/http_server.go @@ -113,10 +113,29 @@ func (router *http_router_t) ServeHTTP(w http.ResponseWriter, r *http.Request) { default: module_type := segments[separator_index+1] module_name := segments[separator_index+2] - params["group_name"] = segments[0] + group_name := segments[0] + params["group_name"] = group_name switch module_type { case "repos": params["repo_name"] = module_name + + if non_empty_last_segments_len > separator_index+3 { + switch segments[separator_index+3] { + case "info": + err = handle_repo_info(w, r, params) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + return + case "git-upload-pack": + err = handle_upload_pack(w, r, params) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + return + } + } + params["ref_type"], params["ref_name"], err = get_param_ref_and_type(r) if err != nil { if errors.Is(err, err_no_ref_spec) { @@ -126,7 +145,15 @@ func (router *http_router_t) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } } + // TODO: subgroups + + params["repo"], params["repo_description"], err = open_git_repo(r.Context(), group_name, module_name) + if err != nil { + http.Error(w, "Error opening repo: "+err.Error(), http.StatusInternalServerError) + return + } + if non_empty_last_segments_len == separator_index+3 { if redirect_with_slash(w, r) { return @@ -134,18 +161,9 @@ func (router *http_router_t) ServeHTTP(w http.ResponseWriter, r *http.Request) { handle_repo_index(w, r, params) return } + repo_feature := segments[separator_index+3] switch repo_feature { - case "info": - err = handle_repo_info(w, r, params) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - } - case "git-upload-pack": - err = handle_upload_pack(w, r, params) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - } case "tree": params["rest"] = strings.Join(segments[separator_index+4:], "/") if len(segments) < separator_index+5 && redirect_with_slash(w, r) { |