Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
7d079413
Commit
7d079413
authored
Dec 19, 2017
by
Carson Howard
Committed by
Carson Howard
Mar 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: ls-files: remove dependency on git_array
parent
ee144650
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
11 deletions
+12
-11
examples/ls-files.c
+12
-11
No files found.
examples/ls-files.c
View file @
7d079413
...
@@ -28,7 +28,8 @@
...
@@ -28,7 +28,8 @@
typedef
struct
{
typedef
struct
{
int
error_unmatch
;
int
error_unmatch
;
git_array_t
(
char
*
)
files
;
char
*
files
[
1024
];
int
file_count
;
}
ls_options
;
}
ls_options
;
/* Print a usage message for the program. */
/* Print a usage message for the program. */
...
@@ -46,10 +47,8 @@ static int parse_options(ls_options *opts, int argc, char *argv[])
...
@@ -46,10 +47,8 @@ static int parse_options(ls_options *opts, int argc, char *argv[])
{
{
int
parsing_files
=
0
;
int
parsing_files
=
0
;
int
i
;
int
i
;
char
**
file
;
memset
(
opts
,
0
,
sizeof
(
ls_options
));
memset
(
opts
,
0
,
sizeof
(
ls_options
));
git_array_init
(
opts
->
files
);
if
(
argc
<
2
)
if
(
argc
<
2
)
return
0
;
return
0
;
...
@@ -61,9 +60,12 @@ static int parse_options(ls_options *opts, int argc, char *argv[])
...
@@ -61,9 +60,12 @@ static int parse_options(ls_options *opts, int argc, char *argv[])
if
(
a
[
0
]
!=
'-'
||
parsing_files
)
{
if
(
a
[
0
]
!=
'-'
||
parsing_files
)
{
parsing_files
=
1
;
parsing_files
=
1
;
file
=
git_array_alloc
(
opts
->
files
);
// watch for overflows (just in case)
GITERR_CHECK_ALLOC
(
file
);
if
(
opts
->
file_count
==
1024
)
{
*
file
=
a
;
break
;
}
opts
->
files
[
opts
->
file_count
++
]
=
a
;
}
else
if
(
!
strcmp
(
a
,
"--"
))
{
}
else
if
(
!
strcmp
(
a
,
"--"
))
{
parsing_files
=
1
;
parsing_files
=
1
;
}
else
if
(
!
strcmp
(
a
,
"--error-unmatch"
))
{
}
else
if
(
!
strcmp
(
a
,
"--error-unmatch"
))
{
...
@@ -79,12 +81,12 @@ static int parse_options(ls_options *opts, int argc, char *argv[])
...
@@ -79,12 +81,12 @@ static int parse_options(ls_options *opts, int argc, char *argv[])
static
int
print_paths
(
ls_options
*
opts
,
git_index
*
index
)
static
int
print_paths
(
ls_options
*
opts
,
git_index
*
index
)
{
{
size_
t
i
;
in
t
i
;
const
git_index_entry
*
entry
;
const
git_index_entry
*
entry
;
/* loop through the files found in the args and print them if they exist */
/* loop through the files found in the args and print them if they exist */
for
(
i
=
0
;
i
<
git_array_size
(
opts
->
files
)
;
++
i
)
{
for
(
i
=
0
;
i
<
opts
->
file_count
;
++
i
)
{
const
char
*
path
=
*
(
char
**
)
git_array_get
(
opts
->
files
,
i
)
;
const
char
*
path
=
opts
->
files
[
i
]
;
entry
=
git_index_get_bypath
(
index
,
path
,
GIT_INDEX_STAGE_NORMAL
);
entry
=
git_index_get_bypath
(
index
,
path
,
GIT_INDEX_STAGE_NORMAL
);
if
(
!
entry
&&
opts
->
error_unmatch
)
{
if
(
!
entry
&&
opts
->
error_unmatch
)
{
...
@@ -121,7 +123,7 @@ int main(int argc, char *argv[])
...
@@ -121,7 +123,7 @@ int main(int argc, char *argv[])
goto
cleanup
;
goto
cleanup
;
/* if there are files explicitly listed by the user, we need to treat this command differently */
/* if there are files explicitly listed by the user, we need to treat this command differently */
if
(
git_array_size
(
opts
.
files
)
>
0
)
{
if
(
opts
.
file_count
>
0
)
{
error
=
print_paths
(
&
opts
,
index
);
error
=
print_paths
(
&
opts
,
index
);
}
else
{
}
else
{
entry_count
=
git_index_entrycount
(
index
);
entry_count
=
git_index_entrycount
(
index
);
...
@@ -133,7 +135,6 @@ int main(int argc, char *argv[])
...
@@ -133,7 +135,6 @@ int main(int argc, char *argv[])
}
}
cleanup:
cleanup:
git_array_clear
(
opts
.
files
);
git_index_free
(
index
);
git_index_free
(
index
);
git_repository_free
(
repo
);
git_repository_free
(
repo
);
git_libgit2_shutdown
();
git_libgit2_shutdown
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment