Merge branch 'jc/update-instead-into-void'
[gitweb.git] / wt-status.c
index 60a58b093e3801e5e35e20ca6ff74aaab64c166c..38cb165f124d610c789a8d82de42281c795111f7 100644 (file)
@@ -729,7 +729,6 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
        struct strbuf cmd_stdout = STRBUF_INIT;
        struct strbuf summary = STRBUF_INIT;
        char *summary_content;
-       size_t len;
 
        argv_array_pushf(&sm_summary.env_array, "GIT_INDEX_FILE=%s",
                         s->index_file);
@@ -745,15 +744,11 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
 
        sm_summary.git_cmd = 1;
        sm_summary.no_stdin = 1;
-       fflush(s->fp);
-       sm_summary.out = -1;
 
-       run_command(&sm_summary);
-
-       len = strbuf_read(&cmd_stdout, sm_summary.out, 1024);
+       capture_command(&sm_summary, &cmd_stdout, 1024);
 
        /* prepend header, only if there's an actual output */
-       if (len) {
+       if (cmd_stdout.len) {
                if (uncommitted)
                        strbuf_addstr(&summary, _("Submodules changed but not updated:"));
                else
@@ -764,6 +759,7 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
        strbuf_release(&cmd_stdout);
 
        if (s->display_comment_prefix) {
+               size_t len;
                summary_content = strbuf_detach(&summary, &len);
                strbuf_add_commented_lines(&summary, summary_content, len);
                free(summary_content);
@@ -1160,7 +1156,7 @@ static char *read_and_strip_branch(const char *path)
        if (strbuf_read_file(&sb, git_path("%s", path), 0) <= 0)
                goto got_nothing;
 
-       while (&sb.len && sb.buf[sb.len - 1] == '\n')
+       while (sb.len && sb.buf[sb.len - 1] == '\n')
                strbuf_setlen(&sb, sb.len - 1);
        if (!sb.len)
                goto got_nothing;
@@ -1242,6 +1238,8 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
                state->detached_from =
                        xstrdup(find_unique_abbrev(cb.nsha1, DEFAULT_ABBREV));
        hashcpy(state->detached_sha1, cb.nsha1);
+       state->detached_at = !get_sha1("HEAD", sha1) &&
+                            !hashcmp(sha1, state->detached_sha1);
 
        free(ref);
        strbuf_release(&cb.buf);
@@ -1330,10 +1328,8 @@ void wt_status_print(struct wt_status *s)
                                on_what = _("rebase in progress; onto ");
                                branch_name = state.onto;
                        } else if (state.detached_from) {
-                               unsigned char sha1[20];
                                branch_name = state.detached_from;
-                               if (!get_sha1("HEAD", sha1) &&
-                                   !hashcmp(sha1, state.detached_sha1))
+                               if (state.detached_at)
                                        on_what = _("HEAD detached at ");
                                else
                                        on_what = _("HEAD detached from ");
@@ -1554,6 +1550,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
        base = shorten_unambiguous_ref(base, 0);
        color_fprintf(s->fp, header_color, "...");
        color_fprintf(s->fp, branch_color_remote, "%s", base);
+       free((char *)base);
 
        if (!upstream_is_gone && !num_ours && !num_theirs) {
                fputc(s->null_termination ? '\0' : '\n', s->fp);