jcs
/amend
/amendments
/22
committer: Move diff_line and diff_chunk into committer struct
jcs made amendment 22 over 3 years ago
--- committer.c Mon Oct 18 16:47:01 2021
+++ committer.c Fri Oct 29 15:09:04 2021
@@ -31,20 +31,11 @@ struct stat stb1, stb2;
long diff_format, diff_context, status = 0;
char *ifdefname, *diffargs, *label[2], *ignore_pats;
-#define DIFF_LINE_SIZE 512
-Handle diff_line = NULL;
-size_t diff_line_pos = 0;
-
-#define DIFF_CHUNK_SIZE (1024 * 4)
-Handle diff_chunk = NULL;
-size_t diff_chunk_pos = 0;
-
static short padding = 10;
-static short diff_too_big = 0;
-DialogPtr committer_dialog = NULL;
+static DialogPtr committer_dialog = NULL;
-/* so diff_* know what it's operating on */
+/* so diff_* know what they're operating on */
struct committer *cur_committer = NULL;
void committer_generate_diff(struct committer *committer);
@@ -152,9 +143,9 @@ committer_init(struct browser *browser)
void
committer_close(struct committer *committer)
{
- if (diff_line != NULL) {
- DisposHandle(diff_line);
- diff_line = NULL;
+ if (committer->diff_line != NULL) {
+ DisposHandle(committer->diff_line);
+ committer->diff_line = NULL;
}
if (committer->diffed_files != NULL)
@@ -331,6 +322,12 @@ committer_update_menu(struct committer *committer)
else
EnableItem(edit_menu, EDIT_MENU_COPY_ID);
+ DisableItem(repo_menu, REPO_MENU_ADD_FILE_ID);
+ DisableItem(repo_menu, REPO_MENU_REVERT_FILE_ID);
+ DisableItem(repo_menu, REPO_MENU_APPLY_PATCH_ID);
+
+ DisableItem(commit_menu, COMMIT_MENU_EXPORT_ID);
+
HUnlock(committer->log_te);
HUnlock(committer->diff_te);
@@ -361,7 +358,7 @@ committer_generate_diff(struct committer *committer)
committer->diffed_files = xmalloc(sizeof(short) * nselected_files);
cur_committer = committer;
- diff_too_big = 0;
+ committer->diff_too_big = 0;
HLock(committer->diff_te);
@@ -462,48 +459,49 @@ diff_output(const char *format, ...)
va_list argptr;
size_t len, last_pos, last_line, i;
- if (diff_line == NULL) {
- diff_line = xNewHandle(DIFF_LINE_SIZE);
- diff_line_pos = 0;
- HLock(diff_line);
+ if (cur_committer->diff_line == NULL) {
+ cur_committer->diff_line = xNewHandle(DIFF_LINE_SIZE);
+ cur_committer->diff_line_pos = 0;
+ HLock(cur_committer->diff_line);
}
- last_pos = diff_line_pos;
+ last_pos = cur_committer->diff_line_pos;
last_line = 0;
va_start(argptr, format);
if (format[0] == '%' && format[1] == 'c' && format[2] == '\0') {
/* avoid having to vsprintf just to append 1 character */
- (*diff_line)[last_pos] = va_arg(argptr, int);
+ (*(cur_committer->diff_line))[last_pos] = va_arg(argptr, int);
len = 1;
} else
- len = vsprintf(*diff_line + last_pos, format, argptr);
+ len = vsprintf(*(cur_committer->diff_line) + last_pos, format,
+ argptr);
va_end(argptr);
- diff_line_pos += len;
- if (diff_line_pos >= DIFF_LINE_SIZE)
+ cur_committer->diff_line_pos += len;
+ if (cur_committer->diff_line_pos >= DIFF_LINE_SIZE)
err(1, "diff line overflow!");
- if (len == 1 && (*diff_line)[last_pos] != '\n')
+ if (len == 1 && (*(cur_committer->diff_line))[last_pos] != '\n')
return 1;
- for (i = last_pos; i < diff_line_pos; i++) {
- if (((char *)*diff_line)[i] == '\n') {
- ((char *)*diff_line)[i] = '\r';
- diff_append_line(*diff_line + last_line, i - last_line + 1,
- false);
+ for (i = last_pos; i < cur_committer->diff_line_pos; i++) {
+ if (((char *)*(cur_committer->diff_line))[i] == '\n') {
+ ((char *)*(cur_committer->diff_line))[i] = '\r';
+ diff_append_line(*(cur_committer->diff_line) + last_line,
+ i - last_line + 1, false);
last_line = i + 1;
}
}
- if (last_line == diff_line_pos) {
- diff_line_pos = 0;
+ if (last_line == cur_committer->diff_line_pos) {
+ cur_committer->diff_line_pos = 0;
} else if (last_line > 0) {
- memmove(*diff_line, *diff_line + last_line,
- diff_line_pos - last_line);
- diff_line_pos -= last_line;
+ memmove(*(cur_committer->diff_line), *(cur_committer->diff_line) +
+ last_line, cur_committer->diff_line_pos - last_line);
+ cur_committer->diff_line_pos -= last_line;
}
return len;
@@ -514,9 +512,9 @@ diff_append_line(char *str, size_t len, bool flush)
{
short tabsize;
- if (diff_chunk == NULL) {
- diff_chunk = xNewHandle(DIFF_CHUNK_SIZE);
- diff_chunk_pos = 0;
+ if (cur_committer->diff_chunk == NULL) {
+ cur_committer->diff_chunk = xNewHandle(DIFF_CHUNK_SIZE);
+ cur_committer->diff_chunk_pos = 0;
}
if (str[0] == '-' && str[1] != '-')
@@ -524,13 +522,14 @@ diff_append_line(char *str, size_t len, bool flush)
else if (str[0] == '+' && str[1] != '+')
cur_committer->diff_adds++;
- if (diff_chunk_pos + len >= DIFF_CHUNK_SIZE)
+ if (cur_committer->diff_chunk_pos + len >= DIFF_CHUNK_SIZE)
diff_chunk_write();
- HLock(diff_chunk);
- memcpy(*diff_chunk + diff_chunk_pos, str, len);
- HUnlock(diff_chunk);
- diff_chunk_pos += len;
+ HLock(cur_committer->diff_chunk);
+ memcpy(*(cur_committer->diff_chunk) + cur_committer->diff_chunk_pos,
+ str, len);
+ HUnlock(cur_committer->diff_chunk);
+ cur_committer->diff_chunk_pos += len;
if (flush)
diff_chunk_write();
@@ -539,45 +538,48 @@ diff_append_line(char *str, size_t len, bool flush)
void
diff_chunk_write(void)
{
- HLock(diff_chunk);
+ HLock(cur_committer->diff_chunk);
- if (cur_committer->diff_te_len + diff_chunk_pos > MAX_TEXTEDIT_SIZE) {
+ if (cur_committer->diff_te_len + cur_committer->diff_chunk_pos >
+ MAX_TEXTEDIT_SIZE) {
HUnlock((*(cur_committer->diff_te))->hText);
SetHandleSize((*(cur_committer->diff_te))->hText,
- cur_committer->diff_te_len + diff_chunk_pos);
+ cur_committer->diff_te_len + cur_committer->diff_chunk_pos);
if (MemError())
err(1, "Out of memory! Can't expand diff TE by %lu bytes.",
- diff_chunk_pos);
+ cur_committer->diff_chunk_pos);
HLock((*(cur_committer->diff_te))->hText);
memcpy(*(*(cur_committer->diff_te))->hText +
- cur_committer->diff_te_len, *diff_chunk, diff_chunk_pos);
+ cur_committer->diff_te_len, *(cur_committer->diff_chunk),
+ cur_committer->diff_chunk_pos);
HUnlock((*(cur_committer->diff_te))->hText);
} else {
- TEStylInsert(*diff_chunk, diff_chunk_pos, 0,
- cur_committer->diff_te);
+ TEStylInsert(*(cur_committer->diff_chunk),
+ cur_committer->diff_chunk_pos, 0, cur_committer->diff_te);
}
- HUnlock(diff_chunk);
+ HUnlock(cur_committer->diff_chunk);
- cur_committer->diff_te_len += diff_chunk_pos;
- diff_chunk_pos = 0;
+ cur_committer->diff_te_len += cur_committer->diff_chunk_pos;
+ cur_committer->diff_chunk_pos = 0;
}
void
diff_finish(void)
{
- if (diff_line != NULL) {
- if (diff_line_pos)
- diff_append_line(*diff_line, diff_line_pos, true);
+ if (cur_committer->diff_line != NULL) {
+ if (cur_committer->diff_line_pos)
+ diff_append_line(*(cur_committer->diff_line),
+ cur_committer->diff_line_pos, true);
- DisposHandle(diff_line);
- diff_line = NULL;
+ DisposHandle(cur_committer->diff_line);
+ cur_committer->diff_line = NULL;
}
- if (diff_chunk != NULL) {
- if (diff_chunk_pos)
+ if (cur_committer->diff_chunk != NULL) {
+ if (cur_committer->diff_chunk_pos)
diff_chunk_write();
- DisposHandle(diff_chunk);
- diff_chunk = NULL;
+ DisposHandle(cur_committer->diff_chunk);
+ cur_committer->diff_chunk = NULL;
}
HUnlock((*(cur_committer->diff_te))->hText);
--- committer.h Mon Oct 18 15:49:37 2021
+++ committer.h Fri Oct 29 14:56:42 2021
@@ -34,6 +34,13 @@ struct committer {
short *diffed_files;
short diff_adds;
short diff_subs;
+ short diff_too_big;
+#define DIFF_LINE_SIZE 512
+ Handle diff_line;
+ size_t diff_line_pos;
+#define DIFF_CHUNK_SIZE (1024 * 4)
+ Handle diff_chunk;
+ size_t diff_chunk_pos;
};
void committer_init(struct browser *browser);