MCPcopy Index your code
hub / github.com/git/git / find_unique

Function find_unique

add-interactive.c:143–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141}
142
143static ssize_t find_unique(const char *string, struct prefix_item_list *list)
144{
145 bool exact_match;
146 size_t index = string_list_find_insert_index(&list->sorted, string, &exact_match);
147 struct string_list_item *item;
148
149 if (list->items.nr != list->sorted.nr)
150 BUG("prefix_item_list in inconsistent state (%"PRIuMAX
151 " vs %"PRIuMAX")",
152 (uintmax_t)list->items.nr, (uintmax_t)list->sorted.nr);
153
154 if (exact_match)
155 item = list->sorted.items[index].util;
156 else if (index > 0 &&
157 starts_with(list->sorted.items[index - 1].string, string))
158 return -1;
159 else if (index + 1 < list->sorted.nr &&
160 starts_with(list->sorted.items[index + 1].string, string))
161 return -1;
162 else if (index < list->sorted.nr &&
163 starts_with(list->sorted.items[index].string, string))
164 item = list->sorted.items[index].util;
165 else
166 return -1;
167 return item - list->items.items;
168}
169
170struct list_options {
171 int columns;

Callers 1

list_and_chooseFunction · 0.70

Calls 2

starts_withFunction · 0.85

Tested by

no test coverage detected