From 6c5f9baa3bc0d63e141e0afc23110205379905a4 Mon Sep 17 00:00:00 2001 From: Jason Riedy Date: Tue, 23 Aug 2005 13:31:09 -0700 Subject: [PATCH 1/6] Replace zero-length array decls with []. C99 denotes variable-sized members with [], not [0]. Signed-off-by: Jason Riedy --- cache.h | 8 ++++---- commit.c | 2 +- ls-files.c | 2 +- receive-pack.c | 2 +- server-info.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cache.h b/cache.h index ba5c4ab7ee..e7f5a2e16f 100644 --- a/cache.h +++ b/cache.h @@ -100,7 +100,7 @@ struct cache_entry { unsigned int ce_size; unsigned char sha1[20]; unsigned short ce_flags; - char name[0]; + char name[]; }; #define CE_NAMEMASK (0x0fff) @@ -283,7 +283,7 @@ extern int checkout_entry(struct cache_entry *ce, struct checkout *state); extern struct alternate_object_database { struct alternate_object_database *next; char *name; - char base[0]; /* more */ + char base[]; /* more */ } *alt_odb_list; extern void prepare_alt_odb(void); @@ -296,7 +296,7 @@ extern struct packed_git { unsigned int pack_last_used; unsigned int pack_use_cnt; unsigned char sha1[20]; - char pack_name[0]; /* something like ".git/objects/pack/xxxxx.pack" */ + char pack_name[]; /* something like ".git/objects/pack/xxxxx.pack" */ } *packed_git; struct pack_entry { @@ -310,7 +310,7 @@ struct ref { unsigned char old_sha1[20]; unsigned char new_sha1[20]; struct ref *peer_ref; /* when renaming */ - char name[0]; + char name[]; }; extern int git_connect(int fd[2], char *url, const char *prog); diff --git a/commit.c b/commit.c index e51eda1524..56192587af 100644 --- a/commit.c +++ b/commit.c @@ -102,7 +102,7 @@ static unsigned long parse_commit_date(const char *buf) static struct commit_graft { unsigned char sha1[20]; int nr_parent; - unsigned char parent[0][20]; /* more */ + unsigned char parent[][20]; /* more */ } **commit_graft; static int commit_graft_alloc, commit_graft_nr; diff --git a/ls-files.c b/ls-files.c index 2c7aada88c..56f3919e06 100644 --- a/ls-files.c +++ b/ls-files.c @@ -205,7 +205,7 @@ static int excluded(const char *pathname) struct nond_on_fs { int len; - char name[0]; + char name[]; }; static struct nond_on_fs **dir; diff --git a/receive-pack.c b/receive-pack.c index 9026f1bf82..3a1b2ab694 100644 --- a/receive-pack.c +++ b/receive-pack.c @@ -24,7 +24,7 @@ struct command { unsigned char updated; unsigned char old_sha1[20]; unsigned char new_sha1[20]; - char ref_name[0]; + char ref_name[]; }; static struct command *commands = NULL; diff --git a/server-info.c b/server-info.c index 2b3aecab4a..cb58eb607e 100644 --- a/server-info.c +++ b/server-info.c @@ -70,7 +70,7 @@ static struct pack_info { int nr_alloc; int nr_heads; unsigned char (*head)[20]; - char dep[0]; /* more */ + char dep[]; /* more */ } **info; static int num_pack; static const char *objdir; From c7c81b3a51de2778535c8bb18d42a4bb7dfd57bc Mon Sep 17 00:00:00 2001 From: Jason Riedy Date: Tue, 23 Aug 2005 13:34:07 -0700 Subject: [PATCH 2/6] 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 --- apply.c | 2 +- cache.h | 4 ++++ connect.c | 6 ++++-- diff.c | 19 +++++++++++-------- fsck-cache.c | 5 ++++- path.c | 4 +++- pull.c | 2 +- rsh.c | 6 ++++-- sha1_file.c | 5 ++++- ssh-pull.c | 5 ++++- ssh-push.c | 4 +++- 11 files changed, 43 insertions(+), 19 deletions(-) diff --git a/apply.c b/apply.c index 7c1a8411f2..ee59be643e 100644 --- a/apply.c +++ b/apply.c @@ -1377,7 +1377,7 @@ static struct excludes { 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; while (x) { if (fnmatch(x->path, pathname, 0) == 0) diff --git a/cache.h b/cache.h index e7f5a2e16f..e4f4664572 100644 --- a/cache.h +++ b/cache.h @@ -58,7 +58,11 @@ * We accept older names for now but warn. */ extern char *gitenv_bc(const char *); +#ifdef __GNUC__ #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 diff --git a/connect.c b/connect.c index a6657b1384..c0bf869e96 100644 --- a/connect.c +++ b/connect.c @@ -383,8 +383,10 @@ int git_connect(int fd[2], char *url, const char *prog) close(pipefd[1][0]); close(pipefd[1][1]); if (protocol == PROTO_SSH) { - const char *ssh = getenv("GIT_SSH") ? : "ssh"; - const char *ssh_basename = strrchr(ssh, '/'); + const char *ssh, *ssh_basename; + ssh = getenv("GIT_SSH"); + if (!ssh) ssh = "ssh"; + ssh_basename = strrchr(ssh, '/'); if (!ssh_basename) ssh_basename = ssh; else diff --git a/diff.c b/diff.c index 137d0d0c0c..9015c81d76 100644 --- a/diff.c +++ b/diff.c @@ -19,6 +19,7 @@ static const char *external_diff(void) { static const char *external_diff_cmd = NULL; static int done_preparing = 0; + const char *env_diff_opts; if (done_preparing) return external_diff_cmd; @@ -31,11 +32,11 @@ static const char *external_diff(void) * * 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... */ - 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; return external_diff_cmd; @@ -530,10 +531,12 @@ static void run_external_diff(const char *pgm, pid_t pid; int status; static int atexit_asked = 0; + const char *othername; + othername = (other? other : name); if (one && two) { 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 && (temp[0].name == temp[0].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. */ if (one && two) - builtin_diff(name, other ? : name, temp, xfrm_msg, + builtin_diff(name, othername, temp, xfrm_msg, complete_rewrite); else 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) { fprintf(stderr, "queue[%d] %s (%s) %s %06o %s\n", - x, one ? : "", + x, one ? one : "", s->path, DIFF_FILE_VALID(s) ? "valid" : "invalid", s->mode, s->sha1_valid ? sha1_to_hex(s->sha1) : ""); fprintf(stderr, "queue[%d] %s size %lu flags %d\n", - x, one ? : "", + x, one ? one : "", 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->two, i, "two"); 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); } diff --git a/fsck-cache.c b/fsck-cache.c index 8091780193..ca24a1b844 100644 --- a/fsck-cache.c +++ b/fsck-cache.c @@ -390,7 +390,10 @@ static int fsck_head_link(void) char hex[40]; unsigned char sha1[20]; 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); if (readlink(path, link, sizeof(link)) < 0) diff --git a/path.c b/path.c index b85f087f43..142e575e5c 100644 --- a/path.c +++ b/path.c @@ -41,10 +41,12 @@ char *mkpath(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; unsigned len; + git_dir = gitenv(GIT_DIR_ENVIRONMENT); + if (!git_dir) git_dir = DEFAULT_GIT_DIR_ENVIRONMENT; len = strlen(git_dir); if (len > PATH_MAX-100) return bad_path; diff --git a/pull.c b/pull.c index e7bf83bb03..ff550441e9 100644 --- a/pull.c +++ b/pull.c @@ -156,7 +156,7 @@ static int loop(void) //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)) return -1; if (!obj->type) diff --git a/rsh.c b/rsh.c index bcb1c80d84..04cbdf7a67 100644 --- a/rsh.c +++ b/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"); } if (!fork()) { - const char *ssh = getenv("GIT_SSH") ? : "ssh"; - const char *ssh_basename = strrchr(ssh, '/'); + const char *ssh, *ssh_basename; + ssh = getenv("GIT_SSH"); + if (!ssh) ssh = "ssh"; + ssh_basename = strrchr(ssh, '/'); if (!ssh_basename) ssh_basename = ssh; else diff --git a/sha1_file.c b/sha1_file.c index 776697755a..fa37f1e3ef 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -283,7 +283,10 @@ void prepare_alt_odb(void) char *map; int fd; 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()); if (alt_odb_tail) diff --git a/ssh-pull.c b/ssh-pull.c index b7f313bf27..f1d8e706d3 100644 --- a/ssh-pull.c +++ b/ssh-pull.c @@ -87,7 +87,10 @@ int main(int argc, char **argv) char *commit_id; char *url; 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] == '-') { if (argv[arg][1] == 't') { diff --git a/ssh-push.c b/ssh-push.c index ee424a8712..5bd4569974 100644 --- a/ssh-push.c +++ b/ssh-push.c @@ -105,10 +105,12 @@ int main(int argc, char **argv) char *commit_id; char *url; int fd_in, fd_out; - const char *prog = getenv("GIT_SSH_PULL") ? : "git-ssh-pull"; + const char *prog; unsigned char sha1[20]; char hex[41]; + prog = getenv("GIT_SSH_PULL"); + if (!prog) prog = "git-ssh-pull"; while (arg < argc && argv[arg][0] == '-') { if (argv[arg][1] == 'w') arg++; From 3cd6ecda4a02e943934885910feeba957b730123 Mon Sep 17 00:00:00 2001 From: Jason Riedy Date: Tue, 23 Aug 2005 13:34:44 -0700 Subject: [PATCH 3/6] Include sys/time.h in daemon.c. Some systems and feature levels want sys/time.h for fd_set functionality. Signed-off-by: Jason Riedy --- daemon.c | 1 + 1 file changed, 1 insertion(+) diff --git a/daemon.c b/daemon.c index 932d908bad..fb3f25c486 100644 --- a/daemon.c +++ b/daemon.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include From e72a7d45dc67afa1328750d401ddd4dbeb2131d9 Mon Sep 17 00:00:00 2001 From: Jason Riedy Date: Tue, 23 Aug 2005 13:52:01 -0700 Subject: [PATCH 4/6] Replace unsetenv() and setenv() with older putenv(). Solaris 8 doesn't have the newer unsetenv() and setenv() functions, so replace them with putenv(). The one use of unsetenv() in fsck-cache.c now sets GIT_ALTERNATE_OBJECT_ DIRECTORIES to the empty string. Every place that var is used, NULLs are also replaced with empty strings, so it's ok. Signed-off-by: Jason Riedy --- fsck-cache.c | 2 +- receive-pack.c | 2 +- upload-pack.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fsck-cache.c b/fsck-cache.c index ca24a1b844..e53d01a40f 100644 --- a/fsck-cache.c +++ b/fsck-cache.c @@ -454,7 +454,7 @@ int main(int argc, char **argv) if (standalone && check_full) die("Only one of --standalone or --full can be used."); if (standalone) - unsetenv("GIT_ALTERNATE_OBJECT_DIRECTORIES"); + putenv("GIT_ALTERNATE_OBJECT_DIRECTORIES="); fsck_head_link(); fsck_object_dir(get_object_directory()); diff --git a/receive-pack.c b/receive-pack.c index 3a1b2ab694..1ef0c13935 100644 --- a/receive-pack.c +++ b/receive-pack.c @@ -269,7 +269,7 @@ int main(int argc, char **argv) /* If we have a ".git" directory, chdir to it */ chdir(".git"); - setenv("GIT_DIR", ".", 1); + putenv("GIT_DIR=."); if (access("objects", X_OK) < 0 || access("refs/heads", X_OK) < 0) die("%s doesn't appear to be a git directory", dir); diff --git a/upload-pack.c b/upload-pack.c index 95d3812051..da10742c44 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -179,7 +179,7 @@ int main(int argc, char **argv) chdir(".git"); if (access("objects", X_OK) || access("refs", X_OK)) die("git-upload-pack: %s doesn't seem to be a git archive", dir); - setenv("GIT_DIR", ".", 1); + putenv("GIT_DIR=."); upload_pack(); return 0; } From fb2af0375bcef9f5f5cbb1f4dc9f81459ce1f4b1 Mon Sep 17 00:00:00 2001 From: Jason Riedy Date: Tue, 23 Aug 2005 13:52:52 -0700 Subject: [PATCH 5/6] Replace C99 array initializers with code. The only use of C99 array initializers is in ident.c, so just replace it with initializing code. Signed-off-by: Jason Riedy --- ident.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/ident.c b/ident.c index 9ef636ee87..0fe81f6900 100644 --- a/ident.c +++ b/ident.c @@ -58,14 +58,24 @@ static int add_raw(char *buf, int size, int offset, const char *str) static int crud(unsigned char c) { - static const char crud_array[256] = { - [0 ... 31] = 1, - [' '] = 1, - ['.'] = 1, [','] = 1, - [':'] = 1, [';'] = 1, - ['<'] = 1, ['>'] = 1, - ['"'] = 1, ['\''] = 1, - }; + static char crud_array[256]; + static int crud_array_initialized = 0; + + if (!crud_array_initialized) { + int k; + + for (k = 0; k <= 31; ++k) crud_array[k] = 1; + crud_array[' '] = 1; + crud_array['.'] = 1; + crud_array[','] = 1; + crud_array[':'] = 1; + crud_array[';'] = 1; + crud_array['<'] = 1; + crud_array['>'] = 1; + crud_array['"'] = 1; + crud_array['\''] = 1; + crud_array_initialized = 1; + } return crud_array[c]; } From 928f74de22536129b696218073a3940ae4ab1199 Mon Sep 17 00:00:00 2001 From: Amos Waterland Date: Sun, 28 Aug 2005 23:05:36 -0500 Subject: [PATCH 6/6] [PATCH] tutorial note about git branch Explain that an asterisk will be displayed in front of the current branch when you run `git branch' to see which are available. Signed-off-by: Amos Waterland Signed-off-by: Junio C Hamano --- Documentation/tutorial.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/tutorial.txt b/Documentation/tutorial.txt index 997e958259..866dbbe9b8 100644 --- a/Documentation/tutorial.txt +++ b/Documentation/tutorial.txt @@ -671,6 +671,7 @@ you have, you can say git branch which is nothing more than a simple script around "ls .git/refs/heads". +There will be asterisk in front of the branch you are currently on. Sometimes you may wish to create a new branch _without_ actually checking it out and switching to it. If so, just use the command