| Brandon Williams | ec0cb49 | 2018-05-16 22:57:48 | [diff] [blame] | 1 | #ifndef REFSPEC_H |
| 2 | #define REFSPEC_H |
| 3 | |
| 4 | #define TAG_REFSPEC "refs/tags/*:refs/tags/*" |
| Brandon Williams | 0ad4a5f | 2018-05-16 22:57:49 | [diff] [blame] | 5 | extern const struct refspec_item *tag_refspec; |
| Brandon Williams | ec0cb49 | 2018-05-16 22:57:48 | [diff] [blame] | 6 | |
| Jacob Keller | 0becfec | 2020-08-15 00:25:07 | [diff] [blame] | 7 | /** |
| Jacob Keller | c0192df | 2020-09-30 21:25:29 | [diff] [blame] | 8 | * A struct refspec_item holds the parsed interpretation of a refspec. If it |
| 9 | * will force updates (starts with a '+'), force is true. If it is a pattern |
| 10 | * (sides end with '*') pattern is true. If it is a negative refspec, (starts |
| 11 | * with '^'), negative is true. src and dest are the two sides (including '*' |
| 12 | * characters if present); if there is only one side, it is src, and dst is |
| 13 | * NULL; if sides exist but are empty (i.e., the refspec either starts or ends |
| 14 | * with ':'), the corresponding side is "". |
| Jacob Keller | 0becfec | 2020-08-15 00:25:07 | [diff] [blame] | 15 | * |
| 16 | * remote_find_tracking(), given a remote and a struct refspec_item with either src |
| 17 | * or dst filled out, will fill out the other such that the result is in the |
| 18 | * "fetch" specification for the remote (note that this evaluates patterns and |
| 19 | * returns a single result). |
| 20 | */ |
| Brandon Williams | 0ad4a5f | 2018-05-16 22:57:49 | [diff] [blame] | 21 | struct refspec_item { |
| Brandon Williams | ec0cb49 | 2018-05-16 22:57:48 | [diff] [blame] | 22 | unsigned force : 1; |
| 23 | unsigned pattern : 1; |
| 24 | unsigned matching : 1; |
| 25 | unsigned exact_sha1 : 1; |
| Jacob Keller | c0192df | 2020-09-30 21:25:29 | [diff] [blame] | 26 | unsigned negative : 1; |
| Brandon Williams | ec0cb49 | 2018-05-16 22:57:48 | [diff] [blame] | 27 | |
| 28 | char *src; |
| 29 | char *dst; |
| 30 | }; |
| 31 | |
| Brandon Williams | 6d4c057 | 2018-05-16 22:57:51 | [diff] [blame] | 32 | #define REFSPEC_FETCH 1 |
| 33 | #define REFSPEC_PUSH 0 |
| 34 | |
| 35 | #define REFSPEC_INIT_FETCH { .fetch = REFSPEC_FETCH } |
| 36 | #define REFSPEC_INIT_PUSH { .fetch = REFSPEC_PUSH } |
| 37 | |
| Heba Waly | d27eb35 | 2019-11-17 21:04:45 | [diff] [blame] | 38 | /** |
| Jacob Keller | 0becfec | 2020-08-15 00:25:07 | [diff] [blame] | 39 | * An array of strings can be parsed into a struct refspec using |
| Heba Waly | d27eb35 | 2019-11-17 21:04:45 | [diff] [blame] | 40 | * parse_fetch_refspec() or parse_push_refspec(). |
| Heba Waly | d27eb35 | 2019-11-17 21:04:45 | [diff] [blame] | 41 | */ |
| Brandon Williams | 6d4c057 | 2018-05-16 22:57:51 | [diff] [blame] | 42 | struct refspec { |
| 43 | struct refspec_item *items; |
| 44 | int alloc; |
| 45 | int nr; |
| 46 | |
| 47 | const char **raw; |
| 48 | int raw_alloc; |
| 49 | int raw_nr; |
| 50 | |
| 51 | int fetch; |
| 52 | }; |
| 53 | |
| Ævar Arnfjörð Bjarmason | c495fd3 | 2018-06-05 19:54:39 | [diff] [blame] | 54 | int refspec_item_init(struct refspec_item *item, const char *refspec, |
| 55 | int fetch); |
| Ævar Arnfjörð Bjarmason | dc06422 | 2018-06-05 19:54:38 | [diff] [blame] | 56 | void refspec_item_init_or_die(struct refspec_item *item, const char *refspec, |
| 57 | int fetch); |
| Brandon Williams | 6d4c057 | 2018-05-16 22:57:51 | [diff] [blame] | 58 | void refspec_item_clear(struct refspec_item *item); |
| 59 | void refspec_init(struct refspec *rs, int fetch); |
| 60 | void refspec_append(struct refspec *rs, const char *refspec); |
| René Scharfe | 1af8b8c | 2020-09-05 14:49:30 | [diff] [blame] | 61 | __attribute__((format (printf,2,3))) |
| 62 | void refspec_appendf(struct refspec *rs, const char *fmt, ...); |
| Brandon Williams | 6d4c057 | 2018-05-16 22:57:51 | [diff] [blame] | 63 | void refspec_appendn(struct refspec *rs, const char **refspecs, int nr); |
| 64 | void refspec_clear(struct refspec *rs); |
| 65 | |
| Brandon Williams | c8fa9ef | 2018-05-16 22:57:52 | [diff] [blame] | 66 | int valid_fetch_refspec(const char *refspec); |
| Sean Barag | f2c6fda | 2020-10-01 03:46:13 | [diff] [blame] | 67 | int valid_remote_name(const char *name); |
| Brandon Williams | c8fa9ef | 2018-05-16 22:57:52 | [diff] [blame] | 68 | |
| Jeff King | 873cd28 | 2020-07-28 20:23:25 | [diff] [blame] | 69 | struct strvec; |
| Jonathan Nieder | 6c301ad | 2018-05-31 07:23:39 | [diff] [blame] | 70 | /* |
| 71 | * Determine what <prefix> values to pass to the peer in ref-prefix lines |
| Ævar Arnfjörð Bjarmason | 5db9210 | 2022-08-04 16:28:36 | [diff] [blame] | 72 | * (see linkgit:gitprotocol-v2[5]). |
| Jonathan Nieder | 6c301ad | 2018-05-31 07:23:39 | [diff] [blame] | 73 | */ |
| Brandon Williams | 6373cb5 | 2018-05-16 23:48:21 | [diff] [blame] | 74 | void refspec_ref_prefixes(const struct refspec *rs, |
| Jeff King | 873cd28 | 2020-07-28 20:23:25 | [diff] [blame] | 75 | struct strvec *ref_prefixes); |
| Brandon Williams | 6373cb5 | 2018-05-16 23:48:21 | [diff] [blame] | 76 | |
| Brandon Williams | ec0cb49 | 2018-05-16 22:57:48 | [diff] [blame] | 77 | #endif /* REFSPEC_H */ |