1 /* 2 * Copyright (C) the libgit2 contributors. All rights reserved. 3 * 4 * This file is part of libgit2, distributed under the GNU GPL v2 with 5 * a Linking Exception. For full terms see the included COPYING file. 6 */ 7 #ifndef INCLUDE_git_cherrypick_h__ 8 #define INCLUDE_git_cherrypick_h__ 9 10 #include "common.h" 11 #include "types.h" 12 #include "merge.h" 13 14 /** 15 * @file git2/cherrypick.h 16 * @brief Git cherry-pick routines 17 * @defgroup git_cherrypick Git cherry-pick routines 18 * @ingroup Git 19 * @{ 20 */ 21 GIT_BEGIN_DECL 22 23 /** 24 * Cherry-pick options 25 */ 26 typedef struct { 27 unsigned int version; 28 29 /** For merge commits, the "mainline" is treated as the parent. */ 30 unsigned int mainline; 31 32 git_merge_options merge_opts; /**< Options for the merging */ 33 git_checkout_options checkout_opts; /**< Options for the checkout */ 34 } git_cherrypick_options; 35 36 #define GIT_CHERRYPICK_OPTIONS_VERSION 1 37 #define GIT_CHERRYPICK_OPTIONS_INIT {GIT_CHERRYPICK_OPTIONS_VERSION, 0, GIT_MERGE_OPTIONS_INIT, GIT_CHECKOUT_OPTIONS_INIT} 38 39 /** 40 * Initialize git_cherrypick_options structure 41 * 42 * Initializes a `git_cherrypick_options` with default values. Equivalent to creating 43 * an instance with GIT_CHERRYPICK_OPTIONS_INIT. 44 * 45 * @param opts The `git_cherrypick_options` struct to initialize. 46 * @param version The struct version; pass `GIT_CHERRYPICK_OPTIONS_VERSION`. 47 * @return Zero on success; -1 on failure. 48 */ 49 GIT_EXTERN(int) git_cherrypick_options_init( 50 git_cherrypick_options *opts, 51 unsigned int version); 52 53 /** 54 * Cherry-picks the given commit against the given "our" commit, producing an 55 * index that reflects the result of the cherry-pick. 56 * 57 * The returned index must be freed explicitly with `git_index_free`. 58 * 59 * @param out pointer to store the index result in 60 * @param repo the repository that contains the given commits 61 * @param cherrypick_commit the commit to cherry-pick 62 * @param our_commit the commit to cherry-pick against (eg, HEAD) 63 * @param mainline the parent of the `cherrypick_commit`, if it is a merge 64 * @param merge_options the merge options (or null for defaults) 65 * @return zero on success, -1 on failure. 66 */ 67 GIT_EXTERN(int) git_cherrypick_commit( 68 git_index **out, 69 git_repository *repo, 70 git_commit *cherrypick_commit, 71 git_commit *our_commit, 72 unsigned int mainline, 73 const git_merge_options *merge_options); 74 75 /** 76 * Cherry-pick the given commit, producing changes in the index and working directory. 77 * 78 * @param repo the repository to cherry-pick 79 * @param commit the commit to cherry-pick 80 * @param cherrypick_options the cherry-pick options (or null for defaults) 81 * @return zero on success, -1 on failure. 82 */ 83 GIT_EXTERN(int) git_cherrypick( 84 git_repository *repo, 85 git_commit *commit, 86 const git_cherrypick_options *cherrypick_options); 87 88 /** @} */ 89 GIT_END_DECL 90 91 #endif 92 93