| 2723 | } |
| 2724 | |
| 2725 | static void pprint_rename(struct strbuf *name, const char *a, const char *b) |
| 2726 | { |
| 2727 | const char *old_name = a; |
| 2728 | const char *new_name = b; |
| 2729 | int pfx_length, sfx_length; |
| 2730 | int pfx_adjust_for_slash; |
| 2731 | int len_a = strlen(a); |
| 2732 | int len_b = strlen(b); |
| 2733 | int a_midlen, b_midlen; |
| 2734 | int qlen_a = quote_c_style(a, NULL, NULL, 0); |
| 2735 | int qlen_b = quote_c_style(b, NULL, NULL, 0); |
| 2736 | |
| 2737 | if (qlen_a || qlen_b) { |
| 2738 | quote_c_style(a, name, NULL, 0); |
| 2739 | strbuf_addstr(name, " => "); |
| 2740 | quote_c_style(b, name, NULL, 0); |
| 2741 | return; |
| 2742 | } |
| 2743 | |
| 2744 | /* Find common prefix */ |
| 2745 | pfx_length = 0; |
| 2746 | while (*old_name && *new_name && *old_name == *new_name) { |
| 2747 | if (*old_name == '/') |
| 2748 | pfx_length = old_name - a + 1; |
| 2749 | old_name++; |
| 2750 | new_name++; |
| 2751 | } |
| 2752 | |
| 2753 | /* Find common suffix */ |
| 2754 | old_name = a + len_a; |
| 2755 | new_name = b + len_b; |
| 2756 | sfx_length = 0; |
| 2757 | /* |
| 2758 | * If there is a common prefix, it must end in a slash. In |
| 2759 | * that case we let this loop run 1 into the prefix to see the |
| 2760 | * same slash. |
| 2761 | * |
| 2762 | * If there is no common prefix, we cannot do this as it would |
| 2763 | * underrun the input strings. |
| 2764 | */ |
| 2765 | pfx_adjust_for_slash = (pfx_length ? 1 : 0); |
| 2766 | while (a + pfx_length - pfx_adjust_for_slash <= old_name && |
| 2767 | b + pfx_length - pfx_adjust_for_slash <= new_name && |
| 2768 | *old_name == *new_name) { |
| 2769 | if (*old_name == '/') |
| 2770 | sfx_length = len_a - (old_name - a); |
| 2771 | old_name--; |
| 2772 | new_name--; |
| 2773 | } |
| 2774 | |
| 2775 | /* |
| 2776 | * pfx{mid-a => mid-b}sfx |
| 2777 | * {pfx-a => pfx-b}sfx |
| 2778 | * pfx{sfx-a => sfx-b} |
| 2779 | * name-a => name-b |
| 2780 | */ |
| 2781 | a_midlen = len_a - pfx_length - sfx_length; |
| 2782 | b_midlen = len_b - pfx_length - sfx_length; |
no test coverage detected