git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [RFC PATCH 0/2] gitweb: tags feed
@ 2012-09-25 20:10 Giuseppe Bilotta
  2012-09-25 20:10 ` [PATCH 1/2] gitweb: infrastructure for " Giuseppe Bilotta
  2012-09-25 20:10 ` [PATCH 2/2] gitweb: expose tags feed in appropriate places Giuseppe Bilotta
  0 siblings, 2 replies; 4+ messages in thread
From: Giuseppe Bilotta @ 2012-09-25 20:10 UTC (permalink / raw)
  To: git; +Cc: Jakub Narebski, Giuseppe Bilotta

The idea of this small patchset is to generate feeds listing only tags.
This is useful to allow users to follow only the ‘stable’ (i.e. tagged, not
in-progress) releases of the project from its gitweb (e.g. because the
project doesn't have an actual website, or whatever).

It's a draft implementation, comments welcome.

Giuseppe Bilotta (2):
  gitweb: infrastructure for tags feed
  gitweb: expose tags feed in appropriate places

 gitweb/gitweb.perl | 126 ++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 91 insertions(+), 35 deletions(-)

-- 
1.7.12.1.577.gff9625d

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] gitweb: infrastructure for tags feed
  2012-09-25 20:10 [RFC PATCH 0/2] gitweb: tags feed Giuseppe Bilotta
@ 2012-09-25 20:10 ` Giuseppe Bilotta
  2012-09-25 20:10 ` [PATCH 2/2] gitweb: expose tags feed in appropriate places Giuseppe Bilotta
  1 sibling, 0 replies; 4+ messages in thread
From: Giuseppe Bilotta @ 2012-09-25 20:10 UTC (permalink / raw)
  To: git; +Cc: Jakub Narebski, Giuseppe Bilotta

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 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_name ? $file_name : ())
+				or next;
+			@difftree = map { chomp; $_ } <$fd>;
+			close $fd
+				or next;
+		}
+
+		my $co_hash = $tags ? $clco{'name'} : $commit;
+		my $co_url = href(-full=>1, action=>$co_action, hash=>$co_hash);
+		my $co_title = esc_html($tags ? $clco{'subject'} : $co{'title'});
 
 		# print element (entry, item)
