From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Mark Ruvald Pedersen <mped@oticon.com>,
Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH 2/2] rebase: allow overriding the maximal length of the generated labels
Date: Thu, 10 Aug 2023 16:35:00 +0000 [thread overview]
Message-ID: <fa757ac107d58a607a2faabd3e70934ee22d1b51.1691685300.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1562.git.git.1691685300.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
With this change, users can override the compiled-in default for the
maximal length of the label names generated by `git rebase
--rebase-merges`.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Mark Ruvald Pedersen <mped@demant.com>
---
Documentation/config/rebase.txt | 6 ++++++
sequencer.c | 8 ++++++--
t/t3430-rebase-merges.sh | 11 +++++++++++
3 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/Documentation/config/rebase.txt b/Documentation/config/rebase.txt
index afaf6dad99b..9c248accec2 100644
--- a/Documentation/config/rebase.txt
+++ b/Documentation/config/rebase.txt
@@ -77,3 +77,9 @@ rebase.rebaseMerges::
equivalent to `--no-rebase-merges`. Passing `--rebase-merges` on the
command line, with or without an argument, overrides any
`rebase.rebaseMerges` configuration.
+
+rebase.maxLabelLength::
+ When generating label names from commit subjects, truncate the names to
+ this length. By default, the names are truncated to a little less than
+ `NAME_MAX` (to allow e.g. `.lock` files to be written for the
+ corresponding loose refs).
diff --git a/sequencer.c b/sequencer.c
index be837bd2948..b1fc44f0321 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -5349,6 +5349,7 @@ struct label_state {
struct oidmap commit2label;
struct hashmap labels;
struct strbuf buf;
+ int max_label_length;
};
static const char *label_oid(struct object_id *oid, const char *label,
@@ -5406,7 +5407,7 @@ static const char *label_oid(struct object_id *oid, const char *label,
} else {
struct strbuf *buf = &state->buf;
int label_is_utf8 = 1; /* start with this assumption */
- size_t max_len = buf->len + GIT_MAX_LABEL_LENGTH;
+ size_t max_len = buf->len + state->max_label_length;
/*
* Sanitize labels by replacing non-alpha-numeric characters
@@ -5504,7 +5505,8 @@ static int make_script_with_merges(struct pretty_print_context *pp,
struct string_entry *entry;
struct oidset interesting = OIDSET_INIT, child_seen = OIDSET_INIT,
shown = OIDSET_INIT;
- struct label_state state = { OIDMAP_INIT, { NULL }, STRBUF_INIT };
+ struct label_state state =
+ { OIDMAP_INIT, { NULL }, STRBUF_INIT, GIT_MAX_LABEL_LENGTH };
int abbr = flags & TODO_LIST_ABBREVIATE_CMDS;
const char *cmd_pick = abbr ? "p" : "pick",
@@ -5512,6 +5514,8 @@ static int make_script_with_merges(struct pretty_print_context *pp,
*cmd_reset = abbr ? "t" : "reset",
*cmd_merge = abbr ? "m" : "merge";
+ git_config_get_int("rebase.maxlabellength", &state.max_label_length);
+
oidmap_init(&commit2todo, 0);
oidmap_init(&state.commit2label, 0);
hashmap_init(&state.labels, labels_cmp, NULL, 0);
diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
index 96ae0edf1e1..ac5c390652f 100755
--- a/t/t3430-rebase-merges.sh
+++ b/t/t3430-rebase-merges.sh
@@ -586,4 +586,15 @@ test_expect_success 'progress shows the correct total' '
test_line_count = 14 progress
'
+test_expect_success 'truncate label names' '
+ commit=$(git commit-tree -p HEAD^ -p HEAD -m "0123456789 我 123" HEAD^{tree}) &&
+ git merge --ff-only $commit &&
+
+ done="$(git rev-parse --git-path rebase-merge/done)" &&
+ git -c rebase.maxLabelLength=14 rebase --rebase-merges -x "cp \"$done\" out" --root &&
+ grep "label 0123456789-我$" out &&
+ git -c rebase.maxLabelLength=13 rebase --rebase-merges -x "cp \"$done\" out" --root &&
+ grep "label 0123456789-$" out
+'
+
test_done
--
gitgitgadget
next prev parent reply other threads:[~2023-08-10 16:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-10 16:34 [PATCH 0/2] sequencer: truncate lockfile and ref to NAME_MAX Mark Ruvald Pedersen via GitGitGadget
2023-08-10 16:34 ` [PATCH 1/2] sequencer: truncate labels to accommodate loose refs Mark Ruvald Pedersen via GitGitGadget
2023-08-10 17:12 ` Junio C Hamano
2023-08-16 8:36 ` Johannes Schindelin
2023-08-16 16:28 ` Junio C Hamano
2023-08-10 16:35 ` Johannes Schindelin via GitGitGadget [this message]
2023-08-10 17:15 ` [PATCH 2/2] rebase: allow overriding the maximal length of the generated labels Junio C Hamano
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=fa757ac107d58a607a2faabd3e70934ee22d1b51.1691685300.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
--cc=mped@oticon.com \
/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).