Code

Merge branch 'js/c-merge-recursive'
[git.git] / gitweb / gitweb.perl
index 4fe3fc7b4494c37e05947736f0ae82d6feba5764..966c54a63cacf20d2a71241f738df0378e46f569 100755 (executable)
@@ -36,6 +36,9 @@ our $git_temp = "/tmp/gitweb";
 # target of the home link on top of all pages
 our $home_link = $my_uri;
 
+# string of the home link on top of all pages
+our $home_link_str = "++GITWEB_HOME_LINK_STR++";
+
 # name of your site or organization to appear in page titles
 # replace this with something more descriptive for clearer bookmarks
 our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
@@ -51,6 +54,10 @@ our $logo = "++GITWEB_LOGO++";
 # source of projects list
 our $projects_list = "++GITWEB_LIST++";
 
+# list of git base URLs used for URL to where fetch project from,
+# i.e. full URL is "$git_base_url/$project"
+our @git_base_url_list = ("++GITWEB_BASE_URL++");
+
 # default blob_plain mimetype and default charset for text/plain blob
 our $default_blob_plain_mimetype = 'text/plain';
 our $default_text_plain_charset  = undef;
@@ -177,6 +184,33 @@ if (!defined($actions{$action})) {
 $actions{$action}->();
 exit;
 
+## ======================================================================
+## action links
+
+sub href(%) {
+       my %mapping = (
+               action => "a",
+               project => "p",
+               file_name => "f",
+               hash => "h",
+               hash_parent => "hp",
+               hash_base => "hb",
+               page => "pg",
+               searchtext => "s",
+       );
+
+       my %params = @_;
+       $params{"project"} ||= $project;
+
+       my $href = "$my_uri?";
+       $href .= esc_param( join(";",
+               map { "$mapping{$_}=$params{$_}" } keys %params
+       ) );
+
+       return $href;
+}
+
+
 ## ======================================================================
 ## validation, quoting/unquoting and escaping
 
@@ -354,7 +388,7 @@ sub format_log_line_html {
        if ($line =~ m/([0-9a-fA-F]{40})/) {
                my $hash_text = $1;
                if (git_get_type($hash_text) eq "commit") {
-                       my $link = $cgi->a({-class => "text", -href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_text")}, $hash_text);
+                       my $link = $cgi->a({-class => "text", -href => href(action=>"commit", hash=>$hash_text)}, $hash_text);
                        $line =~ s/$hash_text/$link/;
                }
        }
@@ -391,16 +425,15 @@ sub format_ref_marker {
 
 # format, perhaps shortened and with markers, title line
 sub format_subject_html {
-       my ($long, $short, $query, $extra) = @_;
+       my ($long, $short, $href, $extra) = @_;
        $extra = '' unless defined($extra);
 
        if (length($short) < length($long)) {
-               return $cgi->a({-href => "$my_uri?" . esc_param($query),
-                              -class => "list", -title => $long},
+               return $cgi->a({-href => $href, -class => "list",
+                               -title => $long},
                       esc_html($short) . $extra);
        } else {
-               return $cgi->a({-href => "$my_uri?" . esc_param($query),
-                              -class => "list"},
+               return $cgi->a({-href => $href, -class => "list"},
                       esc_html($long)  . $extra);
        }
 }
@@ -500,6 +533,16 @@ sub git_get_project_description {
        return $descr;
 }
 
+sub git_get_project_url_list {
+       my $path = shift;
+
+       open my $fd, "$projectroot/$path/cloneurl" or return undef;
+       my @git_project_url_list = map { chomp; $_ } <$fd>;
+       close $fd;
+
+       return wantarray ? @git_project_url_list : \@git_project_url_list;
+}
+
 sub git_get_projects_list {
        my @list;
 
@@ -858,6 +901,7 @@ sub mimetype_guess_file {
        my %mimemap;
        open(MIME, $mimemap) or return undef;
        while (<MIME>) {
+               next if m/^#/; # skip comments
                my ($mime, $exts) = split(/\t+/);
                if (defined $exts) {
                        my @exts = split(/\s+/, $exts);
@@ -879,7 +923,10 @@ sub mimetype_guess {
 
        if ($mimetypes_file) {
                my $file = $mimetypes_file;
-               #$file =~ m#^/# or $file = "$projectroot/$path/$file";
+               if ($file !~ m!^/!) { # if it is relative path
+                       # it is relative to project
+                       $file = "$projectroot/$project/$file";
+               }
                $mime = mimetype_guess_file($filename, $file);
        }
        $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
@@ -949,10 +996,11 @@ sub git_header_html {
 <?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
-<!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
+<!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
 <!-- git core binaries version $git_version -->
 <head>
 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
+<meta name="generator" content="gitweb/$version git/$git_version"/>
 <meta name="robots" content="index, nofollow"/>
 <title>$title</title>
 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
@@ -960,8 +1008,7 @@ EOF
        if (defined $project) {
                printf('<link rel="alternate" title="%s log" '.
                       'href="%s" type="application/rss+xml"/>'."\n",
-                      esc_param($project),
-                      esc_param("$my_uri?p=$project;a=rss"));
+                      esc_param($project), href(action=>"rss"));
        }
 
        print "</head>\n" .
@@ -970,9 +1017,9 @@ EOF
              "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
              "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
              "</a>\n";
-       print $cgi->a({-href => esc_param($home_link)}, "projects") . " / ";
+       print $cgi->a({-href => esc_param($home_link)}, $home_link_str) . " / ";
        if (defined $project) {
-               print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, esc_html($project));
+               print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
                if (defined $action) {
                        print " / $action";
                }
@@ -1009,7 +1056,7 @@ sub git_footer_html {
                if (defined $descr) {
                        print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
                }
-               print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
+               print $cgi->a({-href => href(action=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
        } else {
                print $cgi->a({-href => "$my_uri?" . esc_param("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
        }
@@ -1044,27 +1091,25 @@ sub git_print_page_nav {
                @navs = grep { $_ ne $suppress } @navs;
        }
 
-       my %arg = map { $_, ''} @navs;
+       my %arg = map { $_ => {action=>$_} } @navs;
        if (defined $head) {
                for (qw(commit commitdiff)) {
-                       $arg{$_} = ";h=$head";
+                       $arg{$_}{hash} = $head;
                }
                if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
                        for (qw(shortlog log)) {
-                               $arg{$_} = ";h=$head";
+                               $arg{$_}{hash} = $head;
                        }
                }
        }
-       $arg{tree} .= ";h=$treehead" if defined $treehead;
-       $arg{tree} .= ";hb=$treebase" if defined $treebase;
+       $arg{tree}{hash} = $treehead if defined $treehead;
+       $arg{tree}{hash_base} = $treebase if defined $treebase;
 
        print "<div class=\"page_nav\">\n" .
                (join " | ",
-                map { $_ eq $current
-                                        ? $_
-                                        : $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$_$arg{$_}")}, "$_")
-                                }
-                @navs);
+                map { $_ eq $current ?
+                      $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
+                } @navs);
        print "<br/>\n$extra<br/>\n" .
              "</div>\n";
 }
@@ -1075,14 +1120,14 @@ sub format_paging_nav {
 
 
        if ($hash ne $head || $page) {
-               $paging_nav .= $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$action")}, "HEAD");
+               $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
        } else {
                $paging_nav .= "HEAD";
        }
 
        if ($page > 0) {
                $paging_nav .= " &sdot; " .
-                       $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$action;h=$hash;pg=" . ($page-1)),
+                       $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page-1),
                                 -accesskey => "p", -title => "Alt-p"}, "prev");
        } else {
                $paging_nav .= " &sdot; prev";
@@ -1090,7 +1135,7 @@ sub format_paging_nav {
 
        if ($nrevs >= (100 * ($page+1)-1)) {
                $paging_nav .= " &sdot; " .
-                       $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$action;h=$hash;pg=" . ($page+1)),
+                       $cgi->a({-href => href(action=>$action, hash=>$hash, page=>$page+1),
                                 -accesskey => "n", -title => "Alt-n"}, "next");
        } else {
                $paging_nav .= " &sdot; next";
@@ -1104,15 +1149,16 @@ sub format_paging_nav {
 
 sub git_print_header_div {
        my ($action, $title, $hash, $hash_base) = @_;
-       my $rest = '';
+       my %args = ();
 
-       $rest .= ";h=$hash" if $hash;
-       $rest .= ";hb=$hash_base" if $hash_base;
+       $args{action} = $action;
+       $args{hash} = $hash if $hash;
+       $args{hash_base} = $hash_base if $hash_base;
 
        print "<div class=\"header\">\n" .
-             $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$action$rest"),
-                      -class => "title"}, $title ? $title : $action) . "\n" .
-             "</div>\n";
+             $cgi->a({-href => href(%args), -class => "title"},
+             $title ? $title : $action) .
+             "\n</div>\n";
 }
 
 sub git_print_page_path {
@@ -1123,7 +1169,7 @@ sub git_print_page_path {
                print "<div class=\"page_path\"><b>/</b></div>\n";
        } elsif (defined $type && $type eq 'blob') {
                print "<div class=\"page_path\"><b>" .
-                       $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;f=$file_name")}, esc_html($name)) . "</b><br/></div>\n";
+                       $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name)}, esc_html($name)) . "</b><br/></div>\n";
        } else {
                print "<div class=\"page_path\"><b>" . esc_html($name) . "</b><br/></div>\n";
        }
@@ -1132,6 +1178,145 @@ sub git_print_page_path {
 ## ......................................................................
 ## functions printing large fragments of HTML
 
+sub git_difftree_body {
+       my ($difftree, $parent) = @_;
+
+       print "<div class=\"list_head\">\n";
+       if ($#{$difftree} > 10) {
+               print(($#{$difftree} + 1) . " files changed:\n");
+       }
+       print "</div>\n";
+
+       print "<table class=\"diff_tree\">\n";
+       my $alternate = 0;
+       foreach my $line (@{$difftree}) {
+               # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M   ls-files.c'
+               # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M   rev-tree.c'
+               if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
+                       next;
+               }
+               my $from_mode = $1;
+               my $to_mode = $2;
+               my $from_id = $3;
+               my $to_id = $4;
+               my $status = $5;
+               my $similarity = $6; # score
+               my $file = validate_input(unquote($7));
+
+               if ($alternate) {
+                       print "<tr class=\"dark\">\n";
+               } else {
+                       print "<tr class=\"light\">\n";
+               }
+               $alternate ^= 1;
+
+               if ($status eq "A") { # created
+                       my $mode_chng = "";
+                       if (S_ISREG(oct $to_mode)) {
+                               $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
+                       }
+                       print "<td>" .
+                             $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$file),
+                                     -class => "list"}, esc_html($file)) .
+                             "</td>\n" .
+                             "<td><span class=\"file_status new\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
+                             "<td class=\"link\">" .
+                             $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$file)}, "blob") .
+                             "</td>\n";
+
+               } elsif ($status eq "D") { # deleted
+                       print "<td>" .
+                             $cgi->a({-href => href(action=>"blob", hash=>$from_id, hash_base=>$parent, file_name=>$file),
+                                      -class => "list"}, esc_html($file)) . "</td>\n" .
+                             "<td><span class=\"file_status deleted\">[deleted " . file_type($from_mode). "]</span></td>\n" .
+                             "<td class=\"link\">" .
+                             $cgi->a({-href => href(action=>"blob", hash=>$from_id, hash_base=>$parent, file_name=>$file)}, "blob") . " | " .
+                             $cgi->a({-href => href(action=>"history", hash_base=>$parent, file_name=>$file)}, "history") .
+                             "</td>\n"
+
+               } elsif ($status eq "M" || $status eq "T") { # modified, or type changed
+                       my $mode_chnge = "";
+                       if ($from_mode != $to_mode) {
+                               $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
+                               if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
+                                       $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
+                               }
+                               if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
+                                       if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
+                                               $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
+                                       } elsif (S_ISREG($to_mode)) {
+                                               $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
+                                       }
+                               }
+                               $mode_chnge .= "]</span>\n";
+                       }
+                       print "<td>";
+                       if ($to_id ne $from_id) { # modified
+                               print $cgi->a({-href => href(action=>"blobdiff", hash=>$to_id, hash_parent=>$from_id, hash_base=>$hash, file_name=>$file),
+                                             -class => "list"}, esc_html($file));
+                       } else { # mode changed
+                               print $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$file),
+                                             -class => "list"}, esc_html($file));
+                       }
+                       print "</td>\n" .
+                             "<td>$mode_chnge</td>\n" .
+                             "<td class=\"link\">" .
+                               $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$file)}, "blob");
+                       if ($to_id ne $from_id) { # modified
+                               print $cgi->a({-href => href(action=>"blobdiff", hash=>$to_id, hash_parent=>$from_id, hash_base=>$hash, file_name=>$file)}, "diff");
+                       }
+                       print " | " . $cgi->a({-href => href(action=>"history", hash_base=>$hash, file_name=>$file)}, "history") . "\n";
+                       print "</td>\n";
+
+               } elsif ($status eq "R") { # renamed
+                       my ($from_file, $to_file) = split "\t", $file;
+                       my $mode_chng = "";
+                       if ($from_mode != $to_mode) {
+                               $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
+                       }
+                       print "<td>" .
+                             $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$to_file),
+                                     -class => "list"}, esc_html($to_file)) . "</td>\n" .
+                             "<td><span class=\"file_status moved\">[moved from " .
+                             $cgi->a({-href => href(action=>"blob", hash=>$from_id, hash_base=>$parent, file_name=>$from_file),
+                                     -class => "list"}, esc_html($from_file)) .
+                             " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
+                             "<td class=\"link\">" .
+                             $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$to_file)}, "blob");
+                       if ($to_id ne $from_id) {
+                               print " | " .
+                                     $cgi->a({-href => "$my_uri?" .
+                                             esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file;fp=$from_file")}, "diff");
+                       }
+                       print "</td>\n";
+
+               } elsif ($status eq "C") { # copied
+                       my ($from_file, $to_file) = split "\t", $file;
+                       my $mode_chng = "";
+                       if ($from_mode != $to_mode) {
+                               $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
+                       }
+                       print "<td>" .
+                             $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$to_file),
+                                     -class => "list"}, esc_html($to_file)) . "</td>\n" .
+                             "<td><span class=\"file_status copied\">[copied from " .
+                             $cgi->a({-href => href(action=>"blob", hash=>$from_id, hash_base=>$parent, file_name=>$from_file),
+                                     -class => "list"}, esc_html($from_file)) .
+                             " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
+                             "<td class=\"link\">" .
+                             $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$to_file)}, "blob");
+                       if ($to_id ne $from_id) {
+                               print " | " .
+                                     $cgi->a({-href => "$my_uri?" .
+                                             esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file;fp=$from_file")}, "diff");
+                       }
+                       print "</td>\n";
+               } # we should not encounter Unmerged (U) or Unknown (X) status
+               print "</tr>\n";
+       }
+       print "</table>\n";
+}
+
 sub git_shortlog_body {
        # uses global variable $project
        my ($revlist, $from, $to, $refs, $extra) = @_;
@@ -1155,11 +1340,11 @@ sub git_shortlog_body {
                print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
                      "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
                      "<td>";
-               print format_subject_html($co{'title'}, $co{'title_short'}, "p=$project;a=commit;h=$commit", $ref);
+               print format_subject_html($co{'title'}, $co{'title_short'}, href(action=>"commit", hash=>$commit), $ref);
                print "</td>\n" .
                      "<td class=\"link\">" .
-                     $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") . " | " .
-                     $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
+                     $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
+                     $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
                      "</td>\n" .
                      "</tr>\n";
        }
@@ -1201,12 +1386,12 @@ sub git_history_body {
                      "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
                      "<td>";
                # originally git_history used chop_str($co{'title'}, 50)
-               print format_subject_html($co{'title'}, $co{'title_short'}, "p=$project;a=commit;h=$commit", $ref);
+               print format_subject_html($co{'title'}, $co{'title_short'}, href(action=>"commit", hash=>$commit), $ref);
                print "</td>\n" .
                      "<td class=\"link\">" .
-                     $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") . " | " .
-                     $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") . " | " .
-                     $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$ftype;hb=$commit;f=$file_name")}, $ftype);
+                     $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
+                     $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
+                     $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype);
 
                if ($ftype eq 'blob') {
                        my $blob_current = git_get_hash_by_path($hash_base, $file_name);
@@ -1214,7 +1399,7 @@ sub git_history_body {
                        if (defined $blob_current && defined $blob_parent &&
                                        $blob_current ne $blob_parent) {
                                print " | " .
-                                       $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$blob_current;hp=$blob_parent;hb=$commit;f=$file_name")},
+                                       $cgi->a({-href => href(action=>"blobdiff", hash=>$blob_current, hash_parent=>$blob_parent, hash_base=>$commit, file_name=>$file_name)},
                                                "diff to current");
                        }
                }
@@ -1254,28 +1439,28 @@ sub git_tags_body {
                $alternate ^= 1;
                print "<td><i>$tag{'age'}</i></td>\n" .
                      "<td>" .
-                     $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"),
+                     $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
                               -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") .
                      "</td>\n" .
                      "<td>";
                if (defined $comment) {
-                       print format_subject_html($comment, $comment_short, "p=$project;a=tag;h=$tag{'id'}");
+                       print format_subject_html($comment, $comment_short, href(action=>"tag", hash=>$tag{'id'}));
                }
                print "</td>\n" .
                      "<td class=\"selflink\">";
                if ($tag{'type'} eq "tag") {
-                       print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag");
+                       print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
                } else {
                        print "&nbsp;";
                }
                print "</td>\n" .
                      "<td class=\"link\">" . " | " .
-                     $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
+                     $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
                if ($tag{'reftype'} eq "commit") {
-                       print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
-                             " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
+                       print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") .
+                             " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'refid'})}, "log");
                } elsif ($tag{'reftype'} eq "blob") {
-                       print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$tag{'refid'}")}, "raw");
+                       print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
                }
                print "</td>\n" .
                      "</tr>";
@@ -1308,12 +1493,12 @@ sub git_heads_body {
                $alternate ^= 1;
                print "<td><i>$tag{'age'}</i></td>\n" .
                      ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
-                     $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"),
+                     $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'}),
                               -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") .
                      "</td>\n" .
                      "<td class=\"link\">" .
-                     $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . " | " .
-                     $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") .
+                     $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . " | " .
+                     $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") .
                      "</td>\n" .
                      "</tr>";
        }
@@ -1522,8 +1707,18 @@ sub git_summary {
        print "<table cellspacing=\"0\">\n" .
              "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
              "<tr><td>owner</td><td>$owner</td></tr>\n" .
-             "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
-             "</table>\n";
+             "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
+       # use per project git URL list in $projectroot/$project/cloneurl
+       # or make project git URL from git base URL and project name
+       my $url_tag = "URL";
+       my @url_list = git_get_project_url_list($project);
+       @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
+       foreach my $git_url (@url_list) {
+               next unless $git_url;
+               print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
+               $url_tag = "";
+       }
+       print "</table>\n";
 
        open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash($project)
                or die_error(undef, "Open git-rev-list failed");
@@ -1531,20 +1726,20 @@ sub git_summary {
        close $fd;
        git_print_header_div('shortlog');
        git_shortlog_body(\@revlist, 0, 15, $refs,
-                         $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "..."));
+                         $cgi->a({-href => href(action=>"shortlog")}, "..."));
 
        my $taglist = git_get_refs_list("refs/tags");
        if (defined @$taglist) {
                git_print_header_div('tags');
                git_tags_body($taglist, 0, 15,
-                             $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags")}, "..."));
+                             $cgi->a({-href => href(action=>"tags")}, "..."));
        }
 
        my $headlist = git_get_refs_list("refs/heads");
        if (defined @$headlist) {
                git_print_header_div('heads');
                git_heads_body($headlist, $head, 0, 15,
-                              $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads")}, "..."));
+                              $cgi->a({-href => href(action=>"heads")}, "..."));
        }
 
        git_footer_html();
@@ -1560,8 +1755,8 @@ sub git_tag {
              "<table cellspacing=\"0\">\n" .
              "<tr>\n" .
              "<td>object</td>\n" .
-             "<td>" . $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
-             "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
+             "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})}, $tag{'object'}) . "</td>\n" .
+             "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})}, $tag{'type'}) . "</td>\n" .
              "</tr>\n";
        if (defined($tag{'author'})) {
                my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
@@ -1600,8 +1795,8 @@ sub git_blame2 {
                or die_error(undef, "Open git-blame failed");
        git_header_html();
        my $formats_nav =
-               $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
-               " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;f=$file_name")}, "head");
+               $cgi->a({-href => href(action=>"blobl", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)}, "blob") .
+               " | " . $cgi->a({-href => href(action=>"blame", file_name=>$file_name)}, "head");
        git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
        git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
        git_print_page_path($file_name, $ftype);
@@ -1627,7 +1822,7 @@ sub git_blame2 {
                }
                print "<tr class=\"$rev_color[$current_color]\">\n";
                print "<td class=\"sha1\">" .
-                       $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html($rev)) . "</td>\n";
+                       $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)}, esc_html($rev)) . "</td>\n";
                print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html($lineno) . "</a></td>\n";
                print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
                print "</tr>\n";
