threads / discuss / 3443

PATCH: simplify calls to git programs in git-fmt-merge-msg

Subject: PATCH: simplify calls to git programs in git-fmt-merge-msg

## tl;dr

5 messages between Feb 23, 2006 and Feb 23, 2006.

replies: 4people: 3as markdown or json

Alex Riesen· Feb 23, 2006, 10:26 UTC · lore
It also makes it work on ActiveState Perl.
---
 git-fmt-merge-msg.perl |   31 +++++--------------------------
 1 files changed, 5 insertions(+), 26 deletions(-)
1c0dd861fa32017cf7bc4226bfa54d390a3fb91e
diff --git a/git-fmt-merge-msg.perl b/git-fmt-merge-msg.perl
index c13af48..dae383f 100755
--- a/git-fmt-merge-msg.perl
+++ b/git-fmt-merge-msg.perl
@@ -28,28 +28,13 @@ sub andjoin {
 }
 
 sub repoconfig {
-	my $val;
-	eval {
-		my $pid = open(my $fh, '-|');
-		if (!$pid) {
-			exec('git-repo-config', '--get', 'merge.summary');
-		}
-		($val) = <$fh>;
-		close $fh;
-	};
+	my ($val) = qx{git-repo-config --get merge.summary};
 	return $val;
 }
 
 sub current_branch {
-	my $fh;
-	my $pid = open($fh, '-|');
-	die "$!" unless defined $pid;
-	if (!$pid) {
-	    exec('git-symbolic-ref', 'HEAD') or die "$!";
-	}
-	my ($bra) = <$fh>;
+	my ($bra) = qx{git-symbolic-ref HEAD};
 	chomp($bra);
-	close $fh or die "$!";
 	$bra =~ s|^refs/heads/||;
 	if ($bra ne 'master') {
 		$bra = " into $bra";
@@ -61,18 +46,12 @@ sub current_branch {
 
 sub shortlog {
 	my ($tip) = @_;
-	my ($fh, @result);
-	my $pid = open($fh, '-|');
-	die "$!" unless defined $pid;
-	if (!$pid) {
-	    exec('git-log', '--topo-order',
-		 '--pretty=oneline', $tip, '^HEAD') or die "$!";
-	}
-	while (<$fh>) {
+	my @result;
+	foreach ( qx{git-log --topo-order --pretty=oneline $tip ^HEAD} ) {
 		s/^[0-9a-f]{40}\s+//;
 		push @result, $_;
 	}
-	close $fh or die "$!";
+	die "git-log failed\n" if $?;
 	return @result;
 }
 
-- 
1.2.3.g6ae0e
Junio C Hamano· Feb 23, 2006, 10:35 UTC · re: Alex Riesen · lore

Re: PATCH: simplify calls to git programs in git-fmt-merge-msg

"Alex Riesen" <raa.lkml@gmail.com> writes:
> It also makes it work on ActiveState Perl.
>
> ---

ActiveState or not, this simplification is pretty much welcomed. The only problem I _might_ have later is with shortlog, though I have not looked at it closely yet.

Thanks.
Alex Riesen· Feb 23, 2006, 10:57 UTC · re: Junio C Hamano · lore

Re: PATCH: simplify calls to git programs in git-fmt-merge-msg

On 2/23/06, Junio C Hamano <junkio@cox.net> wrote:
Show 8 quoted lines
>
> > It also makes it work on ActiveState Perl.
> >
> > ---
>
> ActiveState or not, this simplification is pretty much welcomed.
> The only problem I _might_ have later is with shortlog, though I
> have not looked at it closely yet.
I tested it a bit.
I suppose you can have two following concerns there:
- $tip - it seem to be always an sha1
- perl can decide to fetch whole output of git-log into memory.
  I heard it optimizes such cases into reading only when needed...
Johannes Schindelin· Feb 23, 2006, 12:36 UTC · re: Alex Riesen · lore

Re: PATCH: simplify calls to git programs in git-fmt-merge-msg

Hi,
On Thu, 23 Feb 2006, Alex Riesen wrote:
> It also makes it work on ActiveState Perl.
Thank you for teaching me this very valuable construct: qx{ ... }.

Ciao, Dscho

Alex Riesen· Feb 23, 2006, 12:40 UTC · re: Johannes Schindelin · lore

Re: PATCH: simplify calls to git programs in git-fmt-merge-msg

On 2/23/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
>
> > It also makes it work on ActiveState Perl.
>
> Thank you for teaching me this very valuable construct: qx{ ... }.
You're welcome. That's the same as shells old `` (backquote).

← back to recent threads