diff mbox series

misc. gitweb patches (directories first, …)

Message ID a9673d0b-4698-fc68-1a80-10940c4a8330@debian.org (mailing list archive)
State New
Headers show
Series misc. gitweb patches (directories first, …) | expand

Commit Message

Thorsten Glaser Feb. 28, 2025, 6:31 a.m. UTC
Hi again²,

and while at it, why not feed the remainder of my local gitweb
patches to you in the hope they can be applied.

The two extra comments are to not desynchronise the syntax
highlighting of my editor (jupp) which mis-interprets the
presence of that unescaped double quote in the regex before.

The other hunk is to render subdirectories before files in
a directory, as is prudent and expected, on Unix at least.
It may not be the most efficient way to do this (I’m not a
Perl programmer, but willing to learn) though does the job.



bye,
//mirabilos
diff mbox series

Patch

diff --git a/src/plugins/scmgit/cgi-bin/gitweb.cgi b/src/plugins/scmgit/cgi-bin/gitweb.cgi
index c81eef0e5d..909d55792a 100755
--- a/src/plugins/scmgit/cgi-bin/gitweb.cgi
+++ b/src/plugins/scmgit/cgi-bin/gitweb.cgi
@@ -5436,7 +5437,7 @@  sub git_patchset_body {
 	while ($patch_line) {
 
 		# parse "git diff" header line
-		if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
+		if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {  #"
 			# $1 is from_name, which we do not use
 			$to_name = unquote($2);
 			$to_name =~ s!^b/!!;
@@ -7287,8 +7288,26 @@  sub git_tree {
 
 		print "</tr>\n";
 	}
+	# directories first
 	foreach my $line (@entries) {
 		my %t = parse_ls_tree_line($line, -z => 1, -l => $show_sizes);
+		next unless ($t{'type'} eq "tree");
+
+		if ($alternate) {
+			print "<tr class=\"dark\">\n";
+		} else {
+			print "<tr class=\"light\">\n";
+		}
+		$alternate ^= 1;
+
+		git_print_tree_entry(\%t, $basedir, $hash_base, $have_blame);
+
+		print "</tr>\n";
+	}
+	# then nōn-directories
+	foreach my $line (@entries) {
+		my %t = parse_ls_tree_line($line, -z => 1, -l => $show_sizes);
+		next if ($t{'type'} eq "tree");
 
 		if ($alternate) {
 			print "<tr class=\"dark\">\n";
@@ -7422,7 +7441,7 @@  sub git_snapshot {
 		$cmd .= ' | ' . quote_command(@{$known_snapshot_formats{$format}{'compressor'}});
 	}
 
-	$filename =~ s/(["\\])/\\$1/g;
+	$filename =~ s/(["\\])/\\$1/g;  #"
 	my %latest_date;
 	if (%co) {
 		%latest_date = parse_date($co{'committer_epoch'}, $co{'committer_tz'});