diff options
author | Han-Wen Nienhuys <hanwen@google.com> | 2022-09-19 18:34:50 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-09-19 20:11:11 +0200 |
commit | 71e5473493612f74244e2fa7a257a868df98be53 (patch) | |
tree | d749311ef5041031f8a5c569a680837d862990f8 /refs.h | |
parent | Git 2.38-rc0 (diff) | |
download | git-71e5473493612f74244e2fa7a257a868df98be53.tar.xz git-71e5473493612f74244e2fa7a257a868df98be53.zip |
refs: unify parse_worktree_ref() and ref_type()
The logic to handle worktree refs (worktrees/NAME/REF and
main-worktree/REF) existed in two places:
* ref_type() in refs.c
* parse_worktree_ref() in worktree.c
Collapse this logic together in one function parse_worktree_ref():
this avoids having to cross-check the result of parse_worktree_ref()
and ref_type().
Introduce enum ref_worktree_type, which is slightly different from
enum ref_type. The latter is a misleading name (one would think that
'ref_type' would have the symref option).
Instead, enum ref_worktree_type only makes explicit how a refname
relates to a worktree. From this point of view, HEAD and
refs/bisect/abc are the same: they specify the current worktree
implicitly.
The files-backend must avoid packing refs/bisect/* and friends into
packed-refs, so expose is_per_worktree_ref() separately.
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.h')
-rw-r--r-- | refs.h | 33 |
1 files changed, 26 insertions, 7 deletions
@@ -820,15 +820,34 @@ int parse_hide_refs_config(const char *var, const char *value, const char *); */ int ref_is_hidden(const char *, const char *); -enum ref_type { - REF_TYPE_PER_WORKTREE, /* refs inside refs/ but not shared */ - REF_TYPE_PSEUDOREF, /* refs outside refs/ in current worktree */ - REF_TYPE_MAIN_PSEUDOREF, /* pseudo refs from the main worktree */ - REF_TYPE_OTHER_PSEUDOREF, /* pseudo refs from other worktrees */ - REF_TYPE_NORMAL, /* normal/shared refs inside refs/ */ +/* Is this a per-worktree ref living in the refs/ namespace? */ +int is_per_worktree_ref(const char *refname); + +/* Describes how a refname relates to worktrees */ +enum ref_worktree_type { + REF_WORKTREE_CURRENT, /* implicitly per worktree, eg. HEAD or + refs/bisect/SOMETHING */ + REF_WORKTREE_MAIN, /* explicitly in main worktree, eg. + main-worktree/HEAD */ + REF_WORKTREE_OTHER, /* explicitly in named worktree, eg. + worktrees/bla/HEAD */ + REF_WORKTREE_SHARED, /* the default, eg. refs/heads/main */ }; -enum ref_type ref_type(const char *refname); +/* + * Parse a `maybe_worktree_ref` as a ref that possibly refers to a worktree ref + * (ie. either REFNAME, main-worktree/REFNAME or worktree/WORKTREE/REFNAME). It + * returns what kind of ref was found, and in case of REF_WORKTREE_OTHER, the + * worktree name is returned in `worktree_name` (pointing into + * `maybe_worktree_ref`) and `worktree_name_length`. The bare refname (the + * refname stripped of prefixes) is returned in `bare_refname`. The + * `worktree_name`, `worktree_name_length` and `bare_refname` arguments may be + * NULL. + */ +enum ref_worktree_type parse_worktree_ref(const char *maybe_worktree_ref, + const char **worktree_name, + int *worktree_name_length, + const char **bare_refname); enum expire_reflog_flags { EXPIRE_REFLOGS_DRY_RUN = 1 << 0, |