@matheusbsbs / matheus-bagliano / commits / 804fe31557
Fork 0

sequencer: implement apply_autostash_oid()

Split apply_save_autostash() into apply_autostash_oid() and apply_save_autostash() where the former operates on an OID string and the latter reads the OID from a file before passing it into apply_save_autostash_oid(). This function is required for a future commmit which will rely on being able to apply an autostash whose OID is stored as a string. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Apr 7, 2020 at 10:28 UTC 804fe3155761e73c3dcc4e162ddb3ff560f16cd7
2 files changed +27 -12
sequencer.c
+26 -12
@@ -3707,26 +3707,18 @@ void create_autostash(struct repository *r, const char *path,
3707 strbuf_release(&buf);
3708 }
3709
3710 -static int apply_save_autostash(const char *path, int attempt_apply)
3710 +static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
3711 {
3712 - struct strbuf stash_oid = STRBUF_INIT;
3712 struct child_process child = CHILD_PROCESS_INIT;
3713 int ret = 0;
3714
3716 - if (!read_oneliner(&stash_oid, path,
3717 - READ_ONELINER_SKIP_IF_EMPTY)) {
3718 - strbuf_release(&stash_oid);
3719 - return 0;
3720 - }
3721 - strbuf_trim(&stash_oid);
3722 -
3715 if (attempt_apply) {
3716 child.git_cmd = 1;
3717 child.no_stdout = 1;
3718 child.no_stderr = 1;
3719 argv_array_push(&child.args, "stash");
3720 argv_array_push(&child.args, "apply");
3729 - argv_array_push(&child.args, stash_oid.buf);
3721 + argv_array_push(&child.args, stash_oid);
3722 ret = run_command(&child);
3723 }
3724
@@ -3741,9 +3733,9 @@ static int apply_save_autostash(const char *path, int attempt_apply)
3733 argv_array_push(&store.args, "-m");
3734 argv_array_push(&store.args, "autostash");
3735 argv_array_push(&store.args, "-q");
3744 - argv_array_push(&store.args, stash_oid.buf);
3736 + argv_array_push(&store.args, stash_oid);
3737 if (run_command(&store))
3746 - ret = error(_("cannot store %s"), stash_oid.buf);
3738 + ret = error(_("cannot store %s"), stash_oid);
3739 else
3740 fprintf(stderr,
3741 _("%s\n"
@@ -3755,6 +3747,23 @@ static int apply_save_autostash(const char *path, int attempt_apply)
3747 _("Autostash exists; creating a new stash entry."));
3748 }
3749
3750 + return ret;
3751 +}
3752 +
3753 +static int apply_save_autostash(const char *path, int attempt_apply)
3754 +{
3755 + struct strbuf stash_oid = STRBUF_INIT;
3756 + int ret = 0;
3757 +
3758 + if (!read_oneliner(&stash_oid, path,
3759 + READ_ONELINER_SKIP_IF_EMPTY)) {
3760 + strbuf_release(&stash_oid);
3761 + return 0;
3762 + }
3763 + strbuf_trim(&stash_oid);
3764 +
3765 + ret = apply_save_autostash_oid(stash_oid.buf, attempt_apply);
3766 +
3767 unlink(path);
3768 strbuf_release(&stash_oid);
3769 return ret;
@@ -3770,6 +3779,11 @@ int apply_autostash(const char *path)
3779 return apply_save_autostash(path, 1);
3780 }
3781
3782 +int apply_autostash_oid(const char *stash_oid)
3783 +{
3784 + return apply_save_autostash_oid(stash_oid, 1);
3785 +}
3786 +
3787 static const char *reflog_message(struct replay_opts *opts,
3788 const char *sub_action, const char *fmt, ...)
3789 {
sequencer.h
+1
@@ -195,6 +195,7 @@ void create_autostash(struct repository *r, const char *path,
195 const char *default_reflog_action);
196 int save_autostash(const char *path);
197 int apply_autostash(const char *path);
198 +int apply_autostash_oid(const char *stash_oid);
199
200 #define SUMMARY_INITIAL_COMMIT (1 << 0)
201 #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)