Merge branch 'po/doc-core-ignorestat'
[gitweb.git] / builtin / commit.c
index 81dc622a3b72040daca199f05d0a3322f316e6f6..7d90c3591567d10f9a075ec38048b93923f707d4 100644 (file)
@@ -522,6 +522,12 @@ static int is_a_merge(const struct commit *current_head)
        return !!(current_head->parents && current_head->parents->next);
 }
 
+static void assert_split_ident(struct ident_split *id, const struct strbuf *buf)
+{
+       if (split_ident_line(id, buf->buf, buf->len) || !id->date_begin)
+               die("BUG: unable to parse our own ident: %s", buf->buf);
+}
+
 static void export_one(const char *var, const char *s, const char *e, int hack)
 {
        struct strbuf buf = STRBUF_INIT;
@@ -532,20 +538,6 @@ static void export_one(const char *var, const char *s, const char *e, int hack)
        strbuf_release(&buf);
 }
 
-static int sane_ident_split(struct ident_split *person)
-{
-       if (!person->name_begin || !person->name_end ||
-           person->name_begin == person->name_end)
-               return 0; /* no human readable name */
-       if (!person->mail_begin || !person->mail_end ||
-           person->mail_begin == person->mail_end)
-               return 0; /* no usable mail */
-       if (!person->date_begin || !person->date_end ||
-           !person->tz_begin || !person->tz_end)
-               return 0;
-       return 1;
-}
-
 static int parse_force_date(const char *in, struct strbuf *out)
 {
        strbuf_addch(out, '@');
@@ -623,25 +615,15 @@ static void determine_author_info(struct strbuf *author_ident)
        }
 
        strbuf_addstr(author_ident, fmt_ident(name, email, date, IDENT_STRICT));
-       if (!split_ident_line(&author, author_ident->buf, author_ident->len) &&
-           sane_ident_split(&author)) {
-               export_one("GIT_AUTHOR_NAME", author.name_begin, author.name_end, 0);
-               export_one("GIT_AUTHOR_EMAIL", author.mail_begin, author.mail_end, 0);
-               export_one("GIT_AUTHOR_DATE", author.date_begin, author.tz_end, '@');
-       }
-
+       assert_split_ident(&author, author_ident);
+       export_one("GIT_AUTHOR_NAME", author.name_begin, author.name_end, 0);
+       export_one("GIT_AUTHOR_EMAIL", author.mail_begin, author.mail_end, 0);
+       export_one("GIT_AUTHOR_DATE", author.date_begin, author.tz_end, '@');
        free(name);
        free(email);
        free(date);
 }
 
