OSDN Git Service

Merge branch 'nd/worktree-kill-parse-ref'
[git-core/git.git] / worktree.c
index 7bc36f4..c0c5a2b 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "repository.h"
 #include "refs.h"
 #include "strbuf.h"
 #include "worktree.h"
@@ -76,7 +77,7 @@ static struct worktree *get_linked_worktree(const char *id)
        if (!id)
                die("Missing linked worktree name");
 
-       strbuf_git_common_path(&path, "worktrees/%s/gitdir", id);
+       strbuf_git_common_path(&path, the_repository, "worktrees/%s/gitdir", id);
        if (strbuf_read_file(&worktree_path, path.buf, 0) <= 0)
                /* invalid gitdir file */
                goto done;
@@ -209,16 +210,19 @@ struct worktree *find_worktree(struct worktree **list,
 {
        struct worktree *wt;
        char *path;
+       char *to_free = NULL;
 
        if ((wt = find_worktree_by_suffix(list, arg)))
                return wt;
 
-       arg = prefix_filename(prefix, strlen(prefix), arg);
+       if (prefix)
+               arg = to_free = prefix_filename(prefix, arg);
        path = real_pathdup(arg, 1);
        for (; *list; list++)
                if (!fspathcmp(path, real_path((*list)->path)))
                        break;
        free(path);
+       free(to_free);
        return *list;
 }
 
@@ -348,6 +352,7 @@ int submodule_uses_worktrees(const char *path)
 
        /* The env would be set for the superproject. */
        get_common_dir_noenv(&sb, submodule_gitdir);
+       free(submodule_gitdir);
 
        /*
         * The check below is only known to be good for repository format
@@ -367,7 +372,6 @@ int submodule_uses_worktrees(const char *path)
        /* See if there is any file inside the worktrees directory. */
        dir = opendir(sb.buf);
        strbuf_release(&sb);
-       free(submodule_gitdir);
 
        if (!dir)
                return 0;