@matheusbsbs / matheus-bagliano / commits / 9201c70742
Fork 0

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>

Junio C Hamano committed Mar 5, 2006 at 02:47 UTC 9201c707426b3dc0c894775416f576c25c008d46
10 files changed +44 -39
blame.c
+2
@@ -226,6 +226,7 @@ static void print_patch(struct patch *p)
226 }
227 }
228
229 +#if 0
230 /* For debugging only */
231 static void print_map(struct commit *cmit, struct commit *other)
232 {
@@ -259,6 +260,7 @@ static void print_map(struct commit *cmit, struct commit *other)
260 printf("\n");
261 }
262 }
263 +#endif
264
265 // p is a patch from commit to other.
266 static void fill_line_map(struct commit *commit, struct commit *other,
exec_cmd.c
+7 -6
@@ -29,10 +29,9 @@ const char *git_exec_path(void)
29 }
30
31
32 -int execv_git_cmd(char **argv)
32 +int execv_git_cmd(const char **argv)
33 {
34 char git_command[PATH_MAX + 1];
35 - char *tmp;
35 int len, err, i;
36 const char *paths[] = { current_exec_path,
37 getenv("GIT_EXEC_PATH"),
@@ -40,6 +39,8 @@ int execv_git_cmd(char **argv)
39
40 for (i = 0; i < sizeof(paths)/sizeof(paths[0]); ++i) {
41 const char *exec_dir = paths[i];
42 + const char *tmp;
43 +
44 if (!exec_dir) continue;
45
46 if (*exec_dir != '/') {
@@ -82,7 +83,7 @@ int execv_git_cmd(char **argv)
83 argv[0] = git_command;
84
85 /* execve() can only ever return if it fails */
85 - execve(git_command, argv, environ);
86 + execve(git_command, (char **)argv, environ);
87
88 err = errno;
89
@@ -93,11 +94,11 @@ int execv_git_cmd(char **argv)
94 }
95
96
96 -int execl_git_cmd(char *cmd,...)
97 +int execl_git_cmd(const char *cmd,...)
98 {
99 int argc;
99 - char *argv[MAX_ARGS + 1];
100 - char *arg;
100 + const char *argv[MAX_ARGS + 1];
101 + const char *arg;
102 va_list param;
103
104 va_start(param, cmd);
exec_cmd.h
+2 -2
@@ -3,8 +3,8 @@
3
4 extern void git_set_exec_path(const char *exec_path);
5 extern const char* git_exec_path(void);
6 -extern int execv_git_cmd(char **argv); /* NULL terminated */
7 -extern int execl_git_cmd(char *cmd, ...);
6 +extern int execv_git_cmd(const char **argv); /* NULL terminated */
7 +extern int execl_git_cmd(const char *cmd, ...);
8
9
10 #endif /* __GIT_EXEC_CMD_H_ */
git.c
+16 -16
@@ -216,33 +216,33 @@ static void prepend_to_path(const char *dir, int len)
216 setenv("PATH", path, 1);
217 }
218
219 -static void show_man_page(char *git_cmd)
219 +static void show_man_page(const char *git_cmd)
220 {
221 - char *page;
221 + const char *page;
222
223 if (!strncmp(git_cmd, "git", 3))
224 page = git_cmd;
225 else {
226 int page_len = strlen(git_cmd) + 4;
227 -
228 - page = malloc(page_len + 1);
229 - strcpy(page, "git-");
230 - strcpy(page + 4, git_cmd);
231 - page[page_len] = 0;
227 + char *p = malloc(page_len + 1);
228 + strcpy(p, "git-");
229 + strcpy(p + 4, git_cmd);
230 + p[page_len] = 0;
231 + page = p;
232 }
233
234 execlp("man", "man", page, NULL);
235 }
236
237 -static int cmd_version(int argc, char **argv, char **envp)
237 +static int cmd_version(int argc, const char **argv, char **envp)
238 {
239 printf("git version %s\n", GIT_VERSION);
240 return 0;
241 }
242
243 -static int cmd_help(int argc, char **argv, char **envp)
243 +static int cmd_help(int argc, const char **argv, char **envp)
244 {
245 - char *help_cmd = argv[1];
245 + const char *help_cmd = argv[1];
246 if (!help_cmd)
247 cmd_usage(git_exec_path(), NULL);
248 show_man_page(help_cmd);
@@ -251,7 +251,7 @@ static int cmd_help(int argc, char **argv, char **envp)
251
252 #define LOGSIZE (65536)
253
254 -static int cmd_log(int argc, char **argv, char **envp)
254 +static int cmd_log(int argc, const char **argv, char **envp)
255 {
256 struct rev_info rev;
257 struct commit *commit;
@@ -263,7 +263,7 @@ static int cmd_log(int argc, char **argv, char **envp)
263
264 argc = setup_revisions(argc, argv, &rev, "HEAD");
265 while (1 < argc) {
266 - char *arg = argv[1];
266 + const char *arg = argv[1];
267 if (!strncmp(arg, "--pretty", 8)) {
268 commit_format = get_commit_format(arg + 8);
269 if (commit_format == CMIT_FMT_ONELINE)
@@ -325,12 +325,12 @@ static int cmd_log(int argc, char **argv, char **envp)
325
326 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
327
328 -static void handle_internal_command(int argc, char **argv, char **envp)
328 +static void handle_internal_command(int argc, const char **argv, char **envp)
329 {
330 const char *cmd = argv[0];
331 static struct cmd_struct {
332 const char *cmd;
333 - int (*fn)(int, char **, char **);
333 + int (*fn)(int, const char **, char **);
334 } commands[] = {
335 { "version", cmd_version },
336 { "help", cmd_help },
@@ -346,9 +346,9 @@ static void handle_internal_command(int argc, char **argv, char **envp)
346 }
347 }
348
349 -int main(int argc, char **argv, char **envp)
349 +int main(int argc, const char **argv, char **envp)
350 {
351 - char *cmd = argv[0];
351 + const char *cmd = argv[0];
352 char *slash = strrchr(cmd, '/');
353 char git_command[PATH_MAX + 1];
354 const char *exec_path = NULL;
receive-pack.c
+6 -4
@@ -6,7 +6,7 @@
6
7 static const char receive_pack_usage[] = "git-receive-pack <git-dir>";
8
9 -static char *unpacker[] = { "unpack-objects", NULL };
9 +static const char *unpacker[] = { "unpack-objects", NULL };
10
11 static int report_status = 0;
12
@@ -177,7 +177,7 @@ static void run_update_post_hook(struct command *cmd)
177 {
178 struct command *cmd_p;
179 int argc;
180 - char **argv;
180 + const char **argv;
181
182 if (access(update_post_hook, X_OK) < 0)
183 return;
@@ -190,10 +190,12 @@ static void run_update_post_hook(struct command *cmd)
190 argv[0] = update_post_hook;
191
192 for (argc = 1, cmd_p = cmd; cmd_p; cmd_p = cmd_p->next) {
193 + char *p;
194 if (cmd_p->error_string)
195 continue;
195 - argv[argc] = xmalloc(strlen(cmd_p->ref_name) + 1);
196 - strcpy(argv[argc], cmd_p->ref_name);
196 + p = xmalloc(strlen(cmd_p->ref_name) + 1);
197 + strcpy(p, cmd_p->ref_name);
198 + argv[argc] = p;
199 argc++;
200 }
201 argv[argc] = NULL;
run-command.c
+3 -3
@@ -3,7 +3,7 @@
3 #include <sys/wait.h>
4 #include "exec_cmd.h"
5
6 -int run_command_v_opt(int argc, char **argv, int flags)
6 +int run_command_v_opt(int argc, const char **argv, int flags)
7 {
8 pid_t pid = fork();
9
@@ -47,7 +47,7 @@ int run_command_v_opt(int argc, char **argv, int flags)
47 }
48 }
49
50 -int run_command_v(int argc, char **argv)
50 +int run_command_v(int argc, const char **argv)
51 {
52 return run_command_v_opt(argc, argv, 0);
53 }
@@ -55,7 +55,7 @@ int run_command_v(int argc, char **argv)
55 int run_command(const char *cmd, ...)
56 {
57 int argc;
58 - char *argv[MAX_RUN_COMMAND_ARGS];
58 + const char *argv[MAX_RUN_COMMAND_ARGS];
59 const char *arg;
60 va_list param;
61
run-command.h
+2 -2
@@ -13,8 +13,8 @@ enum {
13
14 #define RUN_COMMAND_NO_STDIO 1
15 #define RUN_GIT_CMD 2 /*If this is to be git sub-command */
16 -int run_command_v_opt(int argc, char **argv, int opt);
17 -int run_command_v(int argc, char **argv);
16 +int run_command_v_opt(int argc, const char **argv, int opt);
17 +int run_command_v(int argc, const char **argv);
18 int run_command(const char *cmd, ...);
19
20 #endif
send-pack.c
+2 -2
@@ -27,7 +27,7 @@ static int is_zero_sha1(const unsigned char *sha1)
27
28 static void exec_pack_objects(void)
29 {
30 - static char *args[] = {
30 + static const char *args[] = {
31 "pack-objects",
32 "--stdout",
33 NULL
@@ -39,7 +39,7 @@ static void exec_pack_objects(void)
39 static void exec_rev_list(struct ref *refs)
40 {
41 struct ref *ref;
42 - static char *args[1000];
42 + static const char *args[1000];
43 int i = 0, j;
44
45 args[i++] = "rev-list"; /* 0 */
shell.c
+1 -1
@@ -15,7 +15,7 @@ static int do_generic_cmd(const char *me, char *arg)
15 my_argv[1] = arg;
16 my_argv[2] = NULL;
17
18 - return execv_git_cmd((char**) my_argv);
18 + return execv_git_cmd(my_argv);
19 }
20
21 static struct commands {
upload-pack.c
+3 -3
@@ -46,7 +46,7 @@ static void create_pack_file(void)
46 if (!pid) {
47 int i;
48 int args;
49 - char **argv;
49 + const char **argv;
50 char *buf;
51 char **p;
52
@@ -56,9 +56,9 @@ static void create_pack_file(void)
56 }
57 else
58 args = nr_has + nr_needs + 5;
59 - argv = xmalloc(args * sizeof(char *));
59 + p = xmalloc(args * sizeof(char *));
60 + argv = (const char **) p;
61 buf = xmalloc(args * 45);
61 - p = argv;
62
63 dup2(fd[1], 1);
64 close(0);