git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 3/3] count-objects: report how much disk space taken by garbage files

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 8, 2013, 18:47 UTC
Message-ID
<7vsj561w3g.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1360295307-5469-4-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  We may do some redundant stat() here, but I don't think it can slow
>  count-objects down much to worry about.
I don't either.  Looks like a good change to me.

It appears that the sb.buf refactoring is better done to the previous patch, but that is minor.

Show 91 quoted lines
>  Documentation/git-count-objects.txt |  2 ++
>  builtin/count-objects.c             | 29 ++++++++++++++++++-----------
>  2 files changed, 20 insertions(+), 11 deletions(-)
>
> diff --git a/Documentation/git-count-objects.txt b/Documentation/git-count-objects.txt
> index 1611d7c..da6e72e 100644
> --- a/Documentation/git-count-objects.txt
> +++ b/Documentation/git-count-objects.txt
> @@ -35,6 +35,8 @@ the packs. These objects could be pruned using `git prune-packed`.
>  +
>  garbage: the number of files in object database that are not valid
>  loose objects nor valid packs
> ++
> +size-garbage: disk space consumed by garbage files, in KiB
>  
>  GIT
>  ---
> diff --git a/builtin/count-objects.c b/builtin/count-objects.c
> index 118b2ae..90d476d 100644
> --- a/builtin/count-objects.c
> +++ b/builtin/count-objects.c
> @@ -10,24 +10,33 @@
>  #include "parse-options.h"
>  
>  static unsigned long garbage;
> +static off_t size_garbage;
>  
>  extern void (*report_pack_garbage)(const char *path, int len, const char *name);
>  static void real_report_pack_garbage(const char *path, int len, const char *name)
>  {
> +	struct strbuf sb = STRBUF_INIT;
> +	struct stat st;
> +
>  	if (len && name)
> -		error("garbage found: %.*s/%s", len, path, name);
> +		strbuf_addf(&sb, "%.*s/%s", len, path, name);
>  	else if (!len && name)
> -		error("garbage found: %s%s", path, name);
> +		strbuf_addf(&sb, "%s%s", path, name);
>  	else
> -		error("garbage found: %s", path);
> +		strbuf_addf(&sb, "%s", path);
> +	error(_("garbage found: %s"), sb.buf);
> +
> +	if (!stat(sb.buf, &st))
> +		size_garbage += st.st_size;
> +
>  	garbage++;
> +	strbuf_release(&sb);
>  }
>  
>  static void count_objects(DIR *d, char *path, int len, int verbose,
>  			  unsigned long *loose,
>  			  off_t *loose_size,
> -			  unsigned long *packed_loose,
> -			  unsigned long *garbage)
> +			  unsigned long *packed_loose)
>  {
>  	struct dirent *ent;
>  	while ((ent = readdir(d)) != NULL) {
> @@ -59,11 +68,8 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
>  				(*loose_size) += xsize_t(on_disk_bytes(st));
>  		}
>  		if (bad) {
> -			if (verbose) {
> -				error("garbage found: %.*s/%s",
> -				      len + 2, path, ent->d_name);
> -				(*garbage)++;
> -			}
> +			if (verbose)
> +				report_pack_garbage(path, len + 2, ent->d_name);
>  			continue;
>  		}
>  		(*loose)++;
> @@ -113,7 +119,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
>  		if (!d)
>  			continue;
>  		count_objects(d, path, len, verbose,
> -			      &loose, &loose_size, &packed_loose, &garbage);
> +			      &loose, &loose_size, &packed_loose);
>  		closedir(d);
>  	}
>  	if (verbose) {
> @@ -138,6 +144,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
>  		printf("size-pack: %lu\n", (unsigned long) (size_pack / 1024));
>  		printf("prune-packable: %lu\n", packed_loose);
>  		printf("garbage: %lu\n", garbage);
> +		printf("size-garbage: %lu\n", (unsigned long) (size_garbage / 1024));
>  	}
>  	else
>  		printf("%lu objects, %lu kilobytes\n",
Previous: Nguyễn Thái Ngọc Duy
Message 14 of 14 in “git-count-objects.txt: describe each line in -v output”
  1. 1/2 git-count-objects.txt: describe each line in -v outputNguyễn Thái Ngọc Duy, Feb 4, 2013
  2. 2/2 count-objects: report garbage files in .git/objects/pack directory tooNguyễn Thái Ngọc Duy, Feb 4, 2013
  3. Junio C HamanoFeb 4, 2013
  4. Junio C HamanoFeb 4, 2013
  5. Duy NguyenFeb 7, 2013
  6. Junio C HamanoFeb 7, 2013
  7. Duy NguyenFeb 7, 2013
  8. 0/3 count-objects improvementsNguyễn Thái Ngọc Duy, Feb 8, 2013
  9. 1/3 git-count-objects.txt: describe each line in -v outputNguyễn Thái Ngọc Duy, Feb 8, 2013
  10. 2/3 count-objects: report garbage files in pack directory tooNguyễn Thái Ngọc Duy, Feb 8, 2013
  11. Junio C HamanoFeb 8, 2013
  12. Duy NguyenFeb 9, 2013
  13. 3/3 count-objects: report how much disk space taken by garbage filesNguyễn Thái Ngọc Duy, Feb 8, 2013
  14. Junio C HamanoFeb 8, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.