Merge branch 'jk/unused-parameter-fixes'
[gitweb.git] / builtin / am.c
index c78a745289fc16618d3739d1443c3fc6fef47be7..8f27f3375b1e92f2ef026e0a1530ca8b6b3235bf 100644 (file)
@@ -260,36 +260,6 @@ static int read_state_file(struct strbuf *sb, const struct am_state *state,
        die_errno(_("could not read '%s'"), am_path(state, file));
 }
 
-/**
- * Take a series of KEY='VALUE' lines where VALUE part is
- * sq-quoted, and append <KEY, VALUE> at the end of the string list
- */
-static int parse_key_value_squoted(char *buf, struct string_list *list)
-{
-       while (*buf) {
-               struct string_list_item *item;
-               char *np;
-               char *cp = strchr(buf, '=');
-               if (!cp) {
-                       np = strchrnul(buf, '\n');
-                       return error(_("unable to parse '%.*s'"),
-                                    (int) (np - buf), buf);
-               }
-               np = strchrnul(cp, '\n');
-               *cp++ = '\0';
-               item = string_list_append(list, buf);
-
-               buf = np + (*np == '\n');
-               *np = '\0';
-               cp = sq_dequote(cp);
-               if (!cp)
-                       return error(_("unable to dequote value of '%s'"),
-                                    item->string);
-               item->util = xstrdup(cp);
-       }
-       return 0;
-}
-
 /**
  * Reads and parses the state directory's "author-script" file, and sets
  * state->author_name, state->author_email and state->author_date accordingly.
@@ -309,65 +279,13 @@ static int parse_key_value_squoted(char *buf, struct string_list *list)
 static int read_am_author_script(struct am_state *state)
 {
        const char *filename = am_path(state, "author-script");
-       struct strbuf buf = STRBUF_INIT;
-       struct string_list kv = STRING_LIST_INIT_DUP;
-       int retval = -1; /* assume failure */
-       int i, name_i = -2, email_i = -2, date_i = -2, err = 0;
-       int fd;
 
        assert(!state->author_name);
        assert(!state->author_email);
        assert(!state->author_date);
 
-       fd = open(filename, O_RDONLY);
-       if (fd < 0) {
-               if (errno == ENOENT)
-                       return 0;
-               return error_errno(_("could not open '%s' for reading"),
-                                  filename);
-       }
-       strbuf_read(&buf, fd, 0);
-       close(fd);
-       if (parse_key_value_squoted(buf.buf, &kv))
-               goto finish;
-
-       for (i = 0; i < kv.nr; i++) {
-               if (!strcmp(kv.items[i].string, "GIT_AUTHOR_NAME")) {
-                       if (name_i != -2)
-                               name_i = error(_("'GIT_AUTHOR_NAME' already given"));
-                       else
-                               name_i = i;
-               } else if (!strcmp(kv.items[i].string, "GIT_AUTHOR_EMAIL")) {
-                       if (email_i != -2)
-                               email_i = error(_("'GIT_AUTHOR_EMAIL' already given"));
-                       else
-                               email_i = i;
-               } else if (!strcmp(kv.items[i].string, "GIT_AUTHOR_DATE")) {
-                       if (date_i != -2)
-                               date_i = error(_("'GIT_AUTHOR_DATE' already given"));
-                       else
-                               date_i = i;
-               } else {
-                       err = error(_("unknown variable '%s'"),
-                                   kv.items[i].string);
-               }
-       }
-       if (name_i == -2)
-               error(_("missing 'GIT_AUTHOR_NAME'"));
-       if (email_i == -2)
-               error(_("missing 'GIT_AUTHOR_EMAIL'"));
-       if (date_i == -2)
-               error(_("missing 'GIT_AUTHOR_DATE'"));
-       if (date_i < 0 || email_i < 0 || date_i < 0 || err)
-               goto finish;
-       state->author_name = kv.items[name_i].util;
-       state->author_email = kv.items[email_i].util;
-       state->author_date = kv.items[date_i].util;
-       retval = 0;
-finish:
-       string_list_clear(&kv, !!retval);
-       strbuf_release(&buf);
-       return retval;
+       return read_author_script(filename, &state->author_name,
+                                 &state->author_email, &state->author_date, 1);
 }
 
 /**
@@ -1406,7 +1324,7 @@ static void write_commit_patch(const struct am_state *state, struct commit *comm
        FILE *fp;
 
        fp = xfopen(am_path(state, "patch"), "w");
-       init_revisions(&rev_info, NULL);
+       repo_init_revisions(the_repository, &rev_info, NULL);
        rev_info.diff = 1;
        rev_info.abbrev = 0;
        rev_info.disable_stdin = 1;
@@ -1441,7 +1359,7 @@ static void write_index_patch(const struct am_state *state)
                                   the_repository->hash_algo->empty_tree);
 
        fp = xfopen(am_path(state, "patch"), "w");
-       init_revisions(&rev_info, NULL);
+       repo_init_revisions(the_repository, &rev_info, NULL);
        rev_info.diff = 1;
        rev_info.disable_stdin = 1;
        rev_info.no_commit_id = 1;
@@ -1599,7 +1517,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
                struct rev_info rev_info;
                const char *diff_filter_str = "--diff-filter=AM";
 
-               init_revisions(&rev_info, NULL);
+               repo_init_revisions(the_repository, &rev_info, NULL);
                rev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
                diff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1, rev_info.prefix);
                add_pending_oid(&rev_info, "HEAD", &our_tree, 0);
@@ -1638,7 +1556,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
                o.verbosity = 0;
 
        if (merge_recursive_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {
-               rerere(state->allow_rerere_autoupdate);
+               repo_rerere(the_repository, state->allow_rerere_autoupdate);
                free(their_tree_name);
                return error(_("Failed to merge in the changes."));
        }
@@ -1933,7 +1851,7 @@ static void am_resolve(struct am_state *state)
                        goto next;
        }
 
-       rerere(0);
+       repo_rerere(the_repository, 0);
 
        do_commit(state);
 
@@ -2195,7 +2113,9 @@ static int parse_opt_patchformat(const struct option *opt, const char *arg, int
 {
        int *opt_value = opt->value;
 
-       if (!strcmp(arg, "mbox"))
+       if (unset)
+               *opt_value = PATCH_FORMAT_UNKNOWN;
+       else if (!strcmp(arg, "mbox"))
                *opt_value = PATCH_FORMAT_MBOX;
        else if (!strcmp(arg, "stgit"))
                *opt_value = PATCH_FORMAT_STGIT;
@@ -2358,7 +2278,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
        /* Ensure a valid committer ident can be constructed */
        git_committer_info(IDENT_STRICT);
 
-       if (read_index_preload(&the_index, NULL) < 0)
+       if (read_index_preload(&the_index, NULL, 0) < 0)
                die(_("failed to read the index"));
 
        if (in_progress) {