Fix ?: statements.
Omitting the first branch in ?: is a GNU extension. Cute, but not supported by other compilers. Replaced mostly by explicit tests. Calls to getenv() simply are repeated on non-GNU compilers. Signed-off-by: Jason Riedy <ejr@cs.berkeley.edu>
This commit is contained in:
2
apply.c
2
apply.c
@ -1377,7 +1377,7 @@ static struct excludes {
|
|||||||
|
|
||||||
static int use_patch(struct patch *p)
|
static int use_patch(struct patch *p)
|
||||||
{
|
{
|
||||||
const char *pathname = p->new_name ? : p->old_name;
|
const char *pathname = p->new_name ? p->new_name : p->old_name;
|
||||||
struct excludes *x = excludes;
|
struct excludes *x = excludes;
|
||||||
while (x) {
|
while (x) {
|
||||||
if (fnmatch(x->path, pathname, 0) == 0)
|
if (fnmatch(x->path, pathname, 0) == 0)
|
||||||
|
4
cache.h
4
cache.h
@ -58,7 +58,11 @@
|
|||||||
* We accept older names for now but warn.
|
* We accept older names for now but warn.
|
||||||
*/
|
*/
|
||||||
extern char *gitenv_bc(const char *);
|
extern char *gitenv_bc(const char *);
|
||||||
|
#ifdef __GNUC__
|
||||||
#define gitenv(e) (getenv(e) ? : gitenv_bc(e))
|
#define gitenv(e) (getenv(e) ? : gitenv_bc(e))
|
||||||
|
#else
|
||||||
|
#define gitenv(e) (getenv(e) ? getenv(e) : gitenv_bc(e))
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Basic data structures for the directory cache
|
* Basic data structures for the directory cache
|
||||||
|
@ -383,8 +383,10 @@ int git_connect(int fd[2], char *url, const char *prog)
|
|||||||
close(pipefd[1][0]);
|
close(pipefd[1][0]);
|
||||||
close(pipefd[1][1]);
|
close(pipefd[1][1]);
|
||||||
if (protocol == PROTO_SSH) {
|
if (protocol == PROTO_SSH) {
|
||||||
const char *ssh = getenv("GIT_SSH") ? : "ssh";
|
const char *ssh, *ssh_basename;
|
||||||
const char *ssh_basename = strrchr(ssh, '/');
|
ssh = getenv("GIT_SSH");
|
||||||
|
if (!ssh) ssh = "ssh";
|
||||||
|
ssh_basename = strrchr(ssh, '/');
|
||||||
if (!ssh_basename)
|
if (!ssh_basename)
|
||||||
ssh_basename = ssh;
|
ssh_basename = ssh;
|
||||||
else
|
else
|
||||||
|
19
diff.c
19
diff.c
@ -19,6 +19,7 @@ static const char *external_diff(void)
|
|||||||
{
|
{
|
||||||
static const char *external_diff_cmd = NULL;
|
static const char *external_diff_cmd = NULL;
|
||||||
static int done_preparing = 0;
|
static int done_preparing = 0;
|
||||||
|
const char *env_diff_opts;
|
||||||
|
|
||||||
if (done_preparing)
|
if (done_preparing)
|
||||||
return external_diff_cmd;
|
return external_diff_cmd;
|
||||||
@ -31,11 +32,11 @@ static const char *external_diff(void)
|
|||||||
*
|
*
|
||||||
* GIT_DIFF_OPTS="-c";
|
* GIT_DIFF_OPTS="-c";
|
||||||
*/
|
*/
|
||||||
if (gitenv("GIT_EXTERNAL_DIFF"))
|
external_diff_cmd = gitenv("GIT_EXTERNAL_DIFF");
|
||||||
external_diff_cmd = gitenv("GIT_EXTERNAL_DIFF");
|
|
||||||
|
|
||||||
/* In case external diff fails... */
|
/* In case external diff fails... */
|
||||||
diff_opts = gitenv("GIT_DIFF_OPTS") ? : diff_opts;
|
env_diff_opts = gitenv("GIT_DIFF_OPTS");
|
||||||
|
if (env_diff_opts) diff_opts = env_diff_opts;
|
||||||
|
|
||||||
done_preparing = 1;
|
done_preparing = 1;
|
||||||
return external_diff_cmd;
|
return external_diff_cmd;
|
||||||
@ -530,10 +531,12 @@ static void run_external_diff(const char *pgm,
|
|||||||
pid_t pid;
|
pid_t pid;
|
||||||
int status;
|
int status;
|
||||||
static int atexit_asked = 0;
|
static int atexit_asked = 0;
|
||||||
|
const char *othername;
|
||||||
|
|
||||||
|
othername = (other? other : name);
|
||||||
if (one && two) {
|
if (one && two) {
|
||||||
prepare_temp_file(name, &temp[0], one);
|
prepare_temp_file(name, &temp[0], one);
|
||||||
prepare_temp_file(other ? : name, &temp[1], two);
|
prepare_temp_file(othername, &temp[1], two);
|
||||||
if (! atexit_asked &&
|
if (! atexit_asked &&
|
||||||
(temp[0].name == temp[0].tmp_path ||
|
(temp[0].name == temp[0].tmp_path ||
|
||||||
temp[1].name == temp[1].tmp_path)) {
|
temp[1].name == temp[1].tmp_path)) {
|
||||||
@ -574,7 +577,7 @@ static void run_external_diff(const char *pgm,
|
|||||||
* otherwise we use the built-in one.
|
* otherwise we use the built-in one.
|
||||||
*/
|
*/
|
||||||
if (one && two)
|
if (one && two)
|
||||||
builtin_diff(name, other ? : name, temp, xfrm_msg,
|
builtin_diff(name, othername, temp, xfrm_msg,
|
||||||
complete_rewrite);
|
complete_rewrite);
|
||||||
else
|
else
|
||||||
printf("* Unmerged path %s\n", name);
|
printf("* Unmerged path %s\n", name);
|
||||||
@ -889,13 +892,13 @@ int diff_queue_is_empty(void)
|
|||||||
void diff_debug_filespec(struct diff_filespec *s, int x, const char *one)
|
void diff_debug_filespec(struct diff_filespec *s, int x, const char *one)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "queue[%d] %s (%s) %s %06o %s\n",
|
fprintf(stderr, "queue[%d] %s (%s) %s %06o %s\n",
|
||||||
x, one ? : "",
|
x, one ? one : "",
|
||||||
s->path,
|
s->path,
|
||||||
DIFF_FILE_VALID(s) ? "valid" : "invalid",
|
DIFF_FILE_VALID(s) ? "valid" : "invalid",
|
||||||
s->mode,
|
s->mode,
|
||||||
s->sha1_valid ? sha1_to_hex(s->sha1) : "");
|
s->sha1_valid ? sha1_to_hex(s->sha1) : "");
|
||||||
fprintf(stderr, "queue[%d] %s size %lu flags %d\n",
|
fprintf(stderr, "queue[%d] %s size %lu flags %d\n",
|
||||||
x, one ? : "",
|
x, one ? one : "",
|
||||||
s->size, s->xfrm_flags);
|
s->size, s->xfrm_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -904,7 +907,7 @@ void diff_debug_filepair(const struct diff_filepair *p, int i)
|
|||||||
diff_debug_filespec(p->one, i, "one");
|
diff_debug_filespec(p->one, i, "one");
|
||||||
diff_debug_filespec(p->two, i, "two");
|
diff_debug_filespec(p->two, i, "two");
|
||||||
fprintf(stderr, "score %d, status %c stays %d broken %d\n",
|
fprintf(stderr, "score %d, status %c stays %d broken %d\n",
|
||||||
p->score, p->status ? : '?',
|
p->score, p->status ? p->status : '?',
|
||||||
p->source_stays, p->broken_pair);
|
p->source_stays, p->broken_pair);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,7 +390,10 @@ static int fsck_head_link(void)
|
|||||||
char hex[40];
|
char hex[40];
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
static char path[PATH_MAX], link[PATH_MAX];
|
static char path[PATH_MAX], link[PATH_MAX];
|
||||||
const char *git_dir = gitenv(GIT_DIR_ENVIRONMENT) ? : DEFAULT_GIT_DIR_ENVIRONMENT;
|
const char *git_dir;
|
||||||
|
|
||||||
|
git_dir = gitenv(GIT_DIR_ENVIRONMENT);
|
||||||
|
if (!git_dir) git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
|
||||||
|
|
||||||
snprintf(path, sizeof(path), "%s/HEAD", git_dir);
|
snprintf(path, sizeof(path), "%s/HEAD", git_dir);
|
||||||
if (readlink(path, link, sizeof(link)) < 0)
|
if (readlink(path, link, sizeof(link)) < 0)
|
||||||
|
4
path.c
4
path.c
@ -41,10 +41,12 @@ char *mkpath(const char *fmt, ...)
|
|||||||
|
|
||||||
char *git_path(const char *fmt, ...)
|
char *git_path(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
const char *git_dir = gitenv(GIT_DIR_ENVIRONMENT) ? : DEFAULT_GIT_DIR_ENVIRONMENT;
|
const char *git_dir;
|
||||||
va_list args;
|
va_list args;
|
||||||
unsigned len;
|
unsigned len;
|
||||||
|
|
||||||
|
git_dir = gitenv(GIT_DIR_ENVIRONMENT);
|
||||||
|
if (!git_dir) git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
|
||||||
len = strlen(git_dir);
|
len = strlen(git_dir);
|
||||||
if (len > PATH_MAX-100)
|
if (len > PATH_MAX-100)
|
||||||
return bad_path;
|
return bad_path;
|
||||||
|
2
pull.c
2
pull.c
@ -156,7 +156,7 @@ static int loop(void)
|
|||||||
|
|
||||||
//fprintf(stderr, "fetch %s\n", sha1_to_hex(obj->sha1));
|
//fprintf(stderr, "fetch %s\n", sha1_to_hex(obj->sha1));
|
||||||
|
|
||||||
if (make_sure_we_have_it(obj->type ?: "object",
|
if (make_sure_we_have_it(obj->type ? obj->type : "object",
|
||||||
obj->sha1))
|
obj->sha1))
|
||||||
return -1;
|
return -1;
|
||||||
if (!obj->type)
|
if (!obj->type)
|
||||||
|
6
rsh.c
6
rsh.c
@ -56,8 +56,10 @@ int setup_connection(int *fd_in, int *fd_out, const char *remote_prog,
|
|||||||
return error("Couldn't create socket");
|
return error("Couldn't create socket");
|
||||||
}
|
}
|
||||||
if (!fork()) {
|
if (!fork()) {
|
||||||
const char *ssh = getenv("GIT_SSH") ? : "ssh";
|
const char *ssh, *ssh_basename;
|
||||||
const char *ssh_basename = strrchr(ssh, '/');
|
ssh = getenv("GIT_SSH");
|
||||||
|
if (!ssh) ssh = "ssh";
|
||||||
|
ssh_basename = strrchr(ssh, '/');
|
||||||
if (!ssh_basename)
|
if (!ssh_basename)
|
||||||
ssh_basename = ssh;
|
ssh_basename = ssh;
|
||||||
else
|
else
|
||||||
|
@ -283,7 +283,10 @@ void prepare_alt_odb(void)
|
|||||||
char *map;
|
char *map;
|
||||||
int fd;
|
int fd;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *alt = gitenv(ALTERNATE_DB_ENVIRONMENT) ? : "";
|
char *alt;
|
||||||
|
|
||||||
|
alt = gitenv(ALTERNATE_DB_ENVIRONMENT);
|
||||||
|
if (!alt) alt = "";
|
||||||
|
|
||||||
sprintf(path, "%s/info/alternates", get_object_directory());
|
sprintf(path, "%s/info/alternates", get_object_directory());
|
||||||
if (alt_odb_tail)
|
if (alt_odb_tail)
|
||||||
|
@ -87,7 +87,10 @@ int main(int argc, char **argv)
|
|||||||
char *commit_id;
|
char *commit_id;
|
||||||
char *url;
|
char *url;
|
||||||
int arg = 1;
|
int arg = 1;
|
||||||
const char *prog = getenv("GIT_SSH_PUSH") ? : "git-ssh-push";
|
const char *prog;
|
||||||
|
|
||||||
|
prog = getenv("GIT_SSH_PUSH");
|
||||||
|
if (!prog) prog = "git-ssh-push";
|
||||||
|
|
||||||
while (arg < argc && argv[arg][0] == '-') {
|
while (arg < argc && argv[arg][0] == '-') {
|
||||||
if (argv[arg][1] == 't') {
|
if (argv[arg][1] == 't') {
|
||||||
|
@ -105,10 +105,12 @@ int main(int argc, char **argv)
|
|||||||
char *commit_id;
|
char *commit_id;
|
||||||
char *url;
|
char *url;
|
||||||
int fd_in, fd_out;
|
int fd_in, fd_out;
|
||||||
const char *prog = getenv("GIT_SSH_PULL") ? : "git-ssh-pull";
|
const char *prog;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
char hex[41];
|
char hex[41];
|
||||||
|
|
||||||
|
prog = getenv("GIT_SSH_PULL");
|
||||||
|
if (!prog) prog = "git-ssh-pull";
|
||||||
while (arg < argc && argv[arg][0] == '-') {
|
while (arg < argc && argv[arg][0] == '-') {
|
||||||
if (argv[arg][1] == 'w')
|
if (argv[arg][1] == 'w')
|
||||||
arg++;
|
arg++;
|
||||||
|
Reference in New Issue
Block a user