Merge branch 'jc/maint-combined-diff-work-tree'
authorJunio C Hamano <gitster@pobox.com>
Thu, 18 Aug 2011 00:25:59 +0000 (17:25 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Aug 2011 00:25:59 +0000 (17:25 -0700)
* jc/maint-combined-diff-work-tree:
  diff -c/--cc: do not mistake "resolved as deletion" as "use working tree"

Conflicts:
combine-diff.c

1  2 
combine-diff.c

diff --cc combine-diff.c
index be67cfcd45469497f81e0c36ed87a11fd409daee,360b816b3ef7e08cbeef9c9823e212354f8847eb..b11eb7102c53d3418aa875ee899e61e01de87bca
@@@ -691,84 -681,9 +691,85 @@@ static void dump_quoted_path(const cha
        puts(buf.buf);
  }
  
 +static void show_combined_header(struct combine_diff_path *elem,
 +                               int num_parent,
 +                               int dense,
 +                               struct rev_info *rev,
 +                               int mode_differs,
 +                               int show_file_header)
 +{
 +      struct diff_options *opt = &rev->diffopt;
 +      int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? 40 : DEFAULT_ABBREV;
 +      const char *a_prefix = opt->a_prefix ? opt->a_prefix : "a/";
 +      const char *b_prefix = opt->b_prefix ? opt->b_prefix : "b/";
 +      int use_color = DIFF_OPT_TST(opt, COLOR_DIFF);
 +      const char *c_meta = diff_get_color(use_color, DIFF_METAINFO);
 +      const char *c_reset = diff_get_color(use_color, DIFF_RESET);
 +      const char *abb;
 +      int added = 0;
 +      int deleted = 0;
 +      int i;
 +
 +      if (rev->loginfo && !rev->no_commit_id)
 +              show_log(rev);
 +
 +      dump_quoted_path(dense ? "diff --cc " : "diff --combined ",
 +                       "", elem->path, c_meta, c_reset);
 +      printf("%sindex ", c_meta);
 +      for (i = 0; i < num_parent; i++) {
 +              abb = find_unique_abbrev(elem->parent[i].sha1,
 +                                       abbrev);
 +              printf("%s%s", i ? "," : "", abb);
 +      }
 +      abb = find_unique_abbrev(elem->sha1, abbrev);
 +      printf("..%s%s\n", abb, c_reset);
 +
 +      if (mode_differs) {
 +              deleted = !elem->mode;
 +
 +              /* We say it was added if nobody had it */
 +              added = !deleted;
 +              for (i = 0; added && i < num_parent; i++)
 +                      if (elem->parent[i].status !=
 +                          DIFF_STATUS_ADDED)
 +                              added = 0;
 +              if (added)
 +                      printf("%snew file mode %06o",
 +                             c_meta, elem->mode);
 +              else {
 +                      if (deleted)
 +                              printf("%sdeleted file ", c_meta);
 +                      printf("mode ");
 +                      for (i = 0; i < num_parent; i++) {
 +                              printf("%s%06o", i ? "," : "",
 +                                     elem->parent[i].mode);
 +                      }
 +                      if (elem->mode)
 +                              printf("..%06o", elem->mode);
 +              }
 +              printf("%s\n", c_reset);
 +      }
 +
 +      if (!show_file_header)
 +              return;
 +
 +      if (added)
 +              dump_quoted_path("--- ", "", "/dev/null",
 +                               c_meta, c_reset);
 +      else
 +              dump_quoted_path("--- ", a_prefix, elem->path,
 +                               c_meta, c_reset);
 +      if (deleted)
 +              dump_quoted_path("+++ ", "", "/dev/null",
 +                               c_meta, c_reset);
 +      else
 +              dump_quoted_path("+++ ", b_prefix, elem->path,
 +                               c_meta, c_reset);
 +}
 +
  static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
-                           int dense, struct rev_info *rev)
+                           int dense, int working_tree_file,
+                           struct rev_info *rev)
  {
        struct diff_options *opt = &rev->diffopt;
        unsigned long result_size, cnt, lno;
        struct sline *sline; /* survived lines */
        int mode_differs = 0;
        int i, show_hunks;
-       int working_tree_file = is_null_sha1(elem->sha1);
 -      int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? 40 : DEFAULT_ABBREV;
 -      const char *a_prefix, *b_prefix;
        mmfile_t result_file;
 +      struct userdiff_driver *userdiff;
 +      struct userdiff_driver *textconv = NULL;
 +      int is_binary;
  
        context = opt->context;
 -      a_prefix = opt->a_prefix ? opt->a_prefix : "a/";
 -      b_prefix = opt->b_prefix ? opt->b_prefix : "b/";
 +      userdiff = userdiff_find_by_path(elem->path);
 +      if (!userdiff)
 +              userdiff = userdiff_find_by_name("default");
 +      if (DIFF_OPT_TST(opt, ALLOW_TEXTCONV))
 +              textconv = userdiff_get_textconv(userdiff);
  
        /* Read the result of merge first */
        if (!working_tree_file)