Make git-checkout-index a builtin
Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Aug 4, 2006 at 01:23 UTC
e414156ab6e7869b29622ee3439e3c91361f5b0e
4 files changed
+18
-16
Makefile
+4
-2
@@ -173,7 +173,6 @@ SIMPLE_PROGRAMS = \
173
174
# ... and all the rest that could be moved out of bindir to gitexecdir
175
PROGRAMS = \
176
- git-checkout-index$X \
176
git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \
177
git-hash-object$X git-index-pack$X git-local-fetch$X \
178
git-merge-base$X \
@@ -187,7 +186,9 @@ PROGRAMS = \
186
git-pack-redundant$X git-var$X \
187
git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
188
190
-BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \
189
+BUILT_INS = \
190
+ git-checkout-index$X \
191
+ git-log$X git-whatchanged$X git-show$X git-update-ref$X \
192
git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
193
git-grep$X git-add$X git-rm$X git-rev-list$X git-stripspace$X \
194
git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
@@ -245,6 +246,7 @@ LIB_OBJS = \
246
alloc.o merge-file.o path-list.o $(DIFF_OBJS)
247
248
BUILTIN_OBJS = \
249
+ builtin-checkout-index.o \
250
builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \
251
builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \
252
builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
builtin-checkout-index.c
renamed
+12
-14
@@ -42,8 +42,6 @@
42
#include "cache-tree.h"
43
44
#define CHECKOUT_ALL 4
45
-static const char *prefix;
46
-static int prefix_length;
45
static int line_termination = '\n';
46
static int checkout_stage; /* default to checkout stage0 */
47
static int to_tempfile;
@@ -51,7 +49,7 @@ static char topath[4][MAXPATHLEN+1];
49
50
static struct checkout state;
51
54
-static void write_tempfile_record (const char *name)
52
+static void write_tempfile_record(const char *name, int prefix_length)
53
{
54
int i;
55
@@ -77,7 +75,7 @@ static void write_tempfile_record (const char *name)
75
}
76
}
77
80
-static int checkout_file(const char *name)
78
+static int checkout_file(const char *name, int prefix_length)
79
{
80
int namelen = strlen(name);
81
int pos = cache_name_pos(name, namelen);
@@ -106,7 +104,7 @@ static int checkout_file(const char *name)
104
105
if (did_checkout) {
106
if (to_tempfile)
109
- write_tempfile_record(name);
107
+ write_tempfile_record(name, prefix_length);
108
return errs > 0 ? -1 : 0;
109
}
110
@@ -124,7 +122,7 @@ static int checkout_file(const char *name)
122
return -1;
123
}
124
127
-static int checkout_all(void)
125
+static int checkout_all(const char *prefix, int prefix_length)
126
{
127
int i, errs = 0;
128
struct cache_entry* last_ce = NULL;
@@ -141,7 +139,7 @@ static int checkout_all(void)
139
if (last_ce && to_tempfile) {
140
if (ce_namelen(last_ce) != ce_namelen(ce)
141
|| memcmp(last_ce->name, ce->name, ce_namelen(ce)))
144
- write_tempfile_record(last_ce->name);
142
+ write_tempfile_record(last_ce->name, prefix_length);
143
}
144
if (checkout_entry(ce, &state,
145
to_tempfile ? topath[ce_stage(ce)] : NULL) < 0)
@@ -149,7 +147,7 @@ static int checkout_all(void)
147
last_ce = ce;
148
}
149
if (last_ce && to_tempfile)
152
- write_tempfile_record(last_ce->name);
150
+ write_tempfile_record(last_ce->name, prefix_length);
151
if (errs)
152
/* we have already done our error reporting.
153
* exit with the same code as die().
@@ -163,16 +161,16 @@ static const char checkout_cache_usage[] =
161
162
static struct lock_file lock_file;
163
166
-int main(int argc, char **argv)
164
+int cmd_checkout_index(int argc, const char **argv, const char *prefix)
165
{
166
int i;
167
int newfd = -1;
168
int all = 0;
169
int read_from_stdin = 0;
170
+ int prefix_length;
171
173
- state.base_dir = "";
174
- prefix = setup_git_directory();
172
git_config(git_default_config);
173
+ state.base_dir = "";
174
prefix_length = prefix ? strlen(prefix) : 0;
175
176
if (read_cache() < 0) {
@@ -270,7 +268,7 @@ int main(int argc, char **argv)
268
if (read_from_stdin)
269
die("git-checkout-index: don't mix '--stdin' and explicit filenames");
270
p = prefix_path(prefix, prefix_length, arg);
273
- checkout_file(p);
271
+ checkout_file(p, prefix_length);
272
if (p < arg || p > arg + strlen(arg))
273
free((char*)p);
274
}
@@ -292,7 +290,7 @@ int main(int argc, char **argv)
290
else
291
path_name = buf.buf;
292
p = prefix_path(prefix, prefix_length, path_name);
295
- checkout_file(p);
293
+ checkout_file(p, prefix_length);
294
if (p < path_name || p > path_name + strlen(path_name))
295
free((char *)p);
296
if (path_name != buf.buf)
@@ -301,7 +299,7 @@ int main(int argc, char **argv)
299
}
300
301
if (all)
304
- checkout_all();
302
+ checkout_all(prefix, prefix_length);
303
304
if (0 <= newfd &&
305
(write_cache(newfd, active_cache, active_nr) ||
builtin.h
+1
@@ -53,6 +53,7 @@ extern int cmd_name_rev(int argc, const char **argv, const char *prefix);
53
extern int cmd_pack_objects(int argc, const char **argv, const char *prefix);
54
extern int cmd_unpack_objects(int argc, const char **argv, const char *prefix);
55
extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);
56
+extern int cmd_checkout_index(int argc, const char **argv, const char *prefix);
57
58
extern int cmd_write_tree(int argc, const char **argv, const char *prefix);
59
extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
git.c
+1
@@ -269,6 +269,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
269
{ "pack-objects", cmd_pack_objects, NEEDS_PREFIX },
270
{ "unpack-objects", cmd_unpack_objects, NEEDS_PREFIX },
271
{ "symbolic-ref", cmd_symbolic_ref, NEEDS_PREFIX },
272
+ { "checkout-index", cmd_checkout_index, NEEDS_PREFIX },
273
};
274
int i;
275