#include "submodule.h"
#include "column.h"
#include "strbuf.h"
+#include "utf8.h"
+
+static char cut_line[] =
+"------------------------ >8 ------------------------\n";
static char default_wt_status_colors[][COLOR_MAXLEN] = {
GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
strbuf_release(&onebuf);
}
+static const char *wt_status_diff_status_string(int status)
+{
+ switch (status) {
+ case DIFF_STATUS_ADDED:
+ return _("new file");
+ case DIFF_STATUS_COPIED:
+ return _("copied");
+ case DIFF_STATUS_DELETED:
+ return _("deleted");
+ case DIFF_STATUS_MODIFIED:
+ return _("modified");
+ case DIFF_STATUS_RENAMED:
+ return _("renamed");
+ case DIFF_STATUS_TYPE_CHANGED:
+ return _("typechange");
+ case DIFF_STATUS_UNKNOWN:
+ return _("unknown");
+ case DIFF_STATUS_UNMERGED:
+ return _("unmerged");
+ default:
+ return NULL;
+ }
+}
+
static void wt_status_print_change_data(struct wt_status *s,
int change_type,
struct string_list_item *it)
const char *one, *two;
struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT;
struct strbuf extra = STRBUF_INIT;
+ static char *padding;
+ const char *what;
+ int len;
+
+ if (!padding) {
+ int width = 0;
+ /* If DIFF_STATUS_* uses outside this range, we're in trouble */
+ for (status = 'A'; status <= 'Z'; status++) {
+ what = wt_status_diff_status_string(status);
+ len = what ? strlen(what) : 0;
+ if (len > width)
+ width = len;
+ }
+ width += 2; /* colon and a space */
+ padding = xmallocz(width);
+ memset(padding, ' ', width);
+ }
one_name = two_name = it->string;
switch (change_type) {
two = quote_path(two_name, s->prefix, &twobuf);
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
- switch (status) {
- case DIFF_STATUS_ADDED:
- status_printf_more(s, c, _("new file: %s"), one);
- break;
- case DIFF_STATUS_COPIED:
- status_printf_more(s, c, _("copied: %s -> %s"), one, two);
- break;
- case DIFF_STATUS_DELETED:
- status_printf_more(s, c, _("deleted: %s"), one);
- break;
- case DIFF_STATUS_MODIFIED:
- status_printf_more(s, c, _("modified: %s"), one);
- break;
- case DIFF_STATUS_RENAMED:
- status_printf_more(s, c, _("renamed: %s -> %s"), one, two);
- break;
- case DIFF_STATUS_TYPE_CHANGED:
- status_printf_more(s, c, _("typechange: %s"), one);
- break;
- case DIFF_STATUS_UNKNOWN:
- status_printf_more(s, c, _("unknown: %s"), one);
- break;
- case DIFF_STATUS_UNMERGED:
- status_printf_more(s, c, _("unmerged: %s"), one);
- break;
- default:
+ what = wt_status_diff_status_string(status);
+ if (!what)
die(_("bug: unhandled diff status %c"), status);
- }
+ /* 1 for colon, which is not part of "what" */
+ len = strlen(padding) - (utf8_strwidth(what) + 1);
+ assert(len >= 0);
+ if (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED)
+ status_printf_more(s, c, "%s:%.*s%s -> %s",
+ what, len, padding, one, two);
+ else
+ status_printf_more(s, c, "%s:%.*s%s",
+ what, len, padding, one);
if (extra.len) {
status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf);
strbuf_release(&extra);
status_printf_ln(s, GIT_COLOR_NORMAL, "");
}
+void wt_status_truncate_message_at_cut_line(struct strbuf *buf)
+{
+ const char *p;
+ struct strbuf pattern = STRBUF_INIT;
+
+ strbuf_addf(&pattern, "%c %s", comment_line_char, cut_line);
+ p = strstr(buf->buf, pattern.buf);
+ if (p && (p == buf->buf || p[-1] == '\n'))
+ strbuf_setlen(buf, p - buf->buf);
+ strbuf_release(&pattern);
+}
+
static void wt_status_print_verbose(struct wt_status *s)
{
struct rev_info rev;
* If we're not going to stdout, then we definitely don't
* want color, since we are going to the commit message
* file (and even the "auto" setting won't work, since it
- * will have checked isatty on stdout).
+ * will have checked isatty on stdout). But we then do want
+ * to insert the scissor line here to reliably remove the
+ * diff before committing.
*/
- if (s->fp != stdout)
+ if (s->fp != stdout) {
+ const char *explanation = _("Do not touch the line above.\nEverything below will be removed.");
+ struct strbuf buf = STRBUF_INIT;
+
rev.diffopt.use_color = 0;
+ fprintf(s->fp, "%c %s", comment_line_char, cut_line);
+ strbuf_add_commented_lines(&buf, explanation, strlen(explanation));
+ fputs(buf.buf, s->fp);
+ strbuf_release(&buf);
+ }
run_diff_index(&rev, 1);
}