@matheusbsbs / matheus-bagliano / commits / 960b8ad1b1
Fork 0

Make the exit code of add_file_to_index actually useful

Update the programs which used the function (as add_file_to_cache). Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Alex Riesen committed May 12, 2008 at 19:57 UTC 960b8ad1b1824b1b82c2b09a000c2119f97633a0
4 files changed +13 -9
builtin-add.c
+4 -2
@@ -94,7 +94,8 @@ static void update_callback(struct diff_queue_struct *q,
94 case DIFF_STATUS_UNMERGED:
95 case DIFF_STATUS_MODIFIED:
96 case DIFF_STATUS_TYPE_CHANGED:
97 - add_file_to_cache(path, verbose);
97 + if (add_file_to_cache(path, verbose))
98 + die("updating files failed");
99 break;
100 case DIFF_STATUS_DELETED:
101 remove_file_from_cache(path);
@@ -254,7 +255,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
255 }
256
257 for (i = 0; i < dir.nr; i++)
257 - add_file_to_cache(dir.entries[i]->name, verbose);
258 + if (add_file_to_cache(dir.entries[i]->name, verbose))
259 + die("adding files failed");
260
261 finish:
262 if (active_cache_changed) {
builtin-commit.c
+4 -3
@@ -178,9 +178,10 @@ static void add_remove_files(struct path_list *list)
178 struct stat st;
179 struct path_list_item *p = &(list->items[i]);
180
181 - if (!lstat(p->path, &st))
182 - add_to_cache(p->path, &st, 0);
183 - else
181 + if (!lstat(p->path, &st)) {
182 + if (add_to_cache(p->path, &st, 0))
183 + die("updating files failed");
184 + } else
185 remove_file_from_cache(p->path);
186 }
187 }
builtin-mv.c
+2 -1
@@ -256,7 +256,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
256
257 for (i = 0; i < added.nr; i++) {
258 const char *path = added.items[i].path;
259 - add_file_to_cache(path, verbose);
259 + if (add_file_to_cache(path, verbose))
260 + die("updating index entries failed");
261 }
262
263 for (i = 0; i < deleted.nr; i++)
read-cache.c
+3 -3
@@ -470,7 +470,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
470 unsigned ce_option = CE_MATCH_IGNORE_VALID|CE_MATCH_RACY_IS_DIRTY;
471
472 if (!S_ISREG(st_mode) && !S_ISLNK(st_mode) && !S_ISDIR(st_mode))
473 - die("%s: can only add regular files, symbolic links or git-directories", path);
473 + return error("%s: can only add regular files, symbolic links or git-directories", path);
474
475 namelen = strlen(path);
476 if (S_ISDIR(st_mode)) {
@@ -505,12 +505,12 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
505 return 0;
506 }
507 if (index_path(ce->sha1, path, st, 1))
508 - die("unable to index file %s", path);
508 + return error("unable to index file %s", path);
509 if (ignore_case && alias && different_name(ce, alias))
510 ce = create_alias_ce(ce, alias);
511 ce->ce_flags |= CE_ADDED;
512 if (add_index_entry(istate, ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE))
513 - die("unable to add %s to index",path);
513 + return error("unable to add %s to index",path);
514 if (verbose)
515 printf("add '%s'\n", path);
516 return 0;