From: Junio C Hamano Date: Tue, 27 May 2008 05:38:19 +0000 (-0700) Subject: Merge branch 'jc/diff-no-no-index' X-Git-Tag: v1.5.6-rc1~41 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/3beb56bde63d1a10abc02ffe76c1f98d59ec0874?ds=inline;hp=-c Merge branch 'jc/diff-no-no-index' * jc/diff-no-no-index: git diff --no-index: default to page like other diff frontends git-diff: allow --no-index semantics a bit more "git diff": do not ignore index without --no-index diff-files: do not play --no-index games tests: do not use implicit "git diff --no-index" --- 3beb56bde63d1a10abc02ffe76c1f98d59ec0874 diff --combined Makefile index 4e36487c3c,ad09e6c8ba..cce5a6e1bf --- a/Makefile +++ b/Makefile @@@ -235,6 -235,7 +235,6 @@@ BASIC_LDFLAGS SCRIPT_SH += git-am.sh SCRIPT_SH += git-bisect.sh -SCRIPT_SH += git-clone.sh SCRIPT_SH += git-filter-branch.sh SCRIPT_SH += git-lost-found.sh SCRIPT_SH += git-merge-octopus.sh @@@ -375,7 -376,6 +375,7 @@@ LIB_H += tree. LIB_H += tree-walk.h LIB_H += unpack-trees.h LIB_H += utf8.h +LIB_H += wt-status.h LIB_OBJS += alias.o LIB_OBJS += alloc.o @@@ -405,6 -405,7 +405,7 @@@ LIB_OBJS += diffcore-order. LIB_OBJS += diffcore-pickaxe.o LIB_OBJS += diffcore-rename.o LIB_OBJS += diff-delta.o + LIB_OBJS += diff-no-index.o LIB_OBJS += diff-lib.o LIB_OBJS += diff.o LIB_OBJS += dir.o @@@ -484,7 -485,6 +485,7 @@@ BUILTIN_OBJS += builtin-check-ref-forma BUILTIN_OBJS += builtin-checkout-index.o BUILTIN_OBJS += builtin-checkout.o BUILTIN_OBJS += builtin-clean.o +BUILTIN_OBJS += builtin-clone.o BUILTIN_OBJS += builtin-commit-tree.o BUILTIN_OBJS += builtin-commit.o BUILTIN_OBJS += builtin-config.o diff --combined builtin-diff-files.c index 907392a1f3,3aa031f24f..384d871263 --- a/builtin-diff-files.c +++ b/builtin-diff-files.c @@@ -10,26 -10,54 +10,54 @@@ #include "builtin.h" static const char diff_files_usage[] = - "git-diff-files [-q] [-0/-1/2/3 |-c|--cc|--no-index] [] [...]" + "git-diff-files [-q] [-0/-1/2/3 |-c|--cc] [] [...]" COMMON_DIFF_OPTIONS_HELP; int cmd_diff_files(int argc, const char **argv, const char *prefix) { struct rev_info rev; - int nongit; int result; + unsigned options = 0; - prefix = setup_git_directory_gently(&nongit); init_revisions(&rev, prefix); - git_config(git_diff_basic_config); /* no "diff" UI options */ + git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ rev.abbrev = 0; - if (!setup_diff_no_index(&rev, argc, argv, nongit, prefix)) - argc = 0; - else - argc = setup_revisions(argc, argv, &rev, NULL); + argc = setup_revisions(argc, argv, &rev, NULL); + while (1 < argc && argv[1][0] == '-') { + if (!strcmp(argv[1], "--base")) + rev.max_count = 1; + else if (!strcmp(argv[1], "--ours")) + rev.max_count = 2; + else if (!strcmp(argv[1], "--theirs")) + rev.max_count = 3; + else if (!strcmp(argv[1], "-q")) + options |= DIFF_SILENT_ON_REMOVED; + else + usage(diff_files_usage); + argv++; argc--; + } if (!rev.diffopt.output_format) rev.diffopt.output_format = DIFF_FORMAT_RAW; - result = run_diff_files_cmd(&rev, argc, argv); + + /* + * Make sure there are NO revision (i.e. pending object) parameter, + * rev.max_count is reasonable (0 <= n <= 3), and + * there is no other revision filtering parameters. + */ + if (rev.pending.nr || + rev.min_age != -1 || rev.max_age != -1 || + 3 < rev.max_count) + usage(diff_files_usage); + + if (rev.max_count == -1 && + (rev.diffopt.output_format & DIFF_FORMAT_PATCH)) + rev.combine_merges = rev.dense_combined_merges = 1; + + if (read_cache() < 0) { + perror("read_cache"); + return -1; + } + result = run_diff_files(&rev, options); return diff_result_code(&rev.diffopt, result); } diff --combined builtin-diff.c index 583291a9c0,8b3b51eae0..4c289e798a --- a/builtin-diff.c +++ b/builtin-diff.c @@@ -202,6 -202,37 +202,37 @@@ static void refresh_index_quietly(void rollback_lock_file(lock_file); } + static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv) + { + int result; + unsigned int options = 0; + + while (1 < argc && argv[1][0] == '-') { + if (!strcmp(argv[1], "--base")) + revs->max_count = 1; + else if (!strcmp(argv[1], "--ours")) + revs->max_count = 2; + else if (!strcmp(argv[1], "--theirs")) + revs->max_count = 3; + else if (!strcmp(argv[1], "-q")) + options |= DIFF_SILENT_ON_REMOVED; + else + return error("invalid option: %s", argv[1]); + argv++; argc--; + } + + if (revs->max_count == -1 && + (revs->diffopt.output_format & DIFF_FORMAT_PATCH)) + revs->combine_merges = revs->dense_combined_merges = 1; + + if (read_cache() < 0) { + perror("read_cache"); + return -1; + } + result = run_diff_files(revs, options); + return diff_result_code(&revs->diffopt, result); + } + int cmd_diff(int argc, const char **argv, const char *prefix) { int i; @@@ -230,31 -261,34 +261,34 @@@ * N=2, M=0: * tree vs tree (diff-tree) * + * N=0, M=0, P=2: + * compare two filesystem entities (aka --no-index). + * * Other cases are errors. */ prefix = setup_git_directory_gently(&nongit); - git_config(git_diff_ui_config); + git_config(git_diff_ui_config, NULL); if (diff_use_color_default == -1) diff_use_color_default = git_use_color_default; init_revisions(&rev, prefix); + + /* If this is a no-index diff, just run it and exit there. */ + diff_no_index(&rev, argc, argv, nongit, prefix); + + /* Otherwise, we are doing the usual "git" diff */ rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index; - if (!setup_diff_no_index(&rev, argc, argv, nongit, prefix)) - argc = 0; - else - argc = setup_revisions(argc, argv, &rev, NULL); + if (nongit) + die("Not a git repository"); + argc = setup_revisions(argc, argv, &rev, NULL); if (!rev.diffopt.output_format) { rev.diffopt.output_format = DIFF_FORMAT_PATCH; if (diff_setup_done(&rev.diffopt) < 0) die("diff_setup_done failed"); } - if (rev.diffopt.prefix && nongit) { - rev.diffopt.prefix = NULL; - rev.diffopt.prefix_length = 0; - } DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL); DIFF_OPT_SET(&rev.diffopt, RECURSIVE); @@@ -265,7 -299,8 +299,8 @@@ if (!DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS)) setup_pager(); - /* Do we have --cached and not have a pending object, then + /* + * Do we have --cached and not have a pending object, then * default to HEAD by hand. Eek. */ if (!rev.pending.nr) { @@@ -333,7 -368,7 +368,7 @@@ if (!ents) { switch (blobs) { case 0: - result = run_diff_files_cmd(&rev, argc, argv); + result = builtin_diff_files(&rev, argc, argv); break; case 1: if (paths != 1) diff --combined diff.h index b0b700a5f6,e019730638..5dc0cb595b --- a/diff.h +++ b/diff.h @@@ -63,7 -63,6 +63,7 @@@ typedef void (*diff_format_fn_t)(struc #define DIFF_OPT_REVERSE_DIFF (1 << 15) #define DIFF_OPT_CHECK_FAILED (1 << 16) #define DIFF_OPT_RELATIVE_NAME (1 << 17) +#define DIFF_OPT_IGNORE_SUBMODULES (1 << 18) #define DIFF_OPT_TST(opts, flag) ((opts)->flags & DIFF_OPT_##flag) #define DIFF_OPT_SET(opts, flag) ((opts)->flags |= DIFF_OPT_##flag) #define DIFF_OPT_CLR(opts, flag) ((opts)->flags &= ~DIFF_OPT_##flag) @@@ -182,8 -181,8 +182,8 @@@ extern void diff_unmerge(struct diff_op #define DIFF_SETUP_USE_CACHE 2 #define DIFF_SETUP_USE_SIZE_CACHE 4 -extern int git_diff_basic_config(const char *var, const char *value); -extern int git_diff_ui_config(const char *var, const char *value); +extern int git_diff_basic_config(const char *var, const char *value, void *cb); +extern int git_diff_ui_config(const char *var, const char *value, void *cb); extern int diff_use_color_default; extern void diff_setup(struct diff_options *); extern int diff_opt_parse(struct diff_options *, const char **, int); @@@ -251,10 -250,6 +251,6 @@@ extern const char *diff_unique_abbrev(c /* report racily-clean paths as modified */ #define DIFF_RACY_IS_MODIFIED 02 extern int run_diff_files(struct rev_info *revs, unsigned int option); - extern int setup_diff_no_index(struct rev_info *revs, - int argc, const char ** argv, int nongit, const char *prefix); - extern int run_diff_files_cmd(struct rev_info *revs, int argc, const char **argv); - extern int run_diff_index(struct rev_info *revs, int cached); extern int do_diff_cache(const unsigned char *, struct diff_options *); @@@ -262,4 -257,6 +258,6 @@@ extern int diff_flush_patch_id(struct d extern int diff_result_code(struct diff_options *, int); + extern void diff_no_index(struct rev_info *, int, const char **, int, const char *); + #endif /* DIFF_H */ diff --combined git.c index 2c9004f02e,4b79380b72..272bf03da3 --- a/git.c +++ b/git.c @@@ -286,7 -286,6 +286,7 @@@ static void handle_internal_command(in { "check-attr", cmd_check_attr, RUN_SETUP | NEED_WORK_TREE }, { "cherry", cmd_cherry, RUN_SETUP }, { "cherry-pick", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE }, + { "clone", cmd_clone }, { "clean", cmd_clean, RUN_SETUP | NEED_WORK_TREE }, { "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE }, { "commit-tree", cmd_commit_tree, RUN_SETUP }, @@@ -294,7 -293,7 +294,7 @@@ { "count-objects", cmd_count_objects, RUN_SETUP }, { "describe", cmd_describe, RUN_SETUP }, { "diff", cmd_diff }, - { "diff-files", cmd_diff_files }, + { "diff-files", cmd_diff_files, RUN_SETUP }, { "diff-index", cmd_diff_index, RUN_SETUP }, { "diff-tree", cmd_diff_tree, RUN_SETUP }, { "fast-export", cmd_fast_export, RUN_SETUP },