Skip to content

Commit 7e2fe3a

Browse files
committed
vcs-svn: remove buffer_read_string
All previous users of buffer_read_string have already been converted to use the more intuitive buffer_read_binary, so remove the old API to avoid some confusion. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
1 parent e7d04ee commit 7e2fe3a

5 files changed

Lines changed: 17 additions & 48 deletions

File tree

t/t0081-line-buffer.sh

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ long_read_test () {
5353
} >input &
5454
} &&
5555
test-line-buffer input <<-EOF >output &&
56-
read $readsize
56+
binary $readsize
5757
copy $copysize
5858
EOF
5959
kill $! &&
@@ -71,41 +71,41 @@ test_expect_success 'setup: have pipes?' '
7171
'
7272

7373
test_expect_success 'hello world' '
74-
echo HELLO >expect &&
74+
echo ">HELLO" >expect &&
7575
test-line-buffer <<-\EOF >actual &&
76-
read 6
76+
binary 6
7777
HELLO
7878
EOF
7979
test_cmp expect actual
8080
'
8181

8282
test_expect_success PIPE '0-length read, no input available' '
83-
>expect &&
83+
printf ">" >expect &&
8484
rm -f input &&
8585
mkfifo input &&
8686
{
8787
sleep 100 >input &
8888
} &&
8989
test-line-buffer input <<-\EOF >actual &&
90-
read 0
90+
binary 0
9191
copy 0
9292
EOF
9393
kill $! &&
9494
test_cmp expect actual
9595
'
9696

9797
test_expect_success '0-length read, send along greeting' '
98-
echo HELLO >expect &&
98+
echo ">HELLO" >expect &&
9999
test-line-buffer <<-\EOF >actual &&
100-
read 0
100+
binary 0
101101
copy 6
102102
HELLO
103103
EOF
104104
test_cmp expect actual
105105
'
106106

107107
test_expect_success PIPE '1-byte read, no input available' '
108-
printf "%s" ab >expect &&
108+
printf ">%s" ab >expect &&
109109
rm -f input &&
110110
mkfifo input &&
111111
{
@@ -116,7 +116,7 @@ test_expect_success PIPE '1-byte read, no input available' '
116116
} >input &
117117
} &&
118118
test-line-buffer input <<-\EOF >actual &&
119-
read 1
119+
binary 1
120120
copy 1
121121
EOF
122122
kill $! &&
@@ -140,15 +140,6 @@ test_expect_success 'read from file descriptor' '
140140
test_cmp expect actual
141141
'
142142

143-
test_expect_success 'buffer_read_string copes with null byte' '
144-
>expect &&
145-
q_to_nul <<-\EOF | test-line-buffer >actual &&
146-
read 2
147-
Q
148-
EOF
149-
test_cmp expect actual
150-
'
151-
152143
test_expect_success 'skip, copy null byte' '
153144
echo Q | q_to_nul >expect &&
154145
q_to_nul <<-\EOF | test-line-buffer >actual &&
@@ -170,18 +161,18 @@ test_expect_success 'read null byte' '
170161
'
171162

172163
test_expect_success 'long reads are truncated' '
173-
echo foo >expect &&
164+
echo ">foo" >expect &&
174165
test-line-buffer <<-\EOF >actual &&
175-
read 5
166+
binary 5
176167
foo
177168
EOF
178169
test_cmp expect actual
179170
'
180171

181172
test_expect_success 'long copies are truncated' '
182-
printf "%s\n" "" foo >expect &&
173+
printf "%s\n" ">" foo >expect &&
183174
test-line-buffer <<-\EOF >actual &&
184-
read 1
175+
binary 1
185176
186177
copy 5
187178
foo

