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 v2 29/32] count-objects: report unused files in $GIT_DIR/worktrees/... Date: Thu, 11 Sep 2014 05:42:05 +0700 Message-ID: <1410388928-32265-30-git-send-email-pclouds@gmail.com> References: <1409387642-24492-1-git-send-email-pclouds@gmail.com> <1410388928-32265-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 Thu Sep 11 00:44:49 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 1XRqd5-0002ZJ-Lj for gcvg-git-2@plane.gmane.org; Thu, 11 Sep 2014 00:44:48 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753430AbaIJWon convert rfc822-to-quoted-printable (ORCPT ); Wed, 10 Sep 2014 18:44:43 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:62076 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753361AbaIJWom (ORCPT ); Wed, 10 Sep 2014 18:44:42 -0400 Received: by mail-pa0-f48.google.com with SMTP id hz1so11244302pad.21 for ; Wed, 10 Sep 2014 15:44:42 -0700 (PDT) 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=vaccOHUUq4V7AtI4jwBD1smTOg+DhZWlydECX1u+KUE=; b=Y2OGah/ISEXbSrjdNJVGy5LAFPIrVksbzTc9QuVnKUK7HRrY4oy+xiXVTjGPdqo/fy xNYbtHZbvuuGiUgcsJ0Mtlo8tId6w7z8XKi9LSetH5eS5uMy1DB5SzfxAuC9FFU0N9ae CvKgpiyRZGnrvZJWhc/4RTnqTo0/Eu9SfApz4TZGmSkwF+qIUXLnBbcPkp1hSI9kbG/D vMJ844tK2kF6c19wnJU07KNlPtI7M04vgXgp9waaP++bTW+yUzf7M1g8J/1RmoLa7vmw MC+5MnB/jcYHQuhfiz63CZ6KjyMalRuwG9LZzWkDIRKESc8iARgtVnnfdft0XgT9PjUZ 9frQ== X-Received: by 10.68.220.228 with SMTP id pz4mr10144433pbc.16.1410389082582; Wed, 10 Sep 2014 15:44:42 -0700 (PDT) Received: from lanh ([115.73.197.210]) by mx.google.com with ESMTPSA id l3sm15619477pdr.17.2014.09.10.15.44.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Sep 2014 15:44:42 -0700 (PDT) Received: by lanh (sSMTP sendmail emulation); Thu, 11 Sep 2014 05:45:02 +0700 X-Mailer: git-send-email 2.1.0.rc0.78.gc0d8480 In-Reply-To: <1410388928-32265-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 bf4d15e..12f0fc0 100644 --- a/cache.h +++ b/cache.h @@ -690,6 +690,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 /* * Return the name of the file in the local object database that would diff --git a/path.c b/path.c index 1fd99f8..d07ae69 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", "/worktrees", "/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 2.1.0.rc0.78.gc0d8480