Commit ca2d34a8 by Patrick Steinhardt

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.
parent ef5a3851
...@@ -497,10 +497,7 @@ static int is_dirty_cb(const char *path, unsigned int status, void *payload) ...@@ -497,10 +497,7 @@ static int is_dirty_cb(const char *path, unsigned int status, void *payload)
return GIT_PASSTHROUGH; return GIT_PASSTHROUGH;
} }
static int ensure_there_are_changes_to_stash( static int ensure_there_are_changes_to_stash(git_repository *repo, uint32_t flags)
git_repository *repo,
bool include_untracked_files,
bool include_ignored_files)
{ {
int error; int error;
git_status_options opts = GIT_STATUS_OPTIONS_INIT; git_status_options opts = GIT_STATUS_OPTIONS_INIT;
...@@ -508,11 +505,11 @@ static int ensure_there_are_changes_to_stash( ...@@ -508,11 +505,11 @@ static int ensure_there_are_changes_to_stash(
opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR; opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
opts.flags = GIT_STATUS_OPT_EXCLUDE_SUBMODULES; opts.flags = GIT_STATUS_OPT_EXCLUDE_SUBMODULES;
if (include_untracked_files) if (flags & GIT_STASH_INCLUDE_UNTRACKED)
opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED | opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS; GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
if (include_ignored_files) if (flags & GIT_STASH_INCLUDE_IGNORED)
opts.flags |= GIT_STATUS_OPT_INCLUDE_IGNORED | opts.flags |= GIT_STATUS_OPT_INCLUDE_IGNORED |
GIT_STATUS_OPT_RECURSE_IGNORED_DIRS; GIT_STATUS_OPT_RECURSE_IGNORED_DIRS;
...@@ -527,20 +524,14 @@ static int ensure_there_are_changes_to_stash( ...@@ -527,20 +524,14 @@ static int ensure_there_are_changes_to_stash(
return error; return error;
} }
static int reset_index_and_workdir( static int reset_index_and_workdir(git_repository *repo, git_commit *commit, uint32_t flags)
git_repository *repo,
git_commit *commit,
bool remove_untracked,
bool remove_ignored)
{ {
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_FORCE; opts.checkout_strategy = GIT_CHECKOUT_FORCE;
if (flags & GIT_STASH_INCLUDE_UNTRACKED)
if (remove_untracked)
opts.checkout_strategy |= GIT_CHECKOUT_REMOVE_UNTRACKED; opts.checkout_strategy |= GIT_CHECKOUT_REMOVE_UNTRACKED;
if (flags & GIT_STASH_INCLUDE_IGNORED)
if (remove_ignored)
opts.checkout_strategy |= GIT_CHECKOUT_REMOVE_IGNORED; opts.checkout_strategy |= GIT_CHECKOUT_REMOVE_IGNORED;
return git_checkout_tree(repo, (git_object *)commit, &opts); return git_checkout_tree(repo, (git_object *)commit, &opts);
...@@ -566,31 +557,26 @@ int git_stash_save( ...@@ -566,31 +557,26 @@ int git_stash_save(
if ((error = retrieve_base_commit_and_message(&b_commit, &msg, repo)) < 0) if ((error = retrieve_base_commit_and_message(&b_commit, &msg, repo)) < 0)
goto cleanup; goto cleanup;
if ((error = ensure_there_are_changes_to_stash( if ((error = ensure_there_are_changes_to_stash(repo, flags)) < 0)
repo,
(flags & GIT_STASH_INCLUDE_UNTRACKED) != 0,
(flags & GIT_STASH_INCLUDE_IGNORED) != 0)) < 0)
goto cleanup; goto cleanup;
if ((error = git_repository_index(&index, repo)) < 0) if ((error = git_repository_index(&index, repo)) < 0)
goto cleanup; goto cleanup;
if ((error = commit_index( if ((error = commit_index(&i_commit, repo, index, stasher,
&i_commit, repo, index, stasher, git_buf_cstr(&msg), b_commit)) < 0) git_buf_cstr(&msg), b_commit)) < 0)
goto cleanup; goto cleanup;
if ((flags & (GIT_STASH_INCLUDE_UNTRACKED | GIT_STASH_INCLUDE_IGNORED)) && if ((flags & (GIT_STASH_INCLUDE_UNTRACKED | GIT_STASH_INCLUDE_IGNORED)) &&
(error = commit_untracked( (error = commit_untracked(&u_commit, repo, stasher,
&u_commit, repo, stasher, git_buf_cstr(&msg), git_buf_cstr(&msg), i_commit, flags)) < 0)
i_commit, flags)) < 0)
goto cleanup; goto cleanup;
if ((error = prepare_worktree_commit_message(&msg, message)) < 0) if ((error = prepare_worktree_commit_message(&msg, message)) < 0)
goto cleanup; goto cleanup;
if ((error = commit_worktree( if ((error = commit_worktree(out, repo, stasher, git_buf_cstr(&msg),
out, repo, stasher, git_buf_cstr(&msg), i_commit, b_commit, u_commit)) < 0)
i_commit, b_commit, u_commit)) < 0)
goto cleanup; goto cleanup;
git_buf_rtrim(&msg); git_buf_rtrim(&msg);
...@@ -598,11 +584,8 @@ int git_stash_save( ...@@ -598,11 +584,8 @@ int git_stash_save(
if ((error = update_reflog(out, repo, git_buf_cstr(&msg))) < 0) if ((error = update_reflog(out, repo, git_buf_cstr(&msg))) < 0)
goto cleanup; goto cleanup;
if ((error = reset_index_and_workdir( if ((error = reset_index_and_workdir(repo, (flags & GIT_STASH_KEEP_INDEX) ? i_commit : b_commit,
repo, flags)) < 0)
((flags & GIT_STASH_KEEP_INDEX) != 0) ? i_commit : b_commit,
(flags & GIT_STASH_INCLUDE_UNTRACKED) != 0,
(flags & GIT_STASH_INCLUDE_IGNORED) != 0)) < 0)
goto cleanup; goto cleanup;
cleanup: cleanup:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment