aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2008-08-27 12:00:15 +0200
committerSimon Josefsson <simon@josefsson.org>2008-08-27 12:00:15 +0200
commit2ff03f8c1e9cc3103d5702ac293049fba0f7e675 (patch)
tree1dd6e2a75cfdb2882c6c34f0d4cd5c1d9b8cc1d1
parent875f68698ab8143743550ce95b830c130f5587e2 (diff)
downloadgit2cl-2ff03f8c1e9cc3103d5702ac293049fba0f7e675.zip
git2cl-2ff03f8c1e9cc3103d5702ac293049fba0f7e675.tar.gz
git2cl-2ff03f8c1e9cc3103d5702ac293049fba0f7e675.tar.bz2
Invoke git-log if not used as a pipe.
-rwxr-xr-xgit2cl30
1 files changed, 29 insertions, 1 deletions
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 <http://www.red-bean.com/cvs2cl/>:
@@ -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: (.*),) {