| 1444 | } |
| 1445 | |
| 1446 | static int prune_refs(struct display_state *display_state, |
| 1447 | struct refspec *rs, |
| 1448 | struct ref_transaction *transaction, |
| 1449 | struct ref *ref_map) |
| 1450 | { |
| 1451 | int result = 0; |
| 1452 | struct ref *ref, *stale_refs = get_stale_heads(rs, ref_map); |
| 1453 | struct strbuf err = STRBUF_INIT; |
| 1454 | struct string_list refnames = STRING_LIST_INIT_NODUP; |
| 1455 | |
| 1456 | for (ref = stale_refs; ref; ref = ref->next) |
| 1457 | string_list_append(&refnames, ref->name); |
| 1458 | |
| 1459 | if (!dry_run) { |
| 1460 | if (transaction) { |
| 1461 | for (ref = stale_refs; ref; ref = ref->next) { |
| 1462 | result = ref_transaction_delete(transaction, ref->name, NULL, |
| 1463 | NULL, 0, "fetch: prune", &err); |
| 1464 | if (result) |
| 1465 | goto cleanup; |
| 1466 | } |
| 1467 | } else { |
| 1468 | result = refs_delete_refs(get_main_ref_store(the_repository), |
| 1469 | "fetch: prune", &refnames, |
| 1470 | 0); |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | if (verbosity >= 0) { |
| 1475 | int summary_width = transport_summary_width(stale_refs); |
| 1476 | |
| 1477 | for (ref = stale_refs; ref; ref = ref->next) { |
| 1478 | display_ref_update(display_state, '-', _("[deleted]"), NULL, |
| 1479 | _("(none)"), ref->name, |
| 1480 | &ref->new_oid, &ref->old_oid, |
| 1481 | summary_width); |
| 1482 | } |
| 1483 | string_list_sort(&refnames); |
| 1484 | refs_warn_dangling_symrefs(get_main_ref_store(the_repository), |
| 1485 | stderr, " ", dry_run, &refnames); |
| 1486 | } |
| 1487 | |
| 1488 | cleanup: |
| 1489 | string_list_clear(&refnames, 0); |
| 1490 | strbuf_release(&err); |
| 1491 | free_refs(stale_refs); |
| 1492 | return result; |
| 1493 | } |
| 1494 | |
| 1495 | static void check_not_current_branch(struct ref *ref_map) |
| 1496 | { |
no test coverage detected