]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Make ce_uptodate() trustworthy again
authorJunio C Hamano <gitster@pobox.com>
Sun, 24 Jan 2010 08:10:20 +0000 (00:10 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 24 Jan 2010 08:15:29 +0000 (00:15 -0800)
The rule has always been that a cache entry that is ce_uptodate(ce)
means that we already have checked the work tree entity and we know
there is no change in the work tree compared to the index, and nobody
should have to double check.  Note that false ce_uptodate(ce) does not
mean it is known to be dirty---it only means we don't know if it is
clean.

There are a few codepaths (refresh-index and preload-index are among
them) that mark a cache entry as up-to-date based solely on the return
value from ie_match_stat(); this function uses lstat() to see if the
work tree entity has been touched, and for a submodule entry, if its
HEAD points at the same commit as the commit recorded in the index of
the superproject (a submodule that is not even cloned is considered
clean).

A submodule is no longer considered unmodified merely because its HEAD
matches the index of the superproject these days, in order to prevent
people from forgetting to commit in the submodule and updating the
superproject index with the new submodule commit, before commiting the
state in the superproject.  However, the patch to do so didn't update
the codepath that marks cache entries up-to-date based on the updated
definition and instead worked it around by saying "we don't trust the
return value of ce_uptodate() for submodules."

This makes ce_uptodate() trustworthy again by not marking submodule
entries up-to-date.

The next step _could_ be to introduce a few "in-core" flag bits to
cache_entry structure to record "this entry is _known_ to be dirty",
call is_submodule_modified() from ie_match_stat(), and use these new
bits to avoid running this rather expensive check more than once, but
that can be a separate patch.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff-lib.c
preload-index.c
read-cache.c

index 23e180eed13230fa234cdcb86db7dbd914abb4a5..c6c425e624124c23c0f9cc8e1e0d73dc75dcbf64 100644 (file)
@@ -161,7 +161,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                                continue;
                }
 
-               if ((ce_uptodate(ce) && !S_ISGITLINK(ce->ce_mode)) || ce_skip_worktree(ce))
+               if (ce_uptodate(ce) || ce_skip_worktree(ce))
                        continue;
 
                /* If CE_VALID is set, don't look at workdir for file removal */
index 92899333c2d8edbed71fdd3a43e19f25a10e5b03..e3d0bda31a98372eb9b6a8c2cd0fd65917a9dbde 100644 (file)
@@ -47,6 +47,8 @@ static void *preload_thread(void *_data)
 
                if (ce_stage(ce))
                        continue;
+               if (S_ISGITLINK(ce->ce_mode))
+                       continue;
                if (ce_uptodate(ce))
                        continue;
                if (!ce_path_match(ce, p->pathspec))
index 79938bf09a7e5c12de90af4cd81be0fdf755113a..309b77a6c9bae41ba2cde42e0266b02ae4b32497 100644 (file)
@@ -612,7 +612,8 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
        if (alias && !ce_stage(alias) && !ie_match_stat(istate, alias, st, ce_option)) {
                /* Nothing changed, really */
                free(ce);
-               ce_mark_uptodate(alias);
+               if (!S_ISGITLINK(alias->ce_mode))
+                       ce_mark_uptodate(alias);
                alias->ce_flags |= CE_ADDED;
                return 0;
        }
@@ -1050,7 +1051,8 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
                         * because CE_UPTODATE flag is in-core only;
                         * we are not going to write this change out.
                         */
-                       ce_mark_uptodate(ce);
+                       if (!S_ISGITLINK(ce->ce_mode))
+                               ce_mark_uptodate(ce);
                        return ce;
                }
        }