Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2013-11-23 03:02:12 +0400
committerEdward Thomson <ethomson@edwardthomson.com>2013-12-03 02:57:41 +0400
commitbab0b9f2d21d993c3f25ee00ce2d243a4dc0de93 (patch)
tree57e11cab3b255a3fb8a46b00601504a002702f42 /src
parent300d192f7ed45112121f2a35d5ca80a4913c7aad (diff)
clean up state metadata more consistently
Diffstat (limited to 'src')
-rw-r--r--src/merge.c46
-rw-r--r--src/repository.c36
-rw-r--r--src/repository.h2
-rw-r--r--src/reset.c2
-rw-r--r--src/revert.c37
-rw-r--r--src/revert.h14
6 files changed, 59 insertions, 78 deletions
diff --git a/src/merge.c b/src/merge.c
index c31a935b0..05e656d1e 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -2362,6 +2362,17 @@ done:
return error;
}
+static int merge_state_cleanup(git_repository *repo)
+{
+ const char *state_files[] = {
+ GIT_MERGE_HEAD_FILE,
+ GIT_MERGE_MODE_FILE,
+ GIT_MERGE_MSG_FILE,
+ };
+
+ return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files));
+}
+
int git_merge(
git_merge_result **out,
git_repository *repo,
@@ -2453,7 +2464,7 @@ int git_merge(
goto done;
on_error:
- git_repository_merge_cleanup(repo);
+ merge_state_cleanup(repo);
git_index_free(index_new);
git__free(result);
@@ -2497,39 +2508,6 @@ int git_merge__setup(
return error;
}
-int git_repository_merge_cleanup(git_repository *repo)
-{
- int error = 0;
- git_buf merge_head_path = GIT_BUF_INIT,
- merge_mode_path = GIT_BUF_INIT,
- merge_msg_path = GIT_BUF_INIT;
-
- assert(repo);
-
- if (git_buf_joinpath(&merge_head_path, repo->path_repository, GIT_MERGE_HEAD_FILE) < 0 ||
- git_buf_joinpath(&merge_mode_path, repo->path_repository, GIT_MERGE_MODE_FILE) < 0 ||
- git_buf_joinpath(&merge_msg_path, repo->path_repository, GIT_MERGE_MSG_FILE) < 0)
- return -1;
-
- if (git_path_isfile(merge_head_path.ptr)) {
- if ((error = p_unlink(merge_head_path.ptr)) < 0)
- goto cleanup;
- }
-
- if (git_path_isfile(merge_mode_path.ptr))
- (void)p_unlink(merge_mode_path.ptr);
-
- if (git_path_isfile(merge_msg_path.ptr))
- (void)p_unlink(merge_msg_path.ptr);
-
-cleanup:
- git_buf_free(&merge_msg_path);
- git_buf_free(&merge_mode_path);
- git_buf_free(&merge_head_path);
-
- return error;
-}
-
/* Merge result data */
int git_merge_result_is_uptodate(git_merge_result *merge_result)
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;
diff --git a/src/repository.h b/src/repository.h
index 832df3bd2..4e79714f1 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -169,4 +169,6 @@ GIT_INLINE(int) git_repository__ensure_not_bare(
return GIT_EBAREREPO;
}
+int git_repository__cleanup_files(git_repository *repo, const char *files[], size_t files_len);
+
#endif
diff --git a/src/reset.c b/src/reset.c
index a9780bfbc..261a36576 100644
--- a/src/reset.c
+++ b/src/reset.c
@@ -149,7 +149,7 @@ int git_reset(
(error = git_index_write(index)) < 0)
goto cleanup;
- if ((error = git_repository_merge_cleanup(repo)) < 0) {
+ if ((error = git_repository_state_cleanup(repo)) < 0) {
giterr_set(GITERR_INDEX, "%s - failed to clean up merge data", ERROR_MSG);
goto cleanup;
}
diff --git a/src/revert.c b/src/revert.c
index 34ba343b6..5660c9919 100644
--- a/src/revert.c
+++ b/src/revert.c
@@ -9,7 +9,6 @@
#include "repository.h"
#include "filebuf.h"
#include "merge.h"
-#include "revert.h"
#include "git2/types.h"
#include "git2/merge.h"
@@ -103,6 +102,13 @@ static int revert_normalize_opts(
return error;
}
+static int revert_state_cleanup(git_repository *repo)
+{
+ const char *state_files[] = { GIT_REVERT_HEAD_FILE, GIT_MERGE_MSG_FILE };
+
+ return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files));
+}
+
int git_revert(
git_repository *repo,
git_commit *commit,
@@ -175,7 +181,7 @@ int git_revert(
goto done;
on_error:
- git_revert__cleanup(repo);
+ revert_state_cleanup(repo);
done:
git_index_free(index_new);
@@ -188,30 +194,3 @@ done:
return error;
}
-
-int git_revert__cleanup(git_repository *repo)
-{
- int error = 0;
- git_buf revert_head_path = GIT_BUF_INIT,
- merge_msg_path = GIT_BUF_INIT;
-
- assert(repo);
-
- if (git_buf_joinpath(&revert_head_path, repo->path_repository, GIT_REVERT_HEAD_FILE) < 0 ||
- git_buf_joinpath(&merge_msg_path, repo->path_repository, GIT_MERGE_MSG_FILE) < 0)
- return -1;
-
- if (git_path_isfile(revert_head_path.ptr)) {
- if ((error = p_unlink(revert_head_path.ptr)) < 0)
- goto cleanup;
- }
-
- if (git_path_isfile(merge_msg_path.ptr))
- (void)p_unlink(merge_msg_path.ptr);
-
-cleanup:
- git_buf_free(&merge_msg_path);
- git_buf_free(&revert_head_path);
-
- return error;
-}
diff --git a/src/revert.h b/src/revert.h
deleted file mode 100644
index ed3912198..000000000
--- a/src/revert.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-#ifndef INCLUDE_revert_h__
-#define INCLUDE_revert_h__
-
-#include "git2/repository.h"
-
-int git_revert__cleanup(git_repository *repo);
-
-#endif