From a402ac62e1fbf150d9e4554812f9abd2d8d6fd86 Mon Sep 17 00:00:00 2001 From: Jason Haslam Date: Mon, 8 Jun 2015 10:11:18 -0600 Subject: [PATCH] blame: add blame progress callback --- include/git2/blame.h | 16 ++++++++++++++++ src/blame_git.c | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/include/git2/blame.h b/include/git2/blame.h index f42c8155289..f4faa160c45 100644 --- a/include/git2/blame.h +++ b/include/git2/blame.h @@ -51,6 +51,19 @@ typedef enum { GIT_BLAME_IGNORE_WHITESPACE = (1<<6), } git_blame_flag_t; +/** + * Blame progress callback. + * + * Called for each blame suspect. + * + * - 'suspect' is the id of the suspect commit. + * + * Returning a non-zero value will abort the blame. + */ +typedef int (*git_blame_progress_cb)( + const git_oid *suspect, + void *payload); + /** * Blame options structure * @@ -87,6 +100,9 @@ typedef struct git_blame_options { * The default is the last line of the file. */ size_t max_line; + + git_blame_progress_cb progress_cb; + void *payload; } git_blame_options; #define GIT_BLAME_OPTIONS_VERSION 1 diff --git a/src/blame_git.c b/src/blame_git.c index 073137a68a1..e2928fd7951 100644 --- a/src/blame_git.c +++ b/src/blame_git.c @@ -653,6 +653,14 @@ int git_blame__like_git(git_blame *blame, uint32_t opt) if (!suspect) break; + /* Report progress. */ + if (blame->options.progress_cb) { + int error; + const git_oid *id = git_commit_id(suspect->commit); + if ((error = blame->options.progress_cb(id, blame->options.payload))) + return error; + } + /* We'll use this suspect later in the loop, so hold on to it for now. */ origin_incref(suspect);