pull: implement skeletal builtin pull
authorPaul Tan <pyokagan@gmail.com>
Sun, 14 Jun 2015 08:41:51 +0000 (16:41 +0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Jun 2015 19:40:50 +0000 (12:40 -0700)
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>
Makefile
builtin.h
builtin/pull.c [new file with mode: 0644]
git.c
index 54ec511dffb0a7b6775f360fc10deaa2008fdee9..2057a9d4647e3b61a2dab0ff36381e511cef382f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -877,6 +877,7 @@ BUILTIN_OBJS += builtin/pack-refs.o
 BUILTIN_OBJS += builtin/patch-id.o
 BUILTIN_OBJS += builtin/prune-packed.o
 BUILTIN_OBJS += builtin/prune.o
+BUILTIN_OBJS += builtin/pull.o
 BUILTIN_OBJS += builtin/push.o
 BUILTIN_OBJS += builtin/read-tree.o
 BUILTIN_OBJS += builtin/receive-pack.o
index b87df70f96d0f43e4b838f34d7492d116d4d97db..ea3c834f3099cec7809f0e20ef456bce8625513c 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -98,6 +98,7 @@ extern int cmd_pack_redundant(int argc, const char **argv, const char *prefix);
 extern int cmd_patch_id(int argc, const char **argv, const char *prefix);
 extern int cmd_prune(int argc, const char **argv, const char *prefix);
 extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
+extern int cmd_pull(int argc, const char **argv, const char *prefix);
 extern int cmd_push(int argc, const char **argv, const char *prefix);
 extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
 extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);
diff --git a/builtin/pull.c b/builtin/pull.c
new file mode 100644 (file)
index 0000000..cabeed4
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Builtin "git pull"
+ *
+ * Based on git-pull.sh by Junio C Hamano
+ *
+ * Fetch one or more remote refs and merge it/them into the current HEAD.
+ */
+#include "cache.h"
+#include "builtin.h"
+#include "parse-options.h"
+#include "exec_cmd.h"
+
+static const char * const pull_usage[] = {
+       NULL
+};
+
+static struct option pull_options[] = {
+       OPT_END()
+};
+
+int cmd_pull(int argc, const char **argv, const char *prefix)
+{
+       if (!getenv("_GIT_USE_BUILTIN_PULL")) {
+               const char *path = mkpath("%s/git-pull", git_exec_path());
+
+               if (sane_execvp(path, (char **)argv) < 0)
+                       die_errno("could not exec %s", path);
+       }
+
+       argc = parse_options(argc, argv, prefix, pull_options, pull_usage, 0);
+
+       return 0;
+}
diff --git a/git.c b/git.c
index 44374b1d9b6b73b3669f0f851bee058f45ee4f32..e7a77136d6d805367cb900da5c8f2eb71da84f1c 100644 (file)
--- a/git.c
+++ b/git.c
@@ -445,6 +445,7 @@ static struct cmd_struct commands[] = {
        { "pickaxe", cmd_blame, RUN_SETUP },
        { "prune", cmd_prune, RUN_SETUP },
        { "prune-packed", cmd_prune_packed, RUN_SETUP },
+       { "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE },
        { "push", cmd_push, RUN_SETUP },
        { "read-tree", cmd_read_tree, RUN_SETUP },
        { "receive-pack", cmd_receive_pack },