@matheusbsbs / matheus-bagliano / commits / 46ce8b6d2a
Fork 0

Allow fetch--tool to read from stdin

If the reflist is "-" then read the reflist data from stdin instead, this will allow the passing of more than 128K of reflist data - which won't fit in the environment passed by execve. Signed-off-by: Julian Phillips <julian@quantumfyre.co.uk> Signed-off-by: Junio C Hamano <junkio@cox.net>

Julian Phillips committed Feb 13, 2007 at 01:21 UTC 46ce8b6d2a88b67a839fb53bfa0b8849215352b5
1 file changed +25 -2
builtin-fetch--tool.c
+25 -2
@@ -2,6 +2,21 @@
2 #include "refs.h"
3 #include "commit.h"
4
5 +#define CHUNK_SIZE (1048576)
6 +
7 +static char *get_stdin(void)
8 +{
9 + char *data = xmalloc(CHUNK_SIZE);
10 + int offset = 0, read = 0;
11 + read = xread(0, data, CHUNK_SIZE);
12 + while (read == CHUNK_SIZE) {
13 + offset += CHUNK_SIZE;
14 + data = xrealloc(data, offset + CHUNK_SIZE);
15 + read = xread(0, data + offset, CHUNK_SIZE);
16 + }
17 + return data;
18 +}
19 +
20 static void show_new(char *type, unsigned char *sha1_new)
21 {
22 fprintf(stderr, " %s: %s\n", type,
@@ -461,14 +476,22 @@ int cmd_fetch__tool(int argc, const char **argv, const char *prefix)
476 return result;
477 }
478 if (!strcmp("parse-reflist", argv[1])) {
479 + const char *reflist;
480 if (argc != 3)
481 return error("parse-reflist takes 1 arg");
466 - return parse_reflist(argv[2]);
482 + reflist = argv[2];
483 + if (!strcmp(reflist, "-"))
484 + reflist = get_stdin();
485 + return parse_reflist(reflist);
486 }
487 if (!strcmp("expand-refs-wildcard", argv[1])) {
488 + const char *reflist;
489 if (argc < 4)
490 return error("expand-refs-wildcard takes at least 2 args");
471 - return expand_refs_wildcard(argv[2], argc - 3, argv + 3);
491 + reflist = argv[2];
492 + if (!strcmp(reflist, "-"))
493 + reflist = get_stdin();
494 + return expand_refs_wildcard(reflist, argc - 3, argv + 3);
495 }
496
497 return error("Unknown subcommand: %s", argv[1]);