@matheusbsbs / matheus-bagliano / commits / 3bb7256281
Fork 0

make "index-pack" a built-in

This required some fairly trivial packfile function 'const' cleanup, since the builtin commands get a const char *argv[] array. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Jan 22, 2010 at 07:55 UTC 3bb7256281bb1d291bb705a57dc3f30b26b7c127
7 files changed +16 -15
Makefile
+1 -1
@@ -388,7 +388,6 @@ EXTRA_PROGRAMS =
388 PROGRAMS += $(EXTRA_PROGRAMS)
389 PROGRAMS += git-fast-import$X
390 PROGRAMS += git-imap-send$X
391 -PROGRAMS += git-index-pack$X
391 PROGRAMS += git-shell$X
392 PROGRAMS += git-show-index$X
393 PROGRAMS += git-upload-pack$X
@@ -653,6 +652,7 @@ BUILTIN_OBJS += builtin-gc.o
652 BUILTIN_OBJS += builtin-grep.o
653 BUILTIN_OBJS += builtin-hash-object.o
654 BUILTIN_OBJS += builtin-help.o
655 +BUILTIN_OBJS += builtin-index-pack.o
656 BUILTIN_OBJS += builtin-init-db.o
657 BUILTIN_OBJS += builtin-log.o
658 BUILTIN_OBJS += builtin-ls-files.o
builtin-index-pack.c renamed
+7 -9
@@ -166,7 +166,7 @@ static void use(int bytes)
166 consumed_bytes += bytes;
167 }
168
169 -static char *open_pack_file(char *pack_name)
169 +static const char *open_pack_file(const char *pack_name)
170 {
171 if (from_stdin) {
172 input_fd = 0;
@@ -870,18 +870,16 @@ static int git_index_pack_config(const char *k, const char *v, void *cb)
870 return git_default_config(k, v, cb);
871 }
872
873 -int main(int argc, char **argv)
873 +int cmd_index_pack(int argc, const char **argv, const char *prefix)
874 {
875 int i, fix_thin_pack = 0;
876 - char *curr_pack, *pack_name = NULL;
877 - char *curr_index, *index_name = NULL;
876 + const char *curr_pack, *curr_index;
877 + const char *index_name = NULL, *pack_name = NULL;
878 const char *keep_name = NULL, *keep_msg = NULL;
879 char *index_name_buf = NULL, *keep_name_buf = NULL;
880 struct pack_idx_entry **idx_objects;
881 unsigned char pack_sha1[20];
882
883 - git_extract_argv0_path(argv[0]);
884 -
883 if (argc == 2 && !strcmp(argv[1], "-h"))
884 usage(index_pack_usage);
885
@@ -906,7 +904,7 @@ int main(int argc, char **argv)
904 }
905
906 for (i = 1; i < argc; i++) {
909 - char *arg = argv[i];
907 + const char *arg = argv[i];
908
909 if (*arg == '-') {
910 if (!strcmp(arg, "--stdin")) {
@@ -1039,9 +1037,9 @@ int main(int argc, char **argv)
1037 free(index_name_buf);
1038 free(keep_name_buf);
1039 if (pack_name == NULL)
1042 - free(curr_pack);
1040 + free((void *) curr_pack);
1041 if (index_name == NULL)
1044 - free(curr_index);
1042 + free((void *) curr_index);
1043
1044 return 0;
1045 }
builtin-pack-objects.c
+3 -2
@@ -525,7 +525,8 @@ static void write_pack_file(void)
525 if (!pack_to_stdout) {
526 mode_t mode = umask(0);
527 struct stat st;
528 - char *idx_tmp_name, tmpname[PATH_MAX];
528 + const char *idx_tmp_name;
529 + char tmpname[PATH_MAX];
530
531 umask(mode);
532 mode = 0444 & ~mode;
@@ -569,7 +570,7 @@ static void write_pack_file(void)
570 if (rename(idx_tmp_name, tmpname))
571 die_errno("unable to rename temporary index file");
572
572 - free(idx_tmp_name);
573 + free((void *) idx_tmp_name);
574 free(pack_tmp_name);
575 puts(sha1_to_hex(sha1));
576 }
builtin.h
+1
@@ -58,6 +58,7 @@ extern int cmd_grep(int argc, const char **argv, const char *prefix);
58 extern int cmd_hash_object(int argc, const char **argv, const char *prefix);
59 extern int cmd_help(int argc, const char **argv, const char *prefix);
60 extern int cmd_http_fetch(int argc, const char **argv, const char *prefix);
61 +extern int cmd_index_pack(int argc, const char **argv, const char *prefix);
62 extern int cmd_init_db(int argc, const char **argv, const char *prefix);
63 extern int cmd_log(int argc, const char **argv, const char *prefix);
64 extern int cmd_log_reflog(int argc, const char **argv, const char *prefix);
git.c
+1
@@ -320,6 +320,7 @@ static void handle_internal_command(int argc, const char **argv)
320 { "grep", cmd_grep, USE_PAGER },
321 { "hash-object", cmd_hash_object },
322 { "help", cmd_help },
323 + { "index-pack", cmd_index_pack },
324 { "init", cmd_init_db },
325 { "init-db", cmd_init_db },
326 { "log", cmd_log, RUN_SETUP | USE_PAGER },
pack-write.c
+2 -2
@@ -17,8 +17,8 @@ static int sha1_compare(const void *_a, const void *_b)
17 * the SHA1 hash of sorted object names. The objects array passed in
18 * will be sorted by SHA1 on exit.
19 */
20 -char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
21 - int nr_objects, unsigned char *sha1)
20 +const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects,
21 + int nr_objects, unsigned char *sha1)
22 {
23 struct sha1file *f;
24 struct pack_idx_entry **sorted_by_sha, **list, **last;
pack.h
+1 -1
@@ -55,7 +55,7 @@ struct pack_idx_entry {
55 off_t offset;
56 };
57
58 -extern char *write_idx_file(char *index_name, struct pack_idx_entry **objects, int nr_objects, unsigned char *sha1);
58 +extern const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects, int nr_objects, unsigned char *sha1);
59 extern int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr);
60 extern int verify_pack(struct packed_git *);
61 extern void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);