]> git.ipfire.org Git - thirdparty/git.git/commitdiff
entry: extract update_ce_after_write() from write_entry()
authorMatheus Tavares <matheus.bernardino@usp.br>
Tue, 23 Mar 2021 14:19:34 +0000 (11:19 -0300)
committerJunio C Hamano <gitster@pobox.com>
Tue, 23 Mar 2021 17:34:05 +0000 (10:34 -0700)
The code that updates the in-memory index information after an entry is
written currently resides in write_entry(). Extract it to a public
function so that it can be called by the parallel checkout functions,
outside entry.c, in a later patch.

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
entry.c
entry.h

diff --git a/entry.c b/entry.c
index 1e2d9f7baa45dbb9faec28052a93e1d355a11463..4cf0db352fe7804e4d9d90bec97ba5906fde0250 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -251,6 +251,18 @@ int finish_delayed_checkout(struct checkout *state, int *nr_checkouts)
        return errs;
 }
 
+void update_ce_after_write(const struct checkout *state, struct cache_entry *ce,
+                          struct stat *st)
+{
+       if (state->refresh_cache) {
+               assert(state->istate);
+               fill_stat_cache_info(state->istate, ce, st);
+               ce->ce_flags |= CE_UPDATE_IN_BASE;
+               mark_fsmonitor_invalid(state->istate, ce);
+               state->istate->cache_changed |= CE_ENTRY_CHANGED;
+       }
+}
+
 static int write_entry(struct cache_entry *ce,
                       char *path, const struct checkout *state, int to_tempfile)
 {
@@ -371,15 +383,10 @@ static int write_entry(struct cache_entry *ce,
 
 finish:
        if (state->refresh_cache) {
-               assert(state->istate);
-               if (!fstat_done)
-                       if (lstat(ce->name, &st) < 0)
-                               return error_errno("unable to stat just-written file %s",
-                                                  ce->name);
-               fill_stat_cache_info(state->istate, ce, &st);
-               ce->ce_flags |= CE_UPDATE_IN_BASE;
-               mark_fsmonitor_invalid(state->istate, ce);
-               state->istate->cache_changed |= CE_ENTRY_CHANGED;
+               if (!fstat_done && lstat(ce->name, &st) < 0)
+                       return error_errno("unable to stat just-written file %s",
+                                          ce->name);
+               update_ce_after_write(state, ce , &st);
        }
 delayed:
        return 0;
diff --git a/entry.h b/entry.h
index 60df93ca78a55fff9e2d9563a884756783d7151c..ea7290bcd596bf076753da95b2256a72856e9b08 100644 (file)
--- a/entry.h
+++ b/entry.h
@@ -41,5 +41,7 @@ void unlink_entry(const struct cache_entry *ce);
 
 void *read_blob_entry(const struct cache_entry *ce, unsigned long *size);
 int fstat_checkout_output(int fd, const struct checkout *state, struct stat *st);
+void update_ce_after_write(const struct checkout *state, struct cache_entry *ce,
+                          struct stat *st);
 
 #endif /* ENTRY_H */