Add functions to help read and write capabilities. These functions will be reused in following patches.
Signed-off-by: Christian Couder <chrisc...@tuxfamily.org> --- t/t0021/rot13-filter.pl | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/t/t0021/rot13-filter.pl b/t/t0021/rot13-filter.pl index 278fc6f534..ba18b207c6 100644 --- a/t/t0021/rot13-filter.pl +++ b/t/t0021/rot13-filter.pl @@ -116,20 +116,44 @@ sub packet_initialize { packet_flush(); } +sub packet_read_capabilities { + my @cap; + while (1) { + my ( $res, $buf ) = packet_bin_read(); + return ( $res, @cap ) if ( $res != 0 ); + unless ( $buf =~ s/\n$// ) { + die "A non-binary line MUST be terminated by an LF.\n" + . "Received: '$buf'"; + } + die "bad capability buf: '$buf'" unless ( $buf =~ s/capability=// ); + push @cap, $buf; + } +} + +sub packet_read_and_check_capabilities { + my @local_caps = @_; + my @remote_res_caps = packet_read_capabilities(); + my $res = shift @remote_res_caps; + my %remote_caps = map { $_ => 1 } @remote_res_caps; + foreach (@local_caps) { + die "'$_' capability not available" unless (exists($remote_caps{$_})); + } + return $res; +} + +sub packet_write_capabilities { + packet_txt_write( "capability=" . $_ ) foreach (@_); + packet_flush(); +} + print $debug "START\n"; $debug->flush(); packet_initialize("git-filter", 2); -( packet_txt_read() eq ( 0, "capability=clean" ) ) || die "bad capability"; -( packet_txt_read() eq ( 0, "capability=smudge" ) ) || die "bad capability"; -( packet_txt_read() eq ( 0, "capability=delay" ) ) || die "bad capability"; -( packet_bin_read() eq ( 1, "" ) ) || die "bad capability end"; +packet_read_and_check_capabilities("clean", "smudge", "delay"); +packet_write_capabilities(@capabilities); -foreach (@capabilities) { - packet_txt_write( "capability=" . $_ ); -} -packet_flush(); print $debug "init handshake complete\n"; $debug->flush(); -- 2.14.1.576.g3f707d88cd