Skip to contentSkip to conversation

MyFirstObjectWalk: remove unnecessary conditional statement

PATCH In review Johannes Schindelin via GitGitGadget 3 participants 3 messages Mar 28, 2020 – Mar 30, 2020 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MyFirstObjectWalk: remove unnecessary conditional statement

From: Johannes Schindelin <[email protected]>

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.

---
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(-)
Documentation/MyFirstObjectWalk.txt +0 -3
index aa828dfdc44..c3f2d1a831e 100644
@@ -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

Signature · 1 line
gitgitgadget
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Johannes Schindelin via GitGitGadget

From: Johannes Schindelin <[email protected]>

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.

Nice catch. Thanks.

Quoted 4 lines

Let's remove it, to avoid puzzling future readers.

Quoted 32 lines

---
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(-)
Documentation/MyFirstObjectWalk.txt +0 -3
index aa828dfdc44..c3f2d1a831e 100644
@@ -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

Signature · 1 line
gitgitgadget
#2 lore raw
Quoted 8 lines · Emily Shaffer
Quoted 6 lines · Johannes Schindelin via GitGitGadget

From: Johannes Schindelin <[email protected]>

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.

Quoted 8 lines

Nice catch. Thanks.

Quoted 4 lines

Let's remove it, to avoid puzzling future readers.

Thanks, both.