Const tightening.

Mark Wooding noticed there was a type mismatch warning in git.c; this
patch does things slightly differently (mostly tightening const) and
was what I was holding onto, waiting for the setup-revisions change
to be merged into the master branch.

Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Junio C Hamano
2006-03-05 02:47:29 -08:00
parent 4a5d693950
commit 9201c70742
10 changed files with 44 additions and 39 deletions

View File

@ -226,6 +226,7 @@ static void print_patch(struct patch *p)
} }
} }
#if 0
/* For debugging only */ /* For debugging only */
static void print_map(struct commit *cmit, struct commit *other) static void print_map(struct commit *cmit, struct commit *other)
{ {
@ -259,6 +260,7 @@ static void print_map(struct commit *cmit, struct commit *other)
printf("\n"); printf("\n");
} }
} }
#endif
// p is a patch from commit to other. // p is a patch from commit to other.
static void fill_line_map(struct commit *commit, struct commit *other, static void fill_line_map(struct commit *commit, struct commit *other,

View File

@ -29,10 +29,9 @@ const char *git_exec_path(void)
} }
int execv_git_cmd(char **argv) int execv_git_cmd(const char **argv)
{ {
char git_command[PATH_MAX + 1]; char git_command[PATH_MAX + 1];
char *tmp;
int len, err, i; int len, err, i;
const char *paths[] = { current_exec_path, const char *paths[] = { current_exec_path,
getenv("GIT_EXEC_PATH"), getenv("GIT_EXEC_PATH"),
@ -40,6 +39,8 @@ int execv_git_cmd(char **argv)
for (i = 0; i < sizeof(paths)/sizeof(paths[0]); ++i) { for (i = 0; i < sizeof(paths)/sizeof(paths[0]); ++i) {
const char *exec_dir = paths[i]; const char *exec_dir = paths[i];
const char *tmp;
if (!exec_dir) continue; if (!exec_dir) continue;
if (*exec_dir != '/') { if (*exec_dir != '/') {
@ -82,7 +83,7 @@ int execv_git_cmd(char **argv)
argv[0] = git_command; argv[0] = git_command;
/* execve() can only ever return if it fails */ /* execve() can only ever return if it fails */
execve(git_command, argv, environ); execve(git_command, (char **)argv, environ);
err = errno; err = errno;
@ -93,11 +94,11 @@ int execv_git_cmd(char **argv)
} }
int execl_git_cmd(char *cmd,...) int execl_git_cmd(const char *cmd,...)
{ {
int argc; int argc;
char *argv[MAX_ARGS + 1]; const char *argv[MAX_ARGS + 1];
char *arg; const char *arg;
va_list param; va_list param;
va_start(param, cmd); va_start(param, cmd);

View File

@ -3,8 +3,8 @@
extern void git_set_exec_path(const char *exec_path); extern void git_set_exec_path(const char *exec_path);
extern const char* git_exec_path(void); extern const char* git_exec_path(void);
extern int execv_git_cmd(char **argv); /* NULL terminated */ extern int execv_git_cmd(const char **argv); /* NULL terminated */
extern int execl_git_cmd(char *cmd, ...); extern int execl_git_cmd(const char *cmd, ...);
#endif /* __GIT_EXEC_CMD_H_ */ #endif /* __GIT_EXEC_CMD_H_ */

32
git.c
View File

@ -216,33 +216,33 @@ static void prepend_to_path(const char *dir, int len)
setenv("PATH", path, 1); setenv("PATH", path, 1);
} }
static void show_man_page(char *git_cmd) static void show_man_page(const char *git_cmd)
{ {
char *page; const char *page;
if (!strncmp(git_cmd, "git", 3)) if (!strncmp(git_cmd, "git", 3))
page = git_cmd; page = git_cmd;
else { else {
int page_len = strlen(git_cmd) + 4; int page_len = strlen(git_cmd) + 4;
char *p = malloc(page_len + 1);
page = malloc(page_len + 1); strcpy(p, "git-");
strcpy(page, "git-"); strcpy(p + 4, git_cmd);
strcpy(page + 4, git_cmd); p[page_len] = 0;
page[page_len] = 0; page = p;
} }
execlp("man", "man", page, NULL); execlp("man", "man", page, NULL);
} }
static int cmd_version(int argc, char **argv, char **envp) static int cmd_version(int argc, const char **argv, char **envp)
{ {
printf("git version %s\n", GIT_VERSION); printf("git version %s\n", GIT_VERSION);
return 0; return 0;
} }
static int cmd_help(int argc, char **argv, char **envp) static int cmd_help(int argc, const char **argv, char **envp)
{ {
char *help_cmd = argv[1]; const char *help_cmd = argv[1];
if (!help_cmd) if (!help_cmd)
cmd_usage(git_exec_path(), NULL); cmd_usage(git_exec_path(), NULL);
show_man_page(help_cmd); show_man_page(help_cmd);
@ -251,7 +251,7 @@ static int cmd_help(int argc, char **argv, char **envp)
#define LOGSIZE (65536) #define LOGSIZE (65536)
static int cmd_log(int argc, char **argv, char **envp) static int cmd_log(int argc, const char **argv, char **envp)
{ {
struct rev_info rev; struct rev_info rev;
struct commit *commit; struct commit *commit;
@ -263,7 +263,7 @@ static int cmd_log(int argc, char **argv, char **envp)
argc = setup_revisions(argc, argv, &rev, "HEAD"); argc = setup_revisions(argc, argv, &rev, "HEAD");
while (1 < argc) { while (1 < argc) {
char *arg = argv[1]; const char *arg = argv[1];
if (!strncmp(arg, "--pretty", 8)) { if (!strncmp(arg, "--pretty", 8)) {
commit_format = get_commit_format(arg + 8); commit_format = get_commit_format(arg + 8);
if (commit_format == CMIT_FMT_ONELINE) if (commit_format == CMIT_FMT_ONELINE)
@ -325,12 +325,12 @@ static int cmd_log(int argc, char **argv, char **envp)
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
static void handle_internal_command(int argc, char **argv, char **envp) static void handle_internal_command(int argc, const char **argv, char **envp)
{ {
const char *cmd = argv[0]; const char *cmd = argv[0];
static struct cmd_struct { static struct cmd_struct {
const char *cmd; const char *cmd;
int (*fn)(int, char **, char **); int (*fn)(int, const char **, char **);
} commands[] = { } commands[] = {
{ "version", cmd_version }, { "version", cmd_version },
{ "help", cmd_help }, { "help", cmd_help },
@ -346,9 +346,9 @@ static void handle_internal_command(int argc, char **argv, char **envp)
} }
} }
int main(int argc, char **argv, char **envp) int main(int argc, const char **argv, char **envp)
{ {
char *cmd = argv[0]; const char *cmd = argv[0];
char *slash = strrchr(cmd, '/'); char *slash = strrchr(cmd, '/');
char git_command[PATH_MAX + 1]; char git_command[PATH_MAX + 1];
const char *exec_path = NULL; const char *exec_path = NULL;

View File

@ -6,7 +6,7 @@
static const char receive_pack_usage[] = "git-receive-pack <git-dir>"; static const char receive_pack_usage[] = "git-receive-pack <git-dir>";
static char *unpacker[] = { "unpack-objects", NULL }; static const char *unpacker[] = { "unpack-objects", NULL };
static int report_status = 0; static int report_status = 0;
@ -177,7 +177,7 @@ static void run_update_post_hook(struct command *cmd)
{ {
struct command *cmd_p; struct command *cmd_p;
int argc; int argc;
char **argv; const char **argv;
if (access(update_post_hook, X_OK) < 0) if (access(update_post_hook, X_OK) < 0)
return; return;
@ -190,10 +190,12 @@ static void run_update_post_hook(struct command *cmd)
argv[0] = update_post_hook; argv[0] = update_post_hook;
for (argc = 1, cmd_p = cmd; cmd_p; cmd_p = cmd_p->next) { for (argc = 1, cmd_p = cmd; cmd_p; cmd_p = cmd_p->next) {
char *p;
if (cmd_p->error_string) if (cmd_p->error_string)
continue; continue;
argv[argc] = xmalloc(strlen(cmd_p->ref_name) + 1); p = xmalloc(strlen(cmd_p->ref_name) + 1);
strcpy(argv[argc], cmd_p->ref_name); strcpy(p, cmd_p->ref_name);
argv[argc] = p;
argc++; argc++;
} }
argv[argc] = NULL; argv[argc] = NULL;

View File

@ -3,7 +3,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include "exec_cmd.h" #include "exec_cmd.h"
int run_command_v_opt(int argc, char **argv, int flags) int run_command_v_opt(int argc, const char **argv, int flags)
{ {
pid_t pid = fork(); pid_t pid = fork();
@ -47,7 +47,7 @@ int run_command_v_opt(int argc, char **argv, int flags)
} }
} }
int run_command_v(int argc, char **argv) int run_command_v(int argc, const char **argv)
{ {
return run_command_v_opt(argc, argv, 0); return run_command_v_opt(argc, argv, 0);
} }
@ -55,7 +55,7 @@ int run_command_v(int argc, char **argv)
int run_command(const char *cmd, ...) int run_command(const char *cmd, ...)
{ {
int argc; int argc;
char *argv[MAX_RUN_COMMAND_ARGS]; const char *argv[MAX_RUN_COMMAND_ARGS];
const char *arg; const char *arg;
va_list param; va_list param;

View File

@ -13,8 +13,8 @@ enum {
#define RUN_COMMAND_NO_STDIO 1 #define RUN_COMMAND_NO_STDIO 1
#define RUN_GIT_CMD 2 /*If this is to be git sub-command */ #define RUN_GIT_CMD 2 /*If this is to be git sub-command */
int run_command_v_opt(int argc, char **argv, int opt); int run_command_v_opt(int argc, const char **argv, int opt);
int run_command_v(int argc, char **argv); int run_command_v(int argc, const char **argv);
int run_command(const char *cmd, ...); int run_command(const char *cmd, ...);
#endif #endif

View File

@ -27,7 +27,7 @@ static int is_zero_sha1(const unsigned char *sha1)
static void exec_pack_objects(void) static void exec_pack_objects(void)
{ {
static char *args[] = { static const char *args[] = {
"pack-objects", "pack-objects",
"--stdout", "--stdout",
NULL NULL
@ -39,7 +39,7 @@ static void exec_pack_objects(void)
static void exec_rev_list(struct ref *refs) static void exec_rev_list(struct ref *refs)
{ {
struct ref *ref; struct ref *ref;
static char *args[1000]; static const char *args[1000];
int i = 0, j; int i = 0, j;
args[i++] = "rev-list"; /* 0 */ args[i++] = "rev-list"; /* 0 */

View File

@ -15,7 +15,7 @@ static int do_generic_cmd(const char *me, char *arg)
my_argv[1] = arg; my_argv[1] = arg;
my_argv[2] = NULL; my_argv[2] = NULL;
return execv_git_cmd((char**) my_argv); return execv_git_cmd(my_argv);
} }
static struct commands { static struct commands {

View File

@ -46,7 +46,7 @@ static void create_pack_file(void)
if (!pid) { if (!pid) {
int i; int i;
int args; int args;
char **argv; const char **argv;
char *buf; char *buf;
char **p; char **p;
@ -56,9 +56,9 @@ static void create_pack_file(void)
} }
else else
args = nr_has + nr_needs + 5; args = nr_has + nr_needs + 5;
argv = xmalloc(args * sizeof(char *)); p = xmalloc(args * sizeof(char *));
argv = (const char **) p;
buf = xmalloc(args * 45); buf = xmalloc(args * 45);
p = argv;
dup2(fd[1], 1); dup2(fd[1], 1);
close(0); close(0);