Merge pull request #5859 from libgit2/ethomson/filter_buf filter: stop taking git_buf as user input
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
diff --git a/include/git2/deprecated.h b/include/git2/deprecated.h
index 37857f8..ac60488 100644
--- a/include/git2/deprecated.h
+++ b/include/git2/deprecated.h
@@ -18,6 +18,7 @@
#include "describe.h"
#include "diff.h"
#include "errors.h"
+#include "filter.h"
#include "index.h"
#include "indexer.h"
#include "merge.h"
@@ -119,6 +120,39 @@ GIT_EXTERN(int) git_blob_filtered_content(
/**@}*/
+/** @name Deprecated Filter Functions
+ *
+ * These functions are retained for backward compatibility. The
+ * newer versions of these functions should be preferred in all
+ * new code.
+ *
+ * There is no plan to remove these backward compatibility values at
+ * this time.
+ */
+/**@{*/
+
+/** Deprecated in favor of `git_filter_list_stream_buffer`.
+ *
+ * @deprecated Use git_filter_list_stream_buffer
+ * @see Use git_filter_list_stream_buffer
+ */
+GIT_EXTERN(int) git_filter_list_stream_data(
+ git_filter_list *filters,
+ git_buf *data,
+ git_writestream *target);
+
+/** Deprecated in favor of `git_filter_list_apply_to_buffer`.
+ *
+ * @deprecated Use git_filter_list_apply_to_buffer
+ * @see Use git_filter_list_apply_to_buffer
+ */
+GIT_EXTERN(int) git_filter_list_apply_to_data(
+ git_buf *out,
+ git_filter_list *filters,
+ git_buf *in);
+
+/**@}*/
+
/** @name Deprecated Tree Functions
*
* These functions are retained for backward compatibility. The
diff --git a/include/git2/filter.h b/include/git2/filter.h
index 8860590..a0185ee 100644
--- a/include/git2/filter.h
+++ b/include/git2/filter.h
@@ -122,27 +122,17 @@ GIT_EXTERN(int) git_filter_list_contains(
/**
* Apply filter list to a data buffer.
*
- * See `git2/buffer.h` for background on `git_buf` objects.
- *
- * If the `in` buffer holds data allocated by libgit2 (i.e. `in->asize` is
- * not zero), then it will be overwritten when applying the filters. If
- * not, then it will be left untouched.
- *
- * If there are no filters to apply (or `filters` is NULL), then the `out`
- * buffer will reference the `in` buffer data (with `asize` set to zero)
- * instead of allocating data. This keeps allocations to a minimum, but
- * it means you have to be careful about freeing the `in` data since `out`
- * may be pointing to it!
- *
* @param out Buffer to store the result of the filtering
* @param filters A loaded git_filter_list (or NULL)
* @param in Buffer containing the data to filter
+ * @param in_len The length of the input buffer
* @return 0 on success, an error code otherwise
*/
-GIT_EXTERN(int) git_filter_list_apply_to_data(
+GIT_EXTERN(int) git_filter_list_apply_to_buffer(
git_buf *out,
git_filter_list *filters,
- git_buf *in);
+ const char *in,
+ size_t in_len);
/**
* Apply a filter list to the contents of a file on disk
@@ -175,12 +165,14 @@ GIT_EXTERN(int) git_filter_list_apply_to_blob(
* Apply a filter list to an arbitrary buffer as a stream
*
* @param filters the list of filters to apply
- * @param data the buffer to filter
+ * @param buffer the buffer to filter
+ * @param len the size of the buffer
* @param target the stream into which the data will be written
*/
-GIT_EXTERN(int) git_filter_list_stream_data(
+GIT_EXTERN(int) git_filter_list_stream_buffer(
git_filter_list *filters,
- git_buf *data,
+ const char *buffer,
+ size_t len,
git_writestream *target);
/**
diff --git a/src/checkout.c b/src/checkout.c
index cadc4c8..f69b302 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -2121,7 +2121,7 @@ static int checkout_write_merge(
if ((error = git_filter_list__load_ext(
&fl, data->repo, NULL, git_buf_cstr(&path_workdir),
GIT_FILTER_TO_WORKTREE, &filter_opts)) < 0 ||
- (error = git_filter_list_apply_to_data(&out_data, fl, &in_data)) < 0)
+ (error = git_filter_list__convert_buf(&out_data, fl, &in_data)) < 0)
goto done;
} else {
out_data.ptr = (char *)result.ptr;
diff --git a/src/diff_file.c b/src/diff_file.c
index 2116f00..eeaf4a5 100644
--- a/src/diff_file.c
+++ b/src/diff_file.c
@@ -362,10 +362,7 @@ static int diff_file_content_load_workdir_file(
if (!(error = git_futils_readbuffer_fd(&raw, fd, (size_t)fc->file->size))) {
git_buf out = GIT_BUF_INIT;
- error = git_filter_list_apply_to_data(&out, fl, &raw);
-
- if (out.ptr != raw.ptr)
- git_buf_dispose(&raw);
+ error = git_filter_list__convert_buf(&out, fl, &raw);
if (!error) {
fc->map.len = out.size;
diff --git a/src/filter.c b/src/filter.c
index b82becd..6c09a6a 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -720,28 +720,47 @@ static void buf_stream_init(struct buf_stream *writer, git_buf *target)
git_buf_clear(target);
}
-int git_filter_list_apply_to_data(
- git_buf *tgt, git_filter_list *filters, git_buf *src)
+int git_filter_list_apply_to_buffer(
+ git_buf *out,
+ git_filter_list *filters,
+ const char *in,
+ size_t in_len)
{
struct buf_stream writer;
int error;
- if ((error = git_buf_sanitize(tgt)) < 0 ||
- (error = git_buf_sanitize(src)) < 0)
- return error;
+ if ((error = git_buf_sanitize(out)) < 0)
+ return error;
- if (!filters) {
- git_buf_attach_notowned(tgt, src->ptr, src->size);
+ buf_stream_init(&writer, out);
+
+ if ((error = git_filter_list_stream_buffer(filters,
+ in, in_len, &writer.parent)) < 0)
+ return error;
+
+ GIT_ASSERT(writer.complete);
+ return error;
+}
+
+int git_filter_list__convert_buf(
+ git_buf *out,
+ git_filter_list *filters,
+ git_buf *in)
+{
+ int error;
+
+ if (!filters || git_filter_list_length(filters) == 0) {
+ git_buf_swap(out, in);
+ git_buf_dispose(in);
return 0;
}
- buf_stream_init(&writer, tgt);
+ error = git_filter_list_apply_to_buffer(out, filters,
+ in->ptr, in->size);
- if ((error = git_filter_list_stream_data(filters, src,
- &writer.parent)) < 0)
- return error;
+ if (!error)
+ git_buf_dispose(in);
- GIT_ASSERT(writer.complete);
return error;
}
@@ -1002,24 +1021,21 @@ done:
return error;
}
-int git_filter_list_stream_data(
+int git_filter_list_stream_buffer(
git_filter_list *filters,
- git_buf *data,
+ const char *buffer,
+ size_t len,
git_writestream *target)
{
git_vector filter_streams = GIT_VECTOR_INIT;
git_writestream *stream_start;
int error, initialized = 0;
- if ((error = git_buf_sanitize(data)) < 0)
- return error;
-
if ((error = stream_list_init(&stream_start, &filter_streams, filters, target)) < 0)
goto out;
initialized = 1;
- if ((error = stream_start->write(
- stream_start, data->ptr, data->size)) < 0)
+ if ((error = stream_start->write(stream_start, buffer, len)) < 0)
goto out;
out:
@@ -1043,7 +1059,7 @@ int git_filter_list_stream_blob(
if (filters)
git_oid_cpy(&filters->source.oid, git_blob_id(blob));
- return git_filter_list_stream_data(filters, &in, target);
+ return git_filter_list_stream_buffer(filters, in.ptr, in.size, target);
}
int git_filter_init(git_filter *filter, unsigned int version)
@@ -1051,3 +1067,31 @@ int git_filter_init(git_filter *filter, unsigned int version)
GIT_INIT_STRUCTURE_FROM_TEMPLATE(filter, version, git_filter, GIT_FILTER_INIT);
return 0;
}
+
+#ifndef GIT_DEPRECATE_HARD
+
+int git_filter_list_stream_data(
+ git_filter_list *filters,
+ git_buf *data,
+ git_writestream *target)
+{
+ int error;
+
+ if ((error = git_buf_sanitize(data)) < 0)
+ return error;
+
+ return git_filter_list_stream_buffer(filters, data->ptr, data->size, target);
+}
+
+int git_filter_list_apply_to_data(
+ git_buf *tgt, git_filter_list *filters, git_buf *src)
+{
+ int error;
+
+ if ((error = git_buf_sanitize(src)) < 0)
+ return error;
+
+ return git_filter_list_apply_to_buffer(tgt, filters, src->ptr, src->size);
+}
+
+#endif
diff --git a/src/filter.h b/src/filter.h
index 34081fb..bbc4c0f 100644
--- a/src/filter.h
+++ b/src/filter.h
@@ -36,6 +36,15 @@ extern int git_filter_list__load_ext(
git_filter_options *filter_opts);
/*
+ * The given input buffer will be converted to the given output buffer.
+ * The input buffer will be freed (_if_ it was allocated).
+ */
+extern int git_filter_list__convert_buf(
+ git_buf *out,
+ git_filter_list *filters,
+ git_buf *in);
+
+/*
* Available filters
*/
diff --git a/src/odb.c b/src/odb.c
index b2988c4..1b91434 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -260,9 +260,7 @@ int git_odb__hashfd_filtered(
if (!(error = git_futils_readbuffer_fd(&raw, fd, size))) {
git_buf post = GIT_BUF_INIT;
- error = git_filter_list_apply_to_data(&post, fl, &raw);
-
- git_buf_dispose(&raw);
+ error = git_filter_list__convert_buf(&post, fl, &raw);
if (!error)
error = git_odb_hash(out, post.ptr, post.size, type);
diff --git a/tests/filter/crlf.c b/tests/filter/crlf.c
index a266005..bc9c7f2 100644
--- a/tests/filter/crlf.c
+++ b/tests/filter/crlf.c
@@ -23,7 +23,9 @@ void test_filter_crlf__to_worktree(void)
{
git_filter_list *fl;
git_filter *crlf;
- git_buf in = { 0 }, out = { 0 };
+ git_buf out = GIT_BUF_INIT;
+ const char *in;
+ size_t in_len;
cl_git_pass(git_filter_list_new(
&fl, g_repo, GIT_FILTER_TO_WORKTREE, 0));
@@ -33,10 +35,10 @@ void test_filter_crlf__to_worktree(void)
cl_git_pass(git_filter_list_push(fl, crlf, NULL));
- in.ptr = "Some text\nRight here\n";
- in.size = strlen(in.ptr);
+ in = "Some text\nRight here\n";
+ in_len = strlen(in);
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Some text\r\nRight here\r\n", out.ptr);
@@ -48,7 +50,9 @@ void test_filter_crlf__to_odb(void)
{
git_filter_list *fl;
git_filter *crlf;
- git_buf in = { 0 }, out = { 0 };
+ git_buf out = GIT_BUF_INIT;
+ const char *in;
+ size_t in_len;
cl_git_pass(git_filter_list_new(
&fl, g_repo, GIT_FILTER_TO_ODB, 0));
@@ -58,10 +62,10 @@ void test_filter_crlf__to_odb(void)
cl_git_pass(git_filter_list_push(fl, crlf, NULL));
- in.ptr = "Some text\r\nRight here\r\n";
- in.size = strlen(in.ptr);
+ in = "Some text\r\nRight here\r\n";
+ in_len = strlen(in);
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Some text\nRight here\n", out.ptr);
@@ -73,7 +77,9 @@ void test_filter_crlf__with_safecrlf(void)
{
git_filter_list *fl;
git_filter *crlf;
- git_buf in = {0}, out = GIT_BUF_INIT;
+ git_buf out = GIT_BUF_INIT;
+ const char *in;
+ size_t in_len;
cl_repo_set_bool(g_repo, "core.safecrlf", true);
@@ -86,31 +92,31 @@ void test_filter_crlf__with_safecrlf(void)
cl_git_pass(git_filter_list_push(fl, crlf, NULL));
/* Normalized \r\n succeeds with safecrlf */
- in.ptr = "Normal\r\nCRLF\r\nline-endings.\r\n";
- in.size = strlen(in.ptr);
+ in = "Normal\r\nCRLF\r\nline-endings.\r\n";
+ in_len = strlen(in);
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Normal\nCRLF\nline-endings.\n", out.ptr);
/* Mix of line endings fails with safecrlf */
- in.ptr = "Mixed\nup\r\nLF\nand\r\nCRLF\nline-endings.\r\n";
- in.size = strlen(in.ptr);
+ in = "Mixed\nup\r\nLF\nand\r\nCRLF\nline-endings.\r\n";
+ in_len = strlen(in);
- cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_fail(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_i(git_error_last()->klass, GIT_ERROR_FILTER);
/* Normalized \n fails for autocrlf=true when safecrlf=true */
- in.ptr = "Normal\nLF\nonly\nline-endings.\n";
- in.size = strlen(in.ptr);
+ in = "Normal\nLF\nonly\nline-endings.\n";
+ in_len = strlen(in);
- cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_fail(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_i(git_error_last()->klass, GIT_ERROR_FILTER);
/* String with \r but without \r\n does not fail with safecrlf */
- in.ptr = "Normal\nCR only\rand some more\nline-endings.\n";
- in.size = strlen(in.ptr);
+ in = "Normal\nCR only\rand some more\nline-endings.\n";
+ in_len = strlen(in);
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Normal\nCR only\rand some more\nline-endings.\n", out.ptr);
git_filter_list_free(fl);
@@ -121,7 +127,9 @@ void test_filter_crlf__with_safecrlf_and_unsafe_allowed(void)
{
git_filter_list *fl;
git_filter *crlf;
- git_buf in = {0}, out = GIT_BUF_INIT;
+ git_buf out = GIT_BUF_INIT;
+ const char *in;
+ size_t in_len;
cl_repo_set_bool(g_repo, "core.safecrlf", true);
@@ -134,25 +142,25 @@ void test_filter_crlf__with_safecrlf_and_unsafe_allowed(void)
cl_git_pass(git_filter_list_push(fl, crlf, NULL));
/* Normalized \r\n succeeds with safecrlf */
- in.ptr = "Normal\r\nCRLF\r\nline-endings.\r\n";
- in.size = strlen(in.ptr);
+ in = "Normal\r\nCRLF\r\nline-endings.\r\n";
+ in_len = strlen(in);
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Normal\nCRLF\nline-endings.\n", out.ptr);
/* Mix of line endings fails with safecrlf, but allowed to pass */
- in.ptr = "Mixed\nup\r\nLF\nand\r\nCRLF\nline-endings.\r\n";
- in.size = strlen(in.ptr);
+ in = "Mixed\nup\r\nLF\nand\r\nCRLF\nline-endings.\r\n";
+ in_len = strlen(in);
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
/* TODO: check for warning */
cl_assert_equal_s("Mixed\nup\nLF\nand\nCRLF\nline-endings.\n", out.ptr);
/* Normalized \n fails with safecrlf, but allowed to pass */
- in.ptr = "Normal\nLF\nonly\nline-endings.\n";
- in.size = strlen(in.ptr);
+ in = "Normal\nLF\nonly\nline-endings.\n";
+ in_len = strlen(in);
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
/* TODO: check for warning */
cl_assert_equal_s("Normal\nLF\nonly\nline-endings.\n", out.ptr);
@@ -164,7 +172,9 @@ void test_filter_crlf__no_safecrlf(void)
{
git_filter_list *fl;
git_filter *crlf;
- git_buf in = {0}, out = GIT_BUF_INIT;
+ git_buf out = GIT_BUF_INIT;
+ const char *in;
+ size_t in_len;
cl_git_pass(git_filter_list_new(
&fl, g_repo, GIT_FILTER_TO_ODB, 0));
@@ -175,24 +185,24 @@ void test_filter_crlf__no_safecrlf(void)
cl_git_pass(git_filter_list_push(fl, crlf, NULL));
/* Normalized \r\n succeeds with safecrlf */
- in.ptr = "Normal\r\nCRLF\r\nline-endings.\r\n";
- in.size = strlen(in.ptr);
+ in = "Normal\r\nCRLF\r\nline-endings.\r\n";
+ in_len = strlen(in);
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Normal\nCRLF\nline-endings.\n", out.ptr);
/* Mix of line endings fails with safecrlf */
- in.ptr = "Mixed\nup\r\nLF\nand\r\nCRLF\nline-endings.\r\n";
- in.size = strlen(in.ptr);
+ in = "Mixed\nup\r\nLF\nand\r\nCRLF\nline-endings.\r\n";
+ in_len = strlen(in);
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Mixed\nup\nLF\nand\nCRLF\nline-endings.\n", out.ptr);
/* Normalized \n fails with safecrlf */
- in.ptr = "Normal\nLF\nonly\nline-endings.\n";
- in.size = strlen(in.ptr);
+ in = "Normal\nLF\nonly\nline-endings.\n";
+ in_len = strlen(in);
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Normal\nLF\nonly\nline-endings.\n", out.ptr);
git_filter_list_free(fl);
@@ -203,7 +213,9 @@ void test_filter_crlf__safecrlf_warn(void)
{
git_filter_list *fl;
git_filter *crlf;
- git_buf in = {0}, out = GIT_BUF_INIT;
+ git_buf out = GIT_BUF_INIT;
+ const char *in;
+ size_t in_len;
cl_repo_set_string(g_repo, "core.safecrlf", "warn");
@@ -216,26 +228,26 @@ void test_filter_crlf__safecrlf_warn(void)
cl_git_pass(git_filter_list_push(fl, crlf, NULL));
/* Normalized \r\n succeeds with safecrlf=warn */
- in.ptr = "Normal\r\nCRLF\r\nline-endings.\r\n";
- in.size = strlen(in.ptr);
+ in = "Normal\r\nCRLF\r\nline-endings.\r\n";
+ in_len = strlen(in);
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Normal\nCRLF\nline-endings.\n", out.ptr);
/* Mix of line endings succeeds with safecrlf=warn */
- in.ptr = "Mixed\nup\r\nLF\nand\r\nCRLF\nline-endings.\r\n";
- in.size = strlen(in.ptr);
+ in = "Mixed\nup\r\nLF\nand\r\nCRLF\nline-endings.\r\n";
+ in_len = strlen(in);
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
/* TODO: check for warning */
cl_assert_equal_s("Mixed\nup\nLF\nand\nCRLF\nline-endings.\n", out.ptr);
/* Normalized \n is reversible, so does not fail with safecrlf=warn */
- in.ptr = "Normal\nLF\nonly\nline-endings.\n";
- in.size = strlen(in.ptr);
+ in = "Normal\nLF\nonly\nline-endings.\n";
+ in_len = strlen(in);
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
- cl_assert_equal_s(in.ptr, out.ptr);
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
+ cl_assert_equal_s(in, out.ptr);
git_filter_list_free(fl);
git_buf_dispose(&out);
diff --git a/tests/filter/custom.c b/tests/filter/custom.c
index fe2025f..3554cb5 100644
--- a/tests/filter/custom.c
+++ b/tests/filter/custom.c
@@ -95,13 +95,17 @@ static void register_custom_filters(void)
void test_filter_custom__to_odb(void)
{
git_filter_list *fl;
- git_buf out = { 0 };
- git_buf in = GIT_BUF_INIT_CONST(workdir_data, strlen(workdir_data));
+ git_buf out = GIT_BUF_INIT;
+ const char *in;
+ size_t in_len;
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "herofile", GIT_FILTER_TO_ODB, 0));
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ in = workdir_data;
+ in_len = strlen(workdir_data);
+
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_i(BITFLIPPED_AND_REVERSED_DATA_LEN, out.size);
@@ -115,14 +119,17 @@ void test_filter_custom__to_odb(void)
void test_filter_custom__to_workdir(void)
{
git_filter_list *fl;
- git_buf out = { 0 };
- git_buf in = GIT_BUF_INIT_CONST(
- bitflipped_and_reversed_data, BITFLIPPED_AND_REVERSED_DATA_LEN);
+ git_buf out = GIT_BUF_INIT;
+ const char *in;
+ size_t in_len;
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "herofile", GIT_FILTER_TO_WORKTREE, 0));
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ in = (char *)bitflipped_and_reversed_data;
+ in_len = BITFLIPPED_AND_REVERSED_DATA_LEN;
+
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_i(strlen(workdir_data), out.size);
@@ -246,12 +253,16 @@ void test_filter_custom__erroneous_filter_fails(void)
{
git_filter_list *filters;
git_buf out = GIT_BUF_INIT;
- git_buf in = GIT_BUF_INIT_CONST(workdir_data, strlen(workdir_data));
+ const char *in;
+ size_t in_len;
cl_git_pass(git_filter_list_load(
&filters, g_repo, NULL, "villain", GIT_FILTER_TO_WORKTREE, 0));
- cl_git_fail(git_filter_list_apply_to_data(&out, filters, &in));
+ in = workdir_data;
+ in_len = strlen(workdir_data);
+
+ cl_git_fail(git_filter_list_apply_to_buffer(&out, filters, in, in_len));
git_filter_list_free(filters);
git_buf_dispose(&out);
diff --git a/tests/filter/wildcard.c b/tests/filter/wildcard.c
index 3c25ea2..62a84ea 100644
--- a/tests/filter/wildcard.c
+++ b/tests/filter/wildcard.c
@@ -123,13 +123,12 @@ static git_filter *create_wildcard_filter(void)
void test_filter_wildcard__reverse(void)
{
git_filter_list *fl;
- git_buf in = GIT_BUF_INIT, out = GIT_BUF_INIT;
+ git_buf out = GIT_BUF_INIT;
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "hero-reverse-foo", GIT_FILTER_TO_ODB, 0));
- cl_git_pass(git_buf_put(&in, (char *)input, DATA_LEN));
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, (char *)input, DATA_LEN));
cl_assert_equal_i(DATA_LEN, out.size);
@@ -138,19 +137,17 @@ void test_filter_wildcard__reverse(void)
git_filter_list_free(fl);
git_buf_dispose(&out);
- git_buf_dispose(&in);
}
void test_filter_wildcard__flip(void)
{
git_filter_list *fl;
- git_buf in = GIT_BUF_INIT, out = GIT_BUF_INIT;
+ git_buf out = GIT_BUF_INIT;
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "hero-flip-foo", GIT_FILTER_TO_ODB, 0));
- cl_git_pass(git_buf_put(&in, (char *)input, DATA_LEN));
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, (char *)input, DATA_LEN));
cl_assert_equal_i(DATA_LEN, out.size);
@@ -159,19 +156,17 @@ void test_filter_wildcard__flip(void)
git_filter_list_free(fl);
git_buf_dispose(&out);
- git_buf_dispose(&in);
}
void test_filter_wildcard__none(void)
{
git_filter_list *fl;
- git_buf in = GIT_BUF_INIT, out = GIT_BUF_INIT;
+ git_buf out = GIT_BUF_INIT;
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "none-foo", GIT_FILTER_TO_ODB, 0));
- cl_git_pass(git_buf_put(&in, (char *)input, DATA_LEN));
- cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+ cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, (char *)input, DATA_LEN));
cl_assert_equal_i(DATA_LEN, out.size);
@@ -180,5 +175,4 @@ void test_filter_wildcard__none(void)
git_filter_list_free(fl);
git_buf_dispose(&out);
- git_buf_dispose(&in);
}