diff options
author | Vicent Martà <vicent@github.com> | 2013-01-04 08:36:13 -0800 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2013-01-04 08:36:13 -0800 |
commit | 686a243a738d0b8563a55e798aa248a26ad31f2f (patch) | |
tree | bd9cd4f7fd3beee2b9027ab9cb03abcbd575d123 /src | |
parent | 37955f5401a1868b0e7b112cb816ea91ed03ee4f (diff) | |
parent | 42e50b5ed10fcebab794d35cefa1eedcd79072b6 (diff) | |
download | libgit2-686a243a738d0b8563a55e798aa248a26ad31f2f.tar.gz |
Merge pull request #1184 from ethomson/mergehead_iterator
MERGE_HEAD contents iterator
Diffstat (limited to 'src')
-rw-r--r-- | src/merge.c | 53 | ||||
-rw-r--r-- | src/merge.h | 1 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/merge.c b/src/merge.c index dfdadca81..f52c112c9 100644 --- a/src/merge.c +++ b/src/merge.c @@ -241,3 +241,56 @@ int git_merge__bases_many(git_commit_list **out, git_revwalk *walk, git_commit_l *out = result; return 0; } + +int git_repository_mergehead_foreach(git_repository *repo, + git_repository_mergehead_foreach_cb cb, + void *payload) +{ + git_buf merge_head_path = GIT_BUF_INIT, merge_head_file = GIT_BUF_INIT; + char *buffer, *line; + size_t line_num = 1; + git_oid oid; + int error = 0; + + assert(repo && cb); + + if ((error = git_buf_joinpath(&merge_head_path, repo->path_repository, + GIT_MERGE_HEAD_FILE)) < 0) + return error; + + if ((error = git_futils_readbuffer(&merge_head_file, + git_buf_cstr(&merge_head_path))) < 0) + goto cleanup; + + buffer = merge_head_file.ptr; + + while ((line = git__strsep(&buffer, "\n")) != NULL) { + if (strlen(line) != GIT_OID_HEXSZ) { + giterr_set(GITERR_INVALID, "Unable to parse OID - invalid length"); + error = -1; + goto cleanup; + } + + if ((error = git_oid_fromstr(&oid, line)) < 0) + goto cleanup; + + if (cb(&oid, payload) < 0) { + error = GIT_EUSER; + goto cleanup; + } + + ++line_num; + } + + if (*buffer) { + giterr_set(GITERR_MERGE, "No EOL at line %d", line_num); + error = -1; + goto cleanup; + } + +cleanup: + git_buf_free(&merge_head_path); + git_buf_free(&merge_head_file); + + return error; +} diff --git a/src/merge.h b/src/merge.h index af24de474..03b41e388 100644 --- a/src/merge.h +++ b/src/merge.h @@ -10,6 +10,7 @@ #include "git2/types.h" #include "git2/merge.h" #include "commit_list.h" +#include "vector.h" #define GIT_MERGE_MSG_FILE "MERGE_MSG" #define GIT_MERGE_MODE_FILE "MERGE_MODE" |