Subject: [PATCH 3/3] tests: avoid unnecessary use of GIT_TRACE in repo-setup tests

From: Jonathan Nieder <[email-masked]>
Date: Tue, 25 Jan 2011 19:01:47 -0600

Now that the startup info is printed by a separate helper, there
is no need to mark that output with "setup: " or use an environment
variable to request it.

While we're changing the test-repo-setup output format, stop quoting
newlines to give the tests a chance of passing when $TEST_DIRECTORY
contains a newline or backslash.

Signed-off-by: Jonathan Nieder <[email-masked]>
---
Thanks for reading.

 t/t1510-repo-setup.sh |   12 +++++-------
 test-repo-setup.c     |   40 ++++++----------------------------------
 2 files changed, 11 insertions(+), 41 deletions(-)

diff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh
index c2edf6f..a8cb445 100755
--- a/t/t1510-repo-setup.sh
+++ b/t/t1510-repo-setup.sh
@@ -56,9 +56,7 @@ test_repo () {
 			GIT_WORK_TREE="$3" &&
 			export GIT_WORK_TREE
 		fi &&
-		rm -f trace &&
-		GIT_TRACE="$(pwd)/trace" test-repo-setup &&
-		grep '^setup: ' trace >result &&
+		test-repo-setup >result &&
 		test_cmp expected result
 	)
 }
@@ -105,10 +103,10 @@ setup_env () {
 
 expect () {
 	cat >"$1/expected" <<-EOF
-	setup: git_dir: $2
-	setup: worktree: $3
-	setup: cwd: $4
-	setup: prefix: $5
+	git_dir: $2
+	worktree: $3
+	cwd: $4
+	prefix: $5
 	EOF
 }
 
diff --git a/test-repo-setup.c b/test-repo-setup.c
index 3b66237..72d35fe 100644
--- a/test-repo-setup.c
+++ b/test-repo-setup.c
@@ -1,52 +1,24 @@
 #include "cache.h"
 
-static const char *quote_crnl(const char *path)
-{
-	static char new_path[PATH_MAX];
-	const char *p2 = path;
-	char *p1 = new_path;
-
-	if (!path)
-		return NULL;
-
-	while (*p2) {
-		switch (*p2) {
-		case '\\': *p1++ = '\\'; *p1++ = '\\'; break;
-		case '\n': *p1++ = '\\'; *p1++ = 'n'; break;
-		case '\r': *p1++ = '\\'; *p1++ = 'r'; break;
-		default:
-			*p1++ = *p2;
-		}
-		p2++;
-	}
-	*p1 = '\0';
-	return new_path;
-}
-
 static void trace_repo_setup(void)
 {
-	const char *git_work_tree;
+	const char *git_work_tree = get_git_work_tree();
 	const char *prefix = startup_info->prefix;
 	char cwd[PATH_MAX];
-	char *trace = getenv("GIT_TRACE");
-
-	if (!trace || !strcmp(trace, "") ||
-	    !strcmp(trace, "0") || !strcasecmp(trace, "false"))
-		return;
 
 	if (!getcwd(cwd, PATH_MAX))
 		die("Unable to get current working directory");
 
-	if (!(git_work_tree = get_git_work_tree()))
+	if (!git_work_tree)
 		git_work_tree = "(null)";
 
 	if (!prefix)
 		prefix = "(null)";
 
-	trace_printf("setup: git_dir: %s\n", quote_crnl(get_git_dir()));
-	trace_printf("setup: worktree: %s\n", quote_crnl(git_work_tree));
-	trace_printf("setup: cwd: %s\n", quote_crnl(cwd));
-	trace_printf("setup: prefix: %s\n", quote_crnl(prefix));
+	printf("git_dir: %s\n", get_git_dir());
+	printf("worktree: %s\n", git_work_tree);
+	printf("cwd: %s\n", cwd);
+	printf("prefix: %s\n", prefix);
 }
 
 int main(int argc, char **argv)
-- 
1.7.4.rc3