test-lib: introduce test_commit_bulk
[gitweb.git] / worktree.c
index 125eeb2d7c27b576f01614c87fe1cdc123cb151b..5b4793caa34e3ab981268662efdc1d840ac53390 100644 (file)
@@ -228,9 +228,12 @@ struct worktree *find_worktree(struct worktree **list,
                free(to_free);
                return NULL;
        }
-       for (; *list; list++)
-               if (!fspathcmp(path, real_path((*list)->path)))
+       for (; *list; list++) {
+               const char *wt_path = real_path_if_valid((*list)->path);
+
+               if (wt_path && !fspathcmp(path, wt_path))
                        break;
+       }
        free(path);
        free(to_free);
        return *list;
@@ -450,7 +453,7 @@ int submodule_uses_worktrees(const char *path)
        DIR *dir;
        struct dirent *d;
        int ret = 0;
-       struct repository_format format;
+       struct repository_format format = REPOSITORY_FORMAT_INIT;
 
        submodule_gitdir = git_pathdup_submodule(path, "%s", "");
        if (!submodule_gitdir)
@@ -468,8 +471,10 @@ int submodule_uses_worktrees(const char *path)
        read_repository_format(&format, sb.buf);
        if (format.version != 0) {
                strbuf_release(&sb);
+               clear_repository_format(&format);
                return 1;
        }
+       clear_repository_format(&format);
 
        /* Replace config by worktrees. */
        strbuf_setlen(&sb, sb.len - strlen("config"));