Skip to content

Commit ca2d34a

Browse files
committed
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 parent ef5a385 commit ca2d34a

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

src/stash.c

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -497,22 +497,19 @@ static int is_dirty_cb(const char *path, unsigned int status, void *payload)
497497
return GIT_PASSTHROUGH;
498498
}
499499

500-
static int ensure_there_are_changes_to_stash(
501-
git_repository *repo,
502-
bool include_untracked_files,
503-
bool include_ignored_files)
500+
static int ensure_there_are_changes_to_stash(git_repository *repo, uint32_t flags)
504501
{
505502
int error;
506503
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
507504

508505
opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
509506
opts.flags = GIT_STATUS_OPT_EXCLUDE_SUBMODULES;
510507

511-
if (include_untracked_files)
508+
if (flags & GIT_STASH_INCLUDE_UNTRACKED)
512509
opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED |
513510
GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
514511

515-
if (include_ignored_files)
512+
if (flags & GIT_STASH_INCLUDE_IGNORED)
516513
opts.flags |= GIT_STATUS_OPT_INCLUDE_IGNORED |
517514
GIT_STATUS_OPT_RECURSE_IGNORED_DIRS;
518515

@@ -527,20 +524,14 @@ static int ensure_there_are_changes_to_stash(
527524
return error;
528525
}
529526

530-
static int reset_index_and_workdir(
531-
git_repository *repo,
532-
git_commit *commit,
533-
bool remove_untracked,
534-
bool remove_ignored)
527+
static int reset_index_and_workdir(git_repository *repo, git_commit *commit, uint32_t flags)
535528
{
536529
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
537530

538531
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
539-
540-
if (remove_untracked)
532+
if (flags & GIT_STASH_INCLUDE_UNTRACKED)
541533
opts.checkout_strategy |= GIT_CHECKOUT_REMOVE_UNTRACKED;
542-
543-
if (remove_ignored)
534+
if (flags & GIT_STASH_INCLUDE_IGNORED)
544535
opts.checkout_strategy |= GIT_CHECKOUT_REMOVE_IGNORED;
545536

546537
return git_checkout_tree(repo, (git_object *)commit, &opts);
@@ -566,43 +557,35 @@ int git_stash_save(
566557
if ((error = retrieve_base_commit_and_message(&b_commit, &msg, repo)) < 0)
567558
goto cleanup;
568559

569-
if ((error = ensure_there_are_changes_to_stash(
570-
repo,
571-
(flags & GIT_STASH_INCLUDE_UNTRACKED) != 0,
572-
(flags & GIT_STASH_INCLUDE_IGNORED) != 0)) < 0)
560+
if ((error = ensure_there_are_changes_to_stash(repo, flags)) < 0)
573561
goto cleanup;
574562

575563
if ((error = git_repository_index(&index, repo)) < 0)
576564
goto cleanup;
577565

578-
if ((error = commit_index(
579-
&i_commit, repo, index, stasher, git_buf_cstr(&msg), b_commit)) < 0)
566+
if ((error = commit_index(&i_commit, repo, index, stasher,
567+
git_buf_cstr(&msg), b_commit)) < 0)
580568
goto cleanup;
581569

582570
if ((flags & (GIT_STASH_INCLUDE_UNTRACKED | GIT_STASH_INCLUDE_IGNORED)) &&
583-
(error = commit_untracked(
584-
&u_commit, repo, stasher, git_buf_cstr(&msg),
585-
i_commit, flags)) < 0)
571+
(error = commit_untracked(&u_commit, repo, stasher,
572+
git_buf_cstr(&msg), i_commit, flags)) < 0)
586573
goto cleanup;
587574

588575
if ((error = prepare_worktree_commit_message(&msg, message)) < 0)
589576
goto cleanup;
590577

591-
if ((error = commit_worktree(
592-
out, repo, stasher, git_buf_cstr(&msg),
593-
i_commit, b_commit, u_commit)) < 0)
578+
if ((error = commit_worktree(out, repo, stasher, git_buf_cstr(&msg),
579+
i_commit, b_commit, u_commit)) < 0)
594580
goto cleanup;
595581

596582
git_buf_rtrim(&msg);
597583

598584
if ((error = update_reflog(out, repo, git_buf_cstr(&msg))) < 0)
599585
goto cleanup;
600586

601-
if ((error = reset_index_and_workdir(
602-
repo,
603-
((flags & GIT_STASH_KEEP_INDEX) != 0) ? i_commit : b_commit,
604-
(flags & GIT_STASH_INCLUDE_UNTRACKED) != 0,
605-
(flags & GIT_STASH_INCLUDE_IGNORED) != 0)) < 0)
587+
if ((error = reset_index_and_workdir(repo, (flags & GIT_STASH_KEEP_INDEX) ? i_commit : b_commit,
588+
flags)) < 0)
606589
goto cleanup;
607590

608591
cleanup:

0 commit comments

Comments
 (0)