[PATCH] Support commit_format in diff-tree
[gitweb.git] / diff-tree.c
index c3a5617c578d3a863b9759967e9583c0c5c944ea..3c8838582fbe516ef028dc5564d0e39287f0f4ea 100644 (file)
@@ -19,6 +19,7 @@ static int diff_break_opt = -1;
 static const char *orderfile = NULL;
 static const char *header = NULL;
 static const char *header_prefix = "";
+static enum cmit_fmt commit_format = CMIT_FMT_RAW;
 
 // What paths are we interested in?
 static int nr_paths = 0;
@@ -321,7 +322,7 @@ static char *generate_header(const char *commit, const char *parent, const char
 
        offset = sprintf(this_header, "%s%s (from %s)\n", header_prefix, commit, parent);
        if (verbose_header) {
-               offset += pretty_print_commit(msg, len, this_header + offset, sizeof(this_header) - offset);
+               offset += pretty_print_commit(commit_format, msg, len, this_header + offset, sizeof(this_header) - offset);
                this_header[offset++] = '\n';
                this_header[offset++] = 0;
        }
@@ -397,7 +398,20 @@ static int diff_tree_stdin(char *line)
 }
 
 static char *diff_tree_usage =
-"git-diff-tree [-p] [-r] [-z] [--stdin] [-M] [-C] [-R] [-S<string>] [-O<orderfile>] [-m] [-s] [-v] [-t] <tree-ish> <tree-ish>";
+"git-diff-tree [-p] [-r] [-z] [--stdin] [-M] [-C] [-R] [-S<string>] [-O<orderfile>] [-m] [-s] [-v] [--pretty] [-t] <tree-ish> <tree-ish>";
+
+static enum cmit_fmt get_commit_format(const char *arg)
+{
+       if (!*arg)
+               return CMIT_FMT_DEFAULT;
+       if (!strcmp(arg, "=raw"))
+               return CMIT_FMT_RAW;
+       if (!strcmp(arg, "=medium"))
+               return CMIT_FMT_MEDIUM;
+       if (!strcmp(arg, "=short"))
+               return CMIT_FMT_SHORT;
+       usage(diff_tree_usage);
+}
 
 int main(int argc, const char **argv)
 {
@@ -459,16 +473,19 @@ int main(int argc, const char **argv)
                }
                if (!strncmp(arg, "-M", 2)) {
                        detect_rename = DIFF_DETECT_RENAME;
-                       diff_score_opt = diff_scoreopt_parse(arg);
+                       if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1)
+                               usage(diff_tree_usage);
                        continue;
                }
                if (!strncmp(arg, "-C", 2)) {
                        detect_rename = DIFF_DETECT_COPY;
-                       diff_score_opt = diff_scoreopt_parse(arg);
+                       if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1)
+                               usage(diff_tree_usage);
                        continue;
                }
                if (!strncmp(arg, "-B", 2)) {
-                       diff_break_opt = diff_scoreopt_parse(arg);
+                       if ((diff_break_opt = diff_scoreopt_parse(arg)) == -1)
+                               usage(diff_tree_usage);
                        continue;
                }
                if (!strcmp(arg, "-z")) {
@@ -488,6 +505,11 @@ int main(int argc, const char **argv)
                        header_prefix = "diff-tree ";
                        continue;
                }
+               if (!strncmp(arg, "--pretty", 8)) {
+                       verbose_header = 1;
+                       commit_format = get_commit_format(arg+8);
+                       continue;
+               }
                if (!strcmp(arg, "--stdin")) {
                        read_stdin = 1;
                        continue;