+
+ if (prune_empty_dirs && no_dups) {
+ int j, prev_depth = 0;
+
+ prev_i = 0; /* It's OK that this isn't really true. */
+
+ for (i = flist->low; i <= flist->high; i++) {
+ struct file_struct *fp, *file = flist->files[i];
+
+ /* This temporarily abuses the dir.depth value for a
+ * directory that is in a chain that might get pruned.
+ * We restore the old value if it gets a reprieve. */
+ if (S_ISDIR(file->mode) && file->dir.depth) {
+ /* Dump empty dirs when coming back down. */
+ for (j = prev_depth; j >= file->dir.depth; j--) {
+ fp = flist->files[prev_i];
+ if (fp->dir.depth >= 0)
+ break;
+ prev_i = -fp->dir.depth-1;
+ clear_file(fp, flist);
+ }
+ prev_depth = file->dir.depth;
+ if (is_excluded(f_name(file, fbuf), 1,
+ ALL_FILTERS)) {
+ /* Keep dirs through this dir. */
+ for (j = prev_depth-1; ; j--) {
+ fp = flist->files[prev_i];
+ if (fp->dir.depth >= 0)
+ break;
+ prev_i = -fp->dir.depth-1;
+ fp->dir.depth = j;
+ }
+ } else
+ file->dir.depth = -prev_i-1;
+ prev_i = i;
+ } else {
+ /* Keep dirs through this non-dir. */
+ for (j = prev_depth; ; j--) {
+ fp = flist->files[prev_i];
+ if (fp->dir.depth >= 0)
+ break;
+ prev_i = -fp->dir.depth-1;
+ fp->dir.depth = j;
+ }
+ }
+ }
+ /* Dump empty all remaining empty dirs. */
+ while (1) {
+ struct file_struct *fp = flist->files[prev_i];
+ if (fp->dir.depth >= 0)
+ break;
+ prev_i = -fp->dir.depth-1;
+ clear_file(fp, flist);
+ }
+
+ for (i = flist->low; i <= flist->high; i++) {
+ if (flist->files[i]->basename)
+ break;
+ }
+ flist->low = i;
+ for (i = flist->high; i >= flist->low; i--) {
+ if (flist->files[i]->basename)
+ break;
+ }
+ flist->high = i;
+ }