From b9a62cbeb91e52aea8fc427a84e72f475dfe60cf Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 12 May 2011 16:50:29 -0700 Subject: packed_object_info_detail(): do not return a string Instead return an integer that can be given to typename() if the caller wants a string, just like everybody else does. Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index b1b5bb5896..cdb51120a0 100644 --- a/cache.h +++ b/cache.h @@ -1020,7 +1020,7 @@ extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *); extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *); extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t); -extern const char *packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *); +extern int packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *); /* Dumb servers support */ extern int update_server_info(int); -- cgit v1.2.1 From 9a4905902230c080f0f6a64ed7f0aaa5777d2f5b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 12 May 2011 15:51:38 -0700 Subject: sha1_object_info_extended(): expose a bit more info The original interface for sha1_object_info() takes an object name and gives back a type and its size (the latter is given only when it was asked). The new interface wraps its implementation and exposes a bit more pieces of information that the interface used to discard, namely: - where the object is stored (loose? cached? packed?) - if packed, where in which packfile? Signed-off-by: Junio C Hamano --- * In the earlier round, this used u.pack.delta to record the length of the delta chain, but the caller is not necessarily interested in the length of the delta chain per-se, but may only want to know if it is a delta against another object or is stored as a deflated data. Calling packed_object_info_detail() involves walking the reverse index chain to compute the store size of the object and is unnecessarily expensive. We could resurrect the code if a new caller wants to know, but I doubt it. --- cache.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index cdb51120a0..9fbc07e976 100644 --- a/cache.h +++ b/cache.h @@ -1022,6 +1022,34 @@ extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsig extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t); extern int packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *); +struct object_info { + /* Request */ + unsigned long *sizep; + + /* Response */ + enum { + OI_CACHED, + OI_LOOSE, + OI_PACKED + } whence; + union { + /* + * struct { + * ... Nothing to expose in this case + * } cached; + * struct { + * ... Nothing to expose in this case + * } loose; + */ + struct { + struct packed_git *pack; + off_t offset; + unsigned int is_delta; + } packed; + } u; +}; +extern int sha1_object_info_extended(const unsigned char *, struct object_info *); + /* Dumb servers support */ extern int update_server_info(int); -- cgit v1.2.1 From 5266d369b21f8c260fa60d94fb29c3998c521e4a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 13 May 2011 13:20:43 -0700 Subject: sha1_object_info_extended(): hint about objects in delta-base cache An object found in the delta-base cache is not guaranteed to stay there, but we know it came from a pack and it is likely to give us a quick access if we read_sha1_file() it right now, which is a piece of useful information. Signed-off-by: Junio C Hamano --- cache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 9fbc07e976..3a1af9d958 100644 --- a/cache.h +++ b/cache.h @@ -1030,7 +1030,8 @@ struct object_info { enum { OI_CACHED, OI_LOOSE, - OI_PACKED + OI_PACKED, + OI_DBCACHED } whence; union { /* -- cgit v1.2.1 From f8c8abc5b76ffd763b9c7c5e4fb054358e82ca28 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 13 May 2011 15:33:33 -0700 Subject: unpack_object_header(): make it public This function is used to read and skip over the per-object header in a packfile. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 3a1af9d958..7650d2e691 100644 --- a/cache.h +++ b/cache.h @@ -1021,6 +1021,7 @@ extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsign extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t); extern int packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *); +extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *); struct object_info { /* Request */ -- cgit v1.2.1 From dd8e912190540ef6578386aa1343fbbe196cb8c1 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 12 May 2011 14:31:08 -0700 Subject: streaming_write_entry(): use streaming API in write_entry() When the output to a path does not have to be converted, we can read from the object database from the streaming API and write to the file in the working tree, without having to hold everything in the memory. The ident, auto- and safe- crlf conversions inherently require you to read the whole thing before deciding what to do, so while it is technically possible to support them by using a buffer of an unbound size or rewinding and reading the stream twice, it is less practical than the traditional "read the whole thing in core and convert" approach. Adding streaming filters for the other conversions on top of this should be doable by tweaking the can_bypass_conversion() function (it should be renamed to can_filter_stream() when it happens). Then the streaming API can be extended to wrap the git_istream streaming_write_entry() opens on the underlying object in another git_istream that reads from it, filters what is read, and let the streaming_write_entry() read the filtered result. But that is outside the scope of this series. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 7650d2e691..2a7a77f3eb 100644 --- a/cache.h +++ b/cache.h @@ -1156,6 +1156,7 @@ extern int convert_to_git(const char *path, const char *src, size_t len, struct strbuf *dst, enum safe_crlf checksafe); extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst); extern int renormalize_buffer(const char *path, const char *src, size_t len, struct strbuf *dst); +extern int can_bypass_conversion(const char *path); /* add */ /* -- cgit v1.2.1 From f0270efd460e5ee28dca8481181f1ac1ed4111d1 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 14 May 2011 19:42:10 -0700 Subject: sha1_file.c: expose helpers to read loose objects Make map_sha1_file(), parse_sha1_header() and unpack_sha1_header() available to the streaming read API by exporting them via cache.h header file. Signed-off-by: Junio C Hamano --- cache.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 2a7a77f3eb..a5067ba12d 100644 --- a/cache.h +++ b/cache.h @@ -780,6 +780,9 @@ extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1); extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *); extern int force_object_loose(const unsigned char *sha1, time_t mtime); +extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size); +extern int unpack_sha1_header(z_stream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz); +extern int parse_sha1_header(const char *hdr, unsigned long *sizep); /* global flag to enable extra checks when accessing packed objects */ extern int do_check_packed_object_crc; -- cgit v1.2.1