Skip to content

Commit

Permalink
attr.c::path_matches(): the basename is part of the pathname
Browse files Browse the repository at this point in the history
The function takes two strings (pathname and basename) as if they
are independent strings, but in reality, the latter is always
pointing into a substring in the former.

Clarify this relationship by expressing the latter as an offset into
the former.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Mar 26, 2013
1 parent 9db9eec commit bd2f371
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ static void prepare_attr_stack(const char *path, int dirlen)
}

static int path_matches(const char *pathname, int pathlen,
const char *basename,
int basename_offset,
const struct pattern *pat,
const char *base, int baselen)
{
Expand All @@ -667,8 +667,8 @@ static int path_matches(const char *pathname, int pathlen,
return 0;

if (pat->flags & EXC_FLAG_NODIR) {
return match_basename(basename,
pathlen - (basename - pathname),
return match_basename(pathname + basename_offset,
pathlen - basename_offset,
pattern, prefix,
pat->patternlen, pat->flags);
}
Expand Down Expand Up @@ -701,7 +701,7 @@ static int fill_one(const char *what, struct match_attr *a, int rem)
return rem;
}

static int fill(const char *path, int pathlen, const char *basename,
static int fill(const char *path, int pathlen, int basename_offset,
struct attr_stack *stk, int rem)
{
int i;
Expand All @@ -711,7 +711,7 @@ static int fill(const char *path, int pathlen, const char *basename,
struct match_attr *a = stk->attrs[i];
if (a->is_macro)
continue;
if (path_matches(path, pathlen, basename,
if (path_matches(path, pathlen, basename_offset,
&a->u.pat, base, stk->originlen))
rem = fill_one("fill", a, rem);
}
Expand Down Expand Up @@ -750,18 +750,19 @@ static void collect_all_attrs(const char *path)
{
struct attr_stack *stk;
int i, pathlen, rem, dirlen;
const char *basename, *cp, *last_slash = NULL;
const char *cp, *last_slash = NULL;
int basename_offset;

for (cp = path; *cp; cp++) {
if (*cp == '/' && cp[1])
last_slash = cp;
}
pathlen = cp - path;
if (last_slash) {
basename = last_slash + 1;
basename_offset = last_slash + 1 - path;
dirlen = last_slash - path;
} else {
basename = path;
basename_offset = 0;
dirlen = 0;
}

Expand All @@ -771,7 +772,7 @@ static void collect_all_attrs(const char *path)

rem = attr_nr;
for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)
rem = fill(path, pathlen, basename, stk, rem);
rem = fill(path, pathlen, basename_offset, stk, rem);
}

int git_check_attr(const char *path, int num, struct git_attr_check *check)
Expand Down

0 comments on commit bd2f371

Please sign in to comment.