Skip to content

Commit 4803466

Browse files
committed
builtin-commit: avoid double-negation in the code.
The flag no_edit meant "we have got final message from the user and will not editing it any further", but there were quite a few places that needed to check !no_edit. Rename the variable to use_editor and reverse the logic everywhere. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d616a23 commit 4803466

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

builtin-commit.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static char *edit_message, *use_message;
4848
static int all, edit_flag, also, interactive, only, amend, signoff;
4949
static int quiet, verbose, untracked_files, no_verify, allow_empty;
5050

51-
static int no_edit, initial_commit, in_merge;
51+
static int use_editor = 1, initial_commit, in_merge;
5252
const char *only_include_assumed;
5353
struct strbuf message;
5454

@@ -372,7 +372,7 @@ static int prepare_log_message(const char *index_file, const char *prefix)
372372

373373
strbuf_release(&sb);
374374

375-
if (no_edit) {
375+
if (!use_editor) {
376376
struct rev_info rev;
377377
unsigned char sha1[20];
378378
const char *parent = "HEAD";
@@ -398,7 +398,7 @@ static int prepare_log_message(const char *index_file, const char *prefix)
398398
return !!DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES);
399399
}
400400

401-
if (in_merge && !no_edit)
401+
if (in_merge)
402402
fprintf(fp,
403403
"#\n"
404404
"# It looks like you may be committing a MERGE.\n"
@@ -513,9 +513,9 @@ static int parse_and_validate_options(int argc, const char *argv[],
513513
argc = parse_options(argc, argv, builtin_commit_options, usage, 0);
514514

515515
if (logfile || message.len || use_message)
516-
no_edit = 1;
516+
use_editor = 0;
517517
if (edit_flag)
518-
no_edit = 0;
518+
use_editor = 1;
519519

520520
if (get_sha1("HEAD", head_sha1))
521521
initial_commit = 1;
@@ -796,7 +796,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
796796

797797
/* Get the commit message and validate it */
798798
header_len = sb.len;
799-
if (!no_edit) {
799+
if (use_editor) {
800800
char index[PATH_MAX];
801801
const char *env[2] = { index, NULL };
802802
snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);

0 commit comments

Comments
 (0)