Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 461 lines (404 sloc) 11.733 kB
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
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"
f810379 @MadCoder Make builtin-revert.c use parse_options.
MadCoder authored
10 #include "parse-options.h"
45525bd @gitster Make error messages from cherry-pick/revert more sensible
gitster authored
11 #include "cache-tree.h"
0f2d447 @peff revert: actually check for a dirty index
peff authored
12 #include "diff.h"
13 #include "revision.h"
aa1a011 @amenonsen Make cherry-pick use rerere for conflict resolution.
amenonsen authored
14 #include "rerere.h"
6eb1b43 cherry-pick/revert: make direct internal call to merge_tree()
Miklos Vajna authored
15 #include "merge-recursive.h"
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
16
17 /*
18 * This implements the builtins revert and cherry-pick.
19 *
20 * Copyright (c) 2007 Johannes E. Schindelin
21 *
22 * Based on git-revert.sh, which is
23 *
24 * Copyright (c) 2005 Linus Torvalds
25 * Copyright (c) 2005 Junio C Hamano
26 */
27
f810379 @MadCoder Make builtin-revert.c use parse_options.
MadCoder authored
28 static const char * const revert_usage[] = {
1b1dd23 @sbeyer Make usage strings dash-less
sbeyer authored
29 "git revert [options] <commit-ish>",
f810379 @MadCoder Make builtin-revert.c use parse_options.
MadCoder authored
30 NULL
31 };
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
32
f810379 @MadCoder Make builtin-revert.c use parse_options.
MadCoder authored
33 static const char * const cherry_pick_usage[] = {
1b1dd23 @sbeyer Make usage strings dash-less
sbeyer authored
34 "git cherry-pick [options] <commit-ish>",
f810379 @MadCoder Make builtin-revert.c use parse_options.
MadCoder authored
35 NULL
36 };
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
37
cfd9c27 @toofishes Allow cherry-pick (and revert) to add signoff line
toofishes authored
38 static int edit, no_replay, no_commit, mainline, signoff;
4175e9e @gitster More static
gitster authored
39 static enum { REVERT, CHERRY_PICK } action;
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
40 static struct commit *commit;
9791554 @peff cherry-pick: show commit name instead of sha1
peff authored
41 static const char *commit_name;
cb6020b @gitster Teach --[no-]rerere-autoupdate option to merge, revert and friends
gitster authored
42 static int allow_rerere_auto;
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
43
44 static const char *me;
45
46 #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
47
f810379 @MadCoder Make builtin-revert.c use parse_options.
MadCoder authored
48 static void parse_args(int argc, const char **argv)
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
49 {
f810379 @MadCoder Make builtin-revert.c use parse_options.
MadCoder authored
50 const char * const * usage_str =
51 action == REVERT ? revert_usage : cherry_pick_usage;
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
52 unsigned char sha1[20];
f810379 @MadCoder Make builtin-revert.c use parse_options.
MadCoder authored
53 int noop;
54 struct option options[] = {
55 OPT_BOOLEAN('n', "no-commit", &no_commit, "don't automatically commit"),
56 OPT_BOOLEAN('e', "edit", &edit, "edit the commit message"),
57 OPT_BOOLEAN('x', NULL, &no_replay, "append commit name when cherry-picking"),
58 OPT_BOOLEAN('r', NULL, &noop, "no-op (backward compatibility)"),
cfd9c27 @toofishes Allow cherry-pick (and revert) to add signoff line
toofishes authored
59 OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"),
02273fd @gitster Merge branch 'jc/revert-merge'
gitster authored
60 OPT_INTEGER('m', "mainline", &mainline, "parent number"),
cb6020b @gitster Teach --[no-]rerere-autoupdate option to merge, revert and friends
gitster authored
61 OPT_RERERE_AUTOUPDATE(&allow_rerere_auto),
f810379 @MadCoder Make builtin-revert.c use parse_options.
MadCoder authored
62 OPT_END(),
63 };
64
3778292 @bebarino parse-opts: prepare for OPT_FILENAME
bebarino authored
65 if (parse_options(argc, argv, NULL, options, usage_str, 0) != 1)
f810379 @MadCoder Make builtin-revert.c use parse_options.
MadCoder authored
66 usage_with_options(usage_str, options);
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
67
9791554 @peff cherry-pick: show commit name instead of sha1
peff authored
68 commit_name = argv[0];
69 if (get_sha1(commit_name, sha1))
70 die ("Cannot find '%s'", commit_name);
dd9314c @peff cherry-pick: refactor commit parsing code
peff authored
71 commit = lookup_commit_reference(sha1);
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
72 if (!commit)
dd9314c @peff cherry-pick: refactor commit parsing code
peff authored
73 exit(1);
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
74 }
75
76 static char *get_oneline(const char *message)
77 {
78 char *result;
79 const char *p = message, *abbrev, *eol;
80 int abbrev_len, oneline_len;
81
82 if (!p)
83 die ("Could not read commit message of %s",
84 sha1_to_hex(commit->object.sha1));
85 while (*p && (*p != '\n' || p[1] != '\n'))
86 p++;
87
88 if (*p) {
89 p += 2;
90 for (eol = p + 1; *eol && *eol != '\n'; eol++)
91 ; /* do nothing */
92 } else
93 eol = p;
94 abbrev = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
95 abbrev_len = strlen(abbrev);
96 oneline_len = eol - p;
97 result = xmalloc(abbrev_len + 5 + oneline_len);
98 memcpy(result, abbrev, abbrev_len);
99 memcpy(result + abbrev_len, "... ", 4);
100 memcpy(result + abbrev_len + 4, p, oneline_len);
101 result[abbrev_len + 4 + oneline_len] = '\0';
102 return result;
103 }
104
52fae7d @MadCoder Missing statics.
MadCoder authored
105 static char *get_encoding(const char *message)
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
106 {
107 const char *p = message, *eol;
108
109 if (!p)
110 die ("Could not read commit message of %s",
111 sha1_to_hex(commit->object.sha1));
112 while (*p && *p != '\n') {
113 for (eol = p + 1; *eol && *eol != '\n'; eol++)
114 ; /* do nothing */
115 if (!prefixcmp(p, "encoding ")) {
116 char *result = xmalloc(eol - 8 - p);
117 strlcpy(result, p + 9, eol - 8 - p);
118 return result;
119 }
120 p = eol;
121 if (*p == '\n')
122 p++;
123 }
124 return NULL;
125 }
126
4175e9e @gitster More static
gitster authored
127 static struct lock_file msg_file;
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
128 static int msg_fd;
129
130 static void add_to_msg(const char *string)
131 {
132 int len = strlen(string);
133 if (write_in_full(msg_fd, string, len) < 0)
0721c31 @trast Use die_errno() instead of die() when checking syscalls
trast authored
134 die_errno ("Could not write to MERGE_MSG");
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
135 }
136
137 static void add_message_to_msg(const char *message)
138 {
139 const char *p = message;
140 while (*p && (*p != '\n' || p[1] != '\n'))
141 p++;
142
143 if (!*p)
144 add_to_msg(sha1_to_hex(commit->object.sha1));
145
146 p += 2;
147 add_to_msg(p);
148 return;
149 }
150
151 static void set_author_ident_env(const char *message)
152 {
153 const char *p = message;
154 if (!p)
155 die ("Could not read commit message of %s",
156 sha1_to_hex(commit->object.sha1));
157 while (*p && *p != '\n') {
158 const char *eol;
159
160 for (eol = p; *eol && *eol != '\n'; eol++)
161 ; /* do nothing */
162 if (!prefixcmp(p, "author ")) {
163 char *line, *pend, *email, *timestamp;
164
165 p += 7;
182af83 @MadCoder Use xmemdupz() in many places.
MadCoder authored
166 line = xmemdupz(p, eol - p);
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
167 email = strchr(line, '<');
168 if (!email)
169 die ("Could not extract author email from %s",
170 sha1_to_hex(commit->object.sha1));
171 if (email == line)
172 pend = line;
173 else
174 for (pend = email; pend != line + 1 &&
175 isspace(pend[-1]); pend--);
176 ; /* do nothing */
177 *pend = '\0';
178 email++;
179 timestamp = strchr(email, '>');
180 if (!timestamp)
1e5f7ad @sbeyer builtin-revert.c: typofix
sbeyer authored
181 die ("Could not extract author time from %s",
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
182 sha1_to_hex(commit->object.sha1));
183 *timestamp = '\0';
184 for (timestamp++; *timestamp && isspace(*timestamp);
185 timestamp++)
186 ; /* do nothing */
187 setenv("GIT_AUTHOR_NAME", line, 1);
188 setenv("GIT_AUTHOR_EMAIL", email, 1);
189 setenv("GIT_AUTHOR_DATE", timestamp, 1);
190 free(line);
191 return;
192 }
193 p = eol;
194 if (*p == '\n')
195 p++;
196 }
197 die ("No author information found in %s",
198 sha1_to_hex(commit->object.sha1));
199 }
200
9791554 @peff cherry-pick: show commit name instead of sha1
peff authored
201 static char *help_msg(const char *name)
804c717 @wincent revert/cherry-pick: Allow overriding the help text by the calling Por…
wincent authored
202 {
08565bd @peff cherry-pick: format help message as strbuf
peff authored
203 struct strbuf helpbuf = STRBUF_INIT;
804c717 @wincent revert/cherry-pick: Allow overriding the help text by the calling Por…
wincent authored
204 char *msg = getenv("GIT_CHERRY_PICK_HELP");
205
206 if (msg)
207 return msg;
208
08565bd @peff cherry-pick: format help message as strbuf
peff authored
209 strbuf_addstr(&helpbuf, " After resolving the conflicts,\n"
6e35997 @peff cherry-pick: rewrap advice message
peff authored
210 "mark the corrected paths with 'git add <paths>' or 'git rm <paths>'\n"
4d12888 @peff cherry-pick: prettify the advice message
peff authored
211 "and commit the result");
804c717 @wincent revert/cherry-pick: Allow overriding the help text by the calling Por…
wincent authored
212
213 if (action == CHERRY_PICK) {
4d12888 @peff cherry-pick: prettify the advice message
peff authored
214 strbuf_addf(&helpbuf, " with: \n"
215 "\n"
216 " git commit -c %s\n",
9791554 @peff cherry-pick: show commit name instead of sha1
peff authored
217 name);
804c717 @wincent revert/cherry-pick: Allow overriding the help text by the calling Por…
wincent authored
218 }
4d12888 @peff cherry-pick: prettify the advice message
peff authored
219 else
220 strbuf_addch(&helpbuf, '.');
08565bd @peff cherry-pick: format help message as strbuf
peff authored
221 return strbuf_detach(&helpbuf, NULL);
804c717 @wincent revert/cherry-pick: Allow overriding the help text by the calling Por…
wincent authored
222 }
223
6eb1b43 cherry-pick/revert: make direct internal call to merge_tree()
Miklos Vajna authored
224 static struct tree *empty_tree(void)
225 {
226 struct tree *tree = xcalloc(1, sizeof(struct tree));
227
228 tree->object.parsed = 1;
229 tree->object.type = OBJ_TREE;
230 pretend_sha1_file(NULL, 0, OBJ_TREE, tree->object.sha1);
231 return tree;
232 }
233
d38a30d @moy Be more user-friendly when refusing to do something because of conflict.
moy authored
234 static NORETURN void die_dirty_index(const char *me)
235 {
236 if (read_cache_unmerged()) {
237 die_resolve_conflict(me);
238 } else {
239 if (advice_commit_before_merge)
240 die("Your local changes would be overwritten by %s.\n"
241 "Please, commit your changes or stash them to proceed.", me);
242 else
243 die("Your local changes would be overwritten by %s.\n", me);
244 }
245 }
246
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
247 static int revert_or_cherry_pick(int argc, const char **argv)
248 {
249 unsigned char head[20];
7791ecb @gitster revert/cherry-pick: work on merge commits as well
gitster authored
250 struct commit *base, *next, *parent;
6eb1b43 cherry-pick/revert: make direct internal call to merge_tree()
Miklos Vajna authored
251 int i, index_fd, clean;
1a8f274 @spearce Correct new compiler warnings in builtin-revert
spearce authored
252 char *oneline, *reencoded_message = NULL;
253 const char *message, *encoding;
a1a846a @gitster Merge branch 'ar/mksnpath'
gitster authored
254 char *defmsg = git_pathdup("MERGE_MSG");
6eb1b43 cherry-pick/revert: make direct internal call to merge_tree()
Miklos Vajna authored
255 struct merge_options o;
256 struct tree *result, *next_tree, *base_tree, *head_tree;
257 static struct lock_file index_lock;
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
258
ef90d6d @dscho Provide git_config with a callback-data parameter
dscho authored
259 git_config(git_default_config, NULL);
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
260 me = action == REVERT ? "revert" : "cherry-pick";
261 setenv(GIT_REFLOG_ACTION, me, 0);
f810379 @MadCoder Make builtin-revert.c use parse_options.
MadCoder authored
262 parse_args(argc, argv);
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
263
264 /* this is copied from the shell script, but it's never triggered... */
f810379 @MadCoder Make builtin-revert.c use parse_options.
MadCoder authored
265 if (action == REVERT && !no_replay)
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
266 die("revert is incompatible with replay");
267
6eb1b43 cherry-pick/revert: make direct internal call to merge_tree()
Miklos Vajna authored
268 if (read_cache() < 0)
269 die("git %s: failed to read the index", me);
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
270 if (no_commit) {
271 /*
272 * We do not intend to commit immediately. We just want to
71aa2b8 @gitster Resurrect git-revert.sh example and add comment to builtin-revert.c
gitster authored
273 * merge the differences in, so let's compute the tree
274 * that represents the "current" state for merge-recursive
275 * to work on.
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
276 */
45525bd @gitster Make error messages from cherry-pick/revert more sensible
gitster authored
277 if (write_cache_as_tree(head, 0, NULL))
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
278 die ("Your index file is unmerged.");
279 } else {
280 if (get_sha1("HEAD", head))
281 die ("You do not have a valid HEAD");
75f3ff2 @sbeyer Generalize and libify index_is_dirty() to index_differs_from(...)
sbeyer authored
282 if (index_differs_from("HEAD", 0))
d38a30d @moy Be more user-friendly when refusing to do something because of conflict.
moy authored
283 die_dirty_index(me);
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
284 }
6eb1b43 cherry-pick/revert: make direct internal call to merge_tree()
Miklos Vajna authored
285 discard_cache();
286
287 index_fd = hold_locked_index(&index_lock, 1);
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
288
f95ebf7 @dscho Allow cherry-picking root commits
dscho authored
289 if (!commit->parents) {
290 if (action == REVERT)
291 die ("Cannot revert a root commit");
292 parent = NULL;
293 }
294 else if (commit->parents->next) {
7791ecb @gitster revert/cherry-pick: work on merge commits as well
gitster authored
295 /* Reverting or cherry-picking a merge commit */
296 int cnt;
297 struct commit_list *p;
298
299 if (!mainline)
300 die("Commit %s is a merge but no -m option was given.",
301 sha1_to_hex(commit->object.sha1));
302
303 for (cnt = 1, p = commit->parents;
304 cnt != mainline && p;
305 cnt++)
306 p = p->next;
307 if (cnt != mainline || !p)
308 die("Commit %s does not have parent %d",
309 sha1_to_hex(commit->object.sha1), mainline);
310 parent = p->item;
311 } else if (0 < mainline)
312 die("Mainline was specified but commit %s is not a merge.",
313 sha1_to_hex(commit->object.sha1));
314 else
315 parent = commit->parents->item;
316
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
317 if (!(message = commit->buffer))
318 die ("Cannot get commit message for %s",
319 sha1_to_hex(commit->object.sha1));
320
6eb1b43 cherry-pick/revert: make direct internal call to merge_tree()
Miklos Vajna authored
321 if (parent && parse_commit(parent) < 0)
322 die("%s: cannot parse parent commit %s",
323 me, sha1_to_hex(parent->object.sha1));
324
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
325 /*
326 * "commit" is an existing commit. We would want to apply
327 * the difference it introduces since its first parent "prev"
328 * on top of the current HEAD if we are cherry-pick. Or the
329 * reverse of it if we are revert.
330 */
331
acd3b9e @gitster Enhance hold_lock_file_for_{update,append}() API
gitster authored
332 msg_fd = hold_lock_file_for_update(&msg_file, defmsg,
333 LOCK_DIE_ON_ERROR);
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
334
335 encoding = get_encoding(message);
336 if (!encoding)
330db18 Use 'UTF-8' rather than 'utf-8' everywhere for backward compatibility
Brandon Casey authored
337 encoding = "UTF-8";
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
338 if (!git_commit_encoding)
330db18 Use 'UTF-8' rather than 'utf-8' everywhere for backward compatibility
Brandon Casey authored
339 git_commit_encoding = "UTF-8";
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
340 if ((reencoded_message = reencode_string(message,
341 git_commit_encoding, encoding)))
342 message = reencoded_message;
343
344 oneline = get_oneline(message);
345
346 if (action == REVERT) {
e43b010 @dscho git-revert: Revert revert message to old behaviour
dscho authored
347 char *oneline_body = strchr(oneline, ' ');
348
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
349 base = commit;
7791ecb @gitster revert/cherry-pick: work on merge commits as well
gitster authored
350 next = parent;
e43b010 @dscho git-revert: Revert revert message to old behaviour
dscho authored
351 add_to_msg("Revert \"");
352 add_to_msg(oneline_body + 1);
353 add_to_msg("\"\n\nThis reverts commit ");
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
354 add_to_msg(sha1_to_hex(commit->object.sha1));
d5be89d git-revert: record the parent against which a revert was made
Robin Rosenberg authored
355
356 if (commit->parents->next) {
357 add_to_msg(", reversing\nchanges made to ");
358 add_to_msg(sha1_to_hex(parent->object.sha1));
359 }
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
360 add_to_msg(".\n");
361 } else {
7791ecb @gitster revert/cherry-pick: work on merge commits as well
gitster authored
362 base = parent;
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
363 next = commit;
364 set_author_ident_env(message);
365 add_message_to_msg(message);
f810379 @MadCoder Make builtin-revert.c use parse_options.
MadCoder authored
366 if (no_replay) {
0e62404 @spearce cherry-pick: Bug fix 'cherry picked from' message.
spearce authored
367 add_to_msg("(cherry picked from commit ");
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
368 add_to_msg(sha1_to_hex(commit->object.sha1));
369 add_to_msg(")\n");
370 }
371 }
372
6eb1b43 cherry-pick/revert: make direct internal call to merge_tree()
Miklos Vajna authored
373 read_cache();
374 init_merge_options(&o);
375 o.branch1 = "HEAD";
376 o.branch2 = oneline;
377
378 head_tree = parse_tree_indirect(head);
379 next_tree = next ? next->tree : empty_tree();
380 base_tree = base ? base->tree : empty_tree();
381
382 clean = merge_trees(&o,
383 head_tree,
384 next_tree, base_tree, &result);
385
386 if (active_cache_changed &&
387 (write_cache(index_fd, active_cache, active_nr) ||
388 commit_locked_index(&index_lock)))
389 die("%s: Unable to write new index file", me);
0d66e95 @ChrisJohnsen builtin-revert.c: release index lock when cherry-picking an empty commit
ChrisJohnsen authored
390 rollback_lock_file(&index_lock);
6eb1b43 cherry-pick/revert: make direct internal call to merge_tree()
Miklos Vajna authored
391
392 if (!clean) {
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
393 add_to_msg("\nConflicts:\n\n");
394 for (i = 0; i < active_nr;) {
395 struct cache_entry *ce = active_cache[i++];
396 if (ce_stage(ce)) {
397 add_to_msg("\t");
398 add_to_msg(ce->name);
399 add_to_msg("\n");
400 while (i < active_nr && !strcmp(ce->name,
401 active_cache[i]->name))
402 i++;
403 }
404 }
4ed7cd3 Improve use of lockfile API
Brandon Casey authored
405 if (commit_lock_file(&msg_file) < 0)
abda522 @spearce Use .git/MERGE_MSG in cherry-pick/revert
spearce authored
406 die ("Error wrapping up %s", defmsg);
804c717 @wincent revert/cherry-pick: Allow overriding the help text by the calling Por…
wincent authored
407 fprintf(stderr, "Automatic %s failed.%s\n",
9791554 @peff cherry-pick: show commit name instead of sha1
peff authored
408 me, help_msg(commit_name));
cb6020b @gitster Teach --[no-]rerere-autoupdate option to merge, revert and friends
gitster authored
409 rerere(allow_rerere_auto);
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
410 exit(1);
411 }
4ed7cd3 Improve use of lockfile API
Brandon Casey authored
412 if (commit_lock_file(&msg_file) < 0)
abda522 @spearce Use .git/MERGE_MSG in cherry-pick/revert
spearce authored
413 die ("Error wrapping up %s", defmsg);
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
414 fprintf(stderr, "Finished one %s.\n", me);
415
416 /*
417 *
418 * If we are cherry-pick, and if the merge did not result in
419 * hand-editing, we will hit this commit and inherit the original
420 * author date and name.
421 * If we are revert, or if our cherry-pick results in a hand merge,
422 * we had better say that the current user is responsible for that.
423 */
424
425 if (!no_commit) {
cfd9c27 @toofishes Allow cherry-pick (and revert) to add signoff line
toofishes authored
426 /* 6 is max possible length of our args array including NULL */
427 const char *args[6];
428 int i = 0;
429 args[i++] = "commit";
430 args[i++] = "-n";
431 if (signoff)
432 args[i++] = "-s";
433 if (!edit) {
434 args[i++] = "-F";
435 args[i++] = defmsg;
436 }
437 args[i] = NULL;
438 return execv_git_cmd(args);
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
439 }
8e0f700 Avoid unnecessary "if-before-free" tests.
Jim Meyering authored
440 free(reencoded_message);
d258b25 @raalkml Plug a memleak in builtin-revert
raalkml authored
441 free(defmsg);
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
442
443 return 0;
444 }
445
446 int cmd_revert(int argc, const char **argv, const char *prefix)
447 {
448 if (isatty(0))
449 edit = 1;
f810379 @MadCoder Make builtin-revert.c use parse_options.
MadCoder authored
450 no_replay = 1;
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
451 action = REVERT;
452 return revert_or_cherry_pick(argc, argv);
453 }
454
455 int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
456 {
f810379 @MadCoder Make builtin-revert.c use parse_options.
MadCoder authored
457 no_replay = 0;
9509af6 @dscho Make git-revert & git-cherry-pick a builtin
dscho authored
458 action = CHERRY_PICK;
459 return revert_or_cherry_pick(argc, argv);
460 }
Something went wrong with that request. Please try again.