diff options
author | Edward Thomson <ethomson@microsoft.com> | 2013-11-23 03:02:12 +0400 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2013-12-03 02:57:41 +0400 |
commit | bab0b9f2d21d993c3f25ee00ce2d243a4dc0de93 (patch) | |
tree | 57e11cab3b255a3fb8a46b00601504a002702f42 /src/repository.c | |
parent | 300d192f7ed45112121f2a35d5ca80a4913c7aad (diff) |
clean up state metadata more consistently
Diffstat (limited to 'src/repository.c')
-rw-r--r-- | src/repository.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/repository.c b/src/repository.c index dcc02e4fb..278c0384e 100644 --- a/src/repository.c +++ b/src/repository.c @@ -1965,6 +1965,42 @@ int git_repository_state(git_repository *repo) return state; } +int git_repository__cleanup_files(git_repository *repo, const char *files[], size_t files_len) +{ + git_buf path = GIT_BUF_INIT; + size_t i; + int error = 0; + + for (i = 0; i < files_len; ++i) { + git_buf_clear(&path); + + if ((error = git_buf_joinpath(&path, repo->path_repository, files[i])) < 0 || + (git_path_isfile(git_buf_cstr(&path)) && + (error = p_unlink(git_buf_cstr(&path))) < 0)) + goto done; + } + +done: + git_buf_free(&path); + + return error; +} + +static const char *state_files[] = { + GIT_MERGE_HEAD_FILE, + GIT_MERGE_MODE_FILE, + GIT_MERGE_MSG_FILE, + GIT_REVERT_HEAD_FILE, + GIT_CHERRY_PICK_HEAD_FILE, +}; + +int git_repository_state_cleanup(git_repository *repo) +{ + assert(repo); + + return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files)); +} + int git_repository_is_shallow(git_repository *repo) { git_buf path = GIT_BUF_INIT; |