Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Address getenv() issues #2019

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
216 changes: 0 additions & 216 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,219 +126,3 @@ jobs:
platform: Windows
publishRunAttachments: false
condition: succeededOrFailed()

- job: linux_clang
displayName: linux-clang
condition: succeeded()
pool: Hosted Ubuntu 1604
steps:
- bash: |
test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

sudo apt-get update &&
sudo apt-get -y install git gcc make libssl-dev libcurl4-openssl-dev libexpat-dev tcl tk gettext git-email zlib1g-dev apache2-bin &&

export CC=clang || exit 1

ci/install-dependencies.sh || exit 1
ci/run-build-and-tests.sh || {
ci/print-test-failures.sh
exit 1
}

test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || sudo umount "$HOME/test-cache" || exit 1
displayName: 'ci/run-build-and-tests.sh'
env:
GITFILESHAREPWD: $(gitfileshare.pwd)
- task: PublishTestResults@2
displayName: 'Publish Test Results **/TEST-*.xml'
inputs:
mergeTestResults: true
testRunTitle: 'linux-clang'
platform: Linux
publishRunAttachments: false
condition: succeededOrFailed()

- job: linux_gcc
displayName: linux-gcc
condition: succeeded()
pool: Hosted Ubuntu 1604
steps:
- bash: |
test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

sudo add-apt-repository ppa:ubuntu-toolchain-r/test &&
sudo apt-get update &&
sudo apt-get -y install git gcc make libssl-dev libcurl4-openssl-dev libexpat-dev tcl tk gettext git-email zlib1g-dev apache2 language-pack-is git-svn gcc-8 || exit 1

ci/install-dependencies.sh || exit 1
ci/run-build-and-tests.sh || {
ci/print-test-failures.sh
exit 1
}

test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || sudo umount "$HOME/test-cache" || exit 1
displayName: 'ci/run-build-and-tests.sh'
env:
GITFILESHAREPWD: $(gitfileshare.pwd)
- task: PublishTestResults@2
displayName: 'Publish Test Results **/TEST-*.xml'
inputs:
mergeTestResults: true
testRunTitle: 'linux-gcc'
platform: Linux
publishRunAttachments: false
condition: succeededOrFailed()

- job: osx_clang
displayName: osx-clang
condition: succeeded()
pool: Hosted macOS
steps:
- bash: |
test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

export CC=clang

ci/install-dependencies.sh || exit 1
ci/run-build-and-tests.sh || {
ci/print-test-failures.sh
exit 1
}

test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || umount "$HOME/test-cache" || exit 1
displayName: 'ci/run-build-and-tests.sh'
env:
GITFILESHAREPWD: $(gitfileshare.pwd)
- task: PublishTestResults@2
displayName: 'Publish Test Results **/TEST-*.xml'
inputs:
mergeTestResults: true
testRunTitle: 'osx-clang'
platform: macOS
publishRunAttachments: false
condition: succeededOrFailed()

- job: osx_gcc
displayName: osx-gcc
condition: succeeded()
pool: Hosted macOS
steps:
- bash: |
test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

ci/install-dependencies.sh || exit 1
ci/run-build-and-tests.sh || {
ci/print-test-failures.sh
exit 1
}

test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || umount "$HOME/test-cache" || exit 1
displayName: 'ci/run-build-and-tests.sh'
env:
GITFILESHAREPWD: $(gitfileshare.pwd)
- task: PublishTestResults@2
displayName: 'Publish Test Results **/TEST-*.xml'
inputs:
mergeTestResults: true
testRunTitle: 'osx-gcc'
platform: macOS
publishRunAttachments: false
condition: succeededOrFailed()

- job: gettext_poison
displayName: GETTEXT_POISON
condition: succeeded()
pool: Hosted Ubuntu 1604
steps:
- bash: |
test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

sudo apt-get update &&
sudo apt-get -y install git gcc make libssl-dev libcurl4-openssl-dev libexpat-dev tcl tk gettext git-email zlib1g-dev &&

export jobname=GETTEXT_POISON || exit 1

