]> git.ipfire.org Git - thirdparty/git.git/blame - refspec.h
The fifth batch
[thirdparty/git.git] / refspec.h
CommitLineData
ec0cb496
BW
1#ifndef REFSPEC_H
2#define REFSPEC_H
3
4#define TAG_REFSPEC "refs/tags/*:refs/tags/*"
ec0cb496 5
0becfec5 6/**
c0192df6
JK
7 * A struct refspec_item holds the parsed interpretation of a refspec. If it
8 * will force updates (starts with a '+'), force is true. If it is a pattern
9 * (sides end with '*') pattern is true. If it is a negative refspec, (starts
10 * with '^'), negative is true. src and dest are the two sides (including '*'
11 * characters if present); if there is only one side, it is src, and dst is
12 * NULL; if sides exist but are empty (i.e., the refspec either starts or ends
13 * with ':'), the corresponding side is "".
0becfec5
JK
14 *
15 * remote_find_tracking(), given a remote and a struct refspec_item with either src
16 * or dst filled out, will fill out the other such that the result is in the
17 * "fetch" specification for the remote (note that this evaluates patterns and
18 * returns a single result).
19 */
0ad4a5ff 20struct refspec_item {
ec0cb496
BW
21 unsigned force : 1;
22 unsigned pattern : 1;
23 unsigned matching : 1;
24 unsigned exact_sha1 : 1;
c0192df6 25 unsigned negative : 1;
ec0cb496
BW
26
27 char *src;
28 char *dst;
fe17a259
JK
29
30 char *raw;
ec0cb496
BW
31};
32
7b24a170
MS
33struct string_list;
34
3809633d
TB
35#define REFSPEC_INIT_FETCH { .fetch = 1 }
36#define REFSPEC_INIT_PUSH { .fetch = 0 }
6d4c0578 37
d27eb356 38/**
0becfec5 39 * An array of strings can be parsed into a struct refspec using
d27eb356 40 * parse_fetch_refspec() or parse_push_refspec().
d27eb356 41 */
6d4c0578
BW
42struct refspec {
43 struct refspec_item *items;
44 int alloc;
45 int nr;
46
3809633d 47 unsigned fetch : 1;
6d4c0578
BW
48};
49
459e54b5
TB
50int refspec_item_init_fetch(struct refspec_item *item, const char *refspec);
51int refspec_item_init_push(struct refspec_item *item, const char *refspec);
6d4c0578 52void refspec_item_clear(struct refspec_item *item);
0baad1f3
TB
53void refspec_init_fetch(struct refspec *rs);
54void refspec_init_push(struct refspec *rs);
6d4c0578 55void refspec_append(struct refspec *rs, const char *refspec);
1af8b8c0
RS
56__attribute__((format (printf,2,3)))
57void refspec_appendf(struct refspec *rs, const char *fmt, ...);
6d4c0578
BW
58void refspec_appendn(struct refspec *rs, const char **refspecs, int nr);
59void refspec_clear(struct refspec *rs);
60
c8fa9efe
BW
61int valid_fetch_refspec(const char *refspec);
62
873cd28a 63struct strvec;
6c301adb
JN
64/*
65 * Determine what <prefix> values to pass to the peer in ref-prefix lines
5db92105 66 * (see linkgit:gitprotocol-v2[5]).
6c301adb 67 */
6373cb59 68void refspec_ref_prefixes(const struct refspec *rs,
873cd28a 69 struct strvec *ref_prefixes);
6373cb59 70
230d022f
MS
71int refname_matches_negative_refspec_item(const char *refname, struct refspec *rs);
72
73/*
044b6f04
MS
74 * Checks if a refname matches a globbing refspec pattern.
75 * If replacement is provided, computes the corresponding mapped refname.
76 * Returns 1 if refname matches pattern, 0 otherwise.
230d022f 77 */
044b6f04
MS
78int match_refname_with_pattern(const char *pattern, const char *refname,
79 const char *replacement, char **result);
230d022f 80
7b24a170
MS
81/*
82 * Queries a refspec for a match and updates the query item.
83 * Returns 0 on success, -1 if no match is found or negative refspec matches.
84 */
85int refspec_find_match(struct refspec *rs, struct refspec_item *query);
86
87/*
88 * Queries a refspec for all matches and appends results to the provided string
89 * list.
90 */
91void refspec_find_all_matches(struct refspec *rs,
92 struct refspec_item *query,
93 struct string_list *results);
94
d549b6c9
MS
95/*
96 * Remove all entries in the input list which match any negative refspec in
97 * the refspec list.
98 */
99struct ref *apply_negative_refspecs(struct ref *ref_map, struct refspec *rs);
100
101/*
102 * Search for a refspec that matches the given name and return the
103 * corresponding destination (dst) if a match is found, NULL otherwise.
104 */
105char *apply_refspecs(struct refspec *rs, const char *name);
106
ec0cb496 107#endif /* REFSPEC_H */