The function checks if the HEAD for the current project is detached by checking if 'git branch' returns "* (no branch)" Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@xxxxxxxxx> --- gitweb/gitweb.perl | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index a168f6f..ceb0271 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1844,6 +1844,13 @@ sub git_get_head_hash { return $retval; } +# check if current HEAD is detached +sub git_is_head_detached { + my @x = (git_cmd(), 'branch'); + my @ret = split("\n", qx(@x)); + return 0 + grep { /^\* \(no branch\)$/ } @ret; +} + # get type of given object sub git_get_type { my $hash = shift; @@ -2673,11 +2680,9 @@ sub git_get_heads_list { my @headslist; if (grep { $_ eq 'heads' } @class) { - my @x = (git_cmd(), 'branch'); - my @ret = split("\n", qx(@x)); - if (grep { /^\* \(no branch\)$/ } @ret) { ; + if (git_is_head_detached()) { my %ref_item; - @x = (git_cmd(), 'log', '-1', '--pretty=format:%H%n%ct%n%s'); + my @x = (git_cmd(), 'log', '-1', '--pretty=format:%H%n%ct%n%s'); my ($hash, $epoch, $title) = split("\n", qx(@x), 3); $ref_item{'class'} = 'head'; -- 1.5.6.5 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html