git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] [submodule] Replace perl-code with sh

From
Fredrik Gustafsson <iveqy@iveqy.com>
Date
Jun 11, 2013, 23:04 UTC
Message-ID
<1370991854-1414-3-git-send-email-iveqy@iveqy.com>
In-Reply-To
<1370991854-1414-1-git-send-email-iveqy@iveqy.com>

This is a work built on http://thread.gmane.org/gmane.comp.version-control.git/198873/focus=198930

Basically git-submodule.sh needs to use something else than sh to handle newline in filenames (and therefore needs to use a language that accepts \0 in strings).

However, since we're not there yet. I've thrown out the only perl-dependency for git-submodule.sh. It decreases the number of lines of code and uses the same solution as the rest of the script already do.

This would lead to less forks and faster code. A simple testrun of t7400-submodule-basic.sh before this patch resulted in: real 0m8.359s user 0m8.921s sys 0m3.888s

real 0m9.062s user 0m9.025s sys 0m3.784s

real 0m8.490s user 0m9.065s sys 0m3.740s

After this patch was applied: real 0m7.417s user 0m8.717s sys 0m3.804s

real 0m7.873s user 0m8.821s sys 0m3.692s

real 0m8.950s user 0m8.765s sys 0m3.760s

Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>
---
 git-submodule.sh | 52 +++++++++++++++++++++++-----------------------------
 1 file changed, 23 insertions(+), 29 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 31524d3..1652781 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -112,39 +112,33 @@ resolve_relative_url ()
 #
 module_list()
 {
+	null_sha1=0000000000000000000000000000000000000000
+	unmerged=
 	(
 		git ls-files --error-unmatch --stage -z -- "$@" ||
-		echo "unmatched pathspec exists"
+		echo "#unmatched"
 	) |
 	sed -e 's/\x00/\n/g' |
-	perl -e '
-	my %unmerged = ();
-	my ($null_sha1) = ("0" x 40);
-	my @out = ();
-	my $unmatched = 0;
-	while (<STDIN>) {
-		if (/^unmatched pathspec/) {
-			$unmatched = 1;
-			next;
-		}
-		chomp;
-		my ($mode, $sha1, $stage, $path) =
-			/^([0-7]+) ([0-9a-f]{40}) ([0-3])\t(.*)$/;
-		next unless $mode eq "160000";
-		if ($stage ne "0") {
-			if (!$unmerged{$path}++) {
-				push @out, "$mode $null_sha1 U\t$path\n";
-			}
-			next;
-		}
-		push @out, "$_\n";
-	}
-	if ($unmatched) {
-		print "#unmatched\n";
-	} else {
-		print for (@out);
-	}
-	'
+	while read mode sha1 stage path
+	do
+		if test $mode = "#unmatched"
+		then
+			echo "#unmatched"
+		fi
+		if test $mode = "160000"
+		then
+			if test $stage != "0"
+			then
+				if test "$unmerged" != "$path"
+				then
+					echo "$mode $null_sha1 U $path"
+				fi
+				unmerged="$path"
+			else
+				echo "$mode $sha1 $stage $path"
+			fi
+		fi
+	done
 }
 
 die_if_unmatched ()
-- 
1.8.3.253.g20b40b5.dirty
Previous: Phil HordNext: Junio C Hamano
Message 8 of 9 in “module_list enhancements”
  1. 0/2 module_list enhancementsFredrik Gustafsson, Jun 11, 2013
  2. 1/2 [submodule] handle multibyte characters in nameFredrik Gustafsson, Jun 11, 2013
  3. Junio C HamanoJun 12, 2013
  4. Jens LehmannJun 12, 2013
  5. Junio C HamanoJun 12, 2013
  6. Fredrik GustafssonJun 12, 2013
  7. Phil HordJun 13, 2013
  8. 2/2 [submodule] Replace perl-code with shFredrik Gustafsson, Jun 11, 2013
  9. Junio C HamanoJun 12, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.