tig icon indicating copy to clipboard operation
tig copied to clipboard

Display an ellipsis (…) on commits longer than 1 line.

Open unode opened this issue 8 years ago • 9 comments

Good practices recommend the use of multi-line commits with the first line being a short summary. Most often the entire commit is but one line.

When using tig's default 'view' mode, if you want to know whether a commit has additional information you have to open each commit. There is currently no visual clue that a commit is single or multi-line.

Similar to github's commit view I propose that an ellipsis (), or another user configurable character, is added to the end of the first line of multi-line commit messages.

The result is a minimal but useful visual change (space before ellipsis added for clarity):

2017-07-06 17:51 Roland Walker           o erase status line at exit time …
2017-07-06 20:54 Roland Walker           o reduce flicker in file finder; avoid wclear

unode avatar Jul 09 '17 21:07 unode

You can scroll horizontally to see more text which was one of the reasons that Tig doesn't draw the ellipsis (delimiter) (since e81ce2db060515a6b4c8c3e3dd6bebcff30d2345). I am OK with bringing it back, but will have to take a closer look.

jonas avatar Jul 10 '17 16:07 jonas

Hi Jonas, the old behavior was somewhat different. Testing the commit, I see a ~ if the first line of the commit is longer than the available screen/draw area. If the screen is wide enough to display the entire line you don't see the ~ anymore.

What I'm proposing is somewhat different and independent of how wide the draw area is.

In the git log --pretty= jargon, what I'd like to have is something similar to git log --pretty='%s …' but only add the if %b is not an empty string.

unode avatar Jul 10 '17 19:07 unode

OK, I think I understand. You want to show for multi-line commit messages.

jonas avatar Jul 10 '17 20:07 jonas

Exactly. Basically letting the reader know that there is additional information on that commit.

Thanks for considering it.

unode avatar Jul 10 '17 20:07 unode

I had wanted this too, and had drafted the crude proof-of-concept below.

What would probably be more clever is to use %B%x00 in the format instead of %s (emitting the entire commit message), accumulate lines into title until a line starts with NUL, compress interior whitespace, and display what fits.

diff --git a/src/main.c b/src/main.c
index 2db26c7bd..e8dc9c166 100644
--- a/src/main.c
+++ b/src/main.c
@@ -436,12 +436,19 @@ main_read(struct view *view, struct buffer *buf, bool force_stop)

                if (author) {
                        char *title = io_memchr(buf, author, 0);
+                       char amended_title[SIZEOF_STR];
+                       char *body_fragment;

                        parse_author_line(author, &commit->author, &commit->time);
                        if (state->with_graph)
                                graph->render_parents(graph, &commit->graph);
-                       if (title)
-                               main_add_commit(view, LINE_MAIN_COMMIT, commit, title, false);
+
+                       if (title) {
+                               body_fragment = io_memchr(buf, title, 0);
+                               string_format(amended_title, "%s%s", title, (body_fragment && *body_fragment) ? "..." : "");
+                       }
+
+                       main_add_commit(view, LINE_MAIN_COMMIT, commit, amended_title, false);
                }

                return true;
diff --git a/src/options.c b/src/options.c
index 3c6f5b121..d951b9092 100644
--- a/src/options.c
+++ b/src/options.c
@@ -149,8 +149,8 @@ const char *
 log_custom_pretty_arg(void)
 {
        return opt_mailmap
-               ? "--pretty=format:commit %m %H %P%x00%aN <%aE> %ad%x00%s"
-               : "--pretty=format:commit %m %H %P%x00%an <%ae> %ad%x00%s";
+               ? "--pretty=format:commit %m %H %P%x00%aN <%aE> %ad%x00%s%x00%<|(1,trunc)%b%x00"
+               : "--pretty=format:commit %m %H %P%x00%an <%ae> %ad%x00%s%x00%<|(1,trunc)%b%x00";
 }

 #define ENUM_ARG(enum_name, arg_string) ENUM_MAP_ENTRY(arg_string, enum_name)

rolandwalker avatar Jul 10 '17 21:07 rolandwalker

@rolandwalker Thanks, that seems to work.

Also made me realize that using is not that readable. Perhaps using a different color or symbol. Using ... is much better but takes 3 characters. I don't have a problem with this but other users may.

I guess making it configurable is the best compromise.

unode avatar Jul 11 '17 19:07 unode

interface idea

set main-view = … commit-title:yes,body=yes
color commit-body gray default

where body takes no, yes, or ellipsis, and defaults to no.

rolandwalker avatar Jul 12 '17 00:07 rolandwalker

It might be useful to make it possible to assign any string, like body=....

jonas avatar Jul 12 '17 03:07 jonas

I'd like to see this implemented as well.

For the meanwhile, here's an alias that I've created for git that accomplishes this...

alias.lx !f() { git log "$@" --graph --decorate --format=format:'%C(auto)%h%d%C(bold)%C(yellow)_BODY_START_%b_BODY_END_%C(auto)%s' | perl -0777 -n -e 's/_BODY_START__BODY_END_/ /gs; s/_BODY_START_([\s\S]+?)_BODY_END_/ [...] /gs; print' ; } ; f

rivy avatar Feb 06 '23 01:02 rivy