| 6308 | } |
| 6309 | |
| 6310 | static void todo_list_to_strbuf(struct repository *r, |
| 6311 | struct todo_list *todo_list, |
| 6312 | struct strbuf *buf, int num, unsigned flags) |
| 6313 | { |
| 6314 | struct todo_item *item; |
| 6315 | int i, max = todo_list->nr; |
| 6316 | |
| 6317 | if (num > 0 && num < max) |
| 6318 | max = num; |
| 6319 | |
| 6320 | for (item = todo_list->items, i = 0; i < max; i++, item++) { |
| 6321 | char cmd; |
| 6322 | |
| 6323 | /* if the item is not a command write it and continue */ |
| 6324 | if (item->command >= TODO_COMMENT) { |
| 6325 | strbuf_addf(buf, "%.*s\n", item->arg_len, |
| 6326 | todo_item_get_arg(todo_list, item)); |
| 6327 | continue; |
| 6328 | } |
| 6329 | |
| 6330 | /* add command to the buffer */ |
| 6331 | cmd = command_to_char(item->command); |
| 6332 | if ((flags & TODO_LIST_ABBREVIATE_CMDS) && cmd) |
| 6333 | strbuf_addch(buf, cmd); |
| 6334 | else |
| 6335 | strbuf_addstr(buf, command_to_string(item->command)); |
| 6336 | |
| 6337 | /* add commit id */ |
| 6338 | if (item->commit) { |
| 6339 | const char *oid = flags & TODO_LIST_SHORTEN_IDS ? |
| 6340 | short_commit_name(r, item->commit) : |
| 6341 | oid_to_hex(&item->commit->object.oid); |
| 6342 | |
| 6343 | if (item->command == TODO_FIXUP) { |
| 6344 | if (item->flags & TODO_EDIT_FIXUP_MSG) |
| 6345 | strbuf_addstr(buf, " -c"); |
| 6346 | else if (item->flags & TODO_REPLACE_FIXUP_MSG) { |
| 6347 | strbuf_addstr(buf, " -C"); |
| 6348 | } |
| 6349 | } |
| 6350 | |
| 6351 | if (item->command == TODO_MERGE) { |
| 6352 | if (item->flags & TODO_EDIT_MERGE_MSG) |
| 6353 | strbuf_addstr(buf, " -c"); |
| 6354 | else |
| 6355 | strbuf_addstr(buf, " -C"); |
| 6356 | } |
| 6357 | |
| 6358 | strbuf_addf(buf, " %s", oid); |
| 6359 | } |
| 6360 | |
| 6361 | /* add all the rest */ |
| 6362 | if (!item->arg_len) |
| 6363 | strbuf_addch(buf, '\n'); |
| 6364 | else |
| 6365 | strbuf_addf(buf, " %.*s\n", item->arg_len, |
| 6366 | todo_item_get_arg(todo_list, item)); |
| 6367 | } |
no test coverage detected