with -F or -p, emit better function lines: no leading white space

* src/diff.c (print_context_function): For languages like Ada
that allow local functions and procedures, the plain context
function line may start with enough blank characters that the
function name does not get completely printed in the 40
characters limit.  This patch solves this problem by removing
these useless initial blank characters.
* NEWS (Changes in behavior): Mention this change.
This commit is contained in:
Yannick Moy 2010-03-04 14:20:16 +01:00 committed by Jim Meyering
parent d9c2b10e33
commit 24cc227fa1
2 changed files with 14 additions and 5 deletions

7
NEWS
View File

@ -4,6 +4,13 @@ GNU diffutils NEWS -*- outline -*-
** Changes in behavior
In context-style diffs, diff prints a portion of a preceding "function"
line for each hunk, with --show-function-line=RE (-F) or
--show-c-function (-p). Now, it trims leading blanks from such lines
before extracting a prefix. This is useful especially when a function
line is so far indented that the name itself would be truncated or not
included in the limited-width substring that diff appends.
diff once again reports a difference with the diagnostic
"Binary files A and B differ" when at least one of the files
appears to be binary. From 2.8.4 through diffutils-2.9, it printed

View File

@ -145,13 +145,15 @@ print_context_number_range (struct file_data const *file, lin a, lin b)
static void
print_context_function (FILE *out, char const *function)
{
int i;
int i, j;
putc (' ', out);
for (i = 0; i < 40 && function[i] != '\n'; i++)
for (i = 0; isspace ((unsigned char)function[i]) && function[i] != '\n'; i++)
continue;
while (0 < i && isspace ((unsigned char) function[i - 1]))
i--;
fwrite (function, sizeof (char), i, out);
for (j = i; j < i + 40 && function[j] != '\n'; j++)
continue;
while (i < j && isspace ((unsigned char) function[j - 1]))
j--;
fwrite (function + i, sizeof (char), j - i, out);
}
/* Print a portion of an edit script in context format.