From patchwork Thu Sep 10 17:01:53 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: 11768195 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 7FBCA698 for ; Thu, 10 Sep 2020 17:03:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CA32208E4 for ; Thu, 10 Sep 2020 17:03:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="ECglwAyV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726612AbgIJRCs (ORCPT ); Thu, 10 Sep 2020 13:02:48 -0400 Received: from pb-smtp2.pobox.com ([64.147.108.71]:61756 "EHLO pb-smtp2.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726660AbgIJRCb (ORCPT ); Thu, 10 Sep 2020 13:02:31 -0400 Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 721E076059; Thu, 10 Sep 2020 13:02:05 -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=BBKjwfiyvzXymCBJWHU88ABwe eM=; b=ECglwAyVyvvbJ/YofmhIWr9PYk/ja66cTxgu5D/forVuBQ8qyta10A4GG 3VBfyUkoLU8GdzbNd8ecEMOmlsOSxRUxe+YvBKnCZvi4rxd2v8xcjZkrlltpzBvM 6DNA2vR7SHBQDcGQuSzyvFAOiebLTjPNGUPrykFpWRB387Ygh4= 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=x9arM5WZJ84hACXluqc 8DmsXMTXP5PyCk77Mm0zlC/Lh1t4R6iLL5hzapipbCYefeQzQopMFfYyUcYcrnUU /x14jpwFTbxiWO/nvh+RPl7ZXQOZAM2jPPMAEeKOY+tEGpzQcK2t374l9RtUoGBv 1U0tVY54DlLcqD5FoOz5UQAU= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 6826576058; Thu, 10 Sep 2020 13:02:05 -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 929F776055; Thu, 10 Sep 2020 13:02:04 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v2 1/7] quote_path: rename quote_path_relative() to quote_path() Date: Thu, 10 Sep 2020 10:01:53 -0700 Message-Id: <20200910170159.1278781-2-gitster@pobox.com> X-Mailer: git-send-email 2.28.0-603-ga98dad7d4d In-Reply-To: <20200910170159.1278781-1-gitster@pobox.com> References: <20200908205224.4126551-1-gitster@pobox.com> <20200910170159.1278781-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 5A1C5694-F387-11EA-8389-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 Thu Sep 10 17:01:54 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: 11768205 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 71BE5698 for ; Thu, 10 Sep 2020 17:03:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5022720C09 for ; Thu, 10 Sep 2020 17:03:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="CMmj5q1E" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727780AbgIJRDN (ORCPT ); Thu, 10 Sep 2020 13:03:13 -0400 Received: from pb-smtp21.pobox.com ([173.228.157.53]:58819 "EHLO pb-smtp21.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727001AbgIJRCd (ORCPT ); Thu, 10 Sep 2020 13:02:33 -0400 Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 369E3FEEC6; Thu, 10 Sep 2020 13:02:09 -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=uPojmkT63GDILw3NFaTePXV+m CY=; b=CMmj5q1E08iV+CKzan5+3hhmwIpCcfQe+VcsFxHdXqSSu9PuzcvbQHwea itac8E9TXYs6uFVgwhBXCUMVEy0X+Qcr6FgtOVbYFWMNltPkr5aR26hCsBNKhGY2 Tlu38mm+4WcXUmN/TMK7i+sjhJANDYCubOa/YNHP/LqWMj3N4Y= 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=jQcKhCaWb5qUxz8tyRC fEs3Sdl5KjS42LRp3lAmbQM55gwYIlyVUnHb6HrzS63y3N2zzTewh+xyOF+xE2kF YotU/Ivqkn5aaLUTiWY8eaJ16QcV8o6XyWTKoewjnsHB5HSdeADmu9ozigVDWVBx dYuRXS9ZpqyKnN4cvdb23+BU= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 2E76BFEEC5; Thu, 10 Sep 2020 13:02:09 -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 6BFC2FEEC2; Thu, 10 Sep 2020 13:02:06 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v2 2/7] quote_path: give flags parameter to quote_path() Date: Thu, 10 Sep 2020 10:01:54 -0700 Message-Id: <20200910170159.1278781-3-gitster@pobox.com> X-Mailer: git-send-email 2.28.0-603-ga98dad7d4d In-Reply-To: <20200910170159.1278781-1-gitster@pobox.com> References: <20200908205224.4126551-1-gitster@pobox.com> <20200910170159.1278781-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 5B3523BC-F387-11EA-90F7-843F439F7C89-77302942!pb-smtp21.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 | 2 +- quote.h | 2 +- wt-status.c | 24 ++++++++++++------------ 5 files changed, 26 insertions(+), 26 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..a86f9f22a2 100644 --- a/quote.c +++ b/quote.c @@ -352,7 +352,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) +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); diff --git a/quote.h b/quote.h index 837cb42a71..4687b5daf4 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 flags); /* 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 Thu Sep 10 17:01:55 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: 11768207 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 2BAB1698 for ; Thu, 10 Sep 2020 17:03:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0FDC020C09 for ; Thu, 10 Sep 2020 17:03:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="p7yERWeq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726847AbgIJRDQ (ORCPT ); Thu, 10 Sep 2020 13:03:16 -0400 Received: from pb-smtp1.pobox.com ([64.147.108.70]:54766 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727024AbgIJRCc (ORCPT ); Thu, 10 Sep 2020 13:02:32 -0400 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 954286BA5E; Thu, 10 Sep 2020 13:02:09 -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=1vAYWvGtmBlbX0o9EGT2oVEu3 Js=; b=p7yERWeqZf2AIwWeY68Onz6IlEij5iVjkuOYlVAT7urzj+l/hPQcMBrTr xrx8QBAXP0/vJEJW4z1WCtp8jM2HexIugV8NOL7PVylc7rUGWPDBBuTuRJjzu4ty fNClEUe/K0L+axnW+7wpYAFNqBrfpdL6s+K8Q5mexAGutZnZj4= 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=pi4lwfymafzaaT5Bvnp kytUomk7rmu1f2a4WAET2Yyy1Ah0d5W4VWaTuaHZDVieOlSpZyCVEtT/yvLmHmNQ +hRSVCY498n0PO4fd5w8qe2LphSN1JYhndW+tHM5T4XwxbotuXGn9oqXOJYThbRu Nq+vZHGbRVEWY0rDqXLHQ1PU= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 872176BA5D; Thu, 10 Sep 2020 13:02:09 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [35.190.152.57]) (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 DC5956BA5C; Thu, 10 Sep 2020 13:02:08 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v2 3/7] quote_path: optionally allow quoting a path with SP in it Date: Thu, 10 Sep 2020 10:01:55 -0700 Message-Id: <20200910170159.1278781-4-gitster@pobox.com> X-Mailer: git-send-email 2.28.0-603-ga98dad7d4d In-Reply-To: <20200910170159.1278781-1-gitster@pobox.com> References: <20200908205224.4126551-1-gitster@pobox.com> <20200910170159.1278781-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 5CACEED2-F387-11EA-98EF-01D9BED8090B-77302942!pb-smtp1.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 | 7 +++++++ quote.h | 1 + wt-status.c | 15 +++------------ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/quote.c b/quote.c index a86f9f22a2..aa9a37b1b1 100644 --- a/quote.c +++ b/quote.c @@ -360,6 +360,13 @@ char *quote_path(const char *in, const char *prefix, struct strbuf *out, unsigne 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 4687b5daf4..1918d1e00e 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 flags); +#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 Thu Sep 10 17:01:56 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: 11768197 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 66AA2698 for ; Thu, 10 Sep 2020 17:03:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DB9D20C09 for ; Thu, 10 Sep 2020 17:03:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="t9U8fltr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727058AbgIJRDC (ORCPT ); Thu, 10 Sep 2020 13:03:02 -0400 Received: from pb-smtp20.pobox.com ([173.228.157.52]:54718 "EHLO pb-smtp20.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727070AbgIJRCc (ORCPT ); Thu, 10 Sep 2020 13:02:32 -0400 Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id A6056E0E12; Thu, 10 Sep 2020 13:02:13 -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=5JRU/h3y3iEwQbydRN4YuflRC BU=; b=t9U8fltr0Ar7+kgxErtkIuguhkXBN6iW1zvhQbem9DUv1+Ut2R/80pOUV vO2ISLDMsyCbJL1mkVNUhgheGzSlR5UjwVeFrxUlibHUXePUAVPmL7e0cMvSiZfL LxKBpYlwa2MNEbuI8P8j7u0NB1FoViqabBJLA9XZPp2+XyeULE= 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=Je/yLbRzEx/jM7adZjK 5mCDONqM6uQnuRmxv9///ftUSvOIYydBsSXZEyvXLo/aY0A2gaAme62EOEeOGTHM UoP1ypbRU8sjBPogIEhXMM3lM0qQlKrv42XIC1Ix0Qes0kGwfS7ANt5NgSerI1gx 09dRJpi2R8FtpaLhnh0SAeR4= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 9FB8DE0E11; Thu, 10 Sep 2020 13:02:13 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [35.190.152.57]) (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 DD697E0E10; Thu, 10 Sep 2020 13:02:10 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v2 4/7] quote_path: code clarification Date: Thu, 10 Sep 2020 10:01:56 -0700 Message-Id: <20200910170159.1278781-5-gitster@pobox.com> X-Mailer: git-send-email 2.28.0-603-ga98dad7d4d In-Reply-To: <20200910170159.1278781-1-gitster@pobox.com> References: <20200908205224.4126551-1-gitster@pobox.com> <20200910170159.1278781-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 5DDE9CCE-F387-11EA-AC70-F0EA2EB3C613-77302942!pb-smtp20.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The implementation we moved from wt-status to enclose a pathname that has a SP in it inside a dq-pair is a bit convoluted. It lets quote_c_style_counted() do its escaping and then (1) if the input string got escaped, which is checked by seeing if the result begins with a double-quote, declare that we are done. If there wasn't any SP in the input, that is OK, and if there was, the result is quoted already so it is OK, too. (2) if the input string did not get escaped, and the result has SP in it, enclose the whole thing in a dq-pair ourselves. Instead we can scan the path upfront to see if the input has SP in it. If so, we tell quote_c_style_counted() not to enclose its output in a dq-pair, and we add a dq-pair ourselves. Whether the input had bytes that quote_c_style_counted() uses backslash quoting, this would give us a desired quoted string. If the input does not have SP in it, we just let quote_c_style_counted() do its thing as usual, which would enclose the result in a dq-pair only when needed. Signed-off-by: Junio C Hamano --- quote.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/quote.c b/quote.c index aa9a37b1b1..b8107cd403 100644 --- a/quote.c +++ b/quote.c @@ -356,16 +356,21 @@ 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); + int force_dq = ((flags & QUOTE_PATH_QUOTE_SP) && strchr(rel, ' ')); + strbuf_reset(out); - 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, "\""); + /* + * If the caller wants us to enclose the output in a dq-pair + * whether quote_c_style_counted() needs to, we do it ourselves + * and tell quote_c_style_counted() not to. + */ + if (force_dq) strbuf_addch(out, '"'); - } + quote_c_style_counted(rel, strlen(rel), out, NULL, !!force_dq); + if (force_dq) + strbuf_addch(out, '"'); + strbuf_release(&sb); return out->buf; } From patchwork Thu Sep 10 17:01:57 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: 11768201 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 A01D792C for ; Thu, 10 Sep 2020 17:03:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A9DD208E4 for ; Thu, 10 Sep 2020 17:03:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="g9dhL6Qg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727775AbgIJRDL (ORCPT ); Thu, 10 Sep 2020 13:03:11 -0400 Received: from pb-smtp2.pobox.com ([64.147.108.71]:53474 "EHLO pb-smtp2.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727083AbgIJRCd (ORCPT ); Thu, 10 Sep 2020 13:02:33 -0400 Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 074297605D; Thu, 10 Sep 2020 13:02:14 -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=Hp0YNOY8GAT7/AkLoLsHudX6+ oE=; b=g9dhL6QgxY2WlJs8v5uxWVdzWG+wiEsrX04jye19GG+vndo778mLASxv5 0uFrkW0TJ7BEe6IYXdJVkLLNmeqeHENIoh/FbVGVE5DmXKqNt5W0Am+/FcVqcYnq uITUE9i3CSvaO3qEsCxkri5lK6aHFmS1iMytJFw1sURW41UjSY= 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=l9bS0M3fRWxxrTlVOgw NOwF/bX419umPhl4C5Dp61M8gQu0W3chzkmD/R/2VO2b5XXU2oY2lZIERLxlVKtf v7heY/y8qiaGc0QfvMXNYSXMHvW0rjYxevDEcAfS6cPLq9MQ8N45HqrEBwGPT96L J1DiwHUM34RU92wk3vj1KztA= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id F3BF67605C; Thu, 10 Sep 2020 13:02:13 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [35.190.152.57]) (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 6FE4F7605A; Thu, 10 Sep 2020 13:02:13 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v2 5/7] wt-status: consistently quote paths in "status --short" output Date: Thu, 10 Sep 2020 10:01:57 -0700 Message-Id: <20200910170159.1278781-6-gitster@pobox.com> X-Mailer: git-send-email 2.28.0-603-ga98dad7d4d In-Reply-To: <20200910170159.1278781-1-gitster@pobox.com> References: <20200908205224.4126551-1-gitster@pobox.com> <20200910170159.1278781-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 5F6387B2-F387-11EA-8EFC-2F5D23BA3BAF-77302942!pb-smtp2.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 cquoted in "git status --short" output, but untracked, ignored, and unmerged paths weren't. The test was stolen from a patch to fix output for the 'untracked' paths by brian m. carlson, with similar tests added for 'ignored' ones. Signed-off-by: Junio C Hamano --- t/t7508-status.sh | 27 +++++++++++++++++++++++++++ wt-status.c | 4 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/t/t7508-status.sh b/t/t7508-status.sh index e81759319f..2e9c6daf1a 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -814,6 +814,33 @@ 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" && + >"expect with spaces" && + git add "file with spaces" && + + git status -s >output && + test_cmp expect output && + + git status -s --ignored >output && + grep "^!! \"expect with spaces\"$" output && + grep -v "^!! " output >output-wo-ignored && + test_cmp expect output-wo-ignored +' + 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 Thu Sep 10 17:01:58 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: 11768209 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 1E61292C for ; Thu, 10 Sep 2020 17:03:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F215D20C09 for ; Thu, 10 Sep 2020 17:03:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="pjXuMrbj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726807AbgIJRDT (ORCPT ); Thu, 10 Sep 2020 13:03:19 -0400 Received: from pb-smtp21.pobox.com ([173.228.157.53]:53882 "EHLO pb-smtp21.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727094AbgIJRCc (ORCPT ); Thu, 10 Sep 2020 13:02:32 -0400 Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 0AE0CFEECE; Thu, 10 Sep 2020 13:02:18 -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=dykOb3ZypdPJEX40sk7we6g5d pE=; b=pjXuMrbjt9g7sNlB9wCXYaN6zhde5+aye1rwuEYlxUuF2LSpznJNsRKye jfy8ixCP31WnpY/KrGSCPHmlvE15B1VNaC9dR/qOIGtYmFZ3ItpxxyCPiHxCCJdS o5ECC6xcZNm9PAppBA5AjjPeUJmFNHqvclA/lu3nYGcpz4tD88= 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=XAcfesw+Pbmhk01ugir o7vBCClqFtO9CBZR/RoXyMUNx8fwIEWTQo84N7QbaAbvsR77nqmUiJVbm9w/X6oP fj1RA40i9bBANA0l/7tJi97HdCVvW7+zxWRBklhqBtBy10IH3tqWFMCqfERUkVin f1fQZkNv917VSHDC2vT/NaJg= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id E596FFEECD; Thu, 10 Sep 2020 13:02:17 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [35.190.152.57]) (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 2F00EFEEC9; Thu, 10 Sep 2020 13:02:15 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v2 6/7] quote: rename misnamed sq_lookup[] to cq_lookup[] Date: Thu, 10 Sep 2020 10:01:58 -0700 Message-Id: <20200910170159.1278781-7-gitster@pobox.com> X-Mailer: git-send-email 2.28.0-603-ga98dad7d4d In-Reply-To: <20200910170159.1278781-1-gitster@pobox.com> References: <20200908205224.4126551-1-gitster@pobox.com> <20200910170159.1278781-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 606C47A2-F387-11EA-8FB2-843F439F7C89-77302942!pb-smtp21.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 b8107cd403..9a6e0e7dea 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 Thu Sep 10 17:01:59 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: 11768199 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 DC54A92C for ; Thu, 10 Sep 2020 17:03:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BBCC0214F1 for ; Thu, 10 Sep 2020 17:03:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="TTHbfdmq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727771AbgIJRDK (ORCPT ); Thu, 10 Sep 2020 13:03:10 -0400 Received: from pb-smtp1.pobox.com ([64.147.108.70]:57588 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727099AbgIJRCg (ORCPT ); Thu, 10 Sep 2020 13:02:36 -0400 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 21B2F6BA64; Thu, 10 Sep 2020 13:02:18 -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=gi/0O/860iMuLPQHGXZ+SO4iR 0c=; b=TTHbfdmqjXuJz7VYC3/nE1PkGn4gKhUyh4RzNT4Tv5e8Dtnx3y4rA6pxr 8jokejc3fXcGQH12t1IWO0+P5UodYT6PQVkttLfopdxhyaQvNlVz4ZGRV2E08fFT tqPqE7UrfLTorZeIleqUqjU3IxHYJpvySahxc7dGY1ajX2zWVY= 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=cgAn7sX+e3T93naQ6pe ur3hQEBS5iHJNgOscqSkqs18rg9thPK5W/o1GZWpyhBnLgxVAiqS0ZIhVojiyRBd rh5ozBkRUF7Y5HQeWp7JxdJEARQ6jO/NJhWay7oL3SEkNZSwej4RcpbDKj61j8x1 kKTqn1uc//VctZG6tPtzPFj0= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 1993C6BA63; Thu, 10 Sep 2020 13:02:18 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [35.190.152.57]) (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 993FC6BA60; Thu, 10 Sep 2020 13:02:17 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v2 7/7] quote: turn 'nodq' parameter into a set of flags Date: Thu, 10 Sep 2020 10:01:59 -0700 Message-Id: <20200910170159.1278781-8-gitster@pobox.com> X-Mailer: git-send-email 2.28.0-603-ga98dad7d4d In-Reply-To: <20200910170159.1278781-1-gitster@pobox.com> References: <20200908205224.4126551-1-gitster@pobox.com> <20200910170159.1278781-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 61E043A4-F387-11EA-B898-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 | 18 +++++++++++------- quote.h | 7 +++++-- 3 files changed, 20 insertions(+), 13 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 9a6e0e7dea..69f4ca45da 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 { @@ -367,7 +370,8 @@ char *quote_path(const char *in, const char *prefix, struct strbuf *out, unsigne */ if (force_dq) strbuf_addch(out, '"'); - quote_c_style_counted(rel, strlen(rel), out, NULL, !!force_dq); + quote_c_style_counted(rel, strlen(rel), out, NULL, + force_dq ? CQUOTE_NODQ : 0); if (force_dq) strbuf_addch(out, '"'); strbuf_release(&sb); diff --git a/quote.h b/quote.h index 1918d1e00e..4b72a583cf 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,