Skip to content

Commit ac300bd

Browse files
dschogitster
authored andcommitted
rebase: allow overriding the maximal length of the generated labels
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 <[email protected]> Signed-off-by: Mark Ruvald Pedersen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7481d2b commit ac300bd

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

Documentation/config/rebase.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,9 @@ rebase.rebaseMerges::
7777
equivalent to `--no-rebase-merges`. Passing `--rebase-merges` on the
7878
command line, with or without an argument, overrides any
7979
`rebase.rebaseMerges` configuration.
80+
81+
rebase.maxLabelLength::
82+
When generating label names from commit subjects, truncate the names to
83+
this length. By default, the names are truncated to a little less than
84+
`NAME_MAX` (to allow e.g. `.lock` files to be written for the
85+
corresponding loose refs).

sequencer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5339,6 +5339,7 @@ struct label_state {
53395339
struct oidmap commit2label;
53405340
struct hashmap labels;
53415341
struct strbuf buf;
5342+
int max_label_length;
53425343
};
53435344

53445345
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,
53965397
} else {
53975398
struct strbuf *buf = &state->buf;
53985399
int label_is_utf8 = 1; /* start with this assumption */
5399-
size_t max_len = buf->len + GIT_MAX_LABEL_LENGTH;
5400+
size_t max_len = buf->len + state->max_label_length;
54005401

54015402
/*
54025403
* Sanitize labels by replacing non-alpha-numeric characters
@@ -5494,14 +5495,17 @@ static int make_script_with_merges(struct pretty_print_context *pp,
54945495
struct string_entry *entry;
54955496
struct oidset interesting = OIDSET_INIT, child_seen = OIDSET_INIT,
54965497
shown = OIDSET_INIT;
5497-
struct label_state state = { OIDMAP_INIT, { NULL }, STRBUF_INIT };
5498+
struct label_state state =
5499+
{ OIDMAP_INIT, { NULL }, STRBUF_INIT, GIT_MAX_LABEL_LENGTH };
54985500

54995501
int abbr = flags & TODO_LIST_ABBREVIATE_CMDS;
55005502
const char *cmd_pick = abbr ? "p" : "pick",
55015503
*cmd_label = abbr ? "l" : "label",
55025504
*cmd_reset = abbr ? "t" : "reset",
55035505
*cmd_merge = abbr ? "m" : "merge";
55045506

5507+
git_config_get_int("rebase.maxlabellength", &state.max_label_length);
5508+
55055509
oidmap_init(&commit2todo, 0);
55065510
oidmap_init(&state.commit2label, 0);
55075511
hashmap_init(&state.labels, labels_cmp, NULL, 0);

t/t3430-rebase-merges.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,4 +586,15 @@ test_expect_success 'progress shows the correct total' '
586586
test_line_count = 14 progress
587587
'
588588

589+
test_expect_success 'truncate label names' '
590+
commit=$(git commit-tree -p HEAD^ -p HEAD -m "0123456789 我 123" HEAD^{tree}) &&
591+
git merge --ff-only $commit &&
592+
593+
done="$(git rev-parse --git-path rebase-merge/done)" &&
594+
git -c rebase.maxLabelLength=14 rebase --rebase-merges -x "cp \"$done\" out" --root &&
595+
grep "label 0123456789-我$" out &&
596+
git -c rebase.maxLabelLength=13 rebase --rebase-merges -x "cp \"$done\" out" --root &&
597+
grep "label 0123456789-$" out
598+
'
599+
589600
test_done

0 commit comments

Comments
 (0)