@@ -44,10 +44,15 @@ begin
4444 if i = 1 or j = 1 then
4545 -- we're done!
4646 IF in_hunk THEN
47- IF array_length(context, 1 ) IS NOT NULL THEN
47+ context_length := array_length(context, 1 );
48+ IF context_length IS NOT NULL THEN
49+ IF context_length > context_len THEN
50+ context := context[1 :context_len];
51+ context_length = context_len;
52+ END IF;
4853 -- prepend context to hunk
4954 hunk := context || hunk;
50- hunk_lines_context := hunk_lines_context + array_length(context, 1 ) ;
55+ hunk_lines_context := hunk_lines_context + context_length ;
5156 END IF;
5257 -- write out the last hunk
5358 INSERT INTO page_diff_hunk (page_id, revision, start,
8691 raise notice ' context whoa = %' , context;
8792 -- hunk_lines_context := hunk_lines_context + 1;
8893 -- are we done with this hunk?
89- IF array_length(context, 1 ) = context_len THEN
94+ -- we need to check up until twice the context_len, because of
95+ -- pathological splitting case
96+ IF array_length(context, 1 ) = 2 * context_len THEN
9097 -- prepend context to hunk
91- hunk := context || hunk;
98+ hunk := context[context_len + 1 : 2 * context_len] || hunk;
9299 hunk_lines_context = hunk_lines_context + context_len;
93100 -- write out the hunk
94101 INSERT INTO page_diff_hunk (page_id, revision, start,
98105 hunk_lines_added, hunk_lines_deleted, hunk_lines_context);
99106 -- and reset
100107 hunk := array[]::text [];
101- context := array[]:: text [ ];
108+ context := context[ 1 :context_len ];
102109 in_hunk := FALSE;
103110 hunk_lines_added := 0 ;
104111 hunk_lines_deleted := 0 ;
0 commit comments