{"thread":{"id":"676","subject":"[PATCH 1/3] delta read","startedAt":"2005-05-20T20:57:28Z","lastAt":"2005-05-20T20:57:28Z","messageCount":1,"participants":["Nicolas Pitre"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"3644","messageId":"Pine.LNX.4.62.0505201655000.4397@localhost.localdomain","threadId":"676","inReplyTo":null,"subject":"[PATCH 1/3] delta read","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2005-05-20T20:57:28Z","receivedAt":"2005-05-20T20:57:28Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"This patch makes the core code aware of delta objects and undeltafy\nthem as needed.  The convention is to use read_sha1_file() to have\nundeltafication done automatically (most users do that already so\nthis is transparent).\n\nIf the delta object itself has to be accessed then it must be done\nthrough map_sha1_file() and unpack_sha1_file().\n\nIn that context mktag.c has been switched to read_sha1_file() as there\nis no reason to do the full map+unpack manually.\n\nSigned-off-by: Nicolas Pitre <nico@cam.org>\n\nIndex: git/sha1_file.c\n===================================================================\n--- git.orig/sha1_file.c\n+++ git/sha1_file.c\n@@ -9,6 +9,7 @@\n #include <stdarg.h>\n #include <limits.h>\n #include \"cache.h\"\n+#include \"delta.h\"\n \n #ifndef O_NOATIME\n #if defined(__linux__) && (defined(__i386__) || defined(__PPC__))\n@@ -353,6 +354,19 @@\n \tif (map) {\n \t\tbuf = unpack_sha1_file(map, mapsize, type, size);\n \t\tmunmap(map, mapsize);\n+\t\tif (buf && !strcmp(type, \"delta\")) {\n+\t\t\tvoid *ref = NULL, *delta = buf;\n+\t\t\tunsigned long ref_size, delta_size = *size;\n+\t\t\tbuf = NULL;\n+\t\t\tif (delta_size > 20)\n+\t\t\t\tref = read_sha1_file(delta, type, &ref_size);\n+\t\t\tif (ref)\n+\t\t\t\tbuf = patch_delta(ref, ref_size,\n+\t\t\t\t\t\t  delta+20, delta_size-20, \n+\t\t\t\t\t\t  size);\n+\t\t\tfree(delta);\n+\t\t\tfree(ref);\n+\t\t}\n \t\treturn buf;\n \t}\n \treturn NULL;\nIndex: git/mktag.c\n===================================================================\n--- git.orig/mktag.c\n+++ git/mktag.c\n@@ -25,20 +25,14 @@\n static int verify_object(unsigned char *sha1, const char *expected_type)\n {\n \tint ret = -1;\n-\tunsigned long mapsize;\n-\tvoid *map = map_sha1_file(sha1, &mapsize);\n+\tchar type[100];\n+\tunsigned long size;\n+\tvoid *buffer = read_sha1_file(sha1, type, &size);\n \n-\tif (map) {\n-\t\tchar type[100];\n-\t\tunsigned long size;\n-\t\tvoid *buffer = unpack_sha1_file(map, mapsize, type, &size);\n-\n-\t\tif (buffer) {\n-\t\t\tif (!strcmp(type, expected_type))\n-\t\t\t\tret = check_sha1_signature(sha1, buffer, size, type);\n-\t\t\tfree(buffer);\n-\t\t}\n-\t\tmunmap(map, mapsize);\n+\tif (buffer) {\n+\t\tif (!strcmp(type, expected_type))\n+\t\t\tret = check_sha1_signature(sha1, buffer, size, type);\n+\t\tfree(buffer);\n \t}\n \treturn ret;\n }\n"}]}