Skip to content

Commit fc2afe3

Browse files
HaraldNordgrengitster
authored andcommitted
sequencer: teach autostash apply to take optional conflict marker labels
Add label_ours, label_theirs, label_base, and stash_msg parameters to apply_autostash_ref() and the autostash apply machinery so callers can pass custom conflict marker labels through to "git stash apply --label-ours/--label-theirs/--label-base", as well as a custom stash message for "git stash store -m". Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 464927c commit fc2afe3

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

builtin/commit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,8 @@ int cmd_commit(int argc,
19791979
&oid, flags);
19801980
}
19811981

1982-
apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
1982+
apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
1983+
NULL, NULL, NULL, NULL);
19831984

19841985
cleanup:
19851986
free_commit_extra_headers(extra);

builtin/merge.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ static void finish(struct commit *head_commit,
537537
run_hooks_l(the_repository, "post-merge", squash ? "1" : "0", NULL);
538538

539539
if (new_head)
540-
apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
540+
apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
541+
NULL, NULL, NULL, NULL);
541542
strbuf_release(&reflog_message);
542543
}
543544

@@ -1678,7 +1679,8 @@ int cmd_merge(int argc,
16781679
&head_commit->object.oid,
16791680
&commit->object.oid,
16801681
overwrite_ignore)) {
1681-
apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
1682+
apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
1683+
NULL, NULL, NULL, NULL);
16821684
ret = 1;
16831685
goto done;
16841686
}
@@ -1851,7 +1853,8 @@ int cmd_merge(int argc,
18511853
else
18521854
fprintf(stderr, _("Merge with strategy %s failed.\n"),
18531855
use_strategies[0]->name);
1854-
apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
1856+
apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
1857+
NULL, NULL, NULL, NULL);
18551858
ret = 2;
18561859
goto done;
18571860
} else if (best_strategy == wt_strategy)

sequencer.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4727,7 +4727,10 @@ void create_autostash_ref(struct repository *r, const char *refname,
47274727
create_autostash_internal(r, NULL, refname, message, silent);
47284728
}
47294729

4730-
static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
4730+
static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply,
4731+
const char *label_ours, const char *label_theirs,
4732+
const char *label_base,
4733+
const char *stash_msg)
47314734
{
47324735
struct child_process child = CHILD_PROCESS_INIT;
47334736
int ret = 0;
@@ -4738,6 +4741,12 @@ static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
47384741
child.no_stderr = 1;
47394742
strvec_push(&child.args, "stash");
47404743
strvec_push(&child.args, "apply");
4744+
if (label_ours)
4745+
strvec_pushf(&child.args, "--label-ours=%s", label_ours);
4746+
if (label_theirs)
4747+
strvec_pushf(&child.args, "--label-theirs=%s", label_theirs);
4748+
if (label_base)
4749+
strvec_pushf(&child.args, "--label-base=%s", label_base);
47414750
strvec_push(&child.args, stash_oid);
47424751
ret = run_command(&child);
47434752
}
@@ -4751,7 +4760,7 @@ static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
47514760
strvec_push(&store.args, "stash");
47524761
strvec_push(&store.args, "store");
47534762
strvec_push(&store.args, "-m");
4754-
strvec_push(&store.args, "autostash");
4763+
strvec_push(&store.args, stash_msg ? stash_msg : "autostash");
47554764
strvec_push(&store.args, "-q");
47564765
strvec_push(&store.args, stash_oid);
47574766
if (run_command(&store))
@@ -4782,7 +4791,8 @@ static int apply_save_autostash(const char *path, int attempt_apply)
47824791
}
47834792
strbuf_trim(&stash_oid);
47844793

4785-
ret = apply_save_autostash_oid(stash_oid.buf, attempt_apply);
4794+
ret = apply_save_autostash_oid(stash_oid.buf, attempt_apply,
4795+
NULL, NULL, NULL, NULL);
47864796

47874797
unlink(path);
47884798
strbuf_release(&stash_oid);
@@ -4801,11 +4811,14 @@ int apply_autostash(const char *path)
48014811

48024812
int apply_autostash_oid(const char *stash_oid)
48034813
{
4804-
return apply_save_autostash_oid(stash_oid, 1);
4814+
return apply_save_autostash_oid(stash_oid, 1, NULL, NULL, NULL, NULL);
48054815
}
48064816

48074817
static int apply_save_autostash_ref(struct repository *r, const char *refname,
4808-
int attempt_apply)
4818+
int attempt_apply,
4819+
const char *label_ours, const char *label_theirs,
4820+
const char *label_base,
4821+
const char *stash_msg)
48094822
{
48104823
struct object_id stash_oid;
48114824
char stash_oid_hex[GIT_MAX_HEXSZ + 1];
@@ -4821,7 +4834,9 @@ static int apply_save_autostash_ref(struct repository *r, const char *refname,
48214834
return error(_("autostash reference is a symref"));
48224835

48234836
oid_to_hex_r(stash_oid_hex, &stash_oid);
4824-
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,
4839+
stash_msg);
48254840

48264841
refs_delete_ref(get_main_ref_store(r), "", refname,
48274842
&stash_oid, REF_NO_DEREF);
@@ -4831,12 +4846,17 @@ static int apply_save_autostash_ref(struct repository *r, const char *refname,
48314846

48324847
int save_autostash_ref(struct repository *r, const char *refname)
48334848
{
4834-
return apply_save_autostash_ref(r, refname, 0);
4849+
return apply_save_autostash_ref(r, refname, 0,
4850+
NULL, NULL, NULL, NULL);
48354851
}
48364852

4837-
int apply_autostash_ref(struct repository *r, const char *refname)
4853+
int apply_autostash_ref(struct repository *r, const char *refname,
4854+
const char *label_ours, const char *label_theirs,
4855+
const char *label_base, const char *stash_msg)
48384856
{
4839-
return apply_save_autostash_ref(r, refname, 1);
4857+
return apply_save_autostash_ref(r, refname, 1,
4858+
label_ours, label_theirs, label_base,
4859+
stash_msg);
48404860
}
48414861

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

sequencer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ int save_autostash(const char *path);
235235
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);
238-
int apply_autostash_ref(struct repository *r, const char *refname);
238+
int apply_autostash_ref(struct repository *r, const char *refname,
239+
const char *label_ours, const char *label_theirs,
240+
const char *label_base, const char *stash_msg);
239241

240242
#define SUMMARY_INITIAL_COMMIT (1 << 0)
241243
#define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)

0 commit comments

Comments
 (0)