Re: [PATCH v2 1/8] test-pkt-line: add unpack-sideband subcommand

2018-06-14 Thread Brandon Williams
On 06/14, Stefan Beller wrote:
> On Wed, Jun 13, 2018 at 2:39 PM Brandon Williams  wrote:
> >
> > Add an 'unpack-sideband' subcommand to the test-pkt-line helper to
> > enable unpacking packet line data sent multiplexed using a sideband.
> >
> > Signed-off-by: Brandon Williams 
> > ---
> >  t/helper/test-pkt-line.c | 37 +
> >  1 file changed, 37 insertions(+)
> >
> > diff --git a/t/helper/test-pkt-line.c b/t/helper/test-pkt-line.c
> > index 0f19e53c7..2a551 100644
> > --- a/t/helper/test-pkt-line.c
> > +++ b/t/helper/test-pkt-line.c
> > @@ -1,3 +1,4 @@
> > +#include "cache.h"
> >  #include "pkt-line.h"
> >
> >  static void pack_line(const char *line)
> > @@ -48,6 +49,40 @@ static void unpack(void)
> > }
> >  }
> >
> > +static void unpack_sideband(void)
> > +{
> > +   struct packet_reader reader;
> > +   packet_reader_init(, 0, NULL, 0,
> > +  PACKET_READ_GENTLE_ON_EOF |
> > +  PACKET_READ_CHOMP_NEWLINE);
> > +
> > +   while (packet_reader_read() != PACKET_READ_EOF) {
> > +   int band;
> > +   int fd;
> > +
> > +   switch (reader.status) {
> > +   case PACKET_READ_EOF:
> > +   break;
> > +   case PACKET_READ_NORMAL:
> > +   band = reader.line[0] & 0xff;
> > +   if (band == 1)
> > +   fd = 1;
> > +   else
> > +   fd = 2;
> > +
> > +   write_or_die(fd, reader.line+1, reader.pktlen-1);
> 
> white space around + and - ?

Will fix.

> 
> > +
> > +   if (band == 3)
> > +   die("sind-band error");
> 
> s/sind/side/ ?

Thanks for catching this.

> 
> What values for band are possible?
> e.g. band==4 would also just write to fd=1;
> but I suspect we don't want that, yet.
> 
> So maybe
> 
> band = reader.line[0] & 0xff;
> if (band < 1 || band > 2)
> die("unexpected side band %d", band)
> fd = band;
> 
> instead?

Yeah that's must cleaner logic.

-- 
Brandon Williams


Re: [PATCH v2 1/8] test-pkt-line: add unpack-sideband subcommand

2018-06-14 Thread Stefan Beller
On Wed, Jun 13, 2018 at 2:39 PM Brandon Williams  wrote:
>
> Add an 'unpack-sideband' subcommand to the test-pkt-line helper to
> enable unpacking packet line data sent multiplexed using a sideband.
>
> Signed-off-by: Brandon Williams 
> ---
>  t/helper/test-pkt-line.c | 37 +
>  1 file changed, 37 insertions(+)
>
> diff --git a/t/helper/test-pkt-line.c b/t/helper/test-pkt-line.c
> index 0f19e53c7..2a551 100644
> --- a/t/helper/test-pkt-line.c
> +++ b/t/helper/test-pkt-line.c
> @@ -1,3 +1,4 @@
> +#include "cache.h"
>  #include "pkt-line.h"
>
>  static void pack_line(const char *line)
> @@ -48,6 +49,40 @@ static void unpack(void)
> }
>  }
>
> +static void unpack_sideband(void)
> +{
> +   struct packet_reader reader;
> +   packet_reader_init(, 0, NULL, 0,
> +  PACKET_READ_GENTLE_ON_EOF |
> +  PACKET_READ_CHOMP_NEWLINE);
> +
> +   while (packet_reader_read() != PACKET_READ_EOF) {
> +   int band;
> +   int fd;
> +
> +   switch (reader.status) {
> +   case PACKET_READ_EOF:
> +   break;
> +   case PACKET_READ_NORMAL:
> +   band = reader.line[0] & 0xff;
> +   if (band == 1)
> +   fd = 1;
> +   else
> +   fd = 2;
> +
> +   write_or_die(fd, reader.line+1, reader.pktlen-1);

white space around + and - ?

> +
> +   if (band == 3)
> +   die("sind-band error");

s/sind/side/ ?

What values for band are possible?
e.g. band==4 would also just write to fd=1;
but I suspect we don't want that, yet.

So maybe

band = reader.line[0] & 0xff;
if (band < 1 || band > 2)
die("unexpected side band %d", band)
fd = band;

instead?


[PATCH v2 1/8] test-pkt-line: add unpack-sideband subcommand

2018-06-13 Thread Brandon Williams
Add an 'unpack-sideband' subcommand to the test-pkt-line helper to
enable unpacking packet line data sent multiplexed using a sideband.

Signed-off-by: Brandon Williams 
---
 t/helper/test-pkt-line.c | 37 +
 1 file changed, 37 insertions(+)

diff --git a/t/helper/test-pkt-line.c b/t/helper/test-pkt-line.c
index 0f19e53c7..2a551 100644
--- a/t/helper/test-pkt-line.c
+++ b/t/helper/test-pkt-line.c
@@ -1,3 +1,4 @@
+#include "cache.h"
 #include "pkt-line.h"
 
 static void pack_line(const char *line)
@@ -48,6 +49,40 @@ static void unpack(void)
}
 }
 
+static void unpack_sideband(void)
+{
+   struct packet_reader reader;
+   packet_reader_init(, 0, NULL, 0,
+  PACKET_READ_GENTLE_ON_EOF |
+  PACKET_READ_CHOMP_NEWLINE);
+
+   while (packet_reader_read() != PACKET_READ_EOF) {
+   int band;
+   int fd;
+
+   switch (reader.status) {
+   case PACKET_READ_EOF:
+   break;
+   case PACKET_READ_NORMAL:
+   band = reader.line[0] & 0xff;
+   if (band == 1)
+   fd = 1;
+   else
+   fd = 2;
+
+   write_or_die(fd, reader.line+1, reader.pktlen-1);
+
+   if (band == 3)
+   die("sind-band error");
+   break;
+   case PACKET_READ_FLUSH:
+   return;
+   case PACKET_READ_DELIM:
+   break;
+   }
+   }
+}
+
 int cmd_main(int argc, const char **argv)
 {
if (argc < 2)
@@ -57,6 +92,8 @@ int cmd_main(int argc, const char **argv)
pack(argc - 2, argv + 2);
else if (!strcmp(argv[1], "unpack"))
unpack();
+   else if (!strcmp(argv[1], "unpack-sideband"))
+   unpack_sideband();
else
die("invalid argument '%s'", argv[1]);
 
-- 
2.18.0.rc1.242.g61856ae69a-goog