From: Junio C Hamano Date: Fri, 19 Sep 2014 18:38:35 +0000 (-0700) Subject: Merge branch 'rs/more-uses-of-skip-prefix' X-Git-Tag: v2.2.0-rc0~115 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/4fc72d91066d8fcb6de25596429fd603d3d91d79?hp=-c Merge branch 'rs/more-uses-of-skip-prefix' Code clean-up. * rs/more-uses-of-skip-prefix: pack-write: simplify index_pack_lockfile using skip_prefix() and xstrfmt() connect: simplify check_ref() using skip_prefix() and starts_with() --- 4fc72d91066d8fcb6de25596429fd603d3d91d79 diff --combined connect.c index 87b5202632,34193e5e22..d47d0ec604 --- a/connect.c +++ b/connect.c @@@ -13,28 -13,24 +13,24 @@@ static char *server_capabilities; static const char *parse_feature_value(const char *, const char *, int *); - static int check_ref(const char *name, int len, unsigned int flags) + static int check_ref(const char *name, unsigned int flags) { if (!flags) return 1; - if (len < 5 || memcmp(name, "refs/", 5)) + if (!skip_prefix(name, "refs/", &name)) return 0; - /* Skip the "refs/" part */ - name += 5; - len -= 5; - /* REF_NORMAL means that we don't want the magic fake tag refs */ if ((flags & REF_NORMAL) && check_refname_format(name, 0)) return 0; /* REF_HEADS means that we want regular branch heads */ - if ((flags & REF_HEADS) && !memcmp(name, "heads/", 6)) + if ((flags & REF_HEADS) && starts_with(name, "heads/")) return 1; /* REF_TAGS means that we want tags */ - if ((flags & REF_TAGS) && !memcmp(name, "tags/", 5)) + if ((flags & REF_TAGS) && starts_with(name, "tags/")) return 1; /* All type bits clear means that we are ok with anything */ @@@ -43,7 -39,7 +39,7 @@@ int check_ref_type(const struct ref *ref, int flags) { - return check_ref(ref->name, strlen(ref->name), flags); + return check_ref(ref->name, flags); } static void die_initial_contact(int got_at_least_one_head) @@@ -167,7 -163,7 +163,7 @@@ struct ref **get_remote_heads(int in, c continue; } - if (!check_ref(name, name_len, flags)) + if (!check_ref(name, flags)) continue; ref = alloc_ref(buffer + 41); hashcpy(ref->old_sha1, old_sha1); @@@ -537,8 -533,7 +533,8 @@@ static struct child_process *git_proxy_ get_host_and_port(&host, &port); - proxy = xcalloc(1, sizeof(*proxy)); + proxy = xmalloc(sizeof(*proxy)); + child_process_init(proxy); argv_array_push(&proxy->args, git_proxy_command); argv_array_push(&proxy->args, host); argv_array_push(&proxy->args, port); @@@ -640,7 -635,7 +636,7 @@@ static enum protocol parse_connect_url( return protocol; } -static struct child_process no_fork; +static struct child_process no_fork = CHILD_PROCESS_INIT; /* * This returns a dummy child_process if the transport protocol does not @@@ -695,8 -690,7 +691,8 @@@ struct child_process *git_connect(int f target_host, 0); free(target_host); } else { - conn = xcalloc(1, sizeof(*conn)); + conn = xmalloc(sizeof(*conn)); + child_process_init(conn); strbuf_addstr(&cmd, prog); strbuf_addch(&cmd, ' ');