2015-10-02 14:55:31 +03:00
|
|
|
#ifndef WORKTREE_H
|
|
|
|
#define WORKTREE_H
|
|
|
|
|
2018-08-15 20:54:05 +03:00
|
|
|
#include "cache.h"
|
2017-08-23 15:36:59 +03:00
|
|
|
#include "refs.h"
|
|
|
|
|
2018-01-24 12:53:51 +03:00
|
|
|
struct strbuf;
|
|
|
|
|
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 */
|
2018-10-30 09:24:09 +03:00
|
|
|
char *lock_reason; /* private - use worktree_lock_reason */
|
2021-01-20 00:27:34 +03:00
|
|
|
char *prune_reason; /* private - use worktree_prune_reason */
|
2017-10-16 01:07:08 +03:00
|
|
|
struct object_id head_oid;
|
2015-10-08 20:01:04 +03:00
|
|
|
int is_detached;
|
|
|
|
int is_bare;
|
2016-04-22 16:01:28 +03:00
|
|
|
int is_current;
|
2018-10-30 09:24:08 +03:00
|
|
|
int lock_reason_valid; /* private */
|
2021-01-20 00:27:34 +03:00
|
|
|
int prune_reason_valid; /* private */
|
2015-10-08 20:01:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the worktrees. The primary worktree will always be the first returned,
|
2020-06-20 02:35:43 +03:00
|
|
|
* and linked worktrees will follow in no particular order.
|
2015-10-08 20:01:03 +03:00
|
|
|
*
|
|
|
|
* The caller is responsible for freeing the memory from the returned
|
2020-06-20 02:35:43 +03:00
|
|
|
* worktrees by calling free_worktrees().
|
2015-10-08 20:01:03 +03:00
|
|
|
*/
|
2020-06-20 02:35:44 +03:00
|
|
|
struct worktree **get_worktrees(void);
|
2015-10-08 20:01:03 +03:00
|
|
|
|
2016-12-12 22:04:33 +03:00
|
|
|
/*
|
|
|
|
* Returns 1 if linked worktrees exist, 0 otherwise.
|
|
|
|
*/
|
2019-04-29 11:28:14 +03:00
|
|
|
int submodule_uses_worktrees(const char *path);
|
2016-12-12 22:04:33 +03:00
|
|
|
|
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.
|
|
|
|
*/
|
2019-04-29 11:28:14 +03:00
|
|
|
const char *get_worktree_git_dir(const struct worktree *wt);
|
2016-04-22 16:01:26 +03:00
|
|
|
|
2016-06-03 15:19:39 +03:00
|
|
|
/*
|
worktree: improve find_worktree() documentation
Do a better job of explaining that find_worktree()'s main purpose is to
locate a worktree based upon input from a user which may be some sort of
shorthand for identifying a worktree rather than an actual path. For
instance, one shorthand a user can use to identify a worktree is by
unique path suffix (i.e. given worktrees at paths "foo/bar" and
"foo/baz", the latter can be identified simply as "baz"). The actual
heuristics find_worktree() uses to select a worktree may be expanded in
the future (for instance, one day it may allow worktree selection by
<id> of the .git/worktrees/<id>/ administrative directory), thus the
documentation does not provide a precise description of how matching is
performed, instead leaving it open-ended to allow for future
enhancement.
While at it, drop mention of the non-NULL requirement of `prefix` since
NULL has long been allowed. For instance, prefix_filename() has
explicitly allowed NULL since 116fb64e43 (prefix_filename: drop length
parameter, 2017-03-20), and find_worktree() itself since e4da43b1f0
(prefix_filename: return newly allocated string, 2017-03-20).
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-24 12:08:46 +03:00
|
|
|
* Search for the worktree identified unambiguously by `arg` -- typically
|
|
|
|
* supplied by the user via the command-line -- which may be a pathname or some
|
|
|
|
* shorthand uniquely identifying a worktree, thus making it convenient for the
|
|
|
|
* user to specify a worktree with minimal typing. For instance, if the last
|
|
|
|
* component (say, "foo") of a worktree's pathname is unique among worktrees
|
|
|
|
* (say, "work/foo" and "work/bar"), it can be used to identify the worktree
|
|
|
|
* unambiguously.
|
|
|
|
*
|
|
|
|
* `prefix` should be the `prefix` handed to top-level Git commands along with
|
|
|
|
* `argc` and `argv`.
|
|
|
|
*
|
|
|
|
* Return the worktree identified by `arg`, or NULL if not found.
|
2016-06-03 15:19:39 +03:00
|
|
|
*/
|
2019-04-29 11:28:14 +03:00
|
|
|
struct worktree *find_worktree(struct worktree **list,
|
2019-04-29 11:28:23 +03:00
|
|
|
const char *prefix,
|
|
|
|
const char *arg);
|
2016-06-03 15:19:39 +03:00
|
|
|
|
2020-02-24 12:08:47 +03:00
|
|
|
/*
|
|
|
|
* Return the worktree corresponding to `path`, or NULL if no such worktree
|
|
|
|
* exists.
|
|
|
|
*/
|
|
|
|
struct worktree *find_worktree_by_path(struct worktree **, const char *path);
|
|
|
|
|
2016-06-03 15:19:40 +03:00
|
|
|
/*
|
|
|
|
* Return true if the given worktree is the main one.
|
|
|
|
*/
|
2019-04-29 11:28:14 +03:00
|
|
|
int is_main_worktree(const struct worktree *wt);
|
2016-06-03 15:19:40 +03:00
|
|
|
|
2016-06-13 15:18:23 +03:00
|
|
|
/*
|
|
|
|
* Return the reason string if the given worktree is locked or NULL
|
|
|
|
* otherwise.
|
|
|
|
*/
|
2019-04-29 11:28:14 +03:00
|
|
|
const char *worktree_lock_reason(struct worktree *wt);
|
2016-06-13 15:18:23 +03:00
|
|
|
|
2021-01-20 00:27:34 +03:00
|
|
|
/*
|
|
|
|
* Return the reason string if the given worktree should be pruned, otherwise
|
|
|
|
* NULL if it should not be pruned. `expire` defines a grace period to prune
|
|
|
|
* the worktree when its path does not exist.
|
|
|
|
*/
|
|
|
|
const char *worktree_prune_reason(struct worktree *wt, timestamp_t expire);
|
|
|
|
|
2021-01-20 00:27:33 +03:00
|
|
|
/*
|
|
|
|
* Return true if worktree entry should be pruned, along with the reason for
|
|
|
|
* pruning. Otherwise, return false and the worktree's path in `wtpath`, or
|
|
|
|
* NULL if it cannot be determined. Caller is responsible for freeing
|
|
|
|
* returned path.
|
|
|
|
*
|
|
|
|
* `expire` defines a grace period to prune the worktree when its path
|
|
|
|
* does not exist.
|
|
|
|
*/
|
|
|
|
int should_prune_worktree(const char *id,
|
|
|
|
struct strbuf *reason,
|
|
|
|
char **wtpath,
|
|
|
|
timestamp_t expire);
|
|
|
|
|
2018-02-12 12:49:40 +03:00
|
|
|
#define WT_VALIDATE_WORKTREE_MISSING_OK (1 << 0)
|
|
|
|
|
2018-01-24 12:53:51 +03:00
|
|
|
/*
|
|
|
|
* Return zero if the worktree is in good condition. Error message is
|
|
|
|
* returned if "errmsg" is not NULL.
|
|
|
|
*/
|
2019-04-29 11:28:14 +03:00
|
|
|
int validate_worktree(const struct worktree *wt,
|
2019-04-29 11:28:23 +03:00
|
|
|
struct strbuf *errmsg,
|
|
|
|
unsigned flags);
|
2018-01-24 12:53:51 +03:00
|
|
|
|
2018-02-12 12:49:35 +03:00
|
|
|
/*
|
|
|
|
* Update worktrees/xxx/gitdir with the new path.
|
|
|
|
*/
|
2019-04-29 11:28:14 +03:00
|
|
|
void update_worktree_location(struct worktree *wt,
|
2019-04-29 11:28:23 +03:00
|
|
|
const char *path_);
|
2018-02-12 12:49:35 +03:00
|
|
|
|
2020-08-31 09:57:57 +03:00
|
|
|
typedef void (* worktree_repair_fn)(int iserr, const char *path,
|
|
|
|
const char *msg, void *cb_data);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Visit each registered linked worktree and repair corruptions. For each
|
|
|
|
* repair made or error encountered while attempting a repair, the callback
|
|
|
|
* function, if non-NULL, is called with the path of the worktree and a
|
|
|
|
* description of the repair or error, along with the callback user-data.
|
|
|
|
*/
|
|
|
|
void repair_worktrees(worktree_repair_fn, void *cb_data);
|
|
|
|
|
2020-08-31 09:57:58 +03:00
|
|
|
/*
|
|
|
|
* Repair administrative files corresponding to the worktree at the given path.
|
|
|
|
* The worktree's .git file pointing at the repository must be intact for the
|
|
|
|
* repair to succeed. Useful for re-associating an orphaned worktree with the
|
|
|
|
* repository if the worktree has been moved manually (without using "git
|
|
|
|
* worktree move"). For each repair made or error encountered while attempting
|
|
|
|
* a repair, the callback function, if non-NULL, is called with the path of the
|
|
|
|
* worktree and a description of the repair or error, along with the callback
|
|
|
|
* user-data.
|
|
|
|
*/
|
|
|
|
void repair_worktree_at_path(const char *, worktree_repair_fn, void *cb_data);
|
|
|
|
|
2015-10-08 20:01:03 +03:00
|
|
|
/*
|
|
|
|
* Free up the memory for worktree(s)
|
|
|
|
*/
|
2019-04-29 11:28:14 +03:00
|
|
|
void free_worktrees(struct worktree **);
|
2015-10-08 20:01:03 +03:00
|
|
|
|
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,
|
2021-12-02 01:15:43 +03:00
|
|
|
* or NULL otherwise.
|
2015-10-02 14:55:31 +03:00
|
|
|
*/
|
2021-12-02 01:15:43 +03:00
|
|
|
const struct worktree *find_shared_symref(struct worktree **worktrees,
|
|
|
|
const char *symref,
|
2019-04-29 11:28:23 +03:00
|
|
|
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
|
|
|
|
*/
|
2019-04-29 11:28:20 +03:00
|
|
|
const char *worktree_git_path(const struct worktree *wt,
|
2019-04-29 11:28:23 +03:00
|
|
|
const char *fmt, ...)
|
2016-04-22 16:01:29 +03:00
|
|
|
__attribute__((format (printf, 2, 3)));
|
|
|
|
|
2018-10-21 11:08:56 +03: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);
|
|
|
|
|
2022-02-08 00:32:59 +03:00
|
|
|
/**
|
|
|
|
* Enable worktree config for the first time. This will make the following
|
|
|
|
* adjustments:
|
|
|
|
*
|
|
|
|
* 1. Add extensions.worktreeConfig=true in the common config file.
|
|
|
|
*
|
|
|
|
* 2. If the common config file has a core.worktree value, then that value
|
|
|
|
* is moved to the main worktree's config.worktree file.
|
|
|
|
*
|
|
|
|
* 3. If the common config file has a core.bare enabled, then that value
|
|
|
|
* is moved to the main worktree's config.worktree file.
|
|
|
|
*
|
|
|
|
* If extensions.worktreeConfig is already true, then this method
|
|
|
|
* terminates early without any of the above steps. The existing config
|
|
|
|
* arrangement is assumed to be intentional.
|
|
|
|
*
|
|
|
|
* Returns 0 on success. Reports an error message and returns non-zero
|
|
|
|
* if any of these steps fail.
|
|
|
|
*/
|
|
|
|
int init_worktree_config(struct repository *r);
|
|
|
|
|
2015-10-02 14:55:31 +03:00
|
|
|
#endif
|