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

[PATCH 4/4] contrib/diffall: eliminate duplicate while loops

From
Tim Henigan <tim.henigan@gmail.com>
Date
Mar 13, 2012, 17:45 UTC
Message-ID
<1331660734-10538-4-git-send-email-tim.henigan@gmail.com>
In-Reply-To
<1331660734-10538-1-git-send-email-tim.henigan@gmail.com>

There were 3 instances of a 'while read; do' that used identical logic to populate '/tmp/right_dir'. This commit groups them into a single loop.

Signed-off-by: Tim Henigan <tim.henigan@gmail.com>
---
 contrib/diffall/git-diffall |   24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/contrib/diffall/git-diffall b/contrib/diffall/git-diffall
index 8d243c7..b1afefe 100755
--- a/contrib/diffall/git-diffall
+++ b/contrib/diffall/git-diffall
@@ -179,38 +179,32 @@ fi
 mkdir -p "$tmp/$left_dir" "$tmp/$right_dir"
 
 # Populate the tmp/right_dir directory with the files to be compared
-if test -n "$right"
-then
-	while read name
-	do
+while read name
+do
+	if test -n "$right"
+	then
 		ls_list=$(git ls-tree $right "$name")
 		if test -n "$ls_list"
 		then
 			mkdir -p "$tmp/$right_dir/$(dirname "$name")"
 			git show "$right":"$name" >"$tmp/$right_dir/$name" || true
 		fi
-	done < "$tmp/filelist"
-elif test -n "$compare_staged"
-then
-	while read name
-	do
+	elif test -n "$compare_staged"
+	then
 		ls_list=$(git ls-files -- "$name")
 		if test -n "$ls_list"
 		then
 			mkdir -p "$tmp/$right_dir/$(dirname "$name")"
 			git show :"$name" >"$tmp/$right_dir/$name"
 		fi
-	done < "$tmp/filelist"
-else
-	while read name
-	do
+	else
 		if test -e "$name"
 		then
 			mkdir -p "$tmp/$right_dir/$(dirname "$name")"
 			cp "$name" "$tmp/$right_dir"
 		fi
-	done < "$tmp/filelist"
-fi
+	fi
+done < "$tmp/filelist"
 
 # Populate the tmp/left_dir directory with the files to be compared
 while read name
-- 
1.7.10.rc0
Previous: Tim HeniganNext: Tim Henigan
Message 4 of 5 in “contrib/diffall: change comment to reflect actual reason for 'cdup'”
  1. 1/4 contrib/diffall: change comment to reflect actual reason for 'cdup'Tim Henigan, Mar 13, 2012
  2. 2/4 contrib/diffall: teach diffall to create tmp dirs without using mktempTim Henigan, Mar 13, 2012
  3. 3/4 contrib/diffall: teach diffall to handle working copy changes without tarTim Henigan, Mar 13, 2012
  4. 4/4 contrib/diffall: eliminate duplicate while loopsTim Henigan, Mar 13, 2012
  5. Tim HeniganMar 13, 2012

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.