diff options
author | Junio C Hamano <gitster@pobox.com> | 2008-08-27 16:39:57 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-08-27 16:39:57 -0700 |
commit | b46f7e54fcb2d01757d834d14dfd040b6892d695 (patch) | |
tree | f7d2743d855b605f5880cabbed6d21248682e430 /read-cache.c | |
parent | 5a1e8707a6d9c7016a59d9987c1bc72ffe1252c8 (diff) | |
parent | 1e5f764c93edfd8f6575b6ede769b079a1fc5a21 (diff) | |
download | git-b46f7e54fcb2d01757d834d14dfd040b6892d695.tar.gz |
Merge branch 'jc/add-addremove'
* jc/add-addremove:
builtin-add.c: optimize -A option and "git add ."
builtin-add.c: restructure the code for maintainability
Diffstat (limited to 'read-cache.c')
-rw-r--r-- | read-cache.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/read-cache.c b/read-cache.c index a857c8e12f..5150c1e14b 100644 --- a/read-cache.c +++ b/read-cache.c @@ -8,6 +8,11 @@ #include "cache-tree.h" #include "refs.h" #include "dir.h" +#include "tree.h" +#include "commit.h" +#include "diff.h" +#include "diffcore.h" +#include "revision.h" /* Index extensions. * @@ -1483,3 +1488,59 @@ int read_index_unmerged(struct index_state *istate) istate->cache_nr = dst - istate->cache; return !!last; } + +struct update_callback_data +{ + int flags; + int add_errors; +}; + +static void update_callback(struct diff_queue_struct *q, + struct diff_options *opt, void *cbdata) +{ + int i; + struct update_callback_data *data = cbdata; + + for (i = 0; i < q->nr; i++) { + struct diff_filepair *p = q->queue[i]; + const char *path = p->one->path; + switch (p->status) { + default: + die("unexpected diff status %c", p->status); + case DIFF_STATUS_UNMERGED: + case DIFF_STATUS_MODIFIED: + case DIFF_STATUS_TYPE_CHANGED: + if (add_file_to_index(&the_index, path, data->flags)) { + if (!(data->flags & ADD_CACHE_IGNORE_ERRORS)) + die("updating files failed"); + data->add_errors++; + } + break; + case DIFF_STATUS_DELETED: + if (data->flags & ADD_CACHE_IGNORE_REMOVAL) + break; + if (!(data->flags & ADD_CACHE_PRETEND)) + remove_file_from_index(&the_index, path); + if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE)) + printf("remove '%s'\n", path); + break; + } + } +} + +int add_files_to_cache(const char *prefix, const char **pathspec, int flags) +{ + struct update_callback_data data; + struct rev_info rev; + init_revisions(&rev, prefix); + setup_revisions(0, NULL, &rev, NULL); + rev.prune_data = pathspec; + rev.diffopt.output_format = DIFF_FORMAT_CALLBACK; + rev.diffopt.format_callback = update_callback; + data.flags = flags; + data.add_errors = 0; + rev.diffopt.format_callback_data = &data; + run_diff_files(&rev, DIFF_RACY_IS_MODIFIED); + return !!data.add_errors; +} + |