drop trailing newline from warning/error/die messages

Our error reporting routines append a trailing newline, and the strings we pass to them should not include them (otherwise we get an extra blank line after the message). These cases were all found by looking at the results of: git grep -P '[^_](error|error_errno|warning|die|die_errno)\(.*\\n"[,)]' '*.c' Note that we _do_ sometimes include a newline in the middle of such messages, to create multiline output (hence our grep matching "," or ")" after we see the newline, so we know we're at the end of the string). It's possible that one or more of these cases could intentionally be including a blank line at the end, but having looked at them all manually, I think these are all just mistakes. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 5, 2024 at 04:51 UTC 1a60f2066aadf68391aed69f4d5914d914b60f5b
12 files changed +22 -22
builtin/bisect.c
+2 -2
@@ -583,7 +583,7 @@ static int prepare_revs(struct bisect_terms *terms, struct rev_info *revs)
583 refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
584 add_bisect_ref, good, "refs/bisect/", &cb);
585 if (prepare_revision_walk(revs))
586 - res = error(_("revision walk setup failed\n"));
586 + res = error(_("revision walk setup failed"));
587
588 free(good);
589 free(bad);
@@ -1108,7 +1108,7 @@ static enum bisect_error bisect_skip(struct bisect_terms *terms, int argc,
1108 setup_revisions(2, argv + i - 1, &revs, NULL);
1109
1110 if (prepare_revision_walk(&revs))
1111 - die(_("revision walk setup failed\n"));
1111 + die(_("revision walk setup failed"));
1112 while ((commit = get_revision(&revs)) != NULL)
1113 strvec_push(&argv_state,
1114 oid_to_hex(&commit->object.oid));
builtin/fetch.c
+2 -2
@@ -1161,7 +1161,7 @@ static int store_updated_refs(struct display_state *display_state,
1161 opt.exclude_hidden_refs_section = "fetch";
1162 rm = ref_map;
1163 if (check_connected(iterate_ref_map, &rm, &opt)) {
1164 - rc = error(_("%s did not send all necessary objects\n"),
1164 + rc = error(_("%s did not send all necessary objects"),
1165 display_state->url);
1166 goto abort;
1167 }
@@ -1458,7 +1458,7 @@ static void set_option(struct transport *transport, const char *name, const char
1458 die(_("option \"%s\" value \"%s\" is not valid for %s"),
1459 name, value, transport->url);
1460 if (r > 0)
1461 - warning(_("option \"%s\" is ignored for %s\n"),
1461 + warning(_("option \"%s\" is ignored for %s"),
1462 name, transport->url);
1463 }
1464
builtin/stash.c
+1 -1
@@ -484,7 +484,7 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)
484 " to make room.\n"),
485 ce->name, new_path.buf);
486 if (rename(ce->name, new_path.buf))
487 - die("Failed to move %s to %s\n",
487 + die("Failed to move %s to %s",
488 ce->name, new_path.buf);
489 strbuf_release(&new_path);
490 }
builtin/submodule--helper.c
+1 -1
@@ -917,7 +917,7 @@ static void generate_submodule_summary(struct summary_cb *info,
917 } else {
918 /* for a submodule removal (mode:0000000), don't warn */
919 if (p->mod_dst)
920 - warning(_("unexpected mode %o\n"), p->mod_dst);
920 + warning(_("unexpected mode %o"), p->mod_dst);
921 }
922 }
923
fetch-pack.c
+1 -1
@@ -1614,7 +1614,7 @@ static void receive_packfile_uris(struct packet_reader *reader,
1614 while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
1615 if (reader->pktlen < the_hash_algo->hexsz ||
1616 reader->line[the_hash_algo->hexsz] != ' ')
1617 - die("expected '<hash> <uri>', got: %s\n", reader->line);
1617 + die("expected '<hash> <uri>', got: %s", reader->line);
1618
1619 string_list_append(uris, reader->line);
1620 }
loose.c
+2 -2
@@ -162,7 +162,7 @@ int repo_write_loose_object_map(struct repository *repo)
162 errout:
163 rollback_lock_file(&lock);
164 strbuf_release(&buf);
165 - error_errno(_("failed to write loose object index %s\n"), path.buf);
165 + error_errno(_("failed to write loose object index %s"), path.buf);
166 strbuf_release(&path);
167 return -1;
168 }
@@ -197,7 +197,7 @@ static int write_one_object(struct repository *repo, const struct object_id *oid
197 strbuf_release(&path);
198 return 0;
199 errout:
200 - error_errno(_("failed to write loose object index %s\n"), path.buf);
200 + error_errno(_("failed to write loose object index %s"), path.buf);
201 close(fd);
202 rollback_lock_file(&lock);
203 strbuf_release(&buf);
negotiator/skipping.c
+1 -1
@@ -239,7 +239,7 @@ static int ack(struct fetch_negotiator *n, struct commit *c)
239 {
240 int known_to_be_common = !!(c->object.flags & COMMON);
241 if (!(c->object.flags & SEEN))
242 - die("received ack for commit %s not sent as 'have'\n",
242 + die("received ack for commit %s not sent as 'have'",
243 oid_to_hex(&c->object.oid));
244 mark_common(n->data, c);
245 return known_to_be_common;
send-pack.c
+1 -1
@@ -626,7 +626,7 @@ int send_pack(struct send_pack_args *args,
626 strbuf_release(&req_buf);
627 strbuf_release(&cap_buf);
628 reject_atomic_push(remote_refs, args->send_mirror);
629 - error("atomic push failed for ref %s. status: %d\n",
629 + error("atomic push failed for ref %s. status: %d",
630 ref->name, ref->status);
631 return args->porcelain ? 0 : -1;
632 }
serve.c
+1 -1
@@ -323,7 +323,7 @@ static int process_request(void)
323 die("no command requested");
324
325 if (client_hash_algo != hash_algo_by_ptr(the_repository->hash_algo))
326 - die("mismatched object format: server %s; client %s\n",
326 + die("mismatched object format: server %s; client %s",
327 the_repository->hash_algo->name,
328 hash_algos[client_hash_algo].name);
329
t/helper/test-path-utils.c
+3 -3
@@ -38,7 +38,7 @@ static void normalize_argv_string(const char **var, const char *input)
38 *var = input;
39
40 if (*var && (**var == '<' || **var == '('))
41 - die("Bad value: %s\n", input);
41 + die("Bad value: %s", input);
42 }
43
44 struct test_data {
@@ -78,12 +78,12 @@ static int test_function(struct test_data *data, char *(*func)(char *input),
78 if (!strcmp(to, data[i].to))
79 continue;
80 if (!data[i].alternative)
81 - error("FAIL: %s(%s) => '%s' != '%s'\n",
81 + error("FAIL: %s(%s) => '%s' != '%s'",
82 funcname, data[i].from, to, data[i].to);
83 else if (!strcmp(to, data[i].alternative))
84 continue;
85 else
86 - error("FAIL: %s(%s) => '%s' != '%s', '%s'\n",
86 + error("FAIL: %s(%s) => '%s' != '%s', '%s'",
87 funcname, data[i].from, to, data[i].to,
88 data[i].alternative);
89 failed = 1;
t/helper/test-progress.c
+5 -5
@@ -62,13 +62,13 @@ int cmd__progress(int argc, const char **argv)
62 else if (*end == ' ')
63 title = string_list_insert(&titles, end + 1)->string;
64 else
65 - die("invalid input: '%s'\n", line.buf);
65 + die("invalid input: '%s'", line.buf);
66
67 progress = start_progress(title, total);
68 } else if (skip_prefix(line.buf, "progress ", (const char **) &end)) {
69 uint64_t item_count = strtoull(end, &end, 10);
70 if (*end != '\0')
71 - die("invalid input: '%s'\n", line.buf);
71 + die("invalid input: '%s'", line.buf);
72 display_progress(progress, item_count);
73 } else if (skip_prefix(line.buf, "throughput ",
74 (const char **) &end)) {
@@ -76,10 +76,10 @@ int cmd__progress(int argc, const char **argv)
76
77 byte_count = strtoull(end, &end, 10);
78 if (*end != ' ')
79 - die("invalid input: '%s'\n", line.buf);
79 + die("invalid input: '%s'", line.buf);
80 test_ms = strtoull(end + 1, &end, 10);
81 if (*end != '\0')
82 - die("invalid input: '%s'\n", line.buf);
82 + die("invalid input: '%s'", line.buf);
83 progress_test_ns = test_ms * 1000 * 1000;
84 display_throughput(progress, byte_count);
85 } else if (!strcmp(line.buf, "update")) {
@@ -87,7 +87,7 @@ int cmd__progress(int argc, const char **argv)
87 } else if (!strcmp(line.buf, "stop")) {
88 stop_progress(&progress);
89 } else {
90 - die("invalid input: '%s'\n", line.buf);
90 + die("invalid input: '%s'", line.buf);
91 }
92 }
93 strbuf_release(&line);
t/helper/test-reach.c
+2 -2
@@ -67,13 +67,13 @@ int cmd__reach(int ac, const char **av)
67 peeled = deref_tag_noverify(the_repository, orig);
68
69 if (!peeled)
70 - die("failed to load commit for input %s resulting in oid %s\n",
70 + die("failed to load commit for input %s resulting in oid %s",
71 buf.buf, oid_to_hex(&oid));
72
73 c = object_as_type(peeled, OBJ_COMMIT, 0);
74
75 if (!c)
76 - die("failed to load commit for input %s resulting in oid %s\n",
76 + die("failed to load commit for input %s resulting in oid %s",
77 buf.buf, oid_to_hex(&oid));
78
79 switch (buf.buf[0]) {