git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 5/8] t0021/rot13-filter: add packet_initialize()

From
Christian Couder <christian.couder@gmail.com>
Date
Nov 5, 2017, 21:38 UTC
Message-ID
<20171105213836.11717-6-chriscool@tuxfamily.org>
In-Reply-To
<20171105213836.11717-1-chriscool@tuxfamily.org>

Let's refactor the code to initialize communication into its own packet_initialize() function, so that we can reuse this functionality in following patches.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 t/t0021/rot13-filter.pl | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/t/t0021/rot13-filter.pl b/t/t0021/rot13-filter.pl
index f31ff595fe..2f74ab2e45 100644
--- a/t/t0021/rot13-filter.pl
+++ b/t/t0021/rot13-filter.pl
@@ -127,19 +127,25 @@ sub packet_flush {
 	STDOUT->flush();
 }
 
+sub packet_initialize {
+	my ($name, $version) = @_;
+
+	packet_compare_lists([0, $name . "-client"], packet_txt_read()) ||
+		die "bad initialize";
+	packet_compare_lists([0, "version=" . $version], packet_txt_read()) ||
+		die "bad version";
+	packet_compare_lists([1, ""], packet_bin_read()) ||
+		die "bad version end";
+
+	packet_txt_write( $name . "-server" );
+	packet_txt_write( "version=" . $version );
+	packet_flush();
+}
+
 print $debug "START\n";
 $debug->flush();
 
-packet_compare_lists([0, "git-filter-client"], packet_txt_read()) ||
-	die "bad initialize";
-packet_compare_lists([0, "version=2"], packet_txt_read()) ||
-	die "bad version";
-packet_compare_lists([1, ""], packet_bin_read()) ||
-	die "bad version end";
-
-packet_txt_write("git-filter-server");
-packet_txt_write("version=2");
-packet_flush();
+packet_initialize("git-filter", 2);
 
 packet_compare_lists([0, "capability=clean"], packet_txt_read()) ||
 	die "bad capability";
-- 
2.15.0.7.ga9ff306ed9.dirty
Previous: Christian CouderNext: Christian Couder
Message 8 of 14 in “Create Git/Packet.pm”
  1. 0/8 Create Git/Packet.pmChristian Couder, Nov 5, 2017
  2. 1/8 t0021/rot13-filter: fix list comparisonChristian Couder, Nov 5, 2017
  3. Junio C HamanoNov 7, 2017
  4. 2/8 t0021/rot13-filter: refactor packet reading functionsChristian Couder, Nov 5, 2017
  5. Junio C HamanoNov 7, 2017
  6. Christian CouderNov 7, 2017
  7. 8/8 Add Git/Packet.pm from parts of t0021/rot13-filter.plChristian Couder, Nov 5, 2017
  8. 5/8 t0021/rot13-filter: add packet_initialize()Christian Couder, Nov 5, 2017
  9. 3/8 t0021/rot13-filter: improve 'if .. elsif .. else' styleChristian Couder, Nov 5, 2017
  10. 7/8 t0021/rot13-filter: add capability functionsChristian Couder, Nov 5, 2017
  11. Junio C HamanoNov 7, 2017
  12. 6/8 t0021/rot13-filter: refactor checking final lfChristian Couder, Nov 5, 2017
  13. Junio C HamanoNov 7, 2017
  14. 4/8 t0021/rot13-filter: improve error messageChristian Couder, Nov 5, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.