272
/* A helper for reading a line of text from a range in the patch file.
274
* Allocate *STRINGBUF in RESULT_POOL, and read into it one line from FILE.
275
* Reading stops either after a line-terminator was found or after MAX_LEN
276
* bytes have been read. The line-terminator is not stored in *STRINGBUF.
278
* The line-terminator is detected automatically and stored in *EOL
279
* if EOL is not NULL. If EOF is reached and FILE does not end
280
* with a newline character, and EOL is not NULL, *EOL is set to NULL.
282
* SCRATCH_POOL is used for temporary allocations.
285
readline(apr_file_t *file,
286
svn_stringbuf_t **stringbuf,
290
apr_pool_t *result_pool,
291
apr_pool_t *scratch_pool)
293
svn_stringbuf_t *str;
298
svn_boolean_t found_eof;
300
str = svn_stringbuf_create_ensure(80, result_pool);
302
/* Read bytes into STR up to and including, but not storing,
303
* the next EOL sequence. */
311
SVN_ERR(svn_io_file_read_full2(file, &c, sizeof(c), &numbytes,
312
&found_eof, scratch_pool));
314
if (numbytes != 1 || len > max_len)
328
if (!found_eof && len < max_len)
332
/* Check for "\r\n" by peeking at the next byte. */
334
SVN_ERR(svn_io_file_seek(file, APR_CUR, &pos, scratch_pool));
335
SVN_ERR(svn_io_file_read_full2(file, &c, sizeof(c), &numbytes,
336
&found_eof, scratch_pool));
337
if (numbytes == 1 && c == '\n')
344
/* Pretend we never peeked. */
345
SVN_ERR(svn_io_file_seek(file, APR_SET, &pos, scratch_pool));
352
svn_stringbuf_appendbyte(str, c);
367
274
/* Read a line of original or modified hunk text from the specified
368
275
* RANGE within FILE. FILE is expected to contain unidiff text.
369
276
* Leading unidiff symbols ('+', '-', and ' ') are removed from the line,
407
314
max_len = range->end - range->current;
408
SVN_ERR(readline(file, &str, eol, eof, max_len,
409
result_pool, scratch_pool));
315
SVN_ERR(svn_io_file_readline(file, &str, eol, eof, max_len,
316
result_pool, scratch_pool));
410
317
range->current = 0;
411
318
SVN_ERR(svn_io_file_seek(file, APR_CUR, &range->current, scratch_pool));
412
319
filtered = (str->data[0] == verboten || str->data[0] == '\\');
498
405
SVN_ERR(svn_io_file_seek(hunk->apr_file, APR_SET,
499
406
&hunk->diff_text_range.current, scratch_pool));
500
407
max_len = hunk->diff_text_range.end - hunk->diff_text_range.current;
501
SVN_ERR(readline(hunk->apr_file, &line, eol, eof, max_len, result_pool,
408
SVN_ERR(svn_io_file_readline(hunk->apr_file, &line, eol, eof, max_len,
503
411
hunk->diff_text_range.current = 0;
504
412
SVN_ERR(svn_io_file_seek(hunk->apr_file, APR_CUR,
642
550
/* Remember the current line's offset, and read the line. */
644
SVN_ERR(readline(apr_file, &line, NULL, &eof, APR_SIZE_MAX,
645
iterpool, iterpool));
552
SVN_ERR(svn_io_file_readline(apr_file, &line, NULL, &eof, APR_SIZE_MAX,
553
iterpool, iterpool));
647
555
/* Update line offset for next iteration. */
649
557
SVN_ERR(svn_io_file_seek(apr_file, APR_CUR, &pos, iterpool));
651
/* Lines starting with a backslash are comments, such as
652
* "\ No newline at end of file". */
559
/* Lines starting with a backslash indicate a missing EOL:
560
* "\ No newline at end of file" or "end of property". */
653
561
if (line->data[0] == '\\')
657
strcmp(line->data, "\\ No newline at end of file") == 0) ||
659
strcmp(line->data, "\\ No newline at end of property") == 0)))
1218
1121
prop_patch->hunks = apr_array_make(result_pool, 1,
1219
1122
sizeof(svn_diff_hunk_t *));
1221
apr_hash_set(patch->prop_patches, prop_name, APR_HASH_KEY_STRING,
1124
svn_hash_sets(patch->prop_patches, prop_name, prop_patch);
1225
1127
APR_ARRAY_PUSH(prop_patch->hunks, svn_diff_hunk_t *) = hunk;
1246
1148
p = apr_palloc(result_pool, sizeof(*p));
1247
1149
SVN_ERR(svn_io_file_open(&p->apr_file, local_abspath,
1248
APR_READ | APR_BINARY, 0, result_pool));
1150
APR_READ | APR_BUFFERED, APR_OS_DEFAULT,
1249
1152
p->next_patch_offset = 0;
1250
1153
*patch_file = p;
1363
1266
/* Remember the current line's offset, and read the line. */
1364
1267
last_line = pos;
1365
SVN_ERR(readline(patch_file->apr_file, &line, NULL, &eof,
1366
APR_SIZE_MAX, iterpool, iterpool));
1268
SVN_ERR(svn_io_file_readline(patch_file->apr_file, &line, NULL, &eof,
1269
APR_SIZE_MAX, iterpool, iterpool));