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

[PATCH] Replace perl code with pure shell code

From
Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
Date
Jan 29, 2007, 08:09 UTC
Message-ID
<45BDABB5.4070301@fs.ei.tum.de>
Signed-off-by: Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
---
 git-clone.sh |   65 ++++++++++++++++++---------------------------------------
 1 files changed, 21 insertions(+), 44 deletions(-)
diff --git a/git-clone.sh b/git-clone.sh
index ced7dfb..b3c6fa4 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -66,48 +66,6 @@ Perhaps git-update-server-info needs to be run there?"
 	rm -f "$GIT_DIR/REMOTE_HEAD"
 }
 
-# Read git-fetch-pack -k output and store the remote branches.
-copy_refs='
-use File::Path qw(mkpath);
-use File::Basename qw(dirname);
-my $git_dir = $ARGV[0];
-my $use_separate_remote = $ARGV[1];
-my $origin = $ARGV[2];
-
-my $branch_top = ($use_separate_remote ? "remotes/$origin" : "heads");
-my $tag_top = "tags";
-
-sub store {
-	my ($sha1, $name, $top) = @_;
-	$name = "$git_dir/refs/$top/$name";
-	mkpath(dirname($name));
-	open O, ">", "$name";
-	print O "$sha1\n";
-	close O;
-}
-
-open FH, "<", "$git_dir/CLONE_HEAD";
-while (<FH>) {
-	my ($sha1, $name) = /^([0-9a-f]{40})\s(.*)$/;
-	next if ($name =~ /\^\173/);
-	if ($name eq "HEAD") {
-		open O, ">", "$git_dir/REMOTE_HEAD";
-		print O "$sha1\n";
-		close O;
-		next;
-	}
-	if ($name =~ s/^refs\/heads\///) {
-		store($sha1, $name, $branch_top);
-		next;
-	}
-	if ($name =~ s/^refs\/tags\///) {
-		store($sha1, $name, $tag_top);
-		next;
-	}
-}
-close FH;
-'
-
 quiet=
 local=no
 use_local=no
@@ -332,8 +290,27 @@ test -d "$GIT_DIR/refs/reference-tmp" && rm -fr "$GIT_DIR/refs/reference-tmp"
 if test -f "$GIT_DIR/CLONE_HEAD"
 then
 	# Read git-fetch-pack -k output and store the remote branches.
-	@@PERL@@ -e "$copy_refs" "$GIT_DIR" "$use_separate_remote" "$origin" ||
-	exit
+	if [ -n "$use_separate_remote" ]
+	then
+		branch_top="remotes/$origin"
+	else
+		branch_top="heads"
+	fi
+	tag_top="tags"
+	while read sha1 name
+	do
+		case "$name" in
+		HEAD)
+			destname="REMOTE_HEAD" ;;
+		refs/heads/*)
+			destname="refs/$branch_top/${name#refs/heads/}" ;;
+		refs/tags/*)
+			destname="refs/$tag_top/${name#refs/tags/}" ;;
+		*)
+			continue ;;
+		esac
+		git-update-ref -m "clone: from $repo" "$destname" "$sha1" ""
+	done < "$GIT_DIR/CLONE_HEAD"
 fi
 
 cd "$D" || exit
-- 
1.5.0.rc1.196.geebfb
Next: Junio C Hamano
Message 1 of 12 in “Replace perl code with pure shell code”
  1. Replace perl code with pure shell codeSimon 'corecode' Schubert, Jan 29, 2007
  2. Junio C HamanoJan 29, 2007
  3. Replace perl code with pure shell codeSimon 'corecode' Schubert, Jan 29, 2007
  4. Shawn O. PearceJan 29, 2007
  5. Randal L. SchwartzJan 29, 2007
  6. Nikolai WeibullJan 29, 2007
  7. Randal L. SchwartzJan 29, 2007
  8. Nikolai WeibullJan 29, 2007
  9. Randal L. SchwartzJan 29, 2007
  10. Junio C HamanoJan 30, 2007
  11. Jakub NarebskiJan 29, 2007
  12. Randal L. SchwartzJan 29, 2007

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.