Skip to content

Commit

Permalink
Fix incorrect filename coloring in tig status (#1326)
Browse files Browse the repository at this point in the history
Due to the way commit a37ce5c updated
src/draw.c:draw_filename() the whole line in `tig status` got colored
according to `stat-*` which are supposed to color only status markers.

This reverts part of that commit which was done for consistency with the
changes made to draw_filesize().

[tk: also revert and rework draw_file_size() for consistency and add
 comments.]
  • Loading branch information
xaizek authored and koutcher committed Apr 8, 2024
1 parent d4a13ff commit 84e6101
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
8 changes: 8 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Release notes
=============

master
------

Bug fixes:

- Fix `stat-*` coloring file names in `tig status` instead of just
markers (regression in 2.5.9). (#1326)

tig-2.5.9
---------
Expand Down
12 changes: 7 additions & 5 deletions src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,12 @@ draw_id(struct view *view, struct view_column *column, const char *id)
}

static bool
draw_filename(struct view *view, struct view_column *column, enum line_type type, const char *filename)
draw_filename(struct view *view, struct view_column *column, const char *filename, mode_t mode)
{
size_t width = filename ? utf8_width(filename) : 0;
bool trim = width >= column->width;
/* Note, type for filename field is independent from line->type. */
enum line_type type = S_ISDIR(mode) ? LINE_DIRECTORY : LINE_FILE;
int column_width = column->width ? column->width : width;

if (column->opt.file_name.display == FILENAME_NO)
Expand All @@ -289,9 +291,9 @@ draw_filename(struct view *view, struct view_column *column, enum line_type type
}

static bool
draw_file_size(struct view *view, struct view_column *column, enum line_type type, unsigned long size)
draw_file_size(struct view *view, struct view_column *column, unsigned long size, mode_t mode)
{
const char *str = type == LINE_FILE ? mkfilesize(size, column->opt.file_size.display) : NULL;
const char *str = S_ISREG(mode) ? mkfilesize(size, column->opt.file_size.display) : NULL;

if (!column->width || column->opt.file_size.display == FILE_SIZE_NO)
return false;
Expand Down Expand Up @@ -517,7 +519,7 @@ view_column_draw(struct view *view, struct line *line, unsigned int lineno)
continue;

case VIEW_COLUMN_FILE_SIZE:
if (draw_file_size(view, column, line->type, column_data.file_size ? *column_data.file_size : 0))
if (draw_file_size(view, column, column_data.file_size ? *column_data.file_size : 0, mode))
return true;
continue;

Expand All @@ -528,7 +530,7 @@ view_column_draw(struct view *view, struct line *line, unsigned int lineno)
continue;

case VIEW_COLUMN_FILE_NAME:
if (draw_filename(view, column, line->type, column_data.file_name))
if (draw_filename(view, column, column_data.file_name, mode))
return true;
continue;

Expand Down
5 changes: 2 additions & 3 deletions src/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ tree_read(struct view *view, struct buffer *buf, bool force_stop)
struct tree_state *state = view->private;
struct tree_entry *data;
struct line *entry, *line;
enum line_type type;
/* Note, type computed here is only used for sorting, not for drawing. */
enum line_type type = LINE_DEFAULT;
char *pos;
char *mode;
char *id;
Expand All @@ -238,8 +239,6 @@ tree_read(struct view *view, struct buffer *buf, bool force_stop)
type = LINE_FILE;
else if (!strncmp(pos, "tree", STRING_SIZE("tree")))
type = LINE_DIRECTORY;
else
type = LINE_DEFAULT;

/* 95925677ca47beb0b8cce7c0e0011bcc3f61470f */
id = strchr(pos, ' ');
Expand Down

0 comments on commit 84e6101

Please sign in to comment.