Teach prepare_attr_stack() to figure out dirlen itself

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Aug 4, 2011 at 06:36 UTC a872701755347efe22be998d1e39f454fc422ff2
1 file changed +11 -10
attr.c
+11 -10
@@ -535,11 +535,18 @@ static void bootstrap_attr_stack(void)
535 }
536 }
537
538 -static void prepare_attr_stack(const char *path, int dirlen)
538 +static void prepare_attr_stack(const char *path)
539 {
540 struct attr_stack *elem, *info;
541 - int len;
541 + int dirlen, len;
542 struct strbuf pathbuf;
543 + const char *cp;
544 +
545 + cp = strrchr(path, '/');
546 + if (!cp)
547 + dirlen = 0;
548 + else
549 + dirlen = cp - path;
550
551 strbuf_init(&pathbuf, dirlen+2+strlen(GITATTRIBUTES_FILE));
552
@@ -709,20 +716,14 @@ static int macroexpand_one(int attr_nr, int rem)
716 int git_checkattr(const char *path, int num, struct git_attr_check *check)
717 {
718 struct attr_stack *stk;
712 - const char *cp;
713 - int dirlen, pathlen, i, rem;
719 + int pathlen, i, rem;
720
721 bootstrap_attr_stack();
722 for (i = 0; i < attr_nr; i++)
723 check_all_attr[i].value = ATTR__UNKNOWN;
724
725 pathlen = strlen(path);
720 - cp = strrchr(path, '/');
721 - if (!cp)
722 - dirlen = 0;
723 - else
724 - dirlen = cp - path;
725 - prepare_attr_stack(path, dirlen);
726 + prepare_attr_stack(path);
727 rem = attr_nr;
728 for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)
729 rem = fill(path, pathlen, stk, rem);