Skip to content

Commit

Permalink
rebase: allow overriding the maximal length of the generated labels
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dscho committed Aug 10, 2023
1 parent 2b07c4d commit 1ef7cba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Documentation/config/rebase.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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).
5 changes: 4 additions & 1 deletion sequencer.c
Original file line number Diff line number Diff line change
Expand Up @@ -5348,6 +5348,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,
Expand Down Expand Up @@ -5405,7 +5406,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
Expand Down Expand Up @@ -5511,6 +5512,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);
Expand Down
11 changes: 11 additions & 0 deletions t/t3430-rebase-merges.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1ef7cba

Please sign in to comment.