Merge branch 'jc/diff-no-no-index'
authorJunio C Hamano <gitster@pobox.com>
Tue, 27 May 2008 05:38:19 +0000 (22:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 May 2008 05:38:19 +0000 (22:38 -0700)
* 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"

1  2 
Makefile
builtin-diff-files.c
builtin-diff.c
diff.h
git.c
diff --combined Makefile
index 4e36487c3c4d671a90ce255561afb00f1e02c8fd,ad09e6c8ba576bb5408d480199d3ea092f6ff564..cce5a6e1bf9ad8f5ebf8046a5053588d18e90bc6
+++ 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 907392a1f3d9b548389708c8c56c20a05bb5a69c,3aa031f24f83f6f1877d1aaf24bd834183713563..384d871263383e89c6f8f52b16e9e7e147426d1d
  #include "builtin.h"
  
  static const char diff_files_usage[] =
- "git-diff-files [-q] [-0/-1/2/3 |-c|--cc|--no-index] [<common diff options>] [<path>...]"
+ "git-diff-files [-q] [-0/-1/2/3 |-c|--cc] [<common diff options>] [<path>...]"
  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 583291a9c0e52ed8c8e678606be7ec02b603db60,8b3b51eae0f928d217c7c91f294f1498d05ad1cf..4c289e798a25ee3893a483abd8465740999dcbef
@@@ -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;
         * 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);
  
        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) {
        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 b0b700a5f6ec71174c40285f376fc1b2bfb34e3a,e019730638bb84da5696db656e3749f1b9521b56..5dc0cb595b64868ca8b8e26e5311d2df102c89e0
--- 1/diff.h
--- 2/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 2c9004f02e33180dcdbbc5b2e90266599ad41cc1,4b79380b7266d5bac0545c85178ca44d4451648e..272bf03da3b3aee7dbdb088ddc1042c18567492a
--- 1/git.c
--- 2/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 },
                { "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 },