From patchwork Wed Feb 28 13:54:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13575520 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98AC2158D66 for ; Wed, 28 Feb 2024 13:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128508; cv=none; b=tBGi705NiymqEbomvqO7o6TVsujmwKBrd9BW4BGhc/oZMaruxhJr9fPm7zIV3i1YQHAc2qlBpJHXwW10sWZ0XrntqDeKCZ+RbSJnIHTyC4/DPebNmNrL27azT1eC2bkcy8LD2QG/WD/4I2tKF48gUcFnt7mYv4i75Hmx4/h/kQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128508; c=relaxed/simple; bh=42AK6hl/WACClrSMQONOe4tU4sTh7Q7GZLmaHSNvFaM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=r1GJzzMjtsjhjlRI+4K1bBvQEp3Y3Xo/1VRwJqceh9nVWRj1InR6uCF8bees8omhyyB0EwqkOilELh4hNvEsGFcpkFzrwUOItrxyTwMdV+nY/FoRv8xyZWO+UdnWR24PsVE71YoV3bX5U5NF8erCX1PE0lnB54bb3OZ7RkNkGs0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dVSb3Wt7; arc=none smtp.client-ip=209.85.219.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dVSb3Wt7" Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-68f51c5f9baso30660726d6.3 for ; Wed, 28 Feb 2024 05:55:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709128505; x=1709733305; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Hsc2hx8vPi4zbZr2MfgSJmjIiKrVi/+W8V1s5lD25M4=; b=dVSb3Wt7zqc62MDkO3Bc19P1zD4BvyXzz8hl3b6VNLMMIu+XT50+6XIgFZhUAvl8cb iCfivfVcpM4qhYfUYGKBZU7/pZXQ/Scyl0CNJO/DfrlfBqR+GI/eqf4bwtjJxKmbe80h uU9ZfuEbQmq5kZZZVKzeG86BOxk4+fSEMMy7ShdmnOyg96hft3iVZQAo8npwANw9OPKA BhKRAIcIrQvAFZrsZvm9eL9gaIw05zax0LJ796H2uZr8Bf+HryKMR57NAcBFyVlANx12 43iRcTyIvCv8wommaccqTYQjVaZ/ehGTTGwENtz7izUopBRb0qkMSsm4BhjldGg4B64r um4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128505; x=1709733305; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Hsc2hx8vPi4zbZr2MfgSJmjIiKrVi/+W8V1s5lD25M4=; b=oq/vlff1VEW/hJN+uCAMeDrlTLm7RUiTVSMIvQCn6KFI4Qfq8EhvoM1GH6jt2yfqug hzmJtueJQI2ooVGP0eX/DBJv2GPJGQARY8cxvB0YuZE/xKIXYLYtEYsvu9Z0KnUj4U27 5uKalQXF0VmocG5VI92dmKBdUrMtCMk6cLJJWzxvWx5oByWyGYn5DTh0tM2KQ0APL6h/ NsaSbvh2McE2FUwg2B+hyI4Hx4PyYGs2qV9Gr0bMk7moFA5AyOgH1p/I0SYlF7+ltyEr 9qStoPycoC5qhfDMErCQtMtvAFh4ARY2S8Ei5f3wY6PqjYVwHEVjzeGAq3F3XHA0Pwl2 QNsQ== X-Gm-Message-State: AOJu0Yx4O+tUoe6nwKUhGK0AgJLRYiM717ndXTXRzKGXLg1z3Zxj4xwg WWQ+uBEoUqt7iaDOVuR/yvKeBfWW92CTADhVjXIBQd2IxzfS7X+EUPsD2ny0pFQ= X-Google-Smtp-Source: AGHT+IHpvlipDHS/1Dn/fYQ/rPWHGWV3sPzaeRR2zvMIuFVQEXnkLOo38cPcMcUXzjW3UXiqqBV/Mg== X-Received: by 2002:a05:6214:20ec:b0:68f:301b:5482 with SMTP id 12-20020a05621420ec00b0068f301b5482mr6023414qvk.8.1709128505518; Wed, 28 Feb 2024 05:55:05 -0800 (PST) Received: from [127.0.0.1] ([2606:6d00:11:ff90:f134:2d0a:620a:ef80]) by smtp.gmail.com with ESMTPSA id jh15-20020a0562141fcf00b0068fa78ccef7sm5247839qvb.116.2024.02.28.05.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 05:55:05 -0800 (PST) From: Philippe Blain Date: Wed, 28 Feb 2024 08:54:53 -0500 Subject: [PATCH v6 1/2] revision: ensure MERGE_HEAD is a ref in prepare_show_merge Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240228-ml-log-merge-with-cherry-pick-and-other-pseudo-heads-v6-1-8ec34c052b39@gmail.com> References: <20240228-ml-log-merge-with-cherry-pick-and-other-pseudo-heads-v6-0-8ec34c052b39@gmail.com> In-Reply-To: <20240228-ml-log-merge-with-cherry-pick-and-other-pseudo-heads-v6-0-8ec34c052b39@gmail.com> To: git@vger.kernel.org Cc: Johannes Sixt , Elijah Newren , Michael Lohmann , Phillip Wood , Patrick Steinhardt , Junio C Hamano , Michael Lohmann , Philippe Blain X-Mailer: b4 0.14-dev From: Michael Lohmann This is done to (1) ensure MERGE_HEAD is a ref, (2) obtain the oid without any prefixing by refs.c:repo_dwim_ref() (3) error out when MERGE_HEAD is a symref. Note that we avoid marking the new error message for translation as it will be done in the next commit when the message is generalized to other special refs. Helped-by: Junio C Hamano Signed-off-by: Michael Lohmann Signed-off-by: Junio C Hamano Signed-off-by: Philippe Blain --- revision.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/revision.c b/revision.c index 2424c9bd67..df775f74d0 100644 --- a/revision.c +++ b/revision.c @@ -1973,8 +1973,12 @@ 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)) + if (read_ref_full("MERGE_HEAD", + RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE, + &oid, NULL)) die("--merge without MERGE_HEAD?"); + if (is_null_oid(&oid)) + die(_("MERGE_HEAD exists but is a symbolic ref")); other = lookup_commit_or_die(&oid, "MERGE_HEAD"); add_pending_object(revs, &head->object, "HEAD"); add_pending_object(revs, &other->object, "MERGE_HEAD"); From patchwork Wed Feb 28 13:54:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13575521 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79E89158D99 for ; Wed, 28 Feb 2024 13:55:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128509; cv=none; b=SiuxUYEIWj5Z/iOH+M2iUtHVPAasUBNo8YcqdfNdkPXne2fmXVOUcfWW5d8nQ9IVq6GHLq5ZBfpwD5LZmWsuvFQ2hdryQNF4KFtafn4PH6INvYtPExGl/zIElGQMzcEoXbwJTYPQZ+funqJA/9xGKnYOk/eEZ0ECIovc8jEEj30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709128509; c=relaxed/simple; bh=GR9NxrziFxDCJqYOzslF37bSHAB+oguJ/kCJz++Apuo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hqIPJxmHZofGJEKXl6lQhsVrBbGjLTXxOSTswgT1FQbXL6jpKLLt4cqHsNpJbbqrnWsJqvvWdQiAPpBO+J5MYonpQ2f39Z681hulTJla1tigt8jq6nduiqk5R7xlXA4Ol9+NGkQhjAZNKkPSb2zOiiJw/8rAWQl8+DtIQQVoDso= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HiWhtxwN; arc=none smtp.client-ip=209.85.219.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HiWhtxwN" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-6900f479e3cso25393196d6.0 for ; Wed, 28 Feb 2024 05:55:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709128506; x=1709733306; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=+GhcVD01gDVAruHKpHzbKGpvaJTb9p+Wc7Oa865t0m0=; b=HiWhtxwNuAB1tKibuzD6ZaQXP67Z8urvPLqmEME5q0+xC7zLPeIleE68OzcqihyKaQ x06K7WqLSNWAP/ymUyHTPzk7y1SY2FKsGH+eTBE9amIL5nl3mZYAO9e4Hj40EEKU1n7I 4Xg8CHG2nxe3RcAM/+X9gz+/zxbtaVRNeWdKQr4EFPG03OH4fGhO0p70nXJgUchZJQry wjf1lHh8HZIwoZXyOQDoLccWT5brs5lFSaKlH4xB1SBzZvs28GDnTfZch6IrSd1SnBrm yjD7hYwGnQ/KbamCQbUICoDY8C33ap9KwXGzMzY7KAn5zTkkDy+0ZMLARBwZzMVyaMn7 d11A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709128506; x=1709733306; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+GhcVD01gDVAruHKpHzbKGpvaJTb9p+Wc7Oa865t0m0=; b=S3fb9k6UizuQMUV3SDYo3Sw+5op9sPEXhRU7j2uTd2oUoAV2VTdQuho9JPYhcVgOb6 +f7n5gEmqnGj7Ys53wLb2eVhrSRGoav0lOPCkaEyoKGZDKQo7e9CrQpoJRP39/r1sA3Z CctSA4AUMdHZOeBQXZu8FT0B0zQWluaZvzAKIOrvU8BbF3EDF3Ah9lEyU2HOB7ZGw1/U Jq7oW3xl1keBk/JLJX7WgbtuxEL/Dyff/FAHYJt5P/mOnM5uP4FO8cDgDuBibQjj02hV x+5MK/Ge+gtv6YxYLuXpwXoZf4PLrIrIIBqjFXjW1UYXjraPsT2DXC4V5k9MqBnRajRN FGyQ== X-Gm-Message-State: AOJu0YwxQeEOs07ne7j5j/JMODMvGZnh/SXG3RA3UNA1HnTDL6VZlJ4u M2cD2BuaXMD5cWwN3qm3Lm+qOoEuDO85K7cXq+T350Tx87SB8yLa X-Google-Smtp-Source: AGHT+IHt+inqHHQlQJqi6irnn+jlHgv4xbC/aZxfrRorTz1pIqq7sMVYsV3wrGK/NGbwU2erm2/AjA== X-Received: by 2002:a0c:e28c:0:b0:68f:f9aa:f502 with SMTP id r12-20020a0ce28c000000b0068ff9aaf502mr5536977qvl.25.1709128506377; Wed, 28 Feb 2024 05:55:06 -0800 (PST) Received: from [127.0.0.1] ([2606:6d00:11:ff90:f134:2d0a:620a:ef80]) by smtp.gmail.com with ESMTPSA id jh15-20020a0562141fcf00b0068fa78ccef7sm5247839qvb.116.2024.02.28.05.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 05:55:06 -0800 (PST) From: Philippe Blain Date: Wed, 28 Feb 2024 08:54:54 -0500 Subject: [PATCH v6 2/2] revision: implement `git log --merge` also for rebase/cherry-pick/revert Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240228-ml-log-merge-with-cherry-pick-and-other-pseudo-heads-v6-2-8ec34c052b39@gmail.com> References: <20240228-ml-log-merge-with-cherry-pick-and-other-pseudo-heads-v6-0-8ec34c052b39@gmail.com> In-Reply-To: <20240228-ml-log-merge-with-cherry-pick-and-other-pseudo-heads-v6-0-8ec34c052b39@gmail.com> To: git@vger.kernel.org Cc: Johannes Sixt , Elijah Newren , Michael Lohmann , Phillip Wood , Patrick Steinhardt , Junio C Hamano , Michael Lohmann , Philippe Blain X-Mailer: b4 0.14-dev From: Michael Lohmann 'git log' learned in ae3e5e1ef2 (git log -p --merge [[--] paths...], 2006-07-03) to show commits touching conflicted files in the range HEAD...MERGE_HEAD, an addition documented in d249b45547 (Document rev-list's option --merge, 2006-08-04). It can be useful to look at the commit history to understand what lead to merge conflicts also for other mergy operations besides merges, like cherry-pick, revert and rebase. For rebases and cherry-picks, an interesting range to look at is HEAD...{REBASE_HEAD,CHERRY_PICK_HEAD}, since even if all the commits included in that range are not directly part of the 3-way merge, conflicts encountered during these operations can indeed be caused by changes introduced in preceding commits on both sides of the history. For revert, as we are (most likely) reversing changes from a previous commit, an appropriate range is REVERT_HEAD..HEAD, which is equivalent to REVERT_HEAD...HEAD and to HEAD...REVERT_HEAD, if we keep HEAD and its parents on the left side of the range. As such, adjust the code in prepare_show_merge so it constructs the range HEAD...$OTHER for OTHER={MERGE_HEAD, CHERRY_PICK_HEAD, REVERT_HEAD or REBASE_HEAD}. Note that we try these pseudorefs in order, so keep REBASE_HEAD last since the three other operations can be performed during a rebase. Note also that in the uncommon case where $OTHER and HEAD do not share a common ancestor, this will show the complete histories of both sides since their root commits, which is the same behaviour as currently happens in that case for HEAD and MERGE_HEAD. Adjust the documentation of this option accordingly. Co-authored-by: Johannes Sixt Co-authored-by: Philippe Blain Signed-off-by: Michael Lohmann [jc: tweaked in j6t's precedence fix that tries REBASE_HEAD last] Signed-off-by: Junio C Hamano Signed-off-by: Philippe Blain --- Documentation/rev-list-options.txt | 7 +++++-- revision.c | 31 +++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index a583b52c61..29e7b50bcf 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -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...`, + where `` 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 diff --git a/revision.c b/revision.c index df775f74d0..d2ebdd045a 100644 --- a/revision.c +++ b/revision.c @@ -1961,11 +1961,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; @@ -1973,15 +1993,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 (read_ref_full("MERGE_HEAD", - RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE, - &oid, NULL)) - die("--merge without MERGE_HEAD?"); - if (is_null_oid(&oid)) - die(_("MERGE_HEAD exists but is a symbolic ref")); - 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);