diff options
author | Ben Straub <bs@github.com> | 2013-10-28 11:04:58 -0700 |
---|---|---|
committer | Ben Straub <bs@github.com> | 2013-10-28 11:04:58 -0700 |
commit | 42c8f8f807fe986534e0cbabbfabc32cb4eb9077 (patch) | |
tree | fa76cb66e6d49855be344026b1cbe31d03962916 /examples | |
parent | a7d28f40a2a01382b76c55ca0a0672c177adaf69 (diff) | |
parent | 5c50f22a93c78190fb7d81802199ff9defc8cf55 (diff) | |
download | libgit2-42c8f8f807fe986534e0cbabbfabc32cb4eb9077.tar.gz |
Merge remote-tracking branch 'libgit2/development' into blame
Diffstat (limited to 'examples')
-rw-r--r-- | examples/diff.c | 65 | ||||
-rw-r--r-- | examples/log.c | 26 | ||||
-rw-r--r-- | examples/network/clone.c | 8 | ||||
-rw-r--r-- | examples/network/fetch.c | 14 | ||||
-rw-r--r-- | examples/network/index-pack.c | 2 |
5 files changed, 63 insertions, 52 deletions
diff --git a/examples/diff.c b/examples/diff.c index 11efa21ec..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_range *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; } @@ -114,20 +118,15 @@ static void usage(const char *message, const char *arg) exit(1); } -enum { - FORMAT_PATCH = 0, - FORMAT_COMPACT = 1, - FORMAT_RAW = 2 -}; - int main(int argc, char *argv[]) { git_repository *repo = NULL; git_tree *t1 = NULL, *t2 = NULL; git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT; - git_diff_list *diff; - int i, color = -1, format = FORMAT_PATCH, cached = 0; + git_diff *diff; + int i, color = -1, cached = 0; + git_diff_format_t format = GIT_DIFF_FORMAT_PATCH; char *a, *treeish1 = NULL, *treeish2 = NULL; const char *dir = "."; @@ -148,13 +147,15 @@ int main(int argc, char *argv[]) } else if (!strcmp(a, "-p") || !strcmp(a, "-u") || !strcmp(a, "--patch")) - format = FORMAT_PATCH; + format = GIT_DIFF_FORMAT_PATCH; else if (!strcmp(a, "--cached")) cached = 1; + else if (!strcmp(a, "--name-only")) + format = GIT_DIFF_FORMAT_NAME_ONLY; else if (!strcmp(a, "--name-status")) - format = FORMAT_COMPACT; + format = GIT_DIFF_FORMAT_NAME_STATUS; else if (!strcmp(a, "--raw")) - format = FORMAT_RAW; + format = GIT_DIFF_FORMAT_RAW; else if (!strcmp(a, "--color")) color = 0; else if (!strcmp(a, "--no-color")) @@ -218,11 +219,11 @@ int main(int argc, char *argv[]) else if (t1 && cached) check(git_diff_tree_to_index(&diff, repo, t1, NULL, &opts), "Diff"); else if (t1) { - git_diff_list *diff2; + git_diff *diff2; check(git_diff_tree_to_index(&diff, repo, t1, NULL, &opts), "Diff"); check(git_diff_index_to_workdir(&diff2, repo, NULL, &opts), "Diff"); check(git_diff_merge(diff, diff2), "Merge diffs"); - git_diff_list_free(diff2); + git_diff_free(diff2); } else if (cached) { check(resolve_to_tree(repo, "HEAD", &t1), "looking up HEAD"); @@ -238,22 +239,12 @@ int main(int argc, char *argv[]) if (color >= 0) fputs(colors[0], stdout); - switch (format) { - case FORMAT_PATCH: - check(git_diff_print_patch(diff, printer, &color), "Displaying diff"); - break; - case FORMAT_COMPACT: - check(git_diff_print_compact(diff, printer, &color), "Displaying diff"); - break; - case FORMAT_RAW: - check(git_diff_print_raw(diff, printer, &color), "Displaying diff"); - break; - } + check(git_diff_print(diff, format, printer, &color), "Displaying diff"); if (color >= 0) fputs(colors[0], stdout); - git_diff_list_free(diff); + git_diff_free(diff); git_tree_free(t1); git_tree_free(t2); git_repository_free(repo); diff --git a/examples/log.c b/examples/log.c index 413c211e4..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_range *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; } @@ -218,7 +222,7 @@ static int match_with_parent( { git_commit *parent; git_tree *a, *b; - git_diff_list *diff; + git_diff *diff; int ndeltas; check(git_commit_parent(&parent, commit, (size_t)i), "Get parent", NULL); @@ -229,7 +233,7 @@ static int match_with_parent( ndeltas = (int)git_diff_num_deltas(diff); - git_diff_list_free(diff); + git_diff_free(diff); git_tree_free(a); git_tree_free(b); git_commit_free(parent); @@ -373,7 +377,7 @@ int main(int argc, char *argv[]) if (opt.show_diff) { git_tree *a = NULL, *b = NULL; - git_diff_list *diff = NULL; + git_diff *diff = NULL; if (parents > 1) continue; @@ -388,10 +392,10 @@ int main(int argc, char *argv[]) check(git_diff_tree_to_tree( &diff, git_commit_owner(commit), a, b, &diffopts), "Diff commit with parent", NULL); - check(git_diff_print_patch(diff, print_diff, NULL), + check(git_diff_print(diff, GIT_DIFF_FORMAT_PATCH, print_diff, NULL), "Displaying diff", NULL); - git_diff_list_free(diff); + git_diff_free(diff); git_tree_free(a); git_tree_free(b); } diff --git a/examples/network/clone.c b/examples/network/clone.c index db35bd7db..4df47eb7f 100644 --- a/examples/network/clone.c +++ b/examples/network/clone.c @@ -25,13 +25,19 @@ static void print_progress(const progress_data *pd) : 0.f; int kbytes = pd->fetch_progress.received_bytes / 1024; - printf("net %3d%% (%4d kb, %5d/%5d) / idx %3d%% (%5d/%5d) / chk %3d%% (%4" PRIuZ "/%4" PRIuZ ") %s\n", + if (pd->fetch_progress.received_objects == pd->fetch_progress.total_objects) { + printf("Resolving deltas %d/%d\r", + pd->fetch_progress.indexed_deltas, + pd->fetch_progress.total_deltas); + } else { + printf("net %3d%% (%4d kb, %5d/%5d) / idx %3d%% (%5d/%5d) / chk %3d%% (%4" PRIuZ "/%4" PRIuZ ") %s\n", network_percent, kbytes, pd->fetch_progress.received_objects, pd->fetch_progress.total_objects, index_percent, pd->fetch_progress.indexed_objects, pd->fetch_progress.total_objects, checkout_percent, pd->completed_steps, pd->total_steps, pd->path); + } } static int fetch_progress(const git_transfer_progress *stats, void *payload) diff --git a/examples/network/fetch.c b/examples/network/fetch.c index 0c545ad7e..4167ef3ca 100644 --- a/examples/network/fetch.c +++ b/examples/network/fetch.c @@ -72,6 +72,7 @@ int fetch(git_repository *repo, int argc, char **argv) const git_transfer_progress *stats; struct dl_data data; git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; + int resolve_deltas_ln = 0; #ifndef _WIN32 pthread_t worker; #endif @@ -113,10 +114,14 @@ int fetch(git_repository *repo, int argc, char **argv) do { usleep(10000); - if (stats->total_objects > 0) + if (stats->received_objects == stats->total_objects) { + printf("Resolving deltas %d/%d\r", + stats->indexed_deltas, stats->total_deltas); + } else if (stats->total_objects > 0) { printf("Received %d/%d objects (%d) in %" PRIuZ " bytes\r", stats->received_objects, stats->total_objects, stats->indexed_objects, stats->received_bytes); + } } while (!data.finished); if (data.ret < 0) @@ -125,8 +130,13 @@ int fetch(git_repository *repo, int argc, char **argv) pthread_join(worker, NULL); #endif - printf("\rReceived %d/%d objects in %zu bytes\n", + if (stats->local_objects > 0) { + printf("\rReceived %d/%d objects in %zu bytes (used %d local objects)\n", + stats->indexed_objects, stats->total_objects, stats->received_bytes, stats->local_objects); + } else{ + printf("\rReceived %d/%d objects in %zu bytes\n", stats->indexed_objects, stats->total_objects, stats->received_bytes); + } // Disconnect the underlying connection to prevent from idling. git_remote_disconnect(remote); diff --git a/examples/network/index-pack.c b/examples/network/index-pack.c index 889305da8..08b45c58c 100644 --- a/examples/network/index-pack.c +++ b/examples/network/index-pack.c @@ -46,7 +46,7 @@ int index_pack(git_repository *repo, int argc, char **argv) return EXIT_FAILURE; } - if (git_indexer_stream_new(&idx, ".", NULL, NULL) < 0) { + if (git_indexer_stream_new(&idx, ".", NULL, NULL, NULL) < 0) { puts("bad idx"); return -1; } |