]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-revert.c
Merge branch 'pb/prepare-commit-msg'
[git.git] / builtin-revert.c
index 365b330f9e1f2989683611077d260fa49abcb889..e219859f9b04dc94a2444346541e86503085fdea 100644 (file)
@@ -8,6 +8,7 @@
 #include "exec_cmd.h"
 #include "utf8.h"
 #include "parse-options.h"
+#include "cache-tree.h"
 
 /*
  * This implements the builtins revert and cherry-pick.
@@ -30,7 +31,7 @@ static const char * const cherry_pick_usage[] = {
        NULL
 };
 
-static int edit, no_replay, no_commit, needed_deref, mainline;
+static int edit, no_replay, no_commit, mainline;
 static enum { REVERT, CHERRY_PICK } action;
 static struct commit *commit;
 
@@ -66,7 +67,6 @@ static void parse_args(int argc, const char **argv)
        if (commit->object.type == OBJ_TAG) {
                commit = (struct commit *)
                        deref_tag((struct object *)commit, arg, strlen(arg));
-               needed_deref = 1;
        }
        if (commit->object.type != OBJ_COMMIT)
                die ("'%s' does not point to a commit", arg);
@@ -225,6 +225,27 @@ static int merge_recursive(const char *base_sha1,
        return run_command_v_opt(argv, RUN_COMMAND_NO_STDIN | RUN_GIT_CMD);
 }
 
+static char *help_msg(const unsigned char *sha1)
+{
+       static char helpbuf[1024];
+       char *msg = getenv("GIT_CHERRY_PICK_HELP");
+
+       if (msg)
+               return msg;
+
+       strcpy(helpbuf, "  After resolving the conflicts,\n"
+              "mark the corrected paths with 'git add <paths>' "
+              "or 'git rm <paths>' and commit the result.");
+
+       if (action == CHERRY_PICK) {
+               sprintf(helpbuf + strlen(helpbuf),
+                       "\nWhen commiting, use the option "
+                       "'-c %s' to retain authorship and message.",
+                       find_unique_abbrev(sha1, DEFAULT_ABBREV));
+       }
+       return helpbuf;
+}
+
 static int revert_or_cherry_pick(int argc, const char **argv)
 {
        unsigned char head[20];
@@ -250,7 +271,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
                 * that represents the "current" state for merge-recursive
                 * to work on.
                 */
-               if (write_tree(head, 0, NULL))
+               if (write_cache_as_tree(head, 0, NULL))
                        die ("Your index file is unmerged.");
        } else {
                struct wt_status s;
@@ -333,22 +354,11 @@ static int revert_or_cherry_pick(int argc, const char **argv)
                        add_to_msg(")\n");
                }
        }
-       if (needed_deref) {
-               add_to_msg("(original 'git ");
-               add_to_msg(me);
-               add_to_msg("' arguments: ");
-               for (i = 0; i < argc; i++) {
-                       if (i)
-                               add_to_msg(" ");
-                       add_to_msg(argv[i]);
-               }
-               add_to_msg(")\n");
-       }
 
        if (merge_recursive(sha1_to_hex(base->object.sha1),
                                sha1_to_hex(head), "HEAD",
                                sha1_to_hex(next->object.sha1), oneline) ||
-                       write_tree(head, 0, NULL)) {
+                       write_cache_as_tree(head, 0, NULL)) {
                add_to_msg("\nConflicts:\n\n");
                read_cache();
                for (i = 0; i < active_nr;) {
@@ -362,21 +372,13 @@ static int revert_or_cherry_pick(int argc, const char **argv)
                                        i++;
                        }
                }
-               if (close(msg_fd) || commit_lock_file(&msg_file) < 0)
+               if (commit_lock_file(&msg_file) < 0)
                        die ("Error wrapping up %s", defmsg);
-               fprintf(stderr, "Automatic %s failed.  "
-                       "After resolving the conflicts,\n"
-                       "mark the corrected paths with 'git add <paths>' "
-                       "and commit the result.\n", me);
-               if (action == CHERRY_PICK) {
-                       fprintf(stderr, "When commiting, use the option "
-                               "'-c %s' to retain authorship and message.\n",
-                               find_unique_abbrev(commit->object.sha1,
-                                       DEFAULT_ABBREV));
-               }
+               fprintf(stderr, "Automatic %s failed.%s\n",
+                       me, help_msg(commit->object.sha1));
                exit(1);
        }
-       if (close(msg_fd) || commit_lock_file(&msg_file) < 0)
+       if (commit_lock_file(&msg_file) < 0)
                die ("Error wrapping up %s", defmsg);
        fprintf(stderr, "Finished one %s.\n", me);