build-in git-mktree
authorJunio C Hamano <gitster@pobox.com>
Sun, 10 May 2009 17:28:18 +0000 (10:28 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 10 May 2009 19:41:35 +0000 (12:41 -0700)
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile
builtin-mktree.c [moved from mktree.c with 91% similarity]
builtin.h
git.c

index 6e216436c36f4dcbe1121d02a291e9f568ca6071..9d9f0dac27cd1ad06e3c65f43d572ff69b1417ba 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -332,7 +332,6 @@ PROGRAMS += git-index-pack$X
 PROGRAMS += git-merge-index$X
 PROGRAMS += git-merge-tree$X
 PROGRAMS += git-mktag$X
-PROGRAMS += git-mktree$X
 PROGRAMS += git-pack-redundant$X
 PROGRAMS += git-patch-id$X
 PROGRAMS += git-shell$X
@@ -586,6 +585,7 @@ BUILTIN_OBJS += builtin-merge-base.o
 BUILTIN_OBJS += builtin-merge-file.o
 BUILTIN_OBJS += builtin-merge-ours.o
 BUILTIN_OBJS += builtin-merge-recursive.o
+BUILTIN_OBJS += builtin-mktree.o
 BUILTIN_OBJS += builtin-mv.o
 BUILTIN_OBJS += builtin-name-rev.o
 BUILTIN_OBJS += builtin-pack-objects.o
similarity index 91%
rename from mktree.c
rename to builtin-mktree.c
index 137a0950f686691740ac87330cf0ac7bdea8b1e7..3d054272d5f34e310fa619f183e46ee3a91ede75 100644 (file)
--- a/mktree.c
@@ -1,12 +1,11 @@
 /*
  * GIT - the stupid content tracker
  *
- * Copyright (c) Junio C Hamano, 2006
+ * Copyright (c) Junio C Hamano, 2006, 2009
  */
-#include "cache.h"
+#include "builtin.h"
 #include "quote.h"
 #include "tree.h"
-#include "exec_cmd.h"
 
 static struct treeent {
        unsigned mode;
@@ -64,19 +63,15 @@ static void write_tree(unsigned char *sha1)
 
 static const char mktree_usage[] = "git mktree [-z]";
 
-int main(int ac, char **av)
+int cmd_mktree(int ac, const char **av, const char *prefix)
 {
        struct strbuf sb = STRBUF_INIT;
        struct strbuf p_uq = STRBUF_INIT;
        unsigned char sha1[20];
        int line_termination = '\n';
 
-       git_extract_argv0_path(av[0]);
-
-       setup_git_directory();
-
        while ((1 < ac) && av[1][0] == '-') {
-               char *arg = av[1];
+               const char *arg = av[1];
                if (!strcmp("-z", arg))
                        line_termination = 0;
                else
@@ -92,8 +87,9 @@ int main(int ac, char **av)
                char *path;
 
                ptr = sb.buf;
-               /* Input is non-recursive ls-tree output format
-                * mode SP type SP sha1 TAB name
+               /*
+                * Read non-recursive ls-tree output format:
+                *     mode SP type SP sha1 TAB name
                 */
                mode = strtoul(ptr, &ntr, 8);
                if (ptr == ntr || !ntr || *ntr != ' ')
index 425ff8e89b361c34b3336cda58794682c66b57f3..20427d2963fa25c1177bd05ab9f8be2890b9f7ba 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -72,6 +72,7 @@ extern int cmd_merge_base(int argc, const char **argv, const char *prefix);
 extern int cmd_merge_ours(int argc, const char **argv, const char *prefix);
 extern int cmd_merge_file(int argc, const char **argv, const char *prefix);
 extern int cmd_merge_recursive(int argc, const char **argv, const char *prefix);
+extern int cmd_mktree(int argc, const char **argv, const char *prefix);
 extern int cmd_mv(int argc, const char **argv, const char *prefix);
 extern int cmd_name_rev(int argc, const char **argv, const char *prefix);
 extern int cmd_pack_objects(int argc, const char **argv, const char *prefix);
diff --git a/git.c b/git.c
index 5a00726d09a13d5f70ab0378e02bbbd299124d5c..7d7f949f0da85ea124f67ead6f68fdd0ddc75d20 100644 (file)
--- a/git.c
+++ b/git.c
@@ -327,6 +327,7 @@ static void handle_internal_command(int argc, const char **argv)
                { "merge-ours", cmd_merge_ours, RUN_SETUP },
                { "merge-recursive", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },
                { "merge-subtree", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },
+               { "mktree", cmd_mktree, RUN_SETUP },
                { "mv", cmd_mv, RUN_SETUP | NEED_WORK_TREE },
                { "name-rev", cmd_name_rev, RUN_SETUP },
                { "pack-objects", cmd_pack_objects, RUN_SETUP },