worktrees = get_worktrees();
while (worktrees[i]) {
- char *old;
+ char *old, *wt_gitdir;
struct wt_status_state state = { 0 };
struct worktree *wt = worktrees[i++];
struct string_list update_refs = STRING_LIST_INIT_DUP;
}
wt_status_state_free_buffers(&state);
- if (!sequencer_get_update_refs_state(get_worktree_git_dir(wt),
+ wt_gitdir = get_worktree_git_dir(wt);
+ if (!sequencer_get_update_refs_state(wt_gitdir,
&update_refs)) {
struct string_list_item *item;
for_each_string_list_item(item, &update_refs) {
}
string_list_clear(&update_refs, 1);
}
+
+ free(wt_gitdir);
}
free_worktrees(worktrees);
struct worktree *wt = *p;
struct index_state istate =
INDEX_STATE_INIT(the_repository);
- char *path;
+ char *path, *wt_gitdir;
/*
* Make a copy since the buffer is reusable
* while we're examining the index.
*/
path = xstrdup(worktree_git_path(the_repository, wt, "index"));
- read_index_from(&istate, path, get_worktree_git_dir(wt));
+ wt_gitdir = get_worktree_git_dir(wt);
+
+ read_index_from(&istate, path, wt_gitdir);
fsck_index(&istate, path, wt->is_current);
+
discard_index(&istate);
+ free(wt_gitdir);
free(path);
}
free_worktrees(worktrees);
static const char *update_worktree(unsigned char *sha1, const struct worktree *worktree)
{
- const char *retval, *git_dir;
+ const char *retval;
+ char *git_dir;
struct strvec env = STRVEC_INIT;
int invoked_hook;
retval = push_to_deploy(sha1, &env, worktree->path);
strvec_clear(&env);
+ free(git_dir);
return retval;
}
if (!opts->quiet) {
struct strbuf path = STRBUF_INIT;
struct strbuf contents = STRBUF_INIT;
+ char *wt_gitdir = get_worktree_git_dir(NULL);
- strbuf_add_real_path(&path, get_worktree_git_dir(NULL));
+ strbuf_add_real_path(&path, wt_gitdir);
strbuf_addstr(&path, "/HEAD");
strbuf_read_file(&contents, path.buf, 64);
strbuf_stripspace(&contents, NULL);
path.buf, contents.buf);
strbuf_release(&path);
strbuf_release(&contents);
+ free(wt_gitdir);
}
return 1;
}
struct index_state istate = INDEX_STATE_INIT(the_repository);
struct strbuf path = STRBUF_INIT;
int i, found_submodules = 0;
+ char *wt_gitdir;
+
+ wt_gitdir = get_worktree_git_dir(wt);
if (is_directory(worktree_git_path(the_repository, wt, "modules"))) {
/*
*/
found_submodules = 1;
} else if (read_index_from(&istate, worktree_git_path(the_repository, wt, "index"),
- get_worktree_git_dir(wt)) > 0) {
+ wt_gitdir) > 0) {
for (i = 0; i < istate.cache_nr; i++) {
struct cache_entry *ce = istate.cache[i];
int err;
}
discard_index(&istate);
strbuf_release(&path);
+ free(wt_gitdir);
if (found_submodules)
die(_("working trees containing submodules cannot be moved or removed"));
struct worktree **worktrees = get_worktrees();
for (struct worktree **wt = worktrees; *wt; wt++) {
+ char *wt_gitdir = get_worktree_git_dir(*wt);
+
strbuf_reset(&buf);
- strbuf_addstr(&buf, get_worktree_git_dir(*wt));
+ strbuf_addstr(&buf, wt_gitdir);
strbuf_complete(&buf, '/');
len = buf.len;
for (size_t i = 0; i < ARRAY_SIZE(path); i++) {
strbuf_addstr(&buf, path[i]);
add_one_file(buf.buf, revs);
}
+
+ free(wt_gitdir);
}
strbuf_release(&buf);
free_worktrees(worktrees);
for (p = worktrees; *p; p++) {
struct worktree *wt = *p;
struct index_state istate = INDEX_STATE_INIT(revs->repo);
+ char *wt_gitdir;
if (wt->is_current)
continue; /* current index already taken care of */
+ wt_gitdir = get_worktree_git_dir(wt);
+
if (read_index_from(&istate,
worktree_git_path(the_repository, wt, "index"),
- get_worktree_git_dir(wt)) > 0)
+ wt_gitdir) > 0)
do_add_index_objects_to_pending(revs, &istate, flags);
+
discard_index(&istate);
+ free(wt_gitdir);
}
free_worktrees(worktrees);
}
static int is_current_worktree(struct worktree *wt)
{
char *git_dir = absolute_pathdup(repo_get_git_dir(the_repository));
- const char *wt_git_dir = get_worktree_git_dir(wt);
+ char *wt_git_dir = get_worktree_git_dir(wt);
int is_current = !fspathcmp(git_dir, absolute_path(wt_git_dir));
+ free(wt_git_dir);
free(git_dir);
return is_current;
}
return get_worktrees_internal(0);
}
-const char *get_worktree_git_dir(const struct worktree *wt)
+char *get_worktree_git_dir(const struct worktree *wt)
{
if (!wt)
- return repo_get_git_dir(the_repository);
+ return xstrdup(repo_get_git_dir(the_repository));
else if (!wt->id)
- return repo_get_common_dir(the_repository);
+ return xstrdup(repo_get_common_dir(the_repository));
else
- return git_common_path("worktrees/%s", wt->id);
+ return xstrdup(git_common_path("worktrees/%s", wt->id));
}
static struct worktree *find_worktree_by_suffix(struct worktree **list,
* Return git dir of the worktree. Note that the path may be relative.
* If wt is NULL, git dir of current worktree is returned.
*/
-const char *get_worktree_git_dir(const struct worktree *wt);
+char *get_worktree_git_dir(const struct worktree *wt);
/*
* Search for the worktree identified unambiguously by `arg` -- typically