diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/diff.c | 28 | ||||
| -rw-r--r-- | examples/log.c | 16 |
2 files changed, 26 insertions, 18 deletions
diff --git a/examples/diff.c b/examples/diff.c index 2542f4269..694621f1e 100644 --- a/examples/diff.c +++ b/examples/diff.c @@ -45,25 +45,23 @@ char *colors[] = { static int printer( const git_diff_delta *delta, - const git_diff_hunk *range, - char usage, - const char *line, - size_t line_len, + const git_diff_hunk *hunk, + const git_diff_line *line, void *data) { int *last_color = data, color = 0; - (void)delta; (void)range; (void)line_len; + (void)delta; (void)hunk; if (*last_color >= 0) { - switch (usage) { - case GIT_DIFF_LINE_ADDITION: color = 3; break; - case GIT_DIFF_LINE_DELETION: color = 2; break; + switch (line->origin) { + case GIT_DIFF_LINE_ADDITION: color = 3; break; + case GIT_DIFF_LINE_DELETION: color = 2; break; case GIT_DIFF_LINE_ADD_EOFNL: color = 3; break; case GIT_DIFF_LINE_DEL_EOFNL: color = 2; break; - case GIT_DIFF_LINE_FILE_HDR: color = 1; break; - case GIT_DIFF_LINE_HUNK_HDR: color = 4; break; - default: color = 0; + case GIT_DIFF_LINE_FILE_HDR: color = 1; break; + case GIT_DIFF_LINE_HUNK_HDR: color = 4; break; + default: break; } if (color != *last_color) { if (*last_color == 1 || color == 1) @@ -73,7 +71,13 @@ static int printer( } } - fputs(line, stdout); + if (line->origin == GIT_DIFF_LINE_CONTEXT || + line->origin == GIT_DIFF_LINE_ADDITION || + line->origin == GIT_DIFF_LINE_DELETION) + fputc(line->origin, stdout); + + fwrite(line->content, 1, line->content_len, stdout); + return 0; } diff --git a/examples/log.c b/examples/log.c index 30de16ae9..4c2df07c9 100644 --- a/examples/log.c +++ b/examples/log.c @@ -184,14 +184,18 @@ static void print_commit(git_commit *commit) static int print_diff( const git_diff_delta *delta, - const git_diff_hunk *range, - char usage, - const char *line, - size_t line_len, + const git_diff_hunk *hunk, + const git_diff_line *line, void *data) { - (void)delta; (void)range; (void)usage; (void)line_len; (void)data; - fputs(line, stdout); + (void)delta; (void)hunk; (void)data; + + if (line->origin == GIT_DIFF_LINE_CONTEXT || + line->origin == GIT_DIFF_LINE_ADDITION || + line->origin == GIT_DIFF_LINE_DELETION) + fputc(line->origin, stdout); + + fwrite(line->content, 1, line->content_len, stdout); return 0; } |
