Merge branch 'nd/worktree-various-heads'
The experimental "multiple worktree" feature gains more safety to forbid operations on a branch that is checked out or being actively worked on elsewhere, by noticing that e.g. it is being rebased. * nd/worktree-various-heads: branch: do not rename a branch under bisect or rebase worktree.c: check whether branch is bisected in another worktree wt-status.c: split bisect detection out of wt_status_get_state() worktree.c: check whether branch is rebased in another worktree worktree.c: avoid referencing to worktrees[i] multiple times wt-status.c: make wt_status_check_rebase() work on any worktree wt-status.c: split rebase detection out of wt_status_get_state() path.c: refactor and add worktree_git_path() worktree.c: mark current worktree worktree.c: make find_shared_symref() return struct worktree * worktree.c: store "id" instead of "git_dir" path.c: add git_common_path() and strbuf_git_common_path() dir.c: rename str(n)cmp_icase to fspath(n)cmp
This commit is contained in:
53
path.c
53
path.c
@ -5,6 +5,7 @@
|
||||
#include "strbuf.h"
|
||||
#include "string-list.h"
|
||||
#include "dir.h"
|
||||
#include "worktree.h"
|
||||
|
||||
static int get_st_mode_bits(const char *path, int *mode)
|
||||
{
|
||||
@ -383,10 +384,11 @@ static void adjust_git_path(struct strbuf *buf, int git_dir_len)
|
||||
update_common_dir(buf, git_dir_len, NULL);
|
||||
}
|
||||
|
||||
static void do_git_path(struct strbuf *buf, const char *fmt, va_list args)
|
||||
static void do_git_path(const struct worktree *wt, struct strbuf *buf,
|
||||
const char *fmt, va_list args)
|
||||
{
|
||||
int gitdir_len;
|
||||
strbuf_addstr(buf, get_git_dir());
|
||||
strbuf_addstr(buf, get_worktree_git_dir(wt));
|
||||
if (buf->len && !is_dir_sep(buf->buf[buf->len - 1]))
|
||||
strbuf_addch(buf, '/');
|
||||
gitdir_len = buf->len;
|
||||
@ -400,7 +402,7 @@ char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
|
||||
va_list args;
|
||||
strbuf_reset(buf);
|
||||
va_start(args, fmt);
|
||||
do_git_path(buf, fmt, args);
|
||||
do_git_path(NULL, buf, fmt, args);
|
||||
va_end(args);
|
||||
return buf->buf;
|
||||
}
|
||||
@ -409,7 +411,7 @@ void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
do_git_path(sb, fmt, args);
|
||||
do_git_path(NULL, sb, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
@ -418,7 +420,7 @@ const char *git_path(const char *fmt, ...)
|
||||
struct strbuf *pathname = get_pathname();
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
do_git_path(pathname, fmt, args);
|
||||
do_git_path(NULL, pathname, fmt, args);
|
||||
va_end(args);
|
||||
return pathname->buf;
|
||||
}
|
||||
@ -428,7 +430,7 @@ char *git_pathdup(const char *fmt, ...)
|
||||
struct strbuf path = STRBUF_INIT;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
do_git_path(&path, fmt, args);
|
||||
do_git_path(NULL, &path, fmt, args);
|
||||
va_end(args);
|
||||
return strbuf_detach(&path, NULL);
|
||||
}
|
||||
@ -454,6 +456,16 @@ const char *mkpath(const char *fmt, ...)
|
||||
return cleanup_path(pathname->buf);
|
||||
}
|
||||
|
||||
const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...)
|
||||
{
|
||||
struct strbuf *pathname = get_pathname();
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
do_git_path(wt, pathname, fmt, args);
|
||||
va_end(args);
|
||||
return pathname->buf;
|
||||
}
|
||||
|
||||
static void do_submodule_path(struct strbuf *buf, const char *path,
|
||||
const char *fmt, va_list args)
|
||||
{
|
||||
@ -503,6 +515,35 @@ void strbuf_git_path_submodule(struct strbuf *buf, const char *path,
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static void do_git_common_path(struct strbuf *buf,
|
||||
const char *fmt,
|
||||
va_list args)
|
||||
{
|
||||
strbuf_addstr(buf, get_git_common_dir());
|
||||
if (buf->len && !is_dir_sep(buf->buf[buf->len - 1]))
|
||||
strbuf_addch(buf, '/');
|
||||
strbuf_vaddf(buf, fmt, args);
|
||||
strbuf_cleanup_path(buf);
|
||||
}
|
||||
|
||||
const char *git_common_path(const char *fmt, ...)
|
||||
{
|
||||
struct strbuf *pathname = get_pathname();
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
do_git_common_path(pathname, fmt, args);
|
||||
va_end(args);
|
||||
return pathname->buf;
|
||||
}
|
||||
|
||||
void strbuf_git_common_path(struct strbuf *sb, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
do_git_common_path(sb, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
int validate_headref(const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
Reference in New Issue
Block a user