Makefile: ssh-pull.o depends on ssh-fetch.c
[gitweb.git] / builtin-log.c
index 4ee5891dfd63e24db811bbc5f32f87f0f6b233ad..88c835acba66dc9bca31c8cd33d5425289ade5ca 100644 (file)
 #include "revision.h"
 #include "log-tree.h"
 #include "builtin.h"
+#include <time.h>
+#include <sys/time.h>
 
 /* this is in builtin-diff.c */
 void add_head(struct rev_info *revs);
 
-static int cmd_log_wc(int argc, const char **argv, char **envp,
+static void cmd_log_init(int argc, const char **argv, char **envp,
                      struct rev_info *rev)
 {
-       struct commit *commit;
-
        rev->abbrev = DEFAULT_ABBREV;
        rev->commit_format = CMIT_FMT_DEFAULT;
        rev->verbose_header = 1;
        argc = setup_revisions(argc, argv, rev, "HEAD");
-       if (rev->always_show_header) {
-               if (rev->diffopt.pickaxe || rev->diffopt.filter) {
-                       rev->always_show_header = 0;
-                       if (rev->diffopt.output_format == DIFF_FORMAT_RAW)
-                               rev->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
-               }
-       }
-
+       if (rev->diffopt.pickaxe || rev->diffopt.filter)
+               rev->always_show_header = 0;
        if (argc > 1)
                die("unrecognized argument: %s", argv[1]);
+}
+
+static int cmd_log_walk(struct rev_info *rev)
+{
+       struct commit *commit;
 
        prepare_revision_walk(rev);
        setup_pager();
@@ -51,10 +50,15 @@ int cmd_whatchanged(int argc, const char **argv, char **envp)
        struct rev_info rev;
 
        init_revisions(&rev);
+       git_config(git_diff_ui_config);
+       diff_setup(&rev.diffopt);
        rev.diff = 1;
        rev.diffopt.recursive = 1;
        rev.simplify_history = 0;
-       return cmd_log_wc(argc, argv, envp, &rev);
+       cmd_log_init(argc, argv, envp, &rev);
+       if (!rev.diffopt.output_format)
+               rev.diffopt.output_format = DIFF_FORMAT_RAW;
+       return cmd_log_walk(&rev);
 }
 
 int cmd_show(int argc, const char **argv, char **envp)
@@ -62,6 +66,8 @@ int cmd_show(int argc, const char **argv, char **envp)
        struct rev_info rev;
 
        init_revisions(&rev);
+       git_config(git_diff_ui_config);
+       diff_setup(&rev.diffopt);
        rev.diff = 1;
        rev.diffopt.recursive = 1;
        rev.combine_merges = 1;
@@ -69,7 +75,8 @@ int cmd_show(int argc, const char **argv, char **envp)
        rev.always_show_header = 1;
        rev.ignore_merges = 0;
        rev.no_walk = 1;
-       return cmd_log_wc(argc, argv, envp, &rev);
+       cmd_log_init(argc, argv, envp, &rev);
+       return cmd_log_walk(&rev);
 }
 
 int cmd_log(int argc, const char **argv, char **envp)
@@ -77,9 +84,11 @@ int cmd_log(int argc, const char **argv, char **envp)
        struct rev_info rev;
 
        init_revisions(&rev);
+       git_config(git_diff_ui_config);
+       diff_setup(&rev.diffopt);
        rev.always_show_header = 1;
-       rev.diffopt.recursive = 1;
-       return cmd_log_wc(argc, argv, envp, &rev);
+       cmd_log_init(argc, argv, envp, &rev);
+       return cmd_log_walk(&rev);
 }
 
 static int istitlechar(char c)
@@ -101,7 +110,10 @@ static int git_format_config(const char *var, const char *value)
                strcat(extra_headers, value);
                return 0;
        }
-       return git_default_config(var, value);
+       if (!strcmp(var, "diff.color")) {
+               return 0;
+       }
+       return git_diff_ui_config(var, value);
 }
 
 
@@ -160,15 +172,6 @@ static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
        freopen(filename, "w", stdout);
 }
 
