rebase-merges: move labels' whitespace mangling into `label_oid()`
One of the trickier aspects of the design of `git rebase --rebase-merges` is the way labels are generated for the initial todo list: those labels are supposed to be intuitive and first and foremost unique. To that end, `label_oid()` appends a unique suffix when necessary. Those labels not only need to be unique, but they also need to be valid refs. To make sure of that, `make_script_with_merges()` replaces whitespace by dashes. That would appear to be the wrong layer for that sanitizing step, though: all callers of `label_oid()` should get that same benefit. Even if it does not make a difference currently (the only called of `label_oid()` that passes a label that might need to be sanitized _is_ `make_script_with_merges()`), let's move the responsibility for sanitizing labels into the `label_oid()` function. This commit is best viewed with `-w` because it unfortunately needs to change the indentation of a large block of code in `label_oid()`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
d9f6f3b619
commit
867bc1d236
58
sequencer.c
58
sequencer.c
|
@ -4423,7 +4423,6 @@ static const char *label_oid(struct object_id *oid, const char *label,
|
||||||
struct labels_entry *labels_entry;
|
struct labels_entry *labels_entry;
|
||||||
struct string_entry *string_entry;
|
struct string_entry *string_entry;
|
||||||
struct object_id dummy;
|
struct object_id dummy;
|
||||||
size_t len;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
string_entry = oidmap_get(&state->commit2label, oid);
|
string_entry = oidmap_get(&state->commit2label, oid);
|
||||||
|
@ -4443,10 +4442,10 @@ static const char *label_oid(struct object_id *oid, const char *label,
|
||||||
* abbreviation for any uninteresting commit's names that does not
|
* abbreviation for any uninteresting commit's names that does not
|
||||||
* clash with any other label.
|
* clash with any other label.
|
||||||
*/
|
*/
|
||||||
|
strbuf_reset(&state->buf);
|
||||||
if (!label) {
|
if (!label) {
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
strbuf_reset(&state->buf);
|
|
||||||
strbuf_grow(&state->buf, GIT_MAX_HEXSZ);
|
strbuf_grow(&state->buf, GIT_MAX_HEXSZ);
|
||||||
label = p = state->buf.buf;
|
label = p = state->buf.buf;
|
||||||
|
|
||||||
|
@ -4469,32 +4468,37 @@ static const char *label_oid(struct object_id *oid, const char *label,
|
||||||
p[i] = save;
|
p[i] = save;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (((len = strlen(label)) == the_hash_algo->hexsz &&
|
} else {
|
||||||
!get_oid_hex(label, &dummy)) ||
|
|
||||||
(len == 1 && *label == '#') ||
|
|
||||||
hashmap_get_from_hash(&state->labels,
|
|
||||||
strihash(label), label)) {
|
|
||||||
/*
|
|
||||||
* If the label already exists, or if the label is a valid full
|
|
||||||
* OID, or the label is a '#' (which we use as a separator
|
|
||||||
* between merge heads and oneline), we append a dash and a
|
|
||||||
* number to make it unique.
|
|
||||||
*/
|
|
||||||
struct strbuf *buf = &state->buf;
|
struct strbuf *buf = &state->buf;
|
||||||
|
|
||||||
strbuf_reset(buf);
|
for (; *label; label++)
|
||||||
strbuf_add(buf, label, len);
|
strbuf_addch(buf, isspace(*label) ? '-' : *label);
|
||||||
|
|
||||||
for (i = 2; ; i++) {
|
|
||||||
strbuf_setlen(buf, len);
|
|
||||||
strbuf_addf(buf, "-%d", i);
|
|
||||||
if (!hashmap_get_from_hash(&state->labels,
|
|
||||||
strihash(buf->buf),
|
|
||||||
buf->buf))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
label = buf->buf;
|
label = buf->buf;
|
||||||
|
|
||||||
|
if ((buf->len == the_hash_algo->hexsz &&
|
||||||
|
!get_oid_hex(label, &dummy)) ||
|
||||||
|
(buf->len == 1 && *label == '#') ||
|
||||||
|
hashmap_get_from_hash(&state->labels,
|
||||||
|
strihash(label), label)) {
|
||||||
|
/*
|
||||||
|
* If the label already exists, or if the label is a
|
||||||
|
* valid full OID, or the label is a '#' (which we use
|
||||||
|
* as a separator between merge heads and oneline), we
|
||||||
|
* append a dash and a number to make it unique.
|
||||||
|
*/
|
||||||
|
size_t len = buf->len;
|
||||||
|
|
||||||
|
for (i = 2; ; i++) {
|
||||||
|
strbuf_setlen(buf, len);
|
||||||
|
strbuf_addf(buf, "-%d", i);
|
||||||
|
if (!hashmap_get_from_hash(&state->labels,
|
||||||
|
strihash(buf->buf),
|
||||||
|
buf->buf))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
label = buf->buf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FLEX_ALLOC_STR(labels_entry, label, label);
|
FLEX_ALLOC_STR(labels_entry, label, label);
|
||||||
|
@ -4596,10 +4600,6 @@ static int make_script_with_merges(struct pretty_print_context *pp,
|
||||||
else
|
else
|
||||||
strbuf_addbuf(&label, &oneline);
|
strbuf_addbuf(&label, &oneline);
|
||||||
|
|
||||||
for (p1 = label.buf; *p1; p1++)
|
|
||||||
if (isspace(*p1))
|
|
||||||
*(char *)p1 = '-';
|
|
||||||
|
|
||||||
strbuf_reset(&buf);
|
strbuf_reset(&buf);
|
||||||
strbuf_addf(&buf, "%s -C %s",
|
strbuf_addf(&buf, "%s -C %s",
|
||||||
cmd_merge, oid_to_hex(&commit->object.oid));
|
cmd_merge, oid_to_hex(&commit->object.oid));
|
||||||
|
|
Loading…
Reference in New Issue