jcs
/amend
/amendments
/33
committer: If "All Files" is selected, skip diffing unchanged files
If the file size, ctime, and mtime are all the same, consider it
unchanged.
jcs made amendment 33 over 3 years ago
--- browser.c Mon Nov 22 09:48:36 2021
+++ browser.c Wed Dec 15 16:15:08 2021
@@ -243,6 +243,25 @@ browser_add_files(struct browser *browser)
}
short
+browser_is_all_files_selected(struct browser *browser)
+{
+ Cell cell = { 0 };
+
+ if (browser->repo->nfiles == 0)
+ return 0;
+
+ /*
+ * "All Files" is always cell.v=0, so if v=0 is selected or nothing
+ * is, select all files
+ */
+ if (LGetSelect(false, &cell, browser->file_list) == true ||
+ LGetSelect(true, &cell, browser->file_list) == false)
+ return 1;
+
+ return 0;
+}
+
+short
browser_selected_file_ids(struct browser *browser, short **selected_files)
{
Cell cell = { 0 };
@@ -255,12 +274,7 @@ browser_selected_file_ids(struct browser *browser, sho
*selected_files = xmalloc(browser->repo->nfiles * sizeof(short));
- /*
- * "All Files" is always cell.v=0, so if v=0 is selected or nothing
- * is, select all files
- */
- if (LGetSelect(false, &cell, browser->file_list) == true ||
- LGetSelect(true, &cell, browser->file_list) == false) {
+ if (browser_is_all_files_selected(browser)) {
nselected_files = browser->repo->nfiles;
for (i = 0; i < browser->repo->nfiles; i++)
(*selected_files)[i] = browser->repo->files[i]->id;
--- browser.h Wed Nov 17 15:46:59 2021
+++ browser.h Wed Dec 15 16:15:17 2021
@@ -59,6 +59,7 @@ void browser_update(struct browser *browser, EventReco
void browser_show_commit(struct browser *browser,
struct repo_commit *commit);
void browser_export_patch(struct browser *browser);
+short browser_is_all_files_selected(struct browser *browser);
short browser_selected_file_ids(struct browser *browser,
short **selected_files);
void browser_mouse_down(struct browser *browser, EventRecord *event);
--- committer.c Fri Nov 19 16:56:03 2021
+++ committer.c Wed Dec 15 16:16:11 2021
@@ -376,7 +376,7 @@ void
committer_generate_diff(struct committer *committer)
{
struct repo_file *file;
- short i;
+ short i, all_files;
short *selected_files = NULL;
short nselected_files = 0;
TextStyle style;
@@ -404,16 +404,24 @@ committer_generate_diff(struct committer *committer)
style.tsSize = 9;
TESetStyle(doFont | doSize, &style, false, cur_committer->diff_te);
+ all_files = browser_is_all_files_selected(committer->browser);
+
for (i = 0; i < nselected_files; i++) {
file = repo_file_with_id(committer->browser->repo,
selected_files[i]);
if (file == NULL)
err(1, "Failed to find file with id %d", selected_files[i]);
- committer_status("Diffing %s...", file->filename);
- if (repo_diff_file(committer->browser->repo, file))
- committer->diffed_files[committer->ndiffed_files++] =
- file->id;
- diff_finish();
+
+ if (!all_files ||
+ repo_file_changed(committer->browser->repo, file)) {
+ committer_status("Diffing %s...", file->filename);
+ if (repo_diff_file(committer->browser->repo, file))
+ committer->diffed_files[committer->ndiffed_files++] =
+ file->id;
+ diff_finish();
+ } else{
+ committer_status("Skipping unchanged %s...", file->filename);
+ }
}
HUnlock(committer->diff_te);
--- repo.c Sun Nov 21 16:49:03 2021
+++ repo.c Wed Dec 15 16:12:29 2021
@@ -62,7 +62,7 @@ repo_create(void)
char *newpath = NULL;
short error, fh, i;
- SFPutFile(pt, "\pCreate new repository:", NULL, NULL, &reply);
+ SFPutFile(pt, "\pCreate new repository:", "\p", NULL, &reply);
if (!reply.good)
return NULL;
@@ -767,6 +767,44 @@ repo_diff_file(struct repo *repo, struct repo_file *fi
return 0;
return 1;
+}
+
+short
+repo_file_changed(struct repo *repo, struct repo_file *file)
+{
+ Handle texth;
+ Str255 filename = { 0 };
+ struct stat sb;
+ char *filepath;
+ long fsize;
+
+ /* if there's no existing TEXT resource, it's a new file */
+ texth = Get1Resource(REPO_TEXT_RTYPE, file->id);
+ if (texth == NULL) {
+ ReleaseResource(texth);
+ return 1;
+ }
+ fsize = GetHandleSize(texth);
+
+ memcpy((char *)filename, file->filename, sizeof(file->filename));
+ CtoPstr(filename);
+ getpath(repo->vrefnum, filename, &filepath, true);
+
+ if (stat(filepath, &sb) != 0) {
+ free(filepath);
+ return 1;
+ }
+
+ free(filepath);
+
+ if (sb.st_size != fsize)
+ return 1;
+ if (sb.st_ctime != file->ctime)
+ return 1;
+ if (sb.st_mtime != file->mtime)
+ return 1;
+
+ return 0;
}
void
--- repo.h Thu Nov 18 11:01:03 2021
+++ repo.h Wed Dec 15 16:06:05 2021
@@ -89,6 +89,7 @@ void repo_show_diff_text(struct repo *repo, struct rep
struct repo_file *repo_add_file(struct repo *repo);
void repo_file_mark_for_deletion(struct repo *repo, struct repo_file *file);
short repo_diff_file(struct repo *repo, struct repo_file *file);
+short repo_file_changed(struct repo *repo, struct repo_file *file);
short repo_checkout_file(struct repo *repo, struct repo_file *file,
short vrefnum, Str255 filename);
void repo_export_patch(struct repo *repo, struct repo_commit *commit,