user-manual: miscellaneous editing
[gitweb.git] / log-tree.c
index fbe139920ab0eada09dc921c152236d9676da44c..dbd06490f97c735171974f068b48dbdbbb992723 100644 (file)
@@ -2,6 +2,7 @@
 #include "diff.h"
 #include "commit.h"
 #include "log-tree.h"
+#include "reflog-walk.h"
 
 static void show_parents(struct commit *commit, int abbrev)
 {
@@ -101,6 +102,16 @@ static int append_signoff(char *buf, int buf_sz, int at, const char *signoff)
        return at;
 }
 
+static unsigned int digits_in_number(unsigned int number)
+{
+       unsigned int i = 10, result = 1;
+       while (i <= number) {
+               i *= 10;
+               result++;
+       }
+       return result;
+}
+
 void show_log(struct rev_info *opt, const char *sep)
 {
        static char this_header[16384];
@@ -114,6 +125,14 @@ void show_log(struct rev_info *opt, const char *sep)
 
        opt->loginfo = NULL;
        if (!opt->verbose_header) {
+               if (opt->left_right) {
+                       if (commit->object.flags & BOUNDARY)
+                               putchar('-');
+                       else if (commit->object.flags & SYMMETRIC_LEFT)
+                               putchar('<');
+                       else
+                               putchar('>');
+               }
                fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
                if (opt->parents)
                        show_parents(commit, abbrev_commit);
@@ -134,7 +153,7 @@ void show_log(struct rev_info *opt, const char *sep)
        if (*sep != '\n' && opt->commit_format == CMIT_FMT_ONELINE)
                extra = "\n";
        if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE)
-               putchar('\n');
+               putchar(opt->diffopt.line_termination);
        opt->shown_one = 1;
 
        /*
@@ -146,7 +165,8 @@ void show_log(struct rev_info *opt, const char *sep)
                if (opt->total > 0) {
                        static char buffer[64];
                        snprintf(buffer, sizeof(buffer),
-                                       "Subject: [PATCH %d/%d] ",
+                                       "Subject: [PATCH %0*d/%d] ",
+                                       digits_in_number(opt->total),
                                        opt->nr, opt->total);
                        subject = buffer;
                } else if (opt->total == 0)
@@ -166,7 +186,7 @@ void show_log(struct rev_info *opt, const char *sep)
                        snprintf(subject_buffer, sizeof(subject_buffer) - 1,
                                 "%s"
                                 "MIME-Version: 1.0\n"
-                                "Content-Type: multipart/mixed;\n"
+                                "Content-Type: multipart/mixed;"
                                 " boundary=\"%s%s\"\n"
                                 "\n"
                                 "This is a multi-part message in MIME "
@@ -182,20 +202,32 @@ void show_log(struct rev_info *opt, const char *sep)
 
                        snprintf(buffer, sizeof(buffer) - 1,
                                 "--%s%s\n"
-                                "Content-Type: text/x-patch;\n"
+                                "Content-Type: text/x-patch;"
                                 " name=\"%s.diff\"\n"
                                 "Content-Transfer-Encoding: 8bit\n"
-                                "Content-Disposition: inline;\n"
+                                "Content-Disposition: %s;"
                                 " filename=\"%s.diff\"\n\n",
                                 mime_boundary_leader, opt->mime_boundary,
-                                sha1, sha1);
+                                sha1,
+                                opt->no_inline ? "attachment" : "inline",
+                                sha1);
                        opt->diffopt.stat_sep = buffer;
                }
-       } else {
-               printf("%s%s%s",
-                      diff_get_color(opt->diffopt.color_diff, DIFF_COMMIT),
-                      opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ",
-                      diff_unique_abbrev(commit->object.sha1, abbrev_commit));
+       } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
+               fputs(diff_get_color(opt->diffopt.color_diff, DIFF_COMMIT),
+                     stdout);
+               if (opt->commit_format != CMIT_FMT_ONELINE)
+                       fputs("commit ", stdout);
+               if (commit->object.flags & BOUNDARY)
+                       putchar('-');
+               else if (opt->left_right) {
+                       if (commit->object.flags & SYMMETRIC_LEFT)
+                               putchar('<');
+                       else
+                               putchar('>');
+               }
+               fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit),
+                     stdout);
                if (opt->parents)
                        show_parents(commit, abbrev_commit);
                if (parent)
@@ -205,6 +237,15 @@ void show_log(struct rev_info *opt, const char *sep)
                printf("%s",
                       diff_get_color(opt->diffopt.color_diff, DIFF_RESET));
                putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n');
+               if (opt->reflog_info) {
+                       show_reflog_message(opt->reflog_info,
+                                   opt->commit_format == CMIT_FMT_ONELINE,
+                                   opt->relative_date);
+                       if (opt->commit_format == CMIT_FMT_ONELINE) {
+                               printf("%s", sep);
+                               return;
+                       }
+               }
        }
 
        /*
@@ -243,35 +284,14 @@ int log_tree_diff_flush(struct rev_info *opt)
                    opt->commit_format != CMIT_FMT_ONELINE) {
                        int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
                        if ((pch & opt->diffopt.output_format) == pch)
-                               printf("---%c", opt->diffopt.line_termination);
-                       else
-                               putchar(opt->diffopt.line_termination);
+                               printf("---");
+                       putchar('\n');
                }
        }
        diff_flush(&opt->diffopt);
        return 1;
 }
 
-static int diff_root_tree(struct rev_info *opt,
-                         const unsigned char *new, const char *base)
-{
-       int retval;
-       void *tree;
-       struct tree_desc empty, real;
-
-       tree = read_object_with_reference(new, tree_type, &real.size, NULL);
-       if (!tree)
-               die("unable to read root tree (%s)", sha1_to_hex(new));
-       real.buf = tree;
-
-       empty.buf = "";
-       empty.size = 0;
-       retval = diff_tree(&empty, &real, base, &opt->diffopt);
-       free(tree);
-       log_tree_diff_flush(opt);
-       return retval;
-}
-
 static int do_diff_combined(struct rev_info *opt, struct commit *commit)
 {
        unsigned const char *sha1 = commit->object.sha1;
@@ -297,8 +317,10 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
        /* Root commit? */
        parents = commit->parents;
        if (!parents) {
-               if (opt->show_root_diff)
-                       diff_root_tree(opt, sha1, "");
+               if (opt->show_root_diff) {
+                       diff_root_tree_sha1(sha1, "", &opt->diffopt);
+                       log_tree_diff_flush(opt);
+               }
                return !opt->loginfo;
        }