-		my $co_url = href(-full=>1, action=>"commitdiff", hash=>$commit);
 		if ($format eq 'rss') {
 			print "<item>\n" .
-			      "<title>" . esc_html($co{'title'}) . "</title>\n" .
+			      "<title>" . $co_title . "</title>\n" .
 			      "<author>" . esc_html($co{'author'}) . "</author>\n" .
 			      "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
 			      "<guid isPermaLink=\"true\">$co_url</guid>\n" .
 			      "<link>$co_url</link>\n" .
-			      "<description>" . esc_html($co{'title'}) . "</description>\n" .
+			      "<description>" . $co_title . "</description>\n" .
 			      "<content:encoded>" .
 			      "<![CDATA[\n";
 		} elsif ($format eq 'atom') {
 			print "<entry>\n" .
-			      "<title type=\"html\">" . esc_html($co{'title'}) . "</title>\n" .
+			      "<title type=\"html\">" . $co_title . "</title>\n" .
 			      "<updated>$cd{'iso-8601'}</updated>\n" .
 			      "<author>\n" .
 			      "  <name>" . esc_html($co{'author_name'}) . "</name>\n";
 			if ($co{'author_email'}) {
 				print "  <email>" . esc_html($co{'author_email'}) . "</email>\n";
 			}
-			print "</author>\n" .
+			print "</author>\n";
+			unless ($tags) {
 			      # use committer for contributor
-			      "<contributor>\n" .
+			      print "<contributor>\n" .
 			      "  <name>" . esc_html($co{'committer_name'}) . "</name>\n";
-			if ($co{'committer_email'}) {
+			}
+			if (!$tags && $co{'committer_email'}) {
 				print "  <email>" . esc_html($co{'committer_email'}) . "</email>\n";
 			}
-			print "</contributor>\n" .
-			      "<published>$cd{'iso-8601'}</published>\n" .
+			print "</contributor>\n" unless $tags;
+			print "<published>$cd{'iso-8601'}</published>\n" .
 			      "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
 			      "<id>$co_url</id>\n" .
 			      "<content type=\"xhtml\" xml:base=\"" . esc_url($my_url) . "\">\n" .
-- 
1.7.12.1.577.gff9625d

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] gitweb: expose tags feed in appropriate places
  2012-09-25 20:10 [RFC PATCH 0/2] gitweb: tags feed Giuseppe Bilotta
  2012-09-25 20:10 ` [PATCH 1/2] gitweb: infrastructure for " Giuseppe Bilotta
@ 2012-09-25 20:10 ` Giuseppe Bilotta
  1 sibling, 0 replies; 4+ messages in thread
From: Giuseppe Bilotta @ 2012-09-25 20:10 UTC (permalink / raw)
  To: git; +Cc: Jakub Narebski, Giuseppe Bilotta

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 gitweb/gitweb.perl | 47 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 33 insertions(+), 14 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 6cb51f7..9ac28aa 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -804,6 +804,8 @@ our %actions = (
 	"summary" => \&git_summary,
 	"tag" => \&git_tag,
 	"tags" => \&git_tags,
+	"tags_rss" => \&git_tags_rss,
+	"tags_atom" => \&git_tags_atom,
 	"tree" => \&git_tree,
 	"snapshot" => \&git_snapshot,
 	"object" => \&git_object,
@@ -2518,7 +2520,7 @@ sub get_feed_info {
 	return unless (defined $project);
 	# some views should link to OPML, or to generic project feed,
 	# or don't have specific feed yet (so they should use generic)
-	return if (!$action || $action =~ /^(?:tags|heads|forks|tag|search)$/x);
+	return if (!$action || $action =~ /^(?:heads|forks|search)$/x);
 
 	my $branch;
 	# branches refs uses 'refs/heads/' prefix (fullname) to differentiate
@@ -2528,8 +2530,10 @@ sub get_feed_info {
 		$branch = $1;
 	}
 	# find log type for feed description (title)
-	my $type = 'log';
-	if (defined $file_name) {
+	my $type = "log";
+	if ($action eq 'tag' || $action eq 'tags') {
+		$type = "tags";
+	} elsif (defined $file_name) {
 		$type  = "history of $file_name";
 		$type .= "/" if ($action eq 'tree');
 		$type .= " on '$branch'" if (defined $branch);
@@ -3907,6 +3911,7 @@ sub print_feed_meta {
 			$href_params{'-title'} = 'log';
 		}
 
+		my $tag_view = $href_params{-title} eq 'tags';
 		foreach my $format (qw(RSS Atom)) {
 			my $type = lc($format);
 			my %link_attr = (
@@ -3916,7 +3921,7 @@ sub print_feed_meta {
 			);
 
 			$href_params{'extra_options'} = undef;
-			$href_params{'action'} = $type;
+			$href_params{'action'} = ($tag_view ? 'tags_' : '') . $type;
 			$link_attr{'-href'} = href(%href_params);
 			print "<link ".
 			      "rel=\"$link_attr{'-rel'}\" ".
@@ -3925,15 +3930,17 @@ sub print_feed_meta {
 			      "type=\"$link_attr{'-type'}\" ".
 			      "/>\n";
 
-			$href_params{'extra_options'} = '--no-merges';
-			$link_attr{'-href'} = href(%href_params);
-			$link_attr{'-title'} .= ' (no merges)';
-			print "<link ".
-			      "rel=\"$link_attr{'-rel'}\" ".
-			      "title=\"$link_attr{'-title'}\" ".
-			      "href=\"$link_attr{'-href'}\" ".
-			      "type=\"$link_attr{'-type'}\" ".
-			      "/>\n";
+			unless ($tag_view) {
+				$href_params{'extra_options'} = '--no-merges';
+				$link_attr{'-href'} = href(%href_params);
+				$link_attr{'-title'} .= ' (no merges)';
+				print "<link ".
+				      "rel=\"$link_attr{'-rel'}\" ".
+				      "title=\"$link_attr{'-title'}\" ".
+				      "href=\"$link_attr{'-href'}\" ".
+				      "type=\"$link_attr{'-type'}\" ".
+				      "/>\n";
+			}
 		}
 
 	} else {
@@ -4115,8 +4122,9 @@ sub git_footer_html {
 		}
 		$href_params{'-title'} ||= 'log';
 
+		my $tag_view = $href_params{-title} eq 'tags';
 		foreach my $format (qw(RSS Atom)) {
-			$href_params{'action'} = lc($format);
+			$href_params{'action'} = ($tag_view ? 'tags_' : '') . lc($format);
 			print $cgi->a({-href => href(%href_params),
 			              -title => "$href_params{'-title'} $format feed",
 			              -class => $feed_class}, $format)."\n";
@@ -8280,10 +8288,18 @@ sub git_rss {
 	git_feed('rss');
 }
 
+sub git_tags_rss {
+	git_feed('rss', 'tags')
+}
+
 sub git_atom {
 	git_feed('atom');
 }
 
+sub git_tags_atom {
+	git_feed('atom', 'tags')
+}
+
 sub git_opml {
 	my @list = git_get_projects_list($project_filter, $strict_export);
 	if (!@list) {
@@ -8328,6 +8344,9 @@ XML
 		my $rss  = href('project' => $proj{'path'}, 'action' => 'rss', -full => 1);
 		my $html = href('project' => $proj{'path'}, 'action' => 'summary', -full => 1);
 		print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
+		# and now the tags rss feed
+		$rss  = href('project' => $proj{'path'}, 'action' => 'tags_rss', -full => 1);
+		print "<outline type=\"rss\" text=\"$path tags\" title=\"$path tags\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
 	}
 	print <<XML;
 </outline>
-- 
1.7.12.1.577.gff9625d

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] gitweb: expose tags feed in appropriate places
  2017-04-19  6:49 [PATCH 0/2] gitweb: tags feeds Giuseppe Bilotta
@ 2017-04-19  6:49 ` Giuseppe Bilotta
  0 siblings, 0 replies; 4+ messages in thread
From: Giuseppe Bilotta @ 2017-04-19  6:49 UTC (permalink / raw)
  To: Git ML; +Cc: Junio C Hamano, Jakub Narebski, Giuseppe Bilotta

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 gitweb/gitweb.perl | 47 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 33 insertions(+), 14 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 4adea84006..8be7444988 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -851,6 +851,8 @@ our %actions = (
 	"summary" => \&git_summary,
 	"tag" => \&git_tag,
 	"tags" => \&git_tags,
+	"tags_rss" => \&git_tags_rss,
+	"tags_atom" => \&git_tags_atom,
 	"tree" => \&git_tree,
 	"snapshot" => \&git_snapshot,
 	"object" => \&git_object,
@@ -2599,7 +2601,7 @@ sub get_feed_info {
 	return unless (defined $project);
 	# some views should link to OPML, or to generic project feed,
 	# or don't have specific feed yet (so they should use generic)
-	return if (!$action || $action =~ /^(?:tags|heads|forks|tag|search)$/x);
+	return if (!$action || $action =~ /^(?:heads|forks|search)$/x);
 
 	my $branch = undef;
 	# branches refs uses 'refs/' + $get_branch_refs()[x] + '/' prefix
@@ -2614,8 +2616,10 @@ sub get_feed_info {
 		}
 	}
 	# find log type for feed description (title)
-	my $type = 'log';
-	if (defined $file_name) {
+	my $type = "log";
+	if ($action eq 'tag' || $action eq 'tags') {
+		$type = "tags";
+	} elsif (defined $file_name) {
 		$type  = "history of $file_name";
 		$type .= "/" if ($action eq 'tree');
 		$type .= " on '$branch'" if (defined $branch);
@@ -4007,6 +4011,7 @@ sub print_feed_meta {
 			$href_params{'-title'} = 'log';
 		}
 
+		my $tag_view = $href_params{-title} eq 'tags';
 		foreach my $format (qw(RSS Atom)) {
 			my $type = lc($format);
 			my %link_attr = (
@@ -4016,7 +4021,7 @@ sub print_feed_meta {
 			);
 
 			$href_params{'extra_options'} = undef;
-			$href_params{'action'} = $type;
+			$href_params{'action'} = ($tag_view ? 'tags_' : '') . $type;
 			$link_attr{'-href'} = href(%href_params);
 			print "<link ".
 			      "rel=\"$link_attr{'-rel'}\" ".
@@ -4025,15 +4030,17 @@ sub print_feed_meta {
 			      "type=\"$link_attr{'-type'}\" ".
 			      "/>\n";
 
-			$href_params{'extra_options'} = '--no-merges';
-			$link_attr{'-href'} = href(%href_params);
-			$link_attr{'-title'} .= ' (no merges)';
-			print "<link ".
-			      "rel=\"$link_attr{'-rel'}\" ".
-			      "title=\"$link_attr{'-title'}\" ".
-			      "href=\"$link_attr{'-href'}\" ".
-			      "type=\"$link_attr{'-type'}\" ".
-			      "/>\n";
+			unless ($tag_view) {
+				$href_params{'extra_options'} = '--no-merges';
+				$link_attr{'-href'} = href(%href_params);
+				$link_attr{'-title'} .= ' (no merges)';
+				print "<link ".
+				      "rel=\"$link_attr{'-rel'}\" ".
+				      "title=\"$link_attr{'-title'}\" ".
+				      "href=\"$link_attr{'-href'}\" ".
+				      "type=\"$link_attr{'-type'}\" ".
+				      "/>\n";
+			}
 		}
 
 	} else {
@@ -4217,8 +4224,9 @@ sub git_footer_html {
 		}
 		$href_params{'-title'} ||= 'log';
 
+		my $tag_view = $href_params{-title} eq 'tags';
 		foreach my $format (qw(RSS Atom)) {
-			$href_params{'action'} = lc($format);
+			$href_params{'action'} = ($tag_view ? 'tags_' : '') . lc($format);
 			print $cgi->a({-href => href(%href_params),
 			              -title => "$href_params{'-title'} $format feed",
 			              -class => $feed_class}, $format)."\n";
@@ -8409,10 +8417,18 @@ sub git_rss {
 	git_feed('rss');
 }
 
+sub git_tags_rss {
+	git_feed('rss', 'tags')
+}
+
 sub git_atom {
 	git_feed('atom');
 }
 
+sub git_tags_atom {
+	git_feed('atom', 'tags')
+}
+
 sub git_opml {
 	my @list = git_get_projects_list($project_filter, $strict_export);
 	if (!@list) {
@@ -8457,6 +8473,9 @@ XML
 		my $rss  = href('project' => $proj{'path'}, 'action' => 'rss', -full => 1);
 		my $html = href('project' => $proj{'path'}, 'action' => 'summary', -full => 1);
 		print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
+		# and now the tags rss feed
+		$rss  = href('project' => $proj{'path'}, 'action' => 'tags_rss', -full => 1);
+		print "<outline type=\"rss\" text=\"$path tags\" title=\"$path tags\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
 	}
 	print <<XML;
 </outline>
-- 
2.12.2.822.g5451c77231


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-19  6:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-25 20:10 [RFC PATCH 0/2] gitweb: tags feed Giuseppe Bilotta
2012-09-25 20:10 ` [PATCH 1/2] gitweb: infrastructure for " Giuseppe Bilotta
2012-09-25 20:10 ` [PATCH 2/2] gitweb: expose tags feed in appropriate places Giuseppe Bilotta
  -- strict thread matches above, loose matches on Subject: below --
2017-04-19  6:49 [PATCH 0/2] gitweb: tags feeds Giuseppe Bilotta
2017-04-19  6:49 ` [PATCH 2/2] gitweb: expose tags feed in appropriate places Giuseppe Bilotta

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).