AmendHub

Download:

jcs

/

amend

/

amendments

/

2

repo: Only load first 32K into TE when viewing diffs

If this truncates, add a line saying so

jcs made amendment 2 over 2 years ago
--- repo.c Mon Oct 18 17:12:17 2021 +++ repo.c Tue Oct 19 13:33:46 2021 @@ -327,13 +327,27 @@ void repo_show_diff_text(struct repo_commit *commit, TEHandle te) { Handle diffh; + unsigned long len, blen; + char buf[100]; diffh = Get1Resource(REPO_DIFF_RTYPE, commit->id); if (diffh == NULL) err(1, "failed finding DIFF %d", commit->id); HLock(diffh); - TESetText(*diffh, GetHandleSize(diffh), te); + + len = GetHandleSize(diffh); + if (len > 32767L) { + len = 32767L - strlen(REPO_DIFF_TOO_BIG) - 20; + blen = sprintf(buf, REPO_DIFF_TOO_BIG, + GetHandleSize(diffh) - len); + TESetText(*diffh, len, te); + TESetSelect(32767L, 32767L, te); + TEInsert(buf, blen, te); + } else { + TESetText(*diffh, len, te); + } + ReleaseResource(diffh); } @@ -536,7 +550,7 @@ repo_diff_file(struct repo *repo, struct repo_file *fi Str255 fromfilename = { 0 }, tofilename = { 0 }; struct repo_file_attrs attrs; char *fromfilepath, *tofilepath; - char label0[64], label1[64]; + char label0[255], label1[255]; long len; short error, ret, frefnum; --- repo.h Mon Oct 18 15:08:25 2021 +++ repo.h Tue Oct 19 13:31:50 2021 @@ -27,6 +27,8 @@ #define REPO_DIFF_RTYPE 'DIFF' #define REPO_TEXT_RTYPE 'TEXT' +#define REPO_DIFF_TOO_BIG "\r[ Diff too large to view, %lu bytes not shown ]" + struct repo_file { short id; char filename[256]; --- util.c Mon Oct 18 13:14:58 2021 +++ util.c Tue Oct 19 13:27:46 2021 @@ -531,9 +531,9 @@ TECanAddLine(TEHandle teh, size_t addition) HLock(teh); te = *teh; - if ((long)te->teLength + addition > 32767) + if ((long)te->teLength + addition > 32767L) ret = 0; - else if ((long)te->nLines * (long)te->lineHeight > 32767) + else if ((long)te->nLines * (long)te->lineHeight > 32767L) ret = 0; HUnlock(teh);