From 65c2e0c349aa5c7f605defb52dc67f1b3658a1b9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 2 Jun 2005 15:20:54 -0700 Subject: [PATCH] Find size of SHA1 object without inflating everything. This adds sha1_file_size() helper function and uses it in the rename/copy similarity estimator. The helper function handles deltified object as well. Signed-off-by: Junio C Hamano Signed-off-by: Linus Torvalds --- diff.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'diff.c') diff --git a/diff.c b/diff.c index 7cf40daee5..5513632b9f 100644 --- a/diff.c +++ b/diff.c @@ -333,7 +333,6 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only) close(fd); } else { - /* We cannot do size only for SHA1 blobs */ char type[20]; struct sha1_size_cache *e; @@ -343,11 +342,13 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only) s->size = e->size; return 0; } + if (!sha1_file_size(s->sha1, &s->size)) + locate_size_cache(s->sha1, s->size); + } + else { + s->data = read_sha1_file(s->sha1, type, &s->size); + s->should_free = 1; } - s->data = read_sha1_file(s->sha1, type, &s->size); - s->should_free = 1; - if (s->data && size_only) - locate_size_cache(s->sha1, s->size); } return 0; } -- cgit v1.2.1