84f50bed8c9078f4678c9be92a76f5a762ee6185
1#include "test-tool.h"
2#include "git-compat-util.h"
3#include "strbuf.h"
4#include "iterator.h"
5#include "dir-iterator.h"
6
7/* Argument is a directory path to iterate over */
8int cmd__dir_iterator(int argc, const char **argv)
9{
10 struct strbuf path = STRBUF_INIT;
11 struct dir_iterator *diter;
12
13 if (argc < 2)
14 die("BUG: test-dir-iterator needs one argument");
15
16 strbuf_add(&path, argv[1], strlen(argv[1]));
17
18 diter = dir_iterator_begin(path.buf);
19
20 while (dir_iterator_advance(diter) == ITER_OK) {
21 if (S_ISDIR(diter->st.st_mode))
22 printf("[d] ");
23 else if (S_ISREG(diter->st.st_mode))
24 printf("[f] ");
25 else
26 printf("[?] ");
27
28 printf("(%s) [%s] %s\n", diter->relative_path, diter->basename,
29 diter->path.buf);
30 }
31
32 return 0;
33}