提交 471fd3fe 编写于 作者: J Jeff King 提交者: Junio C Hamano

match_explicit_lhs: allow a "verify only" mode

The match_explicit_lhs function has all of the logic
necessary to verify the refspecs without actually doing any
work. This patch lets callers pass a NULL "match" pointer to
indicate they want a "verify only" operation.

For the most part, we just need to avoid writing to the NULL
pointer. However, we also have to refactor the
try_explicit_object_name sub-function; it indicates success by
allocating and returning a new ref. Instead, we give it an
"out" parameter for the match and return a numeric status.
Signed-off-by: NJeff King <peff@peff.net>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 f7ade3d3
......@@ -1031,10 +1031,12 @@ int count_refspec_match(const char *pattern,
}
}
if (!matched) {
if (matched_ref)
*matched_ref = matched_weak;
return weak_match;
}
else {
if (matched_ref)
*matched_ref = matched;
return match;
}
......@@ -1055,18 +1057,25 @@ static struct ref *alloc_delete_ref(void)
return ref;
}
static struct ref *try_explicit_object_name(const char *name)
static int try_explicit_object_name(const char *name,
struct ref **match)
{
unsigned char sha1[20];
struct ref *ref;
if (!*name)
return alloc_delete_ref();
if (!*name) {
if (match)
*match = alloc_delete_ref();
return 0;
}
if (get_sha1(name, sha1))
return NULL;
ref = alloc_ref(name);
hashcpy(ref->new_sha1, sha1);
return ref;
return -1;
if (match) {
*match = alloc_ref(name);
hashcpy((*match)->new_sha1, sha1);
}
return 0;
}
static struct ref *make_linked_ref(const char *name, struct ref ***tail)
......@@ -1103,6 +1112,7 @@ static int match_explicit_lhs(struct ref *src,
{
switch (count_refspec_match(rs->src, src, match)) {
case 1:
if (allocated_match)
*allocated_match = 0;
return 0;
case 0:
......@@ -1110,9 +1120,9 @@ static int match_explicit_lhs(struct ref *src,
* not a reference name. :refs/other is a
* way to delete 'other' ref at the remote end.
*/
*match = try_explicit_object_name(rs->src);
if (!*match)
if (try_explicit_object_name(rs->src, match) < 0)
return error("src refspec %s does not match any.", rs->src);
if (allocated_match)
*allocated_match = 1;
return 0;
default:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册