compat: introduce on_disk_bytes()
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 files occupy on-disk, so give a helper function in git-compat-util.h to compute this value. Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Johannes Sixt <johannes.sixt@telecom.at>
Junio C Hamano committed
Aug 18, 2008 at 21:57 UTC
fdb2a2a600969598fd80f01b009fbbb020d596ab
5 files changed
+15
-11
Makefile
+7
@@ -124,6 +124,9 @@ all::
124
# Define USE_STDEV below if you want git to care about the underlying device
125
# change being considered an inode change from the update-index perspective.
126
#
127
+# Define NO_ST_BLOCKS_IN_STRUCT_STAT if your platform does not have st_blocks
128
+# field that counts the on-disk footprint in 512-byte blocks.
129
+#
130
# Define ASCIIDOC8 if you want to format documentation with AsciiDoc 8
131
#
132
# 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)))
752
NO_SVN_TESTS = YesPlease
753
NO_PERL_MAKEMAKER = YesPlease
754
NO_POSIX_ONLY_PROGRAMS = YesPlease
755
+ NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
756
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat
757
COMPAT_CFLAGS += -DSNPRINTF_SIZE_CORR=1
758
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
@@ -863,6 +867,9 @@ endif
867
ifdef NO_D_INO_IN_DIRENT
868
BASIC_CFLAGS += -DNO_D_INO_IN_DIRENT
869
endif
870
+ifdef NO_ST_BLOCKS_IN_STRUCT_STAT
871
+ BASIC_CFLAGS += -DNO_ST_BLOCKS_IN_STRUCT_STAT
872
+endif
873
ifdef NO_C99_FORMAT
874
BASIC_CFLAGS += -DNO_C99_FORMAT
875
endif
builtin-count-objects.c
+2
-2
@@ -43,7 +43,7 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
43
if (lstat(path, &st) || !S_ISREG(st.st_mode))
44
bad = 1;
45
else
46
- (*loose_size) += xsize_t(st.st_blocks);
46
+ (*loose_size) += xsize_t(on_disk_bytes(st));
47
}
48
if (bad) {
49
if (verbose) {
@@ -115,7 +115,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
115
num_pack++;
116
}
117
printf("count: %lu\n", loose);
118
- printf("size: %lu\n", loose_size / 2);
118
+ printf("size: %lu\n", loose_size / 1024);
119
printf("in-pack: %lu\n", packed);
120
printf("packs: %lu\n", num_pack);
121
printf("prune-packable: %lu\n", packed_loose);
compat/mingw.c
-8
@@ -31,11 +31,6 @@ static inline time_t filetime_to_time_t(const FILETIME *ft)
31
return (time_t)winTime;
32
}
33
34
-static inline size_t size_to_blocks(size_t s)
35
-{
36
- return (s+511)/512;
37
-}
38
-
34
extern int _getdrive( void );
35
/* We keep the do_lstat code in a separate function to avoid recursion.
36
* When a path ends with a slash, the stat will fail with ENOENT. In
@@ -59,7 +54,6 @@ static int do_lstat(const char *file_name, struct stat *buf)
54
buf->st_uid = 0;
55
buf->st_mode = fMode;
56
buf->st_size = fdata.nFileSizeLow; /* Can't use nFileSizeHigh, since it's not a stat64 */
62
- buf->st_blocks = size_to_blocks(buf->st_size);
57
buf->st_dev = _getdrive() - 1;
58
buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
59
buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
@@ -142,7 +136,6 @@ int mingw_fstat(int fd, struct mingw_stat *buf)
136
buf->st_uid = st.st_uid;
137
buf->st_mode = st.st_mode;
138
buf->st_size = st.st_size;
145
- buf->st_blocks = size_to_blocks(buf->st_size);
139
buf->st_dev = st.st_dev;
140
buf->st_atime = st.st_atime;
141
buf->st_mtime = st.st_mtime;
@@ -164,7 +157,6 @@ int mingw_fstat(int fd, struct mingw_stat *buf)
157
buf->st_uid = 0;
158
buf->st_mode = fMode;
159
buf->st_size = fdata.nFileSizeLow; /* Can't use nFileSizeHigh, since it's not a stat64 */
167
- buf->st_blocks = size_to_blocks(buf->st_size);
160
buf->st_dev = _getdrive() - 1;
161
buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
162
buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
compat/mingw.h
-1
@@ -169,7 +169,6 @@ struct mingw_stat {
169
time_t st_mtime, st_atime, st_ctime;
170
unsigned st_dev, st_ino, st_uid, st_gid;
171
size_t st_size;
172
- size_t st_blocks;
172
};
173
int mingw_lstat(const char *file_name, struct mingw_stat *buf);
174
int mingw_fstat(int fd, struct mingw_stat *buf);
git-compat-util.h
+6
@@ -192,6 +192,12 @@ extern int git_munmap(void *start, size_t length);
192
193
#endif /* NO_MMAP */
194
195
+#ifdef NO_ST_BLOCKS_IN_STRUCT_STAT
196
+#define on_disk_bytes(st) ((st).st_size)
197
+#else
198
+#define on_disk_bytes(st) ((st).st_blocks * 512)
199
+#endif
200
+
201
#define DEFAULT_PACKED_GIT_LIMIT \
202
((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256))
203