Skip to content

Commit dfbfc22

Browse files
Denton-Lgitster
authored andcommitted
remote.c: convert if-else ladder to switch
For better readability, convert the if-else ladder into a switch statement. Suggested-by: Patrick Steinhardt <[email protected]> Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b33c590 commit dfbfc22

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

remote.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,6 @@ static void show_push_unqualified_ref_name_error(const char *dst_value,
11571157
const char *matched_src_name)
11581158
{
11591159
struct object_id oid;
1160-
enum object_type type;
11611160

11621161
/*
11631162
* TRANSLATORS: "matches '%s'%" is the <dst> part of "git push
@@ -1182,31 +1181,37 @@ static void show_push_unqualified_ref_name_error(const char *dst_value,
11821181
BUG("'%s' is not a valid object, "
11831182
"match_explicit_lhs() should catch this!",
11841183
matched_src_name);
1185-
type = oid_object_info(the_repository, &oid, NULL);
1186-
if (type == OBJ_COMMIT) {
1184+
1185+
switch (oid_object_info(the_repository, &oid, NULL)) {
1186+
case OBJ_COMMIT:
11871187
advise(_("The <src> part of the refspec is a commit object.\n"
11881188
"Did you mean to create a new branch by pushing to\n"
11891189
"'%s:refs/heads/%s'?"),
11901190
matched_src_name, dst_value);
1191-
} else if (type == OBJ_TAG) {
1191+
break;
1192+
case OBJ_TAG:
11921193
advise(_("The <src> part of the refspec is a tag object.\n"
11931194
"Did you mean to create a new tag by pushing to\n"
11941195
"'%s:refs/tags/%s'?"),
11951196
matched_src_name, dst_value);
1196-
} else if (type == OBJ_TREE) {
1197+
break;
1198+
case OBJ_TREE:
11971199
advise(_("The <src> part of the refspec is a tree object.\n"
11981200
"Did you mean to tag a new tree by pushing to\n"
11991201
"'%s:refs/tags/%s'?"),
12001202
matched_src_name, dst_value);
1201-
} else if (type == OBJ_BLOB) {
1203+
break;
1204+
case OBJ_BLOB:
12021205
advise(_("The <src> part of the refspec is a blob object.\n"
12031206
"Did you mean to tag a new blob by pushing to\n"
12041207
"'%s:refs/tags/%s'?"),
12051208
matched_src_name, dst_value);
1206-
} else {
1209+
break;
1210+
default:
12071211
advise(_("The <src> part of the refspec ('%s') "
12081212
"is an object ID that doesn't exist.\n"),
12091213
matched_src_name);
1214+
break;
12101215
}
12111216
}
12121217

0 commit comments

Comments
 (0)