1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-09 01:16:11 +02:00

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()
This commit is contained in:
Junio C Hamano 2014-09-19 11:38:35 -07:00
commit 4fc72d9106
2 changed files with 11 additions and 16 deletions

View File

@ -13,28 +13,24 @@
static char *server_capabilities; static char *server_capabilities;
static const char *parse_feature_value(const char *, const char *, int *); 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) if (!flags)
return 1; return 1;
if (len < 5 || memcmp(name, "refs/", 5)) if (!skip_prefix(name, "refs/", &name))
return 0; return 0;
/* Skip the "refs/" part */
name += 5;
len -= 5;
/* REF_NORMAL means that we don't want the magic fake tag refs */ /* REF_NORMAL means that we don't want the magic fake tag refs */
if ((flags & REF_NORMAL) && check_refname_format(name, 0)) if ((flags & REF_NORMAL) && check_refname_format(name, 0))
return 0; return 0;
/* REF_HEADS means that we want regular branch heads */ /* 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; return 1;
/* REF_TAGS means that we want tags */ /* 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; return 1;
/* All type bits clear means that we are ok with anything */ /* All type bits clear means that we are ok with anything */
@ -43,7 +39,7 @@ static int check_ref(const char *name, int len, unsigned int flags)
int check_ref_type(const struct ref *ref, int flags) 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) static void die_initial_contact(int got_at_least_one_head)
@ -167,7 +163,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
continue; continue;
} }
if (!check_ref(name, name_len, flags)) if (!check_ref(name, flags))
continue; continue;
ref = alloc_ref(buffer + 41); ref = alloc_ref(buffer + 41);
hashcpy(ref->old_sha1, old_sha1); hashcpy(ref->old_sha1, old_sha1);

View File

@ -288,13 +288,12 @@ char *index_pack_lockfile(int ip_out)
* case, we need it to remove the corresponding .keep file * case, we need it to remove the corresponding .keep file
* later on. If we don't get that then tough luck with it. * later on. If we don't get that then tough luck with it.
*/ */
if (read_in_full(ip_out, packname, 46) == 46 && packname[45] == '\n' && if (read_in_full(ip_out, packname, 46) == 46 && packname[45] == '\n') {
memcmp(packname, "keep\t", 5) == 0) { const char *name;
char path[PATH_MAX];
packname[45] = 0; packname[45] = 0;
snprintf(path, sizeof(path), "%s/pack/pack-%s.keep", if (skip_prefix(packname, "keep\t", &name))
get_object_directory(), packname + 5); return xstrfmt("%s/pack/pack-%s.keep",
return xstrdup(path); get_object_directory(), name);
} }
return NULL; return NULL;
} }