entry: extract update_ce_after_write() from write_entry()

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>

Matheus Tavares committed Mar 23, 2021 at 11:19 UTC 584a0d13f25d60694a1226cd274c33dba62bf9e4
2 files changed +18 -9
entry.c
+16 -9
@@ -251,6 +251,18 @@ int finish_delayed_checkout(struct checkout *state, int *nr_checkouts)
251 return errs;
252 }
253
254 +void update_ce_after_write(const struct checkout *state, struct cache_entry *ce,
255 + struct stat *st)
256 +{
257 + if (state->refresh_cache) {
258 + assert(state->istate);
259 + fill_stat_cache_info(state->istate, ce, st);
260 + ce->ce_flags |= CE_UPDATE_IN_BASE;
261 + mark_fsmonitor_invalid(state->istate, ce);
262 + state->istate->cache_changed |= CE_ENTRY_CHANGED;
263 + }
264 +}
265 +
266 static int write_entry(struct cache_entry *ce,
267 char *path, const struct checkout *state, int to_tempfile)
268 {
@@ -371,15 +383,10 @@ static int write_entry(struct cache_entry *ce,
383
384 finish:
385 if (state->refresh_cache) {
374 - assert(state->istate);
375 - if (!fstat_done)
376 - if (lstat(ce->name, &st) < 0)
377 - return error_errno("unable to stat just-written file %s",
378 - ce->name);
379 - fill_stat_cache_info(state->istate, ce, &st);
380 - ce->ce_flags |= CE_UPDATE_IN_BASE;
381 - mark_fsmonitor_invalid(state->istate, ce);
382 - state->istate->cache_changed |= CE_ENTRY_CHANGED;
386 + if (!fstat_done && lstat(ce->name, &st) < 0)
387 + return error_errno("unable to stat just-written file %s",
388 + ce->name);
389 + update_ce_after_write(state, ce , &st);
390 }
391 delayed:
392 return 0;
entry.h
+2
@@ -41,5 +41,7 @@ void unlink_entry(const struct cache_entry *ce);
41
42 void *read_blob_entry(const struct cache_entry *ce, unsigned long *size);
43 int fstat_checkout_output(int fd, const struct checkout *state, struct stat *st);
44 +void update_ce_after_write(const struct checkout *state, struct cache_entry *ce,
45 + struct stat *st);
46
47 #endif /* ENTRY_H */