ci/run-build-and-tests.sh || {
ci/print-test-failures.sh
exit 1
}

test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || sudo umount "$HOME/test-cache" || exit 1
displayName: 'ci/run-build-and-tests.sh'
env:
GITFILESHAREPWD: $(gitfileshare.pwd)
- task: PublishTestResults@2
displayName: 'Publish Test Results **/TEST-*.xml'
inputs:
mergeTestResults: true
testRunTitle: 'gettext-poison'
platform: Linux
publishRunAttachments: false
condition: succeededOrFailed()

- job: linux32
displayName: Linux32
condition: succeeded()
pool: Hosted Ubuntu 1604
steps:
- bash: |
test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

sudo AGENT_OS="$AGENT_OS" BUILD_BUILDNUMBER="$BUILD_BUILDNUMBER" BUILD_REPOSITORY_URI="$BUILD_REPOSITORY_URI" BUILD_SOURCEBRANCH="$BUILD_SOURCEBRANCH" BUILD_SOURCEVERSION="$BUILD_SOURCEVERSION" SYSTEM_PHASENAME="$SYSTEM_PHASENAME" SYSTEM_TASKDEFINITIONSURI="$SYSTEM_TASKDEFINITIONSURI" SYSTEM_TEAMPROJECT="$SYSTEM_TEAMPROJECT" CC=$CC MAKEFLAGS=-j3 bash -lxc ci/run-linux32-docker.sh || exit 1

sudo chmod a+r t/out/TEST-*.xml

test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || sudo umount "$HOME/test-cache" || exit 1
displayName: 'ci/run-linux32-docker.sh'
env:
GITFILESHAREPWD: $(gitfileshare.pwd)
- task: PublishTestResults@2
displayName: 'Publish Test Results **/TEST-*.xml'
inputs:
mergeTestResults: true
testRunTitle: 'linux32'
platform: Linux
publishRunAttachments: false
condition: succeededOrFailed()

- job: static_analysis
displayName: StaticAnalysis
condition: succeeded()
pool: Hosted Ubuntu 1604
steps:
- bash: |
test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

sudo apt-get update &&
sudo apt-get install -y coccinelle &&

export jobname=StaticAnalysis &&

ci/run-static-analysis.sh || exit 1

test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || sudo umount "$HOME/test-cache" || exit 1
displayName: 'ci/run-static-analysis.sh'
env:
GITFILESHAREPWD: $(gitfileshare.pwd)

- job: documentation
displayName: Documentation
condition: succeeded()
pool: Hosted Ubuntu 1604
steps:
- bash: |
test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

sudo apt-get update &&
sudo apt-get install -y asciidoc xmlto asciidoctor &&

export ALREADY_HAVE_ASCIIDOCTOR=yes. &&
export jobname=Documentation &&

ci/test-documentation.sh || exit 1

test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || sudo umount "$HOME/test-cache" || exit 1
displayName: 'ci/test-documentation.sh'
env:
GITFILESHAREPWD: $(gitfileshare.pwd)
3 changes: 2 additions & 1 deletion builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
if (write_locked_index(&the_index, &index_lock, 0))
die(_("unable to create temporary index"));

old_index_env = getenv(INDEX_ENVIRONMENT);
old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT));
setenv(INDEX_ENVIRONMENT, get_lock_file_path(&index_lock), 1);

if (interactive_add(argc, argv, prefix, patch_interactive) != 0)
Expand All @@ -361,6 +361,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
setenv(INDEX_ENVIRONMENT, old_index_env, 1);
else
unsetenv(INDEX_ENVIRONMENT);
FREE_AND_NULL(old_index_env);

discard_cache();
read_cache_from(get_lock_file_path(&index_lock));
Expand Down
2 changes: 1 addition & 1 deletion builtin/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
int nongit = !startup_info->have_repository;
char *value;

given_config_source.file = getenv(CONFIG_ENVIRONMENT);
given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT));

