Make git-checkout-index a builtin
authorJunio C Hamano <junkio@cox.net>
Fri, 4 Aug 2006 08:23:19 +0000 (01:23 -0700)
committerJunio C Hamano <junkio@cox.net>
Fri, 4 Aug 2006 08:23:19 +0000 (01:23 -0700)
Signed-off-by: Junio C Hamano <junkio@cox.net>
Makefile
builtin-checkout-index.c [moved from checkout-index.c with 92% similarity]
builtin.h
git.c

index db59e00ede5728a666f165bf767dd017d3d7469d..1a3605b1236d6bf90436655ec60299ca59c48565 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -173,7 +173,6 @@ SIMPLE_PROGRAMS = \
 
 # ... and all the rest that could be moved out of bindir to gitexecdir
 PROGRAMS = \
-       git-checkout-index$X \
        git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \
        git-hash-object$X git-index-pack$X git-local-fetch$X \
        git-merge-base$X \
@@ -187,7 +186,9 @@ PROGRAMS = \
        git-pack-redundant$X git-var$X \
        git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
 
-BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \
+BUILT_INS = \
+       git-checkout-index$X \
+       git-log$X git-whatchanged$X git-show$X git-update-ref$X \
        git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
        git-grep$X git-add$X git-rm$X git-rev-list$X git-stripspace$X \
        git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
@@ -245,6 +246,7 @@ LIB_OBJS = \
        alloc.o merge-file.o path-list.o $(DIFF_OBJS)
 
 BUILTIN_OBJS = \
+       builtin-checkout-index.o \
        builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \
        builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \
        builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
similarity index 92%
rename from checkout-index.c
rename to builtin-checkout-index.c
index 61152f34b7fc00e745a2f7524c4da5b5a1a780a2..29ea6fdc6232c1071d88524fa5c11d5ba1882dee 100644 (file)
@@ -42,8 +42,6 @@
 #include "cache-tree.h"
 
 #define CHECKOUT_ALL 4
-static const char *prefix;
-static int prefix_length;
 static int line_termination = '\n';
 static int checkout_stage; /* default to checkout stage0 */
 static int to_tempfile;
@@ -51,7 +49,7 @@ static char topath[4][MAXPATHLEN+1];
 
 static struct checkout state;
 
-static void write_tempfile_record (const char *name)
+static void write_tempfile_record(const char *name, int prefix_length)
 {
        int i;
 
@@ -77,7 +75,7 @@ static void write_tempfile_record (const char *name)
        }
 }
 
-static int checkout_file(const char *name)
+static int checkout_file(const char *name, int prefix_length)
 {
        int namelen = strlen(name);
        int pos = cache_name_pos(name, namelen);
@@ -106,7 +104,7 @@ static int checkout_file(const char *name)
 
        if (did_checkout) {
                if (to_tempfile)
-                       write_tempfile_record(name);
+                       write_tempfile_record(name, prefix_length);
                return errs > 0 ? -1 : 0;
        }
 
@@ -124,7 +122,7 @@ static int checkout_file(const char *name)
        return -1;
 }
 
-static int checkout_all(void)
+static int checkout_all(const char *prefix, int prefix_length)
 {
        int i, errs = 0;
        struct cache_entry* last_ce = NULL;
@@ -141,7 +139,7 @@ static int checkout_all(void)
                if (last_ce && to_tempfile) {
                        if (ce_namelen(last_ce) != ce_namelen(ce)
                            || memcmp(last_ce->name, ce->name, ce_namelen(ce)))
-                               write_tempfile_record(last_ce->name);
+                               write_tempfile_record(last_ce->name, prefix_length);
                }
                if (checkout_entry(ce, &state,
                    to_tempfile ? topath[ce_stage(ce)] : NULL) < 0)
@@ -149,7 +147,7 @@ static int checkout_all(void)
                last_ce = ce;
        }
        if (last_ce && to_tempfile)
-               write_tempfile_record(last_ce->name);
+               write_tempfile_record(last_ce->name, prefix_length);
        if (errs)
                /* we have already done our error reporting.
                 * exit with the same code as die().
@@ -163,16 +161,16 @@ static const char checkout_cache_usage[] =
 
 static struct lock_file lock_file;
 
-int main(int argc, char **argv)
+int cmd_checkout_index(int argc, const char **argv, const char *prefix)
 {
        int i;
        int newfd = -1;
        int all = 0;
        int read_from_stdin = 0;
+       int prefix_length;
 
-       state.base_dir = "";
-       prefix = setup_git_directory();
        git_config(git_default_config);
+       state.base_dir = "";
        prefix_length = prefix ? strlen(prefix) : 0;
 
        if (read_cache() < 0) {
@@ -270,7 +268,7 @@ int main(int argc, char **argv)
                if (read_from_stdin)
                        die("git-checkout-index: don't mix '--stdin' and explicit filenames");
                p = prefix_path(prefix, prefix_length, arg);
-               checkout_file(p);
+               checkout_file(p, prefix_length);
                if (p < arg || p > arg + strlen(arg))
                        free((char*)p);
        }
@@ -292,7 +290,7 @@ int main(int argc, char **argv)
                        else
                                path_name = buf.buf;
                        p = prefix_path(prefix, prefix_length, path_name);
-                       checkout_file(p);
+                       checkout_file(p, prefix_length);
                        if (p < path_name || p > path_name + strlen(path_name))
                                free((char *)p);
                        if (path_name != buf.buf)
@@ -301,7 +299,7 @@ int main(int argc, char **argv)
        }
 
        if (all)
-               checkout_all();
+               checkout_all(prefix, prefix_length);
 
        if (0 <= newfd &&
            (write_cache(newfd, active_cache, active_nr) ||
index b767245c7559b31d46936343dd02651fa86fdbea..3a24637b11d11b1014b5ea3b6927d47e9c0b50fe 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -53,6 +53,7 @@ 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);
 extern int cmd_unpack_objects(int argc, const char **argv, const char *prefix);
 extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);
+extern int cmd_checkout_index(int argc, const char **argv, const char *prefix);
 
 extern int cmd_write_tree(int argc, const char **argv, const char *prefix);
 extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
diff --git a/git.c b/git.c
index e40e85935ca084d784905f3565a2a7555e11e064..07b6d3e9ddb63c09781677c89e1d2d5e837ce0f7 100644 (file)
--- a/git.c
+++ b/git.c
@@ -269,6 +269,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
                { "pack-objects", cmd_pack_objects, NEEDS_PREFIX },
                { "unpack-objects", cmd_unpack_objects, NEEDS_PREFIX },
                { "symbolic-ref", cmd_symbolic_ref, NEEDS_PREFIX },
+               { "checkout-index", cmd_checkout_index, NEEDS_PREFIX },
        };
        int i;