diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-10-18 09:06:48 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-10-18 09:16:36 +0200 |
commit | ca2d34a8445bfa34e6184fa0315b6185cce0f834 (patch) | |
tree | bf65182ea9be087b70e8125ee6bde9e2fc1ad151 /src/stash.c | |
parent | ef5a3851fdece852569ffebf3537883223744a7a (diff) | |
download | libgit2-ca2d34a8445bfa34e6184fa0315b6185cce0f834.tar.gz |
stash: modernize code style of `git_stash_save`
The code style of `git_stash_save` doesn't really match our current
coding style. Update it to match our current policies more closely.
Diffstat (limited to 'src/stash.c')
-rw-r--r-- | src/stash.c | 47 |
1 files changed, 15 insertions, 32 deletions
diff --git a/src/stash.c b/src/stash.c index aa3cecf6e..d619045fc 100644 --- a/src/stash.c +++ b/src/stash.c @@ -497,10 +497,7 @@ static int is_dirty_cb(const char *path, unsigned int status, void *payload) return GIT_PASSTHROUGH; } -static int ensure_there_are_changes_to_stash( - git_repository *repo, - bool include_untracked_files, - bool include_ignored_files) +static int ensure_there_are_changes_to_stash(git_repository *repo, uint32_t flags) { int error; git_status_options opts = GIT_STATUS_OPTIONS_INIT; @@ -508,11 +505,11 @@ static int ensure_there_are_changes_to_stash( opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR; opts.flags = GIT_STATUS_OPT_EXCLUDE_SUBMODULES; - if (include_untracked_files) + if (flags & GIT_STASH_INCLUDE_UNTRACKED) opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS; - if (include_ignored_files) + if (flags & GIT_STASH_INCLUDE_IGNORED) opts.flags |= GIT_STATUS_OPT_INCLUDE_IGNORED | GIT_STATUS_OPT_RECURSE_IGNORED_DIRS; @@ -527,20 +524,14 @@ static int ensure_there_are_changes_to_stash( return error; } -static int reset_index_and_workdir( - git_repository *repo, - git_commit *commit, - bool remove_untracked, - bool remove_ignored) +static int reset_index_and_workdir(git_repository *repo, git_commit *commit, uint32_t flags) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; opts.checkout_strategy = GIT_CHECKOUT_FORCE; - - if (remove_untracked) + if (flags & GIT_STASH_INCLUDE_UNTRACKED) opts.checkout_strategy |= GIT_CHECKOUT_REMOVE_UNTRACKED; - - if (remove_ignored) + if (flags & GIT_STASH_INCLUDE_IGNORED) opts.checkout_strategy |= GIT_CHECKOUT_REMOVE_IGNORED; return git_checkout_tree(repo, (git_object *)commit, &opts); @@ -566,31 +557,26 @@ int git_stash_save( if ((error = retrieve_base_commit_and_message(&b_commit, &msg, repo)) < 0) goto cleanup; - if ((error = ensure_there_are_changes_to_stash( - repo, - (flags & GIT_STASH_INCLUDE_UNTRACKED) != 0, - (flags & GIT_STASH_INCLUDE_IGNORED) != 0)) < 0) + if ((error = ensure_there_are_changes_to_stash(repo, flags)) < 0) goto cleanup; if ((error = git_repository_index(&index, repo)) < 0) goto cleanup; - if ((error = commit_index( - &i_commit, repo, index, stasher, git_buf_cstr(&msg), b_commit)) < 0) + if ((error = commit_index(&i_commit, repo, index, stasher, + git_buf_cstr(&msg), b_commit)) < 0) goto cleanup; if ((flags & (GIT_STASH_INCLUDE_UNTRACKED | GIT_STASH_INCLUDE_IGNORED)) && - (error = commit_untracked( - &u_commit, repo, stasher, git_buf_cstr(&msg), - i_commit, flags)) < 0) + (error = commit_untracked(&u_commit, repo, stasher, + git_buf_cstr(&msg), i_commit, flags)) < 0) goto cleanup; if ((error = prepare_worktree_commit_message(&msg, message)) < 0) goto cleanup; - if ((error = commit_worktree( - out, repo, stasher, git_buf_cstr(&msg), - i_commit, b_commit, u_commit)) < 0) + if ((error = commit_worktree(out, repo, stasher, git_buf_cstr(&msg), + i_commit, b_commit, u_commit)) < 0) goto cleanup; git_buf_rtrim(&msg); @@ -598,11 +584,8 @@ int git_stash_save( if ((error = update_reflog(out, repo, git_buf_cstr(&msg))) < 0) goto cleanup; - if ((error = reset_index_and_workdir( - repo, - ((flags & GIT_STASH_KEEP_INDEX) != 0) ? i_commit : b_commit, - (flags & GIT_STASH_INCLUDE_UNTRACKED) != 0, - (flags & GIT_STASH_INCLUDE_IGNORED) != 0)) < 0) + if ((error = reset_index_and_workdir(repo, (flags & GIT_STASH_KEEP_INDEX) ? i_commit : b_commit, + flags)) < 0) goto cleanup; cleanup: |