From: Junio C Hamano Date: Tue, 16 Sep 2008 07:47:52 +0000 (-0700) Subject: Merge branch 'jc/maint-name-hash-clear' X-Git-Tag: v1.6.1-rc1~239 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/27551baa3eddc4111ceee13dc05850ae80c99a3e?ds=inline;hp=-c Merge branch 'jc/maint-name-hash-clear' * jc/maint-name-hash-clear: discard_cache: reset lazy name_hash bit --- 27551baa3eddc4111ceee13dc05850ae80c99a3e diff --combined read-cache.c index 5150c1e14b,6c57095f73..5b1b3ad03b --- a/read-cache.c +++ b/read-cache.c @@@ -8,11 -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. * @@@ -1123,10 -1118,6 +1123,10 @@@ static void convert_from_disk(struct on ce->ce_size = ntohl(ondisk->size); /* On-disk flags are just 16 bits */ ce->ce_flags = ntohs(ondisk->flags); + + /* For future extension: we do not understand this entry yet */ + if (ce->ce_flags & CE_EXTENDED) + die("Unknown index entry format"); hashcpy(ce->sha1, ondisk->sha1); len = ce->ce_flags & CE_NAMEMASK; @@@ -1164,7 -1155,7 +1164,7 @@@ int read_index_from(struct index_state size_t mmap_size; errno = EBUSY; - if (istate->alloc) + if (istate->initialized) return istate->cache_nr; errno = ENOENT; @@@ -1204,7 -1195,6 +1204,7 @@@ * index size */ istate->alloc = xmalloc(estimate_cache_size(mmap_size, istate->cache_nr)); + istate->initialized = 1; src_offset = sizeof(*hdr); dst_offset = 0; @@@ -1253,11 -1243,11 +1253,12 @@@ int discard_index(struct index_state *i istate->cache_nr = 0; istate->cache_changed = 0; istate->timestamp = 0; + istate->name_hash_initialized = 0; free_hash(&istate->name_hash); cache_tree_free(&(istate->cache_tree)); free(istate->alloc); istate->alloc = NULL; + istate->initialized = 0; /* no need to throw away allocated active_cache */ return 0; @@@ -1488,59 -1478,3 +1489,59 @@@ int read_index_unmerged(struct index_st 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; +} +