Community
Participate
Working Groups
The header of a hunk of an unified diff shows one area where the files differ: @@ from-file-range to-file-range @@ See: http://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html#Detailed%20Unified More precisely: @@ -oldStart,oldLength +newStart,newLength @@ If the length is 1, then only the start value is included in the header. E.g. "@@ -5 +5 @@" instead of "@@ -5,1 +5,1 @@". The method extractPair(String, char, int[]) in Patcher.java tries to handle this, but the two values of the array "pair" are swaped: 588: pair[0]= 1; 589: pair[1]= Integer.parseInt(line.substring(comma+1)); Executing this code, the value of pair will be [1,5], but it has to be [5,1]. Just swap the assignments: 588: pair[0]= Integer.parseInt(line.substring(comma+1)); 589: pair[1]= 1; This fixes the issue.
Created attachment 20746 [details] Patch for Patcher.java This patch swaps the two assignments of pair.
Thanks for the patch! However, I'm somewhat reluctant to use it because I have yet to find the part of the specification saying that "If the length is 1, then only the start value is included in the header". BTW, my code } else { pair[1]= Integer.parseInt(line.substring(comma+1)) works only by accident because the value of comma happens to be -1 in the else case, which results in a line.substring(-1+1) This is not wrong but slightly bogus...
Do you know how to create a patch that uses the "@@ -5 +5 @@" syntax?
Take a file with one changed line. Create an unified diff with no context lines as follows: # diff -U 0 orig_short.txt changed_short.txt --- orig_short.txt Fri May 6 01:46:07 2005 +++ changed_short.txt Fri May 6 14:44:19 2005 @@ -5 +5 @@ -[5] amet, +[5] amet, CHANGED LINE The "specification" can be found in the source code of the Diffutils: File: diffutils-2.8.1/src/context.c Function: print_unidiff_number_range Line: 274 fprintf (outfile, trans_b < trans_a ? "%ld,0" : "%ld", trans_b);
released patch for N20050507