Skip to content

Commit

Permalink
entry: add checkout_entry_ca() taking preloaded conv_attrs
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
matheustavares authored and gitster committed Mar 23, 2021
1 parent 30419e7 commit ae22751
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
11 changes: 6 additions & 5 deletions entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,13 @@ static void mark_colliding_entries(const struct checkout *state,
}
}

int checkout_entry(struct cache_entry *ce, const struct checkout *state,
char *topath, int *nr_checkouts)
int checkout_entry_ca(struct cache_entry *ce, struct conv_attrs *ca,
const struct checkout *state, char *topath,
int *nr_checkouts)
{
static struct strbuf path = STRBUF_INIT;
struct stat st;
struct conv_attrs ca_buf, *ca = NULL;
struct conv_attrs ca_buf;

if (ce->ce_flags & CE_WT_REMOVE) {
if (topath)
Expand All @@ -459,7 +460,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state,
}

if (topath) {
if (S_ISREG(ce->ce_mode)) {
if (S_ISREG(ce->ce_mode) && !ca) {
convert_attrs(state->istate, &ca_buf, ce->name);
ca = &ca_buf;
}
Expand Down Expand Up @@ -530,7 +531,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state,
if (nr_checkouts)
(*nr_checkouts)++;

if (S_ISREG(ce->ce_mode)) {
if (S_ISREG(ce->ce_mode) && !ca) {
convert_attrs(state->istate, &ca_buf, ce->name);
ca = &ca_buf;
}
Expand Down
16 changes: 14 additions & 2 deletions entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,21 @@ struct checkout {
* file named by ce, a temporary file is created by this function and
* its name is returned in topath[], which must be able to hold at
* least TEMPORARY_FILENAME_LENGTH bytes long.
*
* With checkout_entry_ca(), callers can optionally pass a preloaded
* conv_attrs struct (to avoid reloading it), when ce refers to a
* regular file. If ca is NULL, the attributes will be loaded
* internally when (and if) needed.
*/
int checkout_entry(struct cache_entry *ce, const struct checkout *state,
char *topath, int *nr_checkouts);
int checkout_entry_ca(struct cache_entry *ce, struct conv_attrs *ca,
const struct checkout *state, char *topath,
int *nr_checkouts);
static inline int checkout_entry(struct cache_entry *ce,
const struct checkout *state, char *topath,
int *nr_checkouts)
{
return checkout_entry_ca(ce, NULL, state, topath, nr_checkouts);
}

void enable_delayed_checkout(struct checkout *state);
int finish_delayed_checkout(struct checkout *state, int *nr_checkouts);
Expand Down

0 comments on commit ae22751

Please sign in to comment.