4423
struct labels_entry *labels_entry;
4424
struct string_entry *string_entry;
4425
struct object_id dummy;
4426
- size_t len;
4426
int i;
4427
4428
string_entry = oidmap_get(&state->commit2label, oid);
4442
* abbreviation for any uninteresting commit's names that does not
4443
* clash with any other label.
4444
*/
4445
+ strbuf_reset(&state->buf);
4446
if (!label) {
4447
char *p;
4448
4449
- strbuf_reset(&state->buf);
4449
strbuf_grow(&state->buf, GIT_MAX_HEXSZ);
4450
label = p = state->buf.buf;
4451
4468
p[i] = save;
4469
}
4470
}
4472
- } else if (((len = strlen(label)) == the_hash_algo->hexsz &&
4473
- !get_oid_hex(label, &dummy)) ||
4474
- (len == 1 && *label == '#') ||
4475
- hashmap_get_from_hash(&state->labels,
4476
- strihash(label), label)) {
4477
- /*
4478
- * If the label already exists, or if the label is a valid full
4479
- * OID, or the label is a '#' (which we use as a separator
4480
- * between merge heads and oneline), we append a dash and a
4481
- * number to make it unique.
4482
- */
4471
+ } else {
4472
struct strbuf *buf = &state->buf;
4473
4485
- strbuf_reset(buf);
4486
- strbuf_add(buf, label, len);
4474
+ for (; *label; label++)
4475
+ strbuf_addch(buf, isspace(*label) ? '-' : *label);
4476
+ label = buf->buf;
4477
4488
- for (i = 2; ; i++) {
4489
- strbuf_setlen(buf, len);
4490
- strbuf_addf(buf, "-%d", i);
4491
- if (!hashmap_get_from_hash(&state->labels,
4492
- strihash(buf->buf),
4493
- buf->buf))
4494
- break;
4495
- }
4478
+ if ((buf->len == the_hash_algo->hexsz &&
4479
+ !get_oid_hex(label, &dummy)) ||
4480
+ (buf->len == 1 && *label == '#') ||
4481
+ hashmap_get_from_hash(&state->labels,
4482
+ strihash(label), label)) {
4483
+ /*
4484
+ * If the label already exists, or if the label is a
4485
+ * valid full OID, or the label is a '#' (which we use
4486
+ * as a separator between merge heads and oneline), we
4487
+ * append a dash and a number to make it unique.
4488
+ */
4489
+ size_t len = buf->len;
4490
4497
- label = buf->buf;
4491
+ for (i = 2; ; i++) {
4492
+ strbuf_setlen(buf, len);
4493
+ strbuf_addf(buf, "-%d", i);
4494
+ if (!hashmap_get_from_hash(&state->labels,
4495
+ strihash(buf->buf),
4496
+ buf->buf))
4497
+ break;
4498
+ }
4499
+
4500
+ label = buf->buf;
4501
+ }
4502
}
4503
4504
FLEX_ALLOC_STR(labels_entry, label, label);
4600
else
4601
strbuf_addbuf(&label, &oneline);
4602
4599
- for (p1 = label.buf; *p1; p1++)
4600
- if (isspace(*p1))
4601
- *(char *)p1 = '-';
4602
-
4603
strbuf_reset(&buf);
4604
strbuf_addf(&buf, "%s -C %s",
4605
cmd_merge, oid_to_hex(&commit->object.oid));