Commit 0f63689de68526464ea93d1dc72ca49f138cdf39

Stefan Sperling 2019-05-10T18:20:01

remove unnecessary allocation in match_ct_parent_path()

diff --git a/lib/worktree.c b/lib/worktree.c
index 555a850..934b269 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -2353,15 +2353,13 @@ match_ct_parent_path(int *match, struct commitable *ct, const char *path)
 	*match = 0;
 
 	if (strchr(ct->path, '/') == NULL) {
-		ct_parent_path = strdup("/");
-		if (ct_parent_path == NULL)
-			return got_error_from_errno();
-	} else {
-		err = got_path_dirname(&ct_parent_path, ct->path);
-		if (err)
-			return err;
+		*match = got_path_is_root_dir(path);
+		return NULL;
 	}
 
+	err = got_path_dirname(&ct_parent_path, ct->path);
+	if (err)
+		return err;
 	*match = (strcmp(path, ct_parent_path) == 0);
 	free(ct_parent_path);
 	return err;