MCPcopy Index your code
hub / github.com/git/git / cmd_main

Function cmd_main

http-backend.c:764–829  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

762}
763
764int cmd_main(int argc UNUSED, const char **argv UNUSED)
765{
766 const char *method = getenv("REQUEST_METHOD");
767 const char *proto_header;
768 char *dir;
769 struct service_cmd *cmd = NULL;
770 char *cmd_arg = NULL;
771 int i;
772 struct strbuf hdr = STRBUF_INIT;
773
774 set_die_routine(die_webcgi);
775 set_die_is_recursing_routine(die_webcgi_recursing);
776
777 if (!method)
778 die("No REQUEST_METHOD from server");
779 if (!strcmp(method, "HEAD"))
780 method = "GET";
781 dir = getdir();
782
783 for (i = 0; i < ARRAY_SIZE(services); i++) {
784 struct service_cmd *c = &services[i];
785 regex_t re;
786 regmatch_t out[1];
787 int ret;
788
789 if (regcomp(&re, c->pattern, REG_EXTENDED))
790 die("Bogus regex in service table: %s", c->pattern);
791 ret = regexec(&re, dir, 1, out, 0);
792 regfree(&re);
793
794 if (!ret) {
795 size_t n;
796
797 if (strcmp(method, c->method))
798 return bad_request(&hdr, c);
799
800 cmd = c;
801 n = out[0].rm_eo - out[0].rm_so;
802 cmd_arg = xmemdupz(dir + out[0].rm_so + 1, n - 1);
803 dir[out[0].rm_so] = 0;
804 break;
805 }
806 }
807
808 if (!cmd)
809 not_found(&hdr, "Request not supported: '%s'", dir);
810
811 setup_path();
812 if (!enter_repo(the_repository, dir, 0))
813 not_found(&hdr, "Not a git repository: '%s'", dir);
814 if (!getenv("GIT_HTTP_EXPORT_ALL") &&
815 access("git-daemon-export-ok", F_OK) )
816 not_found(&hdr, "Repository not exported: '%s'", dir);
817 free(dir);
818
819 http_config();
820 max_request_buffer = git_env_ulong("GIT_HTTP_MAX_REQUEST_BUFFER",
821 max_request_buffer);

Callers

nothing calls this directly

Calls 13

set_die_routineFunction · 0.85
getdirFunction · 0.85
regcompFunction · 0.85
regfreeFunction · 0.85
bad_requestFunction · 0.85
xmemdupzFunction · 0.85
not_foundFunction · 0.85
setup_pathFunction · 0.85
enter_repoFunction · 0.85
http_configFunction · 0.85
git_env_ulongFunction · 0.85

Tested by

no test coverage detected