From d6b64ed0f3549f56c4d948dc2c0f12abc52fd6c9 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Thu, 3 Aug 2006 17:24:35 +0200 Subject: [PATCH 1/8] Make git-name-rev a builtin Signed-off-by: Matthias Kestenholz Signed-off-by: Junio C Hamano --- Makefile | 7 ++++--- name-rev.c => builtin-name-rev.c | 4 ++-- builtin.h | 1 + git.c | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) rename name-rev.c => builtin-name-rev.c (98%) diff --git a/Makefile b/Makefile index 700c77f564..132c9cf012 100644 --- a/Makefile +++ b/Makefile @@ -185,7 +185,7 @@ PROGRAMS = \ git-unpack-objects$X git-update-server-info$X \ git-upload-pack$X git-verify-pack$X \ git-symbolic-ref$X \ - git-name-rev$X git-pack-redundant$X git-var$X \ + git-pack-redundant$X git-var$X \ git-describe$X git-merge-tree$X git-blame$X git-imap-send$X BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \ @@ -198,7 +198,7 @@ BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \ git-apply$X git-show-branch$X git-diff-files$X git-update-index$X \ git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X \ git-fmt-merge-msg$X git-prune$X git-mv$X git-prune-packed$X \ - git-repo-config$X + git-repo-config$X git-name-rev$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -255,7 +255,8 @@ BUILTIN_OBJS = \ builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \ builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o \ builtin-update-ref.o builtin-fmt-merge-msg.o builtin-prune.o \ - builtin-mv.o builtin-prune-packed.o builtin-repo-config.o + builtin-mv.o builtin-prune-packed.o builtin-repo-config.o \ + builtin-name-rev.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/name-rev.c b/builtin-name-rev.c similarity index 98% rename from name-rev.c rename to builtin-name-rev.c index f92f14e32f..571bba4817 100644 --- a/name-rev.c +++ b/builtin-name-rev.c @@ -1,4 +1,5 @@ #include +#include "builtin.h" #include "cache.h" #include "commit.h" #include "tag.h" @@ -126,12 +127,11 @@ static const char* get_rev_name(struct object *o) return buffer; } -int main(int argc, char **argv) +int cmd_name_rev(int argc, const char **argv, const char *prefix) { struct object_array revs = { 0, 0, NULL }; int as_is = 0, all = 0, transform_stdin = 0; - setup_git_directory(); git_config(git_default_config); if (argc < 2) diff --git a/builtin.h b/builtin.h index 26ebcaf213..d1d9dc14f9 100644 --- a/builtin.h +++ b/builtin.h @@ -49,6 +49,7 @@ extern int cmd_update_ref(int argc, const char **argv, const char *prefix); extern int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix); extern int cmd_mv(int argc, const char **argv, const char *prefix); extern int cmd_repo_config(int argc, const char **argv, const char *prefix); +extern int cmd_name_rev(int argc, const char **argv, const char *prefix); extern int cmd_write_tree(int argc, const char **argv, const char *prefix); extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix); diff --git a/git.c b/git.c index 6e72a893b7..501a7815fc 100644 --- a/git.c +++ b/git.c @@ -265,6 +265,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "mv", cmd_mv, NEEDS_PREFIX }, { "prune-packed", cmd_prune_packed, NEEDS_PREFIX }, { "repo-config", cmd_repo_config }, + { "name-rev", cmd_name_rev, NEEDS_PREFIX }, }; int i; From 5d4a60033543e063bc9d77ca957de0187fb58fb3 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Thu, 3 Aug 2006 17:24:36 +0200 Subject: [PATCH 2/8] Make git-pack-objects a builtin Signed-off-by: Matthias Kestenholz Signed-off-by: Junio C Hamano --- Makefile | 6 +++--- pack-objects.c => builtin-pack-objects.c | 4 ++-- builtin.h | 1 + git.c | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) rename pack-objects.c => builtin-pack-objects.c (99%) diff --git a/Makefile b/Makefile index 132c9cf012..4fd62bcf6d 100644 --- a/Makefile +++ b/Makefile @@ -177,7 +177,7 @@ PROGRAMS = \ git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \ git-hash-object$X git-index-pack$X git-local-fetch$X \ git-merge-base$X \ - git-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \ + git-merge-index$X git-mktag$X git-mktree$X git-patch-id$X \ git-peek-remote$X git-receive-pack$X \ git-send-pack$X git-shell$X \ git-show-index$X git-ssh-fetch$X \ @@ -198,7 +198,7 @@ BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \ git-apply$X git-show-branch$X git-diff-files$X git-update-index$X \ git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X \ git-fmt-merge-msg$X git-prune$X git-mv$X git-prune-packed$X \ - git-repo-config$X git-name-rev$X + git-repo-config$X git-name-rev$X git-pack-objects$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -256,7 +256,7 @@ BUILTIN_OBJS = \ builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o \ builtin-update-ref.o builtin-fmt-merge-msg.o builtin-prune.o \ builtin-mv.o builtin-prune-packed.o builtin-repo-config.o \ - builtin-name-rev.o + builtin-name-rev.o builtin-pack-objects.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/pack-objects.c b/builtin-pack-objects.c similarity index 99% rename from pack-objects.c rename to builtin-pack-objects.c index 861c7f08ff..2301cd5c0f 100644 --- a/pack-objects.c +++ b/builtin-pack-objects.c @@ -1,3 +1,4 @@ +#include "builtin.h" #include "cache.h" #include "object.h" #include "blob.h" @@ -1226,7 +1227,7 @@ static int git_pack_config(const char *k, const char *v) return git_default_config(k, v); } -int main(int argc, char **argv) +int cmd_pack_objects(int argc, const char **argv, const char *prefix) { SHA_CTX ctx; char line[40 + 1 + PATH_MAX + 2]; @@ -1235,7 +1236,6 @@ int main(int argc, char **argv) int num_preferred_base = 0; int i; - setup_git_directory(); git_config(git_pack_config); progress = isatty(2); diff --git a/builtin.h b/builtin.h index d1d9dc14f9..bc57a04c05 100644 --- a/builtin.h +++ b/builtin.h @@ -50,6 +50,7 @@ extern int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix); extern int cmd_mv(int argc, const char **argv, const char *prefix); extern int cmd_repo_config(int argc, const char **argv, const char *prefix); extern int cmd_name_rev(int argc, const char **argv, const char *prefix); +extern int cmd_pack_objects(int argc, const char **argv, const char *prefix); extern int cmd_write_tree(int argc, const char **argv, const char *prefix); extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix); diff --git a/git.c b/git.c index 501a7815fc..5d58946f41 100644 --- a/git.c +++ b/git.c @@ -266,6 +266,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "prune-packed", cmd_prune_packed, NEEDS_PREFIX }, { "repo-config", cmd_repo_config }, { "name-rev", cmd_name_rev, NEEDS_PREFIX }, + { "pack-objects", cmd_pack_objects, NEEDS_PREFIX }, }; int i; From 6441363079d85cf17aee21b8925e9745c8abda16 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Thu, 3 Aug 2006 17:24:37 +0200 Subject: [PATCH 3/8] Make git-unpack-objects a builtin Signed-off-by: Matthias Kestenholz Signed-off-by: Junio C Hamano --- Makefile | 7 ++++--- unpack-objects.c => builtin-unpack-objects.c | 7 +++---- builtin.h | 1 + git.c | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) rename unpack-objects.c => builtin-unpack-objects.c (98%) diff --git a/Makefile b/Makefile index 4fd62bcf6d..b108a8aa7a 100644 --- a/Makefile +++ b/Makefile @@ -182,7 +182,7 @@ PROGRAMS = \ git-send-pack$X git-shell$X \ git-show-index$X git-ssh-fetch$X \ git-ssh-upload$X git-unpack-file$X \ - git-unpack-objects$X git-update-server-info$X \ + git-update-server-info$X \ git-upload-pack$X git-verify-pack$X \ git-symbolic-ref$X \ git-pack-redundant$X git-var$X \ @@ -198,7 +198,8 @@ BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \ git-apply$X git-show-branch$X git-diff-files$X git-update-index$X \ git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X \ git-fmt-merge-msg$X git-prune$X git-mv$X git-prune-packed$X \ - git-repo-config$X git-name-rev$X git-pack-objects$X + git-repo-config$X git-name-rev$X git-pack-objects$X \ + git-unpack-objects$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -256,7 +257,7 @@ BUILTIN_OBJS = \ builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o \ builtin-update-ref.o builtin-fmt-merge-msg.o builtin-prune.o \ builtin-mv.o builtin-prune-packed.o builtin-repo-config.o \ - builtin-name-rev.o builtin-pack-objects.o + builtin-name-rev.o builtin-pack-objects.o builtin-unpack-objects.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/unpack-objects.c b/builtin-unpack-objects.c similarity index 98% rename from unpack-objects.c rename to builtin-unpack-objects.c index 48c1ee7968..09d264d9f2 100644 --- a/unpack-objects.c +++ b/builtin-unpack-objects.c @@ -1,3 +1,4 @@ +#include "builtin.h" #include "cache.h" #include "object.h" #include "delta.h" @@ -112,7 +113,7 @@ static void write_object(void *buf, unsigned long size, const char *type) } static int resolve_delta(const char *type, - void *base, unsigned long base_size, + void *base, unsigned long base_size, void *delta, unsigned long delta_size) { void *result; @@ -260,13 +261,11 @@ static void unpack_all(void) die("unresolved deltas left after unpacking"); } -int main(int argc, char **argv) +int cmd_unpack_objects(int argc, const char **argv, const char *prefix) { int i; unsigned char sha1[20]; - setup_git_directory(); - quiet = !isatty(2); for (i = 1 ; i < argc; i++) { diff --git a/builtin.h b/builtin.h index bc57a04c05..af73c3c19e 100644 --- a/builtin.h +++ b/builtin.h @@ -51,6 +51,7 @@ extern int cmd_mv(int argc, const char **argv, const char *prefix); extern int cmd_repo_config(int argc, const char **argv, const char *prefix); extern int cmd_name_rev(int argc, const char **argv, const char *prefix); extern int cmd_pack_objects(int argc, const char **argv, const char *prefix); +extern int cmd_unpack_objects(int argc, const char **argv, const char *prefix); extern int cmd_write_tree(int argc, const char **argv, const char *prefix); extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix); diff --git a/git.c b/git.c index 5d58946f41..7c3a7f8fd1 100644 --- a/git.c +++ b/git.c @@ -267,6 +267,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "repo-config", cmd_repo_config }, { "name-rev", cmd_name_rev, NEEDS_PREFIX }, { "pack-objects", cmd_pack_objects, NEEDS_PREFIX }, + { "unpack-objects", cmd_unpack_objects, NEEDS_PREFIX }, }; int i; From 640ce1052bbd6a8f1dd4d58beaa521d7592a0f02 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Thu, 3 Aug 2006 17:24:38 +0200 Subject: [PATCH 4/8] Make git-symbolic-ref a builtin Signed-off-by: Matthias Kestenholz Signed-off-by: Junio C Hamano --- Makefile | 6 +++--- symbolic-ref.c => builtin-symbolic-ref.c | 4 ++-- builtin.h | 1 + git.c | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) rename symbolic-ref.c => builtin-symbolic-ref.c (88%) diff --git a/Makefile b/Makefile index b108a8aa7a..db59e00ede 100644 --- a/Makefile +++ b/Makefile @@ -184,7 +184,6 @@ PROGRAMS = \ git-ssh-upload$X git-unpack-file$X \ git-update-server-info$X \ git-upload-pack$X git-verify-pack$X \ - git-symbolic-ref$X \ git-pack-redundant$X git-var$X \ git-describe$X git-merge-tree$X git-blame$X git-imap-send$X @@ -199,7 +198,7 @@ BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \ git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X \ git-fmt-merge-msg$X git-prune$X git-mv$X git-prune-packed$X \ git-repo-config$X git-name-rev$X git-pack-objects$X \ - git-unpack-objects$X + git-unpack-objects$X git-symbolic-ref$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -257,7 +256,8 @@ BUILTIN_OBJS = \ builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o \ builtin-update-ref.o builtin-fmt-merge-msg.o builtin-prune.o \ builtin-mv.o builtin-prune-packed.o builtin-repo-config.o \ - builtin-name-rev.o builtin-pack-objects.o builtin-unpack-objects.o + builtin-name-rev.o builtin-pack-objects.o builtin-unpack-objects.o \ + builtin-symbolic-ref.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/symbolic-ref.c b/builtin-symbolic-ref.c similarity index 88% rename from symbolic-ref.c rename to builtin-symbolic-ref.c index 193c87c174..b4ec6f28ed 100644 --- a/symbolic-ref.c +++ b/builtin-symbolic-ref.c @@ -1,3 +1,4 @@ +#include "builtin.h" #include "cache.h" static const char git_symbolic_ref_usage[] = @@ -17,9 +18,8 @@ static void check_symref(const char *HEAD) die("No such ref: %s", HEAD); } -int main(int argc, const char **argv) +int cmd_symbolic_ref(int argc, const char **argv, const char *prefix) { - setup_git_directory(); git_config(git_default_config); switch (argc) { case 2: diff --git a/builtin.h b/builtin.h index af73c3c19e..b767245c75 100644 --- a/builtin.h +++ b/builtin.h @@ -52,6 +52,7 @@ extern int cmd_repo_config(int argc, const char **argv, const char *prefix); extern int cmd_name_rev(int argc, const char **argv, const char *prefix); extern int cmd_pack_objects(int argc, const char **argv, const char *prefix); extern int cmd_unpack_objects(int argc, const char **argv, const char *prefix); +extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix); extern int cmd_write_tree(int argc, const char **argv, const char *prefix); extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix); diff --git a/git.c b/git.c index 7c3a7f8fd1..e40e85935c 100644 --- a/git.c +++ b/git.c @@ -268,6 +268,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "name-rev", cmd_name_rev, NEEDS_PREFIX }, { "pack-objects", cmd_pack_objects, NEEDS_PREFIX }, { "unpack-objects", cmd_unpack_objects, NEEDS_PREFIX }, + { "symbolic-ref", cmd_symbolic_ref, NEEDS_PREFIX }, }; int i; From e414156ab6e7869b29622ee3439e3c91361f5b0e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 4 Aug 2006 01:23:19 -0700 Subject: [PATCH 5/8] Make git-checkout-index a builtin Signed-off-by: Junio C Hamano --- Makefile | 6 +++-- checkout-index.c => builtin-checkout-index.c | 26 +++++++++----------- builtin.h | 1 + git.c | 1 + 4 files changed, 18 insertions(+), 16 deletions(-) rename checkout-index.c => builtin-checkout-index.c (92%) diff --git a/Makefile b/Makefile index db59e00ede..1a3605b123 100644 --- a/Makefile +++ b/Makefile @@ -173,7 +173,6 @@ SIMPLE_PROGRAMS = \ # ... and all the rest that could be moved out of bindir to gitexecdir PROGRAMS = \ - git-checkout-index$X \ git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \ git-hash-object$X git-index-pack$X git-local-fetch$X \ git-merge-base$X \ @@ -187,7 +186,9 @@ PROGRAMS = \ git-pack-redundant$X git-var$X \ git-describe$X git-merge-tree$X git-blame$X git-imap-send$X -BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \ +BUILT_INS = \ + git-checkout-index$X \ + git-log$X git-whatchanged$X git-show$X git-update-ref$X \ git-count-objects$X git-diff$X git-push$X git-mailsplit$X \ git-grep$X git-add$X git-rm$X git-rev-list$X git-stripspace$X \ git-check-ref-format$X git-rev-parse$X git-mailinfo$X \ @@ -245,6 +246,7 @@ LIB_OBJS = \ alloc.o merge-file.o path-list.o $(DIFF_OBJS) BUILTIN_OBJS = \ + builtin-checkout-index.o \ builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \ builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \ builtin-rm.o builtin-init-db.o builtin-rev-parse.o \ diff --git a/checkout-index.c b/builtin-checkout-index.c similarity index 92% rename from checkout-index.c rename to builtin-checkout-index.c index 61152f34b7..29ea6fdc62 100644 --- a/checkout-index.c +++ b/builtin-checkout-index.c @@ -42,8 +42,6 @@ #include "cache-tree.h" #define CHECKOUT_ALL 4 -static const char *prefix; -static int prefix_length; static int line_termination = '\n'; static int checkout_stage; /* default to checkout stage0 */ static int to_tempfile; @@ -51,7 +49,7 @@ static char topath[4][MAXPATHLEN+1]; static struct checkout state; -static void write_tempfile_record (const char *name) +static void write_tempfile_record(const char *name, int prefix_length) { int i; @@ -77,7 +75,7 @@ static void write_tempfile_record (const char *name) } } -static int checkout_file(const char *name) +static int checkout_file(const char *name, int prefix_length) { int namelen = strlen(name); int pos = cache_name_pos(name, namelen); @@ -106,7 +104,7 @@ static int checkout_file(const char *name) if (did_checkout) { if (to_tempfile) - write_tempfile_record(name); + write_tempfile_record(name, prefix_length); return errs > 0 ? -1 : 0; } @@ -124,7 +122,7 @@ static int checkout_file(const char *name) return -1; } -static int checkout_all(void) +static int checkout_all(const char *prefix, int prefix_length) { int i, errs = 0; struct cache_entry* last_ce = NULL; @@ -141,7 +139,7 @@ static int checkout_all(void) if (last_ce && to_tempfile) { if (ce_namelen(last_ce) != ce_namelen(ce) || memcmp(last_ce->name, ce->name, ce_namelen(ce))) - write_tempfile_record(last_ce->name); + write_tempfile_record(last_ce->name, prefix_length); } if (checkout_entry(ce, &state, to_tempfile ? topath[ce_stage(ce)] : NULL) < 0) @@ -149,7 +147,7 @@ static int checkout_all(void) last_ce = ce; } if (last_ce && to_tempfile) - write_tempfile_record(last_ce->name); + write_tempfile_record(last_ce->name, prefix_length); if (errs) /* we have already done our error reporting. * exit with the same code as die(). @@ -163,16 +161,16 @@ static const char checkout_cache_usage[] = static struct lock_file lock_file; -int main(int argc, char **argv) +int cmd_checkout_index(int argc, const char **argv, const char *prefix) { int i; int newfd = -1; int all = 0; int read_from_stdin = 0; + int prefix_length; - state.base_dir = ""; - prefix = setup_git_directory(); git_config(git_default_config); + state.base_dir = ""; prefix_length = prefix ? strlen(prefix) : 0; if (read_cache() < 0) { @@ -270,7 +268,7 @@ int main(int argc, char **argv) if (read_from_stdin) die("git-checkout-index: don't mix '--stdin' and explicit filenames"); p = prefix_path(prefix, prefix_length, arg); - checkout_file(p); + checkout_file(p, prefix_length); if (p < arg || p > arg + strlen(arg)) free((char*)p); } @@ -292,7 +290,7 @@ int main(int argc, char **argv) else path_name = buf.buf; p = prefix_path(prefix, prefix_length, path_name); - checkout_file(p); + checkout_file(p, prefix_length); if (p < path_name || p > path_name + strlen(path_name)) free((char *)p); if (path_name != buf.buf) @@ -301,7 +299,7 @@ int main(int argc, char **argv) } if (all) - checkout_all(); + checkout_all(prefix, prefix_length); if (0 <= newfd && (write_cache(newfd, active_cache, active_nr) || diff --git a/builtin.h b/builtin.h index b767245c75..3a24637b11 100644 --- a/builtin.h +++ b/builtin.h @@ -53,6 +53,7 @@ extern int cmd_name_rev(int argc, const char **argv, const char *prefix); extern int cmd_pack_objects(int argc, const char **argv, const char *prefix); extern int cmd_unpack_objects(int argc, const char **argv, const char *prefix); extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix); +extern int cmd_checkout_index(int argc, const char **argv, const char *prefix); extern int cmd_write_tree(int argc, const char **argv, const char *prefix); extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix); diff --git a/git.c b/git.c index e40e85935c..07b6d3e9dd 100644 --- a/git.c +++ b/git.c @@ -269,6 +269,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "pack-objects", cmd_pack_objects, NEEDS_PREFIX }, { "unpack-objects", cmd_unpack_objects, NEEDS_PREFIX }, { "symbolic-ref", cmd_symbolic_ref, NEEDS_PREFIX }, + { "checkout-index", cmd_checkout_index, NEEDS_PREFIX }, }; int i; From f754fa9c5480c4556ad268fb5014c4b96cc7b9dc Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 4 Aug 2006 01:51:04 -0700 Subject: [PATCH 6/8] builtins: Makefile clean-up This cleans up the build procedure for built-in commands by: - generating mostly redundant definition of BUILT_INS from BUILTIN_OBJS in the Makefile, - renaming a few files to make the above possible, and - sorting the built-in command table in git.c. It might be a good idea to binary search (or perfect hash) the built-in command table, but that can be done later when somebody feels like. Signed-off-by: Junio C Hamano --- Makefile | 74 +++++++++------ builtin-count.c => builtin-count-objects.c | 0 builtin.h | 102 ++++++++++----------- git.c | 70 +++++++------- builtin-help.c => help.c | 0 5 files changed, 128 insertions(+), 118 deletions(-) rename builtin-count.c => builtin-count-objects.c (100%) rename builtin-help.c => help.c (100%) diff --git a/Makefile b/Makefile index 1a3605b123..dc39f72f1e 100644 --- a/Makefile +++ b/Makefile @@ -187,19 +187,9 @@ PROGRAMS = \ git-describe$X git-merge-tree$X git-blame$X git-imap-send$X BUILT_INS = \ - git-checkout-index$X \ - git-log$X git-whatchanged$X git-show$X git-update-ref$X \ - git-count-objects$X git-diff$X git-push$X git-mailsplit$X \ - git-grep$X git-add$X git-rm$X git-rev-list$X git-stripspace$X \ - git-check-ref-format$X git-rev-parse$X git-mailinfo$X \ - git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \ - git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \ - git-read-tree$X git-commit-tree$X git-write-tree$X \ - git-apply$X git-show-branch$X git-diff-files$X git-update-index$X \ - git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X \ - git-fmt-merge-msg$X git-prune$X git-mv$X git-prune-packed$X \ - git-repo-config$X git-name-rev$X git-pack-objects$X \ - git-unpack-objects$X git-symbolic-ref$X + git-format-patch$X git-show$X git-whatchanged$X \ + git-get-tar-commit-id$X \ + $(patsubst builtin-%.o,git-%$X,$(BUILTIN_OBJS)) # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -228,7 +218,7 @@ LIB_H = \ blob.h cache.h commit.h csum-file.h delta.h \ diff.h object.h pack.h pkt-line.h quote.h refs.h \ run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \ - tree-walk.h log-tree.h dir.h path-list.h + tree-walk.h log-tree.h dir.h path-list.h builtin.h DIFF_OBJS = \ diff.o diff-lib.o diffcore-break.o diffcore-order.o \ @@ -243,23 +233,49 @@ LIB_OBJS = \ server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \ tag.o tree.o usage.o config.o environment.o ctype.o copy.o \ fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \ - alloc.o merge-file.o path-list.o $(DIFF_OBJS) + alloc.o merge-file.o path-list.o help.o $(DIFF_OBJS) BUILTIN_OBJS = \ + builtin-add.o \ + builtin-apply.o \ + builtin-cat-file.o \ builtin-checkout-index.o \ - builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \ - builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \ - builtin-rm.o builtin-init-db.o builtin-rev-parse.o \ - builtin-tar-tree.o builtin-upload-tar.o builtin-update-index.o \ - builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \ - builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \ - builtin-apply.o builtin-show-branch.o builtin-diff-files.o \ - builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \ - builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o \ - builtin-update-ref.o builtin-fmt-merge-msg.o builtin-prune.o \ - builtin-mv.o builtin-prune-packed.o builtin-repo-config.o \ - builtin-name-rev.o builtin-pack-objects.o builtin-unpack-objects.o \ - builtin-symbolic-ref.o + builtin-check-ref-format.o \ + builtin-commit-tree.o \ + builtin-count-objects.o \ + builtin-diff.o \ + builtin-diff-files.o \ + builtin-diff-index.o \ + builtin-diff-stages.o \ + builtin-diff-tree.o \ + builtin-fmt-merge-msg.o \ + builtin-grep.o \ + builtin-init-db.o \ + builtin-log.o \ + builtin-ls-files.o \ + builtin-ls-tree.o \ + builtin-mailinfo.o \ + builtin-mailsplit.o \ + builtin-mv.o \ + builtin-name-rev.o \ + builtin-pack-objects.o \ + builtin-prune.o \ + builtin-prune-packed.o \ + builtin-push.o \ + builtin-read-tree.o \ + builtin-repo-config.o \ + builtin-rev-list.o \ + builtin-rev-parse.o \ + builtin-rm.o \ + builtin-show-branch.o \ + builtin-stripspace.o \ + builtin-symbolic-ref.o \ + builtin-tar-tree.o \ + builtin-unpack-objects.o \ + builtin-update-index.o \ + builtin-update-ref.o \ + builtin-upload-tar.o \ + builtin-write-tree.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz @@ -540,7 +556,7 @@ git$X: git.c common-cmds.h $(BUILTIN_OBJS) $(GITLIBS) GIT-CFLAGS $(ALL_CFLAGS) -o $@ $(filter %.c,$^) \ $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS) -builtin-help.o: common-cmds.h +help.o: common-cmds.h $(BUILT_INS): git$X rm -f $@ && ln git$X $@ diff --git a/builtin-count.c b/builtin-count-objects.c similarity index 100% rename from builtin-count.c rename to builtin-count-objects.c diff --git a/builtin.h b/builtin.h index 3a24637b11..c0bdb051bd 100644 --- a/builtin.h +++ b/builtin.h @@ -8,62 +8,56 @@ extern const char git_version_string[]; extern const char git_usage_string[]; extern void help_unknown_cmd(const char *cmd); - -extern int cmd_help(int argc, const char **argv, const char *prefix); -extern int cmd_version(int argc, const char **argv, const char *prefix); - -extern int cmd_whatchanged(int argc, const char **argv, const char *prefix); -extern int cmd_show(int argc, const char **argv, const char *prefix); -extern int cmd_log(int argc, const char **argv, const char *prefix); -extern int cmd_diff(int argc, const char **argv, const char *prefix); -extern int cmd_format_patch(int argc, const char **argv, const char *prefix); -extern int cmd_count_objects(int argc, const char **argv, const char *prefix); - -extern int cmd_prune(int argc, const char **argv, const char *prefix); -extern int cmd_prune_packed(int argc, const char **argv, const char *prefix); - -extern int cmd_push(int argc, const char **argv, const char *prefix); -extern int cmd_grep(int argc, const char **argv, const char *prefix); -extern int cmd_rm(int argc, const char **argv, const char *prefix); -extern int cmd_add(int argc, const char **argv, const char *prefix); -extern int cmd_rev_list(int argc, const char **argv, const char *prefix); -extern int cmd_check_ref_format(int argc, const char **argv, const char *prefix); -extern int cmd_init_db(int argc, const char **argv, const char *prefix); -extern int cmd_tar_tree(int argc, const char **argv, const char *prefix); -extern int cmd_upload_tar(int argc, const char **argv, const char *prefix); -extern int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix); -extern int cmd_ls_files(int argc, const char **argv, const char *prefix); -extern int cmd_ls_tree(int argc, const char **argv, const char *prefix); -extern int cmd_read_tree(int argc, const char **argv, const char *prefix); -extern int cmd_commit_tree(int argc, const char **argv, const char *prefix); -extern int cmd_apply(int argc, const char **argv, const char *prefix); -extern int cmd_show_branch(int argc, const char **argv, const char *prefix); -extern int cmd_diff_files(int argc, const char **argv, const char *prefix); -extern int cmd_diff_index(int argc, const char **argv, const char *prefix); -extern int cmd_diff_stages(int argc, const char **argv, const char *prefix); -extern int cmd_diff_tree(int argc, const char **argv, const char *prefix); -extern int cmd_cat_file(int argc, const char **argv, const char *prefix); -extern int cmd_rev_parse(int argc, const char **argv, const char *prefix); -extern int cmd_update_index(int argc, const char **argv, const char *prefix); -extern int cmd_update_ref(int argc, const char **argv, const char *prefix); -extern int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix); -extern int cmd_mv(int argc, const char **argv, const char *prefix); -extern int cmd_repo_config(int argc, const char **argv, const char *prefix); -extern int cmd_name_rev(int argc, const char **argv, const char *prefix); -extern int cmd_pack_objects(int argc, const char **argv, const char *prefix); -extern int cmd_unpack_objects(int argc, const char **argv, const char *prefix); -extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix); -extern int cmd_checkout_index(int argc, const char **argv, const char *prefix); - -extern int cmd_write_tree(int argc, const char **argv, const char *prefix); +extern int mailinfo(FILE *in, FILE *out, int ks, const char *encoding, const char *msg, const char *patch); +extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip); +extern void stripspace(FILE *in, FILE *out); extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix); -extern int cmd_mailsplit(int argc, const char **argv, const char *prefix); -extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip); - +extern int cmd_add(int argc, const char **argv, const char *prefix); +extern int cmd_apply(int argc, const char **argv, const char *prefix); +extern int cmd_cat_file(int argc, const char **argv, const char *prefix); +extern int cmd_checkout_index(int argc, const char **argv, const char *prefix); +extern int cmd_check_ref_format(int argc, const char **argv, const char *prefix); +extern int cmd_commit_tree(int argc, const char **argv, const char *prefix); +extern int cmd_count_objects(int argc, const char **argv, const char *prefix); +extern int cmd_diff_files(int argc, const char **argv, const char *prefix); +extern int cmd_diff_index(int argc, const char **argv, const char *prefix); +extern int cmd_diff(int argc, const char **argv, const char *prefix); +extern int cmd_diff_stages(int argc, const char **argv, const char *prefix); +extern int cmd_diff_tree(int argc, const char **argv, const char *prefix); +extern int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix); +extern int cmd_format_patch(int argc, const char **argv, const char *prefix); +extern int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix); +extern int cmd_grep(int argc, const char **argv, const char *prefix); +extern int cmd_help(int argc, const char **argv, const char *prefix); +extern int cmd_init_db(int argc, const char **argv, const char *prefix); +extern int cmd_log(int argc, const char **argv, const char *prefix); +extern int cmd_ls_files(int argc, const char **argv, const char *prefix); +extern int cmd_ls_tree(int argc, const char **argv, const char *prefix); extern int cmd_mailinfo(int argc, const char **argv, const char *prefix); -extern int mailinfo(FILE *in, FILE *out, int ks, const char *encoding, const char *msg, const char *patch); - +extern int cmd_mailsplit(int argc, const char **argv, const char *prefix); +extern int cmd_mv(int argc, const char **argv, const char *prefix); +extern int cmd_name_rev(int argc, const char **argv, const char *prefix); +extern int cmd_pack_objects(int argc, const char **argv, const char *prefix); +extern int cmd_prune(int argc, const char **argv, const char *prefix); +extern int cmd_prune_packed(int argc, const char **argv, const char *prefix); +extern int cmd_push(int argc, const char **argv, const char *prefix); +extern int cmd_read_tree(int argc, const char **argv, const char *prefix); +extern int cmd_repo_config(int argc, const char **argv, const char *prefix); +extern int cmd_rev_list(int argc, const char **argv, const char *prefix); +extern int cmd_rev_parse(int argc, const char **argv, const char *prefix); +extern int cmd_rm(int argc, const char **argv, const char *prefix); +extern int cmd_show_branch(int argc, const char **argv, const char *prefix); +extern int cmd_show(int argc, const char **argv, const char *prefix); extern int cmd_stripspace(int argc, const char **argv, const char *prefix); -extern void stripspace(FILE *in, FILE *out); +extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix); +extern int cmd_tar_tree(int argc, const char **argv, const char *prefix); +extern int cmd_unpack_objects(int argc, const char **argv, const char *prefix); +extern int cmd_update_index(int argc, const char **argv, const char *prefix); +extern int cmd_update_ref(int argc, const char **argv, const char *prefix); +extern int cmd_upload_tar(int argc, const char **argv, const char *prefix); +extern int cmd_version(int argc, const char **argv, const char *prefix); +extern int cmd_whatchanged(int argc, const char **argv, const char *prefix); +extern int cmd_write_tree(int argc, const char **argv, const char *prefix); + #endif diff --git a/git.c b/git.c index 07b6d3e9dd..754db1a2ee 100644 --- a/git.c +++ b/git.c @@ -224,52 +224,52 @@ static void handle_internal_command(int argc, const char **argv, char **envp) int (*fn)(int, const char **, const char *); int option; } commands[] = { - { "version", cmd_version }, - { "help", cmd_help }, - { "log", cmd_log, NEEDS_PREFIX | USE_PAGER }, - { "whatchanged", cmd_whatchanged, NEEDS_PREFIX | USE_PAGER }, - { "show", cmd_show, NEEDS_PREFIX | USE_PAGER }, - { "push", cmd_push }, - { "format-patch", cmd_format_patch, NEEDS_PREFIX }, + { "add", cmd_add, NEEDS_PREFIX }, + { "apply", cmd_apply }, + { "cat-file", cmd_cat_file, NEEDS_PREFIX }, + { "checkout-index", cmd_checkout_index, NEEDS_PREFIX }, + { "check-ref-format", cmd_check_ref_format }, + { "commit-tree", cmd_commit_tree, NEEDS_PREFIX }, { "count-objects", cmd_count_objects }, { "diff", cmd_diff, NEEDS_PREFIX }, - { "grep", cmd_grep, NEEDS_PREFIX }, - { "rm", cmd_rm, NEEDS_PREFIX }, - { "add", cmd_add, NEEDS_PREFIX }, - { "rev-list", cmd_rev_list, NEEDS_PREFIX }, - { "init-db", cmd_init_db }, - { "get-tar-commit-id", cmd_get_tar_commit_id }, - { "upload-tar", cmd_upload_tar }, - { "check-ref-format", cmd_check_ref_format }, - { "ls-files", cmd_ls_files, NEEDS_PREFIX }, - { "ls-tree", cmd_ls_tree, NEEDS_PREFIX }, - { "tar-tree", cmd_tar_tree, NEEDS_PREFIX }, - { "read-tree", cmd_read_tree, NEEDS_PREFIX }, - { "commit-tree", cmd_commit_tree, NEEDS_PREFIX }, - { "apply", cmd_apply }, - { "show-branch", cmd_show_branch, NEEDS_PREFIX }, { "diff-files", cmd_diff_files, NEEDS_PREFIX }, { "diff-index", cmd_diff_index, NEEDS_PREFIX }, { "diff-stages", cmd_diff_stages, NEEDS_PREFIX }, { "diff-tree", cmd_diff_tree, NEEDS_PREFIX }, - { "cat-file", cmd_cat_file, NEEDS_PREFIX }, - { "rev-parse", cmd_rev_parse, NEEDS_PREFIX }, - { "write-tree", cmd_write_tree, NEEDS_PREFIX }, - { "mailsplit", cmd_mailsplit }, - { "mailinfo", cmd_mailinfo }, - { "stripspace", cmd_stripspace }, - { "update-index", cmd_update_index, NEEDS_PREFIX }, - { "update-ref", cmd_update_ref, NEEDS_PREFIX }, { "fmt-merge-msg", cmd_fmt_merge_msg, NEEDS_PREFIX }, - { "prune", cmd_prune, NEEDS_PREFIX }, + { "format-patch", cmd_format_patch, NEEDS_PREFIX }, + { "get-tar-commit-id", cmd_get_tar_commit_id }, + { "grep", cmd_grep, NEEDS_PREFIX }, + { "help", cmd_help }, + { "init-db", cmd_init_db }, + { "log", cmd_log, NEEDS_PREFIX | USE_PAGER }, + { "ls-files", cmd_ls_files, NEEDS_PREFIX }, + { "ls-tree", cmd_ls_tree, NEEDS_PREFIX }, + { "mailinfo", cmd_mailinfo }, + { "mailsplit", cmd_mailsplit }, { "mv", cmd_mv, NEEDS_PREFIX }, - { "prune-packed", cmd_prune_packed, NEEDS_PREFIX }, - { "repo-config", cmd_repo_config }, { "name-rev", cmd_name_rev, NEEDS_PREFIX }, { "pack-objects", cmd_pack_objects, NEEDS_PREFIX }, - { "unpack-objects", cmd_unpack_objects, NEEDS_PREFIX }, + { "prune", cmd_prune, NEEDS_PREFIX }, + { "prune-packed", cmd_prune_packed, NEEDS_PREFIX }, + { "push", cmd_push }, + { "read-tree", cmd_read_tree, NEEDS_PREFIX }, + { "repo-config", cmd_repo_config }, + { "rev-list", cmd_rev_list, NEEDS_PREFIX }, + { "rev-parse", cmd_rev_parse, NEEDS_PREFIX }, + { "rm", cmd_rm, NEEDS_PREFIX }, + { "show-branch", cmd_show_branch, NEEDS_PREFIX }, + { "show", cmd_show, NEEDS_PREFIX | USE_PAGER }, + { "stripspace", cmd_stripspace }, { "symbolic-ref", cmd_symbolic_ref, NEEDS_PREFIX }, - { "checkout-index", cmd_checkout_index, NEEDS_PREFIX }, + { "tar-tree", cmd_tar_tree, NEEDS_PREFIX }, + { "unpack-objects", cmd_unpack_objects, NEEDS_PREFIX }, + { "update-index", cmd_update_index, NEEDS_PREFIX }, + { "update-ref", cmd_update_ref, NEEDS_PREFIX }, + { "upload-tar", cmd_upload_tar }, + { "version", cmd_version }, + { "whatchanged", cmd_whatchanged, NEEDS_PREFIX | USE_PAGER }, + { "write-tree", cmd_write_tree, NEEDS_PREFIX }, }; int i; diff --git a/builtin-help.c b/help.c similarity index 100% rename from builtin-help.c rename to help.c From efffea033457eedb90ad63596687564f797f12de Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 4 Aug 2006 02:04:00 -0700 Subject: [PATCH 7/8] git.c: Rename NEEDS_PREFIX to RUN_SETUP As Matthias Kestenholz noted, the flag does not quite mean "needs prefix" -- it is more like "run setup_git_directory() before running this command", so rename it to avoid future confusion. While we are at it, rewrite the definition of options to make it obvious that we are talking about flag bits by using standard (1< --- git.c | 72 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/git.c b/git.c index 754db1a2ee..96e596b1a3 100644 --- a/git.c +++ b/git.c @@ -213,8 +213,8 @@ static int handle_alias(int *argcp, const char ***argv) const char git_version_string[] = GIT_VERSION; -#define NEEDS_PREFIX 1 -#define USE_PAGER 2 +#define RUN_SETUP (1<<0) +#define USE_PAGER (1<<1) static void handle_internal_command(int argc, const char **argv, char **envp) { @@ -224,52 +224,52 @@ static void handle_internal_command(int argc, const char **argv, char **envp) int (*fn)(int, const char **, const char *); int option; } commands[] = { - { "add", cmd_add, NEEDS_PREFIX }, + { "add", cmd_add, RUN_SETUP }, { "apply", cmd_apply }, - { "cat-file", cmd_cat_file, NEEDS_PREFIX }, - { "checkout-index", cmd_checkout_index, NEEDS_PREFIX }, + { "cat-file", cmd_cat_file, RUN_SETUP }, + { "checkout-index", cmd_checkout_index, RUN_SETUP }, { "check-ref-format", cmd_check_ref_format }, - { "commit-tree", cmd_commit_tree, NEEDS_PREFIX }, + { "commit-tree", cmd_commit_tree, RUN_SETUP }, { "count-objects", cmd_count_objects }, - { "diff", cmd_diff, NEEDS_PREFIX }, - { "diff-files", cmd_diff_files, NEEDS_PREFIX }, - { "diff-index", cmd_diff_index, NEEDS_PREFIX }, - { "diff-stages", cmd_diff_stages, NEEDS_PREFIX }, - { "diff-tree", cmd_diff_tree, NEEDS_PREFIX }, - { "fmt-merge-msg", cmd_fmt_merge_msg, NEEDS_PREFIX }, - { "format-patch", cmd_format_patch, NEEDS_PREFIX }, + { "diff", cmd_diff, RUN_SETUP }, + { "diff-files", cmd_diff_files, RUN_SETUP }, + { "diff-index", cmd_diff_index, RUN_SETUP }, + { "diff-stages", cmd_diff_stages, RUN_SETUP }, + { "diff-tree", cmd_diff_tree, RUN_SETUP }, + { "fmt-merge-msg", cmd_fmt_merge_msg, RUN_SETUP }, + { "format-patch", cmd_format_patch, RUN_SETUP }, { "get-tar-commit-id", cmd_get_tar_commit_id }, - { "grep", cmd_grep, NEEDS_PREFIX }, + { "grep", cmd_grep, RUN_SETUP }, { "help", cmd_help }, { "init-db", cmd_init_db }, - { "log", cmd_log, NEEDS_PREFIX | USE_PAGER }, - { "ls-files", cmd_ls_files, NEEDS_PREFIX }, - { "ls-tree", cmd_ls_tree, NEEDS_PREFIX }, + { "log", cmd_log, RUN_SETUP | USE_PAGER }, + { "ls-files", cmd_ls_files, RUN_SETUP }, + { "ls-tree", cmd_ls_tree, RUN_SETUP }, { "mailinfo", cmd_mailinfo }, { "mailsplit", cmd_mailsplit }, - { "mv", cmd_mv, NEEDS_PREFIX }, - { "name-rev", cmd_name_rev, NEEDS_PREFIX }, - { "pack-objects", cmd_pack_objects, NEEDS_PREFIX }, - { "prune", cmd_prune, NEEDS_PREFIX }, - { "prune-packed", cmd_prune_packed, NEEDS_PREFIX }, + { "mv", cmd_mv, RUN_SETUP }, + { "name-rev", cmd_name_rev, RUN_SETUP }, + { "pack-objects", cmd_pack_objects, RUN_SETUP }, + { "prune", cmd_prune, RUN_SETUP }, + { "prune-packed", cmd_prune_packed, RUN_SETUP }, { "push", cmd_push }, - { "read-tree", cmd_read_tree, NEEDS_PREFIX }, + { "read-tree", cmd_read_tree, RUN_SETUP }, { "repo-config", cmd_repo_config }, - { "rev-list", cmd_rev_list, NEEDS_PREFIX }, - { "rev-parse", cmd_rev_parse, NEEDS_PREFIX }, - { "rm", cmd_rm, NEEDS_PREFIX }, - { "show-branch", cmd_show_branch, NEEDS_PREFIX }, - { "show", cmd_show, NEEDS_PREFIX | USE_PAGER }, + { "rev-list", cmd_rev_list, RUN_SETUP }, + { "rev-parse", cmd_rev_parse, RUN_SETUP }, + { "rm", cmd_rm, RUN_SETUP }, + { "show-branch", cmd_show_branch, RUN_SETUP }, + { "show", cmd_show, RUN_SETUP | USE_PAGER }, { "stripspace", cmd_stripspace }, - { "symbolic-ref", cmd_symbolic_ref, NEEDS_PREFIX }, - { "tar-tree", cmd_tar_tree, NEEDS_PREFIX }, - { "unpack-objects", cmd_unpack_objects, NEEDS_PREFIX }, - { "update-index", cmd_update_index, NEEDS_PREFIX }, - { "update-ref", cmd_update_ref, NEEDS_PREFIX }, + { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP }, + { "tar-tree", cmd_tar_tree, RUN_SETUP }, + { "unpack-objects", cmd_unpack_objects, RUN_SETUP }, + { "update-index", cmd_update_index, RUN_SETUP }, + { "update-ref", cmd_update_ref, RUN_SETUP }, { "upload-tar", cmd_upload_tar }, { "version", cmd_version }, - { "whatchanged", cmd_whatchanged, NEEDS_PREFIX | USE_PAGER }, - { "write-tree", cmd_write_tree, NEEDS_PREFIX }, + { "whatchanged", cmd_whatchanged, RUN_SETUP | USE_PAGER }, + { "write-tree", cmd_write_tree, RUN_SETUP }, }; int i; @@ -286,7 +286,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) continue; prefix = NULL; - if (p->option & NEEDS_PREFIX) + if (p->option & RUN_SETUP) prefix = setup_git_directory(); if (p->option & USE_PAGER) setup_pager(); From 2e3ed670eb09feffe847af55db38da3dcecc2a88 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Thu, 10 Aug 2006 17:02:38 +0200 Subject: [PATCH 8/8] git-verify-pack: make builtin Convert git-verify-pack to a builtin command. Also rename ac to argc and av to argv for consistancy. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- Makefile | 1 + verify-pack.c => builtin-verify-pack.c | 15 ++++++++------- builtin.h | 1 + git.c | 1 + 4 files changed, 11 insertions(+), 7 deletions(-) rename verify-pack.c => builtin-verify-pack.c (83%) diff --git a/Makefile b/Makefile index 733fa660d9..a3ba585cee 100644 --- a/Makefile +++ b/Makefile @@ -275,6 +275,7 @@ BUILTIN_OBJS = \ builtin-update-index.o \ builtin-update-ref.o \ builtin-upload-tar.o \ + builtin-verify-pack.o \ builtin-write-tree.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) diff --git a/verify-pack.c b/builtin-verify-pack.c similarity index 83% rename from verify-pack.c rename to builtin-verify-pack.c index f440a39678..d700761e15 100644 --- a/verify-pack.c +++ b/builtin-verify-pack.c @@ -1,3 +1,4 @@ +#include "builtin.h" #include "cache.h" #include "pack.h" @@ -47,28 +48,28 @@ static int verify_one_pack(const char *path, int verbose) static const char verify_pack_usage[] = "git-verify-pack [-v] ..."; -int main(int ac, char **av) +int cmd_verify_pack(int argc, const char **argv, const char *prefix) { int err = 0; int verbose = 0; int no_more_options = 0; int nothing_done = 1; - while (1 < ac) { - if (!no_more_options && av[1][0] == '-') { - if (!strcmp("-v", av[1])) + while (1 < argc) { + if (!no_more_options && argv[1][0] == '-') { + if (!strcmp("-v", argv[1])) verbose = 1; - else if (!strcmp("--", av[1])) + else if (!strcmp("--", argv[1])) no_more_options = 1; else usage(verify_pack_usage); } else { - if (verify_one_pack(av[1], verbose)) + if (verify_one_pack(argv[1], verbose)) err = 1; nothing_done = 0; } - ac--; av++; + argc--; argv++; } if (nothing_done) diff --git a/builtin.h b/builtin.h index c0bdb051bd..ade58c4a1f 100644 --- a/builtin.h +++ b/builtin.h @@ -59,5 +59,6 @@ extern int cmd_upload_tar(int argc, const char **argv, const char *prefix); extern int cmd_version(int argc, const char **argv, const char *prefix); extern int cmd_whatchanged(int argc, const char **argv, const char *prefix); extern int cmd_write_tree(int argc, const char **argv, const char *prefix); +extern int cmd_verify_pack(int argc, const char **argv, const char *prefix); #endif diff --git a/git.c b/git.c index db0f86790d..5da7787d86 100644 --- a/git.c +++ b/git.c @@ -270,6 +270,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "version", cmd_version }, { "whatchanged", cmd_whatchanged, RUN_SETUP | USE_PAGER }, { "write-tree", cmd_write_tree, RUN_SETUP }, + { "verify-pack", cmd_verify_pack }, }; int i;