Skip to content

Commit fcf0a45

Browse files
HaraldNordgrengitster
authored andcommitted
sequencer: teach autostash apply to take optional conflict marker labels
Add label1, label2, and label_ancestor parameters to the autostash apply machinery so callers can pass custom conflict marker labels through to "git stash apply --ours-label/--theirs-label/--base-label". Introduce apply_autostash_ref_with_labels() for callers that want to pass labels. Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
1 parent 3eb9e7e commit fcf0a45

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

sequencer.c

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4704,7 +4704,9 @@ void create_autostash_ref_silent(struct repository *r, const char *refname)
47044704
create_autostash_internal(r, NULL, refname, 1);
47054705
}
47064706

4707-
static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
4707+
static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply,
4708+
const char *label1, const char *label2,
4709+
const char *label_ancestor)
47084710
{
47094711
struct child_process child = CHILD_PROCESS_INIT;
47104712
int ret = 0;
@@ -4715,6 +4717,12 @@ static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
47154717
child.no_stderr = 1;
47164718
strvec_push(&child.args, "stash");
47174719
strvec_push(&child.args, "apply");
4720+
if (label1)
4721+
strvec_pushf(&child.args, "--ours-label=%s", label1);
4722+
if (label2)
4723+
strvec_pushf(&child.args, "--theirs-label=%s", label2);
4724+
if (label_ancestor)
4725+
strvec_pushf(&child.args, "--base-label=%s", label_ancestor);
47184726
strvec_push(&child.args, stash_oid);
47194727
ret = run_command(&child);
47204728
}
@@ -4759,7 +4767,8 @@ static int apply_save_autostash(const char *path, int attempt_apply)
47594767
}
47604768
strbuf_trim(&stash_oid);
47614769

4762-
ret = apply_save_autostash_oid(stash_oid.buf, attempt_apply);
4770+
ret = apply_save_autostash_oid(stash_oid.buf, attempt_apply,
4771+
NULL, NULL, NULL);
47634772

47644773
unlink(path);
47654774
strbuf_release(&stash_oid);
@@ -4778,11 +4787,13 @@ int apply_autostash(const char *path)
47784787

47794788
int apply_autostash_oid(const char *stash_oid)
47804789
{
4781-
return apply_save_autostash_oid(stash_oid, 1);
4790+
return apply_save_autostash_oid(stash_oid, 1, NULL, NULL, NULL);
47824791
}
47834792

47844793
static int apply_save_autostash_ref(struct repository *r, const char *refname,
4785-
int attempt_apply)
4794+
int attempt_apply,
4795+
const char *label1, const char *label2,
4796+
const char *label_ancestor)
47864797
{
47874798
struct object_id stash_oid;
47884799
char stash_oid_hex[GIT_MAX_HEXSZ + 1];
@@ -4798,7 +4809,8 @@ static int apply_save_autostash_ref(struct repository *r, const char *refname,
47984809
return error(_("autostash reference is a symref"));
47994810

48004811
oid_to_hex_r(stash_oid_hex, &stash_oid);
4801-
ret = apply_save_autostash_oid(stash_oid_hex, attempt_apply);
4812+
ret = apply_save_autostash_oid(stash_oid_hex, attempt_apply,
4813+
label1, label2, label_ancestor);
48024814

48034815
refs_delete_ref(get_main_ref_store(r), "", refname,
48044816
&stash_oid, REF_NO_DEREF);
@@ -4808,12 +4820,20 @@ static int apply_save_autostash_ref(struct repository *r, const char *refname,
48084820

48094821
int save_autostash_ref(struct repository *r, const char *refname)
48104822
{
4811-
return apply_save_autostash_ref(r, refname, 0);
4823+
return apply_save_autostash_ref(r, refname, 0, NULL, NULL, NULL);
48124824
}
48134825

48144826
int apply_autostash_ref(struct repository *r, const char *refname)
48154827
{
4816-
return apply_save_autostash_ref(r, refname, 1);
4828+
return apply_save_autostash_ref(r, refname, 1, NULL, NULL, NULL);
4829+
}
4830+
4831+
int apply_autostash_ref_with_labels(struct repository *r, const char *refname,
4832+
const char *label1, const char *label2,
4833+
const char *label_ancestor)
4834+
{
4835+
return apply_save_autostash_ref(r, refname, 1,
4836+
label1, label2, label_ancestor);
48174837
}
48184838

48194839
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
@@ -233,6 +233,9 @@ int save_autostash_ref(struct repository *r, const char *refname);
233233
int apply_autostash(const char *path);
234234
int apply_autostash_oid(const char *stash_oid);
235235
int apply_autostash_ref(struct repository *r, const char *refname);
236+
int apply_autostash_ref_with_labels(struct repository *r, const char *refname,
237+
const char *label1, const char *label2,
238+
const char *label_ancestor);
236239

237240
#define SUMMARY_INITIAL_COMMIT (1 << 0)
238241
#define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)

0 commit comments

Comments
 (0)