Code

make "git unpack-file" a built-in
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 22 Jan 2010 15:38:03 +0000 (07:38 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 22 Jan 2010 18:02:16 +0000 (10:02 -0800)
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile
builtin-unpack-file.c [new file with mode: 0644]
builtin.h
git.c
unpack-file.c [deleted file]

index c5a1190ebe035b26e60566c8fd1b849b41a9bffd..88e2f8fd494d1feea1e36ec85f7de2968e57e294 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -392,7 +392,6 @@ PROGRAMS += git-index-pack$X
 PROGRAMS += git-pack-redundant$X
 PROGRAMS += git-shell$X
 PROGRAMS += git-show-index$X
-PROGRAMS += git-unpack-file$X
 PROGRAMS += git-upload-pack$X
 PROGRAMS += git-http-backend$X
 
@@ -698,6 +697,7 @@ BUILTIN_OBJS += builtin-stripspace.o
 BUILTIN_OBJS += builtin-symbolic-ref.o
 BUILTIN_OBJS += builtin-tag.o
 BUILTIN_OBJS += builtin-tar-tree.o
+BUILTIN_OBJS += builtin-unpack-file.o
 BUILTIN_OBJS += builtin-unpack-objects.o
 BUILTIN_OBJS += builtin-update-index.o
 BUILTIN_OBJS += builtin-update-ref.o
diff --git a/builtin-unpack-file.c b/builtin-unpack-file.c
new file mode 100644 (file)
index 0000000..608590a
--- /dev/null
@@ -0,0 +1,38 @@
+#include "cache.h"
+#include "blob.h"
+#include "exec_cmd.h"
+
+static char *create_temp_file(unsigned char *sha1)
+{
+       static char path[50];
+       void *buf;
+       enum object_type type;
+       unsigned long size;
+       int fd;
+
+       buf = read_sha1_file(sha1, &type, &size);
+       if (!buf || type != OBJ_BLOB)
+               die("unable to read blob object %s", sha1_to_hex(sha1));
+
+       strcpy(path, ".merge_file_XXXXXX");
+       fd = xmkstemp(path);
+       if (write_in_full(fd, buf, size) != size)
+               die_errno("unable to write temp-file");
+       close(fd);
+       return path;
+}
+
+int cmd_unpack_file(int argc, const char **argv, const char *prefix)
+{
+       unsigned char sha1[20];
+
+       if (argc != 2 || !strcmp(argv[1], "-h"))
+               usage("git unpack-file <sha1>");
+       if (get_sha1(argv[1], sha1))
+               die("Not a valid object name %s", argv[1]);
+
+       git_config(git_default_config, NULL);
+
+       puts(create_temp_file(sha1));
+       return 0;
+}
index 2aaef74e022d368ebf3a163b74fc9d6f568e97b9..d4fec89a15d9373746ce6a833ed27cfdb7d32656 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -103,6 +103,7 @@ extern int cmd_stripspace(int argc, const char **argv, const char *prefix);
 extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);
 extern int cmd_tag(int argc, const char **argv, const char *prefix);
 extern int cmd_tar_tree(int argc, const char **argv, const char *prefix);
+extern int cmd_unpack_file(int argc, const char **argv, const char *prefix);
 extern int cmd_unpack_objects(int argc, const char **argv, const char *prefix);
 extern int cmd_update_index(int argc, const char **argv, const char *prefix);
 extern int cmd_update_ref(int argc, const char **argv, const char *prefix);
diff --git a/git.c b/git.c
index 0b8f8a731e7a80a3bb1d7773efc314dce06d4a8a..832bd2d535eab1a73700a2c17114ee5c34fd1aeb 100644 (file)
--- a/git.c
+++ b/git.c
@@ -370,6 +370,7 @@ static void handle_internal_command(int argc, const char **argv)
                { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
                { "tag", cmd_tag, RUN_SETUP },
                { "tar-tree", cmd_tar_tree },
+               { "unpack-file", cmd_unpack_file, RUN_SETUP },
                { "unpack-objects", cmd_unpack_objects, RUN_SETUP },
                { "update-index", cmd_update_index, RUN_SETUP },
                { "update-ref", cmd_update_ref, RUN_SETUP },
diff --git a/unpack-file.c b/unpack-file.c
deleted file mode 100644 (file)
index e9d8934..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-#include "cache.h"
-#include "blob.h"
-#include "exec_cmd.h"
-
-static char *create_temp_file(unsigned char *sha1)
-{
-       static char path[50];
-       void *buf;
-       enum object_type type;
-       unsigned long size;
-       int fd;
-
-       buf = read_sha1_file(sha1, &type, &size);
-       if (!buf || type != OBJ_BLOB)
-               die("unable to read blob object %s", sha1_to_hex(sha1));
-
-       strcpy(path, ".merge_file_XXXXXX");
-       fd = xmkstemp(path);
-       if (write_in_full(fd, buf, size) != size)
-               die_errno("unable to write temp-file");
-       close(fd);
-       return path;
-}
-
-int main(int argc, char **argv)
-{
-       unsigned char sha1[20];
-
-       git_extract_argv0_path(argv[0]);
-
-       if (argc != 2 || !strcmp(argv[1], "-h"))
-               usage("git unpack-file <sha1>");
-       if (get_sha1(argv[1], sha1))
-               die("Not a valid object name %s", argv[1]);
-
-       setup_git_directory();
-       git_config(git_default_config, NULL);
-
-       puts(create_temp_file(sha1));
-       return 0;
-}