git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
cef513ad88d242b188d48cecd8dfb0b7b7d2ed54 blob 3891 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
 
#include "cache.h"
#include "refs.h"
#include "refspec.h"

static struct refspec_item s_tag_refspec = {
	0,
	1,
	0,
	0,
	"refs/tags/*",
	"refs/tags/*"
};

/* See TAG_REFSPEC for the string version */
const struct refspec_item *tag_refspec = &s_tag_refspec;

/*
 * Parses 'refspec' and populates 'rs'.  returns 1 if successful and 0 if the
 * refspec is invalid.
 */
static int parse_refspec(struct refspec_item *rs, const char *refspec, int fetch)
{
	size_t llen;
	int is_glob;
	const char *lhs, *rhs;
	int flags;

	is_glob = 0;

	lhs = refspec;
	if (*lhs == '+') {
		rs->force = 1;
		lhs++;
	}

	rhs = strrchr(lhs, ':');

	/*
	 * Before going on, special case ":" (or "+:") as a refspec
	 * for pushing matching refs.
	 */
	if (!fetch && rhs == lhs && rhs[1] == '\0') {
		rs->matching = 1;
		return 1;
	}

	if (rhs) {
		size_t rlen = strlen(++rhs);
		is_glob = (1 <= rlen && strchr(rhs, '*'));
		rs->dst = xstrndup(rhs, rlen);
	}

	llen = (rhs ? (rhs - lhs - 1) : strlen(lhs));
	if (1 <= llen && memchr(lhs, '*', llen)) {
		if ((rhs && !is_glob) || (!rhs && fetch))
			return 0;
		is_glob = 1;
	} else if (rhs && is_glob) {
		return 0;
	}

	rs->pattern = is_glob;
	rs->src = xstrndup(lhs, llen);
	flags = REFNAME_ALLOW_ONELEVEL | (is_glob ? REFNAME_REFSPEC_PATTERN : 0);

	if (fetch) {
		struct object_id unused;

		/* LHS */
		if (!*rs->src)
			; /* empty is ok; it means "HEAD" */
		else if (llen == GIT_SHA1_HEXSZ && !get_oid_hex(rs->src, &unused))
			rs->exact_sha1 = 1; /* ok */
		else if (!check_refname_format(rs->src, flags))
			; /* valid looking ref is ok */
		else
			return 0;
		/* RHS */
		if (!rs->dst)
			; /* missing is ok; it is the same as empty */
		else if (!*rs->dst)
			; /* empty is ok; it means "do not store" */
		else if (!check_refname_format(rs->dst, flags))
			; /* valid looking ref is ok */
		else
			return 0;
	} else {
		/*
		 * LHS
		 * - empty is allowed; it means delete.
		 * - when wildcarded, it must be a valid looking ref.
		 * - otherwise, it must be an extended SHA-1, but
		 *   there is no existing way to validate this.
		 */
		if (!*rs->src)
			; /* empty is ok */
		else if (is_glob) {
			if (check_refname_format(rs->src, flags))
				return 0;
		}
		else
			; /* anything goes, for now */
		/*
		 * RHS
		 * - missing is allowed, but LHS then must be a
		 *   valid looking ref.
		 * - empty is not allowed.
		 * - otherwise it must be a valid looking ref.
		 */
		if (!rs->dst) {
			if (check_refname_format(rs->src, flags))
				return 0;
		} else if (!*rs->dst) {
			return 0;
		} else {
			if (check_refname_format(rs->dst, flags))
				return 0;
		}
	}

	return 1;
}

static struct refspec_item *parse_refspec_internal(int nr_refspec, const char **refspec, int fetch, int verify)
{
	int i;
	struct refspec_item *rs = xcalloc(nr_refspec, sizeof(*rs));

	for (i = 0; i < nr_refspec; i++) {
		if (!parse_refspec(&rs[i], refspec[i], fetch))
			goto invalid;
	}

	return rs;

 invalid:
	if (verify) {
		/*
		 * nr_refspec must be greater than zero and i must be valid
		 * since it is only possible to reach this point from within
		 * the for loop above.
		 */
		free_refspec(i+1, rs);
		return NULL;
	}
	die("Invalid refspec '%s'", refspec[i]);
}

int valid_fetch_refspec(const char *fetch_refspec_str)
{
	struct refspec_item *refspec;

	refspec = parse_refspec_internal(1, &fetch_refspec_str, 1, 1);
	free_refspec(1, refspec);
	return !!refspec;
}

struct refspec_item *parse_fetch_refspec(int nr_refspec, const char **refspec)
{
	return parse_refspec_internal(nr_refspec, refspec, 1, 0);
}

struct refspec_item *parse_push_refspec(int nr_refspec, const char **refspec)
{
	return parse_refspec_internal(nr_refspec, refspec, 0, 0);
}

void free_refspec(int nr_refspec, struct refspec_item *refspec)
{
	int i;

	if (!refspec)
		return;

	for (i = 0; i < nr_refspec; i++) {
		free(refspec[i].src);
		free(refspec[i].dst);
	}
	free(refspec);
}
debug log:

solving cef513ad8 ...
found cef513ad8 in https://public-inbox.org/git/20180514215626.164960-4-bmwill@google.com/
found 3cfcbd37d in https://public-inbox.org/git/20180514215626.164960-3-bmwill@google.com/
found ecb0bdff3 in https://public-inbox.org/git/20180514215626.164960-2-bmwill@google.com/

applying [1/3] https://public-inbox.org/git/20180514215626.164960-2-bmwill@google.com/
diff --git a/refspec.c b/refspec.c
new file mode 100644
index 000000000..ecb0bdff3


applying [2/3] https://public-inbox.org/git/20180514215626.164960-3-bmwill@google.com/
diff --git a/refspec.c b/refspec.c
index ecb0bdff3..3cfcbd37d 100644


applying [3/3] https://public-inbox.org/git/20180514215626.164960-4-bmwill@google.com/
diff --git a/refspec.c b/refspec.c
index 3cfcbd37d..cef513ad8 100644

Checking patch refspec.c...
3:174: new blank line at EOF.
+
Applied patch refspec.c cleanly.
Checking patch refspec.c...
Applied patch refspec.c cleanly.
Checking patch refspec.c...
Applied patch refspec.c cleanly.
warning: 1 line adds whitespace errors.

index at:
100644 cef513ad88d242b188d48cecd8dfb0b7b7d2ed54	refspec.c

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox