+ # CVS can't operate outside a srcdir, so we're always setting $CWD.
+ # "local $CWD" restores the previous value when we go out of scope.
+ # Usually that's correct. But if we're removing the last file from
+ # a directory, the post-commit hook will exec in a working directory
+ # that's about to not exist (CVS will prune it).
+ #
+ # chdir() manually here, so we can selectively not chdir() back.
+
+ my $oldcwd = $CWD;
+ chdir($config{srcdir});
+
+ eval q{
+ use IPC::Open3;
+ use Symbol qw(gensym);
+ use IO::File;
+ };
+ error($@) if $@;
+
+ my $cvsout = '';
+ my $cvserr = '';
+ local *CATCHERR = IO::File->new_tmpfile;
+ my $pid = open3(gensym(), \*CATCHOUT, ">&CATCHERR", @cmd);
+ while (my $l = <CATCHOUT>) {
+ $cvsout .= $l
+ unless 1;
+ }
+ waitpid($pid, 0);
+ my $ret = $? >> 8;
+ seek CATCHERR, 0, 0;
+ while (my $l = <CATCHERR>) {
+ $cvserr .= $l
+ unless $l =~ /^cvs commit: changing keyword expansion /;
+ }
+
+ print STDOUT $cvsout;
+ print STDERR $cvserr;