Skip to content

Commit 5e8617f

Browse files
trastgitster
authored andcommitted
bundle: put strbuf_readline_fd in strbuf.c with adjustments
The comment even said that it should eventually go there. While at it, match the calling convention and name of the function to the strbuf_get*line family. So it now is strbuf_getwholeline_fd. Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0482e8 commit 5e8617f

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

bundle.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,14 @@ static void add_to_ref_list(const unsigned char *sha1, const char *name,
2323
list->nr++;
2424
}
2525

26-
/* Eventually this should go to strbuf.[ch] */
27-
static int strbuf_readline_fd(struct strbuf *sb, int fd)
28-
{
29-
strbuf_reset(sb);
30-
31-
while (1) {
32-
char ch;
33-
ssize_t len = xread(fd, &ch, 1);
34-
if (len <= 0)
35-
return len;
36-
strbuf_addch(sb, ch);
37-
if (ch == '\n')
38-
break;
39-
}
40-
return 0;
41-
}
42-
4326
static int parse_bundle_header(int fd, struct bundle_header *header,
4427
const char *report_path)
4528
{
4629
struct strbuf buf = STRBUF_INIT;
4730
int status = 0;
4831

4932
/* The bundle header begins with the signature */
50-
if (strbuf_readline_fd(&buf, fd) ||
33+
if (strbuf_getwholeline_fd(&buf, fd, '\n') ||
5134
strcmp(buf.buf, bundle_signature)) {
5235
if (report_path)
5336
error("'%s' does not look like a v2 bundle file",
@@ -57,7 +40,7 @@ static int parse_bundle_header(int fd, struct bundle_header *header,
5740
}
5841

5942
/* The bundle header ends with an empty line */
60-
while (!strbuf_readline_fd(&buf, fd) &&
43+
while (!strbuf_getwholeline_fd(&buf, fd, '\n') &&
6144
buf.len && buf.buf[0] != '\n') {
6245
unsigned char sha1[20];
6346
int is_prereq = 0;

strbuf.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,22 @@ int strbuf_getline(struct strbuf *sb, FILE *fp, int term)
383383
return 0;
384384
}
385385

386+
int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)
387+
{
388+
strbuf_reset(sb);
389+
390+
while (1) {
391+
char ch;
392+
ssize_t len = xread(fd, &ch, 1);
393+
if (len <= 0)
394+
return EOF;
395+
strbuf_addch(sb, ch);
396+
if (ch == term)
397+
break;
398+
}
399+
return 0;
400+
}
401+
386402
int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
387403
{
388404
int fd, len;

strbuf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint);
108108

109109
extern int strbuf_getwholeline(struct strbuf *, FILE *, int);
110110
extern int strbuf_getline(struct strbuf *, FILE *, int);
111+
extern int strbuf_getwholeline_fd(struct strbuf *, int, int);
111112

112113
extern void stripspace(struct strbuf *buf, int skip_comments);
113114
extern int launch_editor(const char *path, struct strbuf *buffer, const char *const *env);

0 commit comments

Comments
 (0)