remote.c: convert if-else ladder to switch

For better readability, convert the if-else ladder into a switch statement. Suggested-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Aug 8, 2025 at 00:24 UTC dfbfc2221b851ff2d09029a6737c4ec3208cf316
1 file changed +12 -7
remote.c
+12 -7
@@ -1157,7 +1157,6 @@ static void show_push_unqualified_ref_name_error(const char *dst_value,
1157 const char *matched_src_name)
1158 {
1159 struct object_id oid;
1160 - enum object_type type;
1160
1161 /*
1162 * 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,
1181 BUG("'%s' is not a valid object, "
1182 "match_explicit_lhs() should catch this!",
1183 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:
1187 advise(_("The <src> part of the refspec is a commit object.\n"
1188 "Did you mean to create a new branch by pushing to\n"
1189 "'%s:refs/heads/%s'?"),
1190 matched_src_name, dst_value);
1191 - } else if (type == OBJ_TAG) {
1191 + break;
1192 + case OBJ_TAG:
1193 advise(_("The <src> part of the refspec is a tag object.\n"
1194 "Did you mean to create a new tag by pushing to\n"
1195 "'%s:refs/tags/%s'?"),
1196 matched_src_name, dst_value);
1196 - } else if (type == OBJ_TREE) {
1197 + break;
1198 + case OBJ_TREE:
1199 advise(_("The <src> part of the refspec is a tree object.\n"
1200 "Did you mean to tag a new tree by pushing to\n"
1201 "'%s:refs/tags/%s'?"),
1202 matched_src_name, dst_value);
1201 - } else if (type == OBJ_BLOB) {
1203 + break;
1204 + case OBJ_BLOB:
1205 advise(_("The <src> part of the refspec is a blob object.\n"
1206 "Did you mean to tag a new blob by pushing to\n"
1207 "'%s:refs/tags/%s'?"),
1208 matched_src_name, dst_value);
1206 - } else {
1209 + break;
1210 + default:
1211 advise(_("The <src> part of the refspec ('%s') "
1212 "is an object ID that doesn't exist.\n"),
1213 matched_src_name);
1214 + break;
1215 }
1216 }
1217