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_refspec_h__ 8 #define INCLUDE_git_refspec_h__ 9 10 #include "common.h" 11 #include "types.h" 12 #include "net.h" 13 #include "buffer.h" 14 15 /** 16 * @file git2/refspec.h 17 * @brief Git refspec attributes 18 * @defgroup git_refspec Git refspec attributes 19 * @ingroup Git 20 * @{ 21 */ 22 GIT_BEGIN_DECL 23 24 /** 25 * Parse a given refspec string 26 * 27 * @param refspec a pointer to hold the refspec handle 28 * @param input the refspec string 29 * @param is_fetch is this a refspec for a fetch 30 * @return 0 if the refspec string could be parsed, -1 otherwise 31 */ 32 GIT_EXTERN(int) git_refspec_parse(git_refspec **refspec, const char *input, int is_fetch); 33 34 /** 35 * Free a refspec object which has been created by git_refspec_parse 36 * 37 * @param refspec the refspec object 38 */ 39 GIT_EXTERN(void) git_refspec_free(git_refspec *refspec); 40 41 /** 42 * Get the source specifier 43 * 44 * @param refspec the refspec 45 * @return the refspec's source specifier 46 */ 47 GIT_EXTERN(const char *) git_refspec_src(const git_refspec *refspec); 48 49 /** 50 * Get the destination specifier 51 * 52 * @param refspec the refspec 53 * @return the refspec's destination specifier 54 */ 55 GIT_EXTERN(const char *) git_refspec_dst(const git_refspec *refspec); 56 57 /** 58 * Get the refspec's string 59 * 60 * @param refspec the refspec 61 * @returns the refspec's original string 62 */ 63 GIT_EXTERN(const char *) git_refspec_string(const git_refspec *refspec); 64 65 /** 66 * Get the force update setting 67 * 68 * @param refspec the refspec 69 * @return 1 if force update has been set, 0 otherwise 70 */ 71 GIT_EXTERN(int) git_refspec_force(const git_refspec *refspec); 72 73 /** 74 * Get the refspec's direction. 75 * 76 * @param spec refspec 77 * @return GIT_DIRECTION_FETCH or GIT_DIRECTION_PUSH 78 */ 79 GIT_EXTERN(git_direction) git_refspec_direction(const git_refspec *spec); 80 81 /** 82 * Check if a refspec's source descriptor matches a reference 83 * 84 * @param refspec the refspec 85 * @param refname the name of the reference to check 86 * @return 1 if the refspec matches, 0 otherwise 87 */ 88 GIT_EXTERN(int) git_refspec_src_matches(const git_refspec *refspec, const char *refname); 89 90 /** 91 * Check if a refspec's destination descriptor matches a reference 92 * 93 * @param refspec the refspec 94 * @param refname the name of the reference to check 95 * @return 1 if the refspec matches, 0 otherwise 96 */ 97 GIT_EXTERN(int) git_refspec_dst_matches(const git_refspec *refspec, const char *refname); 98 99 /** 100 * Transform a reference to its target following the refspec's rules 101 * 102 * @param out where to store the target name 103 * @param spec the refspec 104 * @param name the name of the reference to transform 105 * @return 0, GIT_EBUFS or another error 106 */ 107 GIT_EXTERN(int) git_refspec_transform(git_buf *out, const git_refspec *spec, const char *name); 108 109 /** 110 * Transform a target reference to its source reference following the refspec's rules 111 * 112 * @param out where to store the source reference name 113 * @param spec the refspec 114 * @param name the name of the reference to transform 115 * @return 0, GIT_EBUFS or another error 116 */ 117 GIT_EXTERN(int) git_refspec_rtransform(git_buf *out, const git_refspec *spec, const char *name); 118 119 GIT_END_DECL 120 121 #endif 122