Re: [PATCH v4 27/27] count-objects: report unused files in $GIT_DIR/repos/...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Mar 1, 2014 at 7:13 AM, Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> wrote:
> 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ễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
> ---
>  builtin/count-objects.c | 37 ++++++++++++++++++++++++++++++++++++-
>  path.c                  |  4 ++++
>  2 files changed, 40 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/count-objects.c b/builtin/count-objects.c
> index a7f70cb..725cd5f 100644
> --- a/builtin/count-objects.c
> +++ b/builtin/count-objects.c
> @@ -78,6 +78,39 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
>         }
>  }
>
> +static void report_linked_checkout_garbage(void)
> +{
> +       /*
> +        * must be more or less in sync with * path.c:update_common_dir().
> +        *
> +        * "logs" is let slip because logs/HEAD is in $GIT_DIR but the
> +        * remaining in $GIT_COMMON_DIR. Probably not worth traversing
> +        * the entire "logs" directory for that.
> +        *
> +        * The same "gc.pid" for because it's a temporary file.
> +        */
> +       const char *list[] = {
> +               "branches", "hooks", "info", "lost-found", "modules",
> +               "objects", "refs", "remotes", "rr-cache", "svn",
> +               "config", "packed-refs", "shallow", NULL
> +       };
> +       struct strbuf sb = STRBUF_INIT;
> +       const char **p;
> +       int len;
> +
> +       if (!file_exists(git_path("commondir")))
> +               return;
> +       strbuf_addf(&sb, "%s/", get_git_dir());
> +       len = sb.len;
> +       for (p = list; *p; p++) {
> +               strbuf_setlen(&sb, len);
> +               strbuf_addstr(&sb, *p);
> +               if (file_exists(sb.buf))
> +                       report_garbage("unused in linked checkout", sb.buf);
> +       }
> +       strbuf_release(&sb);
> +}
> +
>  static char const * const count_objects_usage[] = {
>         N_("git count-objects [-v] [-H | --human-readable]"),
>         NULL
> @@ -102,8 +135,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 = real_report_garbage;
> +               report_linked_checkout_garbage();
> +       }
>         memcpy(path, objdir, len);
>         if (len && objdir[len-1] != '/')
>                 path[len++] = '/';
> diff --git a/path.c b/path.c
> index 47383ff..2e6035d 100644
> --- a/path.c
> +++ b/path.c
> @@ -92,6 +92,10 @@ static void replace_dir(struct strbuf *buf, int len, const char *newdir)
>
>  static void update_common_dir(struct strbuf *buf, int git_dir_len)
>  {
> +       /*
> +        * Remember to report_linked_checkout_garbage()
> +        * builtin/count-objects.c
> +        */

I couldn't figure out why this comment was telling me to remember to
report "linked checkout garbage" until I realized that you omitted the
word "update" (as in "remember to update"). It might be clearer to say
something along these lines:

    Keep synchronized with related list in
    builtin/count-objects.c:report_linked_checkout_garbage().

Is it not possible or just too much of a hassle to maintain this list
in just one place, as in a header which is included by these two
files? The exceptions, such as 'log' and 'gc.pid', could be marked by
a special character in the entry ("!gc.pid", for example) or any such
scheme.

>         const char *common_dir_list[] = {
>                 "branches", "hooks", "info", "logs", "lost-found", "modules",
>                 "objects", "refs", "remotes", "repos", "rr-cache", "svn",
> --
> 1.9.0.40.gaa8c3ea
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]