summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2013-01-04 08:36:13 -0800
committerVicent Martí <vicent@github.com>2013-01-04 08:36:13 -0800
commit686a243a738d0b8563a55e798aa248a26ad31f2f (patch)
treebd9cd4f7fd3beee2b9027ab9cb03abcbd575d123 /src
parent37955f5401a1868b0e7b112cb816ea91ed03ee4f (diff)
parent42e50b5ed10fcebab794d35cefa1eedcd79072b6 (diff)
downloadlibgit2-686a243a738d0b8563a55e798aa248a26ad31f2f.tar.gz
Merge pull request #1184 from ethomson/mergehead_iterator
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"