Blame worktree.h

Packit 4511e4
#ifndef WORKTREE_H
Packit 4511e4
#define WORKTREE_H
Packit 4511e4
Packit 4511e4
#include "refs.h"
Packit 4511e4
Packit 4511e4
struct strbuf;
Packit 4511e4
Packit 4511e4
struct worktree {
Packit 4511e4
	char *path;
Packit 4511e4
	char *id;
Packit 4511e4
	char *head_ref;		/* NULL if HEAD is broken or detached */
Packit 4511e4
	char *lock_reason;	/* internal use */
Packit 4511e4
	struct object_id head_oid;
Packit 4511e4
	int is_detached;
Packit 4511e4
	int is_bare;
Packit 4511e4
	int is_current;
Packit 4511e4
	int lock_reason_valid;
Packit 4511e4
};
Packit 4511e4
Packit 4511e4
/* Functions for acting on the information about worktrees. */
Packit 4511e4
Packit 4511e4
#define GWT_SORT_LINKED (1 << 0) /* keeps linked worktrees sorted */
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * Get the worktrees.  The primary worktree will always be the first returned,
Packit 4511e4
 * and linked worktrees will be pointed to by 'next' in each subsequent
Packit 4511e4
 * worktree.  No specific ordering is done on the linked worktrees.
Packit 4511e4
 *
Packit 4511e4
 * The caller is responsible for freeing the memory from the returned
Packit 4511e4
 * worktree(s).
Packit 4511e4
 */
Packit 4511e4
extern struct worktree **get_worktrees(unsigned flags);
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * Returns 1 if linked worktrees exist, 0 otherwise.
Packit 4511e4
 */
Packit 4511e4
extern int submodule_uses_worktrees(const char *path);
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * Return git dir of the worktree. Note that the path may be relative.
Packit 4511e4
 * If wt is NULL, git dir of current worktree is returned.
Packit 4511e4
 */
Packit 4511e4
extern const char *get_worktree_git_dir(const struct worktree *wt);
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * Search a worktree that can be unambiguously identified by
Packit 4511e4
 * "arg". "prefix" must not be NULL.
Packit 4511e4
 */
Packit 4511e4
extern struct worktree *find_worktree(struct worktree **list,
Packit 4511e4
				      const char *prefix,
Packit 4511e4
				      const char *arg);
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * Return true if the given worktree is the main one.
Packit 4511e4
 */
Packit 4511e4
extern int is_main_worktree(const struct worktree *wt);
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * Return the reason string if the given worktree is locked or NULL
Packit 4511e4
 * otherwise.
Packit 4511e4
 */
Packit 4511e4
extern const char *is_worktree_locked(struct worktree *wt);
Packit 4511e4
Packit 4511e4
#define WT_VALIDATE_WORKTREE_MISSING_OK (1 << 0)
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * Return zero if the worktree is in good condition. Error message is
Packit 4511e4
 * returned if "errmsg" is not NULL.
Packit 4511e4
 */
Packit 4511e4
extern int validate_worktree(const struct worktree *wt,
Packit 4511e4
			     struct strbuf *errmsg,
Packit 4511e4
			     unsigned flags);
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * Update worktrees/xxx/gitdir with the new path.
Packit 4511e4
 */
Packit 4511e4
extern void update_worktree_location(struct worktree *wt,
Packit 4511e4
				     const char *path_);
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * Free up the memory for worktree(s)
Packit 4511e4
 */
Packit 4511e4
extern void free_worktrees(struct worktree **);
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * Check if a per-worktree symref points to a ref in the main worktree
Packit 4511e4
 * or any linked worktree, and return the worktree that holds the ref,
Packit 4511e4
 * or NULL otherwise. The result may be destroyed by the next call.
Packit 4511e4
 */
Packit 4511e4
extern const struct worktree *find_shared_symref(const char *symref,
Packit 4511e4
						 const char *target);
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * Similar to head_ref() for all HEADs _except_ one from the current
Packit 4511e4
 * worktree, which is covered by head_ref().
Packit 4511e4
 */
Packit 4511e4
int other_head_refs(each_ref_fn fn, void *cb_data);
Packit 4511e4
Packit 4511e4
int is_worktree_being_rebased(const struct worktree *wt, const char *target);
Packit 4511e4
int is_worktree_being_bisected(const struct worktree *wt, const char *target);
Packit 4511e4
Packit 4511e4
/*
Packit 4511e4
 * Similar to git_path() but can produce paths for a specified
Packit 4511e4
 * worktree instead of current one
Packit 4511e4
 */
Packit 4511e4
extern const char *worktree_git_path(const struct worktree *wt,
Packit 4511e4
				     const char *fmt, ...)
Packit 4511e4
	__attribute__((format (printf, 2, 3)));
Packit 4511e4
Packit 4511e4
#endif