Skip to content

Commit 91d7b8a

Browse files
Nicolas PitreLinus Torvalds
authored andcommitted
[PATCH] delta read
This makes the core code aware of delta objects and undeltafy them as needed. The convention is to use read_sha1_file() to have undeltafication done automatically (most users do that already so this is transparent). If the delta object itself has to be accessed then it must be done through map_sha1_file() and unpack_sha1_file(). In that context mktag.c has been switched to read_sha1_file() as there is no reason to do the full map+unpack manually. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent e99d59f commit 91d7b8a

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

mktag.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,14 @@
2525
static int verify_object(unsigned char *sha1, const char *expected_type)
2626
{
2727
int ret = -1;
28-
unsigned long mapsize;
29-
void *map = map_sha1_file(sha1, &mapsize);
30-
31-
if (map) {
32-
char type[100];
33-
unsigned long size;
34-
void *buffer = unpack_sha1_file(map, mapsize, type, &size);
35-
36-
if (buffer) {
37-
if (!strcmp(type, expected_type))
38-
ret = check_sha1_signature(sha1, buffer, size, type);
39-
free(buffer);
40-
}
41-
munmap(map, mapsize);
28+
char type[100];
29+
unsigned long size;
30+
void *buffer = read_sha1_file(sha1, type, &size);
31+
32+
if (buffer) {
33+
if (!strcmp(type, expected_type))
34+
ret = check_sha1_signature(sha1, buffer, size, type);
35+
free(buffer);
4236
}
4337
return ret;
4438
}

sha1_file.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <stdarg.h>
1010
#include <limits.h>
1111
#include "cache.h"
12+
#include "delta.h"
1213

1314
#ifndef O_NOATIME
1415
#if defined(__linux__) && (defined(__i386__) || defined(__PPC__))
@@ -353,6 +354,19 @@ void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size
353354
if (map) {
354355
buf = unpack_sha1_file(map, mapsize, type, size);
355356
munmap(map, mapsize);
357+
if (buf && !strcmp(type, "delta")) {
358+
void *ref = NULL, *delta = buf;
359+
unsigned long ref_size, delta_size = *size;
360+
buf = NULL;
361+
if (delta_size > 20)
362+
ref = read_sha1_file(delta, type, &ref_size);
363+
if (ref)
364+
buf = patch_delta(ref, ref_size,
365+
delta+20, delta_size-20,
366+
size);
367+
free(delta);
368+
free(ref);
369+
}
356370
return buf;
357371
}
358372
return NULL;

0 commit comments

Comments
 (0)