Skip to content

Commit f1cb96d

Browse files
pyokagangitster
authored andcommitted
builtin-am: rerere support
git-am.sh will call git-rerere at the following events: * "git rerere" when a three-way merge fails to record the conflicted automerge results. Since 8389b52 (git-rerere: reuse recorded resolve., 2006-01-28) * Since cb6020b (Teach --[no-]rerere-autoupdate option to merge, revert and friends, 2009-12-04), git-am.sh supports the --[no-]rerere-autoupdate option as well, and would pass it to git-rerere. * "git rerere" when --resolved, to record the hand resolution. Since f131dd4 (rerere: record (or avoid misrecording) resolved, skipped or aborted rebase/am, 2006-12-08) * "git rerere clear" when --skip-ing. Since f131dd4 (rerere: record (or avoid misrecording) resolved, skipped or aborted rebase/am, 2006-12-08) * "git rerere clear" when --abort-ing. Since 3e5057a (git am --abort, 2008-07-16) Re-implement the above in builtin/am.c. Signed-off-by: Paul Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7088f80 commit f1cb96d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

builtin/am.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "revision.h"
2525
#include "log-tree.h"
2626
#include "notes-utils.h"
27+
#include "rerere.h"
2728

2829
/**
2930
* Returns 1 if the file is empty or does not exist, 0 otherwise.
@@ -114,6 +115,7 @@ struct am_state {
114115
const char *resolvemsg;
115116
int committer_date_is_author_date;
116117
int ignore_date;
118+
int allow_rerere_autoupdate;
117119
const char *sign_commit;
118120
int rebasing;
119121
};
@@ -1312,6 +1314,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
13121314
o.verbosity = 0;
13131315

13141316
if (merge_recursive_generic(&o, our_tree, his_tree, 1, bases, &result)) {
1317+
rerere(state->allow_rerere_autoupdate);
13151318
free(his_tree_name);
13161319
return error(_("Failed to merge in the changes."));
13171320
}
@@ -1531,6 +1534,8 @@ static void am_resolve(struct am_state *state)
15311534
die_user_resolve(state);
15321535
}
15331536

1537+
rerere(0);
1538+
15341539
do_commit(state);
15351540

15361541
am_next(state);
@@ -1630,13 +1635,30 @@ static int clean_index(const unsigned char *head, const unsigned char *remote)
16301635
return 0;
16311636
}
16321637

1638+
/**
1639+
* Resets rerere's merge resolution metadata.
1640+
*/
1641+
static void am_rerere_clear(void)
1642+
{
1643+
struct string_list merge_rr = STRING_LIST_INIT_DUP;
1644+
int fd = setup_rerere(&merge_rr, 0);
1645+
1646+
if (fd < 0)
1647+
return;
1648+
1649+
rerere_clear(&merge_rr);
1650+
string_list_clear(&merge_rr, 1);
1651+
}
1652+
16331653
/**
16341654
* Resume the current am session by skipping the current patch.
16351655
*/
16361656
static void am_skip(struct am_state *state)
16371657
{
16381658
unsigned char head[GIT_SHA1_RAWSZ];
16391659

1660+
am_rerere_clear();
1661+
16401662
if (get_sha1("HEAD", head))
16411663
hashcpy(head, EMPTY_TREE_SHA1_BIN);
16421664

@@ -1694,6 +1716,8 @@ static void am_abort(struct am_state *state)
16941716
return;
16951717
}
16961718

1719+
am_rerere_clear();
1720+
16971721
curr_branch = resolve_refdup("HEAD", 0, curr_head, NULL);
16981722
has_curr_head = !is_null_sha1(curr_head);
16991723
if (!has_curr_head)
@@ -1823,6 +1847,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
18231847
N_("lie about committer date")),
18241848
OPT_BOOL(0, "ignore-date", &state.ignore_date,
18251849
N_("use current timestamp for author date")),
1850+
OPT_RERERE_AUTOUPDATE(&state.allow_rerere_autoupdate),
18261851
{ OPTION_STRING, 'S', "gpg-sign", &state.sign_commit, N_("key-id"),
18271852
N_("GPG-sign commits"),
18281853
PARSE_OPT_OPTARG, NULL, (intptr_t) "" },

0 commit comments

Comments
 (0)