Skip to content

Commit c7c81b3

Browse files
author
Jason Riedy
committed
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>
1 parent 6c5f9ba commit c7c81b3

File tree

11 files changed

+43
-19
lines changed

11 files changed

+43
-19
lines changed

apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ static struct excludes {
13771377

13781378
static int use_patch(struct patch *p)
13791379
{
1380-
const char *pathname = p->new_name ? : p->old_name;
1380+
const char *pathname = p->new_name ? p->new_name : p->old_name;
13811381
struct excludes *x = excludes;
13821382
while (x) {
13831383
if (fnmatch(x->path, pathname, 0) == 0)

cache.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@
5858
* We accept older names for now but warn.
5959
*/
6060
extern char *gitenv_bc(const char *);
61+
#ifdef __GNUC__
6162
#define gitenv(e) (getenv(e) ? : gitenv_bc(e))
63+
#else
64+
#define gitenv(e) (getenv(e) ? getenv(e) : gitenv_bc(e))
65+
#endif
6266

6367
/*
6468
* Basic data structures for the directory cache

connect.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,10 @@ int git_connect(int fd[2], char *url, const char *prog)
383383
close(pipefd[1][0]);
384384
close(pipefd[1][1]);
385385
if (protocol == PROTO_SSH) {
386-
const char *ssh = getenv("GIT_SSH") ? : "ssh";
387-
const char *ssh_basename = strrchr(ssh, '/');
386+
const char *ssh, *ssh_basename;
387+
ssh = getenv("GIT_SSH");
388+
if (!ssh) ssh = "ssh";
389+
ssh_basename = strrchr(ssh, '/');
388390
if (!ssh_basename)
389391
ssh_basename = ssh;
390392
else

diff.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static const char *external_diff(void)
1919
{
2020
static const char *external_diff_cmd = NULL;
2121
static int done_preparing = 0;
22+
const char *env_diff_opts;
2223

2324
if (done_preparing)
2425
return external_diff_cmd;
@@ -31,11 +32,11 @@ static const char *external_diff(void)
3132
*
3233
* GIT_DIFF_OPTS="-c";
3334
*/
34-
if (gitenv("GIT_EXTERNAL_DIFF"))
35-
external_diff_cmd = gitenv("GIT_EXTERNAL_DIFF");
35+
external_diff_cmd = gitenv("GIT_EXTERNAL_DIFF");
3636

3737
/* In case external diff fails... */
38-
diff_opts = gitenv("GIT_DIFF_OPTS") ? : diff_opts;
38+
env_diff_opts = gitenv("GIT_DIFF_OPTS");
39+
if (env_diff_opts) diff_opts = env_diff_opts;
3940

4041
done_preparing = 1;
4142
return external_diff_cmd;
@@ -530,10 +531,12 @@ static void run_external_diff(const char *pgm,
530531
pid_t pid;
531532
int status;
532533
static int atexit_asked = 0;
534+
const char *othername;
533535

536+
othername = (other? other : name);
534537
if (one && two) {
535538
prepare_temp_file(name, &temp[0], one);
536-
prepare_temp_file(other ? : name, &temp[1], two);
539+
prepare_temp_file(othername, &temp[1], two);
537540
if (! atexit_asked &&
538541
(temp[0].name == temp[0].tmp_path ||
539542
temp[1].name == temp[1].tmp_path)) {
@@ -574,7 +577,7 @@ static void run_external_diff(const char *pgm,
574577
* otherwise we use the built-in one.
575578
*/
576579
if (one && two)
577-
builtin_diff(name, other ? : name, temp, xfrm_msg,
580+
builtin_diff(name, othername, temp, xfrm_msg,
578581
complete_rewrite);
579582
else
580583
printf("* Unmerged path %s\n", name);
@@ -889,13 +892,13 @@ int diff_queue_is_empty(void)
889892
void diff_debug_filespec(struct diff_filespec *s, int x, const char *one)
890893
{
891894
fprintf(stderr, "queue[%d] %s (%s) %s %06o %s\n",
892-
x, one ? : "",
895+
x, one ? one : "",
893896
s->path,
894897
DIFF_FILE_VALID(s) ? "valid" : "invalid",
895898
s->mode,
896899
s->sha1_valid ? sha1_to_hex(s->sha1) : "");
897900
fprintf(stderr, "queue[%d] %s size %lu flags %d\n",
898-
x, one ? : "",
901+
x, one ? one : "",
899902
s->size, s->xfrm_flags);
900903
}
901904

@@ -904,7 +907,7 @@ void diff_debug_filepair(const struct diff_filepair *p, int i)
904907
diff_debug_filespec(p->one, i, "one");
905908
diff_debug_filespec(p->two, i, "two");
906909
fprintf(stderr, "score %d, status %c stays %d broken %d\n",
907-
p->score, p->status ? : '?',
910+
p->score, p->status ? p->status : '?',
908911
p->source_stays, p->broken_pair);
909912
}
910913

fsck-cache.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,10 @@ static int fsck_head_link(void)
390390
char hex[40];
391391
unsigned char sha1[20];
392392
static char path[PATH_MAX], link[PATH_MAX];
393-
const char *git_dir = gitenv(GIT_DIR_ENVIRONMENT) ? : DEFAULT_GIT_DIR_ENVIRONMENT;
393+
const char *git_dir;
394+
395+
git_dir = gitenv(GIT_DIR_ENVIRONMENT);
396+
if (!git_dir) git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
394397

395398
snprintf(path, sizeof(path), "%s/HEAD", git_dir);
396399
if (readlink(path, link, sizeof(link)) < 0)

path.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ char *mkpath(const char *fmt, ...)
4141

4242
char *git_path(const char *fmt, ...)
4343
{
44-
const char *git_dir = gitenv(GIT_DIR_ENVIRONMENT) ? : DEFAULT_GIT_DIR_ENVIRONMENT;
44+
const char *git_dir;
4545
va_list args;
4646
unsigned len;
4747

48+
git_dir = gitenv(GIT_DIR_ENVIRONMENT);
49+
if (!git_dir) git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
4850
len = strlen(git_dir);
4951
if (len > PATH_MAX-100)
5052
return bad_path;

pull.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static int loop(void)
156156

157157
//fprintf(stderr, "fetch %s\n", sha1_to_hex(obj->sha1));
158158

159-
if (make_sure_we_have_it(obj->type ?: "object",
159+
if (make_sure_we_have_it(obj->type ? obj->type : "object",
160160
obj->sha1))
161161
return -1;
162162
if (!obj->type)

rsh.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ int setup_connection(int *fd_in, int *fd_out, const char *remote_prog,
5656
return error("Couldn't create socket");
5757
}
5858
if (!fork()) {
59-
const char *ssh = getenv("GIT_SSH") ? : "ssh";
60-
const char *ssh_basename = strrchr(ssh, '/');
59+
const char *ssh, *ssh_basename;
60+
ssh = getenv("GIT_SSH");
61+
if (!ssh) ssh = "ssh";
62+
ssh_basename = strrchr(ssh, '/');
6163
if (!ssh_basename)
6264
ssh_basename = ssh;
6365
else

sha1_file.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,10 @@ void prepare_alt_odb(void)
283283
char *map;
284284
int fd;
285285
struct stat st;
286-
char *alt = gitenv(ALTERNATE_DB_ENVIRONMENT) ? : "";
286+
char *alt;
287+
288+
alt = gitenv(ALTERNATE_DB_ENVIRONMENT);
289+
if (!alt) alt = "";
287290

288291
sprintf(path, "%s/info/alternates", get_object_directory());
289292
if (alt_odb_tail)

ssh-pull.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ int main(int argc, char **argv)
8787
char *commit_id;
8888
char *url;
8989
int arg = 1;
90-
const char *prog = getenv("GIT_SSH_PUSH") ? : "git-ssh-push";
90+
const char *prog;
91+
92+
prog = getenv("GIT_SSH_PUSH");
93+
if (!prog) prog = "git-ssh-push";
9194

9295
while (arg < argc && argv[arg][0] == '-') {
9396
if (argv[arg][1] == 't') {

0 commit comments

Comments
 (0)