summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxaizek <xaizek@posteo.net>2024-04-07 23:58:55 +0300
committerThomas Koutcher <thomas.koutcher@online.fr>2024-04-08 18:59:52 +0200
commit84e6101313213f3f58bc1066d0c084e5e89277ac (patch)
tree75c3ad8386ccbe8cc1e4618463adf05b64192289
parentd4a13ffb111c06eef8ee958866f2a9a0d5298789 (diff)
Fix incorrect filename coloring in tig status (#1326)
Due to the way commit a37ce5cfe1f256b81092dda365b1d66450e0929e 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.]
-rw-r--r--NEWS.adoc8
-rw-r--r--src/draw.c12
-rw-r--r--src/tree.c5
3 files changed, 17 insertions, 8 deletions
diff --git a/NEWS.adoc b/NEWS.adoc
index 0e5000d6..d8249baa 100644
--- a/NEWS.adoc
+++ b/NEWS.adoc
@@ -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
---------
diff --git a/src/draw.c b/src/draw.c
index c2befa47..3b960f1b 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -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)
@@ -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;
@@ -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;
@@ -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;
diff --git a/src/tree.c b/src/tree.c
index e6c826f1..e18e57bf 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -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;
@@ -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, ' ');