@matheusbsbs / matheus-bagliano / commits / 4afbaefffa
Fork 0

gitweb: ref markers link to named shortlogs

This patch turns ref markers for tags and heads into links to appropriate views for the ref name, depending on current context. For annotated tags, we link to the tag view, unless that's the current view, in which case we switch to shortlog. For other refs, we prefer the current view if it's history or (short)log, and default to shortlog otherwise. Appropriate changes are made in the CSS to prevent ref markers from being annoyingly blue and underlined, unless hovered. A visual indication of the target view difference is also implemented by making annotated tags show up in italic. Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Acked-by: Petr Baudis <pasky@suse.cz> Acked-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Giuseppe Bilotta committed Sep 2, 2008 at 21:47 UTC 4afbaefffa9095fe1391b4b61289a7dc954e9f7b
2 files changed +47 -3
gitweb/gitweb.css
+13
@@ -481,6 +481,19 @@ span.refs span {
481 border-color: #ffccff #ff00ee #ff00ee #ffccff;
482 }
483
484 +span.refs span a {
485 + text-decoration: none;
486 + color: inherit;
487 +}
488 +
489 +span.refs span a:hover {
490 + text-decoration: underline;
491 +}
492 +
493 +span.refs span.indirect {
494 + font-style: italic;
495 +}
496 +
497 span.refs span.ref {
498 background-color: #aaaaff;
499 border-color: #ccccff #0033cc #0033cc #ccccff;
gitweb/gitweb.perl
+34 -3
@@ -1090,13 +1090,23 @@ sub format_log_line_html {
1090 }
1091
1092 # format marker of refs pointing to given object
1093 +
1094 +# the destination action is chosen based on object type and current context:
1095 +# - for annotated tags, we choose the tag view unless it's the current view
1096 +# already, in which case we go to shortlog view
1097 +# - for other refs, we keep the current view if we're in history, shortlog or
1098 +# log view, and select shortlog otherwise
1099 sub format_ref_marker {
1100 my ($refs, $id) = @_;
1101 my $markers = '';
1102
1103 if (defined $refs->{$id}) {
1104 foreach my $ref (@{$refs->{$id}}) {
1105 + # this code exploits the fact that non-lightweight tags are the
1106 + # only indirect objects, and that they are the only objects for which
1107 + # we want to use tag instead of shortlog as action
1108 my ($type, $name) = qw();
1109 + my $indirect = ($ref =~ s/\^\{\}$//);
1110 # e.g. tags/v2.6.11 or heads/next
1111 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1112 $type = $1;
@@ -1106,8 +1116,29 @@ sub format_ref_marker {
1116 $name = $ref;
1117 }
1118
1109 - $markers .= " <span class=\"$type\" title=\"$ref\">" .
1110 - esc_html($name) . "</span>";
1119 + my $class = $type;
1120 + $class .= " indirect" if $indirect;
1121 +
1122 + my $dest_action = "shortlog";
1123 +
1124 + if ($indirect) {
1125 + $dest_action = "tag" unless $action eq "tag";
1126 + } elsif ($action =~ /^(history|(short)?log)$/) {
1127 + $dest_action = $action;
1128 + }
1129 +
1130 + my $dest = "";
1131 + $dest .= "refs/" unless $ref =~ m!^refs/!;
1132 + $dest .= $ref;
1133 +
1134 + my $link = $cgi->a({
1135 + -href => href(
1136 + action=>$dest_action,
1137 + hash=>$dest
1138 + )}, $name);
1139 +
1140 + $markers .= " <span class=\"$class\" title=\"$ref\">" .
1141 + $link . "</span>";
1142 }
1143 }
1144
@@ -1918,7 +1949,7 @@ sub git_get_references {
1949
1950 while (my $line = <$fd>) {
1951 chomp $line;
1921 - if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1952 + if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
1953 if (defined $refs{$1}) {
1954 push @{$refs{$1}}, $2;
1955 } else {