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

[PATCH 2/3] cvsimport: standarize open() calls to external git tools

From
Ben Walton <bwalton@artsci.utoronto.ca>
Date
Jan 19, 2010, 19:03 UTC
Message-ID
<1263927790-1872-2-git-send-email-bwalton@artsci.utoronto.ca>
In-Reply-To
<1263927790-1872-1-git-send-email-bwalton@artsci.utoronto.ca>

This patch standardizes calls to open() where git modules are used as part of a pipeline. Instead of open(X, "git foo ... |)", use open(X, "-|", qw(git foo ...)). This standarization should see all calls made without the use of an 'sh -c' process to split the arguments.

Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>
---
 git-cvsimport.perl |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index adffa0c..e838c2e 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -617,7 +617,7 @@ unless (-d $git_dir) {
 	$last_branch = $opt_o;
 	$orig_branch = "";
 } else {
-	open(F, "git symbolic-ref HEAD |") or
+	open(F, "-|", qw(git symbolic-ref HEAD)) or
 		die "Cannot run git symbolic-ref: $!\n";
 	chomp ($last_branch = <F>);
 	$last_branch = basename($last_branch);
@@ -631,8 +631,8 @@ unless (-d $git_dir) {
 
 	# Get the last import timestamps
 	my $fmt = '($ref, $author) = (%(refname), %(author));';
-	open(H, "git for-each-ref --perl --format='$fmt' $remote |") or
-		die "Cannot run git for-each-ref: $!\n";
+	my @cmd = ('git', 'for-each-ref', '--perl', "--format=$fmt", $remote);
+	open(H, "-|", @cmd) or die "Cannot run git for-each-ref: $!\n";
 	while (defined(my $entry = <H>)) {
 		my ($ref, $author);
 		eval($entry) || die "cannot eval refs list: $@";
@@ -730,7 +730,7 @@ sub update_index (\@\@) {
 }
 
 sub write_tree () {
-	open(my $fh, '-|', "git write-tree")
+	open(my $fh, '-|', qw(git write-tree))
 		or die "unable to open git write-tree: $!";
 	chomp(my $tree = <$fh>);
 	is_sha1($tree)
-- 
1.6.5.3
Previous: Ben WaltonNext: Ben Walton
Message 5 of 6 in “cvsimport: update to use non-dash git commands”
  1. cvsimport: update to use non-dash git commandsBen Walton, Jan 17, 2010
  2. cvsimport: modernize and standardize external tool callingBen Walton, Jan 17, 2010
  3. Junio C HamanoJan 17, 2010
  4. 1/3 cvsimport: modernize callouts to git subcommandsBen Walton, Jan 19, 2010
  5. 2/3 cvsimport: standarize open() calls to external git toolsBen Walton, Jan 19, 2010
  6. 3/3 cvsimport: standarize system() calls to external git toolsBen Walton, Jan 19, 2010

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.