Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
find-git-repos
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
STEVAN Antoine
find-git-repos
Commits
65e03d9a
Verified
Commit
65e03d9a
authored
4 months ago
by
STEVAN Antoine
Browse files
Options
Downloads
Patches
Plain Diff
add main
parent
affe3f99
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.c
+115
-0
115 additions, 0 deletions
main.c
with
115 additions
and
0 deletions
main.c
0 → 100644
+
115
−
0
View file @
65e03d9a
#include
<dirent.h>
#include
<errno.h>
#include
<stdbool.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
typedef
struct
{
char
**
items
;
size_t
size
;
size_t
capacity
;
}
da_str_t
;
#define da_append(da, item) \
do { \
if ((da)->size >= (da)->capacity) { \
if ((da)->capacity == 0) { \
(da)->capacity = 256; \
} \
(da)->items = \
realloc((da)->items, (da)->capacity * sizeof(*(da)->items)); \
} \
(da)->items[(da)->size++] = item; \
} while (0)
#define da_foreach(Type, it, da) \
for (Type *it = (da)->items; it < (da)->items + (da)->size; ++it)
#ifdef DEBUG
#define log_infoln(fmt, ...) printf("INFO: " fmt "\n", ##__VA_ARGS__)
#else // DEBUG
#define log_infoln(fmt, ...) ((void)0)
#endif // DEBUG
da_str_t
ls
(
const
char
*
path
)
{
DIR
*
dp
=
opendir
(
path
);
if
(
dp
==
NULL
)
{
if
(
errno
==
ENOTDIR
)
{
return
(
da_str_t
){
0
};
}
perror
(
"opendir"
);
exit
(
EXIT_FAILURE
);
}
da_str_t
files
=
{
0
};
struct
dirent
*
entry
;
while
((
entry
=
readdir
(
dp
)))
{
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
)
{
continue
;
}
da_append
(
&
files
,
entry
->
d_name
);
}
closedir
(
dp
);
return
files
;
}
char
*
concat
(
const
char
*
s1
,
const
char
*
s2
)
{
char
*
result
=
malloc
(
strlen
(
s1
)
+
strlen
(
s2
)
+
1
);
strcpy
(
result
,
s1
);
strcat
(
result
,
s2
);
return
result
;
}
da_str_t
find_git
(
const
char
*
path
)
{
log_infoln
(
"current: %s"
,
path
);
da_str_t
next
=
ls
(
path
);
if
(
next
.
size
==
0
)
{
log_infoln
(
"
\t
file or empty directory"
);
return
(
da_str_t
){
0
};
}
bool
is_repo
=
false
;
da_foreach
(
char
*
,
f
,
&
next
)
{
log_infoln
(
"
\t\t
next: %s"
,
*
f
);
if
(
strcmp
(
*
f
,
".git"
)
==
0
)
{
is_repo
=
true
;
}
}
da_str_t
repos
=
{
0
};
if
(
is_repo
)
{
log_infoln
(
"
\t
repo"
);
da_append
(
&
repos
,
(
char
*
)
path
);
return
repos
;
}
log_infoln
(
"
\t
NOT a repo"
);
da_foreach
(
char
*
,
f
,
&
next
)
{
char
*
g
=
malloc
(
sizeof
(
f
)
+
1
);
strcpy
(
g
,
*
f
);
da_str_t
res
=
find_git
(
concat
(
concat
(
path
,
"/"
),
g
));
da_foreach
(
char
*
,
r
,
&
res
)
{
da_append
(
&
repos
,
*
r
);
}
}
return
repos
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
// da_str_t files = ls((argc > 1) ? argv[1] : ".");
// da_foreach(char *, f, &files) { printf("%s\n", *f); }
// printf(" %zu\n", files.size);
da_str_t
repos
=
find_git
((
argc
>
1
)
?
argv
[
1
]
:
"."
);
printf
(
"repos found:
\n
"
);
da_foreach
(
char
*
,
r
,
&
repos
)
{
printf
(
"
\t
%s
\n
"
,
*
r
);
}
printf
(
" %zu
\n
"
,
repos
.
size
);
return
EXIT_SUCCESS
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment