rebase -m: do not trigger pre-commit verification
[gitweb.git] / builtin-log.c
index 54ddaad0eccedd74be349d208fecb9a87b143047..99d69f079132ed67e2d5bc83bf95e6e60ba22f6f 100644 (file)
@@ -18,9 +18,6 @@
 static int default_show_root = 1;
 static const char *fmt_patch_subject_prefix = "PATCH";
 
-/* this is in builtin-diff.c */
-void add_head(struct rev_info *revs);
-
 static void add_name_decoration(const char *prefix, const char *name, struct object *obj)
 {
        int plen = strlen(prefix);
@@ -55,13 +52,13 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
        rev->abbrev = DEFAULT_ABBREV;
        rev->commit_format = CMIT_FMT_DEFAULT;
        rev->verbose_header = 1;
-       rev->diffopt.recursive = 1;
+       DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
        rev->show_root_diff = default_show_root;
        rev->subject_prefix = fmt_patch_subject_prefix;
        argc = setup_revisions(argc, argv, rev, "HEAD");
        if (rev->diffopt.pickaxe || rev->diffopt.filter)
                rev->always_show_header = 0;
-       if (rev->diffopt.follow_renames) {
+       if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) {
                rev->always_show_header = 0;
                if (rev->diffopt.nr_paths != 1)
                        usage("git logs can only follow renames on one pathname at a time");
@@ -222,7 +219,7 @@ static int git_log_config(const char *var, const char *value)
 {
        if (!strcmp(var, "format.subjectprefix")) {
                if (!value)
-                       die("format.subjectprefix without value");
+                       config_error_nonbool(var);
                fmt_patch_subject_prefix = xstrdup(value);
                return 0;
        }
@@ -247,7 +244,28 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
        return cmd_log_walk(&rev);
 }
 
-static int show_object(const unsigned char *sha1, int suppress_header)
+static void show_tagger(char *buf, int len, struct rev_info *rev)
+{
+       char *email_end, *p;
+       unsigned long date;
+       int tz;
+
+       email_end = memchr(buf, '>', len);
+       if (!email_end)
+               return;
+       p = ++email_end;
+       while (isspace(*p))
+               p++;
+       date = strtoul(p, &p, 10);
+       while (isspace(*p))
+               p++;
+       tz = (int)strtol(p, NULL, 10);
+       printf("Tagger: %.*s\nDate:   %s\n", (int)(email_end - buf), buf,
+              show_date(date, tz, rev->date_mode));
+}
+
+static int show_object(const unsigned char *sha1, int show_tag_object,
+       struct rev_info *rev)
 {
        unsigned long size;
        enum object_type type;
@@ -257,11 +275,14 @@ static int show_object(const unsigned char *sha1, int suppress_header)
        if (!buf)
                return error("Could not read object %s", sha1_to_hex(sha1));
 
-       if (suppress_header)
-               while (offset < size && buf[offset++] != '\n') {
-                       int new_offset = offset;
+       if (show_tag_object)
+               while (offset < size && buf[offset] != '\n') {
+                       int new_offset = offset + 1;
                        while (new_offset < size && buf[new_offset++] != '\n')
                                ; /* do nothing */
+                       if (!prefixcmp(buf + offset, "tagger "))
+                               show_tagger(buf + offset + 7,
+                                           new_offset - offset - 7, rev);
                        offset = new_offset;
                }
 
@@ -302,29 +323,25 @@ int cmd_show(int argc, const char **argv, const char *prefix)
                const char *name = objects[i].name;
                switch (o->type) {
                case OBJ_BLOB:
-                       ret = show_object(o->sha1, 0);
+                       ret = show_object(o->sha1, 0, NULL);
                        break;
                case OBJ_TAG: {
                        struct tag *t = (struct tag *)o;
 
-                       printf("%stag %s%s\n\n",
-                                       diff_get_color(rev.diffopt.color_diff,
-                                               DIFF_COMMIT),
+                       printf("%stag %s%s\n",
+                                       diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
                                        t->tag,
-                                       diff_get_color(rev.diffopt.color_diff,
-                                               DIFF_RESET));
-                       ret = show_object(o->sha1, 1);
+                                       diff_get_color_opt(&rev.diffopt, DIFF_RESET));
+                       ret = show_object(o->sha1, 1, &rev);
                        objects[i].item = (struct object *)t->tagged;
                        i--;
                        break;
                }
                case OBJ_TREE:
                        printf("%stree %s%s\n\n",
-                                       diff_get_color(rev.diffopt.color_diff,
-                                               DIFF_COMMIT),
+                                       diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
                                        name,
-                                       diff_get_color(rev.diffopt.color_diff,
-                                               DIFF_RESET));
+                                       diff_get_color_opt(&rev.diffopt, DIFF_RESET));
                        read_tree_recursive((struct tree *)o, "", 0, 0, NULL,
                                        show_tree_object);
                        break;
@@ -396,6 +413,8 @@ static int istitlechar(char c)
 static char *extra_headers = NULL;
 static int extra_headers_size = 0;
 static const char *fmt_patch_suffix = ".patch";
+static int numbered = 0;
+static int auto_number = 0;
 
 static int git_format_config(const char *var, const char *value)
 {
@@ -413,13 +432,21 @@ static int git_format_config(const char *var, const char *value)
        }
        if (!strcmp(var, "format.suffix")) {
                if (!value)
-                       die("format.suffix without value");
+                       return config_error_nonbool(var);
                fmt_patch_suffix = xstrdup(value);
                return 0;
        }
        if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
                return 0;
        }
+       if (!strcmp(var, "format.numbered")) {
+               if (value && !strcasecmp(value, "auto")) {
+                       auto_number = 1;
+                       return 0;
+               }
+               numbered = git_config_bool(var, value);
+               return 0;
+       }
 
        return git_log_config(var, value);
 }
@@ -550,7 +577,7 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const cha
 
 static void gen_message_id(char *dest, unsigned int length, char *base)
 {
-       const char *committer = git_committer_info(-1);
+       const char *committer = git_committer_info(IDENT_WARN_ON_NO_NAME);
        const char *email_start = strrchr(committer, '<');
        const char *email_end = strrchr(committer, '>');
        if(!email_start || !email_end || email_start > email_end - 1)
@@ -589,7 +616,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
        struct rev_info rev;
        int nr = 0, total, i, j;
        int use_stdout = 0;
-       int numbered = 0;
        int start_number = -1;
        int keep_subject = 0;
        int numbered_files = 0;         /* _just_ numbers */
@@ -610,7 +636,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
        rev.combine_merges = 0;
        rev.ignore_merges = 1;
        rev.diffopt.msg_sep = "";
-       rev.diffopt.recursive = 1;
+       DIFF_OPT_SET(&rev.diffopt, RECURSIVE);
 
        rev.subject_prefix = fmt_patch_subject_prefix;
        rev.extra_headers = extra_headers;
@@ -626,6 +652,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                else if (!strcmp(argv[i], "-n") ||
                                !strcmp(argv[i], "--numbered"))
                        numbered = 1;
+               else if (!strcmp(argv[i], "-N") ||
+                               !strcmp(argv[i], "--no-numbered")) {
+                       numbered = 0;
+                       auto_number = 0;
+               }
                else if (!prefixcmp(argv[i], "--start-number="))
                        start_number = strtol(argv[i] + 15, NULL, 10);
                else if (!strcmp(argv[i], "--numbered-files"))
@@ -654,7 +685,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                         !strcmp(argv[i], "-s")) {
                        const char *committer;
                        const char *endpos;
-                       committer = git_committer_info(1);
+                       committer = git_committer_info(IDENT_ERROR_ON_NO_NAME);
                        endpos = strchr(committer, '>');
                        if (!endpos)
                                die("bogos committer info %s\n", committer);
@@ -713,8 +744,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
        if (!rev.diffopt.output_format)
                rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH;
 
-       if (!rev.diffopt.text)
-               rev.diffopt.binary = 1;
+       if (!DIFF_OPT_TST(&rev.diffopt, TEXT))
+               DIFF_OPT_SET(&rev.diffopt, BINARY);
 
        if (!output_directory && !use_stdout)
                output_directory = prefix;
@@ -735,7 +766,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                         * does not have.
                         */
                        rev.pending.objects[0].item->flags |= UNINTERESTING;
-                       add_head(&rev);
+                       add_head_to_pending(&rev);
                }
                /*
                 * Otherwise, it is "format-patch -22 HEAD", and/or
@@ -765,6 +796,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                list[nr - 1] = commit;
        }
        total = nr;
+       if (!keep_subject && auto_number && total > 1)
+               numbered = 1;
        if (numbered)
                rev.total = total + start_number - 1;
        rev.add_signoff = add_signoff;
@@ -870,7 +903,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
        revs.diff = 1;
        revs.combine_merges = 0;
        revs.ignore_merges = 1;
-       revs.diffopt.recursive = 1;
+       DIFF_OPT_SET(&revs.diffopt, RECURSIVE);
 
        if (add_pending_commit(head, &revs, 0))
                die("Unknown commit %s", head);