]> Untitled Git - git4ai.git/commitdiff
cgi-скрипт показывающий список веток в репозитории
authorNikolay Shaplov <dhyan@nataraj.su>
Sun, 7 Jun 2026 16:23:56 +0000 (16:23 +0000)
committerNikolay Shaplov <dhyan@nataraj.su>
Sun, 7 Jun 2026 16:23:56 +0000 (16:23 +0000)
cgi/git4ai-branches.pl [new file with mode: 0755]
conf/nginx/git4ai

diff --git a/cgi/git4ai-branches.pl b/cgi/git4ai-branches.pl
new file mode 100755 (executable)
index 0000000..c81f4d3
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+my $GIT_ROOT = '/var/lib/git';
+my $BASE_URL = 'https://gitweb.nataraj.world';
+
+my $repo = $ENV{GIT_REPO};
+
+$repo =~ s{[^a-zA-Z0-9._-]}{}g;
+
+die unless $repo;
+
+my $git_dir = "$GIT_ROOT/$repo";
+
+print "Content-Type: text/html; charset=utf-8\r\n";
+print "Cache-Control: no-store, no-cache, must-revalidate\r\n";
+print "\r\n";
+
+open(my $fh, '-|', 'git', "--git-dir=$git_dir", 'for-each-ref',
+    '--format=%(refname:short)',
+    'refs/heads/')
+    or die "git failed: $!";
+
+my @branches;
+while (<$fh>) {
+    chomp;
+    push @branches, $_;
+}
+close($fh);
+
+print <<HTML;
+<!DOCTYPE html>
+<html>
+<head><meta charset="utf-8">
+<title>git branches: $repo</title>
+</head>
+<body>
+<h2>git branches: $repo</h2>
+<ul>
+HTML
+
+for my $branch (@branches) {
+    my $log_url = "$BASE_URL/git4ai-log/$repo/$branch";
+    print "<li><a href=\"$log_url\">$branch</a></li>\n";
+}
+
+print "</ul>\n</body></html>\n";
index 57832aabd62e894460a1d5b7f2d7654cc9e81e4c..c105b5c50a9f93f137b87680985be72114c7b961 100644 (file)
@@ -4,6 +4,7 @@ map $uri $git4ai_script {
     ~^/git4ai-cat-file/ /srv/cgi/git4ai-cat-file.pl;
     ~^/git4ai-log/      /srv/cgi/git4ai-log.pl;
     ~^/git4ai-ls-tree/  /srv/cgi/git4ai-ls-tree.pl;
+    ~^/git4ai-branches/ /srv/cgi/git4ai-branches.pl;
     ~^/git4ai/          /srv/cgi/git4ai.pl;
 }
 
@@ -80,6 +81,11 @@ location ~ "^/git4ai-ls-tree/([^/]+)/([^/]+)/([^/]+)$" {
     add_header Cache-Control "no-store" always;
 }
 
+location ~ "^/git4ai-branches/([^/]+)$" {
+    return 302 https://gitweb.nataraj.world/git4ai-branches/$1/-/-/-/$request_id;
+    add_header Cache-Control "no-store" always;
+}
+
 #                           repo             branch             id                 offset     nonce
 location ~ "^/git4ai[^/]*/([a-zA-Z0-9._-]+)/([a-zA-Z0-9._-]+|-)/([0-9a-f]{4,40}|-)/([0-9]+|-)(?:/([a-zA-Z0-9]+))?$" {
     set $git_repo    $1;