diff options
author | Russell Belfer <rb@github.com> | 2014-04-22 21:51:54 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-04-22 21:51:54 -0700 |
commit | 37da368545b28157e625212e8009ec041cc4a4ea (patch) | |
tree | 9fac6b09448e10224191507e764263374ed36083 /src/diff.c | |
parent | 3c1aa4c110d2d4c8c3d941b0e4ba66357172da2e (diff) | |
download | libgit2-37da368545b28157e625212e8009ec041cc4a4ea.tar.gz |
Make checkout match diff for untracked/ignored dir
When diff finds an untracked directory, it emulates Git behavior
by looking inside the directory to see if there are any untracked
items inside it. If there are only ignored items inside the dir,
then diff considers it ignored, even if there is no direct ignore
rule for it.
Checkout was not copying this behavior - when it found an untracked
directory, it just treated it as untracked. Unfortunately, when
combined with GIT_CHECKOUT_REMOVE_UNTRACKED, this made is seem that
checkout (and stash, which uses checkout) was removing ignored
items when you had only asked it to remove untracked ones.
This commit moves the logic for advancing past an untracked dir
while scanning for non-ignored items into an iterator helper fn,
and uses that for both diff and checkout.
Diffstat (limited to 'src/diff.c')
-rw-r--r-- | src/diff.c | 77 |
1 files changed, 7 insertions, 70 deletions
diff --git a/src/diff.c b/src/diff.c index 0d1aed4ad..f1c1b0543 100644 --- a/src/diff.c +++ b/src/diff.c @@ -784,72 +784,6 @@ static bool entry_is_prefixed( item->path[pathlen] == '/'); } -static int diff_scan_inside_untracked_dir( - git_diff *diff, diff_in_progress *info, git_delta_t *delta_type) -{ - int error = 0; - git_buf base = GIT_BUF_INIT; - bool is_ignored; - - *delta_type = GIT_DELTA_IGNORED; - git_buf_sets(&base, info->nitem->path); - - /* advance into untracked directory */ - if ((error = git_iterator_advance_into(&info->nitem, info->new_iter)) < 0) { - - /* skip ahead if empty */ - if (error == GIT_ENOTFOUND) { - giterr_clear(); - error = git_iterator_advance(&info->nitem, info->new_iter); - } - - goto done; - } - - /* look for actual untracked file */ - while (info->nitem != NULL && - !diff->pfxcomp(info->nitem->path, git_buf_cstr(&base))) { - is_ignored = git_iterator_current_is_ignored(info->new_iter); - - /* need to recurse into non-ignored directories */ - if (!is_ignored && S_ISDIR(info->nitem->mode)) { - error = git_iterator_advance_into(&info->nitem, info->new_iter); - - if (!error) - continue; - else if (error == GIT_ENOTFOUND) { - error = 0; - is_ignored = true; /* treat empty as ignored */ - } else - break; /* real error, must stop */ - } - - /* found a non-ignored item - treat parent dir as untracked */ - if (!is_ignored) { - *delta_type = GIT_DELTA_UNTRACKED; - break; - } - - if ((error = git_iterator_advance(&info->nitem, info->new_iter)) < 0) - break; - } - - /* finish off scan */ - while (info->nitem != NULL && - !diff->pfxcomp(info->nitem->path, git_buf_cstr(&base))) { - if ((error = git_iterator_advance(&info->nitem, info->new_iter)) < 0) - break; - } - -done: - git_buf_free(&base); - - if (error == GIT_ITEROVER) - error = 0; - - return error; -} - static int handle_unmatched_new_item( git_diff *diff, diff_in_progress *info) { @@ -905,6 +839,7 @@ static int handle_unmatched_new_item( DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS)) { git_diff_delta *last; + bool ignored; /* attempt to insert record for this directory */ if ((error = diff_delta__from_one(diff, delta_type, nitem)) != 0) @@ -916,11 +851,13 @@ static int handle_unmatched_new_item( return git_iterator_advance(&info->nitem, info->new_iter); /* iterate into dir looking for an actual untracked file */ - if (diff_scan_inside_untracked_dir(diff, info, &delta_type) < 0) - return -1; + if ((error = git_iterator_advance_over_and_check_ignored( + &info->nitem, &ignored, info->new_iter)) < 0 && + error != GIT_ITEROVER) + return error; - /* it iteration changed delta type, the update the record */ - if (delta_type == GIT_DELTA_IGNORED) { + /* it iteration only found ignored items, update the record */ + if (ignored) { last->status = GIT_DELTA_IGNORED; /* remove the record if we don't want ignored records */ |