2015-10-02 14:55:31 +03:00
|
|
|
#ifndef WORKTREE_H
|
|
|
|
#define WORKTREE_H
|
|
|
|
|
2017-08-23 15:36:59 +03:00
|
|
|
#include "refs.h"
|
|
|
|
|
2015-10-08 20:01:03 +03:00
|
|
|
struct worktree {
|
|
|
|
char *path;
|
2016-04-22 16:01:26 +03:00
|
|
|
char *id;
|
2017-04-24 13:01:23 +03:00
|
|
|
char *head_ref; /* NULL if HEAD is broken or detached */
|
2016-06-13 15:18:23 +03:00
|
|
|
char *lock_reason; /* internal use */
|
2015-10-08 20:01:04 +03:00
|
|
|
unsigned char head_sha1[20];
|
|
|
|
int is_detached;
|
|
|
|
int is_bare;
|
2016-04-22 16:01:28 +03:00
|
|
|
int is_current;
|
2016-06-13 15:18:23 +03:00
|
|
|
int lock_reason_valid;
|
2015-10-08 20:01:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Functions for acting on the information about worktrees. */
|
|
|
|
|
2016-11-28 12:36:56 +03:00
|
|
|
#define GWT_SORT_LINKED (1 << 0) /* keeps linked worktrees sorted */
|
|
|
|
|
2015-10-08 20:01:03 +03: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).
|
|
|
|
*/
|
2016-11-28 12:36:55 +03:00
|
|
|
extern struct worktree **get_worktrees(unsigned flags);
|
2015-10-08 20:01:03 +03:00
|
|
|
|
2016-12-12 22:04:33 +03:00
|
|
|
/*
|
|
|
|
* Returns 1 if linked worktrees exist, 0 otherwise.
|
|
|
|
*/
|
|
|
|
extern int submodule_uses_worktrees(const char *path);
|
|
|
|
|
2016-04-22 16:01:26 +03: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.
|
|
|
|
*/
|
|
|
|
extern const char *get_worktree_git_dir(const struct worktree *wt);
|
|
|
|
|
2016-06-03 15:19:39 +03:00
|
|
|
/*
|
|
|
|
* Search a worktree that can be unambiguously identified by
|
|
|
|
* "arg". "prefix" must not be NULL.
|
|
|
|
*/
|
|
|
|
extern struct worktree *find_worktree(struct worktree **list,
|
|
|
|
const char *prefix,
|
|
|
|
const char *arg);
|
|
|
|
|
2016-06-03 15:19:40 +03:00
|
|
|
/*
|
|
|
|
* Return true if the given worktree is the main one.
|
|
|
|
*/
|
|
|
|
extern int is_main_worktree(const struct worktree *wt);
|
|
|
|
|
2016-06-13 15:18:23 +03:00
|
|
|
/*
|
|
|
|
* Return the reason string if the given worktree is locked or NULL
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
extern const char *is_worktree_locked(struct worktree *wt);
|
|
|
|
|
2015-10-08 20:01:03 +03:00
|
|
|
/*
|
|
|
|
* Free up the memory for worktree(s)
|
|
|
|
*/
|
|
|
|
extern void free_worktrees(struct worktree **);
|
|
|
|
|
2015-10-02 14:55:31 +03:00
|
|
|
/*
|
|
|
|
* Check if a per-worktree symref points to a ref in the main worktree
|
2016-04-22 16:01:27 +03: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 14:55:31 +03:00
|
|
|
*/
|
2016-04-22 16:01:27 +03:00
|
|
|
extern const struct worktree *find_shared_symref(const char *symref,
|
|
|
|
const char *target);
|
2015-10-02 14:55:31 +03:00
|
|
|
|
2017-08-23 15:36:59 +03: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 16:01:36 +03: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 16:01:29 +03:00
|
|
|
/*
|
|
|
|
* Similar to git_path() but can produce paths for a specified
|
|
|
|
* worktree instead of current one
|
|
|
|
*/
|
|
|
|
extern const char *worktree_git_path(const struct worktree *wt,
|
|
|
|
const char *fmt, ...)
|
|
|
|
__attribute__((format (printf, 2, 3)));
|
|
|
|
|
2015-10-02 14:55:31 +03:00
|
|
|
#endif
|