]> git.ipfire.org Git - thirdparty/git.git/blame_incremental - refspec.h
The sixth batch
[thirdparty/git.git] / refspec.h
... / ...
CommitLineData
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 */
20struct 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
33struct 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 */
42struct refspec {
43 struct refspec_item *items;
44 int alloc;
45 int nr;
46
47 unsigned fetch : 1;
48};
49
50int refspec_item_init_fetch(struct refspec_item *item, const char *refspec);
51int refspec_item_init_push(struct refspec_item *item, const char *refspec);
52void refspec_item_clear(struct refspec_item *item);
53void refspec_init_fetch(struct refspec *rs);
54void refspec_init_push(struct refspec *rs);
55void refspec_append(struct refspec *rs, const char *refspec);
56__attribute__((format (printf,2,3)))
57void refspec_appendf(struct refspec *rs, const char *fmt, ...);
58void refspec_appendn(struct refspec *rs, const char **refspecs, int nr);
59void refspec_clear(struct refspec *rs);
60
61int valid_fetch_refspec(const char *refspec);
62
63struct strvec;
64/*
65 * Determine what <prefix> values to pass to the peer in ref-prefix lines
66 * (see linkgit:gitprotocol-v2[5]).
67 */
68void refspec_ref_prefixes(const struct refspec *rs,
69 struct strvec *ref_prefixes);
70
71int 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 */
78int 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 */
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
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
107#endif /* REFSPEC_H */