Introduce entry point add_interactive and add_files_to_cache
This refactors builtin-add.c a little to provide a unique entry point for launching git add --interactive, which will be used by builtin-commit too. If we later want to make add --interactive a builtin or change how it is launched, we just start from this function. It also exports the private function update() which is used to add all modified paths to the index as add_files_to_cache(). Signed-off-by: Kristian Høgsberg <krh@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kristian Høgsberg committed
Sep 17, 2007 at 20:06 UTC
586801650824f0f7b62c34a206b6a60ffbcd8be0
2 files changed
+18
-9
builtin-add.c
+14
-9
@@ -12,6 +12,7 @@
12
#include "diffcore.h"
13
#include "commit.h"
14
#include "revision.h"
15
+#include "run-command.h"
16
17
static const char builtin_add_usage[] =
18
"git-add [-n] [-v] [-f] [--interactive | -i] [-u] [--refresh] [--] <filepattern>...";
@@ -106,7 +107,7 @@ static void update_callback(struct diff_queue_struct *q,
107
}
108
}
109
109
-static void update(int verbose, const char *prefix, const char **files)
110
+void add_files_to_cache(int verbose, const char *prefix, const char **files)
111
{
112
struct rev_info rev;
113
init_revisions(&rev, prefix);
@@ -115,8 +116,6 @@ static void update(int verbose, const char *prefix, const char **files)
116
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
117
rev.diffopt.format_callback = update_callback;
118
rev.diffopt.format_callback_data = &verbose;
118
- if (read_cache() < 0)
119
- die("index file corrupt");
119
run_diff_files(&rev, 0);
120
}
121
@@ -149,6 +148,13 @@ static int git_add_config(const char *var, const char *value)
148
return git_default_config(var, value);
149
}
150
151
+int interactive_add(void)
152
+{
153
+ const char *argv[2] = { "add--interactive", NULL };
154
+
155
+ return run_command_v_opt(argv, RUN_GIT_CMD);
156
+}
157
+
158
static struct lock_file lock_file;
159
160
static const char ignore_error[] =
@@ -168,12 +174,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
174
add_interactive++;
175
}
176
if (add_interactive) {
171
- const char *args[] = { "add--interactive", NULL };
172
-
173
- if (add_interactive != 1 || argc != 2)
177
+ if (argc != 2)
178
die("add --interactive does not take any parameters");
175
- execv_git_cmd(args);
176
- exit(1);
179
+ exit(interactive_add());
180
}
181
182
git_config(git_add_config);
@@ -213,7 +216,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
216
}
217
218
if (take_worktree_changes) {
216
- update(verbose, prefix, argv + i);
219
+ if (read_cache() < 0)
220
+ die("index file corrupt");
221
+ add_files_to_cache(verbose, prefix, argv + i);
222
goto finish;
223
}
224
commit.h
+4
@@ -128,4 +128,8 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
128
int depth, int shallow_flag, int not_shallow_flag);
129
130
int in_merge_bases(struct commit *, struct commit **, int);
131
+
132
+extern int interactive_add(void);
133
+extern void add_files_to_cache(int verbose, const char *prefix, const char **files);
134
+
135
#endif /* COMMIT_H */