const char *path, int stage, int refresh, int options)
  {
        struct cache_entry *ce;
-       ce = make_cache_entry(mode, oid ? oid->hash : null_sha1, path, stage,
-                             (refresh ? (CE_MATCH_REFRESH |
-                                         CE_MATCH_IGNORE_MISSING) : 0 ));
+       int ret;
+ 
 -      ce = make_cache_entry(mode, sha1 ? sha1 : null_sha1, path, stage, 0);
++      ce = make_cache_entry(mode, oid ? oid->hash : null_sha1, path, stage, 0);
        if (!ce)
                return error(_("addinfo_cache failed for path '%s'"), path);
-       return add_cache_entry(ce, options);
+ 
+       ret = add_cache_entry(ce, options);
+       if (refresh) {
+               struct cache_entry *nce;
+ 
+               nce = refresh_cache_entry(ce, CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING);
+               if (nce != ce)
+                       ret = add_cache_entry(nce, options);
+       }
+       return ret;
  }
  
  static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)