blob: 84f1863d3ac3490bebbb746c61a2d695de09c848 [file] [log] [blame]
John Cai03eae9a2024-09-13 21:16:15 +00001#define USE_THE_REPOSITORY_VARIABLE
Peter Eriksenac6245e2006-05-23 14:15:34 +02002#include "builtin.h"
Elijah Newrenf394e092023-03-21 06:25:54 +00003#include "gettext.h"
Junio C Hamano4674ab62024-05-20 16:14:34 -07004#include "hash.h"
Christian Couder71501a72016-08-08 23:02:59 +02005#include "apply.h"
Christian Couder2fc0f182016-05-11 15:16:19 +02006
Miklos Vajnaf26c4942008-12-28 00:03:57 +01007static const char * const apply_usage[] = {
Alex Henrie9c9b4f22015-01-13 00:44:47 -07008 N_("git apply [<options>] [<patch>...]"),
Miklos Vajnaf26c4942008-12-28 00:03:57 +01009 NULL
10};
Linus Torvaldsc1bb9352005-05-23 10:52:17 -070011
John Cai9b1cb502024-09-13 21:16:14 +000012int cmd_apply(int argc,
13 const char **argv,
14 const char *prefix,
15 struct repository *repo UNUSED)
Christian Couder91b769c2016-05-24 10:11:24 +020016{
Miklos Vajnaf26c4942008-12-28 00:03:57 +010017 int force_apply = 0;
Christian Couderd1b27ce2016-05-11 15:16:17 +020018 int options = 0;
Christian Couder91b769c2016-05-24 10:11:24 +020019 int ret;
Christian Couder2fc0f182016-05-11 15:16:19 +020020 struct apply_state state;
Johannes Schindelin3eaa38d2006-06-24 22:10:11 +020021
Nguyễn Thái Ngọc Duy82ea77e2018-08-13 18:14:39 +020022 if (init_apply_state(&state, the_repository, prefix))
Christian Couder2f5a6d12016-08-08 23:03:08 +020023 exit(128);
Junio C Hamano67160272007-02-17 12:37:25 -080024
Junio C Hamano4674ab62024-05-20 16:14:34 -070025 /*
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 Couder7e1bad22016-09-04 22:18:30 +020034 argc = apply_parse_options(argc, argv,
35 &state, &force_apply, &options,
36 apply_usage);
Stephen Boyd4c8d4c12009-05-23 11:53:11 -070037
Christian Couderf36538d2016-08-08 23:03:09 +020038 if (check_apply_state(&state, force_apply))
39 exit(128);
Junio C Hamanoc536c072015-01-29 15:35:24 -080040
Christian Couder91b769c2016-05-24 10:11:24 +020041 ret = apply_all_patches(&state, argc, argv, options);
Eric Wongdbd0f7d2006-05-09 01:08:23 -070042
Christian Couder6f27b942016-05-24 10:10:46 +020043 clear_apply_state(&state);
44
Christian Couder91b769c2016-05-24 10:11:24 +020045 return ret;
Linus Torvaldsc1bb9352005-05-23 10:52:17 -070046}