@matheusbsbs / matheus-bagliano / commits / 726f852b0e
Fork 0

deprecate the new loose object header format

Now that we encourage and actively preserve objects in a packed form more agressively than we did at the time the new loose object format and core.legacyheaders were introduced, that extra loose object format doesn't appear to be worth it anymore. Because the packing of loose objects has to go through the delta match loop anyway, and since most of them should end up being deltified in most cases, there is really little advantage to have this parallel loose object format as the CPU savings it might provide is rather lost in the noise in the end. This patch gets rid of core.legacyheaders, preserve the legacy format as the only writable loose object format and deprecate the other one to keep things simpler. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nicolas Pitre committed May 9, 2007 at 14:42 UTC 726f852b0ed7e03e88c419a9996c3815911c9db1
6 files changed +11 -126
Documentation/config.txt
-13
@@ -209,19 +209,6 @@ core.compression::
209 compression, and 1..9 are various speed/size tradeoffs, 9 being
210 slowest.
211
212 -core.legacyheaders::
213 - A boolean which
214 - changes the format of loose objects so that they are more
215 - efficient to pack and to send out of the repository over git
216 - native protocol, since v1.4.2. However, loose objects
217 - written in the new format cannot be read by git older than
218 - that version; people fetching from your repository using
219 - older versions of git over dumb transports (e.g. http)
220 - will also be affected.
221 -+
222 -To let git use the new loose object format, you have to
223 -set core.legacyheaders to false.
224 -
212 core.packedGitWindowSize::
213 Number of bytes of a pack file to map into memory in a
214 single mapping operation. Larger window sizes may allow
builtin-pack-objects.c
-69
@@ -346,56 +346,6 @@ static void copy_pack_data(struct sha1file *f,
346 }
347 }
348
349 -static int check_loose_inflate(unsigned char *data, unsigned long len, unsigned long expect)
350 -{
351 - z_stream stream;
352 - unsigned char fakebuf[4096];
353 - int st;
354 -
355 - memset(&stream, 0, sizeof(stream));
356 - stream.next_in = data;
357 - stream.avail_in = len;
358 - stream.next_out = fakebuf;
359 - stream.avail_out = sizeof(fakebuf);
360 - inflateInit(&stream);
361 -
362 - while (1) {
363 - st = inflate(&stream, Z_FINISH);
364 - if (st == Z_STREAM_END || st == Z_OK) {
365 - st = (stream.total_out == expect &&
366 - stream.total_in == len) ? 0 : -1;
367 - break;
368 - }
369 - if (st != Z_BUF_ERROR) {
370 - st = -1;
371 - break;
372 - }
373 - stream.next_out = fakebuf;
374 - stream.avail_out = sizeof(fakebuf);
375 - }
376 - inflateEnd(&stream);
377 - return st;
378 -}
379 -
380 -static int revalidate_loose_object(struct object_entry *entry,
381 - unsigned char *map,
382 - unsigned long mapsize)
383 -{
384 - /* we already know this is a loose object with new type header. */
385 - enum object_type type;
386 - unsigned long size, used;
387 -
388 - if (pack_to_stdout)
389 - return 0;
390 -
391 - used = unpack_object_header_gently(map, mapsize, &type, &size);
392 - if (!used)
393 - return -1;
394 - map += used;
395 - mapsize -= used;
396 - return check_loose_inflate(map, mapsize, size);
397 -}
398 -
349 static unsigned long write_object(struct sha1file *f,
350 struct object_entry *entry)
351 {
@@ -427,25 +377,6 @@ static unsigned long write_object(struct sha1file *f,
377 * and we do not need to deltify it.
378 */
379
430 - if (!no_reuse_object && !entry->in_pack && !entry->delta) {
431 - unsigned char *map;
432 - unsigned long mapsize;
433 - map = map_sha1_file(entry->sha1, &mapsize);
434 - if (map && !legacy_loose_object(map)) {
435 - /* We can copy straight into the pack file */
436 - if (revalidate_loose_object(entry, map, mapsize))
437 - die("corrupt loose object %s",
438 - sha1_to_hex(entry->sha1));
439 - sha1write(f, map, mapsize);
440 - munmap(map, mapsize);
441 - written++;
442 - reused++;
443 - return mapsize;
444 - }
445 - if (map)
446 - munmap(map, mapsize);
447 - }
448 -
380 if (!to_reuse) {
381 buf = read_sha1_file(entry->sha1, &type, &size);
382 if (!buf)
cache.h
-2
@@ -273,7 +273,6 @@ extern void rollback_lock_file(struct lock_file *);
273 extern int delete_ref(const char *, const unsigned char *sha1);
274
275 /* Environment bits from configuration mechanism */
276 -extern int use_legacy_headers;
276 extern int trust_executable_bit;
277 extern int has_symlinks;
278 extern int assume_unchanged;
@@ -354,7 +353,6 @@ extern int move_temp_to_file(const char *tmpfile, const char *filename);
353 extern int has_sha1_pack(const unsigned char *sha1, const char **ignore);
354 extern int has_sha1_file(const unsigned char *sha1);
355 extern void *map_sha1_file(const unsigned char *sha1, unsigned long *);
357 -extern int legacy_loose_object(unsigned char *);
356
357 extern int has_pack_file(const unsigned char *sha1);
358 extern int has_pack_index(const unsigned char *sha1);
config.c
-5
@@ -299,11 +299,6 @@ int git_default_config(const char *var, const char *value)
299 return 0;
300 }
301
302 - if (!strcmp(var, "core.legacyheaders")) {
303 - use_legacy_headers = git_config_bool(var, value);
304 - return 0;
305 - }
306 -
302 if (!strcmp(var, "core.compression")) {
303 int level = git_config_int(var, value);
304 if (level == -1)
environment.c
-1
@@ -11,7 +11,6 @@
11
12 char git_default_email[MAX_GITNAME];
13 char git_default_name[MAX_GITNAME];
14 -int use_legacy_headers = 1;
14 int trust_executable_bit = 1;
15 int has_symlinks = 1;
16 int assume_unchanged;
sha1_file.c
+11 -36
@@ -972,7 +972,7 @@ void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
972 return map;
973 }
974
975 -int legacy_loose_object(unsigned char *map)
975 +static int legacy_loose_object(unsigned char *map)
976 {
977 unsigned int word;
978
@@ -1034,6 +1034,14 @@ static int unpack_sha1_header(z_stream *stream, unsigned char *map, unsigned lon
1034 return inflate(stream, 0);
1035 }
1036
1037 +
1038 + /*
1039 + * There used to be a second loose object header format which
1040 + * was meant to mimic the in-pack format, allowing for direct
1041 + * copy of the object data. This format turned up not to be
1042 + * really worth it and we don't write it any longer. But we
1043 + * can still read it.
1044 + */
1045 used = unpack_object_header_gently(map, mapsize, &type, &size);
1046 if (!used || !valid_loose_object_type[type])
1047 return -1;
@@ -1962,40 +1970,6 @@ static int write_buffer(int fd, const void *buf, size_t len)
1970 return 0;
1971 }
1972
1965 -static int write_binary_header(unsigned char *hdr, enum object_type type, unsigned long len)
1966 -{
1967 - int hdr_len;
1968 - unsigned char c;
1969 -
1970 - c = (type << 4) | (len & 15);
1971 - len >>= 4;
1972 - hdr_len = 1;
1973 - while (len) {
1974 - *hdr++ = c | 0x80;
1975 - hdr_len++;
1976 - c = (len & 0x7f);
1977 - len >>= 7;
1978 - }
1979 - *hdr = c;
1980 - return hdr_len;
1981 -}
1982 -
1983 -static void setup_object_header(z_stream *stream, const char *type, unsigned long len)
1984 -{
1985 - int obj_type, hdrlen;
1986 -
1987 - if (use_legacy_headers) {
1988 - while (deflate(stream, 0) == Z_OK)
1989 - /* nothing */;
1990 - return;
1991 - }
1992 - obj_type = type_from_string(type);
1993 - hdrlen = write_binary_header(stream->next_out, obj_type, len);
1994 - stream->total_out = hdrlen;
1995 - stream->next_out += hdrlen;
1996 - stream->avail_out -= hdrlen;
1997 -}
1998 -
1973 int hash_sha1_file(const void *buf, unsigned long len, const char *type,
1974 unsigned char *sha1)
1975 {
@@ -2062,7 +2036,8 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha
2036 /* First header.. */
2037 stream.next_in = (unsigned char *)hdr;
2038 stream.avail_in = hdrlen;
2065 - setup_object_header(&stream, type, len);
2039 + while (deflate(&stream, 0) == Z_OK)
2040 + /* nothing */;
2041
2042 /* Then the data itself.. */
2043 stream.next_in = buf;