summaryrefslogtreecommitdiff
path: root/file
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-28 01:11:27 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-08-28 01:11:27 (GMT)
commitee34dad7776dd3fb3f658c78a331514eb5aa4f62 (patch)
treed72e1b8798c1a41667d308e4cbe6c30d9b2ad1db /file
parentd240afd8f3e316018fbaaa32e58c50dee2c00221 (diff)
downloadeeshow-ee34dad7776dd3fb3f658c78a331514eb5aa4f62.zip
eeshow-ee34dad7776dd3fb3f658c78a331514eb5aa4f62.tar.gz
eeshow-ee34dad7776dd3fb3f658c78a331514eb5aa4f62.tar.bz2
file/git-hist.c (vcs_git_summary_for_pango, vcs_git_long_for_pango): branches
vcs_git_long_for_pango now shows branches. New vcs_git_summary_for_pango is a branch-showing alternative to vcs_git_summary.
Diffstat (limited to 'file')
-rw-r--r--file/git-hist.c54
-rw-r--r--file/git-hist.h2
2 files changed, 53 insertions, 3 deletions
diff --git a/file/git-hist.c b/file/git-hist.c
index fb8a1e7..1c56d6b 100644
--- a/file/git-hist.c
+++ b/file/git-hist.c
@@ -10,6 +10,7 @@
* (at your option) any later version.
*/
+#define _GNU_SOURCE
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
@@ -253,6 +254,27 @@ const char *vcs_git_summary(struct vcs_hist *h)
}
+char *vcs_git_summary_for_pango(struct vcs_hist *h,
+ char *(*formatter)(const char *fmt, ...))
+{
+ const char *summary;
+
+ if (!h->commit)
+ return formatter("<small>Uncommitted changes</small>");
+ summary = git_commit_summary(h->commit);
+ if (!summary)
+ pfatal_git("git_commit_summary");
+
+ if (h->n_branches)
+ return formatter(
+ "<small><span background=\"#00e00080\"><b>%s</b>%s</span>"
+ " %s</small>",
+ h->branches[0], h->n_branches > 1 ? "+" : "", summary);
+ else
+ return formatter("<small>%s</small>", summary);
+}
+
+
/*
* @@@ This one is a bit inconvenient. It depends both on the information the
* VCS provides, some of which is fairly generic, but some may not be, and
@@ -273,9 +295,35 @@ char *vcs_git_long_for_pango(struct vcs_hist *h,
goto fail;
commit_time = git_commit_time(h->commit);
sig = git_commit_committer(h->commit);
- s = formatter("<b>%s</b> %s%s &lt;%s&gt;<small>\n%s</small>",
- buf.ptr, ctime(&commit_time), sig->name, sig->email,
- git_commit_summary(h->commit));
+
+ if (h->n_branches) {
+ unsigned i;
+ unsigned len = 1;
+
+ for (i = 0; i != h->n_branches; i++)
+ len += strlen(h->branches[i]) + 1;
+
+ char b[len + 1];
+
+ *b = ' ';
+ len = 1;
+ for (i = 0; i != h->n_branches; i++) {
+ strcpy(b + len, h->branches[i]);
+ len += strlen(h->branches[i]);
+ b[len++] = ' ';
+ }
+ b[len] = 0;
+
+ s = formatter(
+ "<span background=\"#00e00080\"><b>%s</b></span>\n"
+ "<b>%s</b> %s%s &lt;%s&gt;<small>\n%s</small>",
+ b, buf.ptr, ctime(&commit_time), sig->name, sig->email,
+ git_commit_summary(h->commit));
+ } else {
+ s = formatter("<b>%s</b> %s%s &lt;%s&gt;<small>\n%s</small>",
+ buf.ptr, ctime(&commit_time), sig->name, sig->email,
+ git_commit_summary(h->commit));
+ }
git_buf_free(&buf);
return s;
diff --git a/file/git-hist.h b/file/git-hist.h
index 6e9b1fa..25babcd 100644
--- a/file/git-hist.h
+++ b/file/git-hist.h
@@ -45,6 +45,8 @@ struct vcs_hist *vcs_head(const struct vcs_history *history);
char *vcs_git_get_rev(struct vcs_hist *h);
const char *vcs_git_summary(struct vcs_hist *hist);
+char *vcs_git_summary_for_pango(struct vcs_hist *hist,
+ char *(*formatter)(const char *fmt, ...));
char *vcs_git_long_for_pango(struct vcs_hist *hist,
char *(*formatter)(const char *fmt, ...));