Merge branch 'mp/rebase-label-length-limit' into maint-2.42
Overly long label names used in the sequencer machinery are now chopped to fit under filesystem limitation. * mp/rebase-label-length-limit: rebase: allow overriding the maximal length of the generated labels sequencer: truncate labels to accommodate loose refs
This commit is contained in:
@ -77,3 +77,9 @@ rebase.rebaseMerges::
|
|||||||
equivalent to `--no-rebase-merges`. Passing `--rebase-merges` on the
|
equivalent to `--no-rebase-merges`. Passing `--rebase-merges` on the
|
||||||
command line, with or without an argument, overrides any
|
command line, with or without an argument, overrides any
|
||||||
`rebase.rebaseMerges` configuration.
|
`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).
|
||||||
|
@ -422,6 +422,10 @@ char *gitdirname(char *);
|
|||||||
#define PATH_MAX 4096
|
#define PATH_MAX 4096
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NAME_MAX
|
||||||
|
#define NAME_MAX 255
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef uintmax_t timestamp_t;
|
typedef uintmax_t timestamp_t;
|
||||||
#define PRItime PRIuMAX
|
#define PRItime PRIuMAX
|
||||||
#define parse_timestamp strtoumax
|
#define parse_timestamp strtoumax
|
||||||
|
47
sequencer.c
47
sequencer.c
@ -51,6 +51,15 @@
|
|||||||
|
|
||||||
#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
|
#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To accommodate common filesystem limitations, where the loose refs' file
|
||||||
|
* names must not exceed `NAME_MAX`, the labels generated by `git rebase
|
||||||
|
* --rebase-merges` need to be truncated if the corresponding commit subjects
|
||||||
|
* are too long.
|
||||||
|
* Add some margin to stay clear from reaching `NAME_MAX`.
|
||||||
|
*/
|
||||||
|
#define GIT_MAX_LABEL_LENGTH ((NAME_MAX) - (LOCK_SUFFIX_LEN) - 16)
|
||||||
|
|
||||||
static const char sign_off_header[] = "Signed-off-by: ";
|
static const char sign_off_header[] = "Signed-off-by: ";
|
||||||
static const char cherry_picked_prefix[] = "(cherry picked from commit ";
|
static const char cherry_picked_prefix[] = "(cherry picked from commit ";
|
||||||
|
|
||||||
@ -5352,6 +5361,7 @@ struct label_state {
|
|||||||
struct oidmap commit2label;
|
struct oidmap commit2label;
|
||||||
struct hashmap labels;
|
struct hashmap labels;
|
||||||
struct strbuf buf;
|
struct strbuf buf;
|
||||||
|
int max_label_length;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *label_oid(struct object_id *oid, const char *label,
|
static const char *label_oid(struct object_id *oid, const char *label,
|
||||||
@ -5408,6 +5418,8 @@ static const char *label_oid(struct object_id *oid, const char *label,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
struct strbuf *buf = &state->buf;
|
struct strbuf *buf = &state->buf;
|
||||||
|
int label_is_utf8 = 1; /* start with this assumption */
|
||||||
|
size_t max_len = buf->len + state->max_label_length;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sanitize labels by replacing non-alpha-numeric characters
|
* Sanitize labels by replacing non-alpha-numeric characters
|
||||||
@ -5416,14 +5428,34 @@ static const char *label_oid(struct object_id *oid, const char *label,
|
|||||||
*
|
*
|
||||||
* Note that we retain non-ASCII UTF-8 characters (identified
|
* Note that we retain non-ASCII UTF-8 characters (identified
|
||||||
* via the most significant bit). They should be all acceptable
|
* via the most significant bit). They should be all acceptable
|
||||||
* in file names. We do not validate the UTF-8 here, that's not
|
* in file names.
|
||||||
* the job of this function.
|
*
|
||||||
|
* As we will use the labels as names of (loose) refs, it is
|
||||||
|
* vital that the name not be longer than the maximum component
|
||||||
|
* size of the file system (`NAME_MAX`). We are careful to
|
||||||
|
* truncate the label accordingly, allowing for the `.lock`
|
||||||
|
* suffix and for the label to be UTF-8 encoded (i.e. we avoid
|
||||||
|
* truncating in the middle of a character).
|
||||||
*/
|
*/
|
||||||
for (; *label; label++)
|
for (; *label && buf->len + 1 < max_len; label++)
|
||||||
if ((*label & 0x80) || isalnum(*label))
|
if (isalnum(*label) ||
|
||||||
|
(!label_is_utf8 && (*label & 0x80)))
|
||||||
strbuf_addch(buf, *label);
|
strbuf_addch(buf, *label);
|
||||||
|
else if (*label & 0x80) {
|
||||||
|
const char *p = label;
|
||||||
|
|
||||||
|
utf8_width(&p, NULL);
|
||||||
|
if (p) {
|
||||||
|
if (buf->len + (p - label) > max_len)
|
||||||
|
break;
|
||||||
|
strbuf_add(buf, label, p - label);
|
||||||
|
label = p - 1;
|
||||||
|
} else {
|
||||||
|
label_is_utf8 = 0;
|
||||||
|
strbuf_addch(buf, *label);
|
||||||
|
}
|
||||||
/* avoid leading dash and double-dashes */
|
/* avoid leading dash and double-dashes */
|
||||||
else if (buf->len && buf->buf[buf->len - 1] != '-')
|
} else if (buf->len && buf->buf[buf->len - 1] != '-')
|
||||||
strbuf_addch(buf, '-');
|
strbuf_addch(buf, '-');
|
||||||
if (!buf->len) {
|
if (!buf->len) {
|
||||||
strbuf_addstr(buf, "rev-");
|
strbuf_addstr(buf, "rev-");
|
||||||
@ -5485,7 +5517,8 @@ static int make_script_with_merges(struct pretty_print_context *pp,
|
|||||||
struct string_entry *entry;
|
struct string_entry *entry;
|
||||||
struct oidset interesting = OIDSET_INIT, child_seen = OIDSET_INIT,
|
struct oidset interesting = OIDSET_INIT, child_seen = OIDSET_INIT,
|
||||||
shown = 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;
|
int abbr = flags & TODO_LIST_ABBREVIATE_CMDS;
|
||||||
const char *cmd_pick = abbr ? "p" : "pick",
|
const char *cmd_pick = abbr ? "p" : "pick",
|
||||||
@ -5493,6 +5526,8 @@ static int make_script_with_merges(struct pretty_print_context *pp,
|
|||||||
*cmd_reset = abbr ? "t" : "reset",
|
*cmd_reset = abbr ? "t" : "reset",
|
||||||
*cmd_merge = abbr ? "m" : "merge";
|
*cmd_merge = abbr ? "m" : "merge";
|
||||||
|
|
||||||
|
git_config_get_int("rebase.maxlabellength", &state.max_label_length);
|
||||||
|
|
||||||
oidmap_init(&commit2todo, 0);
|
oidmap_init(&commit2todo, 0);
|
||||||
oidmap_init(&state.commit2label, 0);
|
oidmap_init(&state.commit2label, 0);
|
||||||
hashmap_init(&state.labels, labels_cmp, NULL, 0);
|
hashmap_init(&state.labels, labels_cmp, NULL, 0);
|
||||||
|
@ -586,4 +586,15 @@ test_expect_success 'progress shows the correct total' '
|
|||||||
test_line_count = 14 progress
|
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
|
test_done
|
||||||
|
Reference in New Issue
Block a user