pull: implement skeletal builtin pull

For the purpose of rewriting git-pull.sh into a C builtin, implement a skeletal builtin/pull.c that redirects to $GIT_EXEC_PATH/git-pull.sh if the environment variable _GIT_USE_BUILTIN_PULL is not defined. This allows us to fall back on the functional git-pull.sh when running the test suite for tests that depend on a working git-pull implementation. This redirection should be removed when all the features of git-pull.sh have been re-implemented in builtin/pull.c. Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Paul Tan committed Jun 14, 2015 at 16:41 UTC 1e1ea69fa4e5fb20baefe9e5422527e971d56a86
4 files changed +36
Makefile
+1
@@ -877,6 +877,7 @@ BUILTIN_OBJS += builtin/pack-refs.o
877 BUILTIN_OBJS += builtin/patch-id.o
878 BUILTIN_OBJS += builtin/prune-packed.o
879 BUILTIN_OBJS += builtin/prune.o
880 +BUILTIN_OBJS += builtin/pull.o
881 BUILTIN_OBJS += builtin/push.o
882 BUILTIN_OBJS += builtin/read-tree.o
883 BUILTIN_OBJS += builtin/receive-pack.o
builtin.h
+1
@@ -98,6 +98,7 @@ extern int cmd_pack_redundant(int argc, const char **argv, const char *prefix);
98 extern int cmd_patch_id(int argc, const char **argv, const char *prefix);
99 extern int cmd_prune(int argc, const char **argv, const char *prefix);
100 extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
101 +extern int cmd_pull(int argc, const char **argv, const char *prefix);
102 extern int cmd_push(int argc, const char **argv, const char *prefix);
103 extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
104 extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);
builtin/pull.c new
+33
@@ -0,0 +1,33 @@
1 +/*
2 + * Builtin "git pull"
3 + *
4 + * Based on git-pull.sh by Junio C Hamano
5 + *
6 + * Fetch one or more remote refs and merge it/them into the current HEAD.
7 + */
8 +#include "cache.h"
9 +#include "builtin.h"
10 +#include "parse-options.h"
11 +#include "exec_cmd.h"
12 +
13 +static const char * const pull_usage[] = {
14 + NULL
15 +};
16 +
17 +static struct option pull_options[] = {
18 + OPT_END()
19 +};
20 +
21 +int cmd_pull(int argc, const char **argv, const char *prefix)
22 +{
23 + if (!getenv("_GIT_USE_BUILTIN_PULL")) {
24 + const char *path = mkpath("%s/git-pull", git_exec_path());
25 +
26 + if (sane_execvp(path, (char **)argv) < 0)
27 + die_errno("could not exec %s", path);
28 + }
29 +
30 + argc = parse_options(argc, argv, prefix, pull_options, pull_usage, 0);
31 +
32 + return 0;
33 +}
git.c
+1
@@ -445,6 +445,7 @@ static struct cmd_struct commands[] = {
445 { "pickaxe", cmd_blame, RUN_SETUP },
446 { "prune", cmd_prune, RUN_SETUP },
447 { "prune-packed", cmd_prune_packed, RUN_SETUP },
448 + { "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
449 { "push", cmd_push, RUN_SETUP },
450 { "read-tree", cmd_read_tree, RUN_SETUP },
451 { "receive-pack", cmd_receive_pack },