| 400 | } |
| 401 | |
| 402 | static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_options *options) |
| 403 | { |
| 404 | int counter = 0, generation = 0, name_prefix_len = 0; |
| 405 | struct commit_list *parents; |
| 406 | int res; |
| 407 | int result; |
| 408 | const char *name; |
| 409 | |
| 410 | if (repo_parse_commit(options->repo, commit)) |
| 411 | return -1; |
| 412 | |
| 413 | name = fsck_get_object_name(options, &commit->object.oid); |
| 414 | if (name) |
| 415 | fsck_put_object_name(options, get_commit_tree_oid(commit), |
| 416 | "%s:", name); |
| 417 | |
| 418 | result = options->walk((struct object *) repo_get_commit_tree(options->repo, commit), |
| 419 | OBJ_TREE, data, options); |
| 420 | if (result < 0) |
| 421 | return result; |
| 422 | res = result; |
| 423 | |
| 424 | parents = commit->parents; |
| 425 | if (name && parents) { |
| 426 | int len = strlen(name), power; |
| 427 | |
| 428 | if (len && name[len - 1] == '^') { |
| 429 | generation = 1; |
| 430 | name_prefix_len = len - 1; |
| 431 | } |
| 432 | else { /* parse ~<generation> suffix */ |
| 433 | for (generation = 0, power = 1; |
| 434 | len && isdigit(name[len - 1]); |
| 435 | power *= 10) |
| 436 | generation += power * (name[--len] - '0'); |
| 437 | if (power > 1 && len && name[len - 1] == '~') |
| 438 | name_prefix_len = len - 1; |
| 439 | else { |
| 440 | /* Maybe a non-first parent, e.g. HEAD^2 */ |
| 441 | generation = 0; |
| 442 | name_prefix_len = len; |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | while (parents) { |
| 448 | if (name) { |
| 449 | struct object_id *oid = &parents->item->object.oid; |
| 450 | |
| 451 | if (counter++) |
| 452 | fsck_put_object_name(options, oid, "%s^%d", |
| 453 | name, counter); |
| 454 | else if (generation > 0) |
| 455 | fsck_put_object_name(options, oid, "%.*s~%d", |
| 456 | name_prefix_len, name, |
| 457 | generation + 1); |
| 458 | else |
| 459 | fsck_put_object_name(options, oid, "%s^", name); |
no test coverage detected