mirror of
https://github.com/git/git.git
synced 2026-03-04 14:37:35 +01:00
Merge branch 'jk/ref-filter-lrstrip-optim' into next
Code clean-up. * jk/ref-filter-lrstrip-optim: ref-filter: clarify lstrip/rstrip component counting
This commit is contained in:
13
ref-filter.c
13
ref-filter.c
@@ -2176,19 +2176,20 @@ static inline char *copy_advance(char *dst, const char *src)
|
||||
static int normalize_component_count(const char *refname, int len)
|
||||
{
|
||||
if (len < 0) {
|
||||
int i;
|
||||
const char *p = refname;
|
||||
int slashes = 0;
|
||||
|
||||
for (const char *p = refname; *p; p++) {
|
||||
if (*p == '/')
|
||||
slashes++;
|
||||
}
|
||||
|
||||
/* Find total no of '/' separated path-components */
|
||||
for (i = 0; p[i]; p[i] == '/' ? i++ : *p++)
|
||||
;
|
||||
/*
|
||||
* The number of components we need to strip is now
|
||||
* the total minus the components to be left (Plus one
|
||||
* because we count the number of '/', but the number
|
||||
* of components is one more than the no of '/').
|
||||
*/
|
||||
len = i + len + 1;
|
||||
len = slashes + len + 1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user