From 93ba78d6f4632ef1c5228965e3edc8c0faf88c1e Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 26 May 2020 00:06:52 +0100 Subject: revert(3p/git): Revert merge of git upstream at v2.26.2 This causes cgit to serve error pages, which is undesirable. This reverts commit 5229c9b232de5bfa959ad6ebbb4c8192ac513352, reversing changes made to f2b211131f2347342dde63975b09cf603149f1a3. --- third_party/git/fsmonitor.c | 174 ++++++++++---------------------------------- 1 file changed, 37 insertions(+), 137 deletions(-) (limited to 'third_party/git/fsmonitor.c') diff --git a/third_party/git/fsmonitor.c b/third_party/git/fsmonitor.c index 932bd9012daf..231e83a94db5 100644 --- a/third_party/git/fsmonitor.c +++ b/third_party/git/fsmonitor.c @@ -6,42 +6,19 @@ #include "run-command.h" #include "strbuf.h" -#define INDEX_EXTENSION_VERSION1 (1) -#define INDEX_EXTENSION_VERSION2 (2) -#define HOOK_INTERFACE_VERSION1 (1) -#define HOOK_INTERFACE_VERSION2 (2) +#define INDEX_EXTENSION_VERSION (1) +#define HOOK_INTERFACE_VERSION (1) struct trace_key trace_fsmonitor = TRACE_KEY_INIT(FSMONITOR); static void fsmonitor_ewah_callback(size_t pos, void *is) { struct index_state *istate = (struct index_state *)is; - struct cache_entry *ce; + struct cache_entry *ce = istate->cache[pos]; - if (pos >= istate->cache_nr) - BUG("fsmonitor_dirty has more entries than the index (%"PRIuMAX" >= %u)", - (uintmax_t)pos, istate->cache_nr); - - ce = istate->cache[pos]; ce->ce_flags &= ~CE_FSMONITOR_VALID; } -static int fsmonitor_hook_version(void) -{ - int hook_version; - - if (git_config_get_int("core.fsmonitorhookversion", &hook_version)) - return -1; - - if (hook_version == HOOK_INTERFACE_VERSION1 || - hook_version == HOOK_INTERFACE_VERSION2) - return hook_version; - - warning("Invalid hook version '%i' in core.fsmonitorhookversion. " - "Must be 1 or 2.", hook_version); - return -1; -} - int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz) { @@ -50,26 +27,17 @@ int read_fsmonitor_extension(struct index_state *istate, const void *data, uint32_t ewah_size; struct ewah_bitmap *fsmonitor_dirty; int ret; - uint64_t timestamp; - struct strbuf last_update = STRBUF_INIT; - if (sz < sizeof(uint32_t) + 1 + sizeof(uint32_t)) + if (sz < sizeof(uint32_t) + sizeof(uint64_t) + sizeof(uint32_t)) return error("corrupt fsmonitor extension (too short)"); hdr_version = get_be32(index); index += sizeof(uint32_t); - if (hdr_version == INDEX_EXTENSION_VERSION1) { - timestamp = get_be64(index); - strbuf_addf(&last_update, "%"PRIu64"", timestamp); - index += sizeof(uint64_t); - } else if (hdr_version == INDEX_EXTENSION_VERSION2) { - strbuf_addstr(&last_update, index); - index += last_update.len + 1; - } else { + if (hdr_version != INDEX_EXTENSION_VERSION) return error("bad fsmonitor version %d", hdr_version); - } - istate->fsmonitor_last_update = strbuf_detach(&last_update, NULL); + istate->fsmonitor_last_update = get_be64(index); + index += sizeof(uint64_t); ewah_size = get_be32(index); index += sizeof(uint32_t); @@ -82,45 +50,32 @@ int read_fsmonitor_extension(struct index_state *istate, const void *data, } istate->fsmonitor_dirty = fsmonitor_dirty; - if (!istate->split_index && - istate->fsmonitor_dirty->bit_size > istate->cache_nr) - BUG("fsmonitor_dirty has more entries than the index (%"PRIuMAX" > %u)", - (uintmax_t)istate->fsmonitor_dirty->bit_size, istate->cache_nr); - trace_printf_key(&trace_fsmonitor, "read fsmonitor extension successful"); return 0; } void fill_fsmonitor_bitmap(struct index_state *istate) { - unsigned int i, skipped = 0; + unsigned int i; istate->fsmonitor_dirty = ewah_new(); - for (i = 0; i < istate->cache_nr; i++) { - if (istate->cache[i]->ce_flags & CE_REMOVE) - skipped++; - else if (!(istate->cache[i]->ce_flags & CE_FSMONITOR_VALID)) - ewah_set(istate->fsmonitor_dirty, i - skipped); - } + for (i = 0; i < istate->cache_nr; i++) + if (!(istate->cache[i]->ce_flags & CE_FSMONITOR_VALID)) + ewah_set(istate->fsmonitor_dirty, i); } void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate) { uint32_t hdr_version; + uint64_t tm; uint32_t ewah_start; uint32_t ewah_size = 0; int fixup = 0; - if (!istate->split_index && - istate->fsmonitor_dirty->bit_size > istate->cache_nr) - BUG("fsmonitor_dirty has more entries than the index (%"PRIuMAX" > %u)", - (uintmax_t)istate->fsmonitor_dirty->bit_size, istate->cache_nr); - - put_be32(&hdr_version, INDEX_EXTENSION_VERSION2); + put_be32(&hdr_version, INDEX_EXTENSION_VERSION); strbuf_add(sb, &hdr_version, sizeof(uint32_t)); - strbuf_addstr(sb, istate->fsmonitor_last_update); - strbuf_addch(sb, 0); /* Want to keep a NUL */ - + put_be64(&tm, istate->fsmonitor_last_update); + strbuf_add(sb, &tm, sizeof(uint64_t)); fixup = sb->len; strbuf_add(sb, &ewah_size, sizeof(uint32_t)); /* we'll fix this up later */ @@ -137,9 +92,9 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate) } /* - * Call the query-fsmonitor hook passing the last update token of the saved results. + * Call the query-fsmonitor hook passing the time of the last saved results. */ -static int query_fsmonitor(int version, const char *last_update, struct strbuf *query_result) +static int query_fsmonitor(int version, uint64_t last_update, struct strbuf *query_result) { struct child_process cp = CHILD_PROCESS_INIT; @@ -148,7 +103,7 @@ static int query_fsmonitor(int version, const char *last_update, struct strbuf * argv_array_push(&cp.args, core_fsmonitor); argv_array_pushf(&cp.args, "%d", version); - argv_array_pushf(&cp.args, "%s", last_update); + argv_array_pushf(&cp.args, "%" PRIuMAX, (uintmax_t)last_update); cp.use_shell = 1; cp.dir = get_git_work_tree(); @@ -175,18 +130,14 @@ static void fsmonitor_refresh_callback(struct index_state *istate, const char *n void refresh_fsmonitor(struct index_state *istate) { struct strbuf query_result = STRBUF_INIT; - int query_success = 0, hook_version = -1; - size_t bol = 0; /* beginning of line */ + int query_success = 0; + size_t bol; /* beginning of line */ uint64_t last_update; - struct strbuf last_update_token = STRBUF_INIT; char *buf; unsigned int i; if (!core_fsmonitor || istate->fsmonitor_has_run_once) return; - - hook_version = fsmonitor_hook_version(); - istate->fsmonitor_has_run_once = 1; trace_printf_key(&trace_fsmonitor, "refresh fsmonitor"); @@ -195,60 +146,26 @@ void refresh_fsmonitor(struct index_state *istate) * should be inclusive to ensure we don't miss potential changes. */ last_update = getnanotime(); - if (hook_version == HOOK_INTERFACE_VERSION1) - strbuf_addf(&last_update_token, "%"PRIu64"", last_update); /* - * If we have a last update token, call query_fsmonitor for the set of - * changes since that token, else assume everything is possibly dirty + * If we have a last update time, call query_fsmonitor for the set of + * changes since that time, else assume everything is possibly dirty * and check it all. */ if (istate->fsmonitor_last_update) { - if (hook_version == -1 || hook_version == HOOK_INTERFACE_VERSION2) { - query_success = !query_fsmonitor(HOOK_INTERFACE_VERSION2, - istate->fsmonitor_last_update, &query_result); - - if (query_success) { - if (hook_version < 0) - hook_version = HOOK_INTERFACE_VERSION2; - - /* - * First entry will be the last update token - * Need to use a char * variable because static - * analysis was suggesting to use strbuf_addbuf - * but we don't want to copy the entire strbuf - * only the the chars up to the first NUL - */ - buf = query_result.buf; - strbuf_addstr(&last_update_token, buf); - if (!last_update_token.len) { - warning("Empty last update token."); - query_success = 0; - } else { - bol = last_update_token.len + 1; - } - } else if (hook_version < 0) { - hook_version = HOOK_INTERFACE_VERSION1; - if (!last_update_token.len) - strbuf_addf(&last_update_token, "%"PRIu64"", last_update); - } - } - - if (hook_version == HOOK_INTERFACE_VERSION1) { - query_success = !query_fsmonitor(HOOK_INTERFACE_VERSION1, - istate->fsmonitor_last_update, &query_result); - } - + query_success = !query_fsmonitor(HOOK_INTERFACE_VERSION, + istate->fsmonitor_last_update, &query_result); trace_performance_since(last_update, "fsmonitor process '%s'", core_fsmonitor); trace_printf_key(&trace_fsmonitor, "fsmonitor process '%s' returned %s", core_fsmonitor, query_success ? "success" : "failure"); } /* a fsmonitor process can return '/' to indicate all entries are invalid */ - if (query_success && query_result.buf[bol] != '/') { + if (query_success && query_result.buf[0] != '/') { /* Mark all entries returned by the monitor as dirty */ buf = query_result.buf; - for (i = bol; i < query_result.len; i++) { + bol = 0; + for (i = 0; i < query_result.len; i++) { if (buf[i] != '\0') continue; fsmonitor_refresh_callback(istate, buf + bol); @@ -256,47 +173,31 @@ void refresh_fsmonitor(struct index_state *istate) } if (bol < query_result.len) fsmonitor_refresh_callback(istate, buf + bol); - - /* Now mark the untracked cache for fsmonitor usage */ - if (istate->untracked) - istate->untracked->use_fsmonitor = 1; } else { - - /* We only want to run the post index changed hook if we've actually changed entries, so keep track - * if we actually changed entries or not */ - int is_cache_changed = 0; /* Mark all entries invalid */ - for (i = 0; i < istate->cache_nr; i++) { - if (istate->cache[i]->ce_flags & CE_FSMONITOR_VALID) { - is_cache_changed = 1; - istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID; - } - } + for (i = 0; i < istate->cache_nr; i++) + istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID; /* If we're going to check every file, ensure we save the results */ - if (is_cache_changed) - istate->cache_changed |= FSMONITOR_CHANGED; + istate->cache_changed |= FSMONITOR_CHANGED; if (istate->untracked) istate->untracked->use_fsmonitor = 0; } strbuf_release(&query_result); - /* Now that we've updated istate, save the last_update_token */ - FREE_AND_NULL(istate->fsmonitor_last_update); - istate->fsmonitor_last_update = strbuf_detach(&last_update_token, NULL); + /* Now that we've updated istate, save the last_update time */ + istate->fsmonitor_last_update = last_update; } void add_fsmonitor(struct index_state *istate) { unsigned int i; - struct strbuf last_update = STRBUF_INIT; if (!istate->fsmonitor_last_update) { trace_printf_key(&trace_fsmonitor, "add fsmonitor"); istate->cache_changed |= FSMONITOR_CHANGED; - strbuf_addf(&last_update, "%"PRIu64"", getnanotime()); - istate->fsmonitor_last_update = strbuf_detach(&last_update, NULL); + istate->fsmonitor_last_update = getnanotime(); /* reset the fsmonitor state */ for (i = 0; i < istate->cache_nr; i++) @@ -318,7 +219,7 @@ void remove_fsmonitor(struct index_state *istate) if (istate->fsmonitor_last_update) { trace_printf_key(&trace_fsmonitor, "remove fsmonitor"); istate->cache_changed |= FSMONITOR_CHANGED; - FREE_AND_NULL(istate->fsmonitor_last_update); + istate->fsmonitor_last_update = 0; } } @@ -335,12 +236,11 @@ void tweak_fsmonitor(struct index_state *istate) } /* Mark all previously saved entries as dirty */ - if (istate->fsmonitor_dirty->bit_size > istate->cache_nr) - BUG("fsmonitor_dirty has more entries than the index (%"PRIuMAX" > %u)", - (uintmax_t)istate->fsmonitor_dirty->bit_size, istate->cache_nr); ewah_each_bit(istate->fsmonitor_dirty, fsmonitor_ewah_callback, istate); - refresh_fsmonitor(istate); + /* Now mark the untracked cache for fsmonitor usage */ + if (istate->untracked) + istate->untracked->use_fsmonitor = 1; } ewah_free(istate->fsmonitor_dirty); -- cgit 1.4.1