diff options
author | Russell Belfer <rb@github.com> | 2013-10-21 13:42:42 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-10-21 13:42:42 -0700 |
commit | 3b5f795446601868d52d09ebac70ae3b7aee157a (patch) | |
tree | ba900c737284e65c172fde7284af3f309b0a0078 /examples/diff.c | |
parent | 74a627f04528f7e02f69d8d7947820582ce7ca15 (diff) | |
download | libgit2-3b5f795446601868d52d09ebac70ae3b7aee157a.tar.gz |
Create git_diff_line and extend git_diff_hunk
Instead of having functions with so very many parameters to pass
hunk and line data, this takes the existing git_diff_hunk struct
and extends it with more hunk data, plus adds a git_diff_line.
Those structs are used to pass back hunk and line data instead of
the old APIs that took tons of parameters.
Some work that was previously only being done for git_diff_patch
creation (scanning the diff content for exact line counts) is now
done for all callbacks, but the performance difference should not
be noticable.
Diffstat (limited to 'examples/diff.c')
-rw-r--r-- | examples/diff.c | 28 |
1 files changed, 16 insertions, 12 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; } |