1
0
mirror of https://github.com/git/git synced 2024-07-02 15:48:44 +00:00

Merge branch 'ml/log-merge-with-cherry-pick-and-other-pseudo-heads'

"git log --merge" learned to pay attention to CHERRY_PICK_HEAD and
other kinds of *_HEAD pseudorefs.

* ml/log-merge-with-cherry-pick-and-other-pseudo-heads:
  revision: implement `git log --merge` also for rebase/cherry-pick/revert
  revision: ensure MERGE_HEAD is a ref in prepare_show_merge
This commit is contained in:
Junio C Hamano 2024-03-07 15:59:41 -08:00
commit 6a887bdd92
2 changed files with 28 additions and 6 deletions

View File

@ -341,8 +341,11 @@ See also linkgit:git-reflog[1].
Under `--pretty=reference`, this information will not be shown at all.
--merge::
After a failed merge, show refs that touch files having a
conflict and don't exist on all heads to merge.
Show commits touching conflicted paths in the range `HEAD...<other>`,
where `<other>` is the first existing pseudoref in `MERGE_HEAD`,
`CHERRY_PICK_HEAD`, `REVERT_HEAD` or `REBASE_HEAD`. Only works
when the index has unmerged entries. This option can be used to show
relevant commits when resolving conflicts from a 3-way merge.
--boundary::
Output excluded boundary commits. Boundary commits are

View File

@ -1970,11 +1970,31 @@ static void add_pending_commit_list(struct rev_info *revs,
}
}
static const char *lookup_other_head(struct object_id *oid)
{
int i;
static const char *const other_head[] = {
"MERGE_HEAD", "CHERRY_PICK_HEAD", "REVERT_HEAD", "REBASE_HEAD"
};
for (i = 0; i < ARRAY_SIZE(other_head); i++)
if (!read_ref_full(other_head[i],
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
oid, NULL)) {
if (is_null_oid(oid))
die(_("%s exists but is a symbolic ref"), other_head[i]);
return other_head[i];
}
die(_("--merge requires one of the pseudorefs MERGE_HEAD, CHERRY_PICK_HEAD, REVERT_HEAD or REBASE_HEAD"));
}
static void prepare_show_merge(struct rev_info *revs)
{
struct commit_list *bases;
struct commit *head, *other;
struct object_id oid;
const char *other_name;
const char **prune = NULL;
int i, prune_num = 1; /* counting terminating NULL */
struct index_state *istate = revs->repo->index;
@ -1982,11 +2002,10 @@ static void prepare_show_merge(struct rev_info *revs)
if (repo_get_oid(the_repository, "HEAD", &oid))
die("--merge without HEAD?");
head = lookup_commit_or_die(&oid, "HEAD");
if (repo_get_oid(the_repository, "MERGE_HEAD", &oid))
die("--merge without MERGE_HEAD?");
other = lookup_commit_or_die(&oid, "MERGE_HEAD");
other_name = lookup_other_head(&oid);
other = lookup_commit_or_die(&oid, other_name);
add_pending_object(revs, &head->object, "HEAD");
add_pending_object(revs, &other->object, "MERGE_HEAD");
add_pending_object(revs, &other->object, other_name);
bases = repo_get_merge_bases(the_repository, head, other);
add_rev_cmdline_list(revs, bases, REV_CMD_MERGE_BASE, UNINTERESTING | BOTTOM);
add_pending_commit_list(revs, bases, UNINTERESTING | BOTTOM);