55 new_revision int ;
66 hunk text [];
77 context text []; -- only contains consecutive lines in LCS
8+ context_length int ;
89 in_hunk boolean := FALSE;
910 hunk_lines_added int := 0 ;
1011 hunk_lines_deleted int := 0 ;
@@ -35,10 +36,11 @@ begin
3536 raise notice ' Determining longest common substring table...' ;
3637 C := lcs_length(X, Y);
3738 raise notice ' Longest common substring table determined.' ;
39+ raise notice ' context_len = %' , context_len;
3840 LOOP -- moving backwards
3941 raise notice ' i = %, j = %' , i, j;
40- raise notice ' context = %' , context;
4142 raise notice ' hunk = %' , hunk;
43+ raise notice ' context here = %' , context;
4244 if i = 1 or j = 1 then
4345 -- we're done!
4446 IF in_hunk THEN
@@ -75,18 +77,24 @@ begin
7577 context := (' ' || Xline) || context;
7678 -- hunk_lines_context := hunk_lines_context + 1;
7779 ELSE
78- context := (' ' || Xline) || context[2 :context_len];
80+ -- pull the last one off before you stick the new one in front
81+ raise notice ' sliced context = %' , context[1 :context_len- 1 ];
82+ context := (' ' || Xline) || context[1 :context_len- 1 ];
7983 END IF;
8084 ELSE
8185 context := (' ' || Xline) || context;
86+ raise notice ' context whoa = %' , context;
8287 -- hunk_lines_context := hunk_lines_context + 1;
8388 -- are we done with this hunk?
8489 IF array_length(context, 1 ) = context_len THEN
90+ -- prepend context to hunk
91+ hunk := context || hunk;
92+ hunk_lines_context = hunk_lines_context + context_len;
8593 -- write out the hunk
8694 INSERT INTO page_diff_hunk (page_id, revision, start,
8795 content, lines_added, lines_deleted, lines_context)
8896 VALUES
89- (page_id, latest .revision , i, array_to_string(hunk, E' \n ' ),
97+ (page_id, latest .revision , i- 1 , array_to_string(hunk, E' \n ' ),
9098 hunk_lines_added, hunk_lines_deleted, hunk_lines_context);
9199 -- and reset
92100 hunk := array[]::text [];
@@ -102,18 +110,20 @@ begin
102110 continue; -- skip the rest of this function and go on
103111 end if;
104112 -- reset context array
113+ context_length := array_length(context, 1 );
114+ raise notice ' context there = %' , context;
105115 IF NOT in_hunk THEN
106116 -- start a new hunk
107117 hunk = context;
108118 in_hunk = TRUE;
109- IF array_length(context, 1 ) IS NOT NULL THEN
110- hunk_lines_context := hunk_lines_context + array_length(context, 1 ) ;
119+ IF context_length IS NOT NULL THEN
120+ hunk_lines_context := context_length ;
111121 END IF;
112122 ELSE
113- IF array_length(context, 1 ) IS NOT NULL THEN
123+ IF context_length IS NOT NULL THEN
114124 -- prepend context to hunk
115125 hunk := context || hunk;
116- hunk_lines_context := hunk_lines_context + array_length(context, 1 ) ;
126+ hunk_lines_context := hunk_lines_context + context_length ;
117127 END IF;
118128 END IF;
119129 context := array[]::text [];
0 commit comments