test-line-buffer.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ static void handle_command(const char *command, const char *arg, struct line_buf
3232
buffer_copy_bytes(buf, strtouint32(arg));
3333
return;
3434
}
35-
case 'r':
36-
if (!prefixcmp(command, "read ")) {
37-
const char *s = buffer_read_string(buf, strtouint32(arg));
38-
fputs(s, stdout);
39-
return;
40-
}
4135
case 's':
4236
if (!prefixcmp(command, "skip ")) {
4337
buffer_skip_bytes(buf, strtouint32(arg));

vcs-svn/line_buffer.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,6 @@ char *buffer_read_line(struct line_buffer *buf)
9191
return buf->line_buffer;
9292
}
9393

94-
char *buffer_read_string(struct line_buffer *buf, uint32_t len)
95-
{
96-
strbuf_reset(&buf->blob_buffer);
97-
strbuf_fread(&buf->blob_buffer, len, buf->infile);
98-
return ferror(buf->infile) ? NULL : buf->blob_buffer.buf;
99-
}
100-
10194
void buffer_read_binary(struct line_buffer *buf,
10295
struct strbuf *sb, uint32_t size)
10396
{
@@ -134,5 +127,4 @@ off_t buffer_skip_bytes(struct line_buffer *buf, off_t nbytes)
134127

135128
void buffer_reset(struct line_buffer *buf)
136129
{
137-
strbuf_release(&buf->blob_buffer);
138130
}

vcs-svn/line_buffer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77

88
struct line_buffer {
99
char line_buffer[LINE_BUFFER_LEN];
10-
struct strbuf blob_buffer;
1110
FILE *infile;
1211
};
13-
#define LINE_BUFFER_INIT {"", STRBUF_INIT, NULL}
12+
#define LINE_BUFFER_INIT { "", NULL }
1413

1514
int buffer_init(struct line_buffer *buf, const char *filename);
1615
int buffer_fdinit(struct line_buffer *buf, int fd);
@@ -23,7 +22,6 @@ long buffer_tmpfile_prepare_to_read(struct line_buffer *buf);
2322

2423
int buffer_ferror(struct line_buffer *buf);
2524
char *buffer_read_line(struct line_buffer *buf);
26-
char *buffer_read_string(struct line_buffer *buf, uint32_t len);
2725
int buffer_read_char(struct line_buffer *buf);
2826
void buffer_read_binary(struct line_buffer *buf, struct strbuf *sb, uint32_t len);
2927
/* Returns number of bytes read (not necessarily written). */

vcs-svn/line_buffer.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ The calling program:
1616

1717
- initializes a `struct line_buffer` to LINE_BUFFER_INIT
1818
- specifies a file to read with `buffer_init`
19-
- processes input with `buffer_read_line`, `buffer_read_string`,
20-
`buffer_skip_bytes`, and `buffer_copy_bytes`
19+
- processes input with `buffer_read_line`, `buffer_skip_bytes`,
20+
and `buffer_copy_bytes`
2121
- closes the file with `buffer_deinit`, perhaps to start over and
2222
read another file.
2323

@@ -37,7 +37,7 @@ the calling program. A program
3737
the temporary file
3838
- declares writing is over with `buffer_tmpfile_prepare_to_read`
3939
- can re-read what was written with `buffer_read_line`,
40-
`buffer_read_string`, and so on
40+
`buffer_copy_bytes`, and so on
4141
- can reuse the temporary file by calling `buffer_tmpfile_rewind`
4242
again
4343
- removes the temporary file with `buffer_deinit`, perhaps to
@@ -64,12 +64,6 @@ Functions
6464
Read a line and strip off the trailing newline.
6565
On failure or end of file, returns NULL.
6666

67-
`buffer_read_string`::
68-
Read `len` characters of input or up to the end of the
69-
file, whichever comes first. Returns NULL on error.
70-
Returns whatever characters were read (possibly "")
71-
for end of file.
72-
7367
`buffer_copy_bytes`::
7468
Read `len` bytes of input and dump them to the standard output
7569
stream. Returns early for error or end of file.

0 commit comments

Comments
 (0)