AmendHub

Download (as of this amendment):

jcs

/

amend

/

amendments

/

129

repo: If command+period is pressed while loading a repo, abort


jcs made amendment 129 over 2 years ago
--- repo.c Wed Nov 1 15:35:55 2023 +++ repo.c Thu Jan 11 13:25:22 2024 @@ -103,6 +103,7 @@ repo_init(struct bile *bile, bool is_new) char *data; unsigned short i; unsigned long *ids; + bool canceled = false; repo = xmalloczero(sizeof(struct repo), "repo"); repo->bile = bile; @@ -133,26 +134,45 @@ repo_init(struct bile *bile, bool is_new) if (repo->files[i]->id >= repo->next_file_id) repo->next_file_id = repo->files[i]->id + 1; xfree(&data); + + if (CommandPeriodPressed()) { + canceled = true; + break; + } } xfree(&ids); + if (canceled || CommandPeriodPressed()) { + repo_close(repo); + repo = NULL; + goto done; + } + progress("Organizing files..."); repo_sort_files(repo); } /* fill in amendment info */ - repo_load_amendments(repo, false); + if (!repo_load_amendments(repo, false)) { + repo_close(repo); + repo = NULL; + } +done: + SetCursor(&arrow); + progress(NULL); + return repo; } -void +bool repo_load_amendments(struct repo *repo, bool fill_in) { size_t size; char *data; unsigned long *ids; unsigned short i; + bool ret = true; if (fill_in) { progress("Loading first %d/%d amendments...", @@ -164,7 +184,7 @@ repo_load_amendments(struct repo *repo, bool fill_in) repo->namendments = bile_sorted_ids_by_type(repo->bile, REPO_AMENDMENT_RTYPE, &ids); if (!repo->namendments) - return; + return true; if (!fill_in) { repo->amendments = xcalloc(repo->namendments, sizeof(Ptr), @@ -175,6 +195,10 @@ repo_load_amendments(struct repo *repo, bool fill_in) } for (i = 0; i < repo->namendments; i++) { + if (!fill_in && CommandPeriodPressed()) { + ret = false; + break; + } if (repo->unloaded_amendments && i < repo->namendments - settings.max_amendments - 1) continue; @@ -198,6 +222,8 @@ repo_load_amendments(struct repo *repo, bool fill_in) xfree(&data); } xfree(&ids); + + return ret; } void --- repo.h Wed Nov 1 15:35:09 2023 +++ repo.h Thu Jan 11 13:15:59 2024 @@ -88,7 +88,7 @@ struct repo { struct repo *repo_open(AppFile *file); struct repo *repo_create(void); void repo_close(struct repo *repo); -void repo_load_amendments(struct repo *repo, bool fill_in); +bool repo_load_amendments(struct repo *repo, bool fill_in); struct repo_amendment *repo_parse_amendment(unsigned long id, unsigned char *data, size_t size); struct repo_file * repo_parse_file(unsigned long id, unsigned char *data,