From patchwork Tue Sep 8 20:52:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 11764523 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E9BBC112E for ; Tue, 8 Sep 2020 20:52:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C79BF2166E for ; Tue, 8 Sep 2020 20:52:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="vXD557Y9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730170AbgIHUwj (ORCPT ); Tue, 8 Sep 2020 16:52:39 -0400 Received: from pb-smtp2.pobox.com ([64.147.108.71]:62976 "EHLO pb-smtp2.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729993AbgIHUwb (ORCPT ); Tue, 8 Sep 2020 16:52:31 -0400 Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 88AD98B6BF; Tue, 8 Sep 2020 16:52:26 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=4PITsaaAov6u1QimAqLbQw+CP eE=; b=vXD557Y9pXLNlQMp0mSPhlhL98Iw+GEreWbHSlLxMLVm6RffL+HvXIQQm QrdzW/D4XRJp+UqRWj3/6lKv61IUOe0FCovnhQVkiGAzFrLCCYZ0JFRaRz6Ga0pP aVPKl7qclJTyro/YauJaPfcbXz4YPe9pAerjI9ANzDrXsRUdek= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=P0BlFRD6VgJVY4Nf/fV Cs3FPQ1RSTtMegq0MP4N7Oqb7rhHakWCoJybutSOSbuYza+lJUXNhUBl6OcIhLXn YcmE/zZ/skL2XHvuQJ6kfwhJcSxS57moZpfU9+fbi/BcfV76wXv+tRlTGtWl8vHS t2Jr9Ff4f9j6wR1XJw9Z3idk= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 818788B6BE; Tue, 8 Sep 2020 16:52:26 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.75.7.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id F0F038B6BD; Tue, 8 Sep 2020 16:52:25 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 1/6] quote_path: rename quote_path_relative() to quote_path() Date: Tue, 8 Sep 2020 13:52:19 -0700 Message-Id: <20200908205224.4126551-2-gitster@pobox.com> X-Mailer: git-send-email 2.28.0-539-g66371d8995 In-Reply-To: <20200908205224.4126551-1-gitster@pobox.com> References: <20200908013013.1099937-1-sandals@crustytoothpaste.net> <20200908205224.4126551-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 3379592E-F215-11EA-92DD-2F5D23BA3BAF-77302942!pb-smtp2.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There is no quote_path_absolute() or anything that causes confusion, and one of the two large consumers already rename the long name locally with a preprocessor macro. Signed-off-by: Junio C Hamano --- builtin/clean.c | 22 +++++++++++----------- builtin/grep.c | 2 +- quote.c | 3 +-- quote.h | 3 +-- wt-status.c | 2 -- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/builtin/clean.c b/builtin/clean.c index e53ea52d89..dee44fff6e 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -162,7 +162,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, if ((force_flag & REMOVE_DIR_KEEP_NESTED_GIT) && is_nonbare_repository_dir(path)) { if (!quiet) { - quote_path_relative(path->buf, prefix, "ed); + quote_path(path->buf, prefix, "ed); printf(dry_run ? _(msg_would_skip_git_dir) : _(msg_skip_git_dir), quoted.buf); } @@ -177,7 +177,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, res = dry_run ? 0 : rmdir(path->buf); if (res) { int saved_errno = errno; - quote_path_relative(path->buf, prefix, "ed); + quote_path(path->buf, prefix, "ed); errno = saved_errno; warning_errno(_(msg_warn_remove_failed), quoted.buf); *dir_gone = 0; @@ -202,7 +202,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone)) ret = 1; if (gone) { - quote_path_relative(path->buf, prefix, "ed); + quote_path(path->buf, prefix, "ed); string_list_append(&dels, quoted.buf); } else *dir_gone = 0; @@ -210,11 +210,11 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, } else { res = dry_run ? 0 : unlink(path->buf); if (!res) { - quote_path_relative(path->buf, prefix, "ed); + quote_path(path->buf, prefix, "ed); string_list_append(&dels, quoted.buf); } else { int saved_errno = errno; - quote_path_relative(path->buf, prefix, "ed); + quote_path(path->buf, prefix, "ed); errno = saved_errno; warning_errno(_(msg_warn_remove_failed), quoted.buf); *dir_gone = 0; @@ -238,7 +238,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, *dir_gone = 1; else { int saved_errno = errno; - quote_path_relative(path->buf, prefix, "ed); + quote_path(path->buf, prefix, "ed); errno = saved_errno; warning_errno(_(msg_warn_remove_failed), quoted.buf); *dir_gone = 0; @@ -266,7 +266,7 @@ static void pretty_print_dels(void) struct column_options copts; for_each_string_list_item(item, &del_list) { - qname = quote_path_relative(item->string, NULL, &buf); + qname = quote_path(item->string, NULL, &buf); string_list_append(&list, qname); } @@ -753,7 +753,7 @@ static int ask_each_cmd(void) for_each_string_list_item(item, &del_list) { /* Ctrl-D should stop removing files */ if (!eof) { - qname = quote_path_relative(item->string, NULL, &buf); + qname = quote_path(item->string, NULL, &buf); /* TRANSLATORS: Make sure to keep [y/N] as is */ printf(_("Remove %s [y/N]? "), qname); if (git_read_line_interactively(&confirm) == EOF) { @@ -1047,19 +1047,19 @@ int cmd_clean(int argc, const char **argv, const char *prefix) if (remove_dirs(&abs_path, prefix, rm_flags, dry_run, quiet, &gone)) errors++; if (gone && !quiet) { - qname = quote_path_relative(item->string, NULL, &buf); + qname = quote_path(item->string, NULL, &buf); printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname); } } else { res = dry_run ? 0 : unlink(abs_path.buf); if (res) { int saved_errno = errno; - qname = quote_path_relative(item->string, NULL, &buf); + qname = quote_path(item->string, NULL, &buf); errno = saved_errno; warning_errno(_(msg_warn_remove_failed), qname); errors++; } else if (!quiet) { - qname = quote_path_relative(item->string, NULL, &buf); + qname = quote_path(item->string, NULL, &buf); printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname); } } diff --git a/builtin/grep.c b/builtin/grep.c index f58979bc3f..9a91ad643a 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -319,7 +319,7 @@ static void grep_source_name(struct grep_opt *opt, const char *filename, } if (opt->relative && opt->prefix_length) - quote_path_relative(filename + tree_name_len, opt->prefix, out); + quote_path(filename + tree_name_len, opt->prefix, out); else quote_c_style(filename + tree_name_len, out, NULL, 0); diff --git a/quote.c b/quote.c index ced0245e80..7bb519c1a7 100644 --- a/quote.c +++ b/quote.c @@ -352,8 +352,7 @@ void write_name_quoted_relative(const char *name, const char *prefix, } /* quote path as relative to the given prefix */ -char *quote_path_relative(const char *in, const char *prefix, - struct strbuf *out) +char *quote_path(const char *in, const char *prefix, struct strbuf *out) { struct strbuf sb = STRBUF_INIT; const char *rel = relative_path(in, prefix, &sb); diff --git a/quote.h b/quote.h index fa09309cf6..837cb42a71 100644 --- a/quote.h +++ b/quote.h @@ -72,8 +72,7 @@ void write_name_quoted_relative(const char *name, const char *prefix, FILE *fp, int terminator); /* quote path as relative to the given prefix */ -char *quote_path_relative(const char *in, const char *prefix, - struct strbuf *out); +char *quote_path(const char *in, const char *prefix, struct strbuf *out); /* quoting as a string literal for other languages */ void perl_quote_buf(struct strbuf *sb, const char *src); diff --git a/wt-status.c b/wt-status.c index bb0f9120de..6b87592856 100644 --- a/wt-status.c +++ b/wt-status.c @@ -259,8 +259,6 @@ static void wt_longstatus_print_trailer(struct wt_status *s) status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", ""); } -#define quote_path quote_path_relative - static const char *wt_status_unmerged_status_string(int stagemask) { switch (stagemask) { From patchwork Tue Sep 8 20:52:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 11764517 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EADDC59D for ; Tue, 8 Sep 2020 20:52:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC6A82166E for ; Tue, 8 Sep 2020 20:52:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="EYJF4RQ3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730340AbgIHUwk (ORCPT ); Tue, 8 Sep 2020 16:52:40 -0400 Received: from pb-smtp1.pobox.com ([64.147.108.70]:62552 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730023AbgIHUwe (ORCPT ); Tue, 8 Sep 2020 16:52:34 -0400 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 4FE89827E6; Tue, 8 Sep 2020 16:52:27 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=g3e5cRI8zndd2Z2wDibCrewp0 +k=; b=EYJF4RQ3VZSQTWVZAgAIuokaActyML0N3yE18dYU3lyZ+VsQvigaevxDm 5nbv+mdhDkXzayd+ViMFpgA8MCYNiJX4MIiTCPMgHuGCjAPlgQyD31CdbkAdCJri DCef1EPeaY6tOLuAO04NTcTRENuJNehozG2tdQAK+guK1j93+s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=u6RJVFPbk0SRyLhPjlE QaIHqekffQcdF+tUvYPrtOuCV9N5RPKFB5xyfbCp0Tw8bFWlb8X0LdR1Wzdhgllg HhYTZYDbkVdjWSIzVXXf7ChN0Cv5MZyAG/RCjDgbdB1lfmm2H8hSyiUzEyMSnrgY pQbSZcJud4Sx7KAw518I33t0= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 47691827E4; Tue, 8 Sep 2020 16:52:27 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.75.7.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id C7414827E3; Tue, 8 Sep 2020 16:52:26 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 2/6] quote_path: give flags parameter to quote_path() Date: Tue, 8 Sep 2020 13:52:20 -0700 Message-Id: <20200908205224.4126551-3-gitster@pobox.com> X-Mailer: git-send-email 2.28.0-539-g66371d8995 In-Reply-To: <20200908205224.4126551-1-gitster@pobox.com> References: <20200908013013.1099937-1-sandals@crustytoothpaste.net> <20200908205224.4126551-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 33F77408-F215-11EA-A8DB-01D9BED8090B-77302942!pb-smtp1.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The quote_path() function computes a path (relative to its base directory) and c-quotes the result if necessary. Teach it to take a flags parameter to allow its behaviour to be enriched later. No behaviour change intended. Signed-off-by: Junio C Hamano --- builtin/clean.c | 22 +++++++++++----------- builtin/grep.c | 2 +- quote.c | 4 ++-- quote.h | 2 +- wt-status.c | 24 ++++++++++++------------ 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/builtin/clean.c b/builtin/clean.c index dee44fff6e..687ab473c2 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -162,7 +162,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, if ((force_flag & REMOVE_DIR_KEEP_NESTED_GIT) && is_nonbare_repository_dir(path)) { if (!quiet) { - quote_path(path->buf, prefix, "ed); + quote_path(path->buf, prefix, "ed, 0); printf(dry_run ? _(msg_would_skip_git_dir) : _(msg_skip_git_dir), quoted.buf); } @@ -177,7 +177,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, res = dry_run ? 0 : rmdir(path->buf); if (res) { int saved_errno = errno; - quote_path(path->buf, prefix, "ed); + quote_path(path->buf, prefix, "ed, 0); errno = saved_errno; warning_errno(_(msg_warn_remove_failed), quoted.buf); *dir_gone = 0; @@ -202,7 +202,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone)) ret = 1; if (gone) { - quote_path(path->buf, prefix, "ed); + quote_path(path->buf, prefix, "ed, 0); string_list_append(&dels, quoted.buf); } else *dir_gone = 0; @@ -210,11 +210,11 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, } else { res = dry_run ? 0 : unlink(path->buf); if (!res) { - quote_path(path->buf, prefix, "ed); + quote_path(path->buf, prefix, "ed, 0); string_list_append(&dels, quoted.buf); } else { int saved_errno = errno; - quote_path(path->buf, prefix, "ed); + quote_path(path->buf, prefix, "ed, 0); errno = saved_errno; warning_errno(_(msg_warn_remove_failed), quoted.buf); *dir_gone = 0; @@ -238,7 +238,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, *dir_gone = 1; else { int saved_errno = errno; - quote_path(path->buf, prefix, "ed); + quote_path(path->buf, prefix, "ed, 0); errno = saved_errno; warning_errno(_(msg_warn_remove_failed), quoted.buf); *dir_gone = 0; @@ -266,7 +266,7 @@ static void pretty_print_dels(void) struct column_options copts; for_each_string_list_item(item, &del_list) { - qname = quote_path(item->string, NULL, &buf); + qname = quote_path(item->string, NULL, &buf, 0); string_list_append(&list, qname); } @@ -753,7 +753,7 @@ static int ask_each_cmd(void) for_each_string_list_item(item, &del_list) { /* Ctrl-D should stop removing files */ if (!eof) { - qname = quote_path(item->string, NULL, &buf); + qname = quote_path(item->string, NULL, &buf, 0); /* TRANSLATORS: Make sure to keep [y/N] as is */ printf(_("Remove %s [y/N]? "), qname); if (git_read_line_interactively(&confirm) == EOF) { @@ -1047,19 +1047,19 @@ int cmd_clean(int argc, const char **argv, const char *prefix) if (remove_dirs(&abs_path, prefix, rm_flags, dry_run, quiet, &gone)) errors++; if (gone && !quiet) { - qname = quote_path(item->string, NULL, &buf); + qname = quote_path(item->string, NULL, &buf, 0); printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname); } } else { res = dry_run ? 0 : unlink(abs_path.buf); if (res) { int saved_errno = errno; - qname = quote_path(item->string, NULL, &buf); + qname = quote_path(item->string, NULL, &buf, 0); errno = saved_errno; warning_errno(_(msg_warn_remove_failed), qname); errors++; } else if (!quiet) { - qname = quote_path(item->string, NULL, &buf); + qname = quote_path(item->string, NULL, &buf, 0); printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname); } } diff --git a/builtin/grep.c b/builtin/grep.c index 9a91ad643a..c8037388c6 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -319,7 +319,7 @@ static void grep_source_name(struct grep_opt *opt, const char *filename, } if (opt->relative && opt->prefix_length) - quote_path(filename + tree_name_len, opt->prefix, out); + quote_path(filename + tree_name_len, opt->prefix, out, 0); else quote_c_style(filename + tree_name_len, out, NULL, 0); diff --git a/quote.c b/quote.c index 7bb519c1a7..03ca85afb0 100644 --- a/quote.c +++ b/quote.c @@ -352,12 +352,12 @@ void write_name_quoted_relative(const char *name, const char *prefix, } /* quote path as relative to the given prefix */ -char *quote_path(const char *in, const char *prefix, struct strbuf *out) +char *quote_path(const char *in, const char *prefix, struct strbuf *out, unsigned flags) { struct strbuf sb = STRBUF_INIT; const char *rel = relative_path(in, prefix, &sb); strbuf_reset(out); - quote_c_style_counted(rel, strlen(rel), out, NULL, 0); + quote_c_style_counted(rel, strlen(rel), out, NULL, flags); strbuf_release(&sb); return out->buf; diff --git a/quote.h b/quote.h index 837cb42a71..db7140b3c7 100644 --- a/quote.h +++ b/quote.h @@ -72,7 +72,7 @@ void write_name_quoted_relative(const char *name, const char *prefix, FILE *fp, int terminator); /* quote path as relative to the given prefix */ -char *quote_path(const char *in, const char *prefix, struct strbuf *out); +char *quote_path(const char *in, const char *prefix, struct strbuf *out, unsigned); /* quoting as a string literal for other languages */ void perl_quote_buf(struct strbuf *sb, const char *src); diff --git a/wt-status.c b/wt-status.c index 6b87592856..d6ca7bd52c 100644 --- a/wt-status.c +++ b/wt-status.c @@ -336,7 +336,7 @@ static void wt_longstatus_print_unmerged_data(struct wt_status *s, memset(padding, ' ', label_width); } - one = quote_path(it->string, s->prefix, &onebuf); + one = quote_path(it->string, s->prefix, &onebuf, 0); status_printf(s, color(WT_STATUS_HEADER, s), "\t"); how = wt_status_unmerged_status_string(d->stagemask); @@ -402,8 +402,8 @@ static void wt_longstatus_print_change_data(struct wt_status *s, if (d->rename_status == status) one_name = d->rename_source; - one = quote_path(one_name, s->prefix, &onebuf); - two = quote_path(two_name, s->prefix, &twobuf); + one = quote_path(one_name, s->prefix, &onebuf, 0); + two = quote_path(two_name, s->prefix, &twobuf, 0); status_printf(s, color(WT_STATUS_HEADER, s), "\t"); what = wt_status_diff_status_string(status); @@ -964,7 +964,7 @@ static void wt_longstatus_print_other(struct wt_status *s, struct string_list_item *it; const char *path; it = &(l->items[i]); - path = quote_path(it->string, s->prefix, &buf); + path = quote_path(it->string, s->prefix, &buf, 0); if (column_active(s->colopts)) { string_list_append(&output, path); continue; @@ -1848,7 +1848,7 @@ static void wt_shortstatus_unmerged(struct string_list_item *it, } else { struct strbuf onebuf = STRBUF_INIT; const char *one; - one = quote_path(it->string, s->prefix, &onebuf); + one = quote_path(it->string, s->prefix, &onebuf, 0); printf(" %s\n", one); strbuf_release(&onebuf); } @@ -1877,7 +1877,7 @@ static void wt_shortstatus_status(struct string_list_item *it, const char *one; if (d->rename_source) { - one = quote_path(d->rename_source, s->prefix, &onebuf); + one = quote_path(d->rename_source, s->prefix, &onebuf, 0); if (*one != '"' && strchr(one, ' ') != NULL) { putchar('"'); strbuf_addch(&onebuf, '"'); @@ -1886,7 +1886,7 @@ static void wt_shortstatus_status(struct string_list_item *it, printf("%s -> ", one); strbuf_release(&onebuf); } - one = quote_path(it->string, s->prefix, &onebuf); + one = quote_path(it->string, s->prefix, &onebuf, 0); if (*one != '"' && strchr(one, ' ') != NULL) { putchar('"'); strbuf_addch(&onebuf, '"'); @@ -1905,7 +1905,7 @@ static void wt_shortstatus_other(struct string_list_item *it, } else { struct strbuf onebuf = STRBUF_INIT; const char *one; - one = quote_path(it->string, s->prefix, &onebuf); + one = quote_path(it->string, s->prefix, &onebuf, 0); color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", sign); printf(" %s\n", one); strbuf_release(&onebuf); @@ -2222,9 +2222,9 @@ static void wt_porcelain_v2_print_changed_entry( */ sep_char = '\t'; eol_char = '\n'; - path = quote_path(it->string, s->prefix, &buf); + path = quote_path(it->string, s->prefix, &buf, 0); if (d->rename_source) - path_from = quote_path(d->rename_source, s->prefix, &buf_from); + path_from = quote_path(d->rename_source, s->prefix, &buf_from, 0); } if (path_from) @@ -2310,7 +2310,7 @@ static void wt_porcelain_v2_print_unmerged_entry( if (s->null_termination) path_index = it->string; else - path_index = quote_path(it->string, s->prefix, &buf_index); + path_index = quote_path(it->string, s->prefix, &buf_index, 0); fprintf(s->fp, "%c %s %s %06o %06o %06o %06o %s %s %s %s%c", unmerged_prefix, key, submodule_token, @@ -2343,7 +2343,7 @@ static void wt_porcelain_v2_print_other( path = it->string; eol_char = '\0'; } else { - path = quote_path(it->string, s->prefix, &buf); + path = quote_path(it->string, s->prefix, &buf, 0); eol_char = '\n'; } From patchwork Tue Sep 8 20:52:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 11764519 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0809D59D for ; Tue, 8 Sep 2020 20:52:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC62E21741 for ; Tue, 8 Sep 2020 20:52:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="FunchI+V" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729941AbgIHUwn (ORCPT ); Tue, 8 Sep 2020 16:52:43 -0400 Received: from pb-smtp20.pobox.com ([173.228.157.52]:54925 "EHLO pb-smtp20.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726699AbgIHUwh (ORCPT ); Tue, 8 Sep 2020 16:52:37 -0400 Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id ED103E7281; Tue, 8 Sep 2020 16:52:32 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=K2Arzo50AUATfduxGXC7J0z5S s0=; b=FunchI+VYn+Io9qviY1jCc8S9R+onmZaDCMrkCRmBVl9jeuvPrSu7PV9c 4gCJlsxly0yQd4Tyji0ptzOK+am4h/XaojTMFS4T5otrPcnQc+//dQ2SU6tw7a3L kXzGcN6A9wNx9NVmrzPtPWaAYMdltGiTjXMh5Yfw/ZGE4nKfVA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=LGoX7Bi5FOLXQVtko4B 9+qcdOl7VWHPAst9d41XdrWbwCj6mQFAKXjjdRP/ZUrL7fOnWjI/pH7nTe4XX3B8 HQRnp1XzVeZP1okqLqRsN57Ij7eP9buQoyW78mANbu4t0zVjhKuLjs/lX4UBduhI C4zNLWowvWzdt0QEEUoKggKs= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id E413EE7280; Tue, 8 Sep 2020 16:52:32 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.75.7.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id BC10EE7279; Tue, 8 Sep 2020 16:52:28 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 3/6] quote_path: optionally allow quoting a path with SP in it Date: Tue, 8 Sep 2020 13:52:21 -0700 Message-Id: <20200908205224.4126551-4-gitster@pobox.com> X-Mailer: git-send-email 2.28.0-539-g66371d8995 In-Reply-To: <20200908205224.4126551-1-gitster@pobox.com> References: <20200908013013.1099937-1-sandals@crustytoothpaste.net> <20200908205224.4126551-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 3521BEB0-F215-11EA-A98D-F0EA2EB3C613-77302942!pb-smtp20.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Some code in wt-status.c special case a path with SP in it, which usually does not have to be c-quoted, and ensure that such a path does get quoted. Move the logic to quote_path() and give it a bit in the flags word, QUOTE_PATH_QUOTE_SP. No behaviour change intended. Signed-off-by: Junio C Hamano --- quote.c | 9 ++++++++- quote.h | 1 + wt-status.c | 15 +++------------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/quote.c b/quote.c index 03ca85afb0..aa9a37b1b1 100644 --- a/quote.c +++ b/quote.c @@ -357,9 +357,16 @@ char *quote_path(const char *in, const char *prefix, struct strbuf *out, unsigne struct strbuf sb = STRBUF_INIT; const char *rel = relative_path(in, prefix, &sb); strbuf_reset(out); - quote_c_style_counted(rel, strlen(rel), out, NULL, flags); + quote_c_style_counted(rel, strlen(rel), out, NULL, 0); strbuf_release(&sb); + if ((flags & QUOTE_PATH_QUOTE_SP) && + (out->buf[0] != '"' && strchr(out->buf, ' '))) { + /* Ensure the whole thing is quoted if the path has SP in it */ + strbuf_insertstr(out, 0, "\""); + strbuf_addch(out, '"'); + } + return out->buf; } diff --git a/quote.h b/quote.h index db7140b3c7..823f56cb94 100644 --- a/quote.h +++ b/quote.h @@ -73,6 +73,7 @@ void write_name_quoted_relative(const char *name, const char *prefix, /* quote path as relative to the given prefix */ char *quote_path(const char *in, const char *prefix, struct strbuf *out, unsigned); +#define QUOTE_PATH_QUOTE_SP 01 /* quoting as a string literal for other languages */ void perl_quote_buf(struct strbuf *sb, const char *src); diff --git a/wt-status.c b/wt-status.c index d6ca7bd52c..adbf6958bd 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1877,21 +1877,12 @@ static void wt_shortstatus_status(struct string_list_item *it, const char *one; if (d->rename_source) { - one = quote_path(d->rename_source, s->prefix, &onebuf, 0); - if (*one != '"' && strchr(one, ' ') != NULL) { - putchar('"'); - strbuf_addch(&onebuf, '"'); - one = onebuf.buf; - } + one = quote_path(d->rename_source, s->prefix, &onebuf, + QUOTE_PATH_QUOTE_SP); printf("%s -> ", one); strbuf_release(&onebuf); } - one = quote_path(it->string, s->prefix, &onebuf, 0); - if (*one != '"' && strchr(one, ' ') != NULL) { - putchar('"'); - strbuf_addch(&onebuf, '"'); - one = onebuf.buf; - } + one = quote_path(it->string, s->prefix, &onebuf, QUOTE_PATH_QUOTE_SP); printf("%s\n", one); strbuf_release(&onebuf); } From patchwork Tue Sep 8 20:52:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 11764521 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 11E79112E for ; Tue, 8 Sep 2020 20:52:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E833A2145D for ; Tue, 8 Sep 2020 20:52:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="uvyV0io6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730346AbgIHUwo (ORCPT ); Tue, 8 Sep 2020 16:52:44 -0400 Received: from pb-smtp21.pobox.com ([173.228.157.53]:53369 "EHLO pb-smtp21.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730093AbgIHUwj (ORCPT ); Tue, 8 Sep 2020 16:52:39 -0400 Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 1CF4EEEE6D; Tue, 8 Sep 2020 16:52:35 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=+JoYfFsHRaiaMsZ1BVZlD24Ke 5s=; b=uvyV0io69QTOwgPd5V3BtAVo7gYZYcAViVZ25IlLzQBvlXGUsFTpgpL7b bIgQ/mN/tiUHIAitfY064maYgoVY4YwatGtiyMkKElOaPOVrbPtxV4FSzRd/6pY4 Rg4le7Y84qtIVPXFQg4Gufn0h09uXHftt/i5sCCevQqt2nVvvU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=vUzlu+QIbAs8KqKd/Lc 9swUH+ZY7w/7M9YBHbuS2Ljn6JyLANbF/fdZOr8hdWxcPYqjA8JcQe/ZqGvh22b3 Hi4/Q85PskZMylp4kJHh5aUs5wM5VC/EzXS5h4iWnubyCBHL5f4Z8WRGlkQkreFd DWxVk/iGAZ5wAVKYnE7DWVDM= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 1666EEEE6C; Tue, 8 Sep 2020 16:52:35 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.75.7.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 56F41EEE6B; Tue, 8 Sep 2020 16:52:32 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 4/6] wt-status: consistently quote paths in "status --short" output Date: Tue, 8 Sep 2020 13:52:22 -0700 Message-Id: <20200908205224.4126551-5-gitster@pobox.com> X-Mailer: git-send-email 2.28.0-539-g66371d8995 In-Reply-To: <20200908205224.4126551-1-gitster@pobox.com> References: <20200908013013.1099937-1-sandals@crustytoothpaste.net> <20200908205224.4126551-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 3744CE3A-F215-11EA-ABF1-843F439F7C89-77302942!pb-smtp21.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Tracked paths with SP in them were c-quoted in "git status --short" output, but untracked, ignored, and unmerged paths weren't. Treat them the same way for consistency. The test was stolen from a patch to fix output for the 'untracked' paths by brian m. carlson. Signed-off-by: Junio C Hamano --- t/t7508-status.sh | 21 +++++++++++++++++++++ wt-status.c | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/t/t7508-status.sh b/t/t7508-status.sh index e81759319f..ef8d19c151 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -814,6 +814,27 @@ test_expect_success 'status -s without relative paths' ' ' +cat >expect <<\EOF + M dir1/modified +A dir2/added +A "file with spaces" +?? dir1/untracked +?? dir2/modified +?? dir2/untracked +?? "file with spaces 2" +?? untracked +EOF + +test_expect_success 'status -s without relative paths' ' + test_when_finished "git rm --cached \"file with spaces\"; rm -f file*" && + >"file with spaces" && + >"file with spaces 2" && + git add "file with spaces" && + git status -s >output && + test_cmp expect output + +' + test_expect_success 'dry-run of partial commit excluding new file in index' ' cat >expect <string, s->prefix, &onebuf, 0); + one = quote_path(it->string, s->prefix, &onebuf, QUOTE_PATH_QUOTE_SP); printf(" %s\n", one); strbuf_release(&onebuf); } @@ -1896,7 +1896,7 @@ static void wt_shortstatus_other(struct string_list_item *it, } else { struct strbuf onebuf = STRBUF_INIT; const char *one; - one = quote_path(it->string, s->prefix, &onebuf, 0); + one = quote_path(it->string, s->prefix, &onebuf, QUOTE_PATH_QUOTE_SP); color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", sign); printf(" %s\n", one); strbuf_release(&onebuf); From patchwork Tue Sep 8 20:52:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 11764527 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0904C59D for ; Tue, 8 Sep 2020 20:52:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E24B921741 for ; Tue, 8 Sep 2020 20:52:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="SfuNjeOe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730369AbgIHUwr (ORCPT ); Tue, 8 Sep 2020 16:52:47 -0400 Received: from pb-smtp2.pobox.com ([64.147.108.71]:62517 "EHLO pb-smtp2.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730104AbgIHUwj (ORCPT ); Tue, 8 Sep 2020 16:52:39 -0400 Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 7D20B8B6C6; Tue, 8 Sep 2020 16:52:35 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=ROfCNOzMFGP0ILtWEJfnlBEUG OA=; b=SfuNjeOeunycyIARvJsFb/RsLUgQf4mEHbPsJbjk9m0OxBOpp2aw9/EPY Hy3+S6prEYQSyJTb+WJF/BbZLKwVjJPPiGV0Y5G3O7tXzGaimyshcS1Gsz8JnMZo cXJb/y6dC4peXs1sJ4P1BPVdPUuAIwd1hCthCsxiXWfLUip+8c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=KeID8r2ApmbOfjP5Kph qcxQAZi8P1nC+EPWtpItbh6XHtt3RGg9NjYUetmaGI0YBCExitwZsbkqK5CJ3jpr Jl/HvVx8634LFzSTinnRXULQ+eyi3RdLW61he7i4gbsYiXUQnCO/174g4IJQPXte CM3j8oSOpE72iNVxH8mUo96s= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 73F388B6C5; Tue, 8 Sep 2020 16:52:35 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.75.7.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id E49D48B6C4; Tue, 8 Sep 2020 16:52:34 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 5/6] quote: rename misnamed sq_lookup[] to cq_lookup[] Date: Tue, 8 Sep 2020 13:52:23 -0700 Message-Id: <20200908205224.4126551-6-gitster@pobox.com> X-Mailer: git-send-email 2.28.0-539-g66371d8995 In-Reply-To: <20200908205224.4126551-1-gitster@pobox.com> References: <20200908013013.1099937-1-sandals@crustytoothpaste.net> <20200908205224.4126551-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 38CF05D6-F215-11EA-B067-2F5D23BA3BAF-77302942!pb-smtp2.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This table is used to see if each byte needs quoting when responding to a request to C-quote the string, not quoting with single-quote in the shell style. Similarly, sq_must_quote() is fed each byte from the string being C-quoted. No behaviour change intended. Signed-off-by: Junio C Hamano --- quote.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/quote.c b/quote.c index aa9a37b1b1..016ebf8873 100644 --- a/quote.c +++ b/quote.c @@ -210,7 +210,7 @@ int sq_dequote_to_strvec(char *arg, struct strvec *array) */ #define X8(x) x, x, x, x, x, x, x, x #define X16(x) X8(x), X8(x) -static signed char const sq_lookup[256] = { +static signed char const cq_lookup[256] = { /* 0 1 2 3 4 5 6 7 */ /* 0x00 */ 1, 1, 1, 1, 1, 1, 1, 'a', /* 0x08 */ 'b', 't', 'n', 'v', 'f', 'r', 1, 1, @@ -223,9 +223,9 @@ static signed char const sq_lookup[256] = { /* 0x80 */ /* set to 0 */ }; -static inline int sq_must_quote(char c) +static inline int cq_must_quote(char c) { - return sq_lookup[(unsigned char)c] + quote_path_fully > 0; + return cq_lookup[(unsigned char)c] + quote_path_fully > 0; } /* returns the longest prefix not needing a quote up to maxlen if positive. @@ -235,9 +235,9 @@ static size_t next_quote_pos(const char *s, ssize_t maxlen) { size_t len; if (maxlen < 0) { - for (len = 0; !sq_must_quote(s[len]); len++); + for (len = 0; !cq_must_quote(s[len]); len++); } else { - for (len = 0; len < maxlen && !sq_must_quote(s[len]); len++); + for (len = 0; len < maxlen && !cq_must_quote(s[len]); len++); } return len; } @@ -291,8 +291,8 @@ static size_t quote_c_style_counted(const char *name, ssize_t maxlen, ch = (unsigned char)*p++; if (maxlen >= 0) maxlen -= len + 1; - if (sq_lookup[ch] >= ' ') { - EMIT(sq_lookup[ch]); + if (cq_lookup[ch] >= ' ') { + EMIT(cq_lookup[ch]); } else { EMIT(((ch >> 6) & 03) + '0'); EMIT(((ch >> 3) & 07) + '0'); From patchwork Tue Sep 8 20:52:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 11764525 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5091112E for ; Tue, 8 Sep 2020 20:52:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABCA42098B for ; Tue, 8 Sep 2020 20:52:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="NCJIa10H" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728709AbgIHUwp (ORCPT ); Tue, 8 Sep 2020 16:52:45 -0400 Received: from pb-smtp1.pobox.com ([64.147.108.70]:64572 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730111AbgIHUwk (ORCPT ); Tue, 8 Sep 2020 16:52:40 -0400 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 462DF827ED; Tue, 8 Sep 2020 16:52:37 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=2j7UAr0wmr8cY4TrZcwJR/Jtr gk=; b=NCJIa10HU0Zqrm7kGPsjboy50QpclkYBCFCSROQPn5qM3rQj4EpwAJcJe Jb5kRSLJ5BA8s/uImCjOgl6qFGrFlrhPv/klRDWxiu3C0bYk+hAsGNYnVsTTGjib 89krF46eiFJ6WiiohT+JHvz925VYrfHINPwOWq6Vi8HqEgnFxs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=nKqaaffnytKKBn856tj HkQO7pKZUhy9pRw6jc5yEpuG0PDfJz2S289rtI6V8dYJgpGmk+FiILJ3YqyvhZZO rM9Nd86Z/Eb+YQXEntZvet9kOlgXVW+iG54REo22jPxXndcENohC82ckN5CJAttZ J1pbZZb/ku8HtQIBB4DrxCgg= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 3EC24827EC; Tue, 8 Sep 2020 16:52:37 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.75.7.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id A47B0827EB; Tue, 8 Sep 2020 16:52:35 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 6/6] quote: turn 'nodq' parameter into a set of flags Date: Tue, 8 Sep 2020 13:52:24 -0700 Message-Id: <20200908205224.4126551-7-gitster@pobox.com> X-Mailer: git-send-email 2.28.0-539-g66371d8995 In-Reply-To: <20200908205224.4126551-1-gitster@pobox.com> References: <20200908013013.1099937-1-sandals@crustytoothpaste.net> <20200908205224.4126551-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 393E94B4-F215-11EA-80D0-01D9BED8090B-77302942!pb-smtp1.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org quote_c_style() and its friend quote_two_c_style() both take an optional "please omit the double quotes around the quoted body" parameter. Turn it into a flag word, assign one bit out of it, and call it CQUOTE_NODQ bit. No behaviour change intended. Signed-off-by: Junio C Hamano --- diff.c | 8 ++++---- quote.c | 15 +++++++++------ quote.h | 7 +++++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/diff.c b/diff.c index 0299a73079..e7d6e60b23 100644 --- a/diff.c +++ b/diff.c @@ -482,14 +482,14 @@ int git_diff_basic_config(const char *var, const char *value, void *cb) static char *quote_two(const char *one, const char *two) { - int need_one = quote_c_style(one, NULL, NULL, 1); - int need_two = quote_c_style(two, NULL, NULL, 1); + int need_one = quote_c_style(one, NULL, NULL, CQUOTE_NODQ); + int need_two = quote_c_style(two, NULL, NULL, CQUOTE_NODQ); struct strbuf res = STRBUF_INIT; if (need_one + need_two) { strbuf_addch(&res, '"'); - quote_c_style(one, &res, NULL, 1); - quote_c_style(two, &res, NULL, 1); + quote_c_style(one, &res, NULL, CQUOTE_NODQ); + quote_c_style(two, &res, NULL, CQUOTE_NODQ); strbuf_addch(&res, '"'); } else { strbuf_addstr(&res, one); diff --git a/quote.c b/quote.c index 016ebf8873..b2f38d0e57 100644 --- a/quote.c +++ b/quote.c @@ -256,7 +256,7 @@ static size_t next_quote_pos(const char *s, ssize_t maxlen) * Return value is the same as in (1). */ static size_t quote_c_style_counted(const char *name, ssize_t maxlen, - struct strbuf *sb, FILE *fp, int no_dq) + struct strbuf *sb, FILE *fp, unsigned flags) { #undef EMIT #define EMIT(c) \ @@ -272,6 +272,7 @@ static size_t quote_c_style_counted(const char *name, ssize_t maxlen, count += (l); \ } while (0) + int no_dq = !!(flags & CQUOTE_NODQ); size_t len, count = 0; const char *p = name; @@ -309,19 +310,21 @@ static size_t quote_c_style_counted(const char *name, ssize_t maxlen, return count; } -size_t quote_c_style(const char *name, struct strbuf *sb, FILE *fp, int nodq) +size_t quote_c_style(const char *name, struct strbuf *sb, FILE *fp, unsigned flags) { - return quote_c_style_counted(name, -1, sb, fp, nodq); + return quote_c_style_counted(name, -1, sb, fp, flags); } -void quote_two_c_style(struct strbuf *sb, const char *prefix, const char *path, int nodq) +void quote_two_c_style(struct strbuf *sb, const char *prefix, const char *path, + unsigned flags) { + int nodq = !!(flags & CQUOTE_NODQ); if (quote_c_style(prefix, NULL, NULL, 0) || quote_c_style(path, NULL, NULL, 0)) { if (!nodq) strbuf_addch(sb, '"'); - quote_c_style(prefix, sb, NULL, 1); - quote_c_style(path, sb, NULL, 1); + quote_c_style(prefix, sb, NULL, CQUOTE_NODQ); + quote_c_style(path, sb, NULL, CQUOTE_NODQ); if (!nodq) strbuf_addch(sb, '"'); } else { diff --git a/quote.h b/quote.h index 823f56cb94..0e49c61144 100644 --- a/quote.h +++ b/quote.h @@ -64,8 +64,11 @@ struct strvec; int sq_dequote_to_strvec(char *arg, struct strvec *); int unquote_c_style(struct strbuf *, const char *quoted, const char **endp); -size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq); -void quote_two_c_style(struct strbuf *, const char *, const char *, int); + +/* Bits in the flags parameter to quote_c_style() */ +#define CQUOTE_NODQ 01 +size_t quote_c_style(const char *name, struct strbuf *, FILE *, unsigned); +void quote_two_c_style(struct strbuf *, const char *, const char *, unsigned); void write_name_quoted(const char *name, FILE *, int terminator); void write_name_quoted_relative(const char *name, const char *prefix,