| 2636 | } |
| 2637 | |
| 2638 | static int ce_write_entry(struct hashfile *f, struct cache_entry *ce, |
| 2639 | struct strbuf *previous_name, struct ondisk_cache_entry *ondisk) |
| 2640 | { |
| 2641 | int size; |
| 2642 | unsigned int saved_namelen; |
| 2643 | int stripped_name = 0; |
| 2644 | static unsigned char padding[8] = { 0x00 }; |
| 2645 | |
| 2646 | if (ce->ce_flags & CE_STRIP_NAME) { |
| 2647 | saved_namelen = ce_namelen(ce); |
| 2648 | ce->ce_namelen = 0; |
| 2649 | stripped_name = 1; |
| 2650 | } |
| 2651 | |
| 2652 | size = offsetof(struct ondisk_cache_entry,data) + ondisk_data_size(ce->ce_flags, 0); |
| 2653 | |
| 2654 | if (!previous_name) { |
| 2655 | int len = ce_namelen(ce); |
| 2656 | copy_cache_entry_to_ondisk(ondisk, ce); |
| 2657 | hashwrite(f, ondisk, size); |
| 2658 | hashwrite(f, ce->name, len); |
| 2659 | hashwrite(f, padding, align_padding_size(size, len)); |
| 2660 | } else { |
| 2661 | int common, to_remove; |
| 2662 | uint8_t prefix_size; |
| 2663 | unsigned char to_remove_vi[16]; |
| 2664 | |
| 2665 | for (common = 0; |
| 2666 | (common < previous_name->len && |
| 2667 | ce->name[common] && |
| 2668 | ce->name[common] == previous_name->buf[common]); |
| 2669 | common++) |
| 2670 | ; /* still matching */ |
| 2671 | to_remove = previous_name->len - common; |
| 2672 | prefix_size = encode_varint(to_remove, to_remove_vi); |
| 2673 | |
| 2674 | copy_cache_entry_to_ondisk(ondisk, ce); |
| 2675 | hashwrite(f, ondisk, size); |
| 2676 | hashwrite(f, to_remove_vi, prefix_size); |
| 2677 | hashwrite(f, ce->name + common, ce_namelen(ce) - common); |
| 2678 | hashwrite(f, padding, 1); |
| 2679 | |
| 2680 | strbuf_splice(previous_name, common, to_remove, |
| 2681 | ce->name + common, ce_namelen(ce) - common); |
| 2682 | } |
| 2683 | if (stripped_name) { |
| 2684 | ce->ce_namelen = saved_namelen; |
| 2685 | ce->ce_flags &= ~CE_STRIP_NAME; |
| 2686 | } |
| 2687 | |
| 2688 | return 0; |
| 2689 | } |
| 2690 | |
| 2691 | /* |
| 2692 | * This function verifies if index_state has the correct sha1 of the |
no test coverage detected