- if (!cache_changed) {
- /* If we have not smudged the cache, be careful
- * to keep it clean. Find out if we have a matching
- * cache entry that add_cache_entry would replace with,
- * and if it matches then do not bother calling it.
- */
- int pos = cache_name_pos(ce->name, namelen);
- if ((0 <= pos) &&
- !memcmp(active_cache[pos], ce, sizeof(*ce))) {
- free(ce);
- /* magic to tell add_file_to_cache that
- * we have not updated anything.
- */
- return 999;
- }
- }
- return add_cache_entry(ce, allow_add);
-}
-
-static int add_file_to_cache(char *path)
-{
- int ret = add_file_to_cache_1(path);
- if (ret == 0)
- cache_changed = 1;
- else if (ret == 999)
- ret = 0;
- return ret;
+ option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
+ option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
+ return add_cache_entry(ce, option);