Skip to content

Commit 16a4372

Browse files
chriscoolgitster
authored andcommitted
promisor-remote: refactor has_control_char()
In a future commit we are going to check if some strings contain control characters, so let's refactor the logic to do that in a new has_control_char() helper function. It cleans up the code a bit anyway. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 64f0f6b commit 16a4372

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

promisor-remote.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,14 @@ static int all_fields_match(struct promisor_info *advertised,
642642
return 1;
643643
}
644644

645+
static bool has_control_char(const char *s)
646+
{
647+
for (const char *c = s; *c; c++)
648+
if (iscntrl(*c))
649+
return true;
650+
return false;
651+
}
652+
645653
static int should_accept_remote(enum accept_promisor accept,
646654
struct promisor_info *advertised,
647655
struct string_list *config_info)
@@ -772,18 +780,14 @@ static bool valid_filter(const char *filter, const char *remote_name)
772780
return !res;
773781
}
774782

775-
/* Check that a token doesn't contain any control character */
776783
static bool valid_token(const char *token, const char *remote_name)
777784
{
778-
const char *c = token;
779-
780-
for (; *c; c++)
781-
if (iscntrl(*c)) {
782-
warning(_("invalid token '%s' for remote '%s' "
783-
"will not be stored"),
784-
token, remote_name);
785-
return false;
786-
}
785+
if (has_control_char(token)) {
786+
warning(_("invalid token '%s' for remote '%s' "
787+
"will not be stored"),
788+
token, remote_name);
789+
return false;
790+
}
787791

788792
return true;
789793
}

0 commit comments

Comments
 (0)