Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2019-11-18 02:16:09 +0300
committerJunio C Hamano <gitster@pobox.com>2019-11-18 06:49:16 +0300
commit867bc1d236b8955414b3dbacf28c7f0c2e337cf4 (patch)
tree07113c5d1f2f2cd7f4d0c9e1aa2d1a38ac34bea6 /sequencer.c
parentd9f6f3b6195a0ca35642561e530798ad1469bd41 (diff)
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>
Diffstat (limited to 'sequencer.c')
-rw-r--r--sequencer.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/sequencer.c b/sequencer.c
index 8952cfa89b..85c66f489f 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -4423,7 +4423,6 @@ static const char *label_oid(struct object_id *oid, const char *label,
struct labels_entry *labels_entry;
struct string_entry *string_entry;
struct object_id dummy;
- size_t len;
int i;
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
* clash with any other label.
*/
+ strbuf_reset(&state->buf);
if (!label) {
char *p;
- strbuf_reset(&state->buf);
strbuf_grow(&state->buf, GIT_MAX_HEXSZ);
label = p = state->buf.buf;
@@ -4469,32 +4468,37 @@ static const char *label_oid(struct object_id *oid, const char *label,
p[i] = save;
}
}
- } else if (((len = strlen(label)) == the_hash_algo->hexsz &&
- !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.
- */
+ } else {
struct strbuf *buf = &state->buf;
- strbuf_reset(buf);
- strbuf_add(buf, label, len);
+ for (; *label; label++)
+ strbuf_addch(buf, isspace(*label) ? '-' : *label);
+ label = buf->buf;
- 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;
- }
+ 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;
- label = buf->buf;
+ 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);
@@ -4596,10 +4600,6 @@ static int make_script_with_merges(struct pretty_print_context *pp,
else
strbuf_addbuf(&label, &oneline);
- for (p1 = label.buf; *p1; p1++)
- if (isspace(*p1))
- *(char *)p1 = '-';
-
strbuf_reset(&buf);
strbuf_addf(&buf, "%s -C %s",
cmd_merge, oid_to_hex(&commit->object.oid));