-
Notifications
You must be signed in to change notification settings - Fork 2.6k
examples: ls-files: add ls-files to list paths in the index #4380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
30e919c
examples: ls-files: list files
991fc08
examples: ls-files: show current files in index
52d83dd
examples: ls-files: handle --error-unmatch
cd39273
examples: ls-files: fix style and refactor
cjhoward92 d2f99e0
examples: ls-files: fix compile error
cjhoward92 37cbc3e
examples: ls-files: build file list with array
3f64a9d
examples: ls-files: use git_array_t to handle files
e866116
examples: ls-files: address PR and style
ee14465
examples: ls-files: fix build error
7d07941
test: ls-files: remove dependency on git_array
29ca3f3
examples: ls-files: update print_paths to print all cases
d7394c3
examples: ls-files: print entry path only when entry is found
8aa437e
tests: ls-files: use puts instead of printf and fix typos
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
examples: ls-files: build file list with array
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| * - default ls-files behavior | ||
| * | ||
| * | ||
| * This currently does not support: | ||
| * - anything else | ||
| * | ||
| * | ||
| */ | ||
|
|
||
| typedef struct { | ||
|
|
@@ -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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could also be scoped to the loop |
||
|
|
@@ -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; | ||
|
|
@@ -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 */ | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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-unmatchoption."