]> git.ipfire.org Git - thirdparty/git.git/blobdiff - wt-status.c
Git 2.45
[thirdparty/git.git] / wt-status.c
index 7108a92b52ce06e5674aadfc5c89d05157a9db93..bdfc23e2ae7de8a9521c03420448e412d4262d84 100644 (file)
@@ -70,7 +70,7 @@ static void status_vprintf(struct wt_status *s, int at_bol, const char *color,
        strbuf_vaddf(&sb, fmt, ap);
        if (!sb.len) {
                if (s->display_comment_prefix) {
-                       strbuf_addch(&sb, comment_line_char);
+                       strbuf_addstr(&sb, comment_line_str);
                        if (!trail)
                                strbuf_addch(&sb, ' ');
                }
@@ -85,7 +85,7 @@ static void status_vprintf(struct wt_status *s, int at_bol, const char *color,
 
                strbuf_reset(&linebuf);
                if (at_bol && s->display_comment_prefix) {
-                       strbuf_addch(&linebuf, comment_line_char);
+                       strbuf_addstr(&linebuf, comment_line_str);
                        if (*line != '\n' && *line != '\t')
                                strbuf_addch(&linebuf, ' ');
                }
@@ -1028,7 +1028,7 @@ static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncom
        if (s->display_comment_prefix) {
                size_t len;
                summary_content = strbuf_detach(&summary, &len);
-               strbuf_add_commented_lines(&summary, summary_content, len, comment_line_char);
+               strbuf_add_commented_lines(&summary, summary_content, len, comment_line_str);
                free(summary_content);
        }
 
@@ -1090,11 +1090,14 @@ size_t wt_status_locate_end(const char *s, size_t len)
        const char *p;
        struct strbuf pattern = STRBUF_INIT;
 
-       strbuf_addf(&pattern, "\n%c %s", comment_line_char, cut_line);
+       strbuf_addf(&pattern, "\n%s %s", comment_line_str, cut_line);
        if (starts_with(s, pattern.buf + 1))
                len = 0;
-       else if ((p = strstr(s, pattern.buf)))
-               len = p - s + 1;
+       else if ((p = strstr(s, pattern.buf))) {
+               size_t newlen = p - s + 1;
+               if (newlen < len)
+                       len = newlen;
+       }
        strbuf_release(&pattern);
        return len;
 }
@@ -1103,8 +1106,8 @@ void wt_status_append_cut_line(struct strbuf *buf)
 {
        const char *explanation = _("Do not modify or remove the line above.\nEverything below it will be ignored.");
 
-       strbuf_commented_addf(buf, comment_line_char, "%s", cut_line);
-       strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_char);
+       strbuf_commented_addf(buf, comment_line_str, "%s", cut_line);
+       strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_str);
 }
 
 void wt_status_add_cut_line(struct wt_status *s)
@@ -1180,8 +1183,6 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
        struct strbuf sb = STRBUF_INIT;
        const char *cp, *ep, *branch_name;
        struct branch *branch;
-       char comment_line_string[3];
-       int i;
        uint64_t t_begin = 0;
 
        assert(s->branch && !s->is_initial);
@@ -1206,20 +1207,15 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
                }
        }
 
-       i = 0;
-       if (s->display_comment_prefix) {
-               comment_line_string[i++] = comment_line_char;
-               comment_line_string[i++] = ' ';
-       }
-       comment_line_string[i] = '\0';
-
        for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1)
                color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s),
-                                "%s%.*s", comment_line_string,
+                                "%s%s%.*s",
+                                s->display_comment_prefix ? comment_line_str : "",
+                                s->display_comment_prefix ? " " : "",
                                 (int)(ep - cp), cp);
        if (s->display_comment_prefix)
-               color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c",
-                                comment_line_char);
+               color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%s",
+                                comment_line_str);
        else
                fputs("\n", s->fp);
        strbuf_release(&sb);
@@ -1386,7 +1382,7 @@ static int read_rebase_todolist(const char *fname, struct string_list *lines)
                          git_path("%s", fname));
        }
        while (!strbuf_getline_lf(&line, f)) {
-               if (line.len && line.buf[0] == comment_line_char)
+               if (starts_with(line.buf, comment_line_str))
                        continue;
                strbuf_trim(&line);
                if (!line.len)