@matheusbsbs / matheus-bagliano / commits / d294e1cad4
Fork 0

gitweb: Change appereance of marker of refs pointing to given object

Change git_get_references to include type of ref in the %refs value, which means putting everything after 'refs/' as a ref name, not only last part of the name. Instead of separating refs pointing to the same object by " / " separator, use anonymous array reference to store all refs pointing to given object. Use 'git-ls-remote .' if $projectroot/$project/info/refs does not exist. (Perhaps it should be used always.) Refs are now in separate span elements. Class is dependent on the ref type: currently known classes are 'tag', 'head', 'remote', and 'ref' (last one for HEAD and other refs in the main directory). There is encompassing span element of class refs, just in case of unknown ref type. This might be considered cleaner separating of git_get_references into filling %refs hash only, and not taking part in formatting ref marker. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jakub Narebski committed Aug 14, 2006 at 02:14 UTC d294e1cad4eef263c7f4912332fd0094e37e95a7
2 files changed +47 -9
gitweb/gitweb.css
+17 -2
@@ -326,15 +326,30 @@ a.rss_logo:hover {
326 background-color: #ee5500;
327 }
328
329 -span.tag {
329 +span.refs span {
330 padding: 0px 4px;
331 font-size: 10px;
332 font-weight: normal;
333 - background-color: #ffffaa;
333 border: 1px solid;
334 + background-color: #ffaaff;
335 + border-color: #ffccff #ff00ee #ff00ee #ffccff;
336 +}
337 +
338 +span.refs span.ref {
339 + background-color: #aaaaff;
340 + border-color: #ccccff #0033cc #0033cc #ccccff;
341 +}
342 +
343 +span.refs span.tag {
344 + background-color: #ffffaa;
345 border-color: #ffffcc #ffee00 #ffee00 #ffffcc;
346 }
347
348 +span.refs span.head {
349 + background-color: #aaffaa;
350 + border-color: #ccffcc #00cc33 #00cc33 #ccffcc;
351 +}
352 +
353 span.atnight {
354 color: #cc0000;
355 }
gitweb/gitweb.perl
+30 -7
@@ -364,9 +364,26 @@ sub format_log_line_html {
364 # format marker of refs pointing to given object
365 sub format_ref_marker {
366 my ($refs, $id) = @_;
367 + my $markers = '';
368
369 if (defined $refs->{$id}) {
369 - return ' <span class="tag">' . esc_html($refs->{$id}) . '</span>';
370 + foreach my $ref (@{$refs->{$id}}) {
371 + my ($type, $name) = qw();
372 + # e.g. tags/v2.6.11 or heads/next
373 + if ($ref =~ m!^(.*?)s?/(.*)$!) {
374 + $type = $1;
375 + $name = $2;
376 + } else {
377 + $type = "ref";
378 + $name = $ref;
379 + }
380 +
381 + $markers .= " <span class=\"$type\">" . esc_html($name) . "</span>";
382 + }
383 + }
384 +
385 + if ($markers) {
386 + return ' <span class="refs">'. $markers . '</span>';
387 } else {
388 return "";
389 }
@@ -561,18 +578,24 @@ sub git_get_project_owner {
578 sub git_get_references {
579 my $type = shift || "";
580 my %refs;
581 + my $fd;
582 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
583 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
566 - open my $fd, "$projectroot/$project/info/refs" or return;
584 + if (-f "$projectroot/$project/info/refs") {
585 + open $fd, "$projectroot/$project/info/refs"
586 + or return;
587 + } else {
588 + open $fd, "-|", $GIT, "ls-remote", "."
589 + or return;
590 + }
591 +
592 while (my $line = <$fd>) {
593 chomp $line;
569 - # attention: for $type == "" it saves only last path part of ref name
570 - # e.g. from 'refs/heads/jn/gitweb' it would leave only 'gitweb'
571 - if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\^]+)/) {
594 + if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
595 if (defined $refs{$1}) {
573 - $refs{$1} .= " / $2";
596 + push @{$refs{$1}}, $2;
597 } else {
575 - $refs{$1} = $2;
598 + $refs{$1} = [ $2 ];
599 }
600 }
601 }