- for (i = 0; i < entries; i++) {
- struct cache_entry *ce = cache[i];
- int size = ce_size(ce);
- if (write(newfd, ce, size) != size)
- return -1;
+ if (stat(ce->name, &st) < 0)
+ return ERR_PTR(-errno);
+
+ changed = cache_match_stat(ce, &st);
+ if (!changed)
+ return ce;
+
+ /*
+ * If the mode has changed, there's no point in trying
+ * to refresh the entry - it's not going to match
+ */
+ if (changed & MODE_CHANGED)
+ return ERR_PTR(-EINVAL);
+
+ if (compare_data(ce, st.st_size))
+ return ERR_PTR(-EINVAL);
+
+ size = ce_size(ce);
+ updated = malloc(size);
+ memcpy(updated, ce, size);
+ fill_stat_cache_info(updated, &st);
+ return updated;
+}
+
+static void refresh_cache(void)
+{
+ int i;
+
+ for (i = 0; i < active_nr; i++) {
+ struct cache_entry *ce, *new;
+ ce = active_cache[i];
+ if (ce_stage(ce)) {
+ printf("%s: needs merge\n", ce->name);
+ while ((i < active_nr) &&
+ ! strcmp(active_cache[i]->name, ce->name))
+ i++;
+ i--;
+ continue;
+ }
+
+ new = refresh_entry(ce);
+ if (IS_ERR(new)) {
+ if (!(not_new && PTR_ERR(new) == -ENOENT))
+ printf("%s: needs update\n", ce->name);
+ continue;
+ }
+ active_cache[i] = new;