-static void split_ident_or_die(struct ident_split *id, const struct strbuf *buf)
-{
-       if (split_ident_line(id, buf->buf, buf->len) ||
-           !sane_ident_split(id))
-               die(_("Malformed ident string: '%s'"), buf->buf);
-}
-
 static int author_date_is_interesting(void)
 {
        return author_message || force_date;
@@ -800,32 +782,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        if (clean_message_contents)
                stripspace(&sb, 0);
 
-       if (signoff) {
-               /*
-                * See if we have a Conflicts: block at the end. If yes, count
-                * its size, so we can ignore it.
-                */
-               int ignore_footer = 0;
-               int i, eol, previous = 0;
-               const char *nl;
-
-               for (i = 0; i < sb.len; i++) {
-                       nl = memchr(sb.buf + i, '\n', sb.len - i);
-                       if (nl)
-                               eol = nl - sb.buf;
-                       else
-                               eol = sb.len;
-                       if (starts_with(sb.buf + previous, "\nConflicts:\n")) {
-                               ignore_footer = sb.len - previous;
-                               break;
-                       }
-                       while (i < eol)
-                               i++;
-                       previous = eol;
-               }
-
-               append_signoff(&sb, ignore_footer, 0);
-       }
+       if (signoff)
+               append_signoff(&sb, ignore_non_trailer(&sb), 0);
 
        if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
                die_errno(_("could not write commit template"));
@@ -880,8 +838,14 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                        status_printf_ln(s, GIT_COLOR_NORMAL,
                                        "%s", only_include_assumed);
 
-               split_ident_or_die(&ai, author_ident);
-               split_ident_or_die(&ci, &committer_ident);
+               /*
+                * These should never fail because they come from our own
+                * fmt_ident. They may fail the sane_ident test, but we know
+                * that the name and mail pointers will at least be valid,
+                * which is enough for our tests and printing here.
+                */
+               assert_split_ident(&ai, author_ident);
+               assert_split_ident(&ci, &committer_ident);
 
                if (ident_cmp(&ai, &ci))
                        status_printf_ln(s, GIT_COLOR_NORMAL,
@@ -1272,22 +1236,21 @@ static int dry_run_commit(int argc, const char **argv, const char *prefix,
        return commitable ? 0 : 1;
 }
 
-static int parse_status_slot(const char *var, int offset)
+static int parse_status_slot(const char *slot)
 {
-       if (!strcasecmp(var+offset, "header"))
+       if (!strcasecmp(slot, "header"))
                return WT_STATUS_HEADER;
-       if (!strcasecmp(var+offset, "branch"))
+       if (!strcasecmp(slot, "branch"))
                return WT_STATUS_ONBRANCH;
-       if (!strcasecmp(var+offset, "updated")
-               || !strcasecmp(var+offset, "added"))
+       if (!strcasecmp(slot, "updated") || !strcasecmp(slot, "added"))
                return WT_STATUS_UPDATED;
-       if (!strcasecmp(var+offset, "changed"))
+       if (!strcasecmp(slot, "changed"))
                return WT_STATUS_CHANGED;
-       if (!strcasecmp(var+offset, "untracked"))
+       if (!strcasecmp(slot, "untracked"))
                return WT_STATUS_UNTRACKED;
-       if (!strcasecmp(var+offset, "nobranch"))
+       if (!strcasecmp(slot, "nobranch"))
                return WT_STATUS_NOBRANCH;
-       if (!strcasecmp(var+offset, "unmerged"))
+       if (!strcasecmp(slot, "unmerged"))
                return WT_STATUS_UNMERGED;
        return -1;
 }
@@ -1327,13 +1290,12 @@ static int git_status_config(const char *k, const char *v, void *cb)
        }
        if (skip_prefix(k, "status.color.", &slot_name) ||
            skip_prefix(k, "color.status.", &slot_name)) {
-               int slot = parse_status_slot(k, slot_name - k);
+               int slot = parse_status_slot(slot_name);
                if (slot < 0)
                        return 0;
                if (!v)
                        return config_error_nonbool(k);
-               color_parse(v, k, s->color_palette[slot]);
-               return 0;
+               return color_parse(v, s->color_palette[slot]);
        }
        if (!strcmp(k, "status.relativepaths")) {
                s->relative_paths = git_config_bool(k, v);
@@ -1515,7 +1477,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
        rev.diffopt.break_opt = 0;
        diff_setup_done(&rev.diffopt);
 
-       head = resolve_ref_unsafe("HEAD", junk_sha1, 0, NULL);
+       head = resolve_ref_unsafe("HEAD", 0, junk_sha1, NULL);
        if (!strcmp(head, "HEAD"))
                head = _("detached HEAD");
        else
@@ -1811,8 +1773,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
            ref_transaction_update(transaction, "HEAD", sha1,
                                   current_head
                                   ? current_head->object.sha1 : NULL,
-                                  0, !!current_head, &err) ||
-           ref_transaction_commit(transaction, sb.buf, &err)) {
+                                  0, !!current_head, sb.buf, &err) ||
+           ref_transaction_commit(transaction, &err)) {
                rollback_index_files();
                die("%s", err.buf);
        }