summaryrefslogtreecommitdiff
path: root/builtin-add.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-05-21 12:04:34 -0700
committerJunio C Hamano <gitster@pobox.com>2008-05-21 12:04:41 -0700
commit38ed1d89f759699de56004b08668e1764613f47b (patch)
tree40001e7853adba4204423a49ab9fb131df322b1c /builtin-add.c
parent377d9c409ffe0f0d994b929aeb94716139207b9d (diff)
downloadgit-38ed1d89f759699de56004b08668e1764613f47b.tar.gz
"git-add -n -u" should not add but just report
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-add.c')
-rw-r--r--builtin-add.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/builtin-add.c b/builtin-add.c
index 4a91e3eb11..05af57f6ec 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -82,9 +82,9 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,
static void update_callback(struct diff_queue_struct *q,
struct diff_options *opt, void *cbdata)
{
- int i, verbose;
+ int i, flags;
- verbose = *((int *)cbdata);
+ flags = *((int *)cbdata);
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
const char *path = p->one->path;
@@ -94,18 +94,19 @@ static void update_callback(struct diff_queue_struct *q,
case DIFF_STATUS_UNMERGED:
case DIFF_STATUS_MODIFIED:
case DIFF_STATUS_TYPE_CHANGED:
- add_file_to_cache(path, verbose);
+ add_file_to_cache(path, flags);
break;
case DIFF_STATUS_DELETED:
- remove_file_from_cache(path);
- if (verbose)
+ if (!(flags & ADD_CACHE_PRETEND))
+ remove_file_from_cache(path);
+ if (flags)
printf("remove '%s'\n", path);
break;
}
}
}
-void add_files_to_cache(int verbose, const char *prefix, const char **pathspec)
+void add_files_to_cache(const char *prefix, const char **pathspec, int flags)
{
struct rev_info rev;
init_revisions(&rev, prefix);
@@ -113,7 +114,7 @@ void add_files_to_cache(int verbose, const char *prefix, const char **pathspec)
rev.prune_data = pathspec;
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
rev.diffopt.format_callback = update_callback;
- rev.diffopt.format_callback_data = &verbose;
+ rev.diffopt.format_callback_data = &flags;
run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
}
@@ -209,10 +210,13 @@ int cmd_add(int argc, const char **argv, const char *prefix)
if (take_worktree_changes) {
const char **pathspec;
+ int flags = ((verbose ? ADD_CACHE_VERBOSE : 0) |
+ (show_only ? ADD_CACHE_PRETEND : 0));
+
if (read_cache() < 0)
die("index file corrupt");
pathspec = get_pathspec(prefix, argv);
- add_files_to_cache(verbose, prefix, pathspec);
+ add_files_to_cache(prefix, pathspec, flags);
goto finish;
}
@@ -254,7 +258,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
}
for (i = 0; i < dir.nr; i++)
- add_file_to_cache(dir.entries[i]->name, verbose);
+ add_file_to_cache(dir.entries[i]->name, verbose ? ADD_CACHE_VERBOSE : 0);
finish:
if (active_cache_changed) {