summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-05-02 12:35:59 +0200
committerPatrick Steinhardt <ps@pks.im>2017-05-05 15:39:25 +0200
commit883eeb5f909f230822c0bc025d3f9ce79781de04 (patch)
tree957edab7f83315a90e685dfcd4569fb889de0258 /include
parent8264a30f4fbfce96f433f01fa6fe537e5cb3570d (diff)
downloadlibgit2-883eeb5f909f230822c0bc025d3f9ce79781de04.tar.gz
worktree: switch over worktree pruning to an opts structure
The current signature of `git_worktree_prune` accepts a flags field to alter its behavior. This is not as flexible as we'd like it to be when we want to enable passing additional options in the future. As the function has not been part of any release yet, we are still free to alter its current signature. This commit does so by using our usual pattern of an options structure, which is easily extendable without breaking the API.
Diffstat (limited to 'include')
-rw-r--r--include/git2/worktree.h41
1 files changed, 32 insertions, 9 deletions
diff --git a/include/git2/worktree.h b/include/git2/worktree.h
index 84e2bc92e..e3bafc3d0 100644
--- a/include/git2/worktree.h
+++ b/include/git2/worktree.h
@@ -161,23 +161,44 @@ typedef enum {
GIT_WORKTREE_PRUNE_WORKING_TREE = 1u << 2,
} git_worktree_prune_t;
+typedef struct git_worktree_prune_options {
+ unsigned int version;
+
+ uint32_t flags;
+} git_worktree_prune_options;
+
+#define GIT_WORKTREE_PRUNE_OPTIONS_VERSION 1
+#define GIT_WORKTREE_PRUNE_OPTIONS_INIT {GIT_WORKTREE_PRUNE_OPTIONS_VERSION,0}
+
+/**
+ * Initializes a `git_worktree_prune_options` with default vaules.
+ * Equivalent to creating an instance with
+ * GIT_WORKTREE_PRUNE_OPTIONS_INIT.
+ *
+ * @param opts the struct to initialize
+ * @param version Verison of struct; pass `GIT_WORKTREE_PRUNE_OPTIONS_VERSION`
+ * @return Zero on success; -1 on failure.
+ */
+GIT_EXTERN(int) git_worktree_prune_init_options(
+ git_worktree_prune_options *opts,
+ unsigned int version);
+
/**
- * Is the worktree prunable with the given set of flags?
+ * Is the worktree prunable with the given options?
*
* A worktree is not prunable in the following scenarios:
*
* - the worktree is linking to a valid on-disk worktree. The
- * GIT_WORKTREE_PRUNE_VALID flag will cause this check to be
- * ignored.
- * - the worktree is not valid but locked. The
- * GIT_WORKRTEE_PRUNE_LOCKED flag will cause this check to be
- * ignored.
+ * `valid` member will cause this check to be ignored.
+ * - the worktree is locked. The `locked` flag will cause this
+ * check to be ignored.
*
* If the worktree is not valid and not locked or if the above
* flags have been passed in, this function will return a
* positive value.
*/
-GIT_EXTERN(int) git_worktree_is_prunable(git_worktree *wt, unsigned flags);
+GIT_EXTERN(int) git_worktree_is_prunable(git_worktree *wt,
+ git_worktree_prune_options *opts);
/**
* Prune working tree
@@ -187,10 +208,12 @@ GIT_EXTERN(int) git_worktree_is_prunable(git_worktree *wt, unsigned flags);
* `git_worktree_is_prunable` succeeds.
*
* @param wt Worktree to prune
- * @param flags git_worktree_prune_t flags
+ * @param opts Specifies which checks to override. See
+ * `git_worktree_is_prunable`. May be NULL
* @return 0 or an error code
*/
-GIT_EXTERN(int) git_worktree_prune(git_worktree *wt, unsigned flags);
+GIT_EXTERN(int) git_worktree_prune(git_worktree *wt,
+ git_worktree_prune_options *opts);
/** @} */
GIT_END_DECL