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 v5 28/28] count-objects: report unused files in $GIT_DIR/repos/... Date: Sat, 8 Mar 2014 09:48:20 +0700 Message-ID: <1394246900-31535-29-git-send-email-pclouds@gmail.com> References: <1393675983-3232-1-git-send-email-pclouds@gmail.com> <1394246900-31535-1-git-send-email-pclouds@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Junio C Hamano , =?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 Mar 08 03:50:48 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 1WM7Lc-0006P0-Bz for gcvg-git-2@plane.gmane.org; Sat, 08 Mar 2014 03:50:48 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753794AbaCHCun convert rfc822-to-quoted-printable (ORCPT ); Fri, 7 Mar 2014 21:50:43 -0500 Received: from mail-pb0-f42.google.com ([209.85.160.42]:56738 "EHLO mail-pb0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753750AbaCHCum (ORCPT ); Fri, 7 Mar 2014 21:50:42 -0500 Received: by mail-pb0-f42.google.com with SMTP id rr13so5008239pbb.1 for ; Fri, 07 Mar 2014 18:50:42 -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=s18gU8j1eDL5lCH0DVYMdKJJaNYsBvx0TKA8LTWFL9I=; b=mCvIvwAb6XCL2SuXabjp11O2aNqg7/MpnUlIfn1IRasrIBOxZsxK8oY6VnwsFLDINM UrSqlLVATgcE3MzzSm4aXE1ujIElyq4sJrfG/1LwcMeDidfxboFe4/meSzfflnS0VQnc PnmD8Mov1vYtl+wfW6p1r+gmZbzE16LFN45X/TPRU+dkHZPzI/qwgm6MYhK5WJSqoK7Q 2RqQkwgIRa7HXNAEr1mLrosnInWoxKZ2/wzxW5m/keMPI0txenkPNRpBrk34GCYAb3om NfmfKYKGe/YUMo7I4Mt2Y7HyVPHGWxwxoLLm0sZbU9EnM29gMbKdaX/fIHUb6+hEmxeS QVxg== X-Received: by 10.67.1.202 with SMTP id bi10mr26495566pad.68.1394247042388; Fri, 07 Mar 2014 18:50:42 -0800 (PST) Received: from lanh ([115.73.205.153]) by mx.google.com with ESMTPSA id g6sm18684784pat.2.2014.03.07.18.50.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 07 Mar 2014 18:50:41 -0800 (PST) Received: by lanh (sSMTP sendmail emulation); Sat, 08 Mar 2014 09:51:15 +0700 X-Mailer: git-send-email 1.9.0.40.gaa8c3ea In-Reply-To: <1394246900-31535-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: In linked checkouts, borrowed parts like config is taken from $GIT_COMMON_DIR. $GIT_DIR/config is never used. Report them as garbage. Signed-off-by: Nguy=E1=BB=85n Th=C3=A1i Ng=E1=BB=8Dc Duy --- builtin/count-objects.c | 4 +++- cache.h | 1 + path.c | 29 +++++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/builtin/count-objects.c b/builtin/count-objects.c index a7f70cb..d3a1620 100644 --- a/builtin/count-objects.c +++ b/builtin/count-objects.c @@ -102,8 +102,10 @@ int cmd_count_objects(int argc, const char **argv,= const char *prefix) /* we do not take arguments other than flags for now */ if (argc) usage_with_options(count_objects_usage, opts); - if (verbose) + if (verbose) { report_garbage =3D real_report_garbage; + report_linked_checkout_garbage(); + } memcpy(path, objdir, len); if (len && objdir[len-1] !=3D '/') path[len++] =3D '/'; diff --git a/cache.h b/cache.h index 979ac6e..a0ff430 100644 --- a/cache.h +++ b/cache.h @@ -662,6 +662,7 @@ extern const char *mkpath(const char *fmt, ...) __a= ttribute__((format (printf, 1 extern const char *git_path(const char *fmt, ...) __attribute__((forma= t (printf, 1, 2))); extern const char *git_path_submodule(const char *path, const char *fm= t, ...) __attribute__((format (printf, 2, 3))); +extern void report_linked_checkout_garbage(void); =20 extern char *sha1_file_name(const unsigned char *sha1); extern char *sha1_pack_name(const unsigned char *sha1); diff --git a/path.c b/path.c index ddb5962..5a7dc45 100644 --- a/path.c +++ b/path.c @@ -4,6 +4,7 @@ #include "cache.h" #include "strbuf.h" #include "string-list.h" +#include "dir.h" =20 static int get_st_mode_bits(const char *path, int *mode) { @@ -91,9 +92,9 @@ static void replace_dir(struct strbuf *buf, int len, = const char *newdir) } =20 static const char *common_list[] =3D { - "/branches", "/hooks", "/info", "/logs", "/lost-found", "/modules", + "/branches", "/hooks", "/info", "!/logs", "/lost-found", "/modules", "/objects", "/refs", "/remotes", "/repos", "/rr-cache", "/svn", - "config", "gc.pid", "packed-refs", "shallow", + "config", "!gc.pid", "packed-refs", "shallow", NULL }; =20 @@ -107,6 +108,8 @@ static void update_common_dir(struct strbuf *buf, i= nt git_dir_len) for (p =3D common_list; *p; p++) { const char *path =3D *p; int is_dir =3D 0; + if (*path =3D=3D '!') + path++; if (*path =3D=3D '/') { path++; is_dir =3D 1; @@ -122,6 +125,28 @@ static void update_common_dir(struct strbuf *buf, = int git_dir_len) } } =20 +void report_linked_checkout_garbage(void) +{ + struct strbuf sb =3D STRBUF_INIT; + const char **p; + int len; + + if (!git_common_dir_env) + return; + strbuf_addf(&sb, "%s/", get_git_dir()); + len =3D sb.len; + for (p =3D common_list; *p; p++) { + const char *path =3D *p; + if (*path =3D=3D '!') + continue; + strbuf_setlen(&sb, len); + strbuf_addstr(&sb, path); + if (file_exists(sb.buf)) + report_garbage("unused in linked checkout", sb.buf); + } + strbuf_release(&sb); +} + static void adjust_git_path(struct strbuf *buf, int git_dir_len) { const char *base =3D buf->buf + git_dir_len; --=20 1.9.0.40.gaa8c3ea