static bool stage_diff_single_write(struct io *io, bool staged, struct line *line, struct line *single, struct line *end) { enum line_type write_as_normal = staged ? LINE_DIFF_ADD : LINE_DIFF_DEL; enum line_type ignore = staged ? LINE_DIFF_DEL : LINE_DIFF_ADD; while (line < end) { const char *prefix = ""; const char *data = box_text(line); if (line == single) { /* Write the complete line. */ } else if (line->type == write_as_normal) { prefix = " "; data = data + 1; } else if (line->type == ignore) { data = NULL; } if (data && !io_printf(io, "%s%s\n", prefix, data)) return false; line++; if (stage_diff_done(line, end)) break; } return true; }
static inline void log_copy_rev(struct view *view, struct line *line) { const char *text = box_text(line); size_t offset = get_graph_indent(text); string_copy_rev_from_commit_line(view->ref, text + offset); }
static bool stage_apply_line(struct io *io, struct line *diff_hdr, struct line *chunk, struct line *single, struct line *end) { struct chunk_header header; bool staged = stage_line_type == LINE_STAT_STAGED; int diff = single->type == LINE_DIFF_DEL ? -1 : 1; if (!parse_chunk_header(&header, box_text(chunk))) return false; if (staged) header.old.lines = header.new.lines - diff; else
static bool stage_diff_write(struct io *io, struct line *line, struct line *end) { while (line < end) { const char *text = box_text(line); if (!io_write(io, text, strlen(text)) || !io_write(io, "\n", 1)) return false; line++; if (stage_diff_done(line, end)) break; } return true; }