]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ml/log-merge-with-cherry-pick-and-other-pseudo-heads'
authorJunio C Hamano <gitster@pobox.com>
Thu, 7 Mar 2024 23:59:41 +0000 (15:59 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 7 Mar 2024 23:59:41 +0000 (15:59 -0800)
"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

Documentation/rev-list-options.txt
revision.c

index bb753b62929c10f5ccc9fc70034ab63a3b6bb7a1..408d9314d0887969a8cb485b59265a3c4b570ced 100644 (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
index 8f0d638af1a14a7db97065c870d66e78ec8239cd..0b18b3aa5fa5609ed073aa9d7fcaff80b5e0a206 100644 (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);