trailer: reuse ignore_non_trailer() to ignore conflict lines
Make sure we look for trailers before any conflict line by reusing the ignore_non_trailer() function. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Nov 9, 2014 at 10:23 UTC
61cfef4ca4bdacbb90866fa8fd0e0f0b16b2cafc
2 files changed
+27
-7
t/t7513-interpret-trailers.sh
+2
@@ -232,6 +232,8 @@ test_expect_success 'with message that has comments' '
232
233
Reviewed-by: Johan
234
Cc: Peff
235
+ # last comment
236
+
237
EOF
238
cat basic_patch >>expected &&
239
git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
trailer.c
+25
-7
@@ -2,6 +2,7 @@
2
#include "string-list.h"
3
#include "run-command.h"
4
#include "string-list.h"
5
+#include "commit.h"
6
#include "trailer.h"
7
/*
8
* Copyright (c) 2013, 2014 Christian Couder <chriscool@tuxfamily.org>
@@ -769,6 +770,22 @@ static int find_trailer_start(struct strbuf **lines, int count)
770
return only_spaces ? count : 0;
771
}
772
773
+/* Get the index of the end of the trailers */
774
+static int find_trailer_end(struct strbuf **lines, int patch_start)
775
+{
776
+ struct strbuf sb = STRBUF_INIT;
777
+ int i, ignore_bytes;
778
+
779
+ for (i = 0; i < patch_start; i++)
780
+ strbuf_addbuf(&sb, lines[i]);
781
+ ignore_bytes = ignore_non_trailer(&sb);
782
+ strbuf_release(&sb);
783
+ for (i = patch_start - 1; i >= 0 && ignore_bytes > 0; i--)
784
+ ignore_bytes -= lines[i]->len;
785
+
786
+ return i + 1;
787
+}
788
+
789
static int has_blank_line_before(struct strbuf **lines, int start)
790
{
791
for (;start >= 0; start--) {
@@ -791,14 +808,15 @@ static int process_input_file(struct strbuf **lines,
808
struct trailer_item **in_tok_last)
809
{
810
int count = 0;
794
- int patch_start, trailer_start, i;
811
+ int patch_start, trailer_start, trailer_end, i;
812
813
/* Get the line count */
814
while (lines[count])
815
count++;
816
817
patch_start = find_patch_start(lines, count);
801
- trailer_start = find_trailer_start(lines, patch_start);
818
+ trailer_end = find_trailer_end(lines, patch_start);
819
+ trailer_start = find_trailer_start(lines, trailer_end);
820
821
/* Print lines before the trailers as is */
822
print_lines(lines, 0, trailer_start);
@@ -807,14 +825,14 @@ static int process_input_file(struct strbuf **lines,
825
printf("\n");
826
827
/* Parse trailer lines */
810
- for (i = trailer_start; i < patch_start; i++) {
828
+ for (i = trailer_start; i < trailer_end; i++) {
829
if (lines[i]->buf[0] != comment_line_char) {
830
struct trailer_item *new = create_trailer_item(lines[i]->buf);
831
add_trailer_item(in_tok_first, in_tok_last, new);
832
}
833
}
834
817
- return patch_start;
835
+ return trailer_end;
836
}
837
838
static void free_all(struct trailer_item **first)
@@ -831,7 +849,7 @@ void process_trailers(const char *file, int trim_empty, struct string_list *trai
849
struct trailer_item *in_tok_last = NULL;
850
struct trailer_item *arg_tok_first;
851
struct strbuf **lines;
834
- int patch_start;
852
+ int trailer_end;
853
854
/* Default config must be setup first */
855
git_config(git_trailer_default_config, NULL);
@@ -840,7 +858,7 @@ void process_trailers(const char *file, int trim_empty, struct string_list *trai
858
lines = read_input_file(file);
859
860
/* Print the lines before the trailers */
843
- patch_start = process_input_file(lines, &in_tok_first, &in_tok_last);
861
+ trailer_end = process_input_file(lines, &in_tok_first, &in_tok_last);
862
863
arg_tok_first = process_command_line_args(trailers);
864
@@ -851,7 +869,7 @@ void process_trailers(const char *file, int trim_empty, struct string_list *trai
869
free_all(&in_tok_first);
870
871
/* Print the lines after the trailers as is */
854
- print_lines(lines, patch_start, INT_MAX);
872
+ print_lines(lines, trailer_end, INT_MAX);
873
874
strbuf_list_free(lines);
875
}