From 8a57c6e9437eeebf849f0def03389078a510312e Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Sat, 3 Jul 2010 14:41:54 +0200 Subject: Convert the users of for_each_string_list to for_each_string_list_item macro The rule for selecting the candidates for conversion is: if the callback function returns only 0 (the condition for for_each_string_list to exit early), than it can be safely converted to the macro. A notable exception are the callers in builtin/remote.c. If converted, the readability in the file will suffer greately. Besides, the code is not very performance critical (at the moment, at least): it does output formatting of the list of remotes. Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- resolve-undo.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'resolve-undo.c') diff --git a/resolve-undo.c b/resolve-undo.c index 174ebec9e5..72b46125b7 100644 --- a/resolve-undo.c +++ b/resolve-undo.c @@ -28,29 +28,25 @@ void record_resolve_undo(struct index_state *istate, struct cache_entry *ce) ui->mode[stage - 1] = ce->ce_mode; } -static int write_one(struct string_list_item *item, void *cbdata) +void resolve_undo_write(struct strbuf *sb, struct string_list *resolve_undo) { - struct strbuf *sb = cbdata; - struct resolve_undo_info *ui = item->util; - int i; + struct string_list_item *item; + for_each_string_list_item(item, resolve_undo) { + struct resolve_undo_info *ui = item->util; + int i; - if (!ui) - return 0; - strbuf_addstr(sb, item->string); - strbuf_addch(sb, 0); - for (i = 0; i < 3; i++) - strbuf_addf(sb, "%o%c", ui->mode[i], 0); - for (i = 0; i < 3; i++) { - if (!ui->mode[i]) + if (!ui) continue; - strbuf_add(sb, ui->sha1[i], 20); + strbuf_addstr(sb, item->string); + strbuf_addch(sb, 0); + for (i = 0; i < 3; i++) + strbuf_addf(sb, "%o%c", ui->mode[i], 0); + for (i = 0; i < 3; i++) { + if (!ui->mode[i]) + continue; + strbuf_add(sb, ui->sha1[i], 20); + } } - return 0; -} - -void resolve_undo_write(struct strbuf *sb, struct string_list *resolve_undo) -{ - for_each_string_list(resolve_undo, write_one, sb); } struct string_list *resolve_undo_read(const char *data, unsigned long size) -- cgit v1.2.1