find_unique_abbrev() simplification.
[git.git] / combine-diff.c
index 15f369e..8ba6949 100644 (file)
@@ -618,8 +618,8 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
        sline->p_lno[i] = sline->p_lno[j];
 }
 
-int show_combined_diff(struct combine_diff_path *elem, int num_parent,
-                      int dense, const char *header)
+static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
+                          int dense, const char *header)
 {
        unsigned long size, cnt, lno;
        char *result, *cp, *ep;
@@ -716,10 +716,7 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
 
        if (show_hunks || mode_differs) {
                const char *abb;
-               char null_abb[DEFAULT_ABBREV + 1];
 
-               memset(null_abb, '0', DEFAULT_ABBREV);
-               null_abb[DEFAULT_ABBREV] = 0;
                if (header) {
                        shown_header++;
                        puts(header);
@@ -734,17 +731,11 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
                for (i = 0; i < num_parent; i++) {
                        if (elem->parent[i].mode != elem->mode)
                                mode_differs = 1;
-                       if (memcmp(elem->parent[i].sha1, null_sha1, 20))
-                               abb = find_unique_abbrev(elem->parent[i].sha1,
-                                                        DEFAULT_ABBREV);
-                       else
-                               abb = null_abb;
+                       abb = find_unique_abbrev(elem->parent[i].sha1,
+                                                DEFAULT_ABBREV);
                        printf("%s%s", i ? "," : "", abb);
                }
-               if (memcmp(elem->sha1, null_sha1, 20))
-                       abb = find_unique_abbrev(elem->sha1, DEFAULT_ABBREV);
-               else
-                       abb = null_abb;
+               abb = find_unique_abbrev(elem->sha1, DEFAULT_ABBREV);
                printf("..%s\n", abb);
 
                if (mode_differs) {
@@ -791,32 +782,69 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
 
        if (header)
                puts(header);
-       offset = strlen(COLONS) - num_parent;
-       if (offset < 0)
-               offset = 0;
-       prefix = COLONS + offset;
 
-       /* Show the modes */
        for (i = 0; i < num_parent; i++) {
-               int mode = p->parent[i].mode;
-               if (mode)
+               if (p->parent[i].mode)
                        mod_type = 'M';
-               printf("%s%06o", prefix, mode);
-               prefix = " ";
        }
-       printf("%s%06o", prefix, p->mode);
        if (!p->mode)
                mod_type = 'D';
 
-       /* Show sha1's */
-       for (i = 0; i < num_parent; i++) {
-               printf("%s%s", prefix, diff_unique_abbrev(p->parent[i].sha1, opt->abbrev));
-               prefix = " ";
+       if (opt->output_format == DIFF_FORMAT_RAW) {
+               offset = strlen(COLONS) - num_parent;
+               if (offset < 0)
+                       offset = 0;
+               prefix = COLONS + offset;
+
+               /* Show the modes */
+               for (i = 0; i < num_parent; i++) {
+                       printf("%s%06o", prefix, p->parent[i].mode);
+                       prefix = " ";
+               }
+               printf("%s%06o", prefix, p->mode);
+
+               /* Show sha1's */
+               for (i = 0; i < num_parent; i++)
+                       printf(" %s", diff_unique_abbrev(p->parent[i].sha1,
+                                                        opt->abbrev));
+               printf(" %s ", diff_unique_abbrev(p->sha1, opt->abbrev));
+       }
+
+       if (opt->output_format == DIFF_FORMAT_RAW ||
+           opt->output_format == DIFF_FORMAT_NAME_STATUS)
+               printf("%c%c", mod_type, inter_name_termination);
+
+       if (line_termination) {
+               if (quote_c_style(p->path, NULL, NULL, 0))
+                       quote_c_style(p->path, NULL, stdout, 0);
+               else
+                       printf("%s", p->path);
+               putchar(line_termination);
        }
-       printf("%s%s", prefix, diff_unique_abbrev(p->sha1, opt->abbrev));
+       else {
+               printf("%s%c", p->path, line_termination);
+       }
+}
+
+int show_combined_diff(struct combine_diff_path *p,
+                      int num_parent,
+                      int dense,
+                      const char *header,
+                      struct diff_options *opt)
+{
+       if (!p->len)
+               return 0;
+       switch (opt->output_format) {
+       case DIFF_FORMAT_RAW:
+       case DIFF_FORMAT_NAME_STATUS:
+       case DIFF_FORMAT_NAME:
+               show_raw_diff(p, num_parent, header, opt);
+               return 1;
 
-       /* Modification type, terminations, filename */
-       printf(" %c%c%s%c", mod_type, inter_name_termination, p->path, line_termination);
+       default:
+       case DIFF_FORMAT_PATCH:
+               return show_patch_diff(p, num_parent, dense, header);
+       }
 }
 
 const char *diff_tree_combined_merge(const unsigned char *sha1,
@@ -829,7 +857,7 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
        struct combine_diff_path *p, *paths = NULL;
        int num_parent, i, num_paths;
 
-       diff_setup(&diffopts);
+       diffopts = *opt;
        diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
        diffopts.recursive = 1;
 
@@ -846,6 +874,7 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
                struct commit *parent = parents->item;
                diff_tree_sha1(parent->object.sha1, commit->object.sha1, "",
                               &diffopts);
+               diffcore_std(&diffopts);
                paths = intersect_paths(paths, i, num_parent);
                diff_flush(&diffopts);
        }
@@ -857,14 +886,8 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
        }
        if (num_paths) {
                for (p = paths; p; p = p->next) {
-                       if (!p->len)
-                               continue;
-                       if (opt->output_format == DIFF_FORMAT_RAW) {
-                               show_raw_diff(p, num_parent, header, opt);
-                               header = NULL;
-                               continue;
-                       }
-                       if (show_combined_diff(p, num_parent, dense, header))
+                       if (show_combined_diff(p, num_parent, dense,
+                                              header, opt))
                                header = NULL;
                }
        }