git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: "brian m. carlson" <sandals@crustytoothpaste.net>,
	"Jeff King" <peff@peff.net>, "René Scharfe" <l.s.r@web.de>
Subject: [PATCH v2 0/7] quote_path() clean-ups
Date: Thu, 10 Sep 2020 10:01:52 -0700	[thread overview]
Message-ID: <20200910170159.1278781-1-gitster@pobox.com> (raw)
In-Reply-To: <20200908205224.4126551-1-gitster@pobox.com>

Here is an update, after seeing Peff's review.

The overall structure of the series stays the same.

 * The second patch lost an incorrect use of 'flags' parameter down
   to quote_c_style_counted() from quote_path().  In the function
   declaration of quote_path(), the flags parameter is now named.

 * The third patch that moves the "optionally quote path with SP in
   it" logic to quote_path() is essentialy unchanged.

 * But the fourth patch rewrites the implementation to avoid
   shifting the output bytes with insertstr().

 * The fifth patch (formerly the fourth) that teachs "status --short"
   to consistently quote hasn't changed, except that we test also
   for the ignored paths.

 * The last two patches are unchanged.  They are optional clean-ups
   that are not required.

We might want to add a bit more tests for:

 - how conflicted "funny" paths are shown.

 - how doubly funny paths (those that quote_c_style_counted() needs
   to use backslash quoting *and* that contain SP) are shown.

but I'd say that is outside the scope of this round.  Seeing what is
done in t3300, the latter test cannot be written portably as far as
I can tell.


Junio C Hamano (7):
  quote_path: rename quote_path_relative() to quote_path()
  quote_path: give flags parameter to quote_path()
  quote_path: optionally allow quoting a path with SP in it
  quote_path: code clarification
  wt-status: consistently quote paths in "status --short" output
  quote: rename misnamed sq_lookup[] to cq_lookup[]
  quote: turn 'nodq' parameter into a set of flags

 builtin/clean.c   | 22 +++++++++++-----------
 builtin/grep.c    |  2 +-
 diff.c            |  8 ++++----
 quote.c           | 47 +++++++++++++++++++++++++++++++----------------
 quote.h           | 11 +++++++----
 t/t7508-status.sh | 27 +++++++++++++++++++++++++++
 wt-status.c       | 37 +++++++++++++------------------------
 7 files changed, 94 insertions(+), 60 deletions(-)

Range-diff against v1:
1:  a9306429f4 = 1:  a9306429f4 quote_path: rename quote_path_relative() to quote_path()
2:  c2784628a4 ! 2:  179d12d16f quote_path: give flags parameter to quote_path()
    @@ quote.c: void write_name_quoted_relative(const char *name, const char *prefix,
      {
      	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;
     
      ## quote.h ##
     @@ quote.h: void write_name_quoted_relative(const char *name, const char *prefix,
    @@ quote.h: 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);
    ++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);
3:  640673148e ! 3:  d566c38d2f quote_path: optionally allow quoting a path with SP in it
    @@ Commit message
     
      ## quote.c ##
     @@ quote.c: 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);
    + 	quote_c_style_counted(rel, strlen(rel), out, NULL, 0);
      	strbuf_release(&sb);
      
     +	if ((flags & QUOTE_PATH_QUOTE_SP) &&
    @@ quote.h
     @@ quote.h: 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);
    + 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 */
-:  ---------- > 4:  f3769b7cf4 quote_path: code clarification
4:  ac9a0c4a33 ! 5:  498bed71e4 wt-status: consistently quote paths in "status --short" output
    @@ Commit message
         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.
    +    paths by brian m. carlson, with similar tests added for 'ignored'
    +    ones.
     
         Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
    @@ t/t7508-status.sh: 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
    ++	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' '
