summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2013-01-03 12:44:09 -0600
committerEdward Thomson <ethomson@microsoft.com>2013-01-03 16:35:59 -0600
commit42e50b5ed10fcebab794d35cefa1eedcd79072b6 (patch)
treebf7f56bda58b5be43edf2f2ba2ea31aa49a51311 /src
parentb449a9ae8c9ac17652c5ab006859dd29b62a5b48 (diff)
downloadlibgit2-42e50b5ed10fcebab794d35cefa1eedcd79072b6.tar.gz
MERGE_HEAD contents iterator
Diffstat (limited to 'src')
-rw-r--r--src/merge.c53
-rw-r--r--src/merge.h1
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"