git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH 1/4] gitweb: Move git-ls-tree output parsing to parse_ls_tree_line
Date: Thu, 31 Aug 2006 00:32:15 +0200	[thread overview]
Message-ID: <200608310032.15543.jnareb@gmail.com> (raw)
In-Reply-To: <200608310030.33512.jnareb@gmail.com>

Add new subroutine parse_ls_tree_line and use it in git_tree.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This patch could be applied regardless of the fact that this 
"tree_blame" view series is proof-of-concept series.

 gitweb/gitweb.perl |   62 ++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index fa7f62a..84a13fd 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1021,6 +1021,27 @@ sub parse_difftree_raw_line {
 	return wantarray ? %res : \%res;
 }
 
+# parse line of git-ls-tree output
+sub parse_ls_tree_line ($;%) {
+	my $line = shift;
+	my %opts = @_;
+	my %res;
+
+	#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa	panic.c'
+	$line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
+
+	$res{'mode'} = $1;
+	$res{'type'} = $2;
+	$res{'hash'} = $3;
+	if ($opts{'-z'}) {
+		$res{'name'} = $4;
+	} else {
+		$res{'name'} = unquote($4);
+	}
+
+	return wantarray ? %res : \%res;
+}
+
 ## ......................................................................
 ## parse to array of hashes functions
 
@@ -2498,51 +2519,54 @@ sub git_tree {
 	print "<table cellspacing=\"0\">\n";
 	my $alternate = 0;
 	foreach my $line (@entries) {
-		#'100644	blob	0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa	panic.c'
-		$line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
-		my $t_mode = $1;
-		my $t_type = $2;
-		my $t_hash = $3;
-		my $t_name = validate_input($4);
+		my %t = parse_ls_tree_line($line, -z => 1);
+
 		if ($alternate) {
 			print "<tr class=\"dark\">\n";
 		} else {
 			print "<tr class=\"light\">\n";
 		}
 		$alternate ^= 1;
-		print "<td class=\"mode\">" . mode_str($t_mode) . "</td>\n";
-		if ($t_type eq "blob") {
+
+		print "<td class=\"mode\">" . mode_str($t{'mode'}) . "</td>\n";
+		if ($t{'type'} eq "blob") {
 			print "<td class=\"list\">" .
-			      $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key),
-			              -class => "list"}, esc_html($t_name)) .
+			      $cgi->a({-href => href(action=>"blob", hash=>$t{'hash'},
+			                             file_name=>"$base$t{'name'}", %base_key),
+			              -class => "list"}, esc_html($t{'name'})) .
 			      "</td>\n" .
 			      "<td class=\"link\">" .
-			      $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
+			      $cgi->a({-href => href(action=>"blob", hash=>$t{'hash'},
+			                             file_name=>"$base$t{'name'}", %base_key)},
 			              "blob");
 			if ($have_blame) {
 				print " | " .
-					$cgi->a({-href => href(action=>"blame", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
+					$cgi->a({-href => href(action=>"blame", hash=>$t{'hash'},
+					                       file_name=>"$base$t{'name'}", %base_key)},
 					        "blame");
 			}
 			print " | " .
 			      $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
-			                             hash=>$t_hash, file_name=>"$base$t_name")},
+			                             hash=>$t{'hash'}, file_name=>"$base$t{'name'}")},
 			              "history") .
 			      " | " .
 			      $cgi->a({-href => href(action=>"blob_plain",
-			                             hash=>$t_hash, file_name=>"$base$t_name")},
+			                             hash=>$t{'hash'}, file_name=>"$base$t{'name'}")},
 			              "raw") .
 			      "</td>\n";
-		} elsif ($t_type eq "tree") {
+		} elsif ($t{'type'} eq "tree") {
 			print "<td class=\"list\">" .
-			      $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
-			              esc_html($t_name)) .
+			      $cgi->a({-href => href(action=>"tree", hash=>$t{'hash'},
+			                             file_name=>"$base$t{'name'}", %base_key)},
+			              esc_html($t{'name'})) .
 			      "</td>\n" .
 			      "<td class=\"link\">" .
-			      $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)},
+			      $cgi->a({-href => href(action=>"tree", hash=>$t{'hash'},
+			                             file_name=>"$base$t{'name'}", %base_key)},
 			              "tree") .
 			      " | " .
-			      $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, file_name=>"$base$t_name")},
+			      $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
+			                             file_name=>"$base$t{'name'}")},
 			              "history") .
 			      "</td>\n";
 		}
-- 
1.4.1.1

       reply	other threads:[~2006-08-30 22:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200608310030.33512.jnareb@gmail.com>
2006-08-30 22:32 ` Jakub Narebski [this message]
2006-08-30 22:35 ` [PATCH 2/4] gitweb: Separate printing of git_tree row into git_print_tree_entry Jakub Narebski
2006-08-30 22:36 ` [PATCH 3/4] gitweb: Extend parse_difftree_raw_line to save commit info Jakub Narebski
2006-08-30 22:36 ` [PATCH 4/4] gitweb: Add "tree_blame" view (WIP) Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200608310032.15543.jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).