argc = parse_options(argc, argv, prefix, builtin_config_options,
builtin_config_usage,
Expand Down
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
6 changes: 4 additions & 2 deletions builtin/init-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
* GIT_WORK_TREE makes sense only in conjunction with GIT_DIR
* without --bare. Catch the error early.
*/
git_dir = getenv(GIT_DIR_ENVIRONMENT);
work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
git_dir = xstrdup_or_null(getenv(GIT_DIR_ENVIRONMENT));
work_tree = xstrdup_or_null(getenv(GIT_WORK_TREE_ENVIRONMENT));
if ((!git_dir || is_bare_repository_cfg == 1) && work_tree)
die(_("%s (or --work-tree=<directory>) not allowed without "
"specifying %s (or --git-dir=<directory>)"),
Expand Down Expand Up @@ -588,6 +588,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
}

UNLEAK(real_git_dir);
UNLEAK(git_dir);
UNLEAK(work_tree);

flags |= INIT_DB_EXIST_OK;
return init_db(git_dir, real_git_dir, template_dir, flags);
Expand Down
15 changes: 10 additions & 5 deletions builtin/merge-recursive.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
static const char builtin_merge_recursive_usage[] =
"git %s <base>... -- <head> <remote> ...";

static const char *better_branch_name(const char *branch)
static char *better_branch_name(const char *branch)
{
static char githead_env[8 + GIT_MAX_HEXSZ + 1];
char *name;

if (strlen(branch) != the_hash_algo->hexsz)
return branch;
return xstrdup(branch);
xsnprintf(githead_env, sizeof(githead_env), "GITHEAD_%s", branch);
name = getenv(githead_env);
return name ? name : branch;
return xstrdup(name ? name : branch);
}

int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
Expand All @@ -26,6 +26,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
int i, failed;
struct object_id h1, h2;
struct merge_options o;
char *better1, *better2;
struct commit *result;

init_merge_options(&o);
Expand Down Expand Up @@ -70,13 +71,17 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
if (get_oid(o.branch2, &h2))
die(_("could not resolve ref '%s'"), o.branch2);

o.branch1 = better_branch_name(o.branch1);
o.branch2 = better_branch_name(o.branch2);
o.branch1 = better1 = better_branch_name(o.branch1);
o.branch2 = better2 = better_branch_name(o.branch2);

if (o.verbosity >= 3)
printf(_("Merging %s with %s\n"), o.branch1, o.branch2);

failed = merge_recursive_generic(&o, &h1, &h2, bases_count, bases, &result);

free(better1);
free(better2);

if (failed < 0)
return 128; /* die() error code */
return failed;
Expand Down
6 changes: 5 additions & 1 deletion compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -2079,11 +2079,14 @@ char *mingw_getenv(const char *name)

len_value = len_value * 3 + 1;
/* We cannot use xcalloc() here because that uses getenv() itself */
value = calloc(len_value, sizeof(char));
//value = calloc(len_value, sizeof(char));
value = calloc(len_value < 16 ? 16 : len_value, sizeof(char));
if (!value)
die("Out of memory, (tried to allocate %u bytes)", len_value);
xwcstoutf(value, w_value, len_value);

/* Be mean and invalidate the previous getenv() result */
{ int offset = !strcmp("GIT_COMMITTER_EMAIL", name) || !strcmp("GIT_AUTHOR_EMAIL", name) ? 2 : (!strcmp("GIT_COMMITTER_DATE", name) || !strcmp("GIT_AUTHOR_DATE", name) ? 3 : 1); char *p = values[(value_counter + ARRAY_SIZE(values) - offset) % ARRAY_SIZE(values)]; if (p) { if (0) error("invalidating '%s' because of '%s'", p, name); xsnprintf(p, 16, "NONONONONONONO!"); } }
/*
* We return `value` which is an allocated value and the caller is NOT
* expecting to have to free it, so we keep a round-robin array,
Expand Down Expand Up @@ -2921,6 +2924,7 @@ static void setup_windows_environment(void)
* executable (by not mistaking the dir separators
* for escape characters).
*/
/* TODO: now that we no longer have a full cached env, we need to set this, right? */
convert_slashes(tmp);
}

Expand Down
Loading