about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-12-27 22:35:43 +0000
committerEric Wong <e@80x24.org>2016-04-05 18:58:27 +0000
commit27be7eabf55103ba77d38768991f2448afe01129 (patch)
tree0362a37211c14c8c5cd7d557da7330b1272c5eac /lib
parentd000afafd3d1992644eb90580aafed91c7221d38 (diff)
downloadpublic-inbox-27be7eabf55103ba77d38768991f2448afe01129.tar.gz
Decorations are helpful elements for showing relationships
between branches and tags.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/RepoBrowseGit.pm30
-rw-r--r--lib/PublicInbox/RepoBrowseGitLog.pm10
2 files changed, 36 insertions, 4 deletions
diff --git a/lib/PublicInbox/RepoBrowseGit.pm b/lib/PublicInbox/RepoBrowseGit.pm
index 55c6df98..498b82c7 100644
--- a/lib/PublicInbox/RepoBrowseGit.pm
+++ b/lib/PublicInbox/RepoBrowseGit.pm
@@ -6,7 +6,8 @@ package PublicInbox::RepoBrowseGit;
 use strict;
 use warnings;
 use base qw(Exporter);
-our @EXPORT_OK = qw(git_unquote git_commit_title);
+our @EXPORT_OK = qw(git_unquote git_commit_title git_dec_links);
+use PublicInbox::Hval qw(utf8_html);
 
 my %GIT_ESC = (
         a => "\a",
@@ -37,4 +38,31 @@ sub git_commit_title {
         $rv;
 }
 
+# example inputs: "HEAD -> master", "tag: v1.0.0",
+sub git_dec_links {
+        my ($rel, $D) = @_;
+        my @l;
+        foreach (split /, /, $D) {
+                if (/\A(\S+) -> (\S+)/) { # 'HEAD -> master'
+                        my ($s, $h) = ($1, $2);
+                        $s = utf8_html($s);
+                        $h = PublicInbox::Hval->utf8($h);
+                        my $r = $h->as_href;
+                        $h = $h->as_html;
+                        push @l, qq($s -&gt; <a\nhref="${rel}log?h=$r">$h</a>);
+                } elsif (s/\Atag: //) {
+                        my $h = PublicInbox::Hval->utf8($_);
+                        my $r = $h->as_href;
+                        $h = $h->as_html;
+                        push @l, qq(<a\nhref="${rel}tag?h=$r"><b>$h</b></a>);
+                } else {
+                        my $h = PublicInbox::Hval->utf8($_);
+                        my $r = $h->as_href;
+                        $h = $h->as_html;
+                        push @l, qq(<a\nhref="${rel}log?h=$r">$h</a>);
+                }
+        }
+        @l;
+}
+
 1;
diff --git a/lib/PublicInbox/RepoBrowseGitLog.pm b/lib/PublicInbox/RepoBrowseGitLog.pm
index 47443878..7dfa7d3f 100644
--- a/lib/PublicInbox/RepoBrowseGitLog.pm
+++ b/lib/PublicInbox/RepoBrowseGitLog.pm
@@ -6,6 +6,7 @@ use strict;
 use warnings;
 use PublicInbox::Hval qw(utf8_html);
 use base qw(PublicInbox::RepoBrowseBase);
+use PublicInbox::RepoBrowseGit qw(git_dec_links);
 
 # enable if we can speed it up..., over 100ms is unnacceptable
 my @graph; # = qw(--graph);
@@ -76,9 +77,12 @@ sub git_log_stream {
 
                 $s =~ s/\As//;
                 $s = utf8_html($s);
-
-                # TODO: handle $D (decorate)
                 $s = qq(<a\nhref="${rel}commit?id=$id">$s</a>);
+
+                if ($D =~ /\AD(.+)/) {
+                        $s .= ' ('. join(', ', git_dec_links($rel, $1)) . ')';
+                }
+
                 if (defined $b) {
                         $an =~ s/\Aa//;
                         $b =~ s/\Ab//;
@@ -95,7 +99,7 @@ sub git_log_stream {
                                 $gr =~ s/([^\n]+)\z/($1."\n") x $nl/es;
                         }
                         $b = utf8_html($b);
-                        $b = "<b>$s</b>\n- $ah @ $ai\n\n$b";
+                        $b = "$s\n- $ah @ $ai\n\n$b";
                         if (@graph) {
                                 $fh->write('<table><tr><td><pre>'. $gr .
                                         '</pre></td><td><pre>' . $b .