diff options
| author | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-08-01 17:49:19 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-08-01 18:39:20 +0200 |
| commit | 074841ec6ae2cc70391544ea76082bc4e2c4a1bf (patch) | |
| tree | a0c9b36cc08aff7074b2b2884304ba7bda4609fe /src | |
| parent | 2340b18102eedc73cbbfeca43f0b22e5d4119c38 (diff) | |
| download | libgit2-074841ec6ae2cc70391544ea76082bc4e2c4a1bf.tar.gz | |
repository: add a getter and remove function for git's prepared message
The 'git revert/cherry-pick/merge -n' commands leave .git/MERGE_MSG
behind so that git-commit can find it. As we don't yet support these
operations, users who are shelling out to let git perform these
operations haven't had a convenient way to get this message.
These functions allow the user to retrieve the message and remove it
when she's created the commit.
Diffstat (limited to 'src')
| -rw-r--r-- | src/repository.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/repository.c b/src/repository.c index e0104f34d..ba2920321 100644 --- a/src/repository.c +++ b/src/repository.c @@ -1071,3 +1071,59 @@ int git_repository_head_tree(git_tree **tree, git_repository *repo) *tree = (git_tree *)obj; return 0; } + +#define MERGE_MSG_FILE "MERGE_MSG" + +int git_repository_message(char *buffer, size_t len, git_repository *repo) +{ + git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT; + struct stat st; + ssize_t size; + int error; + + if (git_buf_joinpath(&path, repo->path_repository, MERGE_MSG_FILE) < 0) + return -1; + + error = p_stat(git_buf_cstr(&path), &st); + if (error < 0) { + if (errno == ENOENT) + error = GIT_ENOTFOUND; + + git_buf_free(&path); + return error; + } + + if (buffer == NULL) { + git_buf_free(&path); + return st.st_size; + } + + if (git_futils_readbuffer(&buf, git_buf_cstr(&path)) < 0) + goto on_error; + + memcpy(buffer, git_buf_cstr(&buf), len); + size = git_buf_len(&buf); + + git_buf_free(&path); + git_buf_free(&buf); + return size; + +on_error: + git_buf_free(&path); + return -1; + +} + +int git_repository_message_remove(git_repository *repo) +{ + git_buf path = GIT_BUF_INIT; + int error; + + if (git_buf_joinpath(&path, repo->path_repository, MERGE_MSG_FILE) < 0) + return -1; + + error = p_unlink(git_buf_cstr(&path)); + git_buf_free(&path); + + return error; +} |
