From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Subject: [PATCH 3/3] ls-tree: remove path filtering logic in show_tree Date: Sat, 8 Nov 2014 18:00:32 +0700 Message-ID: <1415444432-18596-3-git-send-email-pclouds@gmail.com> References: <1415444432-18596-1-git-send-email-pclouds@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Sat Nov 08 12:00:43 2014 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Xn3l3-0006CW-GQ for gcvg-git-2@plane.gmane.org; Sat, 08 Nov 2014 12:00:41 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753727AbaKHLAc convert rfc822-to-quoted-printable (ORCPT ); Sat, 8 Nov 2014 06:00:32 -0500 Received: from mail-pa0-f53.google.com ([209.85.220.53]:57580 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753684AbaKHLAa (ORCPT ); Sat, 8 Nov 2014 06:00:30 -0500 Received: by mail-pa0-f53.google.com with SMTP id kx10so5151090pab.12 for ; Sat, 08 Nov 2014 03:00:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=m913l9ZRXNTqERML9bOR4TUztcHymsz/EIDyKGbyZkk=; b=rvhchHIKb4+P76fpK31TmcKdPY/8vt1gPzwlixBAcljVbCA5A7KCMR1eaX4Kun2OmE T97P1+AqWvCc7lFCTjsx3c6ujdlcgNA3eKFNM2cNLNTd9ywCEyjOVATCz8FRkJxmOnUr aXFWqyefcZby/1HaTZxbpX9avqgIjdJXS8O3J0kGTZiORRY253DSMaWCUSpJlN0g8gzG Xy9Y7qNKUxV4KtobJwlk5SKUBe9daqbfph3a5kroqEHEvnZmrZ2svM/HPyQcjUgAtmle W/Fhaxu5+KOds1JBbcLGUMCJ9N8sMbEL2KNBmfP8s4H8nWOEciwW4SECeAPfE/j/vqRo k9dQ== X-Received: by 10.66.182.200 with SMTP id eg8mr18708580pac.53.1415444429553; Sat, 08 Nov 2014 03:00:29 -0800 (PST) Received: from lanh ([115.73.197.54]) by mx.google.com with ESMTPSA id f12sm11146467pdl.94.2014.11.08.03.00.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Nov 2014 03:00:29 -0800 (PST) Received: by lanh (sSMTP sendmail emulation); Sat, 08 Nov 2014 18:00:43 +0700 X-Mailer: git-send-email 2.1.0.rc0.78.gc0d8480 In-Reply-To: <1415444432-18596-1-git-send-email-pclouds@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ls-tree uses read_tree_recursive() which already does path filtering using pathspec. No need to filter one more time based on prefix only. "ls-tree ../somewhere" does not work because of this. write_name_quotedpfx() can now be retired because nobody else uses it. Signed-off-by: Nguy=E1=BB=85n Th=C3=A1i Ng=E1=BB=8Dc Duy --- builtin/ls-tree.c | 14 +++++++------- quote.c | 21 --------------------- quote.h | 2 -- t/t3102-ls-tree-wildcards.sh | 8 ++++++++ 4 files changed, 15 insertions(+), 30 deletions(-) diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index d226344..3b04a0f 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -65,6 +65,7 @@ static int show_tree(const unsigned char *sha1, struc= t strbuf *base, const char *pathname, unsigned mode, int stage, void *context) { int retval =3D 0; + int baselen; const char *type =3D blob_type; =20 if (S_ISGITLINK(mode)) { @@ -89,11 +90,6 @@ static int show_tree(const unsigned char *sha1, stru= ct strbuf *base, else if (ls_options & LS_TREE_ONLY) return 0; =20 - if (chomp_prefix && - (base->len < chomp_prefix || - memcmp(ls_tree_prefix, base->buf, chomp_prefix))) - return 0; - if (!(ls_options & LS_NAME_ONLY)) { if (ls_options & LS_SHOW_SIZE) { char size_text[24]; @@ -113,8 +109,12 @@ static int show_tree(const unsigned char *sha1, st= ruct strbuf *base, printf("%06o %s %s\t", mode, type, find_unique_abbrev(sha1, abbrev)); } - write_name_quotedpfx(base->buf + chomp_prefix, base->len - chomp_pref= ix, - pathname, stdout, line_termination); + baselen =3D base->len; + strbuf_addstr(base, pathname); + write_name_quoted_relative(base->buf, + chomp_prefix ? ls_tree_prefix : NULL, + stdout, line_termination); + strbuf_setlen(base, baselen); return retval; } =20 diff --git a/quote.c b/quote.c index 45e3db1..7920e18 100644 --- a/quote.c +++ b/quote.c @@ -274,27 +274,6 @@ void write_name_quoted(const char *name, FILE *fp,= int terminator) fputc(terminator, fp); } =20 -void write_name_quotedpfx(const char *pfx, size_t pfxlen, - const char *name, FILE *fp, int terminator) -{ - int needquote =3D 0; - - if (terminator) { - needquote =3D next_quote_pos(pfx, pfxlen) < pfxlen - || name[next_quote_pos(name, -1)]; - } - if (needquote) { - fputc('"', fp); - quote_c_style_counted(pfx, pfxlen, NULL, fp, 1); - quote_c_style(name, NULL, fp, 1); - fputc('"', fp); - } else { - fwrite(pfx, pfxlen, 1, fp); - fputs(name, fp); - } - fputc(terminator, fp); -} - void write_name_quoted_relative(const char *name, const char *prefix, FILE *fp, int terminator) { diff --git a/quote.h b/quote.h index 71dcc3a..99e04d3 100644 --- a/quote.h +++ b/quote.h @@ -56,8 +56,6 @@ extern size_t quote_c_style(const char *name, struct = strbuf *, FILE *, int no_dq extern void quote_two_c_style(struct strbuf *, const char *, const cha= r *, int); =20 extern void write_name_quoted(const char *name, FILE *, int terminator= ); -extern void write_name_quotedpfx(const char *pfx, size_t pfxlen, - const char *name, FILE *, int termina= tor); extern void write_name_quoted_relative(const char *name, const char *p= refix, FILE *fp, int terminator); =20 diff --git a/t/t3102-ls-tree-wildcards.sh b/t/t3102-ls-tree-wildcards.s= h index c286854..83fca8d 100755 --- a/t/t3102-ls-tree-wildcards.sh +++ b/t/t3102-ls-tree-wildcards.sh @@ -19,4 +19,12 @@ EOF test_cmp expected actual ' =20 +test_expect_success 'ls-tree outside prefix' ' + cat >expected <actual && + test_cmp expected actual +' + test_done --=20 2.1.0.rc0.78.gc0d8480