Commit e83c06347d9516d0180594769020b3013a232414

Stefan Sperling 2020-01-27T22:25:59

remove pointless cwd checking from got_repo_map_path()

diff --git a/lib/repository.c b/lib/repository.c
index 694024d..158483e 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -657,15 +657,11 @@ got_repo_map_path(char **in_repo_path, struct got_repository *repo,
 {
 	const struct got_error *err = NULL;
 	const char *repo_abspath = NULL;
-	size_t repolen, cwdlen, len;
-	char *cwd, *canonpath, *path = NULL;
+	size_t repolen, len;
+	char *canonpath, *path = NULL;
 
 	*in_repo_path = NULL;
 
-	cwd = getcwd(NULL, 0);
-	if (cwd == NULL)
-		return got_error_from_errno("getcwd");
-
 	canonpath = strdup(input_path);
 	if (canonpath == NULL) {
 		err = got_error_from_errno("strdup");
@@ -684,7 +680,7 @@ got_repo_map_path(char **in_repo_path, struct got_repository *repo,
 			goto done;
 		}
 	} else {
-		int is_repo_child = 0, is_cwd_child = 0;
+		int is_repo_child = 0;
 
 		path = realpath(canonpath, NULL);
 		if (path == NULL) {
@@ -705,13 +701,10 @@ got_repo_map_path(char **in_repo_path, struct got_repository *repo,
 		}
 
 		repolen = strlen(repo_abspath);
-		cwdlen = strlen(cwd);
 		len = strlen(path);
 
 		if (len > repolen && strncmp(path, repo_abspath, repolen) == 0)
 			is_repo_child = 1;
-		if (len > cwdlen && strncmp(path, cwd, cwdlen) == 0)
-			is_cwd_child = 1;
 
 		if (strcmp(path, repo_abspath) == 0) {
 			free(path);
@@ -720,15 +713,6 @@ got_repo_map_path(char **in_repo_path, struct got_repository *repo,
 				err = got_error_from_errno("strdup");
 				goto done;
 			}
-		} else if (is_repo_child && is_cwd_child) {
-			char *child;
-			/* Strip common prefix with repository path. */
-			err = got_path_skip_common_ancestor(&child,
-			    repo_abspath, path);
-			if (err)
-				goto done;
-			free(path);
-			path = child;
 		} else if (is_repo_child) {
 			/* Matched an on-disk path inside repository. */
 			if (got_repo_is_bare(repo)) {
@@ -746,15 +730,6 @@ got_repo_map_path(char **in_repo_path, struct got_repository *repo,
 				free(path);
 				path = child;
 			}
-		} else if (is_cwd_child) {
-			char *child;
-			/* Strip common prefix with cwd. */
-			err = got_path_skip_common_ancestor(&child, cwd,
-			    path);
-			if (err)
-				goto done;
-			free(path);
-			path = child;
 		} else {
 			/*
 			 * Matched unrelated on-disk path.
@@ -775,7 +750,6 @@ got_repo_map_path(char **in_repo_path, struct got_repository *repo,
 	}
 
 done:
-	free(cwd);
 	free(canonpath);
 	if (err)
 		free(path);