From: Eric Wong Date: Sun, 27 Dec 2015 22:35:43 +0000 (+0000) Subject: repobrowse: log: create links for decorations X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=27be7eabf55103ba77d38768991f2448afe01129;p=thirdparty%2Fpublic-inbox.git repobrowse: log: create links for decorations Decorations are helpful elements for showing relationships between branches and tags. --- diff --git a/lib/PublicInbox/RepoBrowseGit.pm b/lib/PublicInbox/RepoBrowseGit.pm index 55c6df986..498b82c72 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 -> $h); + } elsif (s/\Atag: //) { + my $h = PublicInbox::Hval->utf8($_); + my $r = $h->as_href; + $h = $h->as_html; + push @l, qq($h); + } else { + my $h = PublicInbox::Hval->utf8($_); + my $r = $h->as_href; + $h = $h->as_html; + push @l, qq($h); + } + } + @l; +} + 1; diff --git a/lib/PublicInbox/RepoBrowseGitLog.pm b/lib/PublicInbox/RepoBrowseGitLog.pm index 47443878e..7dfa7d3fc 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($s); + + 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 = "$s\n- $ah @ $ai\n\n$b"; + $b = "$s\n- $ah @ $ai\n\n$b"; if (@graph) { $fh->write('
'. $gr .
 					'
' . $b .