Skip to content
Merged
Prev Previous commit
Next Next commit
examples: ls-files: build file list with array
  • Loading branch information
Carson Howard authored and Carson Howard committed Mar 27, 2018
commit 37cbc3eaf4f853de9e2b2d36563c11bac4af7a3b
18 changes: 9 additions & 9 deletions examples/ls-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
* This example demonstrates the libgit2 index APIs to roughly
* simulate the output of `git ls-files`.
* `git ls-files` has many options and this currently does not show them.
*
*
* `git ls-files` base command shows all paths in the index at that time.
* This includes staged and committed files, but unstaged files will not display.
*
*
* This currently supports:
* - The --error-unmatch paramter with the same output as the git cli
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit: there's one space too much here. I'd also put that whole supported/unsupported thing a little bit shorter: "This currently only supports default behaviour and the --error-unmatch option."

* - default ls-files behavior
*
*
* This currently does not support:
* - anything else
*
*
*/

typedef struct {
Expand Down Expand Up @@ -84,7 +84,7 @@ static int parse_options(ls_options *opts, int argc, char *argv[])
return 0;
}

static int print_paths(ls_options *opts, git_index *index)
static int print_paths(ls_options *opts, git_index *index)
{
int i;
const git_index_entry *entry;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be scoped to the loop

Expand All @@ -109,8 +109,8 @@ static int print_paths(ls_options *opts, git_index *index)
int main(int argc, char *argv[])
{
ls_options opts;
git_repository *repo;
git_index *index;
git_repository *repo = NULL;
git_index *index = NULL;
const git_index_entry *entry;
size_t entry_count;
size_t i = 0;
Expand All @@ -121,10 +121,10 @@ int main(int argc, char *argv[])

git_libgit2_init();

if ((error = git_repository_open_ext(&repo, ".", 0, NULL)) != 0)
if ((error = git_repository_open_ext(&repo, ".", 0, NULL)) < 0)
goto cleanup;

if ((error = git_repository_index(&index, repo)) != 0)
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 */
Expand Down