Skip to content

Commit 804fe31

Browse files
Denton-Lgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 12b6e13 commit 804fe31

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

sequencer.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3707,26 +3707,18 @@ void create_autostash(struct repository *r, const char *path,
37073707
strbuf_release(&buf);
37083708
}
37093709

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)
37113711
{
3712-
struct strbuf stash_oid = STRBUF_INIT;
37133712
struct child_process child = CHILD_PROCESS_INIT;
37143713
int ret = 0;
37153714

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-
37233715
if (attempt_apply) {
37243716
child.git_cmd = 1;
37253717
child.no_stdout = 1;
37263718
child.no_stderr = 1;
37273719
argv_array_push(&child.args, "stash");
37283720
argv_array_push(&child.args, "apply");
3729-
argv_array_push(&child.args, stash_oid.buf);
3721+
argv_array_push(&child.args, stash_oid);
37303722
ret = run_command(&child);
37313723
}
37323724

@@ -3741,9 +3733,9 @@ static int apply_save_autostash(const char *path, int attempt_apply)
37413733
argv_array_push(&store.args, "-m");
37423734
argv_array_push(&store.args, "autostash");
37433735
argv_array_push(&store.args, "-q");
3744-
argv_array_push(&store.args, stash_oid.buf);
3736+
argv_array_push(&store.args, stash_oid);
37453737
if (run_command(&store))
3746-
ret = error(_("cannot store %s"), stash_oid.buf);
3738+
ret = error(_("cannot store %s"), stash_oid);
37473739
else
37483740
fprintf(stderr,
37493741
_("%s\n"
@@ -3755,6 +3747,23 @@ static int apply_save_autostash(const char *path, int attempt_apply)
37553747
_("Autostash exists; creating a new stash entry."));
37563748
}
37573749

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+
37583767
unlink(path);
37593768
strbuf_release(&stash_oid);
37603769
return ret;
@@ -3770,6 +3779,11 @@ int apply_autostash(const char *path)
37703779
return apply_save_autostash(path, 1);
37713780
}
37723781

3782+
int apply_autostash_oid(const char *stash_oid)
3783+
{
3784+
return apply_save_autostash_oid(stash_oid, 1);
3785+
}
3786+
37733787
static const char *reflog_message(struct replay_opts *opts,
37743788
const char *sub_action, const char *fmt, ...)
37753789
{

sequencer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ void create_autostash(struct repository *r, const char *path,
195195
const char *default_reflog_action);
196196
int save_autostash(const char *path);
197197
int apply_autostash(const char *path);
198+
int apply_autostash_oid(const char *stash_oid);
198199

199200
#define SUMMARY_INITIAL_COMMIT (1 << 0)
200201
#define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)

0 commit comments

Comments
 (0)