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