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

[PATCH] MyFirstObjectWalk: remove unnecessary conditional statement

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 28, 2020, 15:19 UTC
Message-ID
<pull.589.git.1585408753519.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

In the given example, `commit` cannot be `NULL` (because this is the loop condition: if it was `NULL`, the loop body would not be entered at all). It took this developer a moment or two to see that this is therefore dead code.

Let's remove it, to avoid puzzling future readers.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
    MyFirstObjectWalk: remove unnecessary conditional statement
    
    Our introductory documentation made me scratch my head because our
    example contains dead code. I'd like to remove it lest we confuse future
    contributors.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-589%2Fdscho%2Fgit-walken-head-scratcher-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-589/dscho/git-walken-head-scratcher-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/589
 Documentation/MyFirstObjectWalk.txt | 3 ---
 1 file changed, 3 deletions(-)
diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt
index aa828dfdc44..c3f2d1a831e 100644
--- a/Documentation/MyFirstObjectWalk.txt
+++ b/Documentation/MyFirstObjectWalk.txt
@@ -357,9 +357,6 @@ static void walken_commit_walk(struct rev_info *rev)
 	...
 
 	while ((commit = get_revision(rev))) {
-		if (!commit)
-			continue;
-
 		strbuf_reset(&prettybuf);
 		pp_commit_easy(CMIT_FMT_ONELINE, commit, &prettybuf);
 		puts(prettybuf.buf);

base-commit: 3bab5d56259722843359702bc27111475437ad2a
-- 
gitgitgadget
Next: Emily Shaffer
Message 1 of 3 in “MyFirstObjectWalk: remove unnecessary conditional statement”
  1. MyFirstObjectWalk: remove unnecessary conditional statementJohannes Schindelin via GitGitGadget, Mar 28, 2020
  2. Emily ShafferMar 30, 2020
  3. Junio C HamanoMar 30, 2020

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.