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
f41e7d2b
Verified
Commit
f41e7d2b
authored
3 months ago
by
STEVAN Antoine
Browse files
Options
Downloads
Patches
Plain Diff
free
parent
c0d4f99d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.c
+20
-9
20 additions, 9 deletions
main.c
with
20 additions
and
9 deletions
main.c
+
20
−
9
View file @
f41e7d2b
...
...
@@ -28,12 +28,15 @@ typedef struct {
#define da_foreach(Type, it, da) \
for (Type *it = (da)->items; it < (da)->items + (da)->size; ++it)
#define da_free(da) free((da)->items)
#ifdef DEBUG
#define log_infoln(fmt, ...) printf("INFO: " fmt "\n", ##__VA_ARGS__)
#else // DEBUG
#define log_infoln(fmt, ...) ((void)0)
#endif // DEBUG
// list all files and directories at a given path
da_str_t
ls
(
const
char
*
path
)
{
DIR
*
dp
=
opendir
(
path
);
if
(
dp
==
NULL
)
{
...
...
@@ -50,7 +53,6 @@ da_str_t ls(const char *path) {
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
)
{
continue
;
}
// FIXME: memory leak here due to concat
da_append
(
&
files
,
strdup
(
entry
->
d_name
));
}
...
...
@@ -90,17 +92,24 @@ da_str_t find_git(const char *path) {
if
(
is_repo
)
{
log_infoln
(
"
\t
repo"
);
da_append
(
&
repos
,
(
char
*
)
path
);
return
repos
;
}
}
else
{
log_infoln
(
"
\t
NOT a repo"
);
da_foreach
(
char
*
,
f
,
&
next
)
{
// FIXME: memory leak here due to concat
da_str_t
res
=
find_git
(
concat
(
concat
(
path
,
"/"
),
*
f
));
char
*
foo
=
concat
(
path
,
"/"
);
char
*
bar
=
concat
(
foo
,
*
f
);
da_str_t
res
=
find_git
(
bar
);
da_foreach
(
char
*
,
r
,
&
res
)
{
da_append
(
&
repos
,
*
r
);
}
da_free
(
&
res
);
free
(
bar
);
free
(
foo
);
}
}
da_foreach
(
char
*
,
f
,
&
next
)
{
free
(
*
f
);
}
da_free
(
&
next
);
return
repos
;
}
...
...
@@ -108,5 +117,7 @@ int main(int argc, char *argv[]) {
da_str_t
repos
=
find_git
((
argc
>
1
)
?
argv
[
1
]
:
"."
);
da_foreach
(
char
*
,
r
,
&
repos
)
{
printf
(
"%s
\n
"
,
*
r
);
}
da_free
(
&
repos
);
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