aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2007-09-17 20:06:44 -0400
committerJunio C Hamano <gitster@pobox.com>2007-09-27 01:19:42 -0700
commit586801650824f0f7b62c34a206b6a60ffbcd8be0 (patch)
treef9d474878042914e343bdcee2b78012c6e9e9fbd
parenta17ba31b0b75365e1245e494d46abae4afc57480 (diff)
downloadgit-586801650824f0f7b62c34a206b6a60ffbcd8be0.tar.gz
git-586801650824f0f7b62c34a206b6a60ffbcd8be0.tar.xz
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>
-rw-r--r--builtin-add.c23
-rw-r--r--commit.h4
2 files changed, 18 insertions, 9 deletions
diff --git a/builtin-add.c b/builtin-add.c
index f9a65803d..966e14503 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -12,6 +12,7 @@
#include "diffcore.h"
#include "commit.h"
#include "revision.h"
+#include "run-command.h"
static const char builtin_add_usage[] =
"git-add [-n] [-v] [-f] [--interactive | -i] [-u] [--refresh] [--] <filepattern>...";
@@ -106,7 +107,7 @@ static void update_callback(struct diff_queue_struct *q,
}
}
-static void update(int verbose, const char *prefix, const char **files)
+void add_files_to_cache(int verbose, const char *prefix, const char **files)
{
struct rev_info rev;
init_revisions(&rev, prefix);
@@ -115,8 +116,6 @@ static void update(int verbose, const char *prefix, const char **files)
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
rev.diffopt.format_callback = update_callback;
rev.diffopt.format_callback_data = &verbose;
- if (read_cache() < 0)
- die("index file corrupt");
run_diff_files(&rev, 0);
}
@@ -149,6 +148,13 @@ static int git_add_config(const char *var, const char *value)
return git_default_config(var, value);
}
+int interactive_add(void)
+{
+ const char *argv[2] = { "add--interactive", NULL };
+
+ return run_command_v_opt(argv, RUN_GIT_CMD);
+}
+
static struct lock_file lock_file;
static const char ignore_error[] =
@@ -168,12 +174,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
add_interactive++;
}
if (add_interactive) {
- const char *args[] = { "add--interactive", NULL };
-
- if (add_interactive != 1 || argc != 2)
+ if (argc != 2)
die("add --interactive does not take any parameters");
- execv_git_cmd(args);
- exit(1);
+ exit(interactive_add());
}
git_config(git_add_config);
@@ -213,7 +216,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
}
if (take_worktree_changes) {
- update(verbose, prefix, argv + i);
+ if (read_cache() < 0)
+ die("index file corrupt");
+ add_files_to_cache(verbose, prefix, argv + i);
goto finish;
}
diff --git a/commit.h b/commit.h
index b779de8cb..b50c30e25 100644
--- a/commit.h
+++ b/commit.h
@@ -128,4 +128,8 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
int depth, int shallow_flag, int not_shallow_flag);
int in_merge_bases(struct commit *, struct commit **, int);
+
+extern int interactive_add(void);
+extern void add_files_to_cache(int verbose, const char *prefix, const char **files);
+
#endif /* COMMIT_H */