Make git-update-index a builtin
Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se> Signed-off-by: Junio C Hamano <junkio@cox.net>
Lukas Sandström committed
Jun 13, 2006 at 22:21 UTC
fefe81c9964a12394d6ea81ce474ff402f0eb070
4 files changed
+18
-11
Makefile
+3
-3
@@ -157,7 +157,7 @@ PROGRAMS = \
157
git-send-pack$X git-shell$X \
158
git-show-index$X git-ssh-fetch$X \
159
git-ssh-upload$X git-unpack-file$X \
160
- git-unpack-objects$X git-update-index$X git-update-server-info$X \
160
+ git-unpack-objects$X git-update-server-info$X \
161
git-upload-pack$X git-verify-pack$X \
162
git-update-ref$X git-symbolic-ref$X \
163
git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \
@@ -170,7 +170,7 @@ BUILT_INS = git-log$X git-whatchanged$X git-show$X \
170
git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
171
git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
172
git-read-tree$X git-commit-tree$X git-write-tree$X \
173
- git-apply$X git-show-branch$X git-diff-files$X \
173
+ git-apply$X git-show-branch$X git-diff-files$X git-update-index$X \
174
git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X
175
176
# what 'all' will build and 'install' will install, in gitexecdir
@@ -221,7 +221,7 @@ BUILTIN_OBJS = \
221
builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \
222
builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \
223
builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
224
- builtin-tar-tree.o builtin-upload-tar.o \
224
+ builtin-tar-tree.o builtin-upload-tar.o builtin-update-index.o \
225
builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
226
builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
227
builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
builtin-update-index.c
renamed
+12
-7
@@ -8,6 +8,7 @@
8
#include "quote.h"
9
#include "cache-tree.h"
10
#include "tree-walk.h"
11
+#include "builtin.h"
12
13
/*
14
* Default to not allowing changes to the list of files. The
@@ -186,8 +187,6 @@ static void chmod_path(int flip, const char *path)
187
die("git-update-index: cannot chmod %cx '%s'", flip, path);
188
}
189
189
-static struct lock_file lock_file;
190
-
190
static void update_one(const char *path, const char *prefix, int prefix_length)
191
{
192
const char *p = prefix_path(prefix, prefix_length, path);
@@ -238,7 +237,7 @@ static void read_index_info(int line_termination)
237
* (2) mode SP type SP sha1 TAB path
238
* The second format is to stuff git-ls-tree output
239
* into the index file.
241
- *
240
+ *
241
* (3) mode SP sha1 SP stage TAB path
242
* This format is to put higher order stages into the
243
* index file and matches git-ls-files --stage output.
@@ -477,7 +476,7 @@ static int do_reupdate(int ac, const char **av,
476
return 0;
477
}
478
480
-int main(int argc, const char **argv)
479
+int cmd_update_index(int argc, const char **argv, char **envp)
480
{
481
int i, newfd, entries, has_errors = 0, line_termination = '\n';
482
int allow_options = 1;
@@ -486,12 +485,16 @@ int main(int argc, const char **argv)
485
int prefix_length = prefix ? strlen(prefix) : 0;
486
char set_executable_bit = 0;
487
unsigned int refresh_flags = 0;
488
+ struct lock_file *lock_file;
489
490
git_config(git_default_config);
491
492
- newfd = hold_lock_file_for_update(&lock_file, get_index_file());
492
+ /* We can't free this memory, it becomes part of a linked list parsed atexit() */
493
+ lock_file = xmalloc(sizeof(struct lock_file));
494
+
495
+ newfd = hold_lock_file_for_update(lock_file, get_index_file());
496
if (newfd < 0)
494
- die("unable to create new index file");
497
+ die("unable to create new cachefile");
498
499
entries = read_cache();
500
if (entries < 0)
@@ -645,9 +648,11 @@ int main(int argc, const char **argv)
648
finish:
649
if (active_cache_changed) {
650
if (write_cache(newfd, active_cache, active_nr) ||
648
- commit_lock_file(&lock_file))
651
+ commit_lock_file(lock_file))
652
die("Unable to write new index file");
653
}
654
655
+ rollback_lock_file(lock_file);
656
+
657
return has_errors ? 1 : 0;
658
}
builtin.h
+1
@@ -47,6 +47,7 @@ extern int cmd_diff_stages(int argc, const char **argv, char **envp);
47
extern int cmd_diff_tree(int argc, const char **argv, char **envp);
48
extern int cmd_cat_file(int argc, const char **argv, char **envp);
49
extern int cmd_rev_parse(int argc, const char **argv, char **envp);
50
+extern int cmd_update_index(int argc, const char **argv, char **envp);
51
52
extern int cmd_write_tree(int argc, const char **argv, char **envp);
53
extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
git.c
+2
-1
@@ -182,7 +182,8 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
182
{ "write-tree", cmd_write_tree },
183
{ "mailsplit", cmd_mailsplit },
184
{ "mailinfo", cmd_mailinfo },
185
- { "stripspace", cmd_stripspace }
185
+ { "stripspace", cmd_stripspace },
186
+ { "update-index", cmd_update_index }
187
};
188
int i;
189