]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
repobrowse: log: create links for decorations
authorEric Wong <e@80x24.org>
Sun, 27 Dec 2015 22:35:43 +0000 (22:35 +0000)
committerEric Wong <e@80x24.org>
Tue, 5 Apr 2016 18:58:27 +0000 (18:58 +0000)
Decorations are helpful elements for showing relationships
between branches and tags.

lib/PublicInbox/RepoBrowseGit.pm
lib/PublicInbox/RepoBrowseGitLog.pm

index 55c6df98694d4f0c1acb6c74017cd33ec572c53f..498b82c722291f2f34470fc284a5c172477ff5a9 100644 (file)
@@ -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;
index 47443878e25c74bdb72e027facce787d2f7fdcbd..7dfa7d3fc52fbd568d778976729ed2cd591bbdb8 100644 (file)
@@ -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 .