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

Re: [PATCH 2/2] count-objects: report garbage files in .git/objects/pack directory too

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 4, 2013, 18:16 UTC
Message-ID
<7v1ucw2bd4.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1359982145-10792-2-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 30 quoted lines
> @@ -1024,11 +1035,15 @@ static void prepare_packed_git_one(char *objdir, int local)
>  		int namelen = strlen(de->d_name);
>  		struct packed_git *p;
>  
> -		if (!has_extension(de->d_name, ".idx"))
> +		if (!has_extension(de->d_name, ".idx")) {
> +			report_pack_garbage(path, len - 1, de->d_name);
>  			continue;
> +		}
>  
> -		if (len + namelen + 1 > sizeof(path))
> +		if (len + namelen + 1 > sizeof(path)) {
> +			report_pack_garbage(path, len - 1, de->d_name);
>  			continue;
> +		}
>  
>  		/* Don't reopen a pack we already have. */
>  		strcpy(path + len, de->d_name);
> @@ -1042,8 +1057,10 @@ static void prepare_packed_git_one(char *objdir, int local)
>  		 * .pack file that we can map.
>  		 */
>  		p = add_packed_git(path, len + namelen, local);
> -		if (!p)
> +		if (!p) {
> +			report_pack_garbage(path, len - 1, de->d_name);
>  			continue;
> +		}
>  		install_packed_git(p);
>  	}
>  	closedir(dir);

I forgot to mention one more thing. Your report_pack_garbage() special cases ".pack" to see if it is a regular file, but this loop structure causes a regular file whose name ends with ".pack" but without corresponding ".idx" file to go unreported.

I think the loop should be restructured to iterate over all known file types and report unknown ones, if you want to repurpose it for the reporting, something along this line, perhaps:

	for (each name) {
		if (does it end with ".idx") {
			if (is it unusable ".idx") {
				report garbage;
			}
                        continue;
		}
		if (! we are in report mode)
			continue;
		if (does it end with ".pack") {
			if (!have we seen corresponding ".idx")
				remember it;
			continue;
		}
		report garbage;
	}
	for (remembered pack) {
		if (does it have corresponding ".idx" &&
			is it really usable ".pack")
			continue;
		report garbage;
	}
Previous: Junio C HamanoNext: Duy Nguyen
Message 4 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.