John Cai | 03eae9a | 2024-09-13 21:16:15 +0000 | [diff] [blame] | 1 | #define USE_THE_REPOSITORY_VARIABLE |
Peter Eriksen | ac6245e | 2006-05-23 14:15:34 +0200 | [diff] [blame] | 2 | #include "builtin.h" |
Elijah Newren | f394e09 | 2023-03-21 06:25:54 +0000 | [diff] [blame] | 3 | #include "gettext.h" |
Junio C Hamano | 4674ab6 | 2024-05-20 16:14:34 -0700 | [diff] [blame] | 4 | #include "hash.h" |
Christian Couder | 71501a7 | 2016-08-08 23:02:59 +0200 | [diff] [blame] | 5 | #include "apply.h" |
Christian Couder | 2fc0f18 | 2016-05-11 15:16:19 +0200 | [diff] [blame] | 6 | |
Miklos Vajna | f26c494 | 2008-12-28 00:03:57 +0100 | [diff] [blame] | 7 | static const char * const apply_usage[] = { |
Alex Henrie | 9c9b4f2 | 2015-01-13 00:44:47 -0700 | [diff] [blame] | 8 | N_("git apply [<options>] [<patch>...]"), |
Miklos Vajna | f26c494 | 2008-12-28 00:03:57 +0100 | [diff] [blame] | 9 | NULL |
| 10 | }; |
Linus Torvalds | c1bb935 | 2005-05-23 10:52:17 -0700 | [diff] [blame] | 11 | |
John Cai | 9b1cb50 | 2024-09-13 21:16:14 +0000 | [diff] [blame] | 12 | int cmd_apply(int argc, |
| 13 | const char **argv, |
| 14 | const char *prefix, |
| 15 | struct repository *repo UNUSED) |
Christian Couder | 91b769c | 2016-05-24 10:11:24 +0200 | [diff] [blame] | 16 | { |
Miklos Vajna | f26c494 | 2008-12-28 00:03:57 +0100 | [diff] [blame] | 17 | int force_apply = 0; |
Christian Couder | d1b27ce | 2016-05-11 15:16:17 +0200 | [diff] [blame] | 18 | int options = 0; |
Christian Couder | 91b769c | 2016-05-24 10:11:24 +0200 | [diff] [blame] | 19 | int ret; |
Christian Couder | 2fc0f18 | 2016-05-11 15:16:19 +0200 | [diff] [blame] | 20 | struct apply_state state; |
Johannes Schindelin | 3eaa38d | 2006-06-24 22:10:11 +0200 | [diff] [blame] | 21 | |
Nguyễn Thái Ngọc Duy | 82ea77e | 2018-08-13 18:14:39 +0200 | [diff] [blame] | 22 | if (init_apply_state(&state, the_repository, prefix)) |
Christian Couder | 2f5a6d1 | 2016-08-08 23:03:08 +0200 | [diff] [blame] | 23 | exit(128); |
Junio C Hamano | 6716027 | 2007-02-17 12:37:25 -0800 | [diff] [blame] | 24 | |
Junio C Hamano | 4674ab6 | 2024-05-20 16:14:34 -0700 | [diff] [blame] | 25 | /* |
| 26 | * We could to redo the "apply.c" machinery to make this |
| 27 | * arbitrary fallback unnecessary, but it is dubious that it |
| 28 | * is worth the effort. |
| 29 | * cf. https://lore.kernel.org/git/xmqqcypfcmn4.fsf@gitster.g/ |
| 30 | */ |
| 31 | if (!the_hash_algo) |
| 32 | repo_set_hash_algo(the_repository, GIT_HASH_SHA1); |
| 33 | |
Christian Couder | 7e1bad2 | 2016-09-04 22:18:30 +0200 | [diff] [blame] | 34 | argc = apply_parse_options(argc, argv, |
| 35 | &state, &force_apply, &options, |
| 36 | apply_usage); |
Stephen Boyd | 4c8d4c1 | 2009-05-23 11:53:11 -0700 | [diff] [blame] | 37 | |
Christian Couder | f36538d | 2016-08-08 23:03:09 +0200 | [diff] [blame] | 38 | if (check_apply_state(&state, force_apply)) |
| 39 | exit(128); |
Junio C Hamano | c536c07 | 2015-01-29 15:35:24 -0800 | [diff] [blame] | 40 | |
Christian Couder | 91b769c | 2016-05-24 10:11:24 +0200 | [diff] [blame] | 41 | ret = apply_all_patches(&state, argc, argv, options); |
Eric Wong | dbd0f7d | 2006-05-09 01:08:23 -0700 | [diff] [blame] | 42 | |
Christian Couder | 6f27b94 | 2016-05-24 10:10:46 +0200 | [diff] [blame] | 43 | clear_apply_state(&state); |
| 44 | |
Christian Couder | 91b769c | 2016-05-24 10:11:24 +0200 | [diff] [blame] | 45 | return ret; |
Linus Torvalds | c1bb935 | 2005-05-23 10:52:17 -0700 | [diff] [blame] | 46 | } |