5:  57c6294695 = 6:  e74186bbd7 quote: rename misnamed sq_lookup[] to cq_lookup[]
6:  480152cfe4 ! 7:  d87d7dd561 quote: turn 'nodq' parameter into a set of flags
    @@ quote.c: static size_t quote_c_style_counted(const char *name, ssize_t maxlen,
      		if (!nodq)
      			strbuf_addch(sb, '"');
      	} else {
    +@@ quote.c: 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);
     
      ## quote.h ##
     @@ quote.h: struct strvec;
-- 
2.28.0-603-ga98dad7d4d


  parent reply	other threads:[~2020-09-10 17:03 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-08  0:28 [Bug report] git status doesn't escape paths of untracked files Patrick Fong
2020-09-08  1:13 ` Junio C Hamano
2020-09-08  1:17 ` brian m. carlson
2020-09-08  1:30   ` Junio C Hamano
2020-09-08  4:41     ` Junio C Hamano
2020-09-08 17:39     ` Junio C Hamano
2020-09-08 19:01       ` Martin Ågren
2020-09-08 21:06       ` René Scharfe
2020-09-09 22:22         ` Junio C Hamano
2020-09-10 14:23           ` René Scharfe
2020-09-10 15:28             ` Junio C Hamano
2020-09-08  1:30 ` [PATCH] wt-status: quote paths identically whether tracked or untracked brian m. carlson
2020-09-08 20:52   ` [PATCH 0/6] quote_path() clean-ups Junio C Hamano
2020-09-08 20:52     ` [PATCH 1/6] quote_path: rename quote_path_relative() to quote_path() Junio C Hamano
2020-09-08 20:52     ` [PATCH 2/6] quote_path: give flags parameter " Junio C Hamano
2020-09-10 12:21       ` Jeff King
2020-09-10 15:04         ` Junio C Hamano
2020-09-10 15:17           ` Junio C Hamano
2020-09-10 20:26             ` Jeff King
2020-09-08 20:52     ` [PATCH 3/6] quote_path: optionally allow quoting a path with SP in it Junio C Hamano
2020-09-10 12:35       ` Jeff King
2020-09-08 20:52     ` [PATCH 4/6] wt-status: consistently quote paths in "status --short" output Junio C Hamano
2020-09-08 20:52     ` [PATCH 5/6] quote: rename misnamed sq_lookup[] to cq_lookup[] Junio C Hamano
2020-09-08 20:52     ` [PATCH 6/6] quote: turn 'nodq' parameter into a set of flags Junio C Hamano
2020-09-10 12:38       ` Jeff King
2020-09-08 22:56     ` [PATCH 0/6] quote_path() clean-ups Chris Torek
2020-09-10 12:39     ` Jeff King
2020-09-10 17:01     ` Junio C Hamano [this message]
2020-09-10 17:01       ` [PATCH v2 1/7] quote_path: rename quote_path_relative() to quote_path() Junio C Hamano
2020-09-10 17:01       ` [PATCH v2 2/7] quote_path: give flags parameter " Junio C Hamano
2020-09-10 17:01       ` [PATCH v2 3/7] quote_path: optionally allow quoting a path with SP in it Junio C Hamano
2020-09-10 17:01       ` [PATCH v2 4/7] quote_path: code clarification Junio C Hamano
2020-09-10 18:08         ` Jeff King
2020-09-10 18:40           ` Junio C Hamano
2020-09-10 19:29             ` Jeff King
2020-09-10 17:01       ` [PATCH v2 5/7] wt-status: consistently quote paths in "status --short" output Junio C Hamano
2020-09-10 18:13         ` Jeff King
2020-09-10 18:38           ` Junio C Hamano
2020-09-10 17:01       ` [PATCH v2 6/7] quote: rename misnamed sq_lookup[] to cq_lookup[] Junio C Hamano
2020-09-10 17:01       ` [PATCH v2 7/7] quote: turn 'nodq' parameter into a set of flags Junio C Hamano
2020-09-10 23:03       ` [PATCH v2 0/7] quote_path() clean-ups brian m. carlson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200910170159.1278781-1-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    --cc=peff@peff.net \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).