summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonas Fonseca <jonas.fonseca@gmail.com>2018-03-19 07:43:55 -0400
committerJonas Fonseca <jonas.fonseca@elementai.com>2019-04-13 20:04:11 -0400
commit261c2763dda60b0aa421ca801cc032b33650f68f (patch)
tree7b3e091e6db139fbcecb3b5d62084dd0e047e5d0
parent6c1f9dde974319ca1b3aaa2c4d7fb9832eb4d0c7 (diff)
Show commit signatures in the main viewcommit-signatures
Fixes #754
-rw-r--r--NEWS.adoc7
-rw-r--r--include/tig/line.h3
-rw-r--r--include/tig/main.h5
-rw-r--r--include/tig/options.h4
-rw-r--r--include/tig/view.h1
-rw-r--r--src/diff.c4
-rw-r--r--src/draw.c30
-rw-r--r--src/io.c2
-rw-r--r--src/main.c21
-rw-r--r--src/options.c16
-rw-r--r--tigrc9
11 files changed, 89 insertions, 13 deletions
diff --git a/NEWS.adoc b/NEWS.adoc
index c589cf3e..0bd9dded 100644
--- a/NEWS.adoc
+++ b/NEWS.adoc
@@ -1,6 +1,13 @@
Release notes
=============
+master
+------
+
+Improvements:
+
+ - Show commit signatures in the main view. (gh:[#754])
+
tig-2.4.1
---------
diff --git a/include/tig/line.h b/include/tig/line.h
index bea8bf80..c3920200 100644
--- a/include/tig/line.h
+++ b/include/tig/line.h
@@ -93,7 +93,8 @@ struct ref;
_(PALETTE_12, ""), \
_(PALETTE_13, ""), \
_(GRAPH_COMMIT, ""), \
- _(SEARCH_RESULT, "")
+ _(SEARCH_RESULT, ""), \
+ _(SIGNATURE, "")
enum line_type {
#define DEFINE_LINE_ENUM(type, line) LINE_##type
diff --git a/include/tig/main.h b/include/tig/main.h
index c7737478..3e02d8fd 100644
--- a/include/tig/main.h
+++ b/include/tig/main.h
@@ -19,10 +19,11 @@
#include "tig/util.h"
struct commit {
- char id[SIZEOF_REV]; /* SHA1 ID. */
const struct ident *author; /* Author of the commit. */
struct time time; /* Date from the author ident. */
struct graph_canvas graph; /* Ancestry chain graphics. */
+ char id[SIZEOF_REV]; /* SHA1 ID. */
+ char signature;
char title[1]; /* First line of the commit message. */
};
@@ -31,6 +32,8 @@ struct main_state {
struct commit current;
char **reflog;
size_t reflogs;
+ char **signature;
+ size_t signatures;
int reflog_width;
char reflogmsg[SIZEOF_STR / 2];
enum line_type goto_line_type;
diff --git a/include/tig/options.h b/include/tig/options.h
index c0229199..98e82459 100644
--- a/include/tig/options.h
+++ b/include/tig/options.h
@@ -70,6 +70,8 @@ typedef struct view_column *view_settings;
_(show_changes, bool, VIEW_NO_FLAGS) \
_(show_notes, bool, VIEW_NO_FLAGS) \
_(show_untracked, bool, VIEW_NO_FLAGS) \
+ _(show_signature, bool, VIEW_NO_FLAGS) \
+ _(signatures, const char **, VIEW_NO_FLAGS) \
_(split_view_height, double, VIEW_RESET_DISPLAY) \
_(split_view_width, double, VIEW_RESET_DISPLAY) \
_(stage_view, view_settings, VIEW_NO_FLAGS) \
@@ -93,6 +95,7 @@ OPTION_INFO(DEFINE_OPTION_EXTERNS)
#define AUTHOR_COLUMN_OPTIONS(_) \
_(display, enum author, VIEW_NO_FLAGS) \
+ _(signature, bool, VIEW_NO_FLAGS) \
_(width, int, VIEW_NO_FLAGS) \
_(maxwidth, int, VIEW_NO_FLAGS) \
@@ -193,6 +196,7 @@ const char *log_custom_pretty_arg();
const char *use_mailmap_arg();
const char *diff_context_arg();
const char *show_notes_arg();
+const char *show_signature_arg();
/*
* Option loading and parsing.
diff --git a/include/tig/view.h b/include/tig/view.h
index 18813b56..ff44091d 100644
--- a/include/tig/view.h
+++ b/include/tig/view.h
@@ -186,6 +186,7 @@ struct view_column_data {
struct view_column *section;
const struct ident *author;
const char *commit_title;
+ char commit_signature;
const struct time *date;
const char *file_name;
const unsigned long *file_size;
diff --git a/src/diff.c b/src/diff.c
index 0db42e48..cf7a2766 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -27,8 +27,8 @@ diff_open(struct view *view, enum open_flags flags)
{
const char *diff_argv[] = {
"git", "show", encoding_arg, "--pretty=fuller", "--root",
- "--patch-with-stat", use_mailmap_arg(),
- show_notes_arg(), diff_context_arg(), ignore_space_arg(),
+ "--patch-with-stat", use_mailmap_arg(), show_notes_arg(),
+ show_signature_arg(), diff_context_arg(), ignore_space_arg(),
DIFF_ARGS, "%(cmdlineargs)", "--no-color", "%(commit)",
"--", "%(fileargs)", NULL
};
diff --git a/src/draw.c b/src/draw.c
index bec72108..9829eda7 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -242,7 +242,7 @@ draw_date(struct view *view, struct view_column *column, const struct time *time
}
static bool
-draw_author(struct view *view, struct view_column *column, const struct ident *author)
+draw_author(struct view *view, struct view_column *column, const struct ident *author, const char signature)
{
bool trim = author_trim(column->width);
const char *text = mkauthor(author, MAX(column->opt.author.width, column->opt.author.maxwidth),
@@ -251,7 +251,31 @@ draw_author(struct view *view, struct view_column *column, const struct ident *a
if (column->opt.author.display == AUTHOR_NO)
return false;
- return draw_field(view, LINE_AUTHOR, text, column->width, ALIGN_LEFT, trim);
+ if (draw_field(view, LINE_AUTHOR, text, column->width, ALIGN_LEFT, trim))
+ return true;
+
+ if (column->opt.author.signature) {
+ const char default_sign[] = { signature ? signature : ' ', 0 };
+ const char *sign = default_sign;
+
+ if (opt_signatures && signature) {
+ int i;
+
+ for (i = 0; opt_signatures[i]; i++) {
+ const char *alias = opt_signatures[i];
+ const char *sep = strchr(alias, '=');
+
+ if (sep && sep - alias == 1 && signature == *alias) {
+ sign = sep + 1;
+ break;
+ }
+ }
+ }
+
+ return draw_field(view, LINE_SIGNATURE, sign, 1, ALIGN_LEFT, false);
+ }
+
+ return false;
}
static bool
@@ -475,7 +499,7 @@ view_column_draw(struct view *view, struct line *line, unsigned int lineno)
continue;
case VIEW_COLUMN_AUTHOR:
- if (draw_author(view, column, column_data.author))
+ if (draw_author(view, column, column_data.author, column_data.commit_signature))
return true;
continue;
diff --git a/src/io.c b/src/io.c
index f60e98d4..720dcd5b 100644
--- a/src/io.c
+++ b/src/io.c
@@ -497,7 +497,7 @@ io_memchr(struct buffer *buf, char *data, int c)
{
char *pos;
- if (!buf || data < buf->data || buf->data + buf->size <= data)
+ if (!buf || !data || data < buf->data || buf->data + buf->size <= data)
return NULL;
pos = memchr(data, c, buf->size - (data - buf->data));
diff --git a/src/main.c b/src/main.c
index 797dbd04..6da4d9d2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -113,7 +113,7 @@ main_add_changes_commit(struct view *view, enum line_type type, const char *pare
char ids[SIZEOF_STR] = NULL_ID " ";
struct main_state *state = view->private;
struct graph *graph = state->graph;
- struct commit commit = {{0}};
+ struct commit commit = {0};
struct timeval now;
struct timezone tz;
@@ -354,6 +354,7 @@ main_get_column_data(struct view *view, const struct line *line, struct view_col
struct commit *commit = line->data;
column_data->author = commit->author;
+ column_data->commit_signature = commit->signature;
column_data->date = &commit->time;
column_data->id = commit->id;
if (state->reflogs)
@@ -454,9 +455,23 @@ main_read(struct view *view, struct buffer *buf, bool force_stop)
main_register_commit(view, &state->current, line, is_boundary);
if (author) {
- char *title = io_memchr(buf, author, 0);
+ char *title;
+
+ if (opt_show_signature) {
+ char *signature = io_memchr(buf, author, 0);
+ char *signer = io_memchr(buf, signature, 0);
+
+ title = io_memchr(buf, signer, 0);
+ if (signature)
+ commit->signature = *signature;
+ parse_author_line(author, &commit->author, &commit->time);
+ // if (signer && *signer)
+ // parse_author_line(signer, &commit->author, NULL);
+ } else {
+ title = io_memchr(buf, author, 0);
+ parse_author_line(author, &commit->author, &commit->time);
+ }
- parse_author_line(author, &commit->author, &commit->time);
if (state->with_graph)
graph->render_parents(graph, &commit->graph);
if (title)
diff --git a/src/options.c b/src/options.c
index efb2f1dd..0cafbb5f 100644
--- a/src/options.c
+++ b/src/options.c
@@ -148,9 +148,15 @@ use_mailmap_arg()
const char *
log_custom_pretty_arg(void)
{
+#define LOG_PRETTY_FORMAT(ident_and_signature) \
+ "--pretty=format:commit %m %H %P%x00" ident_and_signature "%x00%s"
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";
+ ? (opt_show_signature
+ ? LOG_PRETTY_FORMAT("%aN <%aE> %ad%x00%G?%x00%GS")
+ : LOG_PRETTY_FORMAT("%aN <%aE> %ad"))
+ : (opt_show_signature
+ ? LOG_PRETTY_FORMAT("%an <%ae> %ad%x00%G?%x00%GS")
+ : LOG_PRETTY_FORMAT("%an <%ae> %ad"));
}
#define ENUM_ARG(enum_name, arg_string) ENUM_MAP_ENTRY(arg_string, enum_name)
@@ -210,6 +216,12 @@ show_notes_arg()
return "";
}
+const char *
+show_signature_arg()
+{
+ return opt_show_signature ? "--show-signature" : "";
+}
+
void
update_options_from_argv(const char *argv[])
{
diff --git a/tigrc b/tigrc
index 35fa0b54..93923528 100644
--- a/tigrc
+++ b/tigrc
@@ -70,6 +70,8 @@
set blame-view = id:yes,color file-name:auto author:full date:default line-number:yes,interval=1 text
set grep-view = file-name:no line-number:yes,interval=1 text
set main-view = line-number:no,interval=5 id:no date:default author:full commit-title:yes,graph,refs,overflow=no
+# Show pgp commit signatures
+# set main-view-author-signature = yes
set refs-view = line-number:no id:no date:default author:full ref commit-title
set stash-view = line-number:no,interval=5 id:no date:default author:full commit-title
set status-view = line-number:no,interval=5 status:short file-name
@@ -110,6 +112,7 @@ set status-show-untracked-dirs = yes # Show files in untracked directories? (st
set status-show-untracked-files = yes # Show untracked files?
set ignore-space = no # Enum: no, all, some, at-eol (diff)
set show-notes = yes # When non-bool passed as `--show-notes=...` (diff)
+set show-signature = yes # When non-bool passed as `--show-notes=...` (diff)
#set diff-context = 3 # Number of lines to show around diff changes (diff)
#set diff-options = -C # User-defined options for `tig show` (git-diff)
#set diff-highlight = true # String (or bool): Path to diff-highlight script,
@@ -356,6 +359,7 @@ color "TaggerDate: " yellow default
color "Refs: " red default
color "Reflog: " red default
color "Reflog message: " yellow default
+color "gpg: " magenta default
color "stash@{" magenta default
color "commit " green default
color "parent " blue default
@@ -416,6 +420,11 @@ color palette-12 white default bold
color palette-13 red default bold
color graph-commit blue default
color search-result black yellow
+color signature magenta default bold
+
+set signatures = \
+ N= \
+ G=V
# Mappings for colors read from git configuration.
# Set to "no" to disable.