From patchwork Wed Jan 17 08:14:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Lohmann X-Patchwork-Id: 13521467 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 16782D510 for ; Wed, 17 Jan 2024 08:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705479260; cv=none; b=bC8DQXxHr5kKPkTvfByR7HhgXzNz6kiCMI5p0upEcqIQhNlBvOTnAwJLOqVpzX0klMQ+Ix2AEWbqyLdR08Fmw847CmofYXFabu6HJ9RJBTBhST0j/KAs3R94tMnjjC8kc8vaf+jrZsFvTft6OEgU0i4N4bHBlbdO7oXHax414eU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705479260; c=relaxed/simple; bh=aLePuuptoe1N4F0QBY5Lb1B38BO7eHBU9bGuxL4u8LE=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received:Sender: From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; b=P5/kHAJsPlzhWDXIqivzRjtedRnLGNNL/X8mxBTESGNgnph4zLtmZ055FeY7EG5QA0Msre7cE6vvcZrMvOpqr5yRs+Ug30HCV7MkrOqTxoteuGr8mxDAbeDcDmbOWix8hHu97zp5i6lmhwQINsqWExki4PUdemXh29QlvEhw0KI= 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=ikN4AVbb; arc=none smtp.client-ip=209.85.167.42 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="ikN4AVbb" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-50e80d40a41so13682634e87.1 for ; Wed, 17 Jan 2024 00:14:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705479257; x=1706084057; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=PY/854c17wU6Wk1QuYiDzlOdSnPez8PthpA+EukTAcg=; b=ikN4AVbbmuLzfqgCVuypimG6LEcr0+tumrmXS0rxucUdcFpuUr/aVphbX2IEseaG+e q4GrDw7WyPymSAxzq5ktqRpx4Q+FeRR0+eTcaHRzhZ8YlGP9ADiOVEa3NdsLHwO4Nm0y C5LLQLcWPkNA5DOGv3LhBmGGer/cIQO9Ofa0He0d9MhjWICGoCUNGSbVEMc0mUx+/+NQ cqnMU5B1/JXZNQSuXyjOxn7tL385wExEQV9vkFzxtojVbCPXhjexPOJU136uv+bzyedg clefjWWYBXATAQbdQoBvbBmLxD4azZeGWnaw+Yk+O+3y+wthTP6kDf1b5tj/3EeLIzLD 1Z0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705479257; x=1706084057; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=PY/854c17wU6Wk1QuYiDzlOdSnPez8PthpA+EukTAcg=; b=rUz4cZlIVaO7/duGsv1wn9iYOPlHXvHLr058Uixqm9EicMAzILfJX3S5TizT4oG1Ab G4CROFx8pPla0+F+XboM/SdN7R4tAMfzOADQHD0rELjTInWXccO6DQNeh/9e+S3wyIyX PayEnNIl5TixYwQLGGOYEbjmESHIQRojiR2fxu3sftzu9qT5RAOK+c56Ze8a5x+KH//x 2cS+81Ewrxq/C8A7eqeddEbHRf6asFmMxXIQ4iBzgYQv/HGgIBl3CjQDHfX2eNwpAcGO 2HLwmPm9IeA40ns0zoqpe/GB3lif7fvQwByPMNtx2w2l9ARuQN8jncNY0j/Pbarb9Utq Hucw== X-Gm-Message-State: AOJu0YyrODC6v3Xd8uPFSo0wPI1SkdPv4BXS+tH4QS2iMnelFnh01snK zaTZiFjhAJTH0bJ422vG/qY= X-Google-Smtp-Source: AGHT+IGULeKT4h6wf0kJYQqJltYSbqgCqt4KaakxphN8cCVFSle/6bovgLwWAVsioPdXOz4GB5pOgg== X-Received: by 2002:a05:6512:3a95:b0:50e:7bd0:1c3d with SMTP id q21-20020a0565123a9500b0050e7bd01c3dmr5507368lfu.97.1705479256688; Wed, 17 Jan 2024 00:14:16 -0800 (PST) Received: from Michaels-MBP.fritz.box (2001-4dd4-dfc5-0-e407-3f73-62bc-9c57.ipv6dyn.netcologne.de. [2001:4dd4:dfc5:0:e407:3f73:62bc:9c57]) by smtp.gmail.com with ESMTPSA id 7-20020a0564021f4700b00557de30e1f1sm7671803edz.74.2024.01.17.00.14.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 Jan 2024 00:14:16 -0800 (PST) Sender: Michael L From: Michael Lohmann To: gitster@pobox.com Cc: git@vger.kernel.org, mi.al.lohmann@gmail.com, newren@gmail.com, phillip.wood123@gmail.com Subject: [PATCH v3 1/2] revision: ensure MERGE_HEAD is a ref in prepare_show_merge Date: Wed, 17 Jan 2024 09:14:04 +0100 Message-Id: <20240117081405.14012-1-mi.al.lohmann@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Helped-by: Junio C Hamano Signed-off-by: Michael Lohmann --- Changes with respect to v2: - use read_ref_full instead of refs_resolve_ref_unsafe - don't use "other_head" variable to store MERGE_HEAD - check for symbolic ref revision.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/revision.c b/revision.c index 2424c9bd67..aa4c4dc778 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 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 Jan 17 08:14:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Lohmann X-Patchwork-Id: 13521468 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (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 3F442D517 for ; Wed, 17 Jan 2024 08:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705479260; cv=none; b=eOE0loSmFqypMR+RSzlPGpWsQmKbJWsne/DNm0bD7gHrA4OPp9uGbooOhouF3Ggr5lgjblWDuTb9/MrEAqwDl54NSEdE0/ERiCfeQc491ATcD8Sx5LKD4dljMeWIltgwGVlJKMPzX9GV0hpuBfAnB78oW78bTQnR/VNcIJVRALE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705479260; c=relaxed/simple; bh=PcKoL2aDnLbeXDne87yhyRey4WbL8nNJzOysrG9n5w4=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received:Sender: From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; b=tQrwSeIIMKWlY/aLLtNSmeZVR8ZPeZ4KllIXWAm0dhEUxOEL0qRiZ80sjqIVJjaaf098aulRo5B93HzvxmdFOi0bSg3oHaciPxYaaOEE+mvYkVL0N17FJViVWIuXGk3OpfjhfYiWttT9209h1L43Gs62ZyQKmP4X7elBRDjkcjE= 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=kGkI/We2; arc=none smtp.client-ip=209.85.208.54 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="kGkI/We2" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-559b3ee02adso1683507a12.3 for ; Wed, 17 Jan 2024 00:14:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705479257; x=1706084057; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=rIimWQvACma+my2nVnHH5WMYddN7CLQWyOnm1muLZF4=; b=kGkI/We2ipJxLaIErVSnHlISNCtpahndz2PmElOOQfoEeZJIL2nvOLctOXxAA+UYk7 wT62oBgwz1J+YnYUIbnva/m7ROpvFM3ZPPAu77JqqBXXYLibYaZxyi1pJbSAhXs2XGt6 dRUM38/idePbsVcKZCqJ8o5RHM6Uj2NCw7+vm4pXvkhy6g7jf9Cr0AvS+Amv3hKPHUOB pNlsyECkMrcXsk4TWz6S3wji/5ZV+/NoOjoChEl/4zS3fVh+VyqgmcohJevFQtyO5JVT Jp5FhQk5QRUUNB2u6Xl9t1Kf8YEHnCHoiLdCpobDNkIognyavEK2uLCPUrvIpEb+Xqhk Xv4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705479257; x=1706084057; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=rIimWQvACma+my2nVnHH5WMYddN7CLQWyOnm1muLZF4=; b=t5rqWQ9BGjxagKM+chqSCrhn1WTMTrxoPYsao9p1OEu7GZBx3mN3ovIV5E9iw0Woc5 taIqrFe91P3fg19/L+k8k9GaDhA2+2VKdVxJrgik0NmN2TjQr8oQozmht2mQWPCg03zN P9AIyTvwgsAqWb6ToMbRKQsaewob1N43pdvuDkiSegmFuwJYA6D2RL1FVNVV1RZ8zw5N ulX5fhYhC+iPMWm/ZvJmPMEV3MJQ/tmk+blFa1zv1kwUwkWSolsz24lp7dmOjgisFMOa UYfoANF2zwjXF+00zpTbW9VOcBLUrcPcgXVB5qPc1ZN2tnnuI+8zqq8h2/+19JtR3FNA Zflw== X-Gm-Message-State: AOJu0Yx9oJMBVoXJYCrMMSk/mefOBu3NA/3FTFssYGYJn7iTDsXUej36 ikbrk9pJHIwSz2dRo+e324s= X-Google-Smtp-Source: AGHT+IG+23ZKdpn7JVJuf7+ZrGr8D8hKGZ81HTrfemSNJZp6RMOBqIWQniAcX2+YUzbCnATF+OZEwQ== X-Received: by 2002:a05:6402:3095:b0:559:b72d:92ce with SMTP id de21-20020a056402309500b00559b72d92cemr655956edb.15.1705479257200; Wed, 17 Jan 2024 00:14:17 -0800 (PST) Received: from Michaels-MBP.fritz.box (2001-4dd4-dfc5-0-e407-3f73-62bc-9c57.ipv6dyn.netcologne.de. [2001:4dd4:dfc5:0:e407:3f73:62bc:9c57]) by smtp.gmail.com with ESMTPSA id 7-20020a0564021f4700b00557de30e1f1sm7671803edz.74.2024.01.17.00.14.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 Jan 2024 00:14:16 -0800 (PST) Sender: Michael L From: Michael Lohmann To: gitster@pobox.com Cc: git@vger.kernel.org, mi.al.lohmann@gmail.com, newren@gmail.com, phillip.wood123@gmail.com, Johannes Sixt Subject: [PATCH v3 2/2] revision: Implement `git log --merge` also for rebase/cherry_pick/revert Date: Wed, 17 Jan 2024 09:14:05 +0100 Message-Id: <20240117081405.14012-2-mi.al.lohmann@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240117081405.14012-1-mi.al.lohmann@gmail.com> References: <20240117081405.14012-1-mi.al.lohmann@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Co-authored-by: Johannes Sixt Signed-off-by: Michael Lohmann Signed-off-by: Michael Lohmann Signed-off-by: Junio C Hamano --- On 12. Jan 2024, at 21:18, Junio C Hamano wrote: > I like the way your other_merge_candidate() loops over an array of > possible candidates, which makes it a lot easier to extend, though, > admittedly the "die()" message needs auto-generating if we really > wanted to make it maintenance free ;-) I would certainly like that but I did not find an easy way of achieving this in C. Help wanted. Changes with respect to v2: - use read_ref_full instead of refs_resolve_ref_unsafe - check for symbolic ref - extract "other_name" in this patch, instead of patch 1 revision.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/revision.c b/revision.c index aa4c4dc778..c778413c7d 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", "REBASE_HEAD", "CHERRY_PICK_HEAD", "REVERT_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 is a symbolic ref???", other_head[i]); + return other_head[i]; + } + + die("--merge without MERGE_HEAD, REBASE_HEAD, CHERRY_PICK_HEAD or REVERT_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 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);