Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatheus Tavares <matheus.bernardino@usp.br>2022-07-14 14:49:12 +0300
committerJunio C Hamano <gitster@pobox.com>2022-07-14 20:19:28 +0300
commit611c7785e8e22637e183333c54ed266e6e83e163 (patch)
tree8b4379db400b8f61570306598567e03c4eab0eb3 /entry.c
parent11d14dee43794581ca3a7a93f9a081de711845d4 (diff)
checkout: fix two bugs on the final count of updated entries
At the end of `git checkout <pathspec>`, we get a message informing how many entries were updated in the working tree. However, this number can be inaccurate for two reasons: 1) Delayed entries currently get counted twice. 2) Failed entries are included in the count. The first problem happens because the counter is first incremented before inserting the entry in the delayed checkout queue, and once again when finish_delayed_checkout() calls checkout_entry(). And the second happens because the counter is incremented too early in checkout_entry(), before the entry was in fact checked out. Fix that by moving the count increment further down in the call stack and removing the duplicate increment on delayed entries. Note that we have to keep a per-entry reference for the counter (both on parallel checkout and delayed checkout) because not all entries are always accumulated at the same counter. See checkout_worktree(), at builtin/checkout.c for an example. Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'entry.c')
-rw-r--r--entry.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/entry.c b/entry.c
index 1c9df62b30..616e4f073c 100644
--- a/entry.c
+++ b/entry.c
@@ -157,12 +157,11 @@ static int remove_available_paths(struct string_list_item *item, void *cb_data)
available = string_list_lookup(available_paths, item->string);
if (available)
- available->util = (void *)item->string;
+ available->util = item->util;
return !available;
}
-int finish_delayed_checkout(struct checkout *state, int *nr_checkouts,
- int show_progress)
+int finish_delayed_checkout(struct checkout *state, int show_progress)
{
int errs = 0;
unsigned processed_paths = 0;
@@ -227,7 +226,7 @@ int finish_delayed_checkout(struct checkout *state, int *nr_checkouts,
strlen(path->string), 0);
if (ce) {
display_progress(progress, ++processed_paths);
- errs |= checkout_entry(ce, state, NULL, nr_checkouts);
+ errs |= checkout_entry(ce, state, NULL, path->util);
filtered_bytes += ce->ce_stat_data.sd_size;
display_throughput(progress, filtered_bytes);
} else
@@ -266,7 +265,8 @@ void update_ce_after_write(const struct checkout *state, struct cache_entry *ce,
/* Note: ca is used (and required) iff the entry refers to a regular file. */
static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca,
- const struct checkout *state, int to_tempfile)
+ const struct checkout *state, int to_tempfile,
+ int *nr_checkouts)
{
unsigned int ce_mode_s_ifmt = ce->ce_mode & S_IFMT;
struct delayed_checkout *dco = state->delayed_checkout;
@@ -279,6 +279,7 @@ static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca
struct stat st;
const struct submodule *sub;
struct checkout_metadata meta;
+ static int scratch_nr_checkouts;
clone_checkout_metadata(&meta, &state->meta, &ce->oid);
@@ -333,9 +334,15 @@ static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca
ret = async_convert_to_working_tree_ca(ca, ce->name,
new_blob, size,
&buf, &meta, dco);
- if (ret && string_list_has_string(&dco->paths, ce->name)) {
- free(new_blob);
- goto delayed;
+ if (ret) {
+ struct string_list_item *item =
+ string_list_lookup(&dco->paths, ce->name);
+ if (item) {
+ item->util = nr_checkouts ? nr_checkouts
+ : &scratch_nr_checkouts;
+ free(new_blob);
+ goto delayed;
+ }
}
} else {
ret = convert_to_working_tree_ca(ca, ce->name, new_blob,
@@ -392,6 +399,8 @@ finish:
ce->name);
update_ce_after_write(state, ce , &st);
}
+ if (nr_checkouts)
+ (*nr_checkouts)++;
delayed:
return 0;
}
@@ -476,7 +485,7 @@ int checkout_entry_ca(struct cache_entry *ce, struct conv_attrs *ca,
convert_attrs(state->istate, &ca_buf, ce->name);
ca = &ca_buf;
}
- return write_entry(ce, topath, ca, state, 1);
+ return write_entry(ce, topath, ca, state, 1, nr_checkouts);
}
strbuf_reset(&path);
@@ -540,18 +549,15 @@ int checkout_entry_ca(struct cache_entry *ce, struct conv_attrs *ca,
create_directories(path.buf, path.len, state);
- if (nr_checkouts)
- (*nr_checkouts)++;
-
if (S_ISREG(ce->ce_mode) && !ca) {
convert_attrs(state->istate, &ca_buf, ce->name);
ca = &ca_buf;
}
- if (!enqueue_checkout(ce, ca))
+ if (!enqueue_checkout(ce, ca, nr_checkouts))
return 0;
- return write_entry(ce, path.buf, ca, state, 0);
+ return write_entry(ce, path.buf, ca, state, 0, nr_checkouts);
}
void unlink_entry(const struct cache_entry *ce)