From: Junio C Hamano <gitster@pobox.com>
To: Pierre Habouzit <madcoder@debian.org>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 4/5] Full rework of quote_c_style and write_name_quoted.
Date: Wed, 19 Sep 2007 01:28:47 -0700 [thread overview]
Message-ID: <7v1wcvqcsg.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <20070918224122.2B55D344AB3@madism.org> (Pierre Habouzit's message of "Wed, 19 Sep 2007 00:00:51 +0200")
Pierre Habouzit <madcoder@debian.org> writes:
> ...
> Signed-off-by: Pierre Habouzit <madcoder@debian.org>
> ---
> builtin-apply.c | 83 +++++--------
> builtin-blame.c | 3 +-
> builtin-check-attr.c | 2 +-
> builtin-checkout-index.c | 4 +-
> builtin-ls-files.c | 13 +--
> builtin-ls-tree.c | 6 +-
> combine-diff.c | 16 +--
> diff.c | 303 +++++++++++++++++-----------------------------
> quote.c | 198 +++++++++++++++++-------------
> quote.h | 8 +-
> 10 files changed, 268 insertions(+), 368 deletions(-)
> ...
> diff --git a/builtin-apply.c b/builtin-apply.c
> index cffbe52..0328863 100644
> --- a/builtin-apply.c
> +++ b/builtin-apply.c
> @@ -1378,61 +1377,50 @@ static const char minuses[]= "--------------------------------------------------
>
> static void show_stats(struct patch *patch)
> {
> - const char *prefix = "";
> - char *name = patch->new_name;
> - char *qname = NULL;
> - int len, max, add, del, total;
> -
> - if (!name)
> - name = patch->old_name;
> + struct strbuf qname;
> + char *cp = patch->new_name ? patch->new_name : patch->old_name;
> + int max, add, del;
>
> - if (0 < (len = quote_c_style(name, NULL, NULL, 0))) {
> - qname = xmalloc(len + 1);
> - quote_c_style(name, qname, NULL, 0);
> - name = qname;
> - }
> + strbuf_init(&qname, 0);
> + quote_c_style(cp, &qname, NULL, 0);
>
> /*
> * "scale" the filename
> */
> - len = strlen(name);
> max = max_len;
> if (max > 50)
> max = 50;
> - if (len > max) {
> - char *slash;
> - prefix = "...";
> - max -= 3;
> - name += len - max;
> - slash = strchr(name, '/');
> - if (slash)
> - name = slash;
> +
> + if (qname.len > max) {
> + cp = strchr(qname.buf + qname.len + 3 - max, '/');
> + if (cp)
> + cp = qname.buf + qname.len + 3 - max;
> + strbuf_splice(&qname, 0, cp - qname.buf, "...", 3);
> + }
At this point, you have max that is larger by 3 than what old
code had. That would make the next two printf() you added as
expected. This affects scaling of add/delete code. Is this
intentional? I _think_ the change is correct (there is no
reason that name display being cliped should affect the length
of the bar graph), but that should have been documented as a
separate bugfix in the commit log.
> diff --git a/quote.c b/quote.c
> index 67c6527..a8a755a 100644
> --- a/quote.c
> +++ b/quote.c
> @@ -114,83 +114,142 @@ char *sq_dequote(char *arg)
> }
> }
>
> +/* 1 means: quote as octal
> + * 0 means: quote as octal if (quote_path_fully)
> + * -1 means: never quote
> + * c: quote as "\\c"
> + */
> +#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] = {
> + /* 0 1 2 3 4 5 6 7 */
> + /* 0x00 */ 1, 1, 1, 1, 1, 1, 'a', 1,
Isn't BEL == 0x07, not 0x06?
> + /* 0x08 */ 'b', 't', 'n', 'v', 'f', 'r', 1, 1,
> + /* 0x10 */ X16(1),
> + /* 0x20 */ -1, -1, '"', -1, -1, -1, -1, -1,
> + /* 0x28 */ X16(-1), X16(-1), X16(-1),
> + /* 0x58 */ -1, -1, -1, -1,'\\', -1, -1, -1,
> + /* 0x60 */ X16(-1), X16(-1),
Shouldn't you quote DEL == 0177 here?
> + /* 0x80 */ /* set to 0 */
> +};
> +
> +static inline int sq_must_quote(char c) {
> + return sq_lookup[(unsigned char)c] + quote_path_fully > 0;
> +}
> +
> +/* returns the longest prefix not needing a quote up to maxlen if positive.
> + This stops at the first \0 because it's marked as a character needing an
> + escape */
> +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++);
> + } else {
> + for (len = 0; len < maxlen && !sq_must_quote(s[len]); len++);
> + }
> + return len;
> +}
> +
> /*
> * C-style name quoting.
> *
> - * Does one of three things:
> - *
> * (1) if outbuf and outfp are both NULL, inspect the input name and
> * counts the number of bytes that are needed to hold c_style
> * quoted version of name, counting the double quotes around
> * it but not terminating NUL, and returns it. However, if name
> * does not need c_style quoting, it returns 0.
> *
You need to update this comment; you do not have outbuf nor
outfp anymore, you have something else.
next prev parent reply other threads:[~2007-09-19 8:28 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-18 22:39 let's refactor quoting Pierre Habouzit
2007-09-18 17:18 ` [PATCH 1/5] strbuf API additions and enhancements Pierre Habouzit
2007-09-19 12:46 ` Edgar Toernig
2007-09-19 13:36 ` Pierre Habouzit
2007-09-19 18:46 ` Junio C Hamano
2007-09-20 6:17 ` Johannes Sixt
2007-09-20 7:20 ` Kalle Olavi Niemitalo
2007-09-20 16:10 ` Jeff King
2007-09-18 20:15 ` [PATCH 2/5] sq_quote_argv and add_to_string rework with strbuf's Pierre Habouzit
2007-09-19 8:09 ` Junio C Hamano
2007-09-19 8:23 ` Pierre Habouzit
2007-09-18 21:22 ` [PATCH 3/5] Rework unquote_c_style to work on a strbuf Pierre Habouzit
2007-09-19 0:14 ` Pierre Habouzit
2007-09-19 8:09 ` Junio C Hamano
2007-09-19 8:22 ` Pierre Habouzit
2007-09-18 21:48 ` [PATCH 5/5] Avoid duplicating memory, and use xmemdupz instead of xstrdup Pierre Habouzit
2007-09-18 22:00 ` [PATCH 4/5] Full rework of quote_c_style and write_name_quoted Pierre Habouzit
2007-09-19 0:07 ` Pierre Habouzit
2007-09-19 0:55 ` Junio C Hamano
2007-09-19 1:14 ` Pierre Habouzit
2007-09-19 6:37 ` Andreas Ericsson
2007-09-19 8:00 ` Pierre Habouzit
2007-09-19 8:08 ` Andreas Ericsson
2007-09-19 8:21 ` Pierre Habouzit
2007-09-19 8:28 ` David Kastrup
2007-09-19 8:31 ` Junio C Hamano
2007-09-19 8:38 ` David Kastrup
2007-09-19 8:28 ` Junio C Hamano [this message]
2007-09-19 8:47 ` Pierre Habouzit
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=7v1wcvqcsg.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=madcoder@debian.org \
/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).