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 17/19] list-files: add -F/--classify Date: Sun, 30 Nov 2014 15:56:05 +0700 Message-ID: <1417337767-4505-18-git-send-email-pclouds@gmail.com> References: <1417337767-4505-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 Sun Nov 30 09:58: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 1Xv0L4-0003PX-LG for gcvg-git-2@plane.gmane.org; Sun, 30 Nov 2014 09:58:43 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752182AbaK3I6j convert rfc822-to-quoted-printable (ORCPT ); Sun, 30 Nov 2014 03:58:39 -0500 Received: from mail-pd0-f175.google.com ([209.85.192.175]:59544 "EHLO mail-pd0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751982AbaK3I6i (ORCPT ); Sun, 30 Nov 2014 03:58:38 -0500 Received: by mail-pd0-f175.google.com with SMTP id y10so9006111pdj.20 for ; Sun, 30 Nov 2014 00:58:37 -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=vZM2NDt4JdNqCUtT0ViXdyvGuUIhm0T81ZIy/gCTBrI=; b=eXQVdINy4WbcADY4S/nOB8J4z+2fz5pSCz6egHF9PvL6+4hwmOy3php4Bac2mzd4uT Oy5IImpqeqVocemgrRnAgMuH5wV0PFTyqkUGTjAgNFj4wlwkmWQPEalS8N0L4dLsD+C8 rE1wOPWFs505Qe4Nl2/KS5tppuUKZfRWCb5SrFqt/0rWtVDN1oVzby9nqSWCPkKvpVS6 GbI5aTgKgWafj2lpfuKMTvUHp+Qhdc9zWh/M52cf7UV4Ew9pRvBicjnuarMK9waQcVLs 2Yer0zj/7RbPoO5Wig+qmcZNOd5/KH3V3DT8YMmQb4FLNcfLo27xtAlzO42FUCutD6S6 r4wA== X-Received: by 10.70.31.35 with SMTP id x3mr88624050pdh.34.1417337917919; Sun, 30 Nov 2014 00:58:37 -0800 (PST) Received: from lanh ([115.73.247.22]) by mx.google.com with ESMTPSA id zn2sm14323373pbb.41.2014.11.30.00.58.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Nov 2014 00:58:37 -0800 (PST) Received: by lanh (sSMTP sendmail emulation); Sun, 30 Nov 2014 15:58:36 +0700 X-Mailer: git-send-email 2.2.0.60.gb7b3c64 In-Reply-To: <1417337767-4505-1-git-send-email-pclouds@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: This appends an indicator after the file name if it's executable, a directory and so on, like in GNU ls. In fact append_indicator() is a rewrite from get_type_indicator() in coreutils.git commit 7326d1f1a67edf21947ae98194f98c38b6e9e527. Signed-off-by: Nguy=E1=BB=85n Th=C3=A1i Ng=E1=BB=8Dc Duy --- Documentation/git-list-files.txt | 6 ++++++ builtin/ls-files.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/Documentation/git-list-files.txt b/Documentation/git-list-= files.txt index 0ef616b..22084eb 100644 --- a/Documentation/git-list-files.txt +++ b/Documentation/git-list-files.txt @@ -51,6 +51,12 @@ OPTIONS multiple file selections. See linkgit::git-ls-files[1] option `-t` for more information. =20 +-F:: +--classify:: + Append indicator (one of `*/=3D>@|`, which is executable, + directory, socket, Solaris door, symlink, or fifo + respectively) to entries. + -R:: --recursive:: Equivalent of `--max-depth=3D-1` (infinite recursion). diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 41efdaa..28737cb 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -29,6 +29,7 @@ static int show_killed; static int show_valid_bit; static int show_tag; static int show_dirs; +static int show_indicator; static int line_terminator =3D '\n'; static int debug_mode; static int use_color; @@ -77,6 +78,28 @@ static void write_name(struct strbuf *sb, const char= *name) quote_path_relative(name, real_prefix, sb); } =20 +static void append_indicator(struct strbuf *sb, mode_t mode) +{ + char c =3D 0; + if (S_ISREG(mode)) { + if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) + c =3D '*'; + } else if (S_ISDIR(mode)) + c =3D '/'; + else if (S_ISLNK(mode)) + c =3D '@'; + else if (S_ISFIFO(mode)) + c =3D '|'; + else if (S_ISSOCK(mode)) + c =3D '=3D'; +#ifdef S_ISDOOR + else if (S_ISDOOR(mode)) + c =3D '>'; +#endif + if (c) + strbuf_addch(sb, c); +} + static void strbuf_fputs(struct strbuf *sb, const char *full_name, FIL= E *fp) { if (column_active(colopts) || porcelain) { @@ -99,6 +122,8 @@ static void write_dir_entry(struct strbuf *sb, const= struct dir_entry *ent) color_filename(sb, ent->name, quoted.buf, st.st_mode, 1); else strbuf_addbuf(sb, "ed); + if (show_indicator && st.st_mode) + append_indicator(sb, st.st_mode); strbuf_addch(sb, line_terminator); strbuf_release("ed); } @@ -189,6 +214,8 @@ static void write_ce_name(struct strbuf *sb, const = struct cache_entry *ce) color_filename(sb, ce->name, quoted.buf, ce->ce_mode, 1); else strbuf_addbuf(sb, "ed); + if (show_indicator) + append_indicator(sb, ce->ce_mode); strbuf_addch(sb, line_terminator); strbuf_release("ed); } @@ -366,6 +393,8 @@ static void show_directories(const struct cache_ent= ry *ce) } if (show_tag) strbuf_insert(&sb2, 0, tag_cached, strlen(tag_cached)); + if (show_indicator) + append_indicator(&sb2, S_IFDIR); last_directory =3D strbuf_detach(&sb, NULL); strbuf_fputs(&sb2, last_directory, NULL); strbuf_release(&sb2); @@ -701,6 +730,8 @@ int cmd_ls_files(int argc, const char **argv, const= char *cmd_prefix) DIR_SHOW_IGNORED), OPT_BOOL('u', "unmerged", &show_unmerged, N_("show unmerged files")), + OPT_BOOL('F', "classify", &show_indicator, + N_("append indicator (one of */=3D>@|) to entries")), OPT__COLOR(&use_color, N_("show color")), OPT_COLUMN(0, "column", &colopts, N_("show files in columns")), OPT_SET_INT('1', NULL, &colopts, --=20 2.2.0.60.gb7b3c64