MCPcopy Create free account
hub / github.com/git/git / find_unique_prefixes

Function find_unique_prefixes

add-interactive.c:99–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99static void find_unique_prefixes(struct prefix_item_list *list)
100{
101 size_t i;
102
103 if (list->sorted.nr == list->items.nr)
104 return;
105
106 string_list_clear(&list->sorted, 0);
107 /* Avoid reallocating incrementally */
108 list->sorted.items = xmalloc(st_mult(sizeof(*list->sorted.items),
109 list->items.nr));
110 list->sorted.nr = list->sorted.alloc = list->items.nr;
111
112 for (i = 0; i < list->items.nr; i++) {
113 list->sorted.items[i].string = list->items.items[i].string;
114 list->sorted.items[i].util = list->items.items + i;
115 }
116
117 string_list_sort(&list->sorted);
118
119 for (i = 0; i < list->sorted.nr; i++) {
120 struct string_list_item *sorted_item = list->sorted.items + i;
121 struct string_list_item *item = sorted_item->util;
122 size_t *len = item->util;
123
124 *len = 0;
125 while (*len < list->min_length) {
126 char c = item->string[(*len)++];
127
128 if (!c || !isascii(c)) {
129 *len = 0;
130 break;
131 }
132 }
133
134 if (i > 0)
135 extend_prefix_length(item, sorted_item[-1].string,
136 list->max_length);
137 if (i + 1 < list->sorted.nr)
138 extend_prefix_length(item, sorted_item[1].string,
139 list->max_length);
140 }
141}
142
143static ssize_t find_unique(const char *string, struct prefix_item_list *list)
144{

Callers 1

list_and_chooseFunction · 0.85

Calls 5

string_list_clearFunction · 0.85
st_multFunction · 0.85
extend_prefix_lengthFunction · 0.85
xmallocFunction · 0.70
string_list_sortFunction · 0.70

Tested by

no test coverage detected