Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 1 | #include "cache.h" |
| 2 | #include "builtin.h" |
| 3 | #include "object.h" |
| 4 | #include "commit.h" |
| 5 | #include "tag.h" |
| 6 | #include "wt-status.h" |
| 7 | #include "run-command.h" |
| 8 | #include "exec_cmd.h" |
| 9 | #include "utf8.h" |
Pierre Habouzit | f810379 | 2007-10-07 23:02:29 +0200 | [diff] [blame] | 10 | #include "parse-options.h" |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 11 | |
| 12 | /* |
| 13 | * This implements the builtins revert and cherry-pick. |
| 14 | * |
| 15 | * Copyright (c) 2007 Johannes E. Schindelin |
| 16 | * |
| 17 | * Based on git-revert.sh, which is |
| 18 | * |
| 19 | * Copyright (c) 2005 Linus Torvalds |
| 20 | * Copyright (c) 2005 Junio C Hamano |
| 21 | */ |
| 22 | |
Pierre Habouzit | f810379 | 2007-10-07 23:02:29 +0200 | [diff] [blame] | 23 | static const char * const revert_usage[] = { |
| 24 | "git-revert [options] <commit-ish>", |
| 25 | NULL |
| 26 | }; |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 27 | |
Pierre Habouzit | f810379 | 2007-10-07 23:02:29 +0200 | [diff] [blame] | 28 | static const char * const cherry_pick_usage[] = { |
| 29 | "git-cherry-pick [options] <commit-ish>", |
| 30 | NULL |
| 31 | }; |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 32 | |
Junio C Hamano | 02273fd | 2007-11-04 01:26:02 -0700 | [diff] [blame] | 33 | static int edit, no_replay, no_commit, needed_deref, mainline; |
Junio C Hamano | 4175e9e | 2007-06-13 01:42:05 -0700 | [diff] [blame] | 34 | static enum { REVERT, CHERRY_PICK } action; |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 35 | static struct commit *commit; |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 36 | |
| 37 | static const char *me; |
| 38 | |
| 39 | #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION" |
| 40 | |
Pierre Habouzit | f810379 | 2007-10-07 23:02:29 +0200 | [diff] [blame] | 41 | static void parse_args(int argc, const char **argv) |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 42 | { |
Pierre Habouzit | f810379 | 2007-10-07 23:02:29 +0200 | [diff] [blame] | 43 | const char * const * usage_str = |
| 44 | action == REVERT ? revert_usage : cherry_pick_usage; |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 45 | unsigned char sha1[20]; |
| 46 | const char *arg; |
Pierre Habouzit | f810379 | 2007-10-07 23:02:29 +0200 | [diff] [blame] | 47 | int noop; |
| 48 | struct option options[] = { |
| 49 | OPT_BOOLEAN('n', "no-commit", &no_commit, "don't automatically commit"), |
| 50 | OPT_BOOLEAN('e', "edit", &edit, "edit the commit message"), |
| 51 | OPT_BOOLEAN('x', NULL, &no_replay, "append commit name when cherry-picking"), |
| 52 | OPT_BOOLEAN('r', NULL, &noop, "no-op (backward compatibility)"), |
Junio C Hamano | 02273fd | 2007-11-04 01:26:02 -0700 | [diff] [blame] | 53 | OPT_INTEGER('m', "mainline", &mainline, "parent number"), |
Pierre Habouzit | f810379 | 2007-10-07 23:02:29 +0200 | [diff] [blame] | 54 | OPT_END(), |
| 55 | }; |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 56 | |
Pierre Habouzit | f810379 | 2007-10-07 23:02:29 +0200 | [diff] [blame] | 57 | if (parse_options(argc, argv, options, usage_str, 0) != 1) |
| 58 | usage_with_options(usage_str, options); |
| 59 | arg = argv[0]; |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 60 | |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 61 | if (get_sha1(arg, sha1)) |
| 62 | die ("Cannot find '%s'", arg); |
| 63 | commit = (struct commit *)parse_object(sha1); |
| 64 | if (!commit) |
| 65 | die ("Could not find %s", sha1_to_hex(sha1)); |
| 66 | if (commit->object.type == OBJ_TAG) { |
| 67 | commit = (struct commit *) |
| 68 | deref_tag((struct object *)commit, arg, strlen(arg)); |
| 69 | needed_deref = 1; |
| 70 | } |
| 71 | if (commit->object.type != OBJ_COMMIT) |
| 72 | die ("'%s' does not point to a commit", arg); |
| 73 | } |
| 74 | |
| 75 | static char *get_oneline(const char *message) |
| 76 | { |
| 77 | char *result; |
| 78 | const char *p = message, *abbrev, *eol; |
| 79 | int abbrev_len, oneline_len; |
| 80 | |
| 81 | if (!p) |
| 82 | die ("Could not read commit message of %s", |
| 83 | sha1_to_hex(commit->object.sha1)); |
| 84 | while (*p && (*p != '\n' || p[1] != '\n')) |
| 85 | p++; |
| 86 | |
| 87 | if (*p) { |
| 88 | p += 2; |
| 89 | for (eol = p + 1; *eol && *eol != '\n'; eol++) |
| 90 | ; /* do nothing */ |
| 91 | } else |
| 92 | eol = p; |
| 93 | abbrev = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV); |
| 94 | abbrev_len = strlen(abbrev); |
| 95 | oneline_len = eol - p; |
| 96 | result = xmalloc(abbrev_len + 5 + oneline_len); |
| 97 | memcpy(result, abbrev, abbrev_len); |
| 98 | memcpy(result + abbrev_len, "... ", 4); |
| 99 | memcpy(result + abbrev_len + 4, p, oneline_len); |
| 100 | result[abbrev_len + 4 + oneline_len] = '\0'; |
| 101 | return result; |
| 102 | } |
| 103 | |
Pierre Habouzit | 52fae7d | 2007-06-07 22:45:00 +0200 | [diff] [blame] | 104 | static char *get_encoding(const char *message) |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 105 | { |
| 106 | const char *p = message, *eol; |
| 107 | |
| 108 | if (!p) |
| 109 | die ("Could not read commit message of %s", |
| 110 | sha1_to_hex(commit->object.sha1)); |
| 111 | while (*p && *p != '\n') { |
| 112 | for (eol = p + 1; *eol && *eol != '\n'; eol++) |
| 113 | ; /* do nothing */ |
| 114 | if (!prefixcmp(p, "encoding ")) { |
| 115 | char *result = xmalloc(eol - 8 - p); |
| 116 | strlcpy(result, p + 9, eol - 8 - p); |
| 117 | return result; |
| 118 | } |
| 119 | p = eol; |
| 120 | if (*p == '\n') |
| 121 | p++; |
| 122 | } |
| 123 | return NULL; |
| 124 | } |
| 125 | |
Junio C Hamano | 4175e9e | 2007-06-13 01:42:05 -0700 | [diff] [blame] | 126 | static struct lock_file msg_file; |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 127 | static int msg_fd; |
| 128 | |
| 129 | static void add_to_msg(const char *string) |
| 130 | { |
| 131 | int len = strlen(string); |
| 132 | if (write_in_full(msg_fd, string, len) < 0) |
Shawn O. Pearce | 1dcb3b6 | 2007-05-10 18:10:36 -0400 | [diff] [blame] | 133 | die ("Could not write to MERGE_MSG"); |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static void add_message_to_msg(const char *message) |
| 137 | { |
| 138 | const char *p = message; |
| 139 | while (*p && (*p != '\n' || p[1] != '\n')) |
| 140 | p++; |
| 141 | |
| 142 | if (!*p) |
| 143 | add_to_msg(sha1_to_hex(commit->object.sha1)); |
| 144 | |
| 145 | p += 2; |
| 146 | add_to_msg(p); |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | static void set_author_ident_env(const char *message) |
| 151 | { |
| 152 | const char *p = message; |
| 153 | if (!p) |
| 154 | die ("Could not read commit message of %s", |
| 155 | sha1_to_hex(commit->object.sha1)); |
| 156 | while (*p && *p != '\n') { |
| 157 | const char *eol; |
| 158 | |
| 159 | for (eol = p; *eol && *eol != '\n'; eol++) |
| 160 | ; /* do nothing */ |
| 161 | if (!prefixcmp(p, "author ")) { |
| 162 | char *line, *pend, *email, *timestamp; |
| 163 | |
| 164 | p += 7; |
Pierre Habouzit | 182af83 | 2007-09-16 00:32:36 +0200 | [diff] [blame] | 165 | line = xmemdupz(p, eol - p); |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 166 | email = strchr(line, '<'); |
| 167 | if (!email) |
| 168 | die ("Could not extract author email from %s", |
| 169 | sha1_to_hex(commit->object.sha1)); |
| 170 | if (email == line) |
| 171 | pend = line; |
| 172 | else |
| 173 | for (pend = email; pend != line + 1 && |
| 174 | isspace(pend[-1]); pend--); |
| 175 | ; /* do nothing */ |
| 176 | *pend = '\0'; |
| 177 | email++; |
| 178 | timestamp = strchr(email, '>'); |
| 179 | if (!timestamp) |
| 180 | die ("Could not extract author email from %s", |
| 181 | sha1_to_hex(commit->object.sha1)); |
| 182 | *timestamp = '\0'; |
| 183 | for (timestamp++; *timestamp && isspace(*timestamp); |
| 184 | timestamp++) |
| 185 | ; /* do nothing */ |
| 186 | setenv("GIT_AUTHOR_NAME", line, 1); |
| 187 | setenv("GIT_AUTHOR_EMAIL", email, 1); |
| 188 | setenv("GIT_AUTHOR_DATE", timestamp, 1); |
| 189 | free(line); |
| 190 | return; |
| 191 | } |
| 192 | p = eol; |
| 193 | if (*p == '\n') |
| 194 | p++; |
| 195 | } |
| 196 | die ("No author information found in %s", |
| 197 | sha1_to_hex(commit->object.sha1)); |
| 198 | } |
| 199 | |
| 200 | static int merge_recursive(const char *base_sha1, |
| 201 | const char *head_sha1, const char *head_name, |
| 202 | const char *next_sha1, const char *next_name) |
| 203 | { |
| 204 | char buffer[256]; |
Shawn O. Pearce | 497bdc8 | 2007-03-10 03:27:28 -0500 | [diff] [blame] | 205 | const char *argv[6]; |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 206 | |
| 207 | sprintf(buffer, "GITHEAD_%s", head_sha1); |
| 208 | setenv(buffer, head_name, 1); |
| 209 | sprintf(buffer, "GITHEAD_%s", next_sha1); |
| 210 | setenv(buffer, next_name, 1); |
| 211 | |
| 212 | /* |
| 213 | * This three way merge is an interesting one. We are at |
| 214 | * $head, and would want to apply the change between $commit |
| 215 | * and $prev on top of us (when reverting), or the change between |
| 216 | * $prev and $commit on top of us (when cherry-picking or replaying). |
| 217 | */ |
Shawn O. Pearce | 497bdc8 | 2007-03-10 03:27:28 -0500 | [diff] [blame] | 218 | argv[0] = "merge-recursive"; |
| 219 | argv[1] = base_sha1; |
| 220 | argv[2] = "--"; |
| 221 | argv[3] = head_sha1; |
| 222 | argv[4] = next_sha1; |
| 223 | argv[5] = NULL; |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 224 | |
Shawn O. Pearce | 497bdc8 | 2007-03-10 03:27:28 -0500 | [diff] [blame] | 225 | return run_command_v_opt(argv, RUN_COMMAND_NO_STDIN | RUN_GIT_CMD); |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | static int revert_or_cherry_pick(int argc, const char **argv) |
| 229 | { |
| 230 | unsigned char head[20]; |
Junio C Hamano | 7791ecb | 2007-10-23 13:33:26 -0700 | [diff] [blame] | 231 | struct commit *base, *next, *parent; |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 232 | int i; |
Shawn O. Pearce | 1a8f274 | 2007-03-12 15:33:18 -0400 | [diff] [blame] | 233 | char *oneline, *reencoded_message = NULL; |
| 234 | const char *message, *encoding; |
Shawn O. Pearce | abda522 | 2007-05-07 22:57:15 -0400 | [diff] [blame] | 235 | const char *defmsg = xstrdup(git_path("MERGE_MSG")); |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 236 | |
| 237 | git_config(git_default_config); |
| 238 | me = action == REVERT ? "revert" : "cherry-pick"; |
| 239 | setenv(GIT_REFLOG_ACTION, me, 0); |
Pierre Habouzit | f810379 | 2007-10-07 23:02:29 +0200 | [diff] [blame] | 240 | parse_args(argc, argv); |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 241 | |
| 242 | /* this is copied from the shell script, but it's never triggered... */ |
Pierre Habouzit | f810379 | 2007-10-07 23:02:29 +0200 | [diff] [blame] | 243 | if (action == REVERT && !no_replay) |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 244 | die("revert is incompatible with replay"); |
| 245 | |
| 246 | if (no_commit) { |
| 247 | /* |
| 248 | * We do not intend to commit immediately. We just want to |
Junio C Hamano | 71aa2b8 | 2007-11-13 13:45:11 -0800 | [diff] [blame] | 249 | * merge the differences in, so let's compute the tree |
| 250 | * that represents the "current" state for merge-recursive |
| 251 | * to work on. |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 252 | */ |
| 253 | if (write_tree(head, 0, NULL)) |
| 254 | die ("Your index file is unmerged."); |
| 255 | } else { |
| 256 | struct wt_status s; |
| 257 | |
| 258 | if (get_sha1("HEAD", head)) |
| 259 | die ("You do not have a valid HEAD"); |
| 260 | wt_status_prepare(&s); |
Junio C Hamano | 245de36 | 2007-11-13 12:28:53 -0800 | [diff] [blame] | 261 | if (s.commitable) |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 262 | die ("Dirty index: cannot %s", me); |
| 263 | discard_cache(); |
| 264 | } |
| 265 | |
| 266 | if (!commit->parents) |
| 267 | die ("Cannot %s a root commit", me); |
Junio C Hamano | 7791ecb | 2007-10-23 13:33:26 -0700 | [diff] [blame] | 268 | if (commit->parents->next) { |
| 269 | /* Reverting or cherry-picking a merge commit */ |
| 270 | int cnt; |
| 271 | struct commit_list *p; |
| 272 | |
| 273 | if (!mainline) |
| 274 | die("Commit %s is a merge but no -m option was given.", |
| 275 | sha1_to_hex(commit->object.sha1)); |
| 276 | |
| 277 | for (cnt = 1, p = commit->parents; |
| 278 | cnt != mainline && p; |
| 279 | cnt++) |
| 280 | p = p->next; |
| 281 | if (cnt != mainline || !p) |
| 282 | die("Commit %s does not have parent %d", |
| 283 | sha1_to_hex(commit->object.sha1), mainline); |
| 284 | parent = p->item; |
| 285 | } else if (0 < mainline) |
| 286 | die("Mainline was specified but commit %s is not a merge.", |
| 287 | sha1_to_hex(commit->object.sha1)); |
| 288 | else |
| 289 | parent = commit->parents->item; |
| 290 | |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 291 | if (!(message = commit->buffer)) |
| 292 | die ("Cannot get commit message for %s", |
| 293 | sha1_to_hex(commit->object.sha1)); |
| 294 | |
| 295 | /* |
| 296 | * "commit" is an existing commit. We would want to apply |
| 297 | * the difference it introduces since its first parent "prev" |
| 298 | * on top of the current HEAD if we are cherry-pick. Or the |
| 299 | * reverse of it if we are revert. |
| 300 | */ |
| 301 | |
Shawn O. Pearce | abda522 | 2007-05-07 22:57:15 -0400 | [diff] [blame] | 302 | msg_fd = hold_lock_file_for_update(&msg_file, defmsg, 1); |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 303 | |
| 304 | encoding = get_encoding(message); |
| 305 | if (!encoding) |
| 306 | encoding = "utf-8"; |
| 307 | if (!git_commit_encoding) |
| 308 | git_commit_encoding = "utf-8"; |
| 309 | if ((reencoded_message = reencode_string(message, |
| 310 | git_commit_encoding, encoding))) |
| 311 | message = reencoded_message; |
| 312 | |
| 313 | oneline = get_oneline(message); |
| 314 | |
| 315 | if (action == REVERT) { |
Johannes Schindelin | e43b010 | 2007-03-23 17:06:11 +0100 | [diff] [blame] | 316 | char *oneline_body = strchr(oneline, ' '); |
| 317 | |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 318 | base = commit; |
Junio C Hamano | 7791ecb | 2007-10-23 13:33:26 -0700 | [diff] [blame] | 319 | next = parent; |
Johannes Schindelin | e43b010 | 2007-03-23 17:06:11 +0100 | [diff] [blame] | 320 | add_to_msg("Revert \""); |
| 321 | add_to_msg(oneline_body + 1); |
| 322 | add_to_msg("\"\n\nThis reverts commit "); |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 323 | add_to_msg(sha1_to_hex(commit->object.sha1)); |
| 324 | add_to_msg(".\n"); |
| 325 | } else { |
Junio C Hamano | 7791ecb | 2007-10-23 13:33:26 -0700 | [diff] [blame] | 326 | base = parent; |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 327 | next = commit; |
| 328 | set_author_ident_env(message); |
| 329 | add_message_to_msg(message); |
Pierre Habouzit | f810379 | 2007-10-07 23:02:29 +0200 | [diff] [blame] | 330 | if (no_replay) { |
Shawn O. Pearce | 0e62404 | 2007-03-06 00:46:00 -0500 | [diff] [blame] | 331 | add_to_msg("(cherry picked from commit "); |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 332 | add_to_msg(sha1_to_hex(commit->object.sha1)); |
| 333 | add_to_msg(")\n"); |
| 334 | } |
| 335 | } |
| 336 | if (needed_deref) { |
| 337 | add_to_msg("(original 'git "); |
| 338 | add_to_msg(me); |
| 339 | add_to_msg("' arguments: "); |
| 340 | for (i = 0; i < argc; i++) { |
| 341 | if (i) |
| 342 | add_to_msg(" "); |
| 343 | add_to_msg(argv[i]); |
| 344 | } |
| 345 | add_to_msg(")\n"); |
| 346 | } |
| 347 | |
| 348 | if (merge_recursive(sha1_to_hex(base->object.sha1), |
| 349 | sha1_to_hex(head), "HEAD", |
Johannes Schindelin | f52463a | 2007-03-04 14:26:05 +0100 | [diff] [blame] | 350 | sha1_to_hex(next->object.sha1), oneline) || |
| 351 | write_tree(head, 0, NULL)) { |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 352 | add_to_msg("\nConflicts:\n\n"); |
| 353 | read_cache(); |
| 354 | for (i = 0; i < active_nr;) { |
| 355 | struct cache_entry *ce = active_cache[i++]; |
| 356 | if (ce_stage(ce)) { |
| 357 | add_to_msg("\t"); |
| 358 | add_to_msg(ce->name); |
| 359 | add_to_msg("\n"); |
| 360 | while (i < active_nr && !strcmp(ce->name, |
| 361 | active_cache[i]->name)) |
| 362 | i++; |
| 363 | } |
| 364 | } |
| 365 | if (close(msg_fd) || commit_lock_file(&msg_file) < 0) |
Shawn O. Pearce | abda522 | 2007-05-07 22:57:15 -0400 | [diff] [blame] | 366 | die ("Error wrapping up %s", defmsg); |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 367 | fprintf(stderr, "Automatic %s failed. " |
| 368 | "After resolving the conflicts,\n" |
Nicolas Pitre | 04bd8e5 | 2007-10-30 15:59:24 -0400 | [diff] [blame] | 369 | "mark the corrected paths with 'git add <paths>' " |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 370 | "and commit the result.\n", me); |
| 371 | if (action == CHERRY_PICK) { |
Johannes Schindelin | f52463a | 2007-03-04 14:26:05 +0100 | [diff] [blame] | 372 | fprintf(stderr, "When commiting, use the option " |
| 373 | "'-c %s' to retain authorship and message.\n", |
| 374 | find_unique_abbrev(commit->object.sha1, |
| 375 | DEFAULT_ABBREV)); |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 376 | } |
| 377 | exit(1); |
| 378 | } |
| 379 | if (close(msg_fd) || commit_lock_file(&msg_file) < 0) |
Shawn O. Pearce | abda522 | 2007-05-07 22:57:15 -0400 | [diff] [blame] | 380 | die ("Error wrapping up %s", defmsg); |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 381 | fprintf(stderr, "Finished one %s.\n", me); |
| 382 | |
| 383 | /* |
| 384 | * |
| 385 | * If we are cherry-pick, and if the merge did not result in |
| 386 | * hand-editing, we will hit this commit and inherit the original |
| 387 | * author date and name. |
| 388 | * If we are revert, or if our cherry-pick results in a hand merge, |
| 389 | * we had better say that the current user is responsible for that. |
| 390 | */ |
| 391 | |
| 392 | if (!no_commit) { |
| 393 | if (edit) |
Shawn O. Pearce | abda522 | 2007-05-07 22:57:15 -0400 | [diff] [blame] | 394 | return execl_git_cmd("commit", "-n", NULL); |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 395 | else |
Shawn O. Pearce | abda522 | 2007-05-07 22:57:15 -0400 | [diff] [blame] | 396 | return execl_git_cmd("commit", "-n", "-F", defmsg, NULL); |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 397 | } |
| 398 | if (reencoded_message) |
| 399 | free(reencoded_message); |
| 400 | |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | int cmd_revert(int argc, const char **argv, const char *prefix) |
| 405 | { |
| 406 | if (isatty(0)) |
| 407 | edit = 1; |
Pierre Habouzit | f810379 | 2007-10-07 23:02:29 +0200 | [diff] [blame] | 408 | no_replay = 1; |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 409 | action = REVERT; |
| 410 | return revert_or_cherry_pick(argc, argv); |
| 411 | } |
| 412 | |
| 413 | int cmd_cherry_pick(int argc, const char **argv, const char *prefix) |
| 414 | { |
Pierre Habouzit | f810379 | 2007-10-07 23:02:29 +0200 | [diff] [blame] | 415 | no_replay = 0; |
Johannes Schindelin | 9509af6 | 2007-03-01 05:26:30 +0100 | [diff] [blame] | 416 | action = CHERRY_PICK; |
| 417 | return revert_or_cherry_pick(argc, argv); |
| 418 | } |