summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorCarson Howard <carsonh@axosoft.com>2018-03-27 07:21:02 -0700
committerCarson Howard <carsonh@axosoft.com>2018-03-27 07:27:22 -0700
commitd7394c36678473b7db47854fdba39356c7a56e15 (patch)
tree0ada1188f5797ea30e05c0232ad1d64a4f93a8ea /examples
parent29ca3f33b4a8a553c4cfca873ffd34ed2685acbe (diff)
downloadlibgit2-d7394c36678473b7db47854fdba39356c7a56e15.tar.gz
examples: ls-files: print entry path only when entry is found
Diffstat (limited to 'examples')
-rw-r--r--examples/ls-files.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/examples/ls-files.c b/examples/ls-files.c
index af0dc8fff..40f9085c1 100644
--- a/examples/ls-files.c
+++ b/examples/ls-files.c
@@ -83,7 +83,7 @@ static int print_paths(ls_options *opts, git_index *index)
{
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);
@@ -99,14 +99,13 @@ static int print_paths(ls_options *opts, git_index *index)
for (i = 0; i < opts->file_count; ++i) {
const char *path = opts->files[i];
- entry = git_index_get_bypath(index, path, GIT_INDEX_STAGE_NORMAL);
- if (!entry && opts->error_unmatch) {
+ if ((entry = git_index_get_bypath(index, path, GIT_INDEX_STAGE_NORMAL)) != NULL) {
+ printf("%s\n", path);
+ } else if (opts->error_unmatch) {
fprintf(stderr, "error: pathspec '%s' did not match any file(s) known to git.\n", path);
fprintf(stderr, "Did you forget to 'git add'?\n");
return -1;
}
-
- printf("%s\n", path);
}
return 0;