threads / patch / 45402

patchwt-status.c: improve readability for wt_shortstatus_print

Subject: [PATCH] wt-status.c: improve readability for wt_shortstatus_print

## tl;dr

3 messages between Mar 16, 2017 and Mar 17, 2017. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Stefan Beller· Mar 16, 2017, 21:36 UTC · lore
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 wt-status.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)
Show changes to wt-status.c +5 −15
diff --git a/wt-status.c b/wt-status.c
index d47012048f..a52d342695 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1785,34 +1785,24 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
 
 static void wt_shortstatus_print(struct wt_status *s)
 {
-	int i;
+	struct string_list_item *it;
 
 	if (s->show_branch)
 		wt_shortstatus_print_tracking(s);
 
-	for (i = 0; i < s->change.nr; i++) {
-		struct wt_status_change_data *d;
-		struct string_list_item *it;
+	for_each_string_list_item(it, &s->change) {
+		struct wt_status_change_data *d = it->util;
 
-		it = &(s->change.items[i]);
-		d = it->util;
 		if (d->stagemask)
 			wt_shortstatus_unmerged(it, s);
 		else
 			wt_shortstatus_status(it, s);
 	}
-	for (i = 0; i < s->untracked.nr; i++) {
-		struct string_list_item *it;
-
-		it = &(s->untracked.items[i]);
+	for_each_string_list_item(it, &s->untracked)
 		wt_shortstatus_other(it, s, "??");
-	}
-	for (i = 0; i < s->ignored.nr; i++) {
-		struct string_list_item *it;
 
-		it = &(s->ignored.items[i]);
+	for_each_string_list_item(it, &s->ignored)
 		wt_shortstatus_other(it, s, "!!");
-	}
 }
 
 static void wt_porcelain_print(struct wt_status *s)
-- 
2.12.0.269.g1a05a5734c.dirty
Jonathan Nieder· Mar 16, 2017, 22:51 UTC · re: Stefan Beller · lore

Re: [PATCH] wt-status.c: improve readability for wt_shortstatus_print

Stefan Beller wrote:
> Subject: wt-status.c: improve readability for wt_shortstatus_print
Maybe:
	wt-status: simplify by using for_each_string_list_item
	Improve readability by using the for_each_string_list_item helper
	instead of manually iterating with an integer counter.
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>  wt-status.c | 20 +++++---------------
>  1 file changed, 5 insertions(+), 15 deletions(-)
I like the diffstat. :)
With or without a clarified commit message,
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Junio C Hamano· Mar 17, 2017, 05:25 UTC · re: Jonathan Nieder · lore

Re: [PATCH] wt-status.c: improve readability for wt_shortstatus_print

Jonathan Nieder <jrnieder@gmail.com> writes:
Show 10 quoted lines
> Stefan Beller wrote:
>
>> Subject: wt-status.c: improve readability for wt_shortstatus_print
>
> Maybe:
>
> 	wt-status: simplify by using for_each_string_list_item
>
> 	Improve readability by using the for_each_string_list_item helper
> 	instead of manually iterating with an integer counter.

Much better. That matches what I read from the patch when I skimmed it, but it did leave me wondering if I missed something else.

Show 6 quoted lines
>> Signed-off-by: Stefan Beller <sbeller@google.com>
>> ---
>>  wt-status.c | 20 +++++---------------
>>  1 file changed, 5 insertions(+), 15 deletions(-)
>
> I like the diffstat. :)
Me too ;-)
>
> With or without a clarified commit message,
> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

← back to recent threads