-static void reset_all_objects_flags()
-{
-       int i;
-
-       for (i = 0; i < obj_allocs; i++)
-               if (objs[i])
-                       objs[i]->flags = 0;
-}
-
 static int get_patch_id(struct commit *commit, struct diff_options *options,
                unsigned char *sha1)
 {
@@ -220,11 +223,26 @@ static void get_patch_ids(struct rev_info *rev, struct diff_options *options)
        }
 
        /* reset for next revision walk */
-       reset_all_objects_flags();
+       clear_commit_marks((struct commit *)o1,
+                       SEEN | UNINTERESTING | SHOWN | ADDED);
+       clear_commit_marks((struct commit *)o2,
+                       SEEN | UNINTERESTING | SHOWN | ADDED);
        o1->flags = flags1;
        o2->flags = flags2;
 }
 
+static void gen_message_id(char *dest, unsigned int length, char *base)
+{
+       const char *committer = git_committer_info(1);
+       const char *email_start = strrchr(committer, '<');
+       const char *email_end = strrchr(committer, '>');
+       if(!email_start || !email_end || email_start > email_end - 1)
+               die("Could not extract email from committer identity.");
+       snprintf(dest, length, "%s.%lu.git.%.*s", base,
+                (unsigned long) time(NULL),
+                (int)(email_end - email_start - 1), email_start + 1);
+}
+
 int cmd_format_patch(int argc, const char **argv, char **envp)
 {
        struct commit *commit;
@@ -236,20 +254,23 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
        int start_number = -1;
        int keep_subject = 0;
        int ignore_if_in_upstream = 0;
+       int thread = 0;
+       const char *in_reply_to = NULL;
        struct diff_options patch_id_opts;
        char *add_signoff = NULL;
+       char message_id[1024];
+       char ref_message_id[1024];
 
+       git_config(git_format_config);
        init_revisions(&rev);
        rev.commit_format = CMIT_FMT_EMAIL;
        rev.verbose_header = 1;
        rev.diff = 1;
-       rev.diffopt.with_raw = 0;
-       rev.diffopt.with_stat = 1;
        rev.combine_merges = 0;
        rev.ignore_merges = 1;
-       rev.diffopt.output_format = DIFF_FORMAT_PATCH;
+       rev.diffopt.msg_sep = "";
+       rev.diffopt.recursive = 1;
 
-       git_config(git_format_config);
        rev.extra_headers = extra_headers;
 
        /*
@@ -304,6 +325,16 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
                        rev.mime_boundary = argv[i] + 9;
                else if (!strcmp(argv[i], "--ignore-if-in-upstream"))
                        ignore_if_in_upstream = 1;
+               else if (!strcmp(argv[i], "--thread"))
+                       thread = 1;
+               else if (!strncmp(argv[i], "--in-reply-to=", 14))
+                       in_reply_to = argv[i] + 14;
+               else if (!strcmp(argv[i], "--in-reply-to")) {
+                       i++;
+                       if (i == argc)
+                               die("Need a Message-Id for --in-reply-to");
+                       in_reply_to = argv[i];
+               }
                else
                        argv[j++] = argv[i];
        }
@@ -318,6 +349,9 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
        if (argc > 1)
                die ("unrecognized argument: %s", argv[1]);
 
+       if (!rev.diffopt.output_format)
+               rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
+
        if (output_directory) {
                if (use_stdout)
                        die("standard output, or directory, which one?");
@@ -358,10 +392,23 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
        if (numbered)
                rev.total = total + start_number - 1;
        rev.add_signoff = add_signoff;
+       rev.ref_message_id = in_reply_to;
        while (0 <= --nr) {
                int shown;
                commit = list[nr];
                rev.nr = total - nr + (start_number - 1);
+               /* Make the second and subsequent mails replies to the first */
+               if (thread) {
+                       if (nr == (total - 2)) {
+                               strncpy(ref_message_id, message_id,
+                                       sizeof(ref_message_id));
+                               ref_message_id[sizeof(ref_message_id)-1]='\0';
+                               rev.ref_message_id = ref_message_id;
+                       }
+                       gen_message_id(message_id, sizeof(message_id),
+                                      sha1_to_hex(commit->object.sha1));
+                       rev.message_id = message_id;
+               }
                if (!use_stdout)
                        reopen_stdout(commit, rev.nr, keep_subject);
                shown = log_tree_commit(&rev, commit);