[PATCH 1/2] gitweb: infrastructure for tags feed

2017-04-18 Thread Giuseppe Bilotta
Signed-off-by: Giuseppe Bilotta 
---
 gitweb/gitweb.perl | 79 +++---
 1 file changed, 58 insertions(+), 21 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 7cf68f07b7..4adea84006 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3807,6 +3807,7 @@ sub git_get_tags_list {
 
if ($type eq "tag" || $type eq "commit") {
$ref_item{'epoch'} = $epoch;
+   $ref_item{'tz'} = $tz;
if ($epoch) {
$ref_item{'age'} = age_string(time - 
$ref_item{'epoch'});
} else {
@@ -8132,6 +8133,10 @@ sub git_shortlog {
 
 sub git_feed {
my $format = shift || 'atom';
+
+   # feed context: log, tags
+   my $ctx = shift || 'log';
+
my $have_blame = gitweb_check_feature('blame');
 
# Atom: http://www.atomenabled.org/developers/syndication/
@@ -8140,9 +8145,19 @@ sub git_feed {
die_error(400, "Unknown web feed format");
}
 
+   if ($ctx ne 'log' && $ctx ne 'tags') {
+   die_error(400, "Unknown web feed context");
+   }
+   my $tags = $ctx eq 'tags' ? 1 : 0;
+
# log/feed of current (HEAD) branch, log of given branch, history of 
file/directory
my $head = $hash || 'HEAD';
-   my @commitlist = parse_commits($head, 150, 0, $file_name);
+   my @commitlist;
+   if ($tags) {
+   @commitlist = git_get_tags_list(15);
+   } else {
+   @commitlist = parse_commits($head, 150, 0, $file_name);
+   }
 
my %latest_commit;
my %latest_date;
@@ -8154,9 +8169,12 @@ sub git_feed {
}
if (defined($commitlist[0])) {
%latest_commit = %{$commitlist[0]};
-   my $latest_epoch = $latest_commit{'committer_epoch'};
+   my $latest_epoch = $tags ? $latest_commit{'epoch'} :
+  $latest_commit{'committer_epoch'};
exit_if_unmodified_since($latest_epoch);
-   %latest_date = parse_date($latest_epoch, 
$latest_commit{'committer_tz'});
+   %latest_date = parse_date($latest_epoch,
+   $tags ? $latest_commit{'tz'} :
+   $latest_commit{'committer_tz'});
}
print $cgi->header(
-type => $content_type,
@@ -8171,7 +8189,9 @@ sub git_feed {
# header variables
my $title = "$site_name - $project/$action";
my $feed_type = 'log';
-   if (defined $hash) {
+   if ($tags) {
+   $feed_type = 'tags';
+   } elsif (defined $hash) {
$title .= " - '$hash'";
$feed_type = 'branch log';
if (defined $file_name) {
@@ -8189,6 +8209,7 @@ sub git_feed {
$descr = esc_html($descr);
} else {
$descr = "$project " .
+($tags ? 'tags ' : '') .
 ($format eq 'rss' ? 'RSS' : 'Atom') .
 " feed";
}
@@ -8197,7 +8218,9 @@ sub git_feed {
 
#header
my $alt_url;
-   if (defined $file_name) {
+   if ($tags) {
+   $alt_url = href(-full=>1, action=>"tags");
+   } elsif (defined $file_name) {
$alt_url = href(-full=>1, action=>"history", hash=>$hash, 
file_name=>$file_name);
} elsif (defined $hash) {
$alt_url = href(-full=>1, action=>"log", hash=>$hash);
@@ -8261,9 +8284,15 @@ XML
}
 
# contents
+   my $co_action = $tags ? 'tag' : 'commitdiff';
for (my $i = 0; $i <= $#commitlist; $i++) {
+   my %clco; # commit info from commitlist, only used for tags
my %co = %{$commitlist[$i]};
my $commit = $co{'id'};
+   if ($tags) {
+   %clco = %co;
+   %co = parse_tag($commit);
+   }
# we read 150, we always show 30 and the ones more recent than 
48 hours
if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
last;
@@ -8271,44 +8300,52 @@ XML
my %cd = parse_date($co{'author_epoch'}, $co{'author_tz'});
 
# get list of changed files
-   open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
-   $co{'parent'} || "--root",
-   $co{'id'}, "--", (defined $file_name ? $file_name : ())
-   or next;
-   my @difftree = map { chomp; $_ } <$fd>;
-   close $fd
-   or next;
+   my @difftree;
+   unless ($tags) {
+   open my $fd, "-|", git_cmd(), "diff-tree", '-r', 
@diff_opts,
+   $co{'parent'} || "--root",
+   $co{'id'}, "--", (defined $

[PATCH 1/2] gitweb: infrastructure for tags feed

2012-09-25 Thread Giuseppe Bilotta
Signed-off-by: Giuseppe Bilotta 
---
 gitweb/gitweb.perl | 79 +++---
 1 file changed, 58 insertions(+), 21 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 7f8c187..6cb51f7 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3711,6 +3711,7 @@ sub git_get_tags_list {
 
if ($type eq "tag" || $type eq "commit") {
$ref_item{'epoch'} = $epoch;
+   $ref_item{'tz'} = $tz;
if ($epoch) {
$ref_item{'age'} = age_string(time - 
$ref_item{'epoch'});
} else {
@@ -8004,6 +8005,10 @@ sub git_shortlog {
 
 sub git_feed {
my $format = shift || 'atom';
+
+   # feed context: log, tags
+   my $ctx = shift || 'log';
+
my $have_blame = gitweb_check_feature('blame');
 
# Atom: http://www.atomenabled.org/developers/syndication/
@@ -8012,9 +8017,19 @@ sub git_feed {
die_error(400, "Unknown web feed format");
}
 
+   if ($ctx ne 'log' && $ctx ne 'tags') {
+   die_error(400, "Unknown web feed context");
+   }
+   my $tags = $ctx eq 'tags' ? 1 : 0;
+
# log/feed of current (HEAD) branch, log of given branch, history of 
file/directory
my $head = $hash || 'HEAD';
-   my @commitlist = parse_commits($head, 150, 0, $file_name);
+   my @commitlist;
+   if ($tags) {
+   @commitlist = git_get_tags_list(15);
+   } else {
+   @commitlist = parse_commits($head, 150, 0, $file_name);
+   }
 
my %latest_commit;
my %latest_date;
@@ -8026,9 +8041,12 @@ sub git_feed {
}
if (defined($commitlist[0])) {
%latest_commit = %{$commitlist[0]};
-   my $latest_epoch = $latest_commit{'committer_epoch'};
+   my $latest_epoch = $tags ? $latest_commit{'epoch'} :
+  $latest_commit{'committer_epoch'};
exit_if_unmodified_since($latest_epoch);
-   %latest_date = parse_date($latest_epoch, 
$latest_commit{'comitter_tz'});
+   %latest_date = parse_date($latest_epoch,
+   $tags ? $latest_commit{'tz'} :
+   $latest_commit{'committer_tz'});
}
print $cgi->header(
-type => $content_type,
@@ -8043,7 +8061,9 @@ sub git_feed {
# header variables
my $title = "$site_name - $project/$action";
my $feed_type = 'log';
-   if (defined $hash) {
+   if ($tags) {
+   $feed_type = 'tags';
+   } elsif (defined $hash) {
$title .= " - '$hash'";
$feed_type = 'branch log';
if (defined $file_name) {
@@ -8060,6 +8080,7 @@ sub git_feed {
$descr = esc_html($descr);
} else {
$descr = "$project " .
+($tags ? 'tags ' : '') .
 ($format eq 'rss' ? 'RSS' : 'Atom') .
 " feed";
}
@@ -8068,7 +8089,9 @@ sub git_feed {
 
#header
my $alt_url;
-   if (defined $file_name) {
+   if ($tags) {
+   $alt_url = href(-full=>1, action=>"tags");
+   } elsif (defined $file_name) {
$alt_url = href(-full=>1, action=>"history", hash=>$hash, 
file_name=>$file_name);
} elsif (defined $hash) {
$alt_url = href(-full=>1, action=>"log", hash=>$hash);
@@ -8132,9 +8155,15 @@ XML
}
 
# contents
+   my $co_action = $tags ? 'tag' : 'commitdiff';
for (my $i = 0; $i <= $#commitlist; $i++) {
+   my %clco; # commit info from commitlist, only used for tags
my %co = %{$commitlist[$i]};
my $commit = $co{'id'};
+   if ($tags) {
+   %clco = %co;
+   %co = parse_tag($commit);
+   }
# we read 150, we always show 30 and the ones more recent than 
48 hours
if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
last;
@@ -8142,44 +8171,52 @@ XML
my %cd = parse_date($co{'author_epoch'}, $co{'author_tz'});
 
# get list of changed files
-   open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
-   $co{'parent'} || "--root",
-   $co{'id'}, "--", (defined $file_name ? $file_name : ())
-   or next;
-   my @difftree = map { chomp; $_ } <$fd>;
-   close $fd
-   or next;
+   my @difftree;
+   unless ($tags) {
+   open my $fd, "-|", git_cmd(), "diff-tree", '-r', 
@diff_opts,
+   $co{'parent'} || "--root",
+   $co{'id'}, "--", (defined $file_na