git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nicolas Guichard via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Nicolas Guichard <nicolas@guichard.eu>
Subject: [PATCH v2 0/3] rebase-merges: try and use branch names for labels
Date: Fri, 04 Oct 2024 23:22:17 +0000	[thread overview]
Message-ID: <pull.1784.v2.git.git.1728084140.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1784.git.git.1726943880.gitgitgadget@gmail.com>

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


which 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.

Changes since v1:

 * moved load_branch_decorations to re-use the decoration_loaded guard and
   avoid pointlessly appending "refs/heads/" to a static string_list, as
   pointed out by Junio C Hamano (thanks!)
 * fixed a leak in load_branch_decorations found by making the filter
   string_lists non-static

Nicolas Guichard (3):
  load_branch_decorations: fix memory leak with non-static filters
  rebase-update-refs: extract load_branch_decorations
  rebase-merges: try and use branch names as labels

 log-tree.c                    | 26 +++++++++++++++++++++++++
 log-tree.h                    |  1 +
 sequencer.c                   | 36 +++++++++++++++++------------------
 t/t3404-rebase-interactive.sh |  4 ++--
 t/t3430-rebase-merges.sh      | 12 ++++++------
 5 files changed, 53 insertions(+), 26 deletions(-)


base-commit: 8895aca99693e22ec4856744d5b2c25b8736a111
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1784%2Fnicolas-guichard%2Fuse-branch-names-for-rebase-merges-labels-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1784/nicolas-guichard/use-branch-names-for-rebase-merges-labels-v2
Pull-Request: https://github.com/git/git/pull/1784

Range-diff vs v1:

 -:  ----------- > 1:  6250a7f6d6c load_branch_decorations: fix memory leak with non-static filters
 1:  7f3d5e5da35 ! 2:  167418d10d1 sequencer.c: extract load_branch_decorations
     @@ Metadata
      Author: Nicolas Guichard <nicolas@guichard.eu>
      
       ## Commit message ##
     -    sequencer.c: extract load_branch_decorations
     +    rebase-update-refs: extract load_branch_decorations
      
          Extract load_branch_decorations from todo_list_add_update_ref_commands so
          it can be re-used in make_script_with_merges.
      
     +    Since it can now be called multiple times, use non-static lists and place
     +    it next to load_ref_decorations to re-use the decoration_loaded guard.
     +
          Signed-off-by: Nicolas Guichard <nicolas@guichard.eu>
      
     - ## sequencer.c ##
     -@@ sequencer.c: static const char *label_oid(struct object_id *oid, const char *label,
     - 	return string_entry->string;
     + ## log-tree.c ##
     +@@ log-tree.c: void load_ref_decorations(struct decoration_filter *filter, int flags)
     + 	}
       }
       
     -+static void load_branch_decorations(void)
     ++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);
     ++	if (!decoration_loaded) {
     ++		struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
     ++		struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
     ++		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);
     ++
     ++		string_list_clear(&decorate_refs_exclude, false);
     ++		string_list_clear(&decorate_refs_exclude_config, false);
     ++		string_list_clear(&decorate_refs_include, false);
     ++	}
      +}
      +
     - static int make_script_with_merges(struct pretty_print_context *pp,
     - 				   struct rev_info *revs, struct strbuf *out,
     - 				   unsigned flags)
     + static void show_parents(struct commit *commit, int abbrev, FILE *file)
     + {
     + 	struct commit_list *p;
     +
     + ## log-tree.h ##
     +@@ log-tree.h: void log_write_email_headers(struct rev_info *opt, struct commit *commit,
     + 			     int *need_8bit_cte_p,
     + 			     int maybe_multipart);
     + void load_ref_decorations(struct decoration_filter *filter, int flags);
     ++void load_branch_decorations(void);
     + 
     + void fmt_output_commit(struct strbuf *, struct commit *, struct rev_info *);
     + void fmt_output_subject(struct strbuf *, const char *subject, struct rev_info *);
     +
     + ## sequencer.c ##
      @@ sequencer.c: static int add_decorations_to_list(const struct commit *commit,
       static int todo_list_add_update_ref_commands(struct todo_list *todo_list)
       {
 2:  9afe428927d = 3:  dfa1f0a7648 rebase-merges: try and use branch names as labels

-- 
gitgitgadget

  parent reply	other threads:[~2024-10-04 23:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-21 18:37 [PATCH 0/2] rebase-merges: try and use branch names for labels Nicolas Guichard via GitGitGadget
2024-09-21 18:37 ` [PATCH 1/2] sequencer.c: extract load_branch_decorations Nicolas Guichard via GitGitGadget
2024-09-23 19:32   ` Junio C Hamano
2024-09-21 18:38 ` [PATCH 2/2] rebase-merges: try and use branch names as labels Nicolas Guichard via GitGitGadget
2024-09-23 19:38   ` Junio C Hamano
2024-10-04 23:22 ` Nicolas Guichard via GitGitGadget [this message]
2024-10-04 23:22   ` [PATCH v2 1/3] load_branch_decorations: fix memory leak with non-static filters Nicolas Guichard via GitGitGadget
2024-10-05  3:43     ` Eric Sunshine
2024-10-04 23:22   ` [PATCH v2 2/3] rebase-update-refs: extract load_branch_decorations Nicolas Guichard via GitGitGadget
2024-10-05  3:44     ` Eric Sunshine
2024-10-04 23:22   ` [PATCH v2 3/3] rebase-merges: try and use branch names as labels Nicolas Guichard via GitGitGadget
2024-10-09  7:58   ` [PATCH v3 0/3] rebase-merges: try and use branch names for labels Nicolas Guichard via GitGitGadget
2024-10-09  7:58     ` [PATCH v3 1/3] load_branch_decorations: fix memory leak with non-static filters Nicolas Guichard via GitGitGadget
2024-10-09  7:58     ` [PATCH v3 2/3] rebase-update-refs: extract load_branch_decorations Nicolas Guichard via GitGitGadget
2024-10-09  7:58     ` [PATCH v3 3/3] rebase-merges: try and use branch names as labels Nicolas Guichard via GitGitGadget
2024-10-09 14:21       ` Phillip Wood
2024-10-09 17:57         ` Junio C Hamano
2024-10-09 14:22     ` [PATCH v3 0/3] rebase-merges: try and use branch names for labels Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1784.v2.git.git.1728084140.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=nicolas@guichard.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).