@matheusbsbs / matheus-bagliano / commits / 205ffa94be
Fork 0

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 '<file>'\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 <hendeby@isy.liu.se> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Gustaf Hendeby committed May 22, 2008 at 23:59 UTC 205ffa94be8f6492eef4bdaa3315e7fdc7e64e0b
1 file changed +5 -15
builtin-add.c
+5 -15
@@ -196,6 +196,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
196 int i, newfd;
197 const char **pathspec;
198 struct dir_struct dir;
199 + int flags;
200
201 argc = parse_options(argc, argv, builtin_add_options,
202 builtin_add_usage, 0);
@@ -208,11 +209,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
209
210 newfd = hold_locked_index(&lock_file, 1);
211
212 + flags = ((verbose ? ADD_CACHE_VERBOSE : 0) |
213 + (show_only ? ADD_CACHE_PRETEND : 0));
214 +
215 if (take_worktree_changes) {
216 const char **pathspec;
213 - int flags = ((verbose ? ADD_CACHE_VERBOSE : 0) |
214 - (show_only ? ADD_CACHE_PRETEND : 0));
215 -
217 if (read_cache() < 0)
218 die("index file corrupt");
219 pathspec = get_pathspec(prefix, argv);
@@ -234,17 +235,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
235
236 fill_directory(&dir, pathspec, ignored_too);
237
237 - if (show_only) {
238 - const char *sep = "", *eof = "";
239 - for (i = 0; i < dir.nr; i++) {
240 - printf("%s%s", sep, dir.entries[i]->name);
241 - sep = " ";
242 - eof = "\n";
243 - }
244 - fputs(eof, stdout);
245 - return 0;
246 - }
247 -
238 if (read_cache() < 0)
239 die("index file corrupt");
240
@@ -258,7 +248,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
248 }
249
250 for (i = 0; i < dir.nr; i++)
261 - add_file_to_cache(dir.entries[i]->name, verbose ? ADD_CACHE_VERBOSE : 0);
251 + add_file_to_cache(dir.entries[i]->name, flags);
252
253 finish:
254 if (active_cache_changed) {