]> git.ipfire.org Git - thirdparty/git.git/blob - refspec.h
8b04f9995ef2a8bb518d155f195899c8af0284e9
[thirdparty/git.git] / refspec.h
1 #ifndef REFSPEC_H
2 #define REFSPEC_H
3
4 #define TAG_REFSPEC "refs/tags/*:refs/tags/*"
5
6 /**
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 "".
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 */
20 struct refspec_item {
21 unsigned force : 1;
22 unsigned pattern : 1;
23 unsigned matching : 1;
24 unsigned exact_sha1 : 1;
25 unsigned negative : 1;
26
27 char *src;
28 char *dst;
29
30 char *raw;
31 };
32
33 struct string_list;
34
35 #define REFSPEC_INIT_FETCH { .fetch = 1 }
36 #define REFSPEC_INIT_PUSH { .fetch = 0 }
37
38 /**
39 * An array of strings can be parsed into a struct refspec using
40 * parse_fetch_refspec() or parse_push_refspec().
41 */
42 struct refspec {
43 struct refspec_item *items;
44 int alloc;
45 int nr;
46
47 unsigned fetch : 1;
48 };
49
50 int refspec_item_init_fetch(struct refspec_item *item, const char *refspec);
51 int refspec_item_init_push(struct refspec_item *item, const char *refspec);
52 void refspec_item_clear(struct refspec_item *item);
53 void refspec_init_fetch(struct refspec *rs);
54 void refspec_init_push(struct refspec *rs);
55 void refspec_append(struct refspec *rs, const char *refspec);
56 __attribute__((format (printf,2,3)))
57 void refspec_appendf(struct refspec *rs, const char *fmt, ...);
58 void refspec_appendn(struct refspec *rs, const char **refspecs, int nr);
59 void refspec_clear(struct refspec *rs);
60
61 int valid_fetch_refspec(const char *refspec);
62
63 struct strvec;
64 /*
65 * Determine what <prefix> values to pass to the peer in ref-prefix lines
66 * (see linkgit:gitprotocol-v2[5]).
67 */
68 void refspec_ref_prefixes(const struct refspec *rs,
69 struct strvec *ref_prefixes);
70
71 int refname_matches_negative_refspec_item(const char *refname, struct refspec *rs);
72
73 /*
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.
77 */
78 int match_refname_with_pattern(const char *pattern, const char *refname,
79 const char *replacement, char **result);
80
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 */
85 int 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 */
91 void refspec_find_all_matches(struct refspec *rs,
92 struct refspec_item *query,
93 struct string_list *results);
94
95 /*
96 * Remove all entries in the input list which match any negative refspec in
97 * the refspec list.
98 */
99 struct 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 */
105 char *apply_refspecs(struct refspec *rs, const char *name);
106
107 #endif /* REFSPEC_H */