diff options
author | Eric Wong <e@80x24.org> | 2016-03-03 03:12:12 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-04-05 18:58:27 +0000 |
commit | 64d131a6b4435289f8876b20510a6d80d4dde418 (patch) | |
tree | 8a630fe0e16659df08a36b6a5f8d9f9738cfbc47 /lib/PublicInbox/Git.pm | |
parent | 38f685ef4c78788324089f9d1365c7676aa5a5aa (diff) | |
download | public-inbox-64d131a6b4435289f8876b20510a6d80d4dde418.tar.gz |
This should allow us to avoid polluting stderr output when HTTP clients inevitably request broken revisions.
Diffstat (limited to 'lib/PublicInbox/Git.pm')
-rw-r--r-- | lib/PublicInbox/Git.pm | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index bd945007..2b6782a7 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -12,6 +12,8 @@ use warnings; use POSIX qw(dup2); require IO::Handle; use PublicInbox::Spawn qw(spawn popen_rd); +use IO::File; +use Fcntl qw(:seek); # Documentation/SubmittingPatches recommends 12 (Linux v4.4) my $abbrev = `git config core.abbrev` || 12; @@ -20,7 +22,25 @@ sub abbrev { "--abbrev=$abbrev" } sub new { my ($class, $git_dir) = @_; - bless { git_dir => $git_dir }, $class + bless { git_dir => $git_dir, err => IO::File->new_tmpfile }, $class +} + +sub err_begin ($) { + my $err = $_[0]->{err}; + sysseek($err, 0, SEEK_SET) or die "sysseek failed: $!"; + truncate($err, 0) or die "truncate failed: $!"; + my $ret = fileno($err); + defined $ret or die "fileno failed: $!"; + $ret; +} + +sub err ($) { + my $err = $_[0]->{err}; + sysseek($err, 0, SEEK_SET) or die "sysseek failed: $!"; + defined(sysread($err, my $buf, -s $err)) or die "sysread failed: $!"; + sysseek($err, 0, SEEK_SET) or die "sysseek failed: $!"; + truncate($err, 0) or die "truncate failed: $!"; + $buf; } sub _bidi_pipe { |