summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-05-18 13:21:42 -0700
committerJunio C Hamano <gitster@pobox.com>2016-05-18 14:02:53 -0700
commited8641e2e0d37aef0d45e99a688e031cb7b81368 (patch)
treec5cf70c7215f6db97b6c16cb0649acf3fbbfa5c6
parent3ed0a91ba0c426bc4ce13b49dae30ea4ac989b70 (diff)
downloadgit-ed8641e2e0d37aef0d45e99a688e031cb7b81368.tar.gz
attr: add counted string version of git_attr()
Often a potential caller has <name, namelen> pair that represents the name it wants to create an attribute out of. When name[namelen] is not NUL, the caller has to xmemdupz() only to call git_attr(). Add git_attr_counted() that takes such a counted string instead of "const char *name". Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--attr.c8
-rw-r--r--attr.h5
2 files changed, 8 insertions, 5 deletions
diff --git a/attr.c b/attr.c
index eeb29e6a9a..7f20e2124d 100644
--- a/attr.c
+++ b/attr.c
@@ -78,7 +78,7 @@ static int invalid_attr_name(const char *name, int namelen)
return 0;
}
-static struct git_attr *git_attr_internal(const char *name, int len)
+struct git_attr *git_attr_counted(const char *name, size_t len)
{
unsigned hval = hash_name(name, len);
unsigned pos = hval % HASHSIZE;
@@ -109,7 +109,7 @@ static struct git_attr *git_attr_internal(const char *name, int len)
struct git_attr *git_attr(const char *name)
{
- return git_attr_internal(name, strlen(name));
+ return git_attr_counted(name, strlen(name));
}
/* What does a matched pattern decide? */
@@ -199,7 +199,7 @@ static const char *parse_attr(const char *src, int lineno, const char *cp,
else {
e->setto = xmemdupz(equals + 1, ep - equals - 1);
}
- e->attr = git_attr_internal(cp, len);
+ e->attr = git_attr_counted(cp, len);
}
return ep + strspn(ep, blank);
}
@@ -254,7 +254,7 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
sizeof(struct attr_state) * num_attr +
(is_macro ? 0 : namelen + 1));
if (is_macro) {
- res->u.attr = git_attr_internal(name, namelen);
+ res->u.attr = git_attr_counted(name, namelen);
res->u.attr->maybe_macro = 1;
} else {
char *p = (char *)&(res->state[num_attr]);
diff --git a/attr.h b/attr.h
index 4a4ac76379..78d6d5ac9d 100644
--- a/attr.h
+++ b/attr.h
@@ -8,7 +8,10 @@ struct git_attr;
* Given a string, return the gitattribute object that
* corresponds to it.
*/
-struct git_attr *git_attr(const char *);
+extern struct git_attr *git_attr(const char *);
+
+/* The same, but with counted string */
+extern struct git_attr *git_attr_counted(const char *, size_t);
/* Internal use */
extern const char git_attr__true[];