Re: [PATCH v2 1/1] roll wt_status_state into wt_status and populate in the collect phase

2018-09-29 Thread Eric Sunshine
On Sat, Sep 29, 2018 at 2:55 PM Stephen P. Smith  wrote:
> Status variables were initialized in the collect phase and some
> variables were later freed in the print functions.
>
> A "struct wt_status" used to be sufficient for the output phase to
> work.  It was designed to be filled in the collect phase and consumed
> in the output phase, but over time some fields were added and output
> phase started filling the fields.
>
> A "struct wt_status_state" that was used in other codepaths turned out
> to be useful in the "git status" output.  This is not tied to "struct
> wt_status", so filling in the collect phase was not consistently
> followed.
>
> Move the status state structure variables into the status state
> structure and populate them in the collect functions.
>
> Create a new funciton to free the buffers that were being freed in the

s/funciton/function/

> print function.  Call this new function in commit.c where both the
> collect and print functions were being called.
>
> Signed-off-by: Stephen P. Smith 


[PATCH v2 1/1] roll wt_status_state into wt_status and populate in the collect phase

2018-09-29 Thread Stephen P. Smith
Status variables were initialized in the collect phase and some
variables were later freed in the print functions.

A "struct wt_status" used to be sufficient for the output phase to
work.  It was designed to be filled in the collect phase and consumed
in the output phase, but over time some fields were added and output
phase started filling the fields.

A "struct wt_status_state" that was used in other codepaths turned out
to be useful in the "git status" output.  This is not tied to "struct
wt_status", so filling in the collect phase was not consistently
followed.

Move the status state structure variables into the status state
structure and populate them in the collect functions.

Create a new funciton to free the buffers that were being freed in the
print function.  Call this new function in commit.c where both the
collect and print functions were being called.

Based on a patch suggestion by Junio C Hamano. [1]

[1] https://public-inbox.org/git/xmqqr2i5ueg4@gitster-ct.c.googlers.com/

Signed-off-by: Stephen P. Smith 
---
 builtin/commit.c |   3 ++
 wt-status.c  | 134 +--
 wt-status.h  |  38 +++---
 3 files changed, 82 insertions(+), 93 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index d6efd996f8..c91af2fe38 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -508,6 +508,7 @@ static int run_status(FILE *fp, const char *index_file, 
const char *prefix, int
 
wt_status_collect(s);
wt_status_print(s);
+   wt_status_collect_free_buffers(s);
 
return s->committable;
 }
@@ -1390,6 +1391,8 @@ int cmd_status(int argc, const char **argv, const char 
*prefix)
s.prefix = prefix;
 
wt_status_print();
+   wt_status_collect_free_buffers();
+
return 0;
 }
 
diff --git a/wt-status.c b/wt-status.c
index 1822e95f65..cc3e84b997 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -744,21 +744,25 @@ static int has_unmerged(struct wt_status *s)
 
 void wt_status_collect(struct wt_status *s)
 {
-   struct wt_status_state state;
wt_status_collect_changes_worktree(s);
-
if (s->is_initial)
wt_status_collect_changes_initial(s);
else
wt_status_collect_changes_index(s);
wt_status_collect_untracked(s);
 
-   memset(, 0, sizeof(state));
-   wt_status_get_state(, s->branch && !strcmp(s->branch, "HEAD"));
-   if (state.merge_in_progress && !has_unmerged(s))
+   wt_status_get_state(>state, s->branch && !strcmp(s->branch, "HEAD"));
+   if (s->state.merge_in_progress && !has_unmerged(s))
s->committable = 1;
 }
 
+void wt_status_collect_free_buffers(struct wt_status *s)
+{
+   free(s->state.branch);
+   free(s->state.onto);
+   free(s->state.detached_from);
+}
+
 static void wt_longstatus_print_unmerged(struct wt_status *s)
 {
int shown_header = 0;
@@ -1087,8 +1091,7 @@ static void wt_longstatus_print_tracking(struct wt_status 
*s)
 }
 
 static void show_merge_in_progress(struct wt_status *s,
-   struct wt_status_state *state,
-   const char *color)
+  const char *color)
 {
if (has_unmerged(s)) {
status_printf_ln(s, color, _("You have unmerged paths."));
@@ -1109,16 +1112,15 @@ static void show_merge_in_progress(struct wt_status *s,
 }
 
 static void show_am_in_progress(struct wt_status *s,
-   struct wt_status_state *state,
const char *color)
 {
status_printf_ln(s, color,
_("You are in the middle of an am session."));
-   if (state->am_empty_patch)
+   if (s->state.am_empty_patch)
status_printf_ln(s, color,
_("The current patch is empty."));
if (s->hints) {
-   if (!state->am_empty_patch)
+   if (!s->state.am_empty_patch)
status_printf_ln(s, color,
_("  (fix conflicts and then run \"git am 
--continue\")"));
status_printf_ln(s, color,
@@ -1242,10 +1244,9 @@ static int read_rebase_todolist(const char *fname, 
struct string_list *lines)
 }
 
 static void show_rebase_information(struct wt_status *s,
-   struct wt_status_state *state,
-   const char *color)
+   const char *color)
 {
-   if (state->rebase_interactive_in_progress) {
+   if (s->state.rebase_interactive_in_progress) {
int i;
int nr_lines_to_show = 2;
 
@@ -1296,28 +1297,26 @@ static void show_rebase_information(struct wt_status *s,
 }
 
 static void print_rebase_state(struct wt_status *s,
-   struct wt_status_state *state,
-   const char *color)
+