cherry-pick/revert: Use advise() for hints
[gitweb.git] / builtin / revert.c
index c3d64af02ded50a7dcd971d879210cb82d1d26b0..7f35cc6e1734c4000d8971f808356d0fb344ffc6 100644 (file)
@@ -241,27 +241,30 @@ static void set_author_ident_env(const char *message)
                        sha1_to_hex(commit->object.sha1));
 }
 
-static char *help_msg(void)
+static void advise(const char *advice, ...)
 {
-       struct strbuf helpbuf = STRBUF_INIT;
-       char *msg = getenv("GIT_CHERRY_PICK_HELP");
+       va_list params;
 
-       if (msg)
-               return msg;
+       va_start(params, advice);
+       vreportf("hint: ", advice, params);
+       va_end(params);
+}
 
-       strbuf_addstr(&helpbuf, "  After resolving the conflicts,\n"
-               "mark the corrected paths with 'git add <paths>' or 'git rm <paths>'\n"
-               "and commit the result");
+static void print_advice(void)
+{
+       char *msg = getenv("GIT_CHERRY_PICK_HELP");
 
-       if (action == CHERRY_PICK) {
-               strbuf_addf(&helpbuf, " with: \n"
-                       "\n"
-                       "        git commit -c %s\n",
-                           sha1_to_hex(commit->object.sha1));
+       if (msg) {
+               fprintf(stderr, "%s\n", msg);
+               return;
        }
-       else
-               strbuf_addch(&helpbuf, '.');
-       return strbuf_detach(&helpbuf, NULL);
+
+       advise("after resolving the conflicts, mark the corrected paths");
+       advise("with 'git add <paths>' or 'git rm <paths>'");
+
+       if (action == CHERRY_PICK)
+               advise("and commit the result with 'git commit -c %s'",
+                      find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
 }
 
 static void write_message(struct strbuf *msgbuf, const char *filename)
@@ -395,7 +398,6 @@ static int do_pick_commit(void)
        struct commit_message msg = { NULL, NULL, NULL, NULL, NULL };
        char *defmsg = NULL;
        struct strbuf msgbuf = STRBUF_INIT;
-       struct strbuf mebuf = STRBUF_INIT;
        int res;
 
        if (no_commit) {
@@ -492,9 +494,6 @@ static int do_pick_commit(void)
                }
        }
 
-       strbuf_addf(&mebuf, "%s of commit %s", me,
-                   find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
-
        if (!strategy || !strcmp(strategy, "recursive") || action == REVERT) {
                res = do_recursive_merge(base, next, base_label, next_label,
                                         head, &msgbuf);
@@ -503,7 +502,6 @@ static int do_pick_commit(void)
                struct commit_list *common = NULL;
                struct commit_list *remotes = NULL;
 
-               strbuf_addf(&mebuf, " with strategy %s", strategy);
                write_message(&msgbuf, defmsg);
 
                commit_list_insert(base, &common);
@@ -515,15 +513,17 @@ static int do_pick_commit(void)
        }
 
        if (res) {
-               fprintf(stderr, "Automatic %s failed.%s\n",
-                       mebuf.buf, help_msg());
+               error("could not %s %s... %s",
+                     action == REVERT ? "revert" : "apply",
+                     find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV),
+                     msg.subject);
+               print_advice();
                rerere(allow_rerere_auto);
        } else {
                if (!no_commit)
                        res = run_git_commit(defmsg);
        }
 
-       strbuf_release(&mebuf);
        free_message(&msg);
        free(defmsg);