diff options
| author | Russell Belfer <arrbee@arrbee.com> | 2012-03-23 09:26:09 -0700 |
|---|---|---|
| committer | Russell Belfer <arrbee@arrbee.com> | 2012-03-23 09:26:09 -0700 |
| commit | 4b136a94d948e62634633092c9d1052c4b074e6c (patch) | |
| tree | 15ea545035aa86f064ff62c755f24a5c80f28035 /src | |
| parent | 98c4613e2d79f73d5168582c23e87faebc69787b (diff) | |
| download | libgit2-4b136a94d948e62634633092c9d1052c4b074e6c.tar.gz | |
Fix crash in new status and add recurse option
This fixes the bug that @nulltoken found (thank you!) where
if there were untracked directories alphabetically after the
last tracked item, the diff implementation would deref a NULL
pointer.
The fix involved the code which decides if it is necessary
to recurse into a directory in the working dir, so it was
easy to add a new option `GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS`
to control if the contents of untracked directories should be
included in status.
Diffstat (limited to 'src')
| -rw-r--r-- | src/diff.c | 7 | ||||
| -rw-r--r-- | src/status.c | 4 |
2 files changed, 10 insertions, 1 deletions
diff --git a/src/diff.c b/src/diff.c index 3f8041af2..d5a841c3b 100644 --- a/src/diff.c +++ b/src/diff.c @@ -439,7 +439,12 @@ static int diff_from_iterators( is_ignored = git_iterator_current_is_ignored(new); if (S_ISDIR(nitem->mode)) { - if (git__prefixcmp(oitem->path, nitem->path) == 0) { + /* recurse into directory if explicitly requested or + * if there are tracked items inside the directory + */ + if ((diff->opts.flags & GIT_DIFF_RECURSE_UNTRACKED_DIRS) || + (oitem && git__prefixcmp(oitem->path, nitem->path) == 0)) + { if (is_ignored) ignore_prefix = nitem->path; if (git_iterator_advance_into_directory(new, &nitem) < 0) diff --git a/src/status.c b/src/status.c index 0c7a62254..a0716e949 100644 --- a/src/status.c +++ b/src/status.c @@ -137,12 +137,16 @@ int git_status_foreach_ext( } memset(&diffopt, 0, sizeof(diffopt)); + memcpy(&diffopt.pathspec, &opts->pathspec, sizeof(diffopt.pathspec)); + if ((opts->flags & GIT_STATUS_OPT_INCLUDE_UNTRACKED) != 0) diffopt.flags = diffopt.flags | GIT_DIFF_INCLUDE_UNTRACKED; if ((opts->flags & GIT_STATUS_OPT_INCLUDE_IGNORED) != 0) diffopt.flags = diffopt.flags | GIT_DIFF_INCLUDE_IGNORED; if ((opts->flags & GIT_STATUS_OPT_INCLUDE_UNMODIFIED) != 0) diffopt.flags = diffopt.flags | GIT_DIFF_INCLUDE_UNMODIFIED; + if ((opts->flags & GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS) != 0) + diffopt.flags = diffopt.flags | GIT_DIFF_RECURSE_UNTRACKED_DIRS; /* TODO: support EXCLUDE_SUBMODULES flag */ if (show != GIT_STATUS_SHOW_WORKDIR_ONLY && |
