entry: add checkout_entry_ca() taking preloaded conv_attrs

The parallel checkout machinery will call checkout_entry() for entries that could not be written in parallel due to path collisions. At this point, we will already be holding the conversion attributes for each entry, and it would be wasteful to let checkout_entry() load these again. Instead, let's add the checkout_entry_ca() variant, which optionally takes a preloaded conv_attrs struct. 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 ae22751f9b4bbbebcd0366a48a118b5a575af72d
2 files changed +20 -7
entry.c
+6 -5
@@ -440,12 +440,13 @@ static void mark_colliding_entries(const struct checkout *state,
440 }
441 }
442
443 -int checkout_entry(struct cache_entry *ce, const struct checkout *state,
444 - char *topath, int *nr_checkouts)
443 +int checkout_entry_ca(struct cache_entry *ce, struct conv_attrs *ca,
444 + const struct checkout *state, char *topath,
445 + int *nr_checkouts)
446 {
447 static struct strbuf path = STRBUF_INIT;
448 struct stat st;
448 - struct conv_attrs ca_buf, *ca = NULL;
449 + struct conv_attrs ca_buf;
450
451 if (ce->ce_flags & CE_WT_REMOVE) {
452 if (topath)
@@ -459,7 +460,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state,
460 }
461
462 if (topath) {
462 - if (S_ISREG(ce->ce_mode)) {
463 + if (S_ISREG(ce->ce_mode) && !ca) {
464 convert_attrs(state->istate, &ca_buf, ce->name);
465 ca = &ca_buf;
466 }
@@ -530,7 +531,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state,
531 if (nr_checkouts)
532 (*nr_checkouts)++;
533
533 - if (S_ISREG(ce->ce_mode)) {
534 + if (S_ISREG(ce->ce_mode) && !ca) {
535 convert_attrs(state->istate, &ca_buf, ce->name);
536 ca = &ca_buf;
537 }
entry.h
+14 -2
@@ -26,9 +26,21 @@ struct checkout {
26 * file named by ce, a temporary file is created by this function and
27 * its name is returned in topath[], which must be able to hold at
28 * least TEMPORARY_FILENAME_LENGTH bytes long.
29 + *
30 + * With checkout_entry_ca(), callers can optionally pass a preloaded
31 + * conv_attrs struct (to avoid reloading it), when ce refers to a
32 + * regular file. If ca is NULL, the attributes will be loaded
33 + * internally when (and if) needed.
34 */
30 -int checkout_entry(struct cache_entry *ce, const struct checkout *state,
31 - char *topath, int *nr_checkouts);
35 +int checkout_entry_ca(struct cache_entry *ce, struct conv_attrs *ca,
36 + const struct checkout *state, char *topath,
37 + int *nr_checkouts);
38 +static inline int checkout_entry(struct cache_entry *ce,
39 + const struct checkout *state, char *topath,
40 + int *nr_checkouts)
41 +{
42 + return checkout_entry_ca(ce, NULL, state, topath, nr_checkouts);
43 +}
44
45 void enable_delayed_checkout(struct checkout *state);
46 int finish_delayed_checkout(struct checkout *state, int *nr_checkouts);