Skip to content

Commit

Permalink
TO-SPLIT
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Jan 17, 2019
1 parent cb62289 commit 162ee3f
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 31 deletions.
7 changes: 5 additions & 2 deletions builtin/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
argc--;
}

if (show_in_pager == default_pager)
show_in_pager = git_pager(1);
if (show_in_pager == default_pager) {
char *pager = xstrdup_or_null(git_pager(1));
UNLEAK(pager);
show_in_pager = pager;
}
if (show_in_pager) {
opt.color = 0;
opt.name_only = 1;
Expand Down
3 changes: 2 additions & 1 deletion builtin/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,14 @@ static void show_man_page(const char *git_cmd)
{
struct man_viewer_list *viewer;
const char *page = cmd_to_page(git_cmd);
const char *fallback = getenv("GIT_MAN_VIEWER");
const char *fallback;

setup_man_path();
for (viewer = man_viewer_list; viewer; viewer = viewer->next)
{
exec_viewer(viewer->name, page); /* will return when unable */
}
fallback = getenv("GIT_MAN_VIEWER");
if (fallback)
exec_viewer(fallback, page);
exec_viewer("man", page);
Expand Down
12 changes: 4 additions & 8 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,8 @@ int git_config_parse_parameter(const char *text,

int git_config_from_parameters(config_fn_t fn, void *data)
{
const char *env = getenv(CONFIG_DATA_ENVIRONMENT);
char *env = xstrdup_or_null(getenv(CONFIG_DATA_ENVIRONMENT));
int ret = 0;
char *envw;
const char **argv = NULL;
int nr = 0, alloc = 0;
int i;
Expand All @@ -460,10 +459,7 @@ int git_config_from_parameters(config_fn_t fn, void *data)
source.origin_type = CONFIG_ORIGIN_CMDLINE;
cf = &source;

/* sq_dequote will write over it */
envw = xstrdup(env);

if (sq_dequote_to_argv(envw, &argv, &nr, &alloc) < 0) {
if (sq_dequote_to_argv(env, &argv, &nr, &alloc) < 0) {
ret = error(_("bogus format in %s"), CONFIG_DATA_ENVIRONMENT);
goto out;
}
Expand All @@ -477,7 +473,7 @@ int git_config_from_parameters(config_fn_t fn, void *data)

out:
free(argv);
free(envw);
free(env);
cf = source.prev;
return ret;
}
Expand Down Expand Up @@ -2290,7 +2286,7 @@ int git_config_get_max_percent_split_change(void)
int git_config_get_fsmonitor(void)
{
if (git_config_get_pathname("core.fsmonitor", &core_fsmonitor))
core_fsmonitor = getenv("GIT_TEST_FSMONITOR");
core_fsmonitor = xstrdup_or_null(getenv("GIT_TEST_FSMONITOR"));

if (core_fsmonitor && !*core_fsmonitor)
core_fsmonitor = NULL;
Expand Down
15 changes: 7 additions & 8 deletions connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ static int git_proxy_command_options(const char *var, const char *value,

static int git_use_proxy(const char *host)
{
git_proxy_command = getenv("GIT_PROXY_COMMAND");
git_proxy_command = xstrdup_or_null(getenv("GIT_PROXY_COMMAND"));
git_config(git_proxy_command_options, (void*)host);
return (git_proxy_command && *git_proxy_command);
}
Expand Down Expand Up @@ -954,12 +954,12 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,

static const char *get_ssh_command(void)
{
const char *ssh;
static char *ssh;

if ((ssh = getenv("GIT_SSH_COMMAND")))
if ((ssh = xstrdup_or_null(getenv("GIT_SSH_COMMAND"))))
return ssh;

if (!git_config_get_string_const("core.sshcommand", &ssh))
if (!git_config_get_string("core.sshcommand", &ssh))
return ssh;

return NULL;
Expand Down Expand Up @@ -1060,10 +1060,9 @@ static struct child_process *git_connect_git(int fd[2], char *hostandport,
* connect, unless the user has overridden us in
* the environment.
*/
char *target_host = getenv("GIT_OVERRIDE_VIRTUAL_HOST");
if (target_host)
target_host = xstrdup(target_host);
else
char *target_host =
xstrdup_or_null(getenv("GIT_OVERRIDE_VIRTUAL_HOST"));
if (!target_host)
target_host = xstrdup(hostandport);

transport_check_allowed("git");
Expand Down
2 changes: 1 addition & 1 deletion editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ int is_terminal_dumb(void)

const char *git_editor(void)
{
const char *editor = getenv("GIT_EDITOR");
int terminal_is_dumb = is_terminal_dumb();
const char *editor = getenv("GIT_EDITOR");

if (!editor && editor_program)
editor = editor_program;
Expand Down
3 changes: 2 additions & 1 deletion help.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void load_command_list(const char *prefix,
struct cmdnames *main_cmds,
struct cmdnames *other_cmds)
{
const char *env_path = getenv("PATH");
const char *env_path;
const char *exec_path = git_exec_path();

if (exec_path) {
Expand All @@ -268,6 +268,7 @@ void load_command_list(const char *prefix,
uniq(main_cmds);
}

env_path = getenv("PATH");
if (env_path) {
char *paths, *path, *colon;
path = paths = xstrdup(env_path);
Expand Down
4 changes: 2 additions & 2 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ static void set_from_env(const char **var, const char *envname)
{
const char *val = getenv(envname);
if (val)
*var = val;
*var = xstrdup(val);
}

void http_init(struct remote *remote, const char *url, int proactive_auth)
Expand Down Expand Up @@ -1119,7 +1119,7 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)

#ifdef USE_CURL_MULTI
{
char *http_max_requests = getenv("GIT_HTTP_MAX_REQUESTS");
const char *http_max_requests = getenv("GIT_HTTP_MAX_REQUESTS");
if (http_max_requests != NULL)
max_requests = atoi(http_max_requests);
}
Expand Down
8 changes: 6 additions & 2 deletions notes-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ static int notes_rewrite_config(const char *k, const char *v, void *cb)
struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
{
struct notes_rewrite_cfg *c = xmalloc(sizeof(struct notes_rewrite_cfg));
const char *rewrite_mode_env = getenv(GIT_NOTES_REWRITE_MODE_ENVIRONMENT);
const char *rewrite_refs_env = getenv(GIT_NOTES_REWRITE_REF_ENVIRONMENT);
char *rewrite_mode_env =
xstrdup_or_null(getenv(GIT_NOTES_REWRITE_MODE_ENVIRONMENT));
char *rewrite_refs_env =
xstrdup_or_null(getenv(GIT_NOTES_REWRITE_REF_ENVIRONMENT));
c->cmd = cmd;
c->enabled = 1;
c->combine = combine_notes_concatenate;
Expand All @@ -143,10 +145,12 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
*/
error(_("Bad %s value: '%s'"), GIT_NOTES_REWRITE_MODE_ENVIRONMENT,
rewrite_mode_env);
free(rewrite_mode_env);
}
if (rewrite_refs_env) {
c->refs_from_env = 1;
string_list_add_refs_from_colon_sep(c->refs, rewrite_refs_env);
free(rewrite_refs_env);
}
git_config(notes_rewrite_config, c);
if (!c->enabled || !c->refs->nr) {
Expand Down
11 changes: 8 additions & 3 deletions notes.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,12 @@ static int notes_display_config(const char *k, const char *v, void *cb)
const char *default_notes_ref(void)
{
const char *notes_ref = NULL;
if (!notes_ref)
notes_ref = getenv(GIT_NOTES_REF_ENVIRONMENT);
if (!notes_ref) {
static char *env;
free(env);
env = xstrdup_or_null(getenv(GIT_NOTES_REF_ENVIRONMENT));
notes_ref = env;
}
if (!notes_ref)
notes_ref = notes_ref_name; /* value of core.notesRef config */
if (!notes_ref)
Expand Down Expand Up @@ -1039,14 +1043,15 @@ struct notes_tree **load_notes_trees(struct string_list *refs, int flags)

void init_display_notes(struct display_notes_opt *opt)
{
char *display_ref_env;
int load_config_refs = 0;
display_notes_refs.strdup_strings = 1;

assert(!display_notes_trees);

if (!opt || opt->use_default_notes > 0 ||
(opt->use_default_notes == -1 && !opt->extra_notes_refs.nr)) {
const char *display_ref_env;

string_list_append(&display_notes_refs, default_notes_ref());
display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT);
if (display_ref_env) {
Expand Down
3 changes: 2 additions & 1 deletion pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void prepare_pager_args(struct child_process *pager_process, const char *pager)

void setup_pager(void)
{
const char *pager = git_pager(isatty(1));
char *pager = xstrdup_or_null(git_pager(isatty(1)));

if (!pager)
return;
Expand All @@ -124,6 +124,7 @@ void setup_pager(void)

/* spawn the pager */
prepare_pager_args(&pager_process, pager);
FREE_AND_NULL(pager);
pager_process.in = -1;
argv_array_push(&pager_process.env_array, "GIT_PAGER_IN_USE");
if (start_command(&pager_process))
Expand Down
6 changes: 4 additions & 2 deletions setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
struct repository_format *repo_fmt,
int *nongit_ok)
{
const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
const char *work_tree_env;
const char *worktree;
char *gitfile;
int offset;
Expand Down Expand Up @@ -683,6 +683,7 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
}

/* #3, #7, #11, #15, #19, #23, #27, #31 (see t1510) */
work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
if (work_tree_env)
set_git_work_tree(work_tree_env);
else if (is_bare_repository_cfg > 0) {
Expand Down Expand Up @@ -913,7 +914,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
struct strbuf *gitdir,
int die_on_error)
{
const char *env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT);
const char *env_ceiling_dirs;
struct string_list ceiling_dirs = STRING_LIST_INIT_DUP;
const char *gitdirenv;
int ceil_offset = -1, min_offset = offset_1st_component(dir->buf);
Expand All @@ -931,6 +932,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
return GIT_DIR_EXPLICIT;
}

env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT);
if (env_ceiling_dirs) {
int empty_entry_found = 0;

Expand Down

0 comments on commit 162ee3f

Please sign in to comment.