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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
diff --git a/src/stash.c b/src/stash.c
index aa3cecf..d619045 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: