From patchwork Sat Sep 21 18:37:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Guichard X-Patchwork-Id: 13808968 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 46D6C2B9A5 for ; Sat, 21 Sep 2024 18:38:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726943885; cv=none; b=qlI4GpAXWKvjRzAYdKmw9bETCz8wwY9gS1fFrjixiPlOAC2MKmkqCgojMuo7Lm5mWeJlDUJl+LMwARrBosFwPBz/t/BtKH+T1244YsLFTE3XNYqmMkbAcOzR7FOfOKrVdKMlxPiYiavnwnc+DKDg/ZswrhoVdwTtztGdKhhSqNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726943885; c=relaxed/simple; bh=sRSInpGC/Gjvd28IQb3k75hP9iHU1CP+v7jJZMqyILU=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=cLwDcIRy6lqaTyTMxyvIz8z9DCa8ZtDjqdGbPD0ssX3BlQjlQTLf15OIYfVE02d1rAdUP+QcwLnLHYu/NcxtSRV8lSRhBGvTIN9C85oZ9dNZlFeKouW4KpERdkDUriRp9gZq43adq0aAlewOkWQ1jkiTzhjsHfIpgp75q5h9zso= 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=lQVFQ7lp; arc=none smtp.client-ip=209.85.218.43 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="lQVFQ7lp" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a8d100e9ce0so372655166b.2 for ; Sat, 21 Sep 2024 11:38:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726943882; x=1727548682; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=y3lUiRaPU/VBZ9o31F4aIJh+0EZAHSL2RUeZaItGub8=; b=lQVFQ7lpT43hDjzDsWWc9NzjkEzC7qGrT2JEZA8wBZf5rry+b6pxGXBgYTO8SdNYj2 Xk0uSccTYsq4v7Ds4tXJMVd5VIfXxZ16ziFsn9VMgRU8Sysib6rY96JokF4AQbfvnGuU Zozo6UT8OmhYLOavEUClSo7xAWpIw3bfttNfWIEo+uk0Pyze1pbTcWxODskRD2zMxo1g hQn3bS98YWWxY9mLZ/lEHjD9zc+9H7cm+LSEUK7U80fBxEd5QbznIsr5LQNGWjVnZtwC tIGRCuGcEiKuPyXcmsPh4Sh5ZTkG7LLf3IFCT4b9uUgcE22nKWNPc01cWboRwuhDtnfA KglQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726943882; x=1727548682; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y3lUiRaPU/VBZ9o31F4aIJh+0EZAHSL2RUeZaItGub8=; b=kBxivEkUyvEh9xvaBDdPpUVePqxrWPNDJRPc6X4eJiUR++c/9UBjlN5wy6vzFSsDDO RX+/sWuLS0+k8ADP5B5ozPvM597dZeDfArPMC/8/nBWdroa++rg4D8X91X/DAV3T/sBS 9SpBNxnfQ3OiB07KgPe+xzUpP2BJbnw5MGvHvfDDeqkk8pHj2odkdErdzPijvU9AopVd ePPqVyP4eXqBEVgzqDkJRDC5Y3lCPDHkv0jP1pLlsI5vc2lQFbp0KxdklkgNqWPQF/OC ak1BeDTuwx364/R5NAkf+eevrPYQUL+cE8UWV5f8ubdEHzavWDbajDjlZenF/x1jNlEr ygTQ== X-Gm-Message-State: AOJu0YyKS6Xn+o6rt3s0jHMrpClPu6k9RvgObmTR5tnbOt8IYOXm6mbW mv+sNqqqYGoS1iKpmZ+gOuty3f4yChOjvocnoGj3k6mcAZB6UHqPdmvhcA== X-Google-Smtp-Source: AGHT+IH7tCjUooyURq/v+D7gvzz4z2dWrscg/rlzK6VYFQBMlpbXutsk3fWQN28TyqRxyS9p+HRHww== X-Received: by 2002:a17:907:d869:b0:a8d:51d6:b3ef with SMTP id a640c23a62f3a-a90d5835e39mr603817666b.56.1726943881926; Sat, 21 Sep 2024 11:38:01 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90610962d1sm997761066b.32.2024.09.21.11.38.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Sep 2024 11:38:01 -0700 (PDT) Message-Id: <7f3d5e5da356f93ebef300ef73bfd6c312013e09.1726943880.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 21 Sep 2024 18:37:59 +0000 Subject: [PATCH 1/2] sequencer.c: extract load_branch_decorations Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Nicolas Guichard , Nicolas Guichard From: Nicolas Guichard From: Nicolas Guichard Extract load_branch_decorations from todo_list_add_update_ref_commands so it can be re-used in make_script_with_merges. Signed-off-by: Nicolas Guichard --- sequencer.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/sequencer.c b/sequencer.c index 8d01cd50ac9..e5eb6f8cd76 100644 --- a/sequencer.c +++ b/sequencer.c @@ -5810,6 +5810,20 @@ static const char *label_oid(struct object_id *oid, const char *label, return string_entry->string; } +static void load_branch_decorations(void) +{ + static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP; + static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP; + static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP; + struct decoration_filter decoration_filter = { + .include_ref_pattern = &decorate_refs_include, + .exclude_ref_pattern = &decorate_refs_exclude, + .exclude_ref_config_pattern = &decorate_refs_exclude_config, + }; + string_list_append(&decorate_refs_include, "refs/heads/"); + load_ref_decorations(&decoration_filter, 0); +} + static int make_script_with_merges(struct pretty_print_context *pp, struct rev_info *revs, struct strbuf *out, unsigned flags) @@ -6403,14 +6417,6 @@ static int add_decorations_to_list(const struct commit *commit, static int todo_list_add_update_ref_commands(struct todo_list *todo_list) { int i, res; - static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP; - static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP; - static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP; - struct decoration_filter decoration_filter = { - .include_ref_pattern = &decorate_refs_include, - .exclude_ref_pattern = &decorate_refs_exclude, - .exclude_ref_config_pattern = &decorate_refs_exclude_config, - }; struct todo_add_branch_context ctx = { .buf = &todo_list->buf, .refs_to_oids = STRING_LIST_INIT_DUP, @@ -6419,8 +6425,7 @@ static int todo_list_add_update_ref_commands(struct todo_list *todo_list) ctx.items_alloc = 2 * todo_list->nr + 1; ALLOC_ARRAY(ctx.items, ctx.items_alloc); - string_list_append(&decorate_refs_include, "refs/heads/"); - load_ref_decorations(&decoration_filter, 0); + load_branch_decorations(); for (i = 0; i < todo_list->nr; ) { struct todo_item *item = &todo_list->items[i]; From patchwork Sat Sep 21 18:38:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas Guichard X-Patchwork-Id: 13808969 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.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 E66CD2EAE5 for ; Sat, 21 Sep 2024 18:38:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726943886; cv=none; b=macWd4HqoEs4/FgjZi6UWcLFuA18WxUYlXKbEawKLGaQRCLjxb9iA9lMrh54MF4zOgoCpw/CbSDeryyIgjNHaefOipCQBLF9f9M+gCSfqW/V7gR4USQVLOxundkXR7j1vnz9X3kZmhJU+ICakC9nRc/MffaEEkP+qa1xXFYxHMA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726943886; c=relaxed/simple; bh=VGacreGStp+887+1JqzNU3vkRAQ9Sa81o08n1fPxn2Q=; h=Message-Id:In-Reply-To:References:From:Date:Subject:MIME-Version: Content-Type:To:Cc; b=K+H9bUgjgZyair4nCy2TwdnRv8zwOhfqQggusmZgjQcTnXxQxYpf+VV5Ap0b6faQKLgLHSq13NJ5JnhB3WxgfdzSOEU4zIHfLUvRg69/QYiY6efBQLUdCGBlVdMXKjxNDY+hC1rjpIULx5JNwh3uFxz7YtMtrvzRuTvpAMYl5Ms= 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=BMwuRRu7; arc=none smtp.client-ip=209.85.218.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="BMwuRRu7" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a8b155b5e9eso431722566b.1 for ; Sat, 21 Sep 2024 11:38:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726943883; x=1727548683; darn=vger.kernel.org; h=cc:to:fcc:content-transfer-encoding:mime-version:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=3ml4JRejmg2SOm7mBzgk9B2si2qXttZ3P4Q4SCW4Ce4=; b=BMwuRRu7uZ0EdHzhnTvwBuB2avOfyWPxAqhUGqoXH3gdvRxmFxGEWG2+VN1R6BNd8u 08Ct6wSoXLgD9P38kNHygwviulyTH/5Wkk/OzLiP98yxQ6JHCpOaPLH0YgQUbAC4Pgkl jrjoOmlq9gFgw0Z9fZx0mZPh1rycaTE9KDXMipOVqkoe6HKOuf8OAfbKmo4EYCMe4QOE +vtr8d2+aV8HYJ6v81YhH5x9MwI/mkQ3TJCz6m13nwN83zpmxcQREV8v+uKW/FkX5cbm 2uXSDW1azsR7uk4L5PaopGYaVQdukK+/fdCT5Qvt0ia2kSLcUnJKTPbZhwYoumrCLCMJ uBpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726943883; x=1727548683; h=cc:to:fcc:content-transfer-encoding:mime-version:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3ml4JRejmg2SOm7mBzgk9B2si2qXttZ3P4Q4SCW4Ce4=; b=xMgHFFOd0NffIWEypnT/OFpDcYTlH/7U9cFPSsFoWs02jA/6RUrP1rTiSueZDQ5NOc ccW9Zre0LqalHUS0bRMtCz+3MZchTz7d6OEvpLDTyiZb3fEjTOff1bqXLHIignkayxD2 2NzdVMucetQazHPa4O0uBm9bvk1rFVwKeubX0UVFA2ZfKwiaqTT+1e+J+XBPOfX23ZBh 6BC4SE+UpRI4Blg17PLz1bH+qFlhsM13HRHixzkg+Qoj/XhTMEXRxslan6sNckNveLo8 88SGUhQT5x6UdwLGcrV4biy1ncaxK0Iq/XZfgzs23Kly1muFsa6o2tSuPCmOJxQdKTzw rOag== X-Gm-Message-State: AOJu0YwzDd9yZkRxm+Yl+hf1dYxu+LZI6quZeFlNMxBDbXZDjgAi4rhU V7LTG4oZdj7XYxOF1PeZQw286FxpeyNpC3Fgngmfyz/Zr5EY06m3Zp56eQ== X-Google-Smtp-Source: AGHT+IGKt4o0yvu4pfgzlEb2G7M2AUB+4+uSkiHsU85c3OjtIh7S5Gg9+bCgixQD60MpeOyubZyWOg== X-Received: by 2002:a17:906:d7e4:b0:a8d:4d76:a760 with SMTP id a640c23a62f3a-a90d5005e9cmr574709666b.35.1726943882778; Sat, 21 Sep 2024 11:38:02 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90610f3878sm1001346366b.47.2024.09.21.11.38.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Sep 2024 11:38:02 -0700 (PDT) Message-Id: <9afe428927d71df360929238c50284d4c59beaea.1726943880.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 21 Sep 2024 18:38:00 +0000 Subject: [PATCH 2/2] rebase-merges: try and use branch names as labels Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: Nicolas Guichard , Nicolas Guichard From: Nicolas Guichard From: Nicolas Guichard When interactively rebasing merge commits, the commit message is parsed to extract a probably meaningful label name. For instance if the merge commit is “Merge branch 'feature0'”, then the rebase script will have thes lines: ``` label feature0 merge -C $sha feature0 # “Merge branch 'feature0' ``` This heuristic fails in the case of octopus merges or when the merge commit message is actually unrelated to the parent commits. An example that combines both is: ``` *---. 967bfa4 (HEAD -> integration) Integration |\ \ \ | | | * 2135be1 (feature2, feat2) Feature 2 | |_|/ |/| | | | * c88b01a Feature 1 | |/ |/| | * 75f3139 (feat0) Feature 0 |/ * 25c86d0 (main) Initial commit ``` yields the labels Integration, Integration-2 and Integration-3. Fix this by using a branch name for each merge commit's parent that is the tip of at least one branch, and falling back to a label derived from the merge commit message otherwise. In the example above, the labels become feat0, Integration and feature2. Signed-off-by: Nicolas Guichard --- sequencer.c | 25 +++++++++++++++++-------- t/t3404-rebase-interactive.sh | 4 ++-- t/t3430-rebase-merges.sh | 12 ++++++------ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/sequencer.c b/sequencer.c index e5eb6f8cd76..a092bd05692 100644 --- a/sequencer.c +++ b/sequencer.c @@ -5833,7 +5833,7 @@ static int make_script_with_merges(struct pretty_print_context *pp, int root_with_onto = flags & TODO_LIST_ROOT_WITH_ONTO; int skipped_commit = 0; struct strbuf buf = STRBUF_INIT, oneline = STRBUF_INIT; - struct strbuf label = STRBUF_INIT; + struct strbuf label_from_message = STRBUF_INIT; struct commit_list *commits = NULL, **tail = &commits, *iter; struct commit_list *tips = NULL, **tips_tail = &tips; struct commit *commit; @@ -5856,6 +5856,7 @@ static int make_script_with_merges(struct pretty_print_context *pp, oidmap_init(&state.commit2label, 0); hashmap_init(&state.labels, labels_cmp, NULL, 0); strbuf_init(&state.buf, 32); + load_branch_decorations(); if (revs->cmdline.nr && (revs->cmdline.rev[0].flags & BOTTOM)) { struct labels_entry *onto_label_entry; @@ -5916,18 +5917,18 @@ static int make_script_with_merges(struct pretty_print_context *pp, continue; } - /* Create a label */ - strbuf_reset(&label); + /* Create a label from the commit message */ + strbuf_reset(&label_from_message); if (skip_prefix(oneline.buf, "Merge ", &p1) && (p1 = strchr(p1, '\'')) && (p2 = strchr(++p1, '\''))) - strbuf_add(&label, p1, p2 - p1); + strbuf_add(&label_from_message, p1, p2 - p1); else if (skip_prefix(oneline.buf, "Merge pull request ", &p1) && (p1 = strstr(p1, " from "))) - strbuf_addstr(&label, p1 + strlen(" from ")); + strbuf_addstr(&label_from_message, p1 + strlen(" from ")); else - strbuf_addbuf(&label, &oneline); + strbuf_addbuf(&label_from_message, &oneline); strbuf_reset(&buf); strbuf_addf(&buf, "%s -C %s", @@ -5935,6 +5936,14 @@ static int make_script_with_merges(struct pretty_print_context *pp, /* label the tips of merged branches */ for (; to_merge; to_merge = to_merge->next) { + const char *label = label_from_message.buf; + const struct name_decoration *decoration = + get_name_decoration(&to_merge->item->object); + + if (decoration) + skip_prefix(decoration->name, "refs/heads/", + &label); + oid = &to_merge->item->object.oid; strbuf_addch(&buf, ' '); @@ -5947,7 +5956,7 @@ static int make_script_with_merges(struct pretty_print_context *pp, tips_tail = &commit_list_insert(to_merge->item, tips_tail)->next; - strbuf_addstr(&buf, label_oid(oid, label.buf, &state)); + strbuf_addstr(&buf, label_oid(oid, label, &state)); } strbuf_addf(&buf, " # %s", oneline.buf); @@ -6055,7 +6064,7 @@ static int make_script_with_merges(struct pretty_print_context *pp, free_commit_list(commits); free_commit_list(tips); - strbuf_release(&label); + strbuf_release(&label_from_message); strbuf_release(&oneline); strbuf_release(&buf); diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index f171af3061d..4896a801ee2 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -1870,7 +1870,7 @@ test_expect_success '--update-refs adds commands with --rebase-merges' ' pick $(git log -1 --format=%h branch2~1) F pick $(git log -1 --format=%h branch2) I update-ref refs/heads/branch2 - label merge + label branch2 reset onto pick $(git log -1 --format=%h refs/heads/second) J update-ref refs/heads/second @@ -1881,7 +1881,7 @@ test_expect_success '--update-refs adds commands with --rebase-merges' ' update-ref refs/heads/third pick $(git log -1 --format=%h HEAD~2) M update-ref refs/heads/no-conflict-branch - merge -C $(git log -1 --format=%h HEAD~1) merge # merge + merge -C $(git log -1 --format=%h HEAD~1) branch2 # merge update-ref refs/heads/merge-branch EOF diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh index 2aa8593f77a..cb891eeb5fd 100755 --- a/t/t3430-rebase-merges.sh +++ b/t/t3430-rebase-merges.sh @@ -108,19 +108,19 @@ test_expect_success 'generate correct todo list' ' reset onto pick $b B - label E + label first reset onto pick $c C label branch-point pick $f F pick $g G - label H + label second reset branch-point # C pick $d D - merge -C $e E # E - merge -C $h H # H + merge -C $e first # E + merge -C $h second # H EOF @@ -462,11 +462,11 @@ test_expect_success 'A root commit can be a cousin, treat it that way' ' ' test_expect_success 'labels that are object IDs are rewritten' ' - git checkout -b third B && + git checkout --detach B && test_commit I && third=$(git rev-parse HEAD) && git checkout -b labels main && - git merge --no-commit third && + git merge --no-commit $third && test_tick && git commit -m "Merge commit '\''$third'\'' into labels" && echo noop >script-from-scratch &&