commit/status: check $GIT_DIR/MERGE_HEAD only once
The code checked for the MERGE_HEAD file to see if we were about to commit a merge twice in the codepath; also one of them used a variable merge_head_sha1[] which was set but was never used. Just check it once, but do so also in "git status", too, as we will be using this for status generation in the next patch. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Dec 11, 2009 at 23:45 UTC
309883015ff3af6ce14ff9fe401e06cfce8adb13
1 file changed
+4
-6
builtin-commit.c
+4
-6
@@ -36,7 +36,7 @@ static const char * const builtin_status_usage[] = {
36
NULL
37
};
38
39
-static unsigned char head_sha1[20], merge_head_sha1[20];
39
+static unsigned char head_sha1[20];
40
static char *use_message_buffer;
41
static const char commit_editmsg[] = "COMMIT_EDITMSG";
42
static struct lock_file index_lock; /* real index */
@@ -319,7 +319,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
319
*/
320
commit_style = COMMIT_PARTIAL;
321
322
- if (file_exists(git_path("MERGE_HEAD")))
322
+ if (in_merge)
323
die("cannot do a partial commit during a merge.");
324
325
memset(&partial, 0, sizeof(partial));
@@ -758,9 +758,6 @@ static int parse_and_validate_options(int argc, const char *argv[],
758
if (get_sha1("HEAD", head_sha1))
759
initial_commit = 1;
760
761
- if (!get_sha1("MERGE_HEAD", merge_head_sha1))
762
- in_merge = 1;
763
-
761
/* Sanity check options */
762
if (amend && initial_commit)
763
die("You have nothing to amend.");
@@ -951,6 +948,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
948
949
wt_status_prepare(&s);
950
git_config(git_status_config, &s);
951
+ in_merge = file_exists(git_path("MERGE_HEAD"));
952
argc = parse_options(argc, argv, prefix,
953
builtin_status_options,
954
builtin_status_usage, 0);
@@ -1057,10 +1055,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1055
1056
wt_status_prepare(&s);
1057
git_config(git_commit_config, &s);
1058
+ in_merge = file_exists(git_path("MERGE_HEAD"));
1059
1060
if (s.use_color == -1)
1061
s.use_color = git_use_color_default;
1063
-
1062
argc = parse_and_validate_options(argc, argv, builtin_commit_usage,
1063
prefix, &s);
1064
if (dry_run) {