diff options
Diffstat (limited to 'wt-status.c')
-rw-r--r-- | wt-status.c | 69 |
1 files changed, 26 insertions, 43 deletions
diff --git a/wt-status.c b/wt-status.c index 86fec8986f..29666d0dba 100644 --- a/wt-status.c +++ b/wt-status.c @@ -128,7 +128,7 @@ void wt_status_prepare(struct wt_status *s) s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; s->use_color = -1; s->relative_paths = 1; - s->branch = resolve_refdup("HEAD", sha1, 0, NULL); + s->branch = resolve_refdup("HEAD", 0, sha1, NULL); s->reference = "HEAD"; s->fp = stdout; s->index_file = get_index_file(); @@ -188,7 +188,7 @@ static void wt_status_print_unmerged_header(struct wt_status *s) } else { status_printf_ln(s, c, _(" (use \"git add/rm <file>...\" as appropriate to mark resolution)")); } - status_printf_ln(s, c, ""); + status_printf_ln(s, c, "%s", ""); } static void wt_status_print_cached_header(struct wt_status *s) @@ -204,7 +204,7 @@ static void wt_status_print_cached_header(struct wt_status *s) status_printf_ln(s, c, _(" (use \"git reset %s <file>...\" to unstage)"), s->reference); else status_printf_ln(s, c, _(" (use \"git rm --cached <file>...\" to unstage)")); - status_printf_ln(s, c, ""); + status_printf_ln(s, c, "%s", ""); } static void wt_status_print_dirty_header(struct wt_status *s, @@ -223,7 +223,7 @@ static void wt_status_print_dirty_header(struct wt_status *s, status_printf_ln(s, c, _(" (use \"git checkout -- <file>...\" to discard changes in working directory)")); if (has_dirty_submodules) status_printf_ln(s, c, _(" (commit or discard the untracked or modified content in submodules)")); - status_printf_ln(s, c, ""); + status_printf_ln(s, c, "%s", ""); } static void wt_status_print_other_header(struct wt_status *s, @@ -235,12 +235,12 @@ static void wt_status_print_other_header(struct wt_status *s, if (!s->hints) return; status_printf_ln(s, c, _(" (use \"git %s <file>...\" to include in what will be committed)"), how); - status_printf_ln(s, c, ""); + status_printf_ln(s, c, "%s", ""); } static void wt_status_print_trailer(struct wt_status *s) { - status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); + status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", ""); } #define quote_path quote_path_relative @@ -574,14 +574,11 @@ static void wt_status_collect_untracked(struct wt_status *s) { int i; struct dir_struct dir; - struct timeval t_begin; + uint64_t t_begin = getnanotime(); if (!s->show_untracked_files) return; - if (advice_status_u_option) - gettimeofday(&t_begin, NULL); - memset(&dir, 0, sizeof(dir)); if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES) dir.flags |= @@ -612,13 +609,8 @@ static void wt_status_collect_untracked(struct wt_status *s) free(dir.ignored); clear_directory(&dir); - if (advice_status_u_option) { - struct timeval t_end; - gettimeofday(&t_end, NULL); - s->untracked_in_ms = - (uint64_t)t_end.tv_sec * 1000 + t_end.tv_usec / 1000 - - ((uint64_t)t_begin.tv_sec * 1000 + t_begin.tv_usec / 1000); - } + if (advice_status_u_option) + s->untracked_in_ms = (getnanotime() - t_begin) / 1000000; } void wt_status_collect(struct wt_status *s) @@ -733,39 +725,30 @@ static void wt_status_print_changed(struct wt_status *s) static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitted) { - struct child_process sm_summary; - char summary_limit[64]; - char index[PATH_MAX]; - const char *env[] = { NULL, NULL }; - struct argv_array argv = ARGV_ARRAY_INIT; + struct child_process sm_summary = CHILD_PROCESS_INIT; struct strbuf cmd_stdout = STRBUF_INIT; struct strbuf summary = STRBUF_INIT; char *summary_content; size_t len; - sprintf(summary_limit, "%d", s->submodule_summary); - snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file); + argv_array_pushf(&sm_summary.env_array, "GIT_INDEX_FILE=%s", + s->index_file); - env[0] = index; - argv_array_push(&argv, "submodule"); - argv_array_push(&argv, "summary"); - argv_array_push(&argv, uncommitted ? "--files" : "--cached"); - argv_array_push(&argv, "--for-status"); - argv_array_push(&argv, "--summary-limit"); - argv_array_push(&argv, summary_limit); + argv_array_push(&sm_summary.args, "submodule"); + argv_array_push(&sm_summary.args, "summary"); + argv_array_push(&sm_summary.args, uncommitted ? "--files" : "--cached"); + argv_array_push(&sm_summary.args, "--for-status"); + argv_array_push(&sm_summary.args, "--summary-limit"); + argv_array_pushf(&sm_summary.args, "%d", s->submodule_summary); if (!uncommitted) - argv_array_push(&argv, s->amend ? "HEAD^" : "HEAD"); + argv_array_push(&sm_summary.args, s->amend ? "HEAD^" : "HEAD"); - memset(&sm_summary, 0, sizeof(sm_summary)); - sm_summary.argv = argv.argv; - sm_summary.env = env; sm_summary.git_cmd = 1; sm_summary.no_stdin = 1; fflush(s->fp); sm_summary.out = -1; run_command(&sm_summary); - argv_array_clear(&argv); len = strbuf_read(&cmd_stdout, sm_summary.out, 1024); @@ -836,7 +819,7 @@ static void wt_status_print_other(struct wt_status *s, string_list_clear(&output, 0); strbuf_release(&buf); conclude: - status_printf_ln(s, GIT_COLOR_NORMAL, ""); + status_printf_ln(s, GIT_COLOR_NORMAL, "%s", ""); } void wt_status_truncate_message_at_cut_line(struct strbuf *buf) @@ -923,7 +906,7 @@ static void wt_status_print_tracking(struct wt_status *s) color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c", comment_line_char); else - fprintf_ln(s->fp, ""); + fputs("", s->fp); } static int has_unmerged(struct wt_status *s) @@ -1157,7 +1140,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; @@ -1339,7 +1322,7 @@ void wt_status_print(struct wt_status *s) on_what = _("Not currently on any branch."); } } - status_printf(s, color(WT_STATUS_HEADER, s), ""); + status_printf(s, color(WT_STATUS_HEADER, s), "%s", ""); status_printf_more(s, branch_status_color, "%s", on_what); status_printf_more(s, branch_color, "%s\n", branch_name); if (!s->is_initial) @@ -1352,9 +1335,9 @@ void wt_status_print(struct wt_status *s) free(state.detached_from); if (s->is_initial) { - status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); + status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", ""); status_printf_ln(s, color(WT_STATUS_HEADER, s), _("Initial commit")); - status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); + status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", ""); } wt_status_print_updated(s); @@ -1371,7 +1354,7 @@ void wt_status_print(struct wt_status *s) if (s->show_ignored_files) wt_status_print_other(s, &s->ignored, _("Ignored files"), "add -f"); if (advice_status_u_option && 2000 < s->untracked_in_ms) { - status_printf_ln(s, GIT_COLOR_NORMAL, ""); + status_printf_ln(s, GIT_COLOR_NORMAL, "%s", ""); status_printf_ln(s, GIT_COLOR_NORMAL, _("It took %.2f seconds to enumerate untracked files. 'status -uno'\n" "may speed it up, but you have to be careful not to forget to add\n" |