From 8dc78a0f620c252ec37832bc8a75140346f0ad62 Mon Sep 17 00:00:00 2001 From: Jacob Watson Date: Tue, 21 Jun 2022 15:23:33 -0700 Subject: stash: implement partial stashing by path --- include/git2/stash.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/git2/stash.h b/include/git2/stash.h index 32e6f9576..3b8908195 100644 --- a/include/git2/stash.h +++ b/include/git2/stash.h @@ -44,7 +44,12 @@ typedef enum { * All ignored files are also stashed and then cleaned up from * the working directory */ - GIT_STASH_INCLUDE_IGNORED = (1 << 2) + GIT_STASH_INCLUDE_IGNORED = (1 << 2), + + /** + * All changes in the index and working directory are left intact + */ + GIT_STASH_KEEP_ALL = (1 << 3) } git_stash_flags; /** @@ -71,6 +76,65 @@ GIT_EXTERN(int) git_stash_save( const char *message, uint32_t flags); +/** + * Stash save options structure + * + * Initialize with `GIT_STASH_SAVE_OPTIONS_INIT`. Alternatively, you can + * use `git_stash_save_options_init`. + * + */ +typedef struct git_stash_save_options { + unsigned int version; + + /** The identity of the person performing the stashing. */ + const git_signature *stasher; + + /** Optional description along with the stashed state. */ + const char *message; + + /** Flags to control the stashing process. (see GIT_STASH_* above) */ + uint32_t flags; + + /** Optional paths that control which files are stashed. */ + git_strarray paths; +} git_stash_save_options; + +#define GIT_STASH_SAVE_OPTIONS_VERSION 1 +#define GIT_STASH_SAVE_OPTIONS_INIT { \ + GIT_STASH_SAVE_OPTIONS_VERSION, \ + NULL, \ + NULL, \ + GIT_STASH_DEFAULT } + +/** + * Initialize git_stash_save_options structure + * + * Initializes a `git_stash_save_options` with default values. Equivalent to + * creating an instance with `GIT_STASH_SAVE_OPTIONS_INIT`. + * + * @param opts The `git_stash_save_options` struct to initialize. + * @param version The struct version; pass `GIT_STASH_SAVE_OPTIONS_VERSION`. + * @return Zero on success; -1 on failure. + */ +GIT_EXTERN(int) git_stash_save_options_init( + git_stash_save_options *opts, unsigned int version); + +/** + * Save the local modifications to a new stash, with options. + * + * @param out Object id of the commit containing the stashed state. + * This commit is also the target of the direct reference refs/stash. + * + * @param repo The owning repository. + * + * @param opts The stash options. + * + * @return 0 on success, GIT_ENOTFOUND where there's nothing to stash, + * or error code. + */ +GIT_EXTERN(int) git_stash_save_with_opts( + git_oid *out, git_repository *repo, git_stash_save_options *opts); + /** Stash application flags. */ typedef enum { GIT_STASH_APPLY_DEFAULT = 0, -- cgit v1.2.1 From fc9d28970a9fe970025f529c2108a6a3fef03555 Mon Sep 17 00:00:00 2001 From: Jacob Watson Date: Wed, 13 Jul 2022 15:58:52 -0700 Subject: stash: add `const` to arguments --- include/git2/stash.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/git2/stash.h b/include/git2/stash.h index 3b8908195..3d70b36c3 100644 --- a/include/git2/stash.h +++ b/include/git2/stash.h @@ -133,7 +133,9 @@ GIT_EXTERN(int) git_stash_save_options_init( * or error code. */ GIT_EXTERN(int) git_stash_save_with_opts( - git_oid *out, git_repository *repo, git_stash_save_options *opts); + git_oid *out, + git_repository *repo, + const git_stash_save_options *opts); /** Stash application flags. */ typedef enum { -- cgit v1.2.1 From 35580d88a834438275adea77785a5f356352ea21 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 16 Feb 2023 09:11:57 +0000 Subject: stash: fixes from code review --- include/git2/stash.h | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/git2/stash.h b/include/git2/stash.h index 3d70b36c3..dcfc013dc 100644 --- a/include/git2/stash.h +++ b/include/git2/stash.h @@ -57,15 +57,10 @@ typedef enum { * * @param out Object id of the commit containing the stashed state. * This commit is also the target of the direct reference refs/stash. - * * @param repo The owning repository. - * * @param stasher The identity of the person performing the stashing. - * * @param message Optional description along with the stashed state. - * * @param flags Flags to control the stashing process. (see GIT_STASH_* above) - * * @return 0 on success, GIT_ENOTFOUND where there's nothing to stash, * or error code. */ @@ -86,25 +81,21 @@ GIT_EXTERN(int) git_stash_save( typedef struct git_stash_save_options { unsigned int version; + /** Flags to control the stashing process. (see GIT_STASH_* above) */ + uint32_t flags; + /** The identity of the person performing the stashing. */ const git_signature *stasher; /** Optional description along with the stashed state. */ const char *message; - /** Flags to control the stashing process. (see GIT_STASH_* above) */ - uint32_t flags; - /** Optional paths that control which files are stashed. */ git_strarray paths; } git_stash_save_options; #define GIT_STASH_SAVE_OPTIONS_VERSION 1 -#define GIT_STASH_SAVE_OPTIONS_INIT { \ - GIT_STASH_SAVE_OPTIONS_VERSION, \ - NULL, \ - NULL, \ - GIT_STASH_DEFAULT } +#define GIT_STASH_SAVE_OPTIONS_INIT { GIT_STASH_SAVE_OPTIONS_VERSION } /** * Initialize git_stash_save_options structure @@ -121,14 +112,11 @@ GIT_EXTERN(int) git_stash_save_options_init( /** * Save the local modifications to a new stash, with options. - * + * * @param out Object id of the commit containing the stashed state. * This commit is also the target of the direct reference refs/stash. - * * @param repo The owning repository. - * * @param opts The stash options. - * * @return 0 on success, GIT_ENOTFOUND where there's nothing to stash, * or error code. */ -- cgit v1.2.1