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

Re: [PATCH] compat: introduce stat_to_kilobytes

From
Andreas Färber <andreas.faerber@web.de>
Date
Aug 17, 2008, 17:27 UTC
Message-ID
<24873933-3075-408F-9FF7-273F97CB82E6@web.de>
In-Reply-To
<7vy72w6kiv.fsf@gitster.siamese.dyndns.org>
Am 17.08.2008 um 11:47 schrieb Junio C Hamano:
Show 21 quoted lines
> Some platforms do not have st_blocks member in "struct stat"; mingw
> already emulates it by rounding it up to closest 512-byte blocks (even
> though it could overcount when a file has holes).
>
> The reason to use the member is only to figure out how many  
> kilobytes the
> file occupies on-disk, so give a helper in git-compat-util.h to help  
> these
> platforms.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>
> * I suspect you may be better off building on top of something like
>   this.
>
>   The comment before "struct mingw_stat" suggests that the only reason
>   this compatiblity definition exists is to add st_blocks member, so I
>   suspect we could remove the definition and simplify the  
> compatibility
>   layer a lot more, but I do not know MinGW, so I am CC'ing j6t here.
[...]
Show 26 quoted lines
> diff --git a/Makefile b/Makefile
> index 53ab4b5..8f69f16 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -124,6 +124,9 @@ all::
> # Define USE_STDEV below if you want git to care about the  
> underlying device
> # change being considered an inode change from the update-index  
> perspective.
> #
> +# Define NO_ST_BLOCKS_IN_STRUCT_STAT if your platform does not have  
> st_blocks
> +# field that counts the on-disk footprint in 512-byte blocks.
> +#
> # Define ASCIIDOC8 if you want to format documentation with AsciiDoc 8
> #
> # Define DOCBOOK_XSL_172 if you want to format man pages with  
> DocBook XSL v1.72.
> @@ -749,6 +752,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
> 	NO_SVN_TESTS = YesPlease
> 	NO_PERL_MAKEMAKER = YesPlease
> 	NO_POSIX_ONLY_PROGRAMS = YesPlease
> +	NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
> 	COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat
> 	COMPAT_CFLAGS += -DSNPRINTF_SIZE_CORR=1
> 	COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"

What's missing in this one is the translation from Makefile variable to preprocessor define:

ifdef NO_ST_BLOCKS_IN_STRUCT_STAT
	BASIC_CFLAGS += -DNO_ST_BLOCKS_IN_STRUCT_STAT
endif
for this to work:
Show 15 quoted lines
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -192,6 +192,12 @@ extern int git_munmap(void *start, size_t  
> length);
>
> #endif /* NO_MMAP */
>
> +#ifdef NO_ST_BLOCKS_IN_STRUCT_STAT
> +#define stat_to_kilobytes(st) ((((st).st_size+511) / 512) / 2)
> +#else
> +#define stat_to_kilobytes(st) ((st).st_blocks / 2)
> +#endif
> +
> #define DEFAULT_PACKED_GIT_LIMIT \
> 	((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256))
Andreas
Previous: Junio C HamanoNext: Johannes Sixt
Message 4 of 10 in “Don't use struct stat's st_blocks member on Haiku”
  1. 4/6 Don't use struct stat's st_blocks member on HaikuAndreas Färber, Aug 17, 2008
  2. Jakub NarebskiAug 17, 2008
  3. compat: introduce stat_to_kilobytesJunio C Hamano, Aug 17, 2008
  4. Andreas FärberAug 17, 2008
  5. 1/2 compat: introduce stat_to_kilobytesJohannes Sixt, Aug 18, 2008
  6. 2/2 Revert "Windows: Use a customized struct stat that also has the st_blocks member."Johannes Sixt, Aug 18, 2008
  7. Junio C HamanoAug 18, 2008
  8. Junio C HamanoAug 18, 2008
  9. Junio C HamanoAug 19, 2008
  10. Andreas FärberAug 19, 2008

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.