git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/9] fetch: drop unneeded NULL-check for `remote_ref`

From
Patrick Steinhardt <ps@pks.im>
Date
May 17, 2023, 11:48 UTC
Message-ID
<7197540df60d34e8f727e29d300dd0c96e31d310.1684324059.git.ps@pks.im>
In-Reply-To
<cover.1684324059.git.ps@pks.im>

Drop the `NULL` check for `remote_ref` in `update_local_ref()`. The function only has a single caller, and that caller always passes in a non-`NULL` value.

This fixes a false positive in Coverity.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/fetch.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 9147b700e5..f268322e6f 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -953,11 +953,10 @@ static int update_local_ref(struct ref *ref,
 		 * Base this on the remote's ref name, as it's
 		 * more likely to follow a standard layout.
 		 */
-		const char *name = remote_ref ? remote_ref->name : "";
-		if (starts_with(name, "refs/tags/")) {
+		if (starts_with(remote_ref->name, "refs/tags/")) {
 			msg = "storing tag";
 			what = _("[new tag]");
-		} else if (starts_with(name, "refs/heads/")) {
+		} else if (starts_with(remote_ref->name, "refs/heads/")) {
 			msg = "storing head";
 			what = _("[new branch]");
 		} else {
-- 
2.40.1
Previous: Jeff KingNext: Jeff King
Message 4 of 16 in “fetch: smallish cleanups”
  1. 0/9 fetch: smallish cleanupsPatrick Steinhardt, May 17, 2023
  2. 1/9 fetch: drop unused DISPLAY_FORMAT_UNKNOWN enum valuePatrick Steinhardt, May 17, 2023
  3. Jeff KingMay 19, 2023
  4. 2/9 fetch: drop unneeded NULL-check for `remote_ref`Patrick Steinhardt, May 17, 2023
  5. Jeff KingMay 19, 2023
  6. 3/9 fetch: pass through `fetch_config` directlyPatrick Steinhardt, May 17, 2023
  7. Jeff KingMay 19, 2023
  8. Patrick SteinhardtMay 22, 2023
  9. Jeff KingMay 22, 2023
  10. 4/9 fetch: use `fetch_config` to store "fetch.prune" valuePatrick Steinhardt, May 17, 2023
  11. Jeff KingMay 19, 2023
  12. 5/9 fetch: use `fetch_config` to store "fetch.pruneTags" valuePatrick Steinhardt, May 17, 2023
  13. 6/9 fetch: use `fetch_config` to store "fetch.showForcedUpdates" valuePatrick Steinhardt, May 17, 2023
  14. 7/9 fetch: use `fetch_config` to store "fetch.recurseSubmodules" valuePatrick Steinhardt, May 17, 2023
  15. 8/9 fetch: use `fetch_config` to store "fetch.parallel" valuePatrick Steinhardt, May 17, 2023
  16. 9/9 fetch: use `fetch_config` to store "submodule.fetchJobs" valuePatrick Steinhardt, May 17, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.