MCPcopy Index your code
hub / github.com/git/git / cmd__dir_iterator

Function cmd__dir_iterator

t/helper/test-dir-iterator.c:20–64  ·  view source on GitHub ↗

* usage: * tool-test dir-iterator [--pedantic] directory_path */

Source from the content-addressed store, hash-verified

18 * tool-test dir-iterator [--pedantic] directory_path
19 */
20int cmd__dir_iterator(int argc, const char **argv)
21{
22 struct dir_iterator *diter;
23 unsigned int flags = 0;
24 int iter_status;
25
26 for (++argv, --argc; *argv && starts_with(*argv, "--"); ++argv, --argc) {
27 if (strcmp(*argv, "--pedantic") == 0)
28 flags |= DIR_ITERATOR_PEDANTIC;
29 else
30 die("invalid option '%s'", *argv);
31 }
32
33 if (!*argv || argc != 1)
34 die("dir-iterator needs exactly one non-option argument");
35
36 diter = dir_iterator_begin(*argv, flags);
37
38 if (!diter) {
39 printf("dir_iterator_begin failure: %s\n", error_name(errno));
40 exit(EXIT_FAILURE);
41 }
42
43 while ((iter_status = dir_iterator_advance(diter)) == ITER_OK) {
44 if (S_ISDIR(diter->st.st_mode))
45 printf("[d] ");
46 else if (S_ISREG(diter->st.st_mode))
47 printf("[f] ");
48 else if (S_ISLNK(diter->st.st_mode))
49 printf("[s] ");
50 else
51 printf("[?] ");
52
53 printf("(%s) [%s] %s\n", diter->relative_path, diter->basename,
54 diter->path.buf);
55 }
56 dir_iterator_free(diter);
57
58 if (iter_status != ITER_DONE) {
59 printf("dir_iterator_advance failure\n");
60 return 1;
61 }
62
63 return 0;
64}

Callers

nothing calls this directly

Calls 6

starts_withFunction · 0.85
dir_iterator_beginFunction · 0.85
error_nameFunction · 0.85
dir_iterator_advanceFunction · 0.85
dir_iterator_freeFunction · 0.85
dieFunction · 0.50

Tested by

no test coverage detected