server-info: use strbuf to read old info/packs file
This old code uses fgets with a fixed-size buffer. Let's use a strbuf instead, so we don't have to wonder if "1000" is big enough, or what happens if we see a long line. This also lets us drop our custom code to trim the newline. Probably nobody actually cares about the 1000-char limit (after all, the lines generally only say "P pack-[0-9a-f]{40}.pack"), so this is mostly just about cleanup/readability. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
965cc517e5
commit
4ecbd6492c
|
@ -131,7 +131,7 @@ static int parse_pack_def(const char *packname, int old_cnt)
|
||||||
static int read_pack_info_file(const char *infofile)
|
static int read_pack_info_file(const char *infofile)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char line[1000];
|
struct strbuf line = STRBUF_INIT;
|
||||||
int old_cnt = 0;
|
int old_cnt = 0;
|
||||||
int stale = 1;
|
int stale = 1;
|
||||||
|
|
||||||
|
@ -139,32 +139,30 @@ static int read_pack_info_file(const char *infofile)
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return 1; /* nonexistent is not an error. */
|
return 1; /* nonexistent is not an error. */
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), fp)) {
|
while (strbuf_getline(&line, fp) != EOF) {
|
||||||
const char *arg;
|
const char *arg;
|
||||||
int len = strlen(line);
|
|
||||||
if (len && line[len-1] == '\n')
|
|
||||||
line[--len] = 0;
|
|
||||||
|
|
||||||
if (!len)
|
if (!line.len)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (skip_prefix(line, "P ", &arg)) {
|
if (skip_prefix(line.buf, "P ", &arg)) {
|
||||||
/* P name */
|
/* P name */
|
||||||
if (parse_pack_def(arg, old_cnt++))
|
if (parse_pack_def(arg, old_cnt++))
|
||||||
goto out_stale;
|
goto out_stale;
|
||||||
} else if (line[0] == 'D') {
|
} else if (line.buf[0] == 'D') {
|
||||||
/* we used to emit D but that was misguided. */
|
/* we used to emit D but that was misguided. */
|
||||||
goto out_stale;
|
goto out_stale;
|
||||||
} else if (line[0] == 'T') {
|
} else if (line.buf[0] == 'T') {
|
||||||
/* we used to emit T but nobody uses it. */
|
/* we used to emit T but nobody uses it. */
|
||||||
goto out_stale;
|
goto out_stale;
|
||||||
} else {
|
} else {
|
||||||
error("unrecognized: %s", line);
|
error("unrecognized: %s", line.buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stale = 0;
|
stale = 0;
|
||||||
|
|
||||||
out_stale:
|
out_stale:
|
||||||
|
strbuf_release(&line);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return stale;
|
return stale;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue