~herrhotzenplotz/gcli-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 2

[PATCH gcli 1/3] Makefile: Fix dependencies of test programs

Details
Message ID
<20240825015305.91593-1-nsonack@herrhotzenplotz.de>
DKIM signature
pass
Download raw message
Patch: +12 -1
We used to get rebuilds of all test programs when one test was
touched.

Because we want portable Makefiles we need to specify the dependencies
this way - there isn't really a good way to do this without resorting
to unportable pattern matching.

Be verbose instead.

Signed-off-by: Nico Sonack <nsonack@herrhotzenplotz.de>
---
 Makefile.in | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/Makefile.in b/Makefile.in
index 545f110a..63ddb8a1 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -331,6 +331,7 @@ clean-auto:
		$(TEST_PROGRAMS) \
		$(MANPAGES)

###### TEST SUITE #####################################
TEST_PROGRAMS = \
	tests/json-escape \
	tests/github-parse \
@@ -342,7 +343,17 @@ TEST_PROGRAMS = \
	tests/base64 \
	tests/difftests

$(TEST_PROGRAMS): libgcli.a $(TEST_PROGRAMS:=.tests.o)
tests/json-escape: tests/json-escape.tests.o
tests/github-parse: tests/github-parse.tests.o
tests/gitlab-parse: tests/gitlab-parse.tests.o
tests/gitea-parse: tests/gitea-parse.tests.o
tests/bugzilla-parse: tests/bugzilla-parse.tests.o
tests/url-encode: tests/url-encode.tests.o
tests/jsongen: tests/jsongen.tests.o
tests/base64: tests/base64.tests.o
tests/difftests: tests/difftests.tests.o

$(TEST_PROGRAMS): libgcli.a
	$(CCACHE) $(CC) $(CFLAGS) $(CCDEPFLAGS) $(CPPFLAGS) \
		$(LIBATFC_CFLAGS) $(LIBCURL_CFLAGS) $(LIBCRYPTO_CFLAGS) \
		$(LDFLAGS) -o $@ $(@:=.tests.o) libgcli.a \
-- 
2.45.2

[PATCH gcli 2/3] diffutil: Fix buggy hunk range info parser

Details
Message ID
<20240825015305.91593-2-nsonack@herrhotzenplotz.de>
In-Reply-To
<20240825015305.91593-1-nsonack@herrhotzenplotz.de> (view parent)
DKIM signature
pass
Download raw message
Patch: +25 -1
The following header would cause issues:

	@@ -1 +1 @@

Signed-off-by: Nico Sonack <nsonack@herrhotzenplotz.de>
---
 src/diffutil.c    |  3 ++-
 tests/difftests.c | 23 +++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/diffutil.c b/src/diffutil.c
index 96c10b72..fc370298 100644
--- a/src/diffutil.c
+++ b/src/diffutil.c
@@ -349,8 +349,9 @@ parse_hunk_range_info(struct gcli_diff_parser *parser,
	if (read_number(&line, 10, &out->range_r_start) < 0)
		return -1;

	char const delim_r = *line.start++;
	char const delim_r = *line.start;
	if (delim_r == ',') {
		line.start += 1;
		if (read_number(&line, 10, &out->range_r_length) < 0)
			return -1;
	} else if (delim_r != ' ') {
diff --git a/tests/difftests.c b/tests/difftests.c
index ff126e0e..65ef5366 100644
--- a/tests/difftests.c
+++ b/tests/difftests.c
@@ -1022,6 +1022,28 @@ ATF_TC_BODY(bug_patch_series_fail_get_comments, tc)
	ATF_REQUIRE(gcli_patch_series_get_comments(&series, &comments) == 0);
}

ATF_TC_WITHOUT_HEAD(bug_short_hunk_range);
ATF_TC_BODY(bug_short_hunk_range, tc)
{
	struct gcli_diff_parser parser = {0};
	struct gcli_patch patch = {0};

	char const input[] =
		"diff --git a/foo b/foo\n"
		"index 30a503cf..05d233eb 100644\n"
		"--- a/foo\n"
		"+++ b/foo\n"
		"@@ -1 +1 @@\n"
		"-wat\n"
		"+banana\n";

	ATF_REQUIRE(gcli_diff_parser_from_buffer(input, sizeof input, "input", &parser) == 0);
	ATF_REQUIRE(gcli_parse_patch(&parser, &patch) == 0);

	gcli_free_patch(&patch);
	gcli_free_diff_parser(&parser);
}

ATF_TP_ADD_TCS(tp)
{
	ATF_TP_ADD_TC(tp, free_patch_cleans_up_properly);
@@ -1046,6 +1068,7 @@ ATF_TP_ADD_TCS(tp)
	ATF_TP_ADD_TC(tp, new_and_old_with_both_deletions_and_additions);
	ATF_TP_ADD_TC(tp, patch_for_git_object_format_version_1);
	ATF_TP_ADD_TC(tp, bug_patch_series_fail_get_comments);
	ATF_TP_ADD_TC(tp, bug_short_hunk_range);

	return atf_no_error();
}
-- 
2.45.2

[PATCH gcli 3/3] diffutil: Handle diff meta lines (starting with '\') properly

Details
Message ID
<20240825015305.91593-3-nsonack@herrhotzenplotz.de>
In-Reply-To
<20240825015305.91593-1-nsonack@herrhotzenplotz.de> (view parent)
DKIM signature
pass
Download raw message
Patch: +50 -1
We used to get errors parsing diffs when the file diffed was missing
a trailing newline. This gave a diff line like:

	\ No newline at end of file

This caused a hiccup in the parser which made the line a comment
at the end of the diff which makes no sense.

Also add a test case for this specific bug.

Signed-off-by: Nico Sonack <nsonack@herrhotzenplotz.de>
---
 src/diffutil.c                                |  3 +-
 tests/difftests.c                             | 37 +++++++++++++++++++
 .../stuff_with_no_newline_in_diff.diff        | 11 ++++++
 3 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 tests/samples/stuff_with_no_newline_in_diff.diff

diff --git a/src/diffutil.c b/src/diffutil.c
index fc370298..dd57579e 100644
--- a/src/diffutil.c
+++ b/src/diffutil.c
@@ -523,7 +523,7 @@ read_hunk_body(struct gcli_diff_parser *parser, struct gcli_diff_hunk *hunk)
		/* If it is a comment, don't count this line into the absolute diff
		 * offset of the hunk */
		if (line.start[0] == ' ' || line.start[0] == '+' ||
		    line.start[0] == '-')
		    line.start[0] == '-' || line.start[0] == '\\')
		{
			parser->diff_line_offset += 1;
		}
@@ -925,6 +925,7 @@ gcli_hunk_get_comments(struct gcli_diff const *diff,
		case '+':
		case ' ':
		case '-':
		case '\\':
			ctx.diff_line_offset += 1;
			ctx.last_line_is_new = hd == '+';

diff --git a/tests/difftests.c b/tests/difftests.c
index 65ef5366..d7bf9ca3 100644
--- a/tests/difftests.c
+++ b/tests/difftests.c
@@ -1044,6 +1044,42 @@ ATF_TC_BODY(bug_short_hunk_range, tc)
	gcli_free_diff_parser(&parser);
}

ATF_TC_WITHOUT_HEAD(bug_no_newline_at_end_of_file);
ATF_TC_BODY(bug_no_newline_at_end_of_file, tc)
{
	struct gcli_patch patch = {0};
	struct gcli_diff_parser parser = {0};
	struct gcli_diff_comments comments = {0};
	struct gcli_diff_comment *comment = NULL;

	char const *const fname = "stuff_with_no_newline_in_diff.diff";

	FILE *inf = open_sample(fname);
	ATF_REQUIRE(gcli_diff_parser_from_file(inf, fname, &parser) == 0);
	ATF_REQUIRE(gcli_parse_patch(&parser, &patch) == 0);

	TAILQ_INIT(&comments);
	ATF_REQUIRE(gcli_patch_get_comments(&patch, &comments) == 0);

	comment = TAILQ_FIRST(&comments);
	ATF_REQUIRE(comment);

	ATF_CHECK(comment->before.start_row == 1);
	ATF_CHECK(comment->before.end_row == 1);

	ATF_CHECK(comment->after.start_row == 1);
	ATF_CHECK(comment->after.end_row == 1);

	ATF_CHECK_STREQ(comment->comment, "This is a comment\n");
	ATF_CHECK_STREQ(comment->diff_text,
	                "-this is a test file\n"
	                "+this is a test file\n"
	                "\\ No newline at end of file\n");

	gcli_free_patch(&patch);
	gcli_free_diff_parser(&parser);
}

ATF_TP_ADD_TCS(tp)
{
	ATF_TP_ADD_TC(tp, free_patch_cleans_up_properly);
@@ -1069,6 +1105,7 @@ ATF_TP_ADD_TCS(tp)
	ATF_TP_ADD_TC(tp, patch_for_git_object_format_version_1);
	ATF_TP_ADD_TC(tp, bug_patch_series_fail_get_comments);
	ATF_TP_ADD_TC(tp, bug_short_hunk_range);
	ATF_TP_ADD_TC(tp, bug_no_newline_at_end_of_file);

	return atf_no_error();
}
diff --git a/tests/samples/stuff_with_no_newline_in_diff.diff b/tests/samples/stuff_with_no_newline_in_diff.diff
new file mode 100644
index 00000000..7f05b111
--- /dev/null
+++ b/tests/samples/stuff_with_no_newline_in_diff.diff
@@ -0,0 +1,11 @@
diff --git a/test.txt b/test.txt
index 493021b..68a4528 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1 @@
> This is a comment
{
-this is a test file
+this is a test file
\ No newline at end of file
}
-- 
2.45.2
Details
Message ID
<D3OZKIJSJMTV.2OCJTQBA12IBO@gjnoonan.co.uk>
In-Reply-To
<20240825015305.91593-1-nsonack@herrhotzenplotz.de> (view parent)
DKIM signature
pass
Download raw message
Applied and pushed the whole series. Thanks!

-g
Reply to thread Export thread (mbox)