@@ -1654,8 +1849,8 @@ sub git_blame {
                or die_error(undef, "Open git-annotate failed");
        git_header_html();
        my $formats_nav =
-               $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
-               " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;f=$file_name")}, "head");
+               $cgi->a({-href => href(action=>"blobl", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)}, "blob") .
+               " | " . $cgi->a({-href => href(action=>"blame", file_name=>$file_name)}, "head");
        git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
        git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
        git_print_page_path($file_name, 'blob');
@@ -1687,7 +1882,7 @@ HTML
                chomp $line;
                $line_class_num = ($line_class_num + 1) % $line_class_len;
 
-               if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
+               if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
                        $long_rev = $1;
                        $author   = $2;
                        $time     = $3;
@@ -1710,7 +1905,7 @@ HTML
 
                print <<HTML;
   <tr class="$line_class[$line_class_num]">
-    <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
+    <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
     <td class="$age_class">$age_str</td>
     <td>$author</td>
     <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
@@ -1806,13 +2001,13 @@ sub git_blob {
        if (defined $hash_base && (my %co = parse_commit($hash_base))) {
                if (defined $file_name) {
                        if ($have_blame) {
-                               $formats_nav .= $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
+                               $formats_nav .= $cgi->a({-href => href(action=>"blame", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)}, "blame") . " | ";
                        }
                        $formats_nav .=
-                               $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
-                               " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head");
+                               $cgi->a({-href => href(action=>"blob_plain", hash=>$hash, file_name=>$file_name)}, "plain") .
+                               " | " . $cgi->a({-href => href(action=>"blob", hash_base=>"HEAD", file_name=>$file_name)}, "head");
                } else {
-                       $formats_nav .= $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain");
+                       $formats_nav .= $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "plain");
                }
                git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
                git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
