From 2ff03f8c1e9cc3103d5702ac293049fba0f7e675 Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Wed, 27 Aug 2008 12:00:15 +0200 Subject: [PATCH] Invoke git-log if not used as a pipe. --- git2cl | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/git2cl b/git2cl index 9248895..534b78a 100755 --- a/git2cl +++ b/git2cl @@ -10,6 +10,8 @@ # - skip "merge branch" statements as they don't # have information about files (i.e. we never # go into $state 2) +# - behaves like a pipe/filter if input is given from the CLI +# else it calls git log by itself # # The functions mywrap, last_line_len, wrap_log_entry are derived from # the cvs2cl tool, see : @@ -34,6 +36,7 @@ use strict; use POSIX qw(strftime); use Text::Wrap qw(wrap); +use FileHandle; use constant EMPTY_LOG_MESSAGE => '*** empty log message ***'; @@ -53,6 +56,16 @@ my %month = ( 'Nov'=>10, 'Dec'=>11, ); + +my $fh = new FileHandle; + +sub key_ready +{ + my ($rin, $nfd); + vec($rin, fileno(STDIN), 1) = 1; + return $nfd = select($rin, undef, undef, 0); +} + sub strptime { my $str = shift; return undef if not defined $str; @@ -275,7 +288,22 @@ my $done = 0; $state = 0; -while (my $_l = <>) { +# if reading from STDIN, we assume that we are +# getting git log as input +if (key_ready()) +{ + + #my $dummyfh; # don't care about writing + #($fh,$dummyfh) = FileHandle::pipe; + $fh->fdopen(*STDIN, 'r'); +} +else +{ + $fh->open("LC_ALL=C git log --pretty --numstat --summary|") + or die("Cannot execute git log...$!\n"); +} + +while (my $_l = <$fh>) { #print STDERR "debug ($state, " . (@date ? (strftime "%Y-%m-%d", @date) : "") . "): `$_'\n"; if ($state == 0) { if ($_l =~ m,^Author: (.*),) { -- 2.11.4.GIT