@matheusbsbs / matheus-bagliano / commits / 098d0e0e8e
Fork 0

commit, status: use status_printf{,_ln,_more} helpers

wt-status code is used to provide a reminder of changes included and not included for the commit message template opened in the operator's text editor by "git commit". Therefore each line of its output begins with the comment character "#": # Please enter the commit message for your changes. Lines starting Use the new status_printf{,_ln,_more} functions to take care of adding "#" to the beginning of such status lines automatically. Using these will have two advantages over the current code: - The obvious one is to force separation of the "#" from the translatable part of the message when git learns to translate its output. - Another advantage is that this makes it easier for us to drop "#" prefix in "git status" output in later versions of git if we want to. Explained-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Feb 25, 2011 at 23:11 UTC 098d0e0e8e7467bea5306d5bc98b283bfe0174fb
2 files changed +67 -66
builtin/commit.c
+24 -23
@@ -694,50 +694,51 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
694 if (use_editor && include_status) {
695 char *ai_tmp, *ci_tmp;
696 if (in_merge)
697 - fprintf(s->fp,
698 - "#\n"
699 - "# It looks like you may be committing a MERGE.\n"
700 - "# If this is not correct, please remove the file\n"
701 - "# %s\n"
702 - "# and try again.\n"
703 - "#\n",
697 + status_printf_ln(s, GIT_COLOR_NORMAL,
698 + "\n"
699 + "It looks like you may be committing a MERGE.\n"
700 + "If this is not correct, please remove the file\n"
701 + " %s\n"
702 + "and try again.\n"
703 + "",
704 git_path("MERGE_HEAD"));
705
706 - fprintf(s->fp,
707 - "\n"
708 - "# Please enter the commit message for your changes.");
706 + fprintf(s->fp, "\n");
707 + status_printf(s, GIT_COLOR_NORMAL,
708 + "Please enter the commit message for your changes.");
709 if (cleanup_mode == CLEANUP_ALL)
710 - fprintf(s->fp,
710 + status_printf_more(s, GIT_COLOR_NORMAL,
711 " Lines starting\n"
712 - "# with '#' will be ignored, and an empty"
712 + "with '#' will be ignored, and an empty"
713 " message aborts the commit.\n");
714 else /* CLEANUP_SPACE, that is. */
715 - fprintf(s->fp,
715 + status_printf_more(s, GIT_COLOR_NORMAL,
716 " Lines starting\n"
717 - "# with '#' will be kept; you may remove them"
717 + "with '#' will be kept; you may remove them"
718 " yourself if you want to.\n"
719 - "# An empty message aborts the commit.\n");
719 + "An empty message aborts the commit.\n");
720 if (only_include_assumed)
721 - fprintf(s->fp, "# %s\n", only_include_assumed);
721 + status_printf_ln(s, GIT_COLOR_NORMAL,
722 + "%s", only_include_assumed);
723
724 ai_tmp = cut_ident_timestamp_part(author_ident->buf);
725 ci_tmp = cut_ident_timestamp_part(committer_ident.buf);
726 if (strcmp(author_ident->buf, committer_ident.buf))
726 - fprintf(s->fp,
727 + status_printf_ln(s, GIT_COLOR_NORMAL,
728 "%s"
728 - "# Author: %s\n",
729 - ident_shown++ ? "" : "#\n",
729 + "Author: %s",
730 + ident_shown++ ? "" : "\n",
731 author_ident->buf);
732
733 if (!user_ident_sufficiently_given())
733 - fprintf(s->fp,
734 + status_printf_ln(s, GIT_COLOR_NORMAL,
735 "%s"
735 - "# Committer: %s\n",
736 - ident_shown++ ? "" : "#\n",
736 + "Committer: %s",
737 + ident_shown++ ? "" : "\n",
738 committer_ident.buf);
739
740 if (ident_shown)
740 - fprintf(s->fp, "#\n");
741 + status_printf_ln(s, GIT_COLOR_NORMAL, "");
742
743 saved_color_setting = s->use_color;
744 s->use_color = 0;
wt-status.c
+43 -43
@@ -131,33 +131,33 @@ static void wt_status_print_unmerged_header(struct wt_status *s)
131 {
132 const char *c = color(WT_STATUS_HEADER, s);
133
134 - color_fprintf_ln(s->fp, c, "# Unmerged paths:");
134 + status_printf_ln(s, c, "Unmerged paths:");
135 if (!advice_status_hints)
136 return;
137 if (s->in_merge)
138 ;
139 else if (!s->is_initial)
140 - color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference);
140 + status_printf_ln(s, c, " (use \"git reset %s <file>...\" to unstage)", s->reference);
141 else
142 - color_fprintf_ln(s->fp, c, "# (use \"git rm --cached <file>...\" to unstage)");
143 - color_fprintf_ln(s->fp, c, "# (use \"git add/rm <file>...\" as appropriate to mark resolution)");
144 - color_fprintf_ln(s->fp, c, "#");
142 + status_printf_ln(s, c, " (use \"git rm --cached <file>...\" to unstage)");
143 + status_printf_ln(s, c, " (use \"git add/rm <file>...\" as appropriate to mark resolution)");
144 + status_printf_ln(s, c, "");
145 }
146
147 static void wt_status_print_cached_header(struct wt_status *s)
148 {
149 const char *c = color(WT_STATUS_HEADER, s);
150
151 - color_fprintf_ln(s->fp, c, "# Changes to be committed:");
151 + status_printf_ln(s, c, "Changes to be committed:");
152 if (!advice_status_hints)
153 return;
154 if (s->in_merge)
155 ; /* NEEDSWORK: use "git reset --unresolve"??? */
156 else if (!s->is_initial)
157 - color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference);
157 + status_printf_ln(s, c, " (use \"git reset %s <file>...\" to unstage)", s->reference);
158 else
159 - color_fprintf_ln(s->fp, c, "# (use \"git rm --cached <file>...\" to unstage)");
160 - color_fprintf_ln(s->fp, c, "#");
159 + status_printf_ln(s, c, " (use \"git rm --cached <file>...\" to unstage)");
160 + status_printf_ln(s, c, "");
161 }
162
163 static void wt_status_print_dirty_header(struct wt_status *s,
@@ -166,17 +166,17 @@ static void wt_status_print_dirty_header(struct wt_status *s,
166 {
167 const char *c = color(WT_STATUS_HEADER, s);
168
169 - color_fprintf_ln(s->fp, c, "# Changes not staged for commit:");
169 + status_printf_ln(s, c, "Changes not staged for commit:");
170 if (!advice_status_hints)
171 return;
172 if (!has_deleted)
173 - color_fprintf_ln(s->fp, c, "# (use \"git add <file>...\" to update what will be committed)");
173 + status_printf_ln(s, c, " (use \"git add <file>...\" to update what will be committed)");
174 else
175 - color_fprintf_ln(s->fp, c, "# (use \"git add/rm <file>...\" to update what will be committed)");
176 - color_fprintf_ln(s->fp, c, "# (use \"git checkout -- <file>...\" to discard changes in working directory)");
175 + status_printf_ln(s, c, " (use \"git add/rm <file>...\" to update what will be committed)");
176 + status_printf_ln(s, c, " (use \"git checkout -- <file>...\" to discard changes in working directory)");
177 if (has_dirty_submodules)
178 - color_fprintf_ln(s->fp, c, "# (commit or discard the untracked or modified content in submodules)");
179 - color_fprintf_ln(s->fp, c, "#");
178 + status_printf_ln(s, c, " (commit or discard the untracked or modified content in submodules)");
179 + status_printf_ln(s, c, "");
180 }
181
182 static void wt_status_print_other_header(struct wt_status *s,
@@ -184,16 +184,16 @@ static void wt_status_print_other_header(struct wt_status *s,
184 const char *how)
185 {
186 const char *c = color(WT_STATUS_HEADER, s);
187 - color_fprintf_ln(s->fp, c, "# %s files:", what);
187 + status_printf_ln(s, c, "%s files:", what);
188 if (!advice_status_hints)
189 return;
190 - color_fprintf_ln(s->fp, c, "# (use \"git %s <file>...\" to include in what will be committed)", how);
191 - color_fprintf_ln(s->fp, c, "#");
190 + status_printf_ln(s, c, " (use \"git %s <file>...\" to include in what will be committed)", how);
191 + status_printf_ln(s, c, "");
192 }
193
194 static void wt_status_print_trailer(struct wt_status *s)
195 {
196 - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
196 + status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
197 }
198
199 #define quote_path quote_path_relative
@@ -207,7 +207,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s,
207 const char *one, *how = "bug";
208
209 one = quote_path(it->string, -1, &onebuf, s->prefix);
210 - color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
210 + status_printf(s, color(WT_STATUS_HEADER, s), "\t");
211 switch (d->stagemask) {
212 case 1: how = "both deleted:"; break;
213 case 2: how = "added by us:"; break;
@@ -217,7 +217,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s,
217 case 6: how = "both added:"; break;
218 case 7: how = "both modified:"; break;
219 }
220 - color_fprintf(s->fp, c, "%-20s%s\n", how, one);
220 + status_printf_more(s, c, "%-20s%s\n", how, one);
221 strbuf_release(&onebuf);
222 }
223
@@ -260,40 +260,40 @@ static void wt_status_print_change_data(struct wt_status *s,
260 one = quote_path(one_name, -1, &onebuf, s->prefix);
261 two = quote_path(two_name, -1, &twobuf, s->prefix);
262
263 - color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
263 + status_printf(s, color(WT_STATUS_HEADER, s), "\t");
264 switch (status) {
265 case DIFF_STATUS_ADDED:
266 - color_fprintf(s->fp, c, "new file: %s", one);
266 + status_printf_more(s, c, "new file: %s", one);
267 break;
268 case DIFF_STATUS_COPIED:
269 - color_fprintf(s->fp, c, "copied: %s -> %s", one, two);
269 + status_printf_more(s, c, "copied: %s -> %s", one, two);
270 break;
271 case DIFF_STATUS_DELETED:
272 - color_fprintf(s->fp, c, "deleted: %s", one);
272 + status_printf_more(s, c, "deleted: %s", one);
273 break;
274 case DIFF_STATUS_MODIFIED:
275 - color_fprintf(s->fp, c, "modified: %s", one);
275 + status_printf_more(s, c, "modified: %s", one);
276 break;
277 case DIFF_STATUS_RENAMED:
278 - color_fprintf(s->fp, c, "renamed: %s -> %s", one, two);
278 + status_printf_more(s, c, "renamed: %s -> %s", one, two);
279 break;
280 case DIFF_STATUS_TYPE_CHANGED:
281 - color_fprintf(s->fp, c, "typechange: %s", one);
281 + status_printf_more(s, c, "typechange: %s", one);
282 break;
283 case DIFF_STATUS_UNKNOWN:
284 - color_fprintf(s->fp, c, "unknown: %s", one);
284 + status_printf_more(s, c, "unknown: %s", one);
285 break;
286 case DIFF_STATUS_UNMERGED:
287 - color_fprintf(s->fp, c, "unmerged: %s", one);
287 + status_printf_more(s, c, "unmerged: %s", one);
288 break;
289 default:
290 die("bug: unhandled diff status %c", status);
291 }
292 if (extra.len) {
293 - color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "%s", extra.buf);
293 + status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf);
294 strbuf_release(&extra);
295 }
296 - fprintf(s->fp, "\n");
296 + status_printf_more(s, GIT_COLOR_NORMAL, "\n");
297 strbuf_release(&onebuf);
298 strbuf_release(&twobuf);
299 }
@@ -647,9 +647,9 @@ static void wt_status_print_other(struct wt_status *s,
647 for (i = 0; i < l->nr; i++) {
648 struct string_list_item *it;
649 it = &(l->items[i]);
650 - color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
651 - color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s",
652 - quote_path(it->string, strlen(it->string),
650 + status_printf(s, color(WT_STATUS_HEADER, s), "\t");
651 + status_printf_more(s, color(WT_STATUS_UNTRACKED, s),
652 + "%s\n", quote_path(it->string, strlen(it->string),
653 &buf, s->prefix));
654 }
655 strbuf_release(&buf);
@@ -716,17 +716,17 @@ void wt_status_print(struct wt_status *s)
716 branch_status_color = color(WT_STATUS_NOBRANCH, s);
717 on_what = "Not currently on any branch.";
718 }
719 - color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "# ");
720 - color_fprintf(s->fp, branch_status_color, "%s", on_what);
721 - color_fprintf_ln(s->fp, branch_color, "%s", branch_name);
719 + status_printf(s, color(WT_STATUS_HEADER, s), "");
720 + status_printf_more(s, branch_status_color, "%s", on_what);
721 + status_printf_more(s, branch_color, "%s\n", branch_name);
722 if (!s->is_initial)
723 wt_status_print_tracking(s);
724 }
725
726 if (s->is_initial) {
727 - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
728 - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "# Initial commit");
729 - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
727 + status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
728 + status_printf_ln(s, color(WT_STATUS_HEADER, s), "Initial commit");
729 + status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
730 }
731
732 wt_status_print_updated(s);
@@ -743,7 +743,7 @@ void wt_status_print(struct wt_status *s)
743 if (s->show_ignored_files)
744 wt_status_print_other(s, &s->ignored, "Ignored", "add -f");
745 } else if (s->commitable)
746 - fprintf(s->fp, "# Untracked files not listed%s\n",
746 + status_printf_ln(s, GIT_COLOR_NORMAL, "Untracked files not listed%s",
747 advice_status_hints
748 ? " (use -u option to show untracked files)" : "");
749
@@ -751,7 +751,7 @@ void wt_status_print(struct wt_status *s)
751 wt_status_print_verbose(s);
752 if (!s->commitable) {
753 if (s->amend)
754 - fprintf(s->fp, "# No changes\n");
754 + status_printf_ln(s, GIT_COLOR_NORMAL, "No changes");
755 else if (s->nowarn)
756 ; /* nothing */
757 else if (s->workdir_dirty)