Move GIT_MERGE_CONFIG_* to its own enum
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
diff --git a/include/git2/merge.h b/include/git2/merge.h
index dc63ed5..d0092e4 100644
--- a/include/git2/merge.h
+++ b/include/git2/merge.h
@@ -266,19 +266,26 @@ typedef enum {
* to simply set HEAD to the target commit(s).
*/
GIT_MERGE_ANALYSIS_UNBORN = (1 << 3),
+} git_merge_analysis_t;
+
+typedef enum {
+ /*
+ * No configuration was found that suggests a behavior for merge.
+ */
+ GIT_MERGE_CONFIG_NONE = 0,
/**
* There is a `merge.ff=false` configuration setting, suggesting that
* the user does not want to allow a fast-forward merge.
*/
- GIT_MERGE_CONFIG_NO_FASTFORWARD = (1 << 4),
+ GIT_MERGE_CONFIG_NO_FASTFORWARD = (1 << 0),
/**
* There is a `merge.ff=only` configuration setting, suggesting that
* the user only wants fast-forward merges.
*/
- GIT_MERGE_CONFIG_FASTFORWARD_ONLY = (1 << 5),
-} git_merge_analysis_t;
+ GIT_MERGE_CONFIG_FASTFORWARD_ONLY = (1 << 1),
+} git_merge_config_t;
/**
* Analyzes the given branch(es) and determines the opportunities for
@@ -292,6 +299,7 @@ typedef enum {
*/
GIT_EXTERN(int) git_merge_analysis(
git_merge_analysis_t *analysis_out,
+ git_merge_config_t *config_out,
git_repository *repo,
const git_merge_head **their_heads,
size_t their_heads_len);
diff --git a/src/merge.c b/src/merge.c
index 85b7448..02851e5 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -2564,12 +2564,14 @@ done:
return error;
}
-int analysis_config(git_merge_analysis_t *out, git_repository *repo)
+int merge_config(git_merge_config_t *out, git_repository *repo)
{
git_config *config;
const char *value;
int bool_value, error = 0;
+ *out = GIT_MERGE_CONFIG_NONE;
+
if ((error = git_repository_config(&config, repo)) < 0)
goto done;
@@ -2596,7 +2598,8 @@ done:
}
int git_merge_analysis(
- git_merge_analysis_t *out,
+ git_merge_analysis_t *analysis_out,
+ git_merge_config_t *config_out,
git_repository *repo,
const git_merge_head **their_heads,
size_t their_heads_len)
@@ -2604,7 +2607,7 @@ int git_merge_analysis(
git_merge_head *ancestor_head = NULL, *our_head = NULL;
int error = 0;
- assert(out && repo && their_heads);
+ assert(analysis_out && config_out && repo && their_heads);
if (their_heads_len != 1) {
giterr_set(GITERR_MERGE, "Can only merge a single branch");
@@ -2612,13 +2615,13 @@ int git_merge_analysis(
goto done;
}
- *out = GIT_MERGE_ANALYSIS_NONE;
+ *analysis_out = GIT_MERGE_ANALYSIS_NONE;
- if ((error = analysis_config(out, repo)) < 0)
+ if ((error = merge_config(config_out, repo)) < 0)
goto done;
if (git_repository_head_unborn(repo)) {
- *out |= GIT_MERGE_ANALYSIS_FASTFORWARD | GIT_MERGE_ANALYSIS_UNBORN;
+ *analysis_out |= GIT_MERGE_ANALYSIS_FASTFORWARD | GIT_MERGE_ANALYSIS_UNBORN;
goto done;
}
@@ -2627,15 +2630,15 @@ int git_merge_analysis(
/* We're up-to-date if we're trying to merge our own common ancestor. */
if (ancestor_head && git_oid_equal(&ancestor_head->oid, &their_heads[0]->oid))
- *out |= GIT_MERGE_ANALYSIS_UP_TO_DATE;
+ *analysis_out |= GIT_MERGE_ANALYSIS_UP_TO_DATE;
/* We're fastforwardable if we're our own common ancestor. */
else if (ancestor_head && git_oid_equal(&ancestor_head->oid, &our_head->oid))
- *out |= GIT_MERGE_ANALYSIS_FASTFORWARD | GIT_MERGE_ANALYSIS_NORMAL;
+ *analysis_out |= GIT_MERGE_ANALYSIS_FASTFORWARD | GIT_MERGE_ANALYSIS_NORMAL;
/* Otherwise, just a normal merge is possible. */
else
- *out |= GIT_MERGE_ANALYSIS_NORMAL;
+ *analysis_out |= GIT_MERGE_ANALYSIS_NORMAL;
done:
git_merge_head_free(ancestor_head);
diff --git a/tests/merge/workdir/analysis.c b/tests/merge/workdir/analysis.c
index daa4e9d..d4cf587 100644
--- a/tests/merge/workdir/analysis.c
+++ b/tests/merge/workdir/analysis.c
@@ -36,71 +36,76 @@ void test_merge_workdir_analysis__cleanup(void)
cl_git_sandbox_cleanup();
}
-static git_merge_analysis_t analysis_from_branch(const char *branchname)
+static void analysis_from_branch(
+ git_merge_analysis_t *merge_analysis,
+ git_merge_config_t *merge_config,
+ const char *branchname)
{
git_buf refname = GIT_BUF_INIT;
git_reference *their_ref;
git_merge_head *their_head;
- git_merge_analysis_t analysis;
git_buf_printf(&refname, "%s%s", GIT_REFS_HEADS_DIR, branchname);
cl_git_pass(git_reference_lookup(&their_ref, repo, git_buf_cstr(&refname)));
cl_git_pass(git_merge_head_from_ref(&their_head, repo, their_ref));
- cl_git_pass(git_merge_analysis(&analysis, repo, (const git_merge_head **)&their_head, 1));
+ cl_git_pass(git_merge_analysis(merge_analysis, merge_config, repo, (const git_merge_head **)&their_head, 1));
git_buf_free(&refname);
git_merge_head_free(their_head);
git_reference_free(their_ref);
-
- return analysis;
}
void test_merge_workdir_analysis__fastforward(void)
{
- git_merge_analysis_t analysis;
+ git_merge_analysis_t merge_analysis;
+ git_merge_config_t merge_config;
- analysis = analysis_from_branch(FASTFORWARD_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD, (analysis & GIT_MERGE_ANALYSIS_FASTFORWARD));
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, (analysis & GIT_MERGE_ANALYSIS_NORMAL));
+ analysis_from_branch(&merge_analysis, &merge_config, FASTFORWARD_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD, (merge_analysis & GIT_MERGE_ANALYSIS_FASTFORWARD));
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, (merge_analysis & GIT_MERGE_ANALYSIS_NORMAL));
}
void test_merge_workdir_analysis__no_fastforward(void)
{
- git_merge_analysis_t analysis;
+ git_merge_analysis_t merge_analysis;
+ git_merge_config_t merge_config;
- analysis = analysis_from_branch(NOFASTFORWARD_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, analysis);
+ analysis_from_branch(&merge_analysis, &merge_config, NOFASTFORWARD_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, merge_analysis);
}
void test_merge_workdir_analysis__uptodate(void)
{
- git_merge_analysis_t analysis;
+ git_merge_analysis_t merge_analysis;
+ git_merge_config_t merge_config;
- analysis = analysis_from_branch(UPTODATE_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, analysis);
+ analysis_from_branch(&merge_analysis, &merge_config, UPTODATE_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis);
}
void test_merge_workdir_analysis__uptodate_merging_prev_commit(void)
{
- git_merge_analysis_t analysis;
+ git_merge_analysis_t merge_analysis;
+ git_merge_config_t merge_config;
- analysis = analysis_from_branch(PREVIOUS_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, analysis);
+ analysis_from_branch(&merge_analysis, &merge_config, PREVIOUS_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis);
}
void test_merge_workdir_analysis__unborn(void)
{
- git_merge_analysis_t analysis;
+ git_merge_analysis_t merge_analysis;
+ git_merge_config_t merge_config;
git_buf master = GIT_BUF_INIT;
git_buf_joinpath(&master, git_repository_path(repo), "refs/heads/master");
p_unlink(git_buf_cstr(&master));
- analysis = analysis_from_branch(NOFASTFORWARD_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD, (analysis & GIT_MERGE_ANALYSIS_FASTFORWARD));
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_UNBORN, (analysis & GIT_MERGE_ANALYSIS_UNBORN));
+ analysis_from_branch(&merge_analysis, &merge_config, NOFASTFORWARD_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD, (merge_analysis & GIT_MERGE_ANALYSIS_FASTFORWARD));
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_UNBORN, (merge_analysis & GIT_MERGE_ANALYSIS_UNBORN));
git_buf_free(&master);
}
@@ -108,26 +113,28 @@ void test_merge_workdir_analysis__unborn(void)
void test_merge_workdir_analysis__fastforward_with_config_noff(void)
{
git_config *config;
- git_merge_analysis_t analysis;
+ git_merge_analysis_t merge_analysis;
+ git_merge_config_t merge_config;
git_repository_config(&config, repo);
git_config_set_string(config, "merge.ff", "false");
- analysis = analysis_from_branch(FASTFORWARD_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD, (analysis & GIT_MERGE_ANALYSIS_FASTFORWARD));
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, (analysis & GIT_MERGE_ANALYSIS_NORMAL));
- cl_assert_equal_i(GIT_MERGE_CONFIG_NO_FASTFORWARD, (analysis & GIT_MERGE_CONFIG_NO_FASTFORWARD));
+ analysis_from_branch(&merge_analysis, &merge_config, FASTFORWARD_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD, (merge_analysis & GIT_MERGE_ANALYSIS_FASTFORWARD));
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, (merge_analysis & GIT_MERGE_ANALYSIS_NORMAL));
+ cl_assert_equal_i(GIT_MERGE_CONFIG_NO_FASTFORWARD, (merge_config & GIT_MERGE_CONFIG_NO_FASTFORWARD));
}
void test_merge_workdir_analysis__no_fastforward_with_config_ffonly(void)
{
git_config *config;
- git_merge_analysis_t analysis;
+ git_merge_analysis_t merge_analysis;
+ git_merge_config_t merge_config;
git_repository_config(&config, repo);
git_config_set_string(config, "merge.ff", "only");
- analysis = analysis_from_branch(NOFASTFORWARD_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, (analysis & GIT_MERGE_ANALYSIS_NORMAL));
- cl_assert_equal_i(GIT_MERGE_CONFIG_FASTFORWARD_ONLY, (analysis & GIT_MERGE_CONFIG_FASTFORWARD_ONLY));
+ analysis_from_branch(&merge_analysis, &merge_config, NOFASTFORWARD_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, (merge_analysis & GIT_MERGE_ANALYSIS_NORMAL));
+ cl_assert_equal_i(GIT_MERGE_CONFIG_FASTFORWARD_ONLY, (merge_config & GIT_MERGE_CONFIG_FASTFORWARD_ONLY));
}