Skip to content

Commit 162ee3f

Browse files
committed
TO-SPLIT
Signed-off-by: Johannes Schindelin <[email protected]>
1 parent cb62289 commit 162ee3f

File tree

11 files changed

+43
-31
lines changed

11 files changed

+43
-31
lines changed

builtin/grep.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
962962
argc--;
963963
}
964964

965-
if (show_in_pager == default_pager)
966-
show_in_pager = git_pager(1);
965+
if (show_in_pager == default_pager) {
966+
char *pager = xstrdup_or_null(git_pager(1));
967+
UNLEAK(pager);
968+
show_in_pager = pager;
969+
}
967970
if (show_in_pager) {
968971
opt.color = 0;
969972
opt.name_only = 1;

builtin/help.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,14 @@ static void show_man_page(const char *git_cmd)
350350
{
351351
struct man_viewer_list *viewer;
352352
const char *page = cmd_to_page(git_cmd);
353-
const char *fallback = getenv("GIT_MAN_VIEWER");
353+
const char *fallback;
354354

355355
setup_man_path();
356356
for (viewer = man_viewer_list; viewer; viewer = viewer->next)
357357
{
358358
exec_viewer(viewer->name, page); /* will return when unable */
359359
}
360+
fallback = getenv("GIT_MAN_VIEWER");
360361
if (fallback)
361362
exec_viewer(fallback, page);
362363
exec_viewer("man", page);

config.c

+4-8
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,8 @@ int git_config_parse_parameter(const char *text,
444444

445445
int git_config_from_parameters(config_fn_t fn, void *data)
446446
{
447-
const char *env = getenv(CONFIG_DATA_ENVIRONMENT);
447+
char *env = xstrdup_or_null(getenv(CONFIG_DATA_ENVIRONMENT));
448448
int ret = 0;
449-
char *envw;
450449
const char **argv = NULL;
451450
int nr = 0, alloc = 0;
452451
int i;
@@ -460,10 +459,7 @@ int git_config_from_parameters(config_fn_t fn, void *data)
460459
source.origin_type = CONFIG_ORIGIN_CMDLINE;
461460
cf = &source;
462461

463-
/* sq_dequote will write over it */
464-
envw = xstrdup(env);
465-
466-
if (sq_dequote_to_argv(envw, &argv, &nr, &alloc) < 0) {
462+
if (sq_dequote_to_argv(env, &argv, &nr, &alloc) < 0) {
467463
ret = error(_("bogus format in %s"), CONFIG_DATA_ENVIRONMENT);
468464
goto out;
469465
}
@@ -477,7 +473,7 @@ int git_config_from_parameters(config_fn_t fn, void *data)
477473

478474
out:
479475
free(argv);
480-
free(envw);
476+
free(env);
481477
cf = source.prev;
482478
return ret;
483479
}
@@ -2290,7 +2286,7 @@ int git_config_get_max_percent_split_change(void)
22902286
int git_config_get_fsmonitor(void)
22912287
{
22922288
if (git_config_get_pathname("core.fsmonitor", &core_fsmonitor))
2293-
core_fsmonitor = getenv("GIT_TEST_FSMONITOR");
2289+
core_fsmonitor = xstrdup_or_null(getenv("GIT_TEST_FSMONITOR"));
22942290

22952291
if (core_fsmonitor && !*core_fsmonitor)
22962292
core_fsmonitor = NULL;

connect.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ static int git_proxy_command_options(const char *var, const char *value,
832832

833833
static int git_use_proxy(const char *host)
834834
{
835-
git_proxy_command = getenv("GIT_PROXY_COMMAND");
835+
git_proxy_command = xstrdup_or_null(getenv("GIT_PROXY_COMMAND"));
836836
git_config(git_proxy_command_options, (void*)host);
837837
return (git_proxy_command && *git_proxy_command);
838838
}
@@ -954,12 +954,12 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
954954

955955
static const char *get_ssh_command(void)
956956
{
957-
const char *ssh;
957+
static char *ssh;
958958

959-
if ((ssh = getenv("GIT_SSH_COMMAND")))
959+
if ((ssh = xstrdup_or_null(getenv("GIT_SSH_COMMAND"))))
960960
return ssh;
961961

962-
if (!git_config_get_string_const("core.sshcommand", &ssh))
962+
if (!git_config_get_string("core.sshcommand", &ssh))
963963
return ssh;
964964

965965
return NULL;
@@ -1060,10 +1060,9 @@ static struct child_process *git_connect_git(int fd[2], char *hostandport,
10601060
* connect, unless the user has overridden us in
10611061
* the environment.
10621062
*/
1063-
char *target_host = getenv("GIT_OVERRIDE_VIRTUAL_HOST");
1064-
if (target_host)
1065-
target_host = xstrdup(target_host);
1066-
else
1063+
char *target_host =
1064+
xstrdup_or_null(getenv("GIT_OVERRIDE_VIRTUAL_HOST"));
1065+
if (!target_host)
10671066
target_host = xstrdup(hostandport);
10681067

10691068
transport_check_allowed("git");

editor.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ int is_terminal_dumb(void)
1616

1717
const char *git_editor(void)
1818
{
19-
const char *editor = getenv("GIT_EDITOR");
2019
int terminal_is_dumb = is_terminal_dumb();
20+
const char *editor = getenv("GIT_EDITOR");
2121

2222
if (!editor && editor_program)
2323
editor = editor_program;

help.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ void load_command_list(const char *prefix,
259259
struct cmdnames *main_cmds,
260260
struct cmdnames *other_cmds)
261261
{
262-
const char *env_path = getenv("PATH");
262+
const char *env_path;
263263
const char *exec_path = git_exec_path();
264264

265265
if (exec_path) {
@@ -268,6 +268,7 @@ void load_command_list(const char *prefix,
268268
uniq(main_cmds);
269269
}
270270

271+
env_path = getenv("PATH");
271272
if (env_path) {
272273
char *paths, *path, *colon;
273274
path = paths = xstrdup(env_path);

http.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ static void set_from_env(const char **var, const char *envname)
10521052
{
10531053
const char *val = getenv(envname);
10541054
if (val)
1055-
*var = val;
1055+
*var = xstrdup(val);
10561056
}
10571057

10581058
void http_init(struct remote *remote, const char *url, int proactive_auth)
@@ -1119,7 +1119,7 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
11191119

11201120
#ifdef USE_CURL_MULTI
11211121
{
1122-
char *http_max_requests = getenv("GIT_HTTP_MAX_REQUESTS");
1122+
const char *http_max_requests = getenv("GIT_HTTP_MAX_REQUESTS");
11231123
if (http_max_requests != NULL)
11241124
max_requests = atoi(http_max_requests);
11251125
}

notes-utils.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ static int notes_rewrite_config(const char *k, const char *v, void *cb)
123123
struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
124124
{
125125
struct notes_rewrite_cfg *c = xmalloc(sizeof(struct notes_rewrite_cfg));
126-
const char *rewrite_mode_env = getenv(GIT_NOTES_REWRITE_MODE_ENVIRONMENT);
127-
const char *rewrite_refs_env = getenv(GIT_NOTES_REWRITE_REF_ENVIRONMENT);
126+
char *rewrite_mode_env =
127+
xstrdup_or_null(getenv(GIT_NOTES_REWRITE_MODE_ENVIRONMENT));
128+
char *rewrite_refs_env =
129+
xstrdup_or_null(getenv(GIT_NOTES_REWRITE_REF_ENVIRONMENT));
128130
c->cmd = cmd;
129131
c->enabled = 1;
130132
c->combine = combine_notes_concatenate;
@@ -143,10 +145,12 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
143145
*/
144146
error(_("Bad %s value: '%s'"), GIT_NOTES_REWRITE_MODE_ENVIRONMENT,
145147
rewrite_mode_env);
148+
free(rewrite_mode_env);
146149
}
147150
if (rewrite_refs_env) {
148151
c->refs_from_env = 1;
149152
string_list_add_refs_from_colon_sep(c->refs, rewrite_refs_env);
153+
free(rewrite_refs_env);
150154
}
151155
git_config(notes_rewrite_config, c);
152156
if (!c->enabled || !c->refs->nr) {

notes.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,12 @@ static int notes_display_config(const char *k, const char *v, void *cb)
973973
const char *default_notes_ref(void)
974974
{
975975
const char *notes_ref = NULL;
976-
if (!notes_ref)
977-
notes_ref = getenv(GIT_NOTES_REF_ENVIRONMENT);
976+
if (!notes_ref) {
977+
static char *env;
978+
free(env);
979+
env = xstrdup_or_null(getenv(GIT_NOTES_REF_ENVIRONMENT));
980+
notes_ref = env;
981+
}
978982
if (!notes_ref)
979983
notes_ref = notes_ref_name; /* value of core.notesRef config */
980984
if (!notes_ref)
@@ -1039,14 +1043,15 @@ struct notes_tree **load_notes_trees(struct string_list *refs, int flags)
10391043

10401044
void init_display_notes(struct display_notes_opt *opt)
10411045
{
1042-
char *display_ref_env;
10431046
int load_config_refs = 0;
10441047
display_notes_refs.strdup_strings = 1;
10451048

10461049
assert(!display_notes_trees);
10471050

10481051
if (!opt || opt->use_default_notes > 0 ||
10491052
(opt->use_default_notes == -1 && !opt->extra_notes_refs.nr)) {
1053+
const char *display_ref_env;
1054+
10501055
string_list_append(&display_notes_refs, default_notes_ref());
10511056
display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT);
10521057
if (display_ref_env) {

pager.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void prepare_pager_args(struct child_process *pager_process, const char *pager)
104104

105105
void setup_pager(void)
106106
{
107-
const char *pager = git_pager(isatty(1));
107+
char *pager = xstrdup_or_null(git_pager(isatty(1)));
108108

109109
if (!pager)
110110
return;
@@ -124,6 +124,7 @@ void setup_pager(void)
124124

125125
/* spawn the pager */
126126
prepare_pager_args(&pager_process, pager);
127+
FREE_AND_NULL(pager);
127128
pager_process.in = -1;
128129
argv_array_push(&pager_process.env_array, "GIT_PAGER_IN_USE");
129130
if (start_command(&pager_process))

setup.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
654654
struct repository_format *repo_fmt,
655655
int *nongit_ok)
656656
{
657-
const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
657+
const char *work_tree_env;
658658
const char *worktree;
659659
char *gitfile;
660660
int offset;
@@ -683,6 +683,7 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
683683
}
684684

685685
/* #3, #7, #11, #15, #19, #23, #27, #31 (see t1510) */
686+
work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
686687
if (work_tree_env)
687688
set_git_work_tree(work_tree_env);
688689
else if (is_bare_repository_cfg > 0) {
@@ -913,7 +914,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
913914
struct strbuf *gitdir,
914915
int die_on_error)
915916
{
916-
const char *env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT);
917+
const char *env_ceiling_dirs;
917918
struct string_list ceiling_dirs = STRING_LIST_INIT_DUP;
918919
const char *gitdirenv;
919920
int ceil_offset = -1, min_offset = offset_1st_component(dir->buf);
@@ -931,6 +932,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
931932
return GIT_DIR_EXPLICIT;
932933
}
933934

935+
env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT);
934936
if (env_ceiling_dirs) {
935937
int empty_entry_found = 0;
936938

0 commit comments

Comments
 (0)