Commit 3bc3ed80 by Russell Belfer

Improve and comment git_ignore__pop_dir

This just cleans up the improved logic for popping ignore dirs
and documents why the complex behavior is needed.
parent ba8b8c04
...@@ -168,15 +168,25 @@ int git_ignore__pop_dir(git_ignores *ign) ...@@ -168,15 +168,25 @@ int git_ignore__pop_dir(git_ignores *ign)
{ {
if (ign->ign_path.length > 0) { if (ign->ign_path.length > 0) {
git_attr_file *file = git_vector_last(&ign->ign_path); git_attr_file *file = git_vector_last(&ign->ign_path);
size_t keylen = strlen(file->key); const char *start, *end, *scan;
size_t keylen;
while (keylen && file->key[keylen] != '/')
keylen--; /* - ign->dir looks something like "a/b" (or "a/b/c/d")
keylen -= 1; /* because we will skip "0#" prefix */ * - file->key looks something like "0#a/b/.gitignore
*
if (ign->dir.size > keylen && * We are popping the last directory off ign->dir. We also want to
!memcmp(ign->dir.ptr + ign->dir.size - keylen, * remove the file from the vector if the directory part of the key
file->key + 2, keylen)) * matches the ign->dir path. We need to test if the "a/b" part of
* the file key matches the path we are about to pop.
*/
for (start = end = scan = &file->key[2]; *scan; ++scan)
if (*scan == '/')
end = scan; /* point 'end' to last '/' in key */
keylen = (end - start) + 1;
if (ign->dir.size >= keylen &&
!memcmp(ign->dir.ptr + ign->dir.size - keylen, start, keylen))
git_vector_pop(&ign->ign_path); git_vector_pop(&ign->ign_path);
git_buf_rtruncate_at_char(&ign->dir, '/'); git_buf_rtruncate_at_char(&ign->dir, '/');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment