THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.7KB

  1. #ifndef WORKTREE_H
  2. #define WORKTREE_H
  3. #include "cache.h"
  4. #include "refs.h"
  5. struct strbuf;
  6. struct worktree {
  7. char *path;
  8. char *id;
  9. char *head_ref; /* NULL if HEAD is broken or detached */
  10. char *lock_reason; /* private - use worktree_lock_reason */
  11. struct object_id head_oid;
  12. int is_detached;
  13. int is_bare;
  14. int is_current;
  15. int lock_reason_valid; /* private */
  16. };
  17. /* Functions for acting on the information about worktrees. */
  18. #define GWT_SORT_LINKED (1 << 0) /* keeps linked worktrees sorted */
  19. /*
  20. * Get the worktrees. The primary worktree will always be the first returned,
  21. * and linked worktrees will be pointed to by 'next' in each subsequent
  22. * worktree. No specific ordering is done on the linked worktrees.
  23. *
  24. * The caller is responsible for freeing the memory from the returned
  25. * worktree(s).
  26. */
  27. struct worktree **get_worktrees(unsigned flags);
  28. /*
  29. * Returns 1 if linked worktrees exist, 0 otherwise.
  30. */
  31. int submodule_uses_worktrees(const char *path);
  32. /*
  33. * Return git dir of the worktree. Note that the path may be relative.
  34. * If wt is NULL, git dir of current worktree is returned.
  35. */
  36. const char *get_worktree_git_dir(const struct worktree *wt);
  37. /*
  38. * Search a worktree that can be unambiguously identified by
  39. * "arg". "prefix" must not be NULL.
  40. */
  41. struct worktree *find_worktree(struct worktree **list,
  42. const char *prefix,
  43. const char *arg);
  44. /*
  45. * Return true if the given worktree is the main one.
  46. */
  47. int is_main_worktree(const struct worktree *wt);
  48. /*
  49. * Return the reason string if the given worktree is locked or NULL
  50. * otherwise.
  51. */
  52. const char *worktree_lock_reason(struct worktree *wt);
  53. #define WT_VALIDATE_WORKTREE_MISSING_OK (1 << 0)
  54. /*
  55. * Return zero if the worktree is in good condition. Error message is
  56. * returned if "errmsg" is not NULL.
  57. */
  58. int validate_worktree(const struct worktree *wt,
  59. struct strbuf *errmsg,
  60. unsigned flags);
  61. /*
  62. * Update worktrees/xxx/gitdir with the new path.
  63. */
  64. void update_worktree_location(struct worktree *wt,
  65. const char *path_);
  66. /*
  67. * Free up the memory for worktree(s)
  68. */
  69. void free_worktrees(struct worktree **);
  70. /*
  71. * Check if a per-worktree symref points to a ref in the main worktree
  72. * or any linked worktree, and return the worktree that holds the ref,
  73. * or NULL otherwise. The result may be destroyed by the next call.
  74. */
  75. const struct worktree *find_shared_symref(const char *symref,
  76. const char *target);
  77. /*
  78. * Similar to head_ref() for all HEADs _except_ one from the current
  79. * worktree, which is covered by head_ref().
  80. */
  81. int other_head_refs(each_ref_fn fn, void *cb_data);
  82. int is_worktree_being_rebased(const struct worktree *wt, const char *target);
  83. int is_worktree_being_bisected(const struct worktree *wt, const char *target);
  84. /*
  85. * Similar to git_path() but can produce paths for a specified
  86. * worktree instead of current one
  87. */
  88. const char *worktree_git_path(const struct worktree *wt,
  89. const char *fmt, ...)
  90. __attribute__((format (printf, 2, 3)));
  91. /*
  92. * Parse a worktree ref (i.e. with prefix main-worktree/ or
  93. * worktrees/) and return the position of the worktree's name and
  94. * length (or NULL and zero if it's main worktree), and ref.
  95. *
  96. * All name, name_length and ref arguments could be NULL.
  97. */
  98. int parse_worktree_ref(const char *worktree_ref, const char **name,
  99. int *name_length, const char **ref);
  100. /*
  101. * Return a refname suitable for access from the current ref store.
  102. */
  103. void strbuf_worktree_ref(const struct worktree *wt,
  104. struct strbuf *sb,
  105. const char *refname);
  106. /*
  107. * Return a refname suitable for access from the current ref
  108. * store. The result will be destroyed at the next call.
  109. */
  110. const char *worktree_ref(const struct worktree *wt,
  111. const char *refname);
  112. #endif