Merge branch 'jc/everyday-markup' into maint
[gitweb.git] / builtin / log.c
index a131992c52f96daeb7c72b447c5ed6929c01a96a..a491d3dea0e412624e7212060658e22a421cdfbf 100644 (file)
@@ -5,6 +5,7 @@
  *              2006 Junio Hamano
  */
 #include "cache.h"
+#include "refs.h"
 #include "color.h"
 #include "commit.h"
 #include "diff.h"
@@ -31,6 +32,7 @@ static const char *default_date_mode = NULL;
 
 static int default_abbrev_commit;
 static int default_show_root = 1;
+static int default_follow;
 static int decoration_style;
 static int decoration_given;
 static int use_mailmap_config;
@@ -38,8 +40,8 @@ static const char *fmt_patch_subject_prefix = "PATCH";
 static const char *fmt_pretty;
 
 static const char * const builtin_log_usage[] = {
-       N_("git log [<options>] [<revision range>] [[--] <path>...]"),
-       N_("git show [options] <object>..."),
+       N_("git log [<options>] [<revision-range>] [[--] <path>...]"),
+       N_("git show [<options>] <object>..."),
        NULL
 };
 
@@ -102,6 +104,8 @@ static void cmd_log_init_defaults(struct rev_info *rev)
 {
        if (fmt_pretty)
                get_commit_format(fmt_pretty, rev);
+       if (default_follow)
+               DIFF_OPT_SET(&rev->diffopt, DEFAULT_FOLLOW_RENAMES);
        rev->verbose_header = 1;
        DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
        rev->diffopt.stat_width = -1; /* use full terminal width */
@@ -112,7 +116,7 @@ static void cmd_log_init_defaults(struct rev_info *rev)
        DIFF_OPT_SET(&rev->diffopt, ALLOW_TEXTCONV);
 
        if (default_date_mode)
-               rev->date_mode = parse_date_format(default_date_mode);
+               parse_date_format(default_date_mode, &rev->date_mode);
        rev->diffopt.touched_flags = 0;
 }
 
@@ -338,8 +342,7 @@ static int cmd_log_walk(struct rev_info *rev)
         * retain that state information if replacing rev->diffopt in this loop
         */
        while ((commit = get_revision(rev)) != NULL) {
-               if (!log_tree_commit(rev, commit) &&
-                   rev->max_count >= 0)
+               if (!log_tree_commit(rev, commit) && rev->max_count >= 0)
                        /*
                         * We decremented max_count in get_revision,
                         * but we didn't actually show the commit.
@@ -390,6 +393,10 @@ static int git_log_config(const char *var, const char *value, void *cb)
                default_show_root = git_config_bool(var, value);
                return 0;
        }
+       if (!strcmp(var, "log.follow")) {
+               default_follow = git_config_bool(var, value);
+               return 0;
+       }
        if (skip_prefix(var, "color.decorate.", &slot_name))
                return parse_decorate_color_config(var, slot_name, value);
        if (!strcmp(var, "log.mailmap")) {
@@ -496,7 +503,8 @@ static int show_tree_object(const unsigned char *sha1,
        return 0;
 }
 
-static void show_rev_tweak_rev(struct rev_info *rev, struct setup_revision_opt *opt)
+static void show_setup_revisions_tweak(struct rev_info *rev,
+                                      struct setup_revision_opt *opt)
 {
        if (rev->ignore_merges) {
                /* There was no "-m" on the command line */
@@ -531,7 +539,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
 
        memset(&opt, 0, sizeof(opt));
        opt.def = "HEAD";
-       opt.tweak = show_rev_tweak_rev;
+       opt.tweak = show_setup_revisions_tweak;
        cmd_log_init(argc, argv, prefix, &rev, &opt);
 
        if (!rev.no_walk)
@@ -618,6 +626,22 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
        return cmd_log_walk(&rev);
 }
 
+static void log_setup_revisions_tweak(struct rev_info *rev,
+                                     struct setup_revision_opt *opt)
+{
+       if (DIFF_OPT_TST(&rev->diffopt, DEFAULT_FOLLOW_RENAMES) &&
+           rev->prune_data.nr == 1)
+               DIFF_OPT_SET(&rev->diffopt, FOLLOW_RENAMES);
+
+       /* Turn --cc/-c into -p --cc/-c when -p was not given */
+       if (!rev->diffopt.output_format && rev->combine_merges)
+               rev->diffopt.output_format = DIFF_FORMAT_PATCH;
+
+       /* Turn -m on when --cc/-c was given */
+       if (rev->combine_merges)
+               rev->ignore_merges = 0;
+}
+
 int cmd_log(int argc, const char **argv, const char *prefix)
 {
        struct rev_info rev;
@@ -631,6 +655,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)
        memset(&opt, 0, sizeof(opt));
        opt.def = "HEAD";
        opt.revarg_opt = REVARG_COMMITTISH;
+       opt.tweak = log_setup_revisions_tweak;
        cmd_log_init(argc, argv, prefix, &rev, &opt);
        return cmd_log_walk(&rev);
 }
@@ -795,7 +820,7 @@ static int reopen_stdout(struct commit *commit, const char *subject,
 static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
 {
        struct rev_info check_rev;
-       struct commit *commit;
+       struct commit *commit, *c1, *c2;
        struct object *o1, *o2;
        unsigned flags1, flags2;
 
@@ -803,9 +828,11 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
                die(_("Need exactly one range."));
 
        o1 = rev->pending.objects[0].item;
-       flags1 = o1->flags;
        o2 = rev->pending.objects[1].item;
+       flags1 = o1->flags;
        flags2 = o2->flags;
+       c1 = lookup_commit_reference(o1->sha1);
+       c2 = lookup_commit_reference(o2->sha1);
 
        if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING))
                die(_("Not a range."));
@@ -827,10 +854,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
        }
 
        /* reset for next revision walk */
-       clear_commit_marks((struct commit *)o1,
-                       SEEN | UNINTERESTING | SHOWN | ADDED);
-       clear_commit_marks((struct commit *)o2,
-                       SEEN | UNINTERESTING | SHOWN | ADDED);
+       clear_commit_marks(c1, SEEN | UNINTERESTING | SHOWN | ADDED);
+       clear_commit_marks(c2, SEEN | UNINTERESTING | SHOWN | ADDED);
        o1->flags = flags1;
        o2->flags = flags2;
 }
@@ -939,7 +964,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
 
        msg = body;
        pp.fmt = CMIT_FMT_EMAIL;
-       pp.date_mode = DATE_RFC2822;
+       pp.date_mode.type = DATE_RFC2822;
        pp_user_info(&pp, NULL, &sb, committer, encoding);
        pp_title_line(&pp, &msg, &sb, encoding, need_8bit_cte);
        pp_remainder(&pp, &msg, &sb, 0);
@@ -1023,7 +1048,7 @@ static const char *set_outdir(const char *prefix, const char *output_directory)
 }
 
 static const char * const builtin_format_patch_usage[] = {
-       N_("git format-patch [options] [<since> | <revision range>]"),
+       N_("git format-patch [<options>] [<since> | <revision-range>]"),
        NULL
 };
 
@@ -1438,8 +1463,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                        continue;
                }
 
-               if (ignore_if_in_upstream &&
-                               has_commit_patch_id(commit, &ids))
+               if (ignore_if_in_upstream && has_commit_patch_id(commit, &ids))
                        continue;
 
                nr++;
@@ -1632,16 +1656,13 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
                break;
        default:
                current_branch = branch_get(NULL);
-               if (!current_branch || !current_branch->merge
-                                       || !current_branch->merge[0]
-                                       || !current_branch->merge[0]->dst) {
+               upstream = branch_get_upstream(current_branch, NULL);
+               if (!upstream) {
                        fprintf(stderr, _("Could not find a tracked"
                                        " remote branch, please"
                                        " specify <upstream> manually.\n"));
                        usage_with_options(cherry_usage, options);
                }
-
-               upstream = current_branch->merge[0]->dst;
        }
 
        init_revisions(&revs, prefix);