@matheusbsbs / matheus-bagliano / commits / 7ae02a30e8
Fork 0

Extend interface of add_files_to_cache to allow ignore indexing errors

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:58 UTC 7ae02a30e817eda16ea362c6304b6ae28c3a7644
4 files changed +37 -12
builtin-add.c
+28 -9
@@ -79,12 +79,18 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,
79 prune_directory(dir, pathspec, baselen);
80 }
81
82 +struct update_callback_data
83 +{
84 + int flags;
85 + int add_errors;
86 +};
87 +
88 static void update_callback(struct diff_queue_struct *q,
89 struct diff_options *opt, void *cbdata)
90 {
85 - int i, verbose;
91 + int i;
92 + struct update_callback_data *data = cbdata;
93
87 - verbose = *((int *)cbdata);
94 for (i = 0; i < q->nr; i++) {
95 struct diff_filepair *p = q->queue[i];
96 const char *path = p->one->path;
@@ -94,28 +100,35 @@ static void update_callback(struct diff_queue_struct *q,
100 case DIFF_STATUS_UNMERGED:
101 case DIFF_STATUS_MODIFIED:
102 case DIFF_STATUS_TYPE_CHANGED:
97 - if (add_file_to_cache(path, verbose))
98 - die("updating files failed");
103 + if (add_file_to_cache(path, data->flags & ADD_FILES_VERBOSE)) {
104 + if (!(data->flags & ADD_FILES_IGNORE_ERRORS))
105 + die("updating files failed");
106 + data->add_errors++;
107 + }
108 break;
109 case DIFF_STATUS_DELETED:
110 remove_file_from_cache(path);
102 - if (verbose)
111 + if (data->flags & ADD_FILES_VERBOSE)
112 printf("remove '%s'\n", path);
113 break;
114 }
115 }
116 }
117
109 -void add_files_to_cache(int verbose, const char *prefix, const char **pathspec)
118 +int add_files_to_cache(const char *prefix, const char **pathspec, int flags)
119 {
120 + struct update_callback_data data;
121 struct rev_info rev;
122 init_revisions(&rev, prefix);
123 setup_revisions(0, NULL, &rev, NULL);
124 rev.prune_data = pathspec;
125 rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
126 rev.diffopt.format_callback = update_callback;
117 - rev.diffopt.format_callback_data = &verbose;
127 + data.flags = flags;
128 + data.add_errors = 0;
129 + rev.diffopt.format_callback_data = &data;
130 run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
131 + return !!data.add_errors;
132 }
133
134 static void refresh(int verbose, const char **pathspec)
@@ -193,6 +206,7 @@ static struct option builtin_add_options[] = {
206
207 int cmd_add(int argc, const char **argv, const char *prefix)
208 {
209 + int exit_status = 0;
210 int i, newfd;
211 const char **pathspec;
212 struct dir_struct dir;
@@ -209,11 +223,16 @@ int cmd_add(int argc, const char **argv, const char *prefix)
223 newfd = hold_locked_index(&lock_file, 1);
224
225 if (take_worktree_changes) {
226 + int flags = 0;
227 const char **pathspec;
228 if (read_cache() < 0)
229 die("index file corrupt");
230 pathspec = get_pathspec(prefix, argv);
216 - add_files_to_cache(verbose, prefix, pathspec);
231 +
232 + if (verbose)
233 + flags |= ADD_FILES_VERBOSE;
234 +
235 + exit_status = add_files_to_cache(prefix, pathspec, flags);
236 goto finish;
237 }
238
@@ -265,5 +284,5 @@ int cmd_add(int argc, const char **argv, const char *prefix)
284 die("Unable to write new index file");
285 }
286
268 - return 0;
287 + return exit_status;
288 }
builtin-checkout.c
+1 -1
@@ -282,7 +282,7 @@ static int merge_working_tree(struct checkout_opts *opts,
282 * entries in the index.
283 */
284
285 - add_files_to_cache(0, NULL, NULL);
285 + add_files_to_cache(NULL, NULL, 0);
286 work = write_tree_from_memory();
287
288 ret = reset_to_new(new->commit->tree, opts->quiet);
builtin-commit.c
+1 -1
@@ -246,7 +246,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
246 */
247 if (all || (also && pathspec && *pathspec)) {
248 int fd = hold_locked_index(&index_lock, 1);
249 - add_files_to_cache(0, also ? prefix : NULL, pathspec);
249 + add_files_to_cache(also ? prefix : NULL, pathspec, 0);
250 refresh_cache(REFRESH_QUIET);
251 if (write_cache(fd, active_cache, active_nr) ||
252 close_lock_file(&index_lock))
cache.h
+7 -1
@@ -781,7 +781,13 @@ extern int convert_to_git(const char *path, const char *src, size_t len,
781 extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst);
782
783 /* add */
784 -void add_files_to_cache(int verbose, const char *prefix, const char **pathspec);
784 +#define ADD_FILES_VERBOSE 01
785 +#define ADD_FILES_IGNORE_ERRORS 02
786 +/*
787 + * return 0 if success, 1 - if addition of a file failed and
788 + * ADD_FILES_IGNORE_ERRORS was specified in flags
789 + */
790 +int add_files_to_cache(const char *prefix, const char **pathspec, int flags);
791
792 /* diff.c */
793 extern int diff_auto_refresh_index;