jcs
/amend
/amendments
/153
*: Switch diff views to TextView
This removes the 32k limit on viewing/committing a diff and the need
to keep checking for overflow.
We can also get rid of tetab since TextView incorporates that.
jcs made amendment 153 about 1 year ago
--- amend.h Wed Mar 20 21:37:17 2024
+++ amend.h Thu Oct 24 21:39:40 2024
@@ -55,8 +55,11 @@
#define SETTINGS_SAVE_ID 1
#define SETTINGS_CANCEL_ID 2
#define SETTINGS_AUTHOR_ID 3
-#define SETTINGS_TABWIDTH_ID 4
+#define SETTINGS_TABSTOP_ID 4
#define SETTINGS_MAX_AMENDMENTS_ID 5
+
+#define DIFF_FONT monaco
+#define DIFF_FONT_SIZE 9
extern MenuHandle file_menu, edit_menu, repo_menu, amendment_menu;
--- browser.c Mon Mar 25 15:51:12 2024
+++ browser.c Fri Oct 25 13:28:38 2024
@@ -27,7 +27,6 @@
#include "patch.h"
#include "repo.h"
#include "settings.h"
-#include "tetab.h"
#include "util.h"
#define DIFF_BUTTON_FONT geneva
@@ -109,11 +108,11 @@ browser_idle(struct focusable *focusable, EventRecord
struct browser *
browser_init(struct repo *repo)
{
- char title[256], filename[256], *justfilename;
+ char title[128], filename[256], *justfilename;
struct browser *browser;
struct focusable *focusable;
- Rect bounds = { 0 }, te_bounds = { 0 };
- Rect data_bounds = { 0, 0, 0, 1 }; /* tlbr */
+ Rect bounds = { 0 }, data_bounds = { 0 }, tv_bounds = { 0 };
+ Rect padding;
Point cell_size = { 0, 0 };
Cell cell = { 0 };
short width, height;
@@ -194,13 +193,11 @@ browser_init(struct repo *repo)
bounds.left = PADDING;
bounds.right = browser->win->portRect.right - SCROLLBAR_WIDTH - PADDING;
bounds.bottom = browser->win->portRect.bottom - PADDING;
- te_bounds = bounds;
- InsetRect(&te_bounds, 2, 2);
- browser->diff_te = TEStylNew(&te_bounds, &bounds);
- TEAutoView(true, browser->diff_te);
- TETabEnable(browser->diff_te);
- (*(browser->diff_te))->caretHook = NullCaretHook;
- TEActivate(browser->diff_te);
+ tv_bounds = bounds;
+ SetRect(&padding, 2, 2, 2, 2);
+ browser->diff_tv = TVNew(&bounds, &padding);
+ TVLineWrap(browser->diff_tv, false);
+ TVTabStop(browser->diff_tv, settings.tabstop);
/* scrollbar for diff text */
bounds.right = browser->win->portRect.right - PADDING;
@@ -212,8 +209,7 @@ browser_init(struct repo *repo)
browser_update_menu(browser);
browser_add_files(browser);
- UpdateScrollbarForTE(browser->win, browser->diff_scroller,
- browser->diff_te, true);
+ TVUpdateScrollbar(browser->diff_tv, browser->diff_scroller);
focusable = xmalloczero(sizeof(struct focusable));
focusable->cookie = browser;
@@ -243,7 +239,7 @@ browser_close(struct focusable *focusable)
if (browser->repo)
repo_close(browser->repo);
- TEDispose(browser->diff_te);
+ TVDispose(browser->diff_tv);
DisposeWindow(browser->win);
xfree(&browser);
@@ -401,19 +397,18 @@ void
browser_show_amendment(struct browser *browser,
struct repo_amendment *amendment)
{
- if (amendment == NULL) {
- TESetText("", 0, browser->diff_te);
- HLock(browser->diff_te);
- InvalRect(&(*(browser->diff_te))->viewRect);
- HUnlock(browser->diff_te);
- } else {
+ TVTabStop(browser->diff_tv, settings.tabstop);
+
+ TVClear(browser->diff_tv);
+ TVUpdateScrollbar(browser->diff_tv, browser->diff_scroller);
+
+ if (amendment != NULL) {
SetCursor(*(GetCursor(watchCursor)));
- repo_show_diff_text(browser->repo, amendment, browser->diff_te);
+ repo_show_diff_text(browser->repo, amendment, browser->diff_tv);
SetCursor(&arrow);
}
- UpdateScrollbarForTE(browser->win, browser->diff_scroller,
- browser->diff_te, true);
+ TVUpdateScrollbar(browser->diff_tv, browser->diff_scroller);
browser_update_menu(browser);
}
@@ -525,31 +520,27 @@ browser_patch_ldefs(void)
void
browser_update_menu(struct browser *browser)
{
- TERec *diff;
Cell cell = { 0, 0 };
TextFont(systemFont);
TextFace(0);
TextSize(12);
- HLock(browser->diff_te);
- diff = *(browser->diff_te);
-
DisableItem(edit_menu, EDIT_MENU_CUT_ID);
- if (diff->selStart == diff->selEnd)
+ if ((*(browser->diff_tv))->sel_start == (*(browser->diff_tv))->sel_end)
DisableItem(edit_menu, EDIT_MENU_COPY_ID);
else
EnableItem(edit_menu, EDIT_MENU_COPY_ID);
DisableItem(edit_menu, EDIT_MENU_PASTE_ID);
- if (diff->nLines == 0)
+ if ((*(browser->diff_tv))->nlines == 0)
DisableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID);
else
EnableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID);
- HUnlock(browser->diff_te);
+ HUnlock(browser->diff_tv);
if (browser->repo->nfiles == 0)
HiliteControl(browser->diff_button, 255);
@@ -589,9 +580,10 @@ browser_update(struct focusable *focusable, EventRecor
case updateEvt:
FillRect(&browser->win->portRect, fill_pattern);
- r = (*(browser->diff_te))->viewRect;
- FillRect(&r, white);
- TEUpdate(&r, browser->diff_te);
+ HLock(browser->diff_tv);
+ r = (*(browser->diff_tv))->view;
+ HUnlock(browser->diff_tv);
+ TVUpdate(browser->diff_tv);
InsetRect(&r, -1, -1);
FrameRect(&r);
@@ -643,9 +635,11 @@ browser_mouse_down(struct focusable *focusable, EventR
GlobalToLocal(&p);
/* is it in diff text? */
- r = (*(browser->diff_te))->viewRect;
+ HLock(browser->diff_tv);
+ r = (*(browser->diff_tv))->view;
+ HUnlock(browser->diff_tv);
if (PtInRect(p, &r)) {
- TEClick(p, ((event->modifiers & shiftKey) != 0), browser->diff_te);
+ TVClick(browser->diff_tv, p, ((event->modifiers & shiftKey) != 0));
browser_update_menu(browser);
return;
}
@@ -737,10 +731,10 @@ browser_mouse_down(struct focusable *focusable, EventR
case inPageUp:
case inPageDown:
if (control == browser->diff_scroller)
- SetTrackControlTE(browser->diff_te);
+ TVSetTrackScrollControl(browser->diff_tv);
else
break;
- TrackControl(control, p, TrackMouseDownInControl);
+ TrackControl(control, p, TVTrackScrollControl);
break;
case inThumb:
val = GetCtlValue(control);
@@ -750,8 +744,7 @@ browser_mouse_down(struct focusable *focusable, EventR
if (adj != 0) {
val -= adj;
if (control == browser->diff_scroller)
- TEScroll(0, adj * TEGetHeight(0, 0, browser->diff_te),
- browser->diff_te);
+ TVScroll(browser->diff_tv, 0, adj);
SetCtlValue(control, val);
}
break;
@@ -767,10 +760,10 @@ browser_handle_menu(struct focusable *focusable, short
case EDIT_MENU_ID:
switch (item) {
case EDIT_MENU_COPY_ID:
- TECopy(browser->diff_te);
+ TVCopy(browser->diff_tv);
return true;
case EDIT_MENU_SELECT_ALL_ID:
- TESetSelect(0, 1024 * 32, browser->diff_te);
+ TVSetSelect(browser->diff_tv, 0, LONG_MAX);
return true;
}
break;
--- browser.h Tue Oct 31 13:07:23 2023
+++ browser.h Thu Oct 24 11:22:22 2024
@@ -18,9 +18,9 @@
#define __BROWSER_H__
#include <stdlib.h>
-
#include "committer.h"
#include "repo.h"
+#include "textview.h"
enum {
BROWSER_STATE_IDLE,
@@ -42,7 +42,7 @@ struct browser {
struct repo *repo;
ListHandle file_list;
ListHandle amendment_list;
- TEHandle diff_te;
+ TVHandle diff_tv;
ControlHandle diff_scroller;
ControlHandle diff_button;
struct committer *committer;
--- committer.c Mon Mar 25 15:53:32 2024
+++ committer.c Fri Oct 25 20:21:01 2024
@@ -25,7 +25,6 @@
#include "focusable.h"
#include "repo.h"
#include "settings.h"
-#include "tetab.h"
#include "util.h"
#define LABEL_FONT geneva
@@ -53,7 +52,7 @@ bool committer_handle_menu(struct focusable *focusable
void committer_generate_diff(struct committer *committer);
void committer_update_menu(struct committer *committer);
void committer_commit(struct committer *committer);
-void diff_append_line(char *str, size_t len, bool flush);
+void diff_append_line(char *str, size_t len);
void diff_chunk_write(void);
void diff_finish(void);
@@ -63,7 +62,7 @@ committer_init(struct browser *browser)
Str255 title, filename;
struct committer *committer;
struct focusable *focusable;
- Rect bounds = { 0 }, te_bounds = { 0 };
+ Rect bounds = { 0 }, te_bounds = { 0 }, padding;
TextStyle style;
short fh;
@@ -105,7 +104,6 @@ committer_init(struct browser *browser)
style.tsSize = 9;
TESetStyle(doFont | doSize, &style, false, committer->log_te);
TEAutoView(true, committer->log_te);
- TETabEnable(committer->log_te);
TEActivate(committer->log_te);
/* scrollbar for log message */
@@ -123,13 +121,11 @@ committer_init(struct browser *browser)
PADDING;
bounds.right = committer->win->portRect.right - SCROLLBAR_WIDTH -
PADDING;
- te_bounds = bounds;
- InsetRect(&te_bounds, 2, 2);
- committer->diff_te = TEStylNew(&te_bounds, &bounds);
- TEAutoView(true, committer->diff_te);
- TETabEnable(committer->diff_te);
- (*(committer->diff_te))->caretHook = NullCaretHook;
- TEActivate(committer->diff_te);
+ SetRect(&padding, 2, 2, 2, 2);
+ committer->diff_tv = TVNew(&bounds, &padding);
+ TVLineWrap(committer->diff_tv, false);
+ TVTabStop(committer->diff_tv, settings.tabstop);
+ TVAutoCalc(committer->diff_tv, false);
/* scrollbar for diff */
bounds.left = bounds.right;
@@ -145,9 +141,9 @@ committer_init(struct browser *browser)
bounds.bottom = committer->win->portRect.bottom - PADDING;
bounds.top = bounds.bottom - 20;
committer->commit_button = NewControl(committer->win, &bounds,
- "\pCommit", true, 1, 1, 1, pushButProc, 0L);
+ "\pAmend", true, 1, 1, 1, pushButProc, 0L);
- committer->last_te = committer->log_te;
+ committer->log_focused = true;
focusable = xmalloczero(sizeof(struct focusable));
focusable->cookie = committer;
@@ -177,7 +173,7 @@ committer_close(struct focusable *focusable)
xfree(&committer->diffed_files);
TEDispose(committer->log_te);
- TEDispose(committer->diff_te);
+ TVDispose(committer->diff_tv);
DisposeWindow(committer->win);
xfree(&committer);
@@ -193,7 +189,7 @@ committer_idle(struct focusable *focusable, EventRecor
switch (committer->state) {
case COMMITTER_STATE_IDLE:
- if (committer->last_te == committer->log_te)
+ if (committer->log_focused)
TEIdle(committer->log_te);
break;
case COMMITTER_STATE_DO_DIFF:
@@ -225,18 +221,21 @@ committer_update(struct focusable *focusable, EventRec
TextSize(LABEL_FONT_SIZE);
DrawText("Log:", 0, 4);
+ HLock(committer->log_te);
r = (*(committer->log_te))->viewRect;
+ HUnlock(committer->log_te);
TEUpdate(&r, committer->log_te);
InsetRect(&r, -1, -1);
FrameRect(&r);
- r = (*(committer->diff_te))->viewRect;
- TEUpdate(&r, committer->diff_te);
+ HLock(committer->diff_tv);
+ r = (*(committer->diff_tv))->view;
+ TVUpdate(committer->diff_tv);
InsetRect(&r, -1, -1);
FrameRect(&r);
- if ((*(committer->diff_te))->nLines > 0) {
- r = (*(committer->diff_te))->viewRect;
+ if ((*(committer->diff_tv))->nlines > 0) {
+ r = (*(committer->diff_tv))->view;
MoveTo(r.left, r.bottom + FontHeight(monaco, 9) + PADDING);
TextFont(monaco);
TextSize(9);
@@ -244,6 +243,7 @@ committer_update(struct focusable *focusable, EventRec
committer->diff_adds, committer->diff_subs);
DrawText(buf, 0, len);
}
+ HUnlock(committer->diff_tv);
committer_update_menu(committer);
UpdtControl(committer->win, committer->win->visRgn);
@@ -252,10 +252,8 @@ committer_update(struct focusable *focusable, EventRec
case activateEvt:
if (event->modifiers & activeFlag) {
TEActivate(committer->log_te);
- TEActivate(committer->diff_te);
} else {
TEDeactivate(committer->log_te);
- TEDeactivate(committer->diff_te);
}
break;
}
@@ -267,7 +265,6 @@ committer_suspend(struct focusable *focusable)
struct committer *committer = (struct committer *)focusable->cookie;
TEDeactivate(committer->log_te);
- TEDeactivate(committer->diff_te);
}
void
@@ -276,7 +273,6 @@ committer_resume(struct focusable *focusable)
struct committer *committer = (struct committer *)focusable->cookie;
TEActivate(committer->log_te);
- TEActivate(committer->diff_te);
}
void
@@ -310,19 +306,22 @@ committer_mouse_down(struct focusable *focusable, Even
p = event->where;
GlobalToLocal(&p);
- r = (*(committer->diff_te))->viewRect;
+ HLock(committer->log_te);
+ r = (*(committer->log_te))->viewRect;
+ HUnlock(committer->log_te);
if (PtInRect(p, &r)) {
- TEClick(p, ((event->modifiers & shiftKey) != 0),
- committer->diff_te);
- committer->last_te = committer->diff_te;
+ TEClick(p, ((event->modifiers & shiftKey) != 0), committer->log_te);
+ committer->log_focused = true;
committer_update_menu(committer);
return;
}
- r = (*(committer->log_te))->viewRect;
+ HLock(committer->diff_tv);
+ r = (*(committer->diff_tv))->view;
+ HUnlock(committer->diff_tv);
if (PtInRect(p, &r)) {
- TEClick(p, ((event->modifiers & shiftKey) != 0), committer->log_te);
- committer->last_te = committer->log_te;
+ TVClick(committer->diff_tv, p, ((event->modifiers & shiftKey) != 0));
+ committer->log_focused = false;
committer_update_menu(committer);
return;
}
@@ -337,13 +336,14 @@ committer_mouse_down(struct focusable *focusable, Even
case inDownButton:
case inPageUp:
case inPageDown:
- if (control == committer->diff_scroller)
- SetTrackControlTE(committer->diff_te);
- else if (control == committer->log_scroller)
+ if (control == committer->log_scroller) {
SetTrackControlTE(committer->log_te);
- else
- break;
- TrackControl(control, p, TrackMouseDownInControl);
+ TrackControl(control, p, TrackMouseDownInControl);
+ } else if (control == committer->diff_scroller) {
+ TVSetTrackScrollControl(committer->diff_tv);
+ TrackControl(control, p, TVTrackScrollControl);
+ } else
+ TrackControl(control, p, 0L);
break;
case inThumb:
val = GetCtlValue(control);
@@ -353,8 +353,7 @@ committer_mouse_down(struct focusable *focusable, Even
if (adj != 0) {
val -= adj;
if (control == committer->diff_scroller)
- TEScroll(0, adj * TEGetHeight(0, 0, committer->diff_te),
- committer->diff_te);
+ TVScroll(committer->diff_tv, 0, adj);
else if (control == committer->log_scroller)
TEScroll(0, adj * TEGetHeight(0, 0, committer->log_te),
committer->log_te);
@@ -367,22 +366,10 @@ committer_mouse_down(struct focusable *focusable, Even
void
committer_update_menu(struct committer *committer)
{
- HLock(committer->diff_te);
+ HLock(committer->diff_tv);
HLock(committer->log_te);
- if (committer->last_te == committer->diff_te) {
- DisableItem(edit_menu, EDIT_MENU_CUT_ID);
- if ((*(committer->diff_te))->selStart ==
- (*(committer->diff_te))->selEnd)
- DisableItem(edit_menu, EDIT_MENU_COPY_ID);
- else
- EnableItem(edit_menu, EDIT_MENU_COPY_ID);
- if ((*(committer->diff_te))->nLines > 0)
- EnableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID);
- else
- DisableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID);
- DisableItem(edit_menu, EDIT_MENU_PASTE_ID);
- } else if (committer->last_te == committer->log_te) {
+ if (committer->log_focused) {
if ((*(committer->log_te))->selStart ==
(*(committer->log_te))->selEnd) {
DisableItem(edit_menu, EDIT_MENU_CUT_ID);
@@ -396,6 +383,18 @@ committer_update_menu(struct committer *committer)
else
DisableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID);
EnableItem(edit_menu, EDIT_MENU_PASTE_ID);
+ } else {
+ DisableItem(edit_menu, EDIT_MENU_CUT_ID);
+ if ((*(committer->diff_tv))->sel_start ==
+ (*(committer->diff_tv))->sel_end)
+ DisableItem(edit_menu, EDIT_MENU_COPY_ID);
+ else
+ EnableItem(edit_menu, EDIT_MENU_COPY_ID);
+ if ((*(committer->diff_tv))->nlines > 0)
+ EnableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID);
+ else
+ DisableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID);
+ DisableItem(edit_menu, EDIT_MENU_PASTE_ID);
}
DisableItem(repo_menu, REPO_MENU_ADD_FILE_ID);
@@ -406,7 +405,7 @@ committer_update_menu(struct committer *committer)
DisableItem(amendment_menu, AMENDMENT_MENU_EXPORT_ID);
HUnlock(committer->log_te);
- HUnlock(committer->diff_te);
+ HUnlock(committer->diff_tv);
EnableItem(repo_menu, 0);
@@ -423,7 +422,6 @@ committer_generate_diff(struct committer *committer)
short i, all_files, ret;
short *selected_files = NULL;
short nselected_files = 0;
- TextStyle style;
SetCursor(*(GetCursor(watchCursor)));
@@ -441,14 +439,7 @@ committer_generate_diff(struct committer *committer)
committer->canceled = false;
committer->diffed_files = xcalloc(sizeof(struct diffed_file),
nselected_files);
- committer->diff_too_big = false;
- HLock(committer->diff_te);
-
- style.tsFont = monaco;
- style.tsSize = 9;
- TESetStyle(doFont | doSize, &style, false, committer->diff_te);
-
all_files = browser_is_all_files_selected(committer->browser);
committer_diffing = committer;
@@ -487,6 +478,12 @@ committer_generate_diff(struct committer *committer)
diff_finish();
committer->ndiffed_files++;
+
+ if (ret == 1) {
+ TVCalcLines(committer->diff_tv);
+ TVUpdate(committer->diff_tv);
+ TVUpdateScrollbar(committer->diff_tv, committer->diff_scroller);
+ }
}
committer_diffing = NULL;
@@ -494,10 +491,7 @@ committer_generate_diff(struct committer *committer)
if (committer->canceled)
committer->allow_commit = false;
- HUnlock(committer->diff_te);
InvalRect(&committer->win->portRect);
- UpdateScrollbarForTE(committer->win, committer->diff_scroller,
- committer->diff_te, true);
progress(NULL);
@@ -517,31 +511,45 @@ void
committer_commit(struct committer *committer)
{
struct browser *browser;
- short loglen;
+ Handle diff;
+ short loglen, n;
HLock(committer->log_te);
- HLock(committer->diff_te);
-
loglen = (*(committer->log_te))->teLength;
SetCursor(*(GetCursor(watchCursor)));
- progress("Committing changes...");
+ progress("Saving amendment...");
- repo_amend(committer->browser->repo, committer->diffed_files,
- committer->ndiffed_files, committer->diff_adds, committer->diff_subs,
- settings.author, (*(committer->log_te))->hText, loglen,
- (*(committer->diff_te))->hText, committer->diff_te_len);
+ diff = NewHandle(committer->diff_len);
+ if (diff != NULL) {
+ if (TVGetText(committer->diff_tv, *diff, 0, committer->diff_len) !=
+ committer->diff_len) {
+ progress(NULL);
+ panic("Wrong amount of diff text copied");
+ }
+
+ repo_amend(committer->browser->repo, committer->diffed_files,
+ committer->ndiffed_files, committer->diff_adds,
+ committer->diff_subs, settings.author,
+ (*(committer->log_te))->hText, loglen, diff,
+ committer->diff_len);
+ }
- HUnlock(committer->diff_te);
HUnlock(committer->log_te);
progress(NULL);
SetCursor(&arrow);
- browser = committer->browser;
- browser_close_committer(committer->browser);
- browser->state = BROWSER_STATE_UPDATE_AMENDMENT_LIST;
+ if (diff == NULL)
+ warn("Failed allocating %ld bytes for diff",
+ committer->diff_len);
+ else {
+ DisposHandle(diff);
+ browser = committer->browser;
+ browser_close_committer(committer->browser);
+ browser->state = BROWSER_STATE_UPDATE_AMENDMENT_LIST;
+ }
}
bool
@@ -553,7 +561,7 @@ committer_handle_menu(struct focusable *focusable, sho
case EDIT_MENU_ID:
switch (item) {
case EDIT_MENU_CUT_ID:
- if (committer->last_te == committer->log_te) {
+ if (committer->log_focused) {
TECut(committer->log_te);
UpdateScrollbarForTE(committer->win,
committer->log_scroller, committer->log_te, false);
@@ -561,12 +569,14 @@ committer_handle_menu(struct focusable *focusable, sho
}
return true;
case EDIT_MENU_COPY_ID:
- if (committer->last_te)
- TECopy(committer->last_te);
+ if (committer->log_focused)
+ TECopy(committer->log_te);
+ else
+ TVCopy(committer->diff_tv);
committer_update_menu(committer);
return true;
case EDIT_MENU_PASTE_ID:
- if (committer->last_te == committer->log_te) {
+ if (committer->log_focused) {
TEPaste(committer->log_te);
UpdateScrollbarForTE(committer->win,
committer->log_scroller, committer->log_te, false);
@@ -574,8 +584,10 @@ committer_handle_menu(struct focusable *focusable, sho
}
return true;
case EDIT_MENU_SELECT_ALL_ID:
- if (committer->last_te)
- TESetSelect(0, 1024 * 32, committer->last_te);
+ if (committer->log_focused)
+ TESetSelect(0, 1024 * 32, committer->log_te);
+ else
+ TVSetSelect(committer->diff_tv, 0, LONG_MAX);
committer_update_menu(committer);
return true;
}
@@ -596,6 +608,10 @@ diff_output(const char *format, ...)
if (committer_diffing->diff_line == NULL) {
committer_diffing->diff_line = xmalloc(DIFF_LINE_SIZE);
+ if (committer_diffing->diff_line == NULL) {
+ warn("Out of memory");
+ return 0;
+ }
committer_diffing->diff_line_pos = 0;
}
@@ -606,7 +622,7 @@ diff_output(const char *format, ...)
if (format[0] == '%' && format[1] == 'c' && format[2] == '\0') {
/* avoid having to vsprintf just to append 1 character */
- committer_diffing->diff_line[last_pos] = va_arg(argptr, int);
+ committer_diffing->diff_line[last_pos] = va_arg(argptr, short);
len = 1;
} else
len = vsprintf(committer_diffing->diff_line + last_pos, format,
@@ -624,7 +640,7 @@ diff_output(const char *format, ...)
for (i = last_pos; i < committer_diffing->diff_line_pos; i++) {
if (committer_diffing->diff_line[i] == '\r') {
diff_append_line(committer_diffing->diff_line + last_line,
- i - last_line + 1, false);
+ i - last_line + 1);
last_line = i + 1;
}
}
@@ -642,71 +658,30 @@ diff_output(const char *format, ...)
}
void
-diff_append_line(char *str, size_t len, bool flush)
+diff_append_line(char *str, size_t len)
{
+ struct TVStyle style;
+
if (committer_diffing == NULL)
panic("diff_append_line without committer_diffing");
- if (committer_diffing->diff_chunk == NULL) {
- committer_diffing->diff_chunk = xNewHandle(DIFF_CHUNK_SIZE);
- committer_diffing->diff_chunk_pos = 0;
- }
-
if (str[0] == '-' && str[1] != '-')
committer_diffing->diff_subs++;
else if (str[0] == '+' && str[1] != '+')
committer_diffing->diff_adds++;
- if (committer_diffing->diff_chunk_pos + len >= DIFF_CHUNK_SIZE)
- diff_chunk_write();
-
- HLock(committer_diffing->diff_chunk);
- memcpy(*(committer_diffing->diff_chunk) +
- committer_diffing->diff_chunk_pos, str, len);
- HUnlock(committer_diffing->diff_chunk);
- committer_diffing->diff_chunk_pos += len;
+ style.font = DIFF_FONT;
+ style.size = DIFF_FONT_SIZE;
+ style.style = 0;
- if (flush)
- diff_chunk_write();
-
+ TVAppend(committer_diffing->diff_tv, &style, str, len);
+ committer_diffing->diff_len += len;
+
if (CommandPeriodPressed())
committer_diffing->canceled = true;
}
void
-diff_chunk_write(void)
-{
- if (committer_diffing == NULL)
- panic("diff_chunk_write without committer_diffing");
-
- HLock(committer_diffing->diff_chunk);
-
- if (committer_diffing->diff_te_len +
- committer_diffing->diff_chunk_pos > MAX_TEXTEDIT_SIZE) {
- HUnlock((*(committer_diffing->diff_te))->hText);
- SetHandleSize((*(committer_diffing->diff_te))->hText,
- committer_diffing->diff_te_len +
- committer_diffing->diff_chunk_pos);
- if (MemError())
- panic("Out of memory! Can't expand diff TE by %lu bytes.",
- committer_diffing->diff_chunk_pos);
- HLock((*(committer_diffing->diff_te))->hText);
- memcpy(*(*(committer_diffing->diff_te))->hText +
- committer_diffing->diff_te_len, *(committer_diffing->diff_chunk),
- committer_diffing->diff_chunk_pos);
- HUnlock((*(committer_diffing->diff_te))->hText);
- } else {
- TEStylInsert(*(committer_diffing->diff_chunk),
- committer_diffing->diff_chunk_pos, 0,
- committer_diffing->diff_te);
- }
- HUnlock(committer_diffing->diff_chunk);
-
- committer_diffing->diff_te_len += committer_diffing->diff_chunk_pos;
- committer_diffing->diff_chunk_pos = 0;
-}
-
-void
diff_finish(void)
{
if (committer_diffing == NULL)
@@ -715,20 +690,8 @@ diff_finish(void)
if (committer_diffing->diff_line != NULL) {
if (committer_diffing->diff_line_pos)
diff_append_line(committer_diffing->diff_line,
- committer_diffing->diff_line_pos, true);
+ committer_diffing->diff_line_pos);
xfree(&committer_diffing->diff_line);
}
-
- if (committer_diffing->diff_chunk != NULL) {
- if (committer_diffing->diff_chunk_pos)
- diff_chunk_write();
- DisposHandle(committer_diffing->diff_chunk);
- committer_diffing->diff_chunk = NULL;
- }
-
- HUnlock((*(committer_diffing->diff_te))->hText);
- SetHandleSize((*(committer_diffing->diff_te))->hText,
- committer_diffing->diff_te_len);
- TECalText(committer_diffing->diff_te);
}
\ No newline at end of file
--- committer.h Thu Mar 21 09:27:25 2024
+++ committer.h Fri Oct 25 13:31:25 2024
@@ -18,6 +18,7 @@
#define __COMMITTER_H__
#include "browser.h"
+#include "textview.h"
#include "util.h"
#define WAIT_DLOG_ID 128
@@ -34,8 +35,9 @@ struct committer {
short state;
TEHandle log_te;
ControlHandle log_scroller;
- TEHandle diff_te;
- unsigned long diff_te_len;
+ bool log_focused;
+ TVHandle diff_tv;
+ unsigned long diff_len;
ControlHandle diff_scroller;
ControlHandle commit_button;
short ndiffed_files;
@@ -44,14 +46,9 @@ struct committer {
bool canceled;
short diff_adds;
short diff_subs;
- bool diff_too_big;
#define DIFF_LINE_SIZE 512
char *diff_line;
size_t diff_line_pos;
-#define DIFF_CHUNK_SIZE (1024 * 4)
- Handle diff_chunk;
- size_t diff_chunk_pos;
- TEHandle last_te;
};
void committer_init(struct browser *browser);
--- editor.c Mon Mar 25 15:55:04 2024
+++ editor.c Thu Oct 24 21:11:54 2024
@@ -24,7 +24,6 @@
#include "editor.h"
#include "focusable.h"
#include "repo.h"
-#include "tetab.h"
#include "util.h"
#define LABEL_FONT geneva
@@ -128,7 +127,6 @@ editor_init(struct browser *browser, struct repo_amend
style.tsSize = 9;
TESetStyle(doFont | doSize, &style, false, editor->log_te);
TEAutoView(true, editor->log_te);
- TETabEnable(editor->log_te);
HLock(amendment->log);
TEInsert(*(amendment->log), amendment->log_len, editor->log_te);
HUnlock(amendment->log);
--- repo.c Wed Oct 2 12:56:16 2024
+++ repo.c Thu Oct 24 21:50:38 2024
@@ -422,20 +422,16 @@ repo_diff_header(struct repo *repo, struct repo_amendm
void
repo_show_diff_text(struct repo *repo, struct repo_amendment *amendment,
- TEHandle te)
+ TVHandle tv)
{
- char truncbuf[64];
struct bile_object *bob;
- TextStyle style;
+ struct TVStyle style;
size_t size;
char *dtext;
char *buf = NULL;
unsigned long diff_len, all_len;
- short header_len, blen, height, trunc = 0;
- unsigned short warn_off;
+ short header_len, blen, height;
- TESetText("", 0, te);
-
bob = bile_find(repo->bile, REPO_DIFF_RTYPE, amendment->id);
if (bob == NULL) {
warn("Failed finding DIFF %d, corrupted repo?", amendment->id);
@@ -449,12 +445,11 @@ repo_show_diff_text(struct repo *repo, struct repo_ame
header_len = repo_diff_header(repo, amendment, &buf);
all_len = header_len + diff_len;
- if (all_len >= MAX_TEXTEDIT_SIZE) {
- all_len = MAX_TEXTEDIT_SIZE;
- trunc = 1;
- }
-
dtext = xmalloc(all_len);
+ if (dtext == NULL) {
+ warn("Failed allocating %ld bytes for diff", all_len);
+ return;
+ }
memcpy(dtext, buf, header_len);
xfree(&buf);
@@ -464,22 +459,10 @@ repo_show_diff_text(struct repo *repo, struct repo_ame
panic("failed reading diff %lu: %d", amendment->id,
bile_error(repo->bile));
- if (trunc) {
- warn_off = MAX_TEXTEDIT_SIZE - header_len -
- strlen(REPO_DIFF_TOO_BIG);
- blen = snprintf(truncbuf, sizeof(truncbuf), REPO_DIFF_TOO_BIG,
- diff_len - warn_off);
- memcpy(dtext + MAX_TEXTEDIT_SIZE - blen, truncbuf, blen);
- }
-
- /* manually reset scroll without TESetSelect(0, 0, te) which redraws */
- height = (*te)->destRect.bottom - (*te)->destRect.top;
- (*te)->destRect.top = (*te)->viewRect.top;
- (*te)->destRect.bottom = (*te)->viewRect.top + height;
- style.tsFont = monaco;
- style.tsSize = 9;
- TESetStyle(doFont | doSize, &style, false, te);
- TEStylInsert(dtext, all_len, 0, te);
+ style.font = DIFF_FONT;
+ style.size = DIFF_FONT_SIZE;
+ style.style = 0;
+ TVAppend(tv, &style, dtext, all_len);
xfree(&dtext);
xfree(&bob);
@@ -982,7 +965,7 @@ repo_export_amendment(struct repo *repo, struct repo_a
void
repo_amend(struct repo *repo, struct diffed_file *diffed_files,
short nfiles, short adds, short subs, char *author, Handle log,
- short loglen, Handle diff, unsigned long difflen)
+ short loglen, Handle diff, size_t difflen)
{
Str255 tfilename;
struct repo_amendment *amendment;
--- repo.h Wed Mar 20 10:25:16 2024
+++ repo.h Thu Oct 24 20:57:23 2024
@@ -19,6 +19,7 @@
#include <time.h>
#include "bile.h"
+#include "textview.h"
#define REPO_TYPE 'AMRP'
@@ -87,13 +88,13 @@ struct repo *repo_open(AppFile *file);
struct repo *repo_create(void);
void repo_close(struct repo *repo);
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_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,
size_t size);
struct repo_file *repo_file_with_id(struct repo *repo, short id);
void repo_show_diff_text(struct repo *repo, struct repo_amendment *amendment,
- TEHandle te);
+ TVHandle tv);
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);
@@ -104,7 +105,7 @@ void repo_export_amendment(struct repo *repo,
struct repo_amendment *amendment, short vrefnum, Str255 filename);
void repo_amend(struct repo *repo, struct diffed_file *diffed_files,
short nfiles, short adds, short subs, char *author, Handle log,
- short loglen, Handle diff, unsigned long difflen);
+ short loglen, Handle diff, size_t difflen);
void repo_marshall_amendment(struct repo_amendment *amendment,
char **retdata, unsigned long *retlen);
void repo_backup(struct repo *repo);