@@ -1956,8 +2151,8 @@ sub git_log {
                               $commit);
                print "<div class=\"title_text\">\n" .
                      "<div class=\"log_link\">\n" .
-                     $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
-                     " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
+                     $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
+                     " | " . $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
                      "<br/>\n" .
                      "</div>\n" .
                      "<i>" . esc_html($co{'author_name'}) .  " [$ad{'rfc2822'}]</i><br/>\n" .
@@ -2014,7 +2209,7 @@ sub git_commit {
        my $formats_nav = '';
        if (defined $file_name && defined $co{'parent'}) {
                my $parent = $co{'parent'};
-               $formats_nav .= $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame");
+               $formats_nav .= $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)}, "blame");
        }
        git_header_html(undef, $expires);
        git_print_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff',
@@ -2044,19 +2239,19 @@ sub git_commit {
        print "<tr>" .
              "<td>tree</td>" .
              "<td class=\"sha1\">" .
-             $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
+             $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash), class => "list"}, $co{'tree'}) .
              "</td>" .
-             "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
+             "<td class=\"link\">" . $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)}, "tree") .
              "</td>" .
              "</tr>\n";
        my $parents = $co{'parents'};
        foreach my $par (@$parents) {
                print "<tr>" .
                      "<td>parent</td>" .
-                     "<td class=\"sha1\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
+                     "<td class=\"sha1\">" . $cgi->a({-href => href(action=>"commit", hash=>$par), class => "list"}, $par) . "</td>" .
                      "<td class=\"link\">" .
-                     $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par")}, "commit") .
-                     " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
+                     $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
+                     " | " . $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "commitdiff") .
                      "</td>" .
                      "</tr>\n";
        }
@@ -2085,101 +2280,9 @@ sub git_commit {
                }
        }
        print "</div>\n";
-       print "<div class=\"list_head\">\n";
-       if ($#difftree > 10) {
-               print(($#difftree + 1) . " files changed:\n");
-       }
-       print "</div>\n";
-       print "<table class=\"diff_tree\">\n";
-       my $alternate = 0;
-       foreach my $line (@difftree) {
-               # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M      ls-files.c'
-               # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M      rev-tree.c'
-               if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
-                       next;
-               }
-               my $from_mode = $1;
-               my $to_mode = $2;
-               my $from_id = $3;
-               my $to_id = $4;
-               my $status = $5;
-               my $similarity = $6;
-               my $file = validate_input(unquote($7));
-               if ($alternate) {
-                       print "<tr class=\"dark\">\n";
-               } else {
-                       print "<tr class=\"light\">\n";
-               }
-               $alternate ^= 1;
-               if ($status eq "A") {
-                       my $mode_chng = "";
-                       if (S_ISREG(oct $to_mode)) {
-                               $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
-                       }
-                       print "<td>" .
-                             $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file)) . "</td>\n" .
-                             "<td><span class=\"file_status new\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
-                             "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
-               } elsif ($status eq "D") {
-                       print "<td>" .
-                             $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$parent;f=$file"), -class => "list"}, esc_html($file)) . "</td>\n" .
-                             "<td><span class=\"file_status deleted\">[deleted " . file_type($from_mode). "]</span></td>\n" .
-                             "<td class=\"link\">" .
-                             $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$parent;f=$file")}, "blob") .
-                             " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$parent;f=$file")}, "history") .
-                             "</td>\n"
-               } elsif ($status eq "M" || $status eq "T") {
-                       my $mode_chnge = "";
-                       if ($from_mode != $to_mode) {
-                               $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
-                               if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
-                                       $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
-                               }
-                               if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
-                                       if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
-                                               $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
-                                       } elsif (S_ISREG($to_mode)) {
-                                               $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
-                                       }
-                               }
-                               $mode_chnge .= "]</span>\n";
-                       }
-                       print "<td>";
-                       if ($to_id ne $from_id) {
-                               print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file));
-                       } else {
-                               print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file));
-                       }
-                       print "</td>\n" .
-                             "<td>$mode_chnge</td>\n" .
-                             "<td class=\"link\">";
-                       print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
-                       if ($to_id ne $from_id) {
-                               print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
-                       }
-                       print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
-                       print "</td>\n";
-               } elsif ($status eq "R") {
-                       my ($from_file, $to_file) = split "\t", $file;
-                       my $mode_chng = "";
-                       if ($from_mode != $to_mode) {
-                               $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
-                       }
-                       print "<td>" .
-                             $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"), -class => "list"}, esc_html($to_file)) . "</td>\n" .
-                             "<td><span class=\"file_status moved\">[moved from " .
-                             $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$parent;f=$from_file"), -class => "list"}, esc_html($from_file)) .
-                             " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
-                             "<td class=\"link\">" .
-                             $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
-                       if ($to_id ne $from_id) {
-                               print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
-                       }
-                       print "</td>\n";
-               }
-               print "</tr>\n";
-       }
-       print "</table>\n";
+
+       git_difftree_body(\@difftree, $parent);
+
        git_footer_html();
 }