2015-10-02 13:55:31 +02:00
|
|
|
#ifndef WORKTREE_H
|
|
|
|
#define WORKTREE_H
|
|
|
|
|
2018-08-15 19:54:05 +02:00
|
|
|
#include "cache.h"
|
2017-08-23 14:36:59 +02:00
|
|
|
#include "refs.h"
|
|
|
|
|
2018-01-24 10:53:51 +01:00
|
|
|
struct strbuf;
|
|
|
|
|
2015-10-08 19:01:03 +02:00
|
|
|
struct worktree {
|
|
|
|
char *path;
|
2016-04-22 15:01:26 +02:00
|
|
|
char *id;
|
2017-04-24 12:01:23 +02:00
|
|
|
char *head_ref; /* NULL if HEAD is broken or detached */
|
2018-10-30 07:24:09 +01:00
|
|
|
char *lock_reason; /* private - use worktree_lock_reason */
|
2017-10-16 00:07:08 +02:00
|
|
|
struct object_id head_oid;
|
2015-10-08 19:01:04 +02:00
|
|
|
int is_detached;
|
|
|
|
int is_bare;
|
2016-04-22 15:01:28 +02:00
|
|
|
int is_current;
|
2018-10-30 07:24:08 +01:00
|
|
|
int lock_reason_valid; /* private */
|
2015-10-08 19:01:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Functions for acting on the information about worktrees. */
|
|
|
|
|
2016-11-28 10:36:56 +01:00
|
|
|
#define GWT_SORT_LINKED (1 << 0) /* keeps linked worktrees sorted */
|
|
|
|
|
2015-10-08 19:01:03 +02:00
|
|
|
/*
|
|
|
|
* Get the worktrees. The primary worktree will always be the first returned,
|
|
|
|
* and linked worktrees will be pointed to by 'next' in each subsequent
|
|
|
|
* worktree. No specific ordering is done on the linked worktrees.
|
|
|
|
*
|
|
|
|
* The caller is responsible for freeing the memory from the returned
|
|
|
|
* worktree(s).
|
|
|
|
*/
|
2019-04-29 10:28:14 +02:00
|
|
|
struct worktree **get_worktrees(unsigned flags);
|
2015-10-08 19:01:03 +02:00
|
|
|
|
2016-12-12 20:04:33 +01:00
|
|
|
/*
|
|
|
|
* Returns 1 if linked worktrees exist, 0 otherwise.
|
|
|
|
*/
|
2019-04-29 10:28:14 +02:00
|
|
|
int submodule_uses_worktrees(const char *path);
|
2016-12-12 20:04:33 +01:00
|
|
|
|
2016-04-22 15:01:26 +02:00
|
|
|
/*
|
|
|
|
* Return git dir of the worktree. Note that the path may be relative.
|
|
|
|
* If wt is NULL, git dir of current worktree is returned.
|
|
|
|
*/
|
2019-04-29 10:28:14 +02:00
|
|
|
const char *get_worktree_git_dir(const struct worktree *wt);
|
2016-04-22 15:01:26 +02:00
|
|
|
|
2016-06-03 14:19:39 +02:00
|
|
|
/*
|
|
|
|
* Search a worktree that can be unambiguously identified by
|
|
|
|
* "arg". "prefix" must not be NULL.
|
|
|
|
*/
|
2019-04-29 10:28:14 +02:00
|
|
|
struct worktree *find_worktree(struct worktree **list,
|
2019-04-29 10:28:23 +02:00
|
|
|
const char *prefix,
|
|
|
|
const char *arg);
|
2016-06-03 14:19:39 +02:00
|
|
|
|
2016-06-03 14:19:40 +02:00
|
|
|
/*
|
|
|
|
* Return true if the given worktree is the main one.
|
|
|
|
*/
|
2019-04-29 10:28:14 +02:00
|
|
|
int is_main_worktree(const struct worktree *wt);
|
2016-06-03 14:19:40 +02:00
|
|
|
|
2016-06-13 14:18:23 +02:00
|
|
|
/*
|
|
|
|
* Return the reason string if the given worktree is locked or NULL
|
|
|
|
* otherwise.
|
|
|
|
*/
|
2019-04-29 10:28:14 +02:00
|
|
|
const char *worktree_lock_reason(struct worktree *wt);
|
2016-06-13 14:18:23 +02:00
|
|
|
|
2018-02-12 10:49:40 +01:00
|
|
|
#define WT_VALIDATE_WORKTREE_MISSING_OK (1 << 0)
|
|
|
|
|
2018-01-24 10:53:51 +01:00
|
|
|
/*
|
|
|
|
* Return zero if the worktree is in good condition. Error message is
|
|
|
|
* returned if "errmsg" is not NULL.
|
|
|
|
*/
|
2019-04-29 10:28:14 +02:00
|
|
|
int validate_worktree(const struct worktree *wt,
|
2019-04-29 10:28:23 +02:00
|
|
|
struct strbuf *errmsg,
|
|
|
|
unsigned flags);
|
2018-01-24 10:53:51 +01:00
|
|
|
|
2018-02-12 10:49:35 +01:00
|
|
|
/*
|
|
|
|
* Update worktrees/xxx/gitdir with the new path.
|
|
|
|
*/
|
2019-04-29 10:28:14 +02:00
|
|
|
void update_worktree_location(struct worktree *wt,
|
2019-04-29 10:28:23 +02:00
|
|
|
const char *path_);
|
2018-02-12 10:49:35 +01:00
|
|
|
|
2015-10-08 19:01:03 +02:00
|
|
|
/*
|
|
|
|
* Free up the memory for worktree(s)
|
|
|
|
*/
|
2019-04-29 10:28:14 +02:00
|
|
|
void free_worktrees(struct worktree **);
|
2015-10-08 19:01:03 +02:00
|
|
|
|
2015-10-02 13:55:31 +02:00
|
|
|
/*
|
|
|
|
* Check if a per-worktree symref points to a ref in the main worktree
|
2016-04-22 15:01:27 +02:00
|
|
|
* or any linked worktree, and return the worktree that holds the ref,
|
|
|
|
* or NULL otherwise. The result may be destroyed by the next call.
|
2015-10-02 13:55:31 +02:00
|
|
|
*/
|
2019-04-29 10:28:14 +02:00
|
|
|
const struct worktree *find_shared_symref(const char *symref,
|
2019-04-29 10:28:23 +02:00
|
|
|
const char *target);
|
2015-10-02 13:55:31 +02:00
|
|
|
|
2017-08-23 14:36:59 +02:00
|
|
|
/*
|
|
|
|
* Similar to head_ref() for all HEADs _except_ one from the current
|
|
|
|
* worktree, which is covered by head_ref().
|
|
|
|
*/
|
|
|
|
int other_head_refs(each_ref_fn fn, void *cb_data);
|
|
|
|
|
2016-04-22 15:01:36 +02:00
|
|
|
int is_worktree_being_rebased(const struct worktree *wt, const char *target);
|
|
|
|
int is_worktree_being_bisected(const struct worktree *wt, const char *target);
|
|
|
|
|
2016-04-22 15:01:29 +02:00
|
|
|
/*
|
|
|
|
* Similar to git_path() but can produce paths for a specified
|
|
|
|
* worktree instead of current one
|
|
|
|
*/
|
2019-04-29 10:28:20 +02:00
|
|
|
const char *worktree_git_path(const struct worktree *wt,
|
2019-04-29 10:28:23 +02:00
|
|
|
const char *fmt, ...)
|
2016-04-22 15:01:29 +02:00
|
|
|
__attribute__((format (printf, 2, 3)));
|
|
|
|
|
2018-10-21 10:08:54 +02:00
|
|
|
/*
|
|
|
|
* Parse a worktree ref (i.e. with prefix main-worktree/ or
|
|
|
|
* worktrees/) and return the position of the worktree's name and
|
|
|
|
* length (or NULL and zero if it's main worktree), and ref.
|
|
|
|
*
|
|
|
|
* All name, name_length and ref arguments could be NULL.
|
|
|
|
*/
|
|
|
|
int parse_worktree_ref(const char *worktree_ref, const char **name,
|
|
|
|
int *name_length, const char **ref);
|
2018-10-21 10:08:56 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a refname suitable for access from the current ref store.
|
|
|
|
*/
|
|
|
|
void strbuf_worktree_ref(const struct worktree *wt,
|
|
|
|
struct strbuf *sb,
|
|
|
|
const char *refname);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a refname suitable for access from the current ref
|
|
|
|
* store. The result will be destroyed at the next call.
|
|
|
|
*/
|
|
|
|
const char *worktree_ref(const struct worktree *wt,
|
|
|
|
const char *refname);
|
|
|
|
|
2015-10-02 13:55:31 +02:00
|
|
|
#endif
|