Skip to content

Commit 638c49a

Browse files
committed
fixup! test-tool: add pack-deltas helper
Let's make the command-line parsing a bit more stringent. We _could_ use `parse_options()`, but that would be overkill for a single, non-optional argument. Besides, it would not bring any benefit, as the parsed value needs to fit in the `uint32_t` type, and `parse_options()` has no provision to ensure that. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent d1e9900 commit 638c49a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

t/helper/test-pack-deltas.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
#include "hex.h"
99
#include "pack.h"
1010
#include "pack-objects.h"
11+
#include "parse.h"
1112
#include "setup.h"
1213
#include "strbuf.h"
1314
#include "string-list.h"
1415

15-
static const char usage_str[] = "test-tool pack-deltas <n>";
16+
static const char usage_str[] = "test-tool pack-deltas <nr_entries>";
1617

1718
static unsigned long do_compress(void **pptr, unsigned long size)
1819
{
@@ -79,7 +80,7 @@ static void write_ref_delta(struct hashfile *f,
7980

8081
int cmd__pack_deltas(int argc, const char **argv)
8182
{
82-
int N;
83+
unsigned long n;
8384
struct hashfile *f;
8485
struct strbuf line = STRBUF_INIT;
8586

@@ -88,12 +89,13 @@ int cmd__pack_deltas(int argc, const char **argv)
8889
return -1;
8990
}
9091

91-
N = atoi(argv[1]);
92+
if (!git_parse_ulong(argv[1], &n) || n != (uint32_t)n)
93+
die("invalid number of objects: %s", argv[1]);
9294

9395
setup_git_directory();
9496

9597
f = hashfd(1, "<stdout>");
96-
write_pack_header(f, N);
98+
write_pack_header(f, n);
9799

98100
/* Read each line from stdin into 'line' */
99101
while (strbuf_getline_lf(&line, stdin) != EOF) {

0 commit comments

Comments
 (0)