From 38ed1d89f759699de56004b08668e1764613f47b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 21 May 2008 12:04:34 -0700 Subject: "git-add -n -u" should not add but just report Signed-off-by: Junio C Hamano --- builtin-add.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'builtin-add.c') 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) { -- cgit v1.2.1 From 205ffa94be8f6492eef4bdaa3315e7fdc7e64e0b Mon Sep 17 00:00:00 2001 From: Gustaf Hendeby Date: Thu, 22 May 2008 23:59:42 +0200 Subject: Make git add -n and git -u -n output consistent Output format from "git add -n $path" lists path to blobs that are going to be added on a single line, separated with SP. On the other hand, the suggested "git add -u -n" shows one path per line, like "add ''\n". Of course, these two are inconsistent. Plain "git add -n" can afford to only say names of paths, as all it does is to add (update). However, "git add -u" needs to be able to express "remove" somehow. So if we need to have them formatted the same way, we need to unify with the "git add -n -u" format. Incidentally, this is consistent with how 'update-index' says it. This changes the output from "git add -n $paths" but as a general principle, output from Porcelain commands is a fair game for improvements and not for script consumption. Signed-off-by: Gustaf Hendeby Signed-off-by: Junio C Hamano --- builtin-add.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'builtin-add.c') diff --git a/builtin-add.c b/builtin-add.c index 05af57f6ec..8f81f3fbfb 100644 --- a/builtin-add.c +++ b/builtin-add.c @@ -196,6 +196,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) int i, newfd; const char **pathspec; struct dir_struct dir; + int flags; argc = parse_options(argc, argv, builtin_add_options, builtin_add_usage, 0); @@ -208,11 +209,11 @@ int cmd_add(int argc, const char **argv, const char *prefix) newfd = hold_locked_index(&lock_file, 1); + flags = ((verbose ? ADD_CACHE_VERBOSE : 0) | + (show_only ? ADD_CACHE_PRETEND : 0)); + 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); @@ -234,17 +235,6 @@ int cmd_add(int argc, const char **argv, const char *prefix) fill_directory(&dir, pathspec, ignored_too); - if (show_only) { - const char *sep = "", *eof = ""; - for (i = 0; i < dir.nr; i++) { - printf("%s%s", sep, dir.entries[i]->name); - sep = " "; - eof = "\n"; - } - fputs(eof, stdout); - return 0; - } - if (read_cache() < 0) die("index file corrupt"); @@ -258,7 +248,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_CACHE_VERBOSE : 0); + add_file_to_cache(dir.entries[i]->name, flags); finish: if (active_cache_changed) { -- cgit v1.2.1