Skip to content

Commit 52917a9

Browse files
matheustavaresgitster
authored andcommitted
t0021: implementation the rot13-filter.pl script in C
This script is currently used by three test files: t0021-conversion.sh, t2080-parallel-checkout-basics.sh, and t2082-parallel-checkout-attributes.sh. To avoid the need for the PERL dependency at these tests, let's convert the script to a C test-tool command. The following commit will take care of actually modifying the said tests to use the new C helper and removing the Perl script. The Perl script flushes the log file handler after each write. As commented in [1], this seems to be an early design decision that was later reconsidered, but possibly ended up being left in the code by accident: >> +$debug->flush(); > > Isn't $debug flushed automatically? Maybe, but autoflush is not explicitly enabled. I will enable it again (I disabled it because of Eric's comment but I re-read the comment and he is only talking about pipes). Anyways, this behavior is not really needed for the tests and the flush() calls make the code slightly larger, so let's avoid them altogether in the new C version. [1]: https://lore.kernel.org/git/[email protected]/ Helped-by: Johannes Schindelin <[email protected]> Signed-off-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bed8947 commit 52917a9

File tree

6 files changed

+396
-2
lines changed

6 files changed

+396
-2
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ TEST_BUILTINS_OBJS += test-read-midx.o
764764
TEST_BUILTINS_OBJS += test-ref-store.o
765765
TEST_BUILTINS_OBJS += test-reftable.o
766766
TEST_BUILTINS_OBJS += test-regex.o
767+
TEST_BUILTINS_OBJS += test-rot13-filter.o
767768
TEST_BUILTINS_OBJS += test-repository.o
768769
TEST_BUILTINS_OBJS += test-revision-walking.o
769770
TEST_BUILTINS_OBJS += test-run-command.o

pkt-line.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ int write_packetized_from_fd_no_flush(int fd_in, int fd_out)
309309
return err;
310310
}
311311

312-
int write_packetized_from_buf_no_flush(const char *src_in, size_t len, int fd_out)
312+
int write_packetized_from_buf_no_flush_count(const char *src_in, size_t len,
313+
int fd_out, int *packet_counter)
313314
{
314315
int err = 0;
315316
size_t bytes_written = 0;
@@ -324,6 +325,8 @@ int write_packetized_from_buf_no_flush(const char *src_in, size_t len, int fd_ou
324325
break;
325326
err = packet_write_gently(fd_out, src_in + bytes_written, bytes_to_write);
326327
bytes_written += bytes_to_write;
328+
if (packet_counter)
329+
(*packet_counter)++;
327330
}
328331
return err;
329332
}

pkt-line.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((f
3232
int packet_flush_gently(int fd);
3333
int packet_write_fmt_gently(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
3434
int write_packetized_from_fd_no_flush(int fd_in, int fd_out);
35-
int write_packetized_from_buf_no_flush(const char *src_in, size_t len, int fd_out);
35+
int write_packetized_from_buf_no_flush_count(const char *src_in, size_t len,
36+
int fd_out, int *packet_counter);
37+
static inline int write_packetized_from_buf_no_flush(const char *src_in,
38+
size_t len, int fd_out)
39+
{
40+
return write_packetized_from_buf_no_flush_count(src_in, len, fd_out, NULL);
41+
}
3642

3743
/*
3844
* Stdio versions of packet_write functions. When mixing these with fd

0 commit comments

Comments
 (0)