AmendHub

Download:

jcs

/

amend

/

amendments

/

108

repo: Provide some detailed progress while opening repos

This can take a while, so entertain the user while we work.

jcs made amendment 108 about 1 year ago
--- repo.c Thu Nov 10 09:26:24 2022 +++ repo.c Thu Nov 10 10:33:06 2022 @@ -25,7 +25,7 @@ #include "strnatcmp.h" #include "util.h" -struct repo * repo_init(struct bile *bile, short is_new); +struct repo * repo_init(struct bile *bile, bool is_new); void repo_sort_files(struct repo *repo); void repo_sort_amendments(struct repo *repo); short repo_get_file_attrs(struct repo *repo, Str255 filename, @@ -33,7 +33,7 @@ short repo_get_file_attrs(struct repo *repo, Str255 fi short repo_file_update(struct repo *repo, struct repo_file *file); unsigned short repo_diff_header(struct repo *repo, struct repo_amendment *amendment, char **ret); -short repo_migrate(struct repo *repo, short is_new); +short repo_migrate(struct repo *repo, bool is_new); pascal Boolean repo_add_file_filter(struct FileParam *pbp); struct repo * @@ -66,10 +66,6 @@ repo_open(AppFile *file) return NULL; } - progress("Verifying repository structure..."); - bile_verify(bile); - - progress("Reading repository..."); return repo_init(bile, 0); } @@ -95,11 +91,11 @@ repo_create(void) if (bile == NULL) panic("Failed to create %s: %d", PtoCstr(reply.fName), error); - return repo_init(bile, 1); + return repo_init(bile, true); } struct repo * -repo_init(struct bile *bile, short is_new) +repo_init(struct bile *bile, bool is_new) { Str255 buf; struct bile_object *bob; @@ -108,7 +104,7 @@ repo_init(struct bile *bile, short is_new) size_t size; char *data; short error, fh; - unsigned long i; + unsigned short i; repo = xmalloczero(sizeof(struct repo), "repo"); repo->bile = bile; @@ -125,9 +121,11 @@ repo_init(struct bile *bile, short is_new) if (repo->nfiles) { repo->files = xcalloc(repo->nfiles, sizeof(Ptr), "repo files"); for (i = 0; i < repo->nfiles; i++) { + if (i == 0 || i == repo->nfiles - 1 || ((i + 1) % 10) == 0) + progress("Loading file %d/%d...", i + 1, repo->nfiles); bob = bile_get_nth_of_type(bile, i, REPO_FILE_RTYPE); if (bob == NULL) - panic("no %ld file, but count said it should be there", i); + panic("no %d file, but count said it should be there", i); size = bile_read_alloc(bile, REPO_FILE_RTYPE, bob->id, &data); if (size == 0) panic("failed fetching file %ld", bob->id); @@ -148,9 +146,13 @@ repo_init(struct bile *bile, short is_new) repo->amendments = xcalloc(repo->namendments, sizeof(Ptr), "repo amendments"); for (i = 0; i < repo->namendments; i++) { + if (i == 0 || i == repo->namendments - 1 || + ((i + 1) % 10) == 0) + progress("Loading amendment %d/%d...", i + 1, + repo->namendments); bob = bile_get_nth_of_type(bile, i, REPO_AMENDMENT_RTYPE); if (bob == NULL) - panic("no %ld amendment, but count said it should be there", + panic("no %d amendment, but count said it should be there", i); size = bile_read_alloc(bile, REPO_AMENDMENT_RTYPE, bob->id, &data); @@ -162,8 +164,9 @@ repo_init(struct bile *bile, short is_new) repo->next_amendment_id = repo->amendments[i]->id + 1; xfree(&data); } + + repo_sort_amendments(repo); } - repo_sort_amendments(repo); return repo; } @@ -1125,7 +1128,7 @@ repo_marshall_amendment(struct repo_amendment *amendme } short -repo_migrate(struct repo *repo, short is_new) +repo_migrate(struct repo *repo, bool is_new) { struct bile_object *bob; Str255 tname;