]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rebase: allow overriding the maximal length of the generated labels
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 10 Aug 2023 16:35:00 +0000 (16:35 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 10 Aug 2023 17:12:31 +0000 (10:12 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/rebase.txt
sequencer.c
t/t3430-rebase-merges.sh

index afaf6dad99b5542ab06c31e4276a695128ee6b8a..9c248accec2c5d572cf11f26ffcbfe8e7eab1465 100644 (file)
@@ -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).
index c3e23a91f364427aca7735f2ad257c59cf796c0c..5b9b81ea877bf1dacfa4266b71a58b66701984f9 100644 (file)
@@ -5339,6 +5339,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,
@@ -5396,7 +5397,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
@@ -5494,7 +5495,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",
@@ -5502,6 +5504,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);
index 96ae0edf1e17275825c2f6fdd57f09431834ed77..ac5c390652f381ce7a85e37863ac17becc655734 100755 (executable)
@@ -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