Skip to content

Commit

Permalink
daemon: use skip_prefix to avoid magic numbers
Browse files Browse the repository at this point in the history
Like earlier cases, we can use skip_prefix to avoid magic
numbers that must match the length of starts_with prefixes.
However, the numbers are a little more complicated here, as
we keep parsing past the prefix. We can solve it by keeping
a running pointer as we parse; its final value is the
location we want.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jun 20, 2014
1 parent 97313be commit d12c24d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,15 +626,16 @@ static int execute(void)

for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
struct daemon_service *s = &(daemon_service[i]);
int namelen = strlen(s->name);
if (starts_with(line, "git-") &&
!strncmp(s->name, line + 4, namelen) &&
line[namelen + 4] == ' ') {
const char *arg;

if (skip_prefix(line, "git-", &arg) &&
skip_prefix(arg, s->name, &arg) &&
*arg++ == ' ') {
/*
* Note: The directory here is probably context sensitive,
* and might depend on the actual service being performed.
*/
return run_service(line + namelen + 5, s);
return run_service(arg, s);
}
}

Expand Down

0 comments on commit d12c24d

Please sign in to comment.