Skip to content

Commit b0b3768

Browse files
HaraldNordgrengitster
authored andcommitted
sequencer: teach autostash apply to take optional conflict marker labels
Add label_ours, label_theirs, and label_base parameters to the autostash apply machinery so callers can pass custom conflict marker labels through to "git stash apply --label-ours/--label-theirs/--label-base". Introduce apply_autostash_ref_with_labels() for callers that want to pass labels. Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3392b76 commit b0b3768

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

sequencer.c

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4729,7 +4729,9 @@ void create_autostash_ref_silent(struct repository *r, const char *refname)
47294729
create_autostash_internal(r, NULL, refname, true);
47304730
}
47314731

4732-
static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
4732+
static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply,
4733+
const char *label_ours, const char *label_theirs,
4734+
const char *label_base)
47334735
{
47344736
struct child_process child = CHILD_PROCESS_INIT;
47354737
int ret = 0;
@@ -4740,6 +4742,12 @@ static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
47404742
child.no_stderr = 1;
47414743
strvec_push(&child.args, "stash");
47424744
strvec_push(&child.args, "apply");
4745+
if (label_ours)
4746+
strvec_pushf(&child.args, "--label-ours=%s", label_ours);
4747+
if (label_theirs)
4748+
strvec_pushf(&child.args, "--label-theirs=%s", label_theirs);
4749+
if (label_base)
4750+
strvec_pushf(&child.args, "--label-base=%s", label_base);
47434751
strvec_push(&child.args, stash_oid);
47444752
ret = run_command(&child);
47454753
}
@@ -4784,7 +4792,8 @@ static int apply_save_autostash(const char *path, int attempt_apply)
47844792
}
47854793
strbuf_trim(&stash_oid);
47864794

4787-
ret = apply_save_autostash_oid(stash_oid.buf, attempt_apply);
4795+
ret = apply_save_autostash_oid(stash_oid.buf, attempt_apply,
4796+
NULL, NULL, NULL);
47884797

47894798
unlink(path);
47904799
strbuf_release(&stash_oid);
@@ -4803,11 +4812,13 @@ int apply_autostash(const char *path)
48034812

48044813
int apply_autostash_oid(const char *stash_oid)
48054814
{
4806-
return apply_save_autostash_oid(stash_oid, 1);
4815+
return apply_save_autostash_oid(stash_oid, 1, NULL, NULL, NULL);
48074816
}
48084817

48094818
static int apply_save_autostash_ref(struct repository *r, const char *refname,
4810-
int attempt_apply)
4819+
int attempt_apply,
4820+
const char *label_ours, const char *label_theirs,
4821+
const char *label_base)
48114822
{
48124823
struct object_id stash_oid;
48134824
char stash_oid_hex[GIT_MAX_HEXSZ + 1];
@@ -4823,7 +4834,8 @@ static int apply_save_autostash_ref(struct repository *r, const char *refname,
48234834
return error(_("autostash reference is a symref"));
48244835

48254836
oid_to_hex_r(stash_oid_hex, &stash_oid);
4826-
ret = apply_save_autostash_oid(stash_oid_hex, attempt_apply);
4837+
ret = apply_save_autostash_oid(stash_oid_hex, attempt_apply,
4838+
label_ours, label_theirs, label_base);
48274839

48284840
refs_delete_ref(get_main_ref_store(r), "", refname,
48294841
&stash_oid, REF_NO_DEREF);
@@ -4833,12 +4845,20 @@ static int apply_save_autostash_ref(struct repository *r, const char *refname,
48334845

48344846
int save_autostash_ref(struct repository *r, const char *refname)
48354847
{
4836-
return apply_save_autostash_ref(r, refname, 0);
4848+
return apply_save_autostash_ref(r, refname, 0, NULL, NULL, NULL);
48374849
}
48384850

48394851
int apply_autostash_ref(struct repository *r, const char *refname)
48404852
{
4841-
return apply_save_autostash_ref(r, refname, 1);
4853+
return apply_save_autostash_ref(r, refname, 1, NULL, NULL, NULL);
4854+
}
4855+
4856+
int apply_autostash_ref_with_labels(struct repository *r, const char *refname,
4857+
const char *label_ours, const char *label_theirs,
4858+
const char *label_base)
4859+
{
4860+
return apply_save_autostash_ref(r, refname, 1,
4861+
label_ours, label_theirs, label_base);
48424862
}
48434863

48444864
static int checkout_onto(struct repository *r, struct replay_opts *opts,

sequencer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ int save_autostash_ref(struct repository *r, const char *refname);
236236
int apply_autostash(const char *path);
237237
int apply_autostash_oid(const char *stash_oid);
238238
int apply_autostash_ref(struct repository *r, const char *refname);
239+
int apply_autostash_ref_with_labels(struct repository *r, const char *refname,
240+
const char *label_ours, const char *label_theirs,
241+
const char *label_base);
239242

240243
#define SUMMARY_INITIAL_COMMIT (1 << 0)
241244
#define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)

0 commit comments

Comments
 (0)