mirror of
https://github.com/git-for-windows/git.git
synced 2026-06-28 06:35:27 -05:00
The Git project is not exactly the easiest project to get started in: it's written in C and POSIX shell, with bits of Perl, Rust and other languages sprinkled into it. On top of that, the project has grown somewhat organically over time, making the codebase hard to navigate. These are problems that we're aware of, and there have been and still are efforts to clean up some of the technical debt that is natural to exist an a project that is more than 20 years old. Furthermore, we provide resources to newcomers that help them out like our coding guidelines, code of conduct or "MyFirstContribution.adoc". But there is a rather practical problem: finding your way around in our project's tree is not easy. Doing a directory listing in the top-level directory will present you with more than 550 files, which makes it extremely hard for a newcomer to figure out what files they are even supposed to look at. This makes the onboarding experience somewhat harder than it really needs to be. This isn't only a problem for newcomers though, as I myself struggle to find the files I am looking for because of the sheer number of files. Besides the problem of discoverability it also creates a problem of structure. It is not obvious at all which files are part of "libgit.a" and which files are only linked into our final executables. So while we have this split in our build systems, that split is not evident at all in our tree. Introduce a new "lib/" directory and move all of our sources for "libgit.a" into it to fix these issues. It makes the split we have evident and reduces the number of files in our top-level tree from 550 files to ~80 files. This is still a lot of files, but it's significantly easier to navigate already. Furthermore, we can further iterate after this step and think about introducing a better structure for remaining files, as well. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
180 lines
4.1 KiB
C
180 lines
4.1 KiB
C
#define USE_THE_REPOSITORY_VARIABLE
|
|
|
|
#include "git-compat-util.h"
|
|
#include "gettext.h"
|
|
#include "simple-ipc.h"
|
|
#include "fsmonitor-ipc.h"
|
|
#include "repository.h"
|
|
#include "run-command.h"
|
|
#include "strbuf.h"
|
|
#include "trace2.h"
|
|
|
|
#ifndef HAVE_FSMONITOR_DAEMON_BACKEND
|
|
|
|
/*
|
|
* A trivial implementation of the fsmonitor_ipc__ API for unsupported
|
|
* platforms.
|
|
*/
|
|
|
|
int fsmonitor_ipc__is_supported(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
const char *fsmonitor_ipc__get_path(struct repository *r UNUSED)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
enum ipc_active_state fsmonitor_ipc__get_state(void)
|
|
{
|
|
return IPC_STATE__OTHER_ERROR;
|
|
}
|
|
|
|
int fsmonitor_ipc__send_query(const char *since_token UNUSED,
|
|
struct strbuf *answer UNUSED)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
int fsmonitor_ipc__send_command(const char *command UNUSED,
|
|
struct strbuf *answer UNUSED)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
#else
|
|
|
|
int fsmonitor_ipc__is_supported(void)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
enum ipc_active_state fsmonitor_ipc__get_state(void)
|
|
{
|
|
return ipc_get_active_state(fsmonitor_ipc__get_path(the_repository));
|
|
}
|
|
|
|
static int spawn_daemon(void)
|
|
{
|
|
struct child_process cmd = CHILD_PROCESS_INIT;
|
|
|
|
cmd.git_cmd = 1;
|
|
cmd.no_stdin = 1;
|
|
cmd.no_stdout = 1;
|
|
cmd.no_stderr = 1;
|
|
cmd.close_fd_above_stderr = 1;
|
|
cmd.trace2_child_class = "fsmonitor";
|
|
strvec_pushl(&cmd.args, "fsmonitor--daemon", "start", NULL);
|
|
|
|
return run_command(&cmd);
|
|
}
|
|
|
|
int fsmonitor_ipc__send_query(const char *since_token,
|
|
struct strbuf *answer)
|
|
{
|
|
int ret = -1;
|
|
int tried_to_spawn = 0;
|
|
enum ipc_active_state state = IPC_STATE__OTHER_ERROR;
|
|
struct ipc_client_connection *connection = NULL;
|
|
struct ipc_client_connect_options options
|
|
= IPC_CLIENT_CONNECT_OPTIONS_INIT;
|
|
const char *tok = since_token ? since_token : "";
|
|
size_t tok_len = since_token ? strlen(since_token) : 0;
|
|
|
|
options.wait_if_busy = 1;
|
|
options.wait_if_not_found = 0;
|
|
|
|
trace2_region_enter("fsm_client", "query", NULL);
|
|
trace2_data_string("fsm_client", NULL, "query/command", tok);
|
|
|
|
try_again:
|
|
state = ipc_client_try_connect(fsmonitor_ipc__get_path(the_repository),
|
|
&options, &connection);
|
|
|
|
switch (state) {
|
|
case IPC_STATE__LISTENING:
|
|
ret = ipc_client_send_command_to_connection(
|
|
connection, tok, tok_len, answer);
|
|
ipc_client_close_connection(connection);
|
|
|
|
trace2_data_intmax("fsm_client", NULL,
|
|
"query/response-length", answer->len);
|
|
goto done;
|
|
|
|
case IPC_STATE__NOT_LISTENING:
|
|
case IPC_STATE__PATH_NOT_FOUND:
|
|
if (tried_to_spawn)
|
|
goto done;
|
|
|
|
tried_to_spawn++;
|
|
if (spawn_daemon())
|
|
goto done;
|
|
|
|
/*
|
|
* Try again, but this time give the daemon a chance to
|
|
* actually create the pipe/socket.
|
|
*
|
|
* Granted, the daemon just started so it can't possibly have
|
|
* any FS cached yet, so we'll always get a trivial answer.
|
|
* BUT the answer should include a new token that can serve
|
|
* as the basis for subsequent requests.
|
|
*/
|
|
options.wait_if_not_found = 1;
|
|
goto try_again;
|
|
|
|
case IPC_STATE__INVALID_PATH:
|
|
ret = error(_("fsmonitor_ipc__send_query: invalid path '%s'"),
|
|
fsmonitor_ipc__get_path(the_repository));
|
|
goto done;
|
|
|
|
case IPC_STATE__OTHER_ERROR:
|
|
default:
|
|
ret = error(_("fsmonitor_ipc__send_query: unspecified error on '%s'"),
|
|
fsmonitor_ipc__get_path(the_repository));
|
|
goto done;
|
|
}
|
|
|
|
done:
|
|
trace2_region_leave("fsm_client", "query", NULL);
|
|
|
|
return ret;
|
|
}
|
|
|
|
int fsmonitor_ipc__send_command(const char *command,
|
|
struct strbuf *answer)
|
|
{
|
|
struct ipc_client_connection *connection = NULL;
|
|
struct ipc_client_connect_options options
|
|
= IPC_CLIENT_CONNECT_OPTIONS_INIT;
|
|
int ret;
|
|
enum ipc_active_state state;
|
|
const char *c = command ? command : "";
|
|
size_t c_len = command ? strlen(command) : 0;
|
|
|
|
strbuf_reset(answer);
|
|
|
|
options.wait_if_busy = 1;
|
|
options.wait_if_not_found = 0;
|
|
|
|
state = ipc_client_try_connect(fsmonitor_ipc__get_path(the_repository),
|
|
&options, &connection);
|
|
if (state != IPC_STATE__LISTENING) {
|
|
die(_("fsmonitor--daemon is not running"));
|
|
return -1;
|
|
}
|
|
|
|
ret = ipc_client_send_command_to_connection(connection, c, c_len,
|
|
answer);
|
|
ipc_client_close_connection(connection);
|
|
|
|
if (ret == -1) {
|
|
die(_("could not send '%s' command to fsmonitor--daemon"), c);
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
#endif
|