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
29ca3f33
Commit
29ca3f33
authored
Jan 06, 2018
by
Carson Howard
Committed by
Carson Howard
Mar 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples: ls-files: update print_paths to print all cases
parent
7d079413
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
19 deletions
+17
-19
examples/ls-files.c
+17
-19
No files found.
examples/ls-files.c
View file @
29ca3f33
...
...
@@ -29,10 +29,9 @@
typedef
struct
{
int
error_unmatch
;
char
*
files
[
1024
];
in
t
file_count
;
size_
t
file_count
;
}
ls_options
;
/* Print a usage message for the program. */
static
void
usage
(
const
char
*
message
,
const
char
*
arg
)
{
if
(
message
&&
arg
)
...
...
@@ -60,9 +59,10 @@ static int parse_options(ls_options *opts, int argc, char *argv[])
if
(
a
[
0
]
!=
'-'
||
parsing_files
)
{
parsing_files
=
1
;
/
/ watch for overflows (just in case)
/
* watch for overflows (just in case) */
if
(
opts
->
file_count
==
1024
)
{
break
;
fprintf
(
stderr
,
"ls-files can only support 1024 files at this time.
\n
"
);
return
-
1
;
}
opts
->
files
[
opts
->
file_count
++
]
=
a
;
...
...
@@ -81,8 +81,19 @@ static int parse_options(ls_options *opts, int argc, char *argv[])
static
int
print_paths
(
ls_options
*
opts
,
git_index
*
index
)
{
in
t
i
;
size_
t
i
;
const
git_index_entry
*
entry
;
/* if there are not files explicitly listed by the user print all entries in the index */
if
(
opts
->
file_count
==
0
)
{
size_t
entry_count
=
git_index_entrycount
(
index
);
for
(
i
=
0
;
i
<
entry_count
;
i
++
)
{
entry
=
git_index_get_byindex
(
index
,
i
);
printf
(
"%s
\n
"
,
entry
->
path
);
}
return
0
;
}
/* loop through the files found in the args and print them if they exist */
for
(
i
=
0
;
i
<
opts
->
file_count
;
++
i
)
{
...
...
@@ -106,9 +117,6 @@ int main(int argc, char *argv[])
ls_options
opts
;
git_repository
*
repo
=
NULL
;
git_index
*
index
=
NULL
;
const
git_index_entry
*
entry
;
size_t
entry_count
;
size_t
i
=
0
;
int
error
;
if
((
error
=
parse_options
(
&
opts
,
argc
,
argv
))
<
0
)
...
...
@@ -122,17 +130,7 @@ int main(int argc, char *argv[])
if
((
error
=
git_repository_index
(
&
index
,
repo
))
<
0
)
goto
cleanup
;
/* if there are files explicitly listed by the user, we need to treat this command differently */
if
(
opts
.
file_count
>
0
)
{
error
=
print_paths
(
&
opts
,
index
);
}
else
{
entry_count
=
git_index_entrycount
(
index
);
for
(
i
=
0
;
i
<
entry_count
;
i
++
)
{
entry
=
git_index_get_byindex
(
index
,
i
);
printf
(
"%s
\n
"
,
entry
->
path
);
}
}
error
=
print_paths
(
&
opts
,
index
);
cleanup:
git_index_free
(
index
);
...
...
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