2020-10-30 04:32:13 +08:00
|
|
|
/*
|
2023-11-24 19:10:31 +08:00
|
|
|
* "git replay" builtin command
|
2020-10-30 04:32:13 +08:00
|
|
|
*/
|
|
|
|
|
2023-11-24 19:10:31 +08:00
|
|
|
#include "git-compat-util.h"
|
|
|
|
|
|
|
|
#include "builtin.h"
|
2023-03-21 14:26:03 +08:00
|
|
|
#include "environment.h"
|
2023-02-24 08:09:27 +08:00
|
|
|
#include "hex.h"
|
2020-10-30 04:32:13 +08:00
|
|
|
#include "lockfile.h"
|
|
|
|
#include "merge-ort.h"
|
2023-04-11 15:41:49 +08:00
|
|
|
#include "object-name.h"
|
2023-11-24 19:10:32 +08:00
|
|
|
#include "parse-options.h"
|
2020-10-30 04:32:13 +08:00
|
|
|
#include "refs.h"
|
|
|
|
#include "revision.h"
|
2023-11-24 19:10:41 +08:00
|
|
|
#include "strmap.h"
|
2023-11-24 19:10:31 +08:00
|
|
|
#include <oidset.h>
|
|
|
|
#include <tree.h>
|
2020-10-30 04:32:13 +08:00
|
|
|
|
|
|
|
static const char *short_commit_name(struct commit *commit)
|
|
|
|
{
|
2023-03-28 21:58:46 +08:00
|
|
|
return repo_find_unique_abbrev(the_repository, &commit->object.oid,
|
|
|
|
DEFAULT_ABBREV);
|
2020-10-30 04:32:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct commit *peel_committish(const char *name)
|
|
|
|
{
|
|
|
|
struct object *obj;
|
|
|
|
struct object_id oid;
|
|
|
|
|
2023-03-28 21:58:46 +08:00
|
|
|
if (repo_get_oid(the_repository, name, &oid))
|
2020-10-30 04:32:13 +08:00
|
|
|
return NULL;
|
|
|
|
obj = parse_object(the_repository, &oid);
|
2023-03-28 21:58:46 +08:00
|
|
|
return (struct commit *)repo_peel_to_type(the_repository, name, 0, obj,
|
|
|
|
OBJ_COMMIT);
|
2020-10-30 04:32:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *get_author(const char *message)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
const char *a;
|
|
|
|
|
|
|
|
a = find_commit_header(message, "author", &len);
|
|
|
|
if (a)
|
|
|
|
return xmemdupz(a, len);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct commit *create_commit(struct tree *tree,
|
|
|
|
struct commit *based_on,
|
|
|
|
struct commit *parent)
|
|
|
|
{
|
|
|
|
struct object_id ret;
|
2024-06-11 17:20:42 +08:00
|
|
|
struct object *obj = NULL;
|
2020-10-30 04:32:13 +08:00
|
|
|
struct commit_list *parents = NULL;
|
|
|
|
char *author;
|
2023-11-24 19:10:36 +08:00
|
|
|
char *sign_commit = NULL; /* FIXME: cli users might want to sign again */
|
2024-06-11 17:20:42 +08:00
|
|
|
struct commit_extra_header *extra = NULL;
|
2020-10-30 04:32:13 +08:00
|
|
|
struct strbuf msg = STRBUF_INIT;
|
|
|
|
const char *out_enc = get_commit_output_encoding();
|
2023-03-28 21:58:48 +08:00
|
|
|
const char *message = repo_logmsg_reencode(the_repository, based_on,
|
|
|
|
NULL, out_enc);
|
2020-10-30 04:32:13 +08:00
|
|
|
const char *orig_message = NULL;
|
|
|
|
const char *exclude_gpgsig[] = { "gpgsig", NULL };
|
|
|
|
|
|
|
|
commit_list_insert(parent, &parents);
|
|
|
|
extra = read_commit_extra_headers(based_on, exclude_gpgsig);
|
|
|
|
find_commit_subject(message, &orig_message);
|
|
|
|
strbuf_addstr(&msg, orig_message);
|
|
|
|
author = get_author(message);
|
|
|
|
reset_ident_date();
|
|
|
|
if (commit_tree_extended(msg.buf, msg.len, &tree->object.oid, parents,
|
|
|
|
&ret, author, NULL, sign_commit, extra)) {
|
|
|
|
error(_("failed to write commit object"));
|
2024-06-11 17:20:42 +08:00
|
|
|
goto out;
|
2020-10-30 04:32:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
obj = parse_object(the_repository, &ret);
|
2024-06-11 17:20:42 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
free_commit_extra_headers(extra);
|
|
|
|
free_commit_list(parents);
|
|
|
|
strbuf_release(&msg);
|
|
|
|
free(author);
|
2020-10-30 04:32:13 +08:00
|
|
|
return (struct commit *)obj;
|
|
|
|
}
|
|
|
|
|
2023-11-24 19:10:41 +08:00
|
|
|
struct ref_info {
|
|
|
|
struct commit *onto;
|
|
|
|
struct strset positive_refs;
|
|
|
|
struct strset negative_refs;
|
|
|
|
int positive_refexprs;
|
|
|
|
int negative_refexprs;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void get_ref_information(struct rev_cmdline_info *cmd_info,
|
|
|
|
struct ref_info *ref_info)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ref_info->onto = NULL;
|
|
|
|
strset_init(&ref_info->positive_refs);
|
|
|
|
strset_init(&ref_info->negative_refs);
|
|
|
|
ref_info->positive_refexprs = 0;
|
|
|
|
ref_info->negative_refexprs = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When the user specifies e.g.
|
|
|
|
* git replay origin/main..mybranch
|
|
|
|
* git replay ^origin/next mybranch1 mybranch2
|
|
|
|
* we want to be able to determine where to replay the commits. In
|
|
|
|
* these examples, the branches are probably based on an old version
|
|
|
|
* of either origin/main or origin/next, so we want to replay on the
|
|
|
|
* newest version of that branch. In contrast we would want to error
|
|
|
|
* out if they ran
|
|
|
|
* git replay ^origin/master ^origin/next mybranch
|
|
|
|
* git replay mybranch~2..mybranch
|
|
|
|
* the first of those because there's no unique base to choose, and
|
|
|
|
* the second because they'd likely just be replaying commits on top
|
|
|
|
* of the same commit and not making any difference.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < cmd_info->nr; i++) {
|
|
|
|
struct rev_cmdline_entry *e = cmd_info->rev + i;
|
|
|
|
struct object_id oid;
|
|
|
|
const char *refexpr = e->name;
|
|
|
|
char *fullname = NULL;
|
|
|
|
int can_uniquely_dwim = 1;
|
|
|
|
|
|
|
|
if (*refexpr == '^')
|
|
|
|
refexpr++;
|
|
|
|
if (repo_dwim_ref(the_repository, refexpr, strlen(refexpr), &oid, &fullname, 0) != 1)
|
|
|
|
can_uniquely_dwim = 0;
|
|
|
|
|
|
|
|
if (e->flags & BOTTOM) {
|
|
|
|
if (can_uniquely_dwim)
|
|
|
|
strset_add(&ref_info->negative_refs, fullname);
|
|
|
|
if (!ref_info->negative_refexprs)
|
|
|
|
ref_info->onto = lookup_commit_reference_gently(the_repository,
|
|
|
|
&e->item->oid, 1);
|
|
|
|
ref_info->negative_refexprs++;
|
|
|
|
} else {
|
|
|
|
if (can_uniquely_dwim)
|
|
|
|
strset_add(&ref_info->positive_refs, fullname);
|
|
|
|
ref_info->positive_refexprs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(fullname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
|
|
|
|
const char *onto_name,
|
2024-08-01 18:38:11 +08:00
|
|
|
char **advance_name,
|
2023-11-24 19:10:41 +08:00
|
|
|
struct commit **onto,
|
|
|
|
struct strset **update_refs)
|
|
|
|
{
|
|
|
|
struct ref_info rinfo;
|
|
|
|
|
|
|
|
get_ref_information(cmd_info, &rinfo);
|
|
|
|
if (!rinfo.positive_refexprs)
|
|
|
|
die(_("need some commits to replay"));
|
|
|
|
if (onto_name && *advance_name)
|
|
|
|
die(_("--onto and --advance are incompatible"));
|
|
|
|
else if (onto_name) {
|
|
|
|
*onto = peel_committish(onto_name);
|
|
|
|
if (rinfo.positive_refexprs <
|
|
|
|
strset_get_size(&rinfo.positive_refs))
|
|
|
|
die(_("all positive revisions given must be references"));
|
|
|
|
} else if (*advance_name) {
|
|
|
|
struct object_id oid;
|
|
|
|
char *fullname = NULL;
|
|
|
|
|
|
|
|
*onto = peel_committish(*advance_name);
|
|
|
|
if (repo_dwim_ref(the_repository, *advance_name, strlen(*advance_name),
|
|
|
|
&oid, &fullname, 0) == 1) {
|
2024-08-01 18:38:11 +08:00
|
|
|
free(*advance_name);
|
2023-11-24 19:10:41 +08:00
|
|
|
*advance_name = fullname;
|
|
|
|
} else {
|
|
|
|
die(_("argument to --advance must be a reference"));
|
|
|
|
}
|
|
|
|
if (rinfo.positive_refexprs > 1)
|
|
|
|
die(_("cannot advance target with multiple sources because ordering would be ill-defined"));
|
|
|
|
} else {
|
|
|
|
int positive_refs_complete = (
|
|
|
|
rinfo.positive_refexprs ==
|
|
|
|
strset_get_size(&rinfo.positive_refs));
|
|
|
|
int negative_refs_complete = (
|
|
|
|
rinfo.negative_refexprs ==
|
|
|
|
strset_get_size(&rinfo.negative_refs));
|
|
|
|
/*
|
|
|
|
* We need either positive_refs_complete or
|
|
|
|
* negative_refs_complete, but not both.
|
|
|
|
*/
|
|
|
|
if (rinfo.negative_refexprs > 0 &&
|
|
|
|
positive_refs_complete == negative_refs_complete)
|
|
|
|
die(_("cannot implicitly determine whether this is an --advance or --onto operation"));
|
|
|
|
if (negative_refs_complete) {
|
|
|
|
struct hashmap_iter iter;
|
|
|
|
struct strmap_entry *entry;
|
2024-08-01 18:38:11 +08:00
|
|
|
const char *last_key = NULL;
|
2023-11-24 19:10:41 +08:00
|
|
|
|
|
|
|
if (rinfo.negative_refexprs == 0)
|
|
|
|
die(_("all positive revisions given must be references"));
|
|
|
|
else if (rinfo.negative_refexprs > 1)
|
|
|
|
die(_("cannot implicitly determine whether this is an --advance or --onto operation"));
|
|
|
|
else if (rinfo.positive_refexprs > 1)
|
|
|
|
die(_("cannot advance target with multiple source branches because ordering would be ill-defined"));
|
|
|
|
|
|
|
|
/* Only one entry, but we have to loop to get it */
|
|
|
|
strset_for_each_entry(&rinfo.negative_refs,
|
|
|
|
&iter, entry) {
|
2024-08-01 18:38:11 +08:00
|
|
|
last_key = entry->key;
|
2023-11-24 19:10:41 +08:00
|
|
|
}
|
2024-08-01 18:38:11 +08:00
|
|
|
|
|
|
|
free(*advance_name);
|
|
|
|
*advance_name = xstrdup_or_null(last_key);
|
2023-11-24 19:10:41 +08:00
|
|
|
} else { /* positive_refs_complete */
|
|
|
|
if (rinfo.negative_refexprs > 1)
|
|
|
|
die(_("cannot implicitly determine correct base for --onto"));
|
|
|
|
if (rinfo.negative_refexprs == 1)
|
|
|
|
*onto = rinfo.onto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!*advance_name) {
|
|
|
|
*update_refs = xcalloc(1, sizeof(**update_refs));
|
|
|
|
**update_refs = rinfo.positive_refs;
|
|
|
|
memset(&rinfo.positive_refs, 0, sizeof(**update_refs));
|
|
|
|
}
|
|
|
|
strset_clear(&rinfo.negative_refs);
|
|
|
|
strset_clear(&rinfo.positive_refs);
|
|
|
|
}
|
|
|
|
|
2023-11-24 19:10:43 +08:00
|
|
|
static struct commit *mapped_commit(kh_oid_map_t *replayed_commits,
|
|
|
|
struct commit *commit,
|
|
|
|
struct commit *fallback)
|
|
|
|
{
|
|
|
|
khint_t pos = kh_get_oid_map(replayed_commits, commit->object.oid);
|
|
|
|
if (pos == kh_end(replayed_commits))
|
|
|
|
return fallback;
|
|
|
|
return kh_value(replayed_commits, pos);
|
|
|
|
}
|
|
|
|
|
2023-11-24 19:10:34 +08:00
|
|
|
static struct commit *pick_regular_commit(struct commit *pickme,
|
2023-11-24 19:10:43 +08:00
|
|
|
kh_oid_map_t *replayed_commits,
|
|
|
|
struct commit *onto,
|
2023-11-24 19:10:34 +08:00
|
|
|
struct merge_options *merge_opt,
|
|
|
|
struct merge_result *result)
|
|
|
|
{
|
2023-11-24 19:10:43 +08:00
|
|
|
struct commit *base, *replayed_base;
|
2023-11-24 19:10:34 +08:00
|
|
|
struct tree *pickme_tree, *base_tree;
|
|
|
|
|
|
|
|
base = pickme->parents->item;
|
2023-11-24 19:10:43 +08:00
|
|
|
replayed_base = mapped_commit(replayed_commits, base, onto);
|
2023-11-24 19:10:34 +08:00
|
|
|
|
2023-11-24 19:10:43 +08:00
|
|
|
result->tree = repo_get_commit_tree(the_repository, replayed_base);
|
2023-11-24 19:10:34 +08:00
|
|
|
pickme_tree = repo_get_commit_tree(the_repository, pickme);
|
|
|
|
base_tree = repo_get_commit_tree(the_repository, base);
|
|
|
|
|
2023-11-24 19:10:43 +08:00
|
|
|
merge_opt->branch1 = short_commit_name(replayed_base);
|
2023-11-24 19:10:34 +08:00
|
|
|
merge_opt->branch2 = short_commit_name(pickme);
|
|
|
|
merge_opt->ancestor = xstrfmt("parent of %s", merge_opt->branch2);
|
|
|
|
|
|
|
|
merge_incore_nonrecursive(merge_opt,
|
|
|
|
base_tree,
|
|
|
|
result->tree,
|
|
|
|
pickme_tree,
|
|
|
|
result);
|
|
|
|
|
|
|
|
free((char*)merge_opt->ancestor);
|
|
|
|
merge_opt->ancestor = NULL;
|
|
|
|
if (!result->clean)
|
|
|
|
return NULL;
|
2023-11-24 19:10:43 +08:00
|
|
|
return create_commit(result->tree, pickme, replayed_base);
|
2023-11-24 19:10:34 +08:00
|
|
|
}
|
|
|
|
|
2023-11-24 19:10:31 +08:00
|
|
|
int cmd_replay(int argc, const char **argv, const char *prefix)
|
2020-10-30 04:32:13 +08:00
|
|
|
{
|
2024-08-01 18:38:11 +08:00
|
|
|
const char *advance_name_opt = NULL;
|
|
|
|
char *advance_name = NULL;
|
2023-11-24 19:10:41 +08:00
|
|
|
struct commit *onto = NULL;
|
2023-11-24 19:10:32 +08:00
|
|
|
const char *onto_name = NULL;
|
2023-11-24 19:10:42 +08:00
|
|
|
int contained = 0;
|
2023-11-24 19:10:41 +08:00
|
|
|
|
2020-10-30 04:32:13 +08:00
|
|
|
struct rev_info revs;
|
2023-11-24 19:10:41 +08:00
|
|
|
struct commit *last_commit = NULL;
|
2020-10-30 04:32:13 +08:00
|
|
|
struct commit *commit;
|
|
|
|
struct merge_options merge_opt;
|
|
|
|
struct merge_result result;
|
2023-11-24 19:10:41 +08:00
|
|
|
struct strset *update_refs = NULL;
|
2023-11-24 19:10:43 +08:00
|
|
|
kh_oid_map_t *replayed_commits;
|
2022-04-14 04:01:40 +08:00
|
|
|
int ret = 0;
|
2020-10-30 04:32:13 +08:00
|
|
|
|
2023-11-24 19:10:32 +08:00
|
|
|
const char * const replay_usage[] = {
|
2023-11-24 19:10:42 +08:00
|
|
|
N_("(EXPERIMENTAL!) git replay "
|
|
|
|
"([--contained] --onto <newbase> | --advance <branch>) "
|
|
|
|
"<revision-range>..."),
|
2023-11-24 19:10:32 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
struct option replay_options[] = {
|
2024-08-01 18:38:11 +08:00
|
|
|
OPT_STRING(0, "advance", &advance_name_opt,
|
2023-11-24 19:10:41 +08:00
|
|
|
N_("branch"),
|
|
|
|
N_("make replay advance given branch")),
|
2023-11-24 19:10:32 +08:00
|
|
|
OPT_STRING(0, "onto", &onto_name,
|
|
|
|
N_("revision"),
|
|
|
|
N_("replay onto given commit")),
|
2023-11-24 19:10:42 +08:00
|
|
|
OPT_BOOL(0, "contained", &contained,
|
|
|
|
N_("advance all branches contained in revision-range")),
|
2023-11-24 19:10:32 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, replay_options, replay_usage,
|
|
|
|
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);
|
|
|
|
|
2024-08-01 18:38:11 +08:00
|
|
|
if (!onto_name && !advance_name_opt) {
|
2023-11-24 19:10:41 +08:00
|
|
|
error(_("option --onto or --advance is mandatory"));
|
2023-11-24 19:10:32 +08:00
|
|
|
usage_with_options(replay_usage, replay_options);
|
2020-10-30 04:32:13 +08:00
|
|
|
}
|
|
|
|
|
2024-08-01 18:38:11 +08:00
|
|
|
if (advance_name_opt && contained)
|
2023-11-24 19:10:42 +08:00
|
|
|
die(_("options '%s' and '%s' cannot be used together"),
|
|
|
|
"--advance", "--contained");
|
2024-08-01 18:38:11 +08:00
|
|
|
advance_name = xstrdup_or_null(advance_name_opt);
|
2023-11-24 19:10:42 +08:00
|
|
|
|
2023-11-24 19:10:31 +08:00
|
|
|
repo_init_revisions(the_repository, &revs, prefix);
|
2023-11-24 19:10:32 +08:00
|
|
|
|
2023-11-24 19:10:35 +08:00
|
|
|
/*
|
|
|
|
* Set desired values for rev walking options here. If they
|
|
|
|
* are changed by some user specified option in setup_revisions()
|
|
|
|
* below, we will detect that below and then warn.
|
|
|
|
*
|
|
|
|
* TODO: In the future we might want to either die(), or allow
|
|
|
|
* some options changing these values if we think they could
|
|
|
|
* be useful.
|
|
|
|
*/
|
2020-10-30 04:32:13 +08:00
|
|
|
revs.reverse = 1;
|
|
|
|
revs.sort_order = REV_SORT_IN_GRAPH_ORDER;
|
|
|
|
revs.topo_order = 1;
|
2023-11-24 19:10:35 +08:00
|
|
|
revs.simplify_history = 0;
|
2020-10-30 04:32:13 +08:00
|
|
|
|
2023-11-24 19:10:40 +08:00
|
|
|
argc = setup_revisions(argc, argv, &revs, NULL);
|
|
|
|
if (argc > 1) {
|
|
|
|
ret = error(_("unrecognized argument: %s"), argv[1]);
|
2022-04-14 04:01:40 +08:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2020-10-30 04:32:13 +08:00
|
|
|
|
2023-11-24 19:10:35 +08:00
|
|
|
/*
|
|
|
|
* Detect and warn if we override some user specified rev
|
|
|
|
* walking options.
|
|
|
|
*/
|
|
|
|
if (revs.reverse != 1) {
|
|
|
|
warning(_("some rev walking options will be overridden as "
|
|
|
|
"'%s' bit in 'struct rev_info' will be forced"),
|
|
|
|
"reverse");
|
|
|
|
revs.reverse = 1;
|
|
|
|
}
|
|
|
|
if (revs.sort_order != REV_SORT_IN_GRAPH_ORDER) {
|
|
|
|
warning(_("some rev walking options will be overridden as "
|
|
|
|
"'%s' bit in 'struct rev_info' will be forced"),
|
|
|
|
"sort_order");
|
|
|
|
revs.sort_order = REV_SORT_IN_GRAPH_ORDER;
|
|
|
|
}
|
|
|
|
if (revs.topo_order != 1) {
|
|
|
|
warning(_("some rev walking options will be overridden as "
|
|
|
|
"'%s' bit in 'struct rev_info' will be forced"),
|
|
|
|
"topo_order");
|
|
|
|
revs.topo_order = 1;
|
|
|
|
}
|
|
|
|
if (revs.simplify_history != 0) {
|
|
|
|
warning(_("some rev walking options will be overridden as "
|
|
|
|
"'%s' bit in 'struct rev_info' will be forced"),
|
|
|
|
"simplify_history");
|
|
|
|
revs.simplify_history = 0;
|
|
|
|
}
|
|
|
|
|
2023-11-24 19:10:41 +08:00
|
|
|
determine_replay_mode(&revs.cmdline, onto_name, &advance_name,
|
|
|
|
&onto, &update_refs);
|
|
|
|
|
|
|
|
if (!onto) /* FIXME: Should handle replaying down to root commit */
|
|
|
|
die("Replaying down to root commit is not supported yet!");
|
|
|
|
|
2022-04-14 04:01:40 +08:00
|
|
|
if (prepare_revision_walk(&revs) < 0) {
|
|
|
|
ret = error(_("error preparing revisions"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2020-10-30 04:32:13 +08:00
|
|
|
|
merge-recursive: honor diff.algorithm
The documentation claims that "recursive defaults to the diff.algorithm
config setting", but this is currently not the case. This fixes it,
ensuring that diff.algorithm is used when -Xdiff-algorithm is not
supplied. This affects the following porcelain commands: "merge",
"rebase", "cherry-pick", "pull", "stash", "log", "am" and "checkout".
It also affects the "merge-tree" ancillary interrogator.
This change refactors the initialization of merge options to introduce
two functions, "init_merge_ui_options" and "init_merge_basic_options"
instead of just one "init_merge_options". This design follows the
approach used in diff.c, providing initialization methods for
porcelain and plumbing commands respectively. Thanks to that, the
"replay" and "merge-recursive" plumbing commands remain unaffected by
diff.algorithm.
Signed-off-by: Antonin Delpeuch <antonin@delpeuch.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-07-14 00:51:46 +08:00
|
|
|
init_basic_merge_options(&merge_opt, the_repository);
|
2020-10-30 04:32:13 +08:00
|
|
|
memset(&result, 0, sizeof(result));
|
2023-11-24 19:10:37 +08:00
|
|
|
merge_opt.show_rename_progress = 0;
|
2020-10-30 04:32:13 +08:00
|
|
|
last_commit = onto;
|
2023-11-24 19:10:43 +08:00
|
|
|
replayed_commits = kh_init_oid_map();
|
2020-10-30 04:32:13 +08:00
|
|
|
while ((commit = get_revision(&revs))) {
|
2023-11-24 19:10:39 +08:00
|
|
|
const struct name_decoration *decoration;
|
2023-11-24 19:10:43 +08:00
|
|
|
khint_t pos;
|
|
|
|
int hr;
|
2020-10-30 04:32:13 +08:00
|
|
|
|
2023-11-24 19:10:33 +08:00
|
|
|
if (!commit->parents)
|
|
|
|
die(_("replaying down to root commit is not supported yet!"));
|
|
|
|
if (commit->parents->next)
|
|
|
|
die(_("replaying merge commits is not supported yet!"));
|
|
|
|
|
2023-11-24 19:10:43 +08:00
|
|
|
last_commit = pick_regular_commit(commit, replayed_commits, onto,
|
|
|
|
&merge_opt, &result);
|
2023-11-24 19:10:39 +08:00
|
|
|
if (!last_commit)
|
fast-rebase: write conflict state to working tree, index, and HEAD
Previously, when fast-rebase hit a conflict, it simply aborted and left
HEAD, the index, and the working tree where they were before the
operation started. While fast-rebase does not support restarting from a
conflicted state, write the conflicted state out anyway as it gives us a
way to see what the conflicts are and write tests that check for them.
This will be important in the upcoming commits, because sequencer.c is
only superficially integrated with merge-ort.c; in particular, it calls
merge_switch_to_result() after EACH merge instead of only calling it at
the end of all the sequence of merges (or when a conflict is hit). This
not only causes needless updates to the working copy and index, but also
causes all intermediate data to be freed and tossed, preventing caching
information from one merge to the next. However, integrating
sequencer.c more deeply with merge-ort.c is a big task, and making this
small extension to fast-rebase.c provides us with a simple way to test
the edge and corner cases that we want to make sure continue working.
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-05-20 14:09:32 +08:00
|
|
|
break;
|
2023-11-24 19:10:39 +08:00
|
|
|
|
2023-11-24 19:10:43 +08:00
|
|
|
/* Record commit -> last_commit mapping */
|
|
|
|
pos = kh_put_oid_map(replayed_commits, commit->object.oid, &hr);
|
|
|
|
if (hr == 0)
|
|
|
|
BUG("Duplicate rewritten commit: %s\n",
|
|
|
|
oid_to_hex(&commit->object.oid));
|
|
|
|
kh_value(replayed_commits, pos) = last_commit;
|
|
|
|
|
2023-11-24 19:10:41 +08:00
|
|
|
/* Update any necessary branches */
|
|
|
|
if (advance_name)
|
|
|
|
continue;
|
2023-11-24 19:10:39 +08:00
|
|
|
decoration = get_name_decoration(&commit->object);
|
|
|
|
if (!decoration)
|
|
|
|
continue;
|
|
|
|
while (decoration) {
|
2023-11-24 19:10:41 +08:00
|
|
|
if (decoration->type == DECORATION_REF_LOCAL &&
|
2023-11-24 19:10:42 +08:00
|
|
|
(contained || strset_contains(update_refs,
|
|
|
|
decoration->name))) {
|
2023-11-24 19:10:39 +08:00
|
|
|
printf("update %s %s %s\n",
|
|
|
|
decoration->name,
|
|
|
|
oid_to_hex(&last_commit->object.oid),
|
|
|
|
oid_to_hex(&commit->object.oid));
|
|
|
|
}
|
|
|
|
decoration = decoration->next;
|
|
|
|
}
|
2020-10-30 04:32:13 +08:00
|
|
|
}
|
|
|
|
|
2023-11-24 19:10:41 +08:00
|
|
|
/* In --advance mode, advance the target ref */
|
|
|
|
if (result.clean == 1 && advance_name) {
|
|
|
|
printf("update %s %s %s\n",
|
|
|
|
advance_name,
|
|
|
|
oid_to_hex(&last_commit->object.oid),
|
|
|
|
oid_to_hex(&onto->object.oid));
|
|
|
|
}
|
|
|
|
|
2023-11-24 19:10:30 +08:00
|
|
|
merge_finalize(&merge_opt, &result);
|
2023-11-24 19:10:43 +08:00
|
|
|
kh_destroy_oid_map(replayed_commits);
|
2023-11-24 19:10:41 +08:00
|
|
|
if (update_refs) {
|
|
|
|
strset_clear(update_refs);
|
|
|
|
free(update_refs);
|
|
|
|
}
|
2023-11-24 19:10:43 +08:00
|
|
|
ret = result.clean;
|
|
|
|
|
|
|
|
cleanup:
|
2022-04-14 04:01:40 +08:00
|
|
|
release_revisions(&revs);
|
2024-08-01 18:38:11 +08:00
|
|
|
free(advance_name);
|
2023-11-24 19:10:39 +08:00
|
|
|
|
|
|
|
/* Return */
|
|
|
|
if (ret < 0)
|
|
|
|
exit(128);
|
|
|
|
return ret ? 0 : 1;
|
2020-10-30 04:32:13 +08:00
|
|
|
}
|