interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / common-init.c

83 lines · 2168 bytes Raw Blame History
1#define USE_THE_REPOSITORY_VARIABLE
2
3#include "git-compat-util.h"
4#include "common-init.h"
5#include "exec-cmd.h"
6#include "gettext.h"
7#include "attr.h"
8#include "odb.h"
9#include "parse.h"
10#include "repository.h"
11#include "replace-object.h"
12#include "setup.h"
13#include "strbuf.h"
14#include "trace2.h"
15
16/*
17 * Many parts of Git have subprograms communicate via pipe, expect the
18 * upstream of a pipe to die with SIGPIPE when the downstream of a
19 * pipe does not need to read all that is written. Some third-party
20 * programs that ignore or block SIGPIPE for their own reason forget
21 * to restore SIGPIPE handling to the default before spawning Git and
22 * break this carefully orchestrated machinery.
23 *
24 * Restore the way SIGPIPE is handled to default, which is what we
25 * expect.
26 */
27static void restore_sigpipe_to_default(void)
28{
29 sigset_t unblock;
30
31 sigemptyset(&unblock);
32 sigaddset(&unblock, SIGPIPE);
33 sigprocmask(SIG_UNBLOCK, &unblock, NULL);
34 signal(SIGPIPE, SIG_DFL);
35}
36
37static void setup_environment(void)
38{
39 char *git_replace_ref_base;
40 const char *replace_ref_base;
41
42 if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
43 disable_replace_refs();
44 replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT);
45 git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base
46 : "refs/replace/");
47 update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base);
48
49 if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0))
50 the_repository->fetch_if_missing = 0;
51}
52
53void init_git(const char **argv)
54{
55 struct strbuf tmp = STRBUF_INIT;
56
57 trace2_initialize_clock();
58
59 /*
60 * Always open file descriptors 0/1/2 to avoid clobbering files
61 * in die(). It also avoids messing up when the pipes are dup'ed
62 * onto stdin/stdout/stderr in the child processes we spawn.
63 */
64 sanitize_stdfds();
65 restore_sigpipe_to_default();
66
67 git_resolve_executable_dir(argv[0]);
68
69 setlocale(LC_CTYPE, "");
70 git_setup_gettext();
71
72 initialize_repository(the_repository);
73 setup_environment();
74
75 attr_start();
76
77 trace2_initialize();
78 trace2_cmd_start(argv);
79 trace2_collect_process_info(TRACE2_PROCESS_INFO_STARTUP);
80
81 if (!strbuf_getcwd(&tmp))
82 tmp_original_cwd = strbuf_detach(&tmp, NULL);
83}