AmendHub

Download:

jcs

/

amend

/

amendments

/

131

diffreg: Check for command+. while running and abort

Also free some arrays that don't seem to ever get freed, just
realloc'd.

jcs made amendment 131 over 2 years ago
--- committer.c Thu Jan 11 13:08:25 2024 +++ committer.c Thu Jan 11 13:56:58 2024 @@ -422,7 +422,7 @@ void committer_generate_diff(struct committer *committer) { struct repo_file *file; - short i, all_files; + short i, all_files, ret; short *selected_files = NULL; short nselected_files = 0; TextStyle style; @@ -478,11 +478,14 @@ committer_generate_diff(struct committer *committer) DIFFED_FILE_METADATA; progress("Diffing %s...", file->filename); - if (repo_diff_file(committer->browser->repo, file)) { + ret = repo_diff_file(committer->browser->repo, file); + + if (ret == 1) { committer->diffed_files[committer->ndiffed_files].flags |= DIFFED_FILE_TEXT; committer->allow_commit = true; - } + } else if (ret == -1) + committer->canceled = true; diff_finish(); committer->ndiffed_files++; --- diff.h Sat Mar 4 22:40:07 2023 +++ diff.h Thu Jan 11 14:33:26 2024 @@ -74,6 +74,7 @@ #define D_MISMATCH2 4 /* path1 was a file, path2 a dir */ #define D_SKIPPED1 5 /* path1 was a special file */ #define D_SKIPPED2 6 /* path2 was a special file */ +#define D_ABORTED 7 /* User canceled */ extern short quitting; extern long diff_format, diff_context, status; --- diffreg.c Sat Mar 4 22:40:19 2023 +++ diffreg.c Thu Jan 11 14:28:35 2024 @@ -331,8 +331,19 @@ diffreg(char *file1, char *file2, int flags) status |= 1; goto closem; } + if (CommandPeriodPressed()) { + rval = D_ABORTED; + status |= 1; + goto closem; + } + prepare(0, f1, stb1.st_size, flags); prepare(1, f2, stb2.st_size, flags); + if (CommandPeriodPressed()) { + rval = D_ABORTED; + status |= 1; + goto closem; + } prune(); sort(sfile[0], slen[0]); @@ -359,9 +370,20 @@ diffreg(char *file1, char *file2, int flags) xfree(&clist); xfree(&klist); + if (CommandPeriodPressed()) { + rval = D_ABORTED; + status |= 1; + goto closem; + } + ixold = xreallocarray(ixold, len[0] + 2, sizeof(*ixold)); ixnew = xreallocarray(ixnew, len[1] + 2, sizeof(*ixnew)); check(f1, f2, flags); + if (CommandPeriodPressed()) { + rval = D_ABORTED; + status |= 1; + goto closem; + } output(file1, f1, file2, f2, flags); closem: if (anychange) { @@ -373,7 +395,12 @@ closem: fclose(f1); if (f2 != NULL) fclose(f2); - + if (ixnew != NULL) + xfree(&ixnew); + if (ixold != NULL) + xfree(&ixold); + if (J != NULL) + xfree(&J); return (rval); } --- repo.c Thu Jan 11 13:25:22 2024 +++ repo.c Thu Jan 11 14:23:38 2024 @@ -159,7 +159,8 @@ repo_init(struct bile *bile, bool is_new) } done: - SetCursor(&arrow); + if (!repo) + SetCursor(&arrow); progress(NULL); return repo; @@ -883,6 +884,9 @@ repo_diff_file(struct repo *repo, struct repo_file *fi if (ret == D_SAME) return 0; + if (ret == D_ABORTED) + return -1; + return 1; }