Bulk Check-in
v2 cover Bulk Check-in
This is a re-roll of the earlier bulk-check-in series. The only change is that the last one is a bit re-structured to pay attention to the packsize limit from the get-go and also not write objects that already exist in the repository, instead of "oops, I forgot to do that, and here is a fix".
Junio C Hamano (5):
write_pack_header(): a helper function create_tmp_packfile(): a helper function finish_tmp_packfile(): a helper function
csum-file: introduce sha1file_checkpoint
bulk-checkin: replace fast-import based implementation
Makefile | 2 + builtin/add.c | 5 + builtin/pack-objects.c | 62 +++-------- bulk-checkin.c | 275 ++++++++++++++++++++++++++++++++++++++++++++++++ bulk-checkin.h | 16 +++ cache.h | 2 + config.c | 4 + csum-file.c | 20 ++++ csum-file.h | 9 ++ environment.c | 1 + fast-import.c | 25 ++--- pack-write.c | 53 +++++++++ pack.h | 6 + sha1_file.c | 67 +----------- t/t1050-large.sh | 94 +++++++++++++++-- zlib.c | 9 ++- 16 files changed, 516 insertions(+), 134 deletions(-) create mode 100644 bulk-checkin.c create mode 100644 bulk-checkin.h
Signature · 1 line
1.7.8.rc4.177.g4d64
PATCH v2 1/5 write_pack_header(): a helper function
Factor out a small logic out of the private write_pack_file() function in builtin/pack-objects.c
--- builtin/pack-objects.c | 9 +++------ pack-write.c | 12 ++++++++++++ pack.h | 2 ++ 3 files changed, 17 insertions(+), 6 deletions(-)
builtin/pack-objects.c +3 -6
@@ -571,7 +571,6 @@ static void write_pack_file(void)uint32_t i =0 , j;struct sha1file *f;off_t offset; -struct pack_header hdr;uint32_t nr_remaining = nr_result;time_t last_mtime =0 ;struct object_entry **write_order;
@@ -596,11 +595,9 @@ static void write_pack_file(void) f =sha1fd (fd, pack_tmp_name); } - hdr.hdr_signature =htonl (PACK_SIGNATURE ); - hdr.hdr_version =htonl (PACK_VERSION ); - hdr.hdr_entries =htonl (nr_remaining); -sha1write (f, &hdr,sizeof (hdr)); - offset =sizeof (hdr); + offset =write_pack_header (f, nr_remaining); +if (!offset) +die_errno ("unable to write pack header" ); nr_written =0 ;for (; i < nr_objects; i++) {struct object_entry *e = write_order[i];
pack-write.c +12 -0
@@ -178,6 +178,18 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objecreturn index_name; } +off_t write_pack_header (struct sha1file *f,uint32_t nr_entries) +{ +struct pack_header hdr; + + hdr.hdr_signature =htonl (PACK_SIGNATURE ); + hdr.hdr_version =htonl (PACK_VERSION ); + hdr.hdr_entries =htonl (nr_entries); +if (sha1write (f, &hdr,sizeof (hdr))) +return 0 ; +return sizeof (hdr); +} +/* * Update pack header with object_count and compute new SHA1 for pack data * associated to pack_fd, and write that SHA1 at the end. That new SHA1
pack.h +2 -0
@@ -2,6 +2,7 @@#define PACK_H #include "object.h" +#include "csum-file.h" /* * Packed object header
@@ -74,6 +75,7 @@ extern const char *write_idx_file(const char *index_name, struct pack_idx_entryextern int check_pack_crc (struct packed_git *p,struct pack_window **w_curs,off_t offset,off_t len,unsigned int nr);extern int verify_pack_index (struct packed_git *);extern int verify_pack (struct packed_git *); +extern off_t write_pack_header (struct sha1file *f,uint32_t );extern void fixup_pack_header_footer (int ,unsigned char *,const char *,uint32_t ,unsigned char *,off_t );extern char *index_pack_lockfile (int fd);extern int encode_in_pack_object_header (enum object_type ,uintmax_t ,unsigned char *);
Signature · 1 line
1.7.8.rc4.177.g4d64
PATCH v2 2/5 create_tmp_packfile(): a helper function
In reply to Junio C HamanoFactor out a small logic out of the private write_pack_file() function in builtin/pack-objects.c
--- builtin/pack-objects.c | 12 +++--------- pack-write.c | 10 ++++++++++ pack.h | 3 +++ 3 files changed, 16 insertions(+), 9 deletions(-)
builtin/pack-objects.c +3 -9
@@ -584,16 +584,10 @@ static void write_pack_file(void)unsigned char sha1[20 ];char *pack_tmp_name =NULL ; -if (pack_to_stdout) { +if (pack_to_stdout) f =sha1fd_throughput (1 ,"<stdout>" , progress_state); - }else { -char tmpname[PATH_MAX ]; -int fd; - fd =odb_mkstemp (tmpname,sizeof (tmpname), -"pack/tmp_pack_XXXXXX" ); - pack_tmp_name =xstrdup (tmpname); - f =sha1fd (fd, pack_tmp_name); - } +else + f =create_tmp_packfile (&pack_tmp_name); offset =write_pack_header (f, nr_remaining);if (!offset)
pack-write.c +10 -0
@@ -328,3 +328,13 @@ int encode_in_pack_object_header(enum object_type type, uintmax_t size, unsigned *hdr = c;return n; } + +struct sha1file *create_tmp_packfile (char **pack_tmp_name) +{ +char tmpname[PATH_MAX ]; +int fd; + + fd =odb_mkstemp (tmpname,sizeof (tmpname),"pack/tmp_pack_XXXXXX" ); + *pack_tmp_name =xstrdup (tmpname); +return sha1fd (fd, *pack_tmp_name); +}
pack.h +3 -0
@@ -84,4 +84,7 @@ extern int encode_in_pack_object_header(enum object_type, uintmax_t, unsigned ch#define PH_ERROR_PACK_SIGNATURE (-2)#define PH_ERROR_PROTOCOL (-3)extern int read_pack_header (int fd,struct pack_header *); + +extern struct sha1file *create_tmp_packfile (char **pack_tmp_name); +#endif
Signature · 1 line
1.7.8.rc4.177.g4d64
PATCH v2 3/5 finish_tmp_packfile(): a helper function
In reply to Junio C HamanoFactor out a small logic out of the private write_pack_file() function in builtin/pack-objects.c.
This changes the order of finishing multi-pack generation slightly. The code used to
- adjust shared perm of temporary packfile
- rename temporary packfile to the final name
- update mtime of the packfile under the final name
- adjust shared perm of temporary idxfile
- rename temporary idxfile to the final name
but because the helper does not want to do the mtime thing, the updated code does that step first and then all the rest.
--- builtin/pack-objects.c | 33 ++++++++++----------------------- pack-write.c | 31 +++++++++++++++++++++++++++++++ pack.h | 1 + 3 files changed, 42 insertions(+), 23 deletions(-)
builtin/pack-objects.c +10 -23
@@ -617,20 +617,8 @@ static void write_pack_file(void)if (!pack_to_stdout) {struct stat st; -const char *idx_tmp_name;char tmpname[PATH_MAX ]; - idx_tmp_name =write_idx_file (NULL , written_list, nr_written, - &pack_idx_opts, sha1); - -snprintf (tmpname,sizeof (tmpname),"%s-%s.pack" , - base_name,sha1_to_hex (sha1)); -free_pack_by_name (tmpname); -if (adjust_shared_perm (pack_tmp_name)) -die_errno ("unable to make temporary pack file readable" ); -if (rename (pack_tmp_name, tmpname)) -die_errno ("unable to rename temporary pack file" ); -/* * Packs are runtime accessed in their mtime * order since newer packs are more likely to contain
@@ -638,28 +626,27 @@ static void write_pack_file(void)* packs then we should modify the mtime of later ones * to preserve this property. */ -if (stat (tmpname, &st) <0 ) { +if (stat (pack_tmp_name, &st) <0 ) {warning ("failed to stat %s: %s" , - tmpname,strerror (errno)); + pack_tmp_name,strerror (errno)); }else if (!last_mtime) { last_mtime = st.st_mtime; }else {struct utimbuf utb; utb.actime = st.st_atime; utb.modtime = --last_mtime; -if (utime (tmpname, &utb) <0 ) +if (utime (pack_tmp_name, &utb) <0 )warning ("failed utime() on %s: %s" , tmpname,strerror (errno)); } -snprintf (tmpname,sizeof (tmpname),"%s-%s.idx" , - base_name,sha1_to_hex (sha1)); -if (adjust_shared_perm (idx_tmp_name)) -die_errno ("unable to make temporary index file readable" ); -if (rename (idx_tmp_name, tmpname)) -die_errno ("unable to rename temporary index file" ); - -free ((void *) idx_tmp_name); +/* Enough space for "-<sha-1>.pack"? */ +if (sizeof (tmpname) <=strlen (base_name) +50 ) +die ("pack base name '%s' too long" , base_name); +snprintf (tmpname,sizeof (tmpname),"%s-" , base_name); +finish_tmp_packfile (tmpname, pack_tmp_name, + written_list, nr_written, + &pack_idx_opts, sha1);free (pack_tmp_name);puts (sha1_to_hex (sha1)); }
pack-write.c +31 -0
@@ -338,3 +338,34 @@ struct sha1file *create_tmp_packfile(char **pack_tmp_name) *pack_tmp_name =xstrdup (tmpname);return sha1fd (fd, *pack_tmp_name); } + +void finish_tmp_packfile (char *name_buffer, +const char *pack_tmp_name, +struct pack_idx_entry **written_list, +uint32_t nr_written, +struct pack_idx_option *pack_idx_opts, +unsigned char sha1[]) +{ +const char *idx_tmp_name; +char *end_of_name_prefix =strrchr (name_buffer,0 ); + +if (adjust_shared_perm (pack_tmp_name)) +die_errno ("unable to make temporary pack file readable" ); + + idx_tmp_name =write_idx_file (NULL , written_list, nr_written, + pack_idx_opts, sha1); +if (adjust_shared_perm (idx_tmp_name)) +die_errno ("unable to make temporary index file readable" ); + +sprintf (end_of_name_prefix,"%s.pack" ,sha1_to_hex (sha1)); +free_pack_by_name (name_buffer); + +if (rename (pack_tmp_name, name_buffer)) +die_errno ("unable to rename temporary pack file" ); + +sprintf (end_of_name_prefix,"%s.idx" ,sha1_to_hex (sha1)); +if (rename (idx_tmp_name, name_buffer)) +die_errno ("unable to rename temporary index file" ); + +free ((void *)idx_tmp_name); +}
pack.h +1 -0
@@ -86,5 +86,6 @@ extern int encode_in_pack_object_header(enum object_type, uintmax_t, unsigned chextern int read_pack_header (int fd,struct pack_header *);extern struct sha1file *create_tmp_packfile (char **pack_tmp_name); +extern void finish_tmp_packfile (char *name_buffer,const char *pack_tmp_name,struct pack_idx_entry **written_list,uint32_t nr_written,struct pack_idx_option *pack_idx_opts,unsigned char sha1[]);#endif
Signature · 1 line
1.7.8.rc4.177.g4d64
PATCH v2 5/5 bulk-checkin: replace fast-import based implementation
In reply to Junio C HamanoThis extends the earlier approach to stream a large file directly from the filesystem to its own packfile, and allows "git add" to send large files directly into a single pack. Older code used to spawn fast-import, but the new bulk-checkin API replaces it.
--- Makefile | 2 + builtin/add.c | 5 + builtin/pack-objects.c | 6 +- bulk-checkin.c | 275 ++++++++++++++++++++++++++++++++++++++++++++++++ bulk-checkin.h | 16 +++ cache.h | 2 + config.c | 4 + environment.c | 1 + sha1_file.c | 67 +----------- t/t1050-large.sh | 94 +++++++++++++++-- zlib.c | 9 ++- 11 files changed, 403 insertions(+), 78 deletions(-) create mode 100644 bulk-checkin.c create mode 100644 bulk-checkin.h
Makefile +2 -0
@@ -505,6 +505,7 @@ LIB_H += argv-array.h LIB_H += attr.h LIB_H += blob.h LIB_H += builtin.h +LIB_H += bulk-checkin.h LIB_H += cache.h LIB_H += cache-tree.h LIB_H += color.h
@@ -591,6 +592,7 @@ LIB_OBJS += base85.o LIB_OBJS += bisect.o LIB_OBJS += blob.o LIB_OBJS += branch.o +LIB_OBJS += bulk-checkin.o LIB_OBJS += bundle.o LIB_OBJS += cache-tree.o LIB_OBJS += color.o
builtin/add.c +5 -0
@@ -13,6 +13,7 @@#include "diff.h" #include "diffcore.h" #include "revision.h" +#include "bulk-checkin.h" static const char *const builtin_add_usage[] = {"git add [options] [--] <filepattern>..." ,
@@ -458,11 +459,15 @@ int cmd_add(int argc, const char **argv, const char *prefix)free (seen); } +plug_bulk_checkin (); + exit_status |=add_files_to_cache (prefix, pathspec, flags);if (add_new_files) exit_status |=add_files (&dir, flags); +unplug_bulk_checkin (); + finish:if (active_cache_changed) { if (write_cache(newfd, active_cache, active_nr) ||
builtin/pack-objects.c +1 -5
@@ -76,7 +76,7 @@ static struct pack_idx_option pack_idx_opts;static const char *base_name;static int progress =1 ;static int window =10 ; -static unsigned long pack_size_limit, pack_size_limit_cfg; +static unsigned long pack_size_limit;static int depth =50 ;static int delta_search_threads;static int pack_to_stdout;
@@ -2009,10 +2009,6 @@ static int git_pack_config(const char *k, const char *v, void *cb) pack_idx_opts.version);return 0 ; } -if (!strcmp (k,"pack.packsizelimit" )) { - pack_size_limit_cfg =git_config_ulong (k, v); -return 0 ; - }return git_default_config (k, v, cb); }
bulk-checkin.c new file +275 -0
275 lines not on this page · raw message
bulk-checkin.h new file +16 -0
@@ -0,0 +1,16 @@ +/* +* Copyright (c) 2011, Google Inc. +*/ +#ifndef BULK_CHECKIN_H +#define BULK_CHECKIN_H + +#include "cache.h" + +extern int index_bulk_checkin (unsigned char sha1[], +int fd,size_t size,enum object_type type, +const char *path,unsigned flags); + +extern void plug_bulk_checkin (void ); +extern void unplug_bulk_checkin (void ); + +#endif
cache.h +2 -0
@@ -35,6 +35,7 @@ int git_inflate(git_zstream *, int flush);void git_deflate_init (git_zstream *,int level);void git_deflate_init_gzip (git_zstream *,int level);void git_deflate_end (git_zstream *); +int git_deflate_abort (git_zstream *);int git_deflate_end_gently (git_zstream *);int git_deflate (git_zstream *,int flush);unsigned long git_deflate_bound (git_zstream *,unsigned long );
@@ -598,6 +599,7 @@ extern size_t packed_git_window_size;extern size_t packed_git_limit;extern size_t delta_base_cache_limit;extern unsigned long big_file_threshold; +extern unsigned long pack_size_limit_cfg;extern int read_replace_refs;extern int fsync_object_files;extern int core_preload_index;
config.c +4 -0
@@ -797,6 +797,10 @@ int git_default_config(const char *var, const char *value, void *dummy)return 0 ; } +if (!strcmp (var,"pack.packsizelimit" )) { + pack_size_limit_cfg =git_config_ulong (var, value); +return 0 ; + }/* Add other config variables here and to Documentation/config.txt. */ return 0 ; }
environment.c +1 -0
@@ -60,6 +60,7 @@ char *notes_ref_name;int grafts_replace_parents =1 ;int core_apply_sparse_checkout;struct startup_info *startup_info; +unsigned long pack_size_limit_cfg;/* Parallel index stat data preload? */ int core_preload_index =0 ;
sha1_file.c +4 -63
85 lines not on this page · raw message
t/t1050-large.sh +85 -9
106 lines not on this page · raw message
zlib.c +8 -1
@@ -188,13 +188,20 @@ void git_deflate_init_gzip(git_zstream *strm, int level) strm->z.msg ? strm->z.msg : "no message"); } -void git_deflate_end (git_zstream *strm) +int git_deflate_abort (git_zstream *strm) {int status;zlib_pre_call (strm); status =deflateEnd (&strm->z);zlib_post_call (strm); +return status; +} + +void git_deflate_end (git_zstream *strm) +{ +int status =git_deflate_abort (strm); +if (status ==Z_OK )return ; error("deflateEnd: %s (%s)", zerr_to_string(status),
Signature · 1 line
1.7.8.rc4.177.g4d64
PATCH v2 4/5 csum-file: introduce sha1file_checkpoint
In reply to Junio C HamanoIt is useful to be able to rewind a check-summed file to a certain previous state after writing data into it using sha1write() API. The fast-import command does this after streaming a blob data to the packfile being generated and then noticing that the same blob has already been written, and it does this with a private code truncate_pack() that is commented as "Yes, this is a layering violation".
Introduce two API functions, sha1file_checkpoint(), that allows the caller to save a state of a sha1file, and then later revert it to the saved state. Use it to reimplement truncate_pack().
--- csum-file.c | 20 ++++++++++++++++++++ csum-file.h | 9 +++++++++ fast-import.c | 25 ++++++++----------------- 3 files changed, 37 insertions(+), 17 deletions(-)
csum-file.c +20 -0
@@ -158,6 +158,26 @@ struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tpreturn f; } +void sha1file_checkpoint (struct sha1file *f,struct sha1file_checkpoint *checkpoint) +{ +sha1flush (f); + checkpoint->offset = f->total; + checkpoint->ctx = f->ctx; +} + +int sha1file_truncate (struct sha1file *f,struct sha1file_checkpoint *checkpoint) +{ +off_t offset = checkpoint->offset; + +if (ftruncate (f->fd, offset) || +lseek (f->fd, offset,SEEK_SET ) != offset) +return -1 ; + f->total = offset; + f->ctx = checkpoint->ctx; + f->offset =0 ;/* sha1flush() was called in checkpoint */ +return 0 ; +} +void crc32_begin (struct sha1file *f) { f->crc32 =crc32 (0 ,NULL ,0 );
csum-file.h +9 -0
@@ -17,6 +17,15 @@ struct sha1file {unsigned char buffer[8192 ]; }; +/* Checkpoint */ +struct sha1file_checkpoint { +off_t offset; +git_SHA_CTX ctx; +}; + +extern void sha1file_checkpoint (struct sha1file *,struct sha1file_checkpoint *); +extern int sha1file_truncate (struct sha1file *,struct sha1file_checkpoint *); +/* sha1close flags */ #define CSUM_CLOSE 1#define CSUM_FSYNC 2
fast-import.c +8 -17
@@ -1143,17 +1143,11 @@ static int store_object(return 0 ; } -static void truncate_pack (off_t to,git_SHA_CTX *ctx) +static void truncate_pack (struct sha1file_checkpoint *checkpoint) { -if (ftruncate (pack_data->pack_fd, to) - ||lseek (pack_data->pack_fd, to,SEEK_SET ) != to) +if (sha1file_truncate (pack_file, checkpoint))die_errno ("cannot truncate pack to skip duplicate" ); - pack_size = to; - -/* yes this is a layering violation */ - pack_file->total = to; - pack_file->offset =0 ; - pack_file->ctx = *ctx; + pack_size = checkpoint->offset; }static void stream_blob (uintmax_t len,unsigned char *sha1out,uintmax_t mark)
@@ -1166,8 +1160,8 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)unsigned long hdrlen;off_t offset;git_SHA_CTX c; -git_SHA_CTX pack_file_ctx;git_zstream s; +struct sha1file_checkpoint checkpoint;int status =Z_OK ;/* Determine if we should auto-checkpoint. */
@@ -1175,11 +1169,8 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark) || (pack_size + 60 + len) < pack_size)cycle_packfile (); - offset = pack_size; - -/* preserve the pack_file SHA1 ctx in case we have to truncate later */ -sha1flush (pack_file); - pack_file_ctx = pack_file->ctx; +sha1file_checkpoint (pack_file, &checkpoint); + offset = checkpoint.offset; hdrlen =snprintf ((char *)out_buf, out_sz,"blob %" PRIuMAX, len) +1 ;if (out_sz <= hdrlen)
@@ -1245,14 +1236,14 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)if (e->idx.offset) { duplicate_count_by_type[OBJ_BLOB ]++; -truncate_pack (offset, &pack_file_ctx); +truncate_pack (&checkpoint); }else if (find_sha1_pack (sha1, packed_git)) { e->type =OBJ_BLOB ; e->pack_id =MAX_PACK_ID ; e->idx.offset =1 ;/* just not zero! */ duplicate_count_by_type[OBJ_BLOB ]++; -truncate_pack (offset, &pack_file_ctx); +truncate_pack (&checkpoint); }else { e->depth =0 ;
Signature · 1 line
1.7.8.rc4.177.g4d64
v3 cover Bulk check-in
In reply to Junio C HamanoI would declare that the earlier parts of the v2 that are about factoring out various API pieces from existing code are basically completed, so they are not part of this iteration.
The bulk-checkin patch from v2 has been tweaked a bit (deflate_to_pack() initializes "already_hashed_to" pointer to 0, instead of the current file position "seekback"), and then the rest of the series builds on top of it to add a new in-pack encoding that I am tentatively calling "chunked".
The basic idea is to represent a large/huge blob as a concatenation of smaller blobs. An entry in a pack in "chunked" representation records a list of object names of the component blob objects. The object name given to such a blob is computed exactly the same way as before. In other words, the name of a object does not depend on its representation; we hash "blob <size> NUL" and the whole large blob contents to come up with its name. It is *not* the hash of the component blob object names.
As can be seen in the log message of the "support chunked-object encoding" patch, many pieces are still missing from this series and filling them will be a long and tortuous journey. But we need to start somewhere.
I specifically excluded any heuristics to split large objects into chunks in a self-synchronising way so that a small edit near the beginning of a large blob results in a handful of new component blobs followed by the same component blobs as used to represent the same blob before such an edit, and I do not plan to work on that part myself. My impression from listening Avery's plug for "bup" is that it is a solved problem; it should be reasonably straightforward to lift the logic and plug it into the framework presented here (once the codebase gets solid enough, that is).
After this series, the next step for me is likely to teach the streaming interface about "chunked" objects, and then pack-objects to take notice and reuse "chunked" representation when sending things out (which means that sending a "chunked" encoded blob would involve sending the component blobs it uses, among other things), but I expect that it will extend well into next year.
Junio C Hamano (6):
bulk-checkin: replace fast-import based implementation
varint-in-pack: refactor varint encoding/decoding new representation types in the packstream
bulk-checkin: allow the same data to be multiply hashed
bulk-checkin: support chunked-object encoding
chunked-object: fallback checkout codepaths
Makefile | 3 + builtin/add.c | 5 + builtin/pack-objects.c | 34 ++--- bulk-checkin.c | 415 ++++++++++++++++++++++++++++++++++++++++++++++++ bulk-checkin.h | 17 ++ cache.h | 13 ++- config.c | 9 + environment.c | 2 + pack-write.c | 50 +++++- pack.h | 2 + sha1_file.c | 150 +++++++++--------- split-chunk.c | 28 ++++ t/t1050-large.sh | 135 +++++++++++++++- zlib.c | 9 +- 14 files changed, 760 insertions(+), 112 deletions(-) create mode 100644 bulk-checkin.c create mode 100644 bulk-checkin.h create mode 100644 split-chunk.c
Signature · 1 line
1.7.8.rc4.177.g4d64
PATCH v3 1/6 bulk-checkin: replace fast-import based implementation
This extends the earlier approach to stream a large file directly from the filesystem to its own packfile, and allows "git add" to send large files directly into a single pack. Older code used to spawn fast-import, but the new bulk-checkin API replaces it.
--- Makefile | 2 + builtin/add.c | 5 + builtin/pack-objects.c | 6 +- bulk-checkin.c | 275 ++++++++++++++++++++++++++++++++++++++++++++++++ bulk-checkin.h | 16 +++ cache.h | 2 + config.c | 4 + environment.c | 1 + sha1_file.c | 67 +----------- t/t1050-large.sh | 94 +++++++++++++++-- zlib.c | 9 ++- 11 files changed, 403 insertions(+), 78 deletions(-) create mode 100644 bulk-checkin.c create mode 100644 bulk-checkin.h
Makefile +2 -0
@@ -505,6 +505,7 @@ LIB_H += argv-array.h LIB_H += attr.h LIB_H += blob.h LIB_H += builtin.h +LIB_H += bulk-checkin.h LIB_H += cache.h LIB_H += cache-tree.h LIB_H += color.h
@@ -591,6 +592,7 @@ LIB_OBJS += base85.o LIB_OBJS += bisect.o LIB_OBJS += blob.o LIB_OBJS += branch.o +LIB_OBJS += bulk-checkin.o LIB_OBJS += bundle.o LIB_OBJS += cache-tree.o LIB_OBJS += color.o
builtin/add.c +5 -0
@@ -13,6 +13,7 @@#include "diff.h" #include "diffcore.h" #include "revision.h" +#include "bulk-checkin.h" static const char *const builtin_add_usage[] = {"git add [options] [--] <filepattern>..." ,
@@ -458,11 +459,15 @@ int cmd_add(int argc, const char **argv, const char *prefix)free (seen); } +plug_bulk_checkin (); + exit_status |=add_files_to_cache (prefix, pathspec, flags);if (add_new_files) exit_status |=add_files (&dir, flags); +unplug_bulk_checkin (); + finish:if (active_cache_changed) { if (write_cache(newfd, active_cache, active_nr) ||
builtin/pack-objects.c +1 -5
@@ -76,7 +76,7 @@ static struct pack_idx_option pack_idx_opts;static const char *base_name;static int progress =1 ;static int window =10 ; -static unsigned long pack_size_limit, pack_size_limit_cfg; +static unsigned long pack_size_limit;static int depth =50 ;static int delta_search_threads;static int pack_to_stdout;
@@ -2009,10 +2009,6 @@ static int git_pack_config(const char *k, const char *v, void *cb) pack_idx_opts.version);return 0 ; } -if (!strcmp (k,"pack.packsizelimit" )) { - pack_size_limit_cfg =git_config_ulong (k, v); -return 0 ; - }return git_default_config (k, v, cb); }
bulk-checkin.c new file +275 -0
275 lines not on this page · raw message
bulk-checkin.h new file +16 -0
@@ -0,0 +1,16 @@ +/* +* Copyright (c) 2011, Google Inc. +*/ +#ifndef BULK_CHECKIN_H +#define BULK_CHECKIN_H + +#include "cache.h" + +extern int index_bulk_checkin (unsigned char sha1[], +int fd,size_t size,enum object_type type, +const char *path,unsigned flags); + +extern void plug_bulk_checkin (void ); +extern void unplug_bulk_checkin (void ); + +#endif
cache.h +2 -0
@@ -35,6 +35,7 @@ int git_inflate(git_zstream *, int flush);void git_deflate_init (git_zstream *,int level);void git_deflate_init_gzip (git_zstream *,int level);void git_deflate_end (git_zstream *); +int git_deflate_abort (git_zstream *);int git_deflate_end_gently (git_zstream *);int git_deflate (git_zstream *,int flush);unsigned long git_deflate_bound (git_zstream *,unsigned long );
@@ -598,6 +599,7 @@ extern size_t packed_git_window_size;extern size_t packed_git_limit;extern size_t delta_base_cache_limit;extern unsigned long big_file_threshold; +extern unsigned long pack_size_limit_cfg;extern int read_replace_refs;extern int fsync_object_files;extern int core_preload_index;
config.c +4 -0
@@ -797,6 +797,10 @@ int git_default_config(const char *var, const char *value, void *dummy)return 0 ; } +if (!strcmp (var,"pack.packsizelimit" )) { + pack_size_limit_cfg =git_config_ulong (var, value); +return 0 ; + }/* Add other config variables here and to Documentation/config.txt. */ return 0 ; }
environment.c +1 -0
@@ -60,6 +60,7 @@ char *notes_ref_name;int grafts_replace_parents =1 ;int core_apply_sparse_checkout;struct startup_info *startup_info; +unsigned long pack_size_limit_cfg;/* Parallel index stat data preload? */ int core_preload_index =0 ;
sha1_file.c +4 -63
85 lines not on this page · raw message
t/t1050-large.sh +85 -9
106 lines not on this page · raw message
zlib.c +8 -1
@@ -188,13 +188,20 @@ void git_deflate_init_gzip(git_zstream *strm, int level) strm->z.msg ? strm->z.msg : "no message"); } -void git_deflate_end (git_zstream *strm) +int git_deflate_abort (git_zstream *strm) {int status;zlib_pre_call (strm); status =deflateEnd (&strm->z);zlib_post_call (strm); +return status; +} + +void git_deflate_end (git_zstream *strm) +{ +int status =git_deflate_abort (strm); +if (status ==Z_OK )return ; error("deflateEnd: %s (%s)", zerr_to_string(status),
Signature · 1 line
1.7.8.rc4.177.g4d64
PATCH v3 2/6 varint-in-pack: refactor varint encoding/decoding
In reply to Junio C HamanoRefactor encode/decode_in_pack_varint() functions from OFS_DELTA codepaths to read and write variable-length integers in the pack stream.
--- builtin/pack-objects.c | 28 +++++++++++++--------------- pack-write.c | 27 +++++++++++++++++++++++++++ pack.h | 2 ++ sha1_file.c | 18 ++++++------------ 4 files changed, 48 insertions(+), 27 deletions(-)
builtin/pack-objects.c +13 -15
@@ -210,7 +210,7 @@ static unsigned long write_object(struct sha1file *f, {unsigned long size, limit, datalen;void *buf; -unsigned char header[10 ], dheader[10 ]; +unsigned char header[10 ];unsigned hdrlen;enum object_type type;int usable_delta, to_reuse;
@@ -304,17 +304,16 @@ static unsigned long write_object(struct sha1file *f,* base from this object's position in the pack. */ off_t ofs = entry->idx.offset - entry->delta->idx.offset; -unsigned pos =sizeof (dheader) -1 ; - dheader[pos] = ofs &127 ; -while (ofs >>=7 ) - dheader[--pos] =128 | (--ofs &127 ); -if (limit && hdrlen +sizeof (dheader) - pos + datalen +20 >= limit) { +unsigned char dheader[10 ]; +unsigned pos =encode_in_pack_varint (ofs, dheader); + +if (limit && hdrlen + pos + datalen +20 >= limit) {free (buf);return 0 ; }sha1write (f, header, hdrlen); -sha1write (f, dheader + pos,sizeof (dheader) - pos); - hdrlen +=sizeof (dheader) - pos; +sha1write (f, dheader, pos); + hdrlen += pos; }else if (type ==OBJ_REF_DELTA ) {/* * Deltas with a base reference contain
@@ -369,17 +368,16 @@ static unsigned long write_object(struct sha1file *f,if (type ==OBJ_OFS_DELTA ) {off_t ofs = entry->idx.offset - entry->delta->idx.offset; -unsigned pos =sizeof (dheader) -1 ; - dheader[pos] = ofs &127 ; -while (ofs >>=7 ) - dheader[--pos] =128 | (--ofs &127 ); -if (limit && hdrlen +sizeof (dheader) - pos + datalen +20 >= limit) { +unsigned char dheader[10 ]; +unsigned pos =encode_in_pack_varint (ofs, dheader); + +if (limit && hdrlen + pos + datalen +20 >= limit) {unuse_pack (&w_curs);return 0 ; }sha1write (f, header, hdrlen); -sha1write (f, dheader + pos,sizeof (dheader) - pos); - hdrlen +=sizeof (dheader) - pos; +sha1write (f, dheader, pos); + hdrlen += pos; reused_delta++; }else if (type ==OBJ_REF_DELTA ) {if (limit && hdrlen +20 + datalen +20 >= limit) {
pack-write.c +27 -0
@@ -302,6 +302,33 @@ char *index_pack_lockfile(int ip_out)return NULL ; } +uintmax_t decode_in_pack_varint (const unsigned char **bufp) +{ +const unsigned char *buf = *bufp; +unsigned char c = *buf++; +uintmax_t val = c &127 ; +while (c &128 ) { + val +=1 ; +if (!val ||MSB (val,7 )) +return 0 ;/* overflow */ + c = *buf++; + val = (val <<7 ) + (c &127 ); + } + *bufp = buf; +return val; +} + +int encode_in_pack_varint (uintmax_t value,unsigned char *buf) +{ +unsigned char varint[16 ]; +unsigned pos =sizeof (varint) -1 ; + varint[pos] = value &127 ; +while (value >>=7 ) + varint[--pos] =128 | (--value &127 ); +memcpy (buf, varint + pos,sizeof (varint) - pos); +return sizeof (varint) - pos; +} +/* * The per-object header is a pretty dense thing, which is * - first byte: low four bits are "size", then three bits of "type",
pack.h +2 -0
@@ -79,6 +79,8 @@ extern off_t write_pack_header(struct sha1file *f, uint32_t);extern void fixup_pack_header_footer (int ,unsigned char *,const char *,uint32_t ,unsigned char *,off_t );extern char *index_pack_lockfile (int fd);extern int encode_in_pack_object_header (enum object_type ,uintmax_t ,unsigned char *); +extern int encode_in_pack_varint (uintmax_t ,unsigned char *); +extern uintmax_t decode_in_pack_varint (const unsigned char **);#define PH_ERROR_EOF (-1)#define PH_ERROR_PACK_SIGNATURE (-2)
sha1_file.c +6 -12
@@ -1484,20 +1484,14 @@ static off_t get_delta_base(struct packed_git *p,* is stupid, as then a REF_DELTA would be smaller to store. */ if (type ==OBJ_OFS_DELTA ) { -unsigned used =0 ; -unsigned char c = base_info[used++]; - base_offset = c &127 ; -while (c &128 ) { - base_offset +=1 ; -if (!base_offset ||MSB (base_offset,7 )) -return 0 ;/* overflow */ - c = base_info[used++]; - base_offset = (base_offset <<7 ) + (c &127 ); - } - base_offset = delta_obj_offset - base_offset; +const unsigned char *buf = base_info; +uintmax_t ofs =decode_in_pack_varint (&buf); +if (!ofs && buf == base_info) +return 0 ;/* overflow */ + base_offset = delta_obj_offset - ofs;if (base_offset <=0 || base_offset >= delta_obj_offset)return 0 ;/* out of bound */ - *curpos += used; + *curpos += buf - base_info; }else if (type ==OBJ_REF_DELTA ) {/* The base entry _must_ be in the same pack */ base_offset =find_pack_entry_one (base_info, p);
Signature · 1 line
1.7.8.rc4.177.g4d64
PATCH v3 3/6 new representation types in the packstream
In reply to Junio C HamanoIn addition to four basic types (commit, tree, blob and tag), the pack stream can encode a few other "representation" types, such as REF_DELTA and OFS_DELTA. As we allocate 3 bits in the first byte for this purpose, we do not have much room to add new representation types in place, but we do have one value reserved for future expansion.
When encoding a new representation type, the early part of the in-pack object header is encoded as if its type is OBJ_EXT (= 5) using exactly the same way as before. That is, the lower 4-bit of the first byte is used for the lowest 4-bit of the size information, the next 3-bit has the type information, and the MSB says if the subsequent bytes encodes higher bits for the size information.
An in-pack object header that records OBJ_EXT as the type is followed by an integer in the same variable-length encoding as OFS_DELTA offset is encoded. This value is the real type of the representation minus 8 (as we do not need to use OBJ_EXT to encode types smaller than 8). Because we do not foresee very many representation types, in practice we would have a single byte with its MSB clear, to represent types 8-135.
The code does not type=8 and upwards for anything yet.
--- cache.h | 4 +++- pack-write.c | 23 +++++++++++++++++------ sha1_file.c | 11 +++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-)
cache.h +3 -1
@@ -381,12 +381,14 @@ enum object_type {OBJ_TREE =2 ,OBJ_BLOB =3 ,OBJ_TAG =4 , -/* 5 for future expansion */ +OBJ_EXT =5 ,OBJ_OFS_DELTA =6 ,OBJ_REF_DELTA =7 ,OBJ_ANY , OBJ_MAX }; +#define OBJ_LAST_BASE_TYPE OBJ_REF_DELTA +#define OBJ_LAST_VALID_TYPE OBJ_REF_DELTAstatic inline enum object_type object_type (unsigned int mode) {
pack-write.c +17 -6
@@ -338,22 +338,33 @@ int encode_in_pack_varint(uintmax_t value, unsigned char *buf)*/ int encode_in_pack_object_header (enum object_type type,uintmax_t size,unsigned char *hdr) { -int n =1 ; +unsigned char *hdr_base;unsigned char c; +enum object_type header_type; -if (type <OBJ_COMMIT || type >OBJ_REF_DELTA ) +if (type <OBJ_COMMIT ||OBJ_LAST_VALID_TYPE < type)die ("bad type %d" , type); +else if (OBJ_LAST_BASE_TYPE < type) + header_type =OBJ_EXT ; +else + header_type = type; - c = (type <<4 ) | (size &15 ); + c = (header_type <<4 ) | (size &15 ); size >>=4 ; + hdr_base = hdr;while (size) { *hdr++ = c |0x80 ; c = size &0x7f ; size >>=7 ; - n++; } - *hdr = c; -return n; + *hdr++ = c; +if (header_type != type) { +int sz; + type = type - (OBJ_LAST_BASE_TYPE +1 ); + sz =encode_in_pack_varint (type, hdr); + hdr += sz; + } +return hdr - hdr_base; }struct sha1file *create_tmp_packfile (char **pack_tmp_name)
sha1_file.c +11 -0
@@ -1275,6 +1275,17 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf, shift +=7 ; } *sizep = size; +if (*type ==OBJ_EXT ) { +const unsigned char *p = buf + used; +uintmax_t val =decode_in_pack_varint (&p); + +if (p == buf + used && !val) { +error ("bad extended object type" ); +return 0 ; + } + *type = val + (OBJ_LAST_BASE_TYPE +1 ); + used = p - buf; + }return used; }
Signature · 1 line
1.7.8.rc4.177.g4d64
PATCH v3 4/6 bulk-checkin: allow the same data to be multiply hashed
In reply to Junio C HamanoThis updates stream_to_pack() machinery to feed the data it is writing out to multiple hash contexts at the same time. Right now we only use a single git_SHA_CTX, so there is no change in functionality.
--- bulk-checkin.c | 33 +++++++++++++++++++++++++-------- 1 files changed, 25 insertions(+), 8 deletions(-)
bulk-checkin.c +25 -8
@@ -75,6 +75,20 @@ static int already_written(struct bulk_checkin_state *state, unsigned char sha1[return 0 ; } +struct chunk_ctx { +struct chunk_ctx *up; +git_SHA_CTX ctx; +}; + +static void chunk_SHA1_Update (struct chunk_ctx *ctx, +const unsigned char *buf,size_t size) +{ +while (ctx) { +git_SHA1_Update (&ctx->ctx, buf, size); + ctx = ctx->up; + } +} +/* * Read the contents from fd for size bytes, streaming it to the * packfile in state while updating the hash in ctx. Signal a failure
@@ -91,7 +105,7 @@ static int already_written(struct bulk_checkin_state *state, unsigned char sha1[* with a new pack. */ static int stream_to_pack (struct bulk_checkin_state *state, -git_SHA_CTX *ctx,off_t *already_hashed_to, +struct chunk_ctx *ctx,off_t *already_hashed_to,int fd,size_t size,enum object_type type,const char *path,unsigned flags) {
@@ -123,7 +137,7 @@ static int stream_to_pack(struct bulk_checkin_state *state,if (rsize < hsize) hsize = rsize;if (hsize) -git_SHA1_Update (ctx, ibuf, hsize); +chunk_SHA1_Update (ctx, ibuf, hsize); *already_hashed_to = offset; } s.next_in = ibuf;
@@ -185,10 +199,11 @@ static int deflate_to_pack(struct bulk_checkin_state *state,unsigned char result_sha1[], int fd, size_t size, enum object_type type, const char *path, - unsigned flags) + unsigned flags, + struct chunk_ctx *up) { off_t seekback, already_hashed_to; -git_SHA_CTX ctx; +struct chunk_ctx ctx;unsigned char obuf[16384 ];unsigned header_len;struct sha1file_checkpoint checkpoint;
@@ -200,8 +215,10 @@ static int deflate_to_pack(struct bulk_checkin_state *state, header_len =sprintf ((char *)obuf,"%s %" PRIuMAX,typename (type), (uintmax_t )size) +1 ; -git_SHA1_Init (&ctx); -git_SHA1_Update (&ctx, obuf, header_len); +memset (&ctx,0 ,sizeof (ctx)); + ctx.up = up; +git_SHA1_Init (&ctx.ctx); +git_SHA1_Update (&ctx.ctx, obuf, header_len);/* Note: idx is non-NULL when we are writing */ if ((flags &HASH_WRITE_OBJECT ) !=0 )
@@ -232,7 +249,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,if (lseek (fd, seekback,SEEK_SET ) == (off_t) -1 )return error ("cannot seek back" ); } -git_SHA1_Final (result_sha1, &ctx); +git_SHA1_Final (result_sha1, &ctx.ctx);if (!idx)return 0 ;
@@ -256,7 +273,7 @@ int index_bulk_checkin(unsigned char *sha1, const char *path, unsigned flags) { int status = deflate_to_pack(&state, sha1, fd, size, type, - path, flags); + path, flags,NULL );if (!state.plugged)finish_bulk_checkin (&state);return status;
Signature · 1 line
1.7.8.rc4.177.g4d64
PATCH v3 5/6 bulk-checkin: support chunked-object encoding
In reply to Junio C HamanoInstead of recording a huge object as a single entry in the packfile, record it as a concatenation of smaller blob objects. This is primarily to make it possible to repack repositories with huge objects and transfer huge objects out of such repositories.
This is the first step of a long and painful journey. We would still need to teach many codepaths about the new encoding:
* The streaming checkout codepath must learn how to read these from the object store and write a concatenation of component blob contents to the working tree. Note that after a repack, a component blob object could be represented as a delta to another blob object.
* The in-core object reading codepath must learn to notice and at least reject reading such objects entirely in-core. It is expected that nobody is interested in producing a patch out of these huge objects, at least initially.
* The object connectivity machinery must learn that component blob objects are reachable from an object that uses them, so that "gc" will not lose them, and "fsck" will not complain about them.
* The pack-object machinery must learn to copy an object that is encoded in chunked-object encoding literally to the destination (while perhaps validating the object name).
* The index-pack and verify-pack machineries need to be told about it.
The split-chunk logic used here is kept deliberately useless in order to avoid distracting the reviewers, and also make sure that the chunked encoding machinery does not depend any particular chunk splitting heuristics. We may want to replace it with a better heuristics, perhaps the one used in "bup" that is based on a self-synchronizing rolling checksum logic, or something.
--- Makefile | 1 + bulk-checkin.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++- bulk-checkin.h | 1 + cache.h | 9 +++- config.c | 5 ++ environment.c | 1 + split-chunk.c | 28 ++++++++++++ t/t1050-large.sh | 29 ++++++++++++ 8 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 split-chunk.c
Makefile +1 -0
@@ -679,6 +679,7 @@ LIB_OBJS += sha1_name.o LIB_OBJS += shallow.o LIB_OBJS += sideband.o LIB_OBJS += sigchain.o +LIB_OBJS += split-chunk.o LIB_OBJS += strbuf.o LIB_OBJS += streaming.o LIB_OBJS += string-list.o
bulk-checkin.c +125 -2
143 lines not on this page · raw message
bulk-checkin.h +1 -0
@@ -12,5 +12,6 @@ extern int index_bulk_checkin(unsigned char sha1[],extern void plug_bulk_checkin (void );extern void unplug_bulk_checkin (void ); +extern size_t carve_chunk (int fd,size_t size);#endif
cache.h +8 -1
@@ -384,11 +384,17 @@ enum object_type {OBJ_EXT =5 ,OBJ_OFS_DELTA =6 ,OBJ_REF_DELTA =7 , +/* OBJ_CHUNKED_COMMIT = 8 */ +/* OBJ_CHUNKED_TREE = 9 */ +OBJ_CHUNKED_BLOB =10 , +/* OBJ_CHUNKED_TAG = 11 */ OBJ_ANY , OBJ_MAX };#define OBJ_LAST_BASE_TYPE OBJ_REF_DELTA -#define OBJ_LAST_VALID_TYPE OBJ_REF_DELTA +#define OBJ_LAST_VALID_TYPE OBJ_CHUNKED_BLOB +#define OBJ_CHUNKED (type) ((type) + 7) +#define OBJ_DEKNUHC (type) ((type) - 7)static inline enum object_type object_type (unsigned int mode) {
@@ -602,6 +608,7 @@ extern size_t packed_git_limit;extern size_t delta_base_cache_limit;extern unsigned long big_file_threshold;extern unsigned long pack_size_limit_cfg; +extern unsigned long split_size_limit_cfg;extern int read_replace_refs;extern int fsync_object_files;extern int core_preload_index;
config.c +5 -0
@@ -801,6 +801,11 @@ int git_default_config(const char *var, const char *value, void *dummy) pack_size_limit_cfg =git_config_ulong (var, value);return 0 ; } + +if (!strcmp (var,"pack.splitsizelimit" )) { + split_size_limit_cfg =git_config_ulong (var, value); +return 0 ; + }/* Add other config variables here and to Documentation/config.txt. */ return 0 ; }
environment.c +1 -0
@@ -61,6 +61,7 @@ int grafts_replace_parents = 1;int core_apply_sparse_checkout;struct startup_info *startup_info;unsigned long pack_size_limit_cfg; +unsigned long split_size_limit_cfg;/* Parallel index stat data preload? */ int core_preload_index =0 ;
split-chunk.c new file +28 -0
@@ -0,0 +1,28 @@ +#include "git-compat-util.h" +#include "bulk-checkin.h" + +/* Cut at around 512kB */ +#define TARGET_CHUNK_SIZE_LOG2 19 +#define TARGET_CHUNK_SIZE (1U << TARGET_CHUNK_SIZE_LOG2) + +/* +* Carve out around 500kB to be stored as a separate blob +*/ +size_t carve_chunk (int fd,size_t size) +{ +size_t chunk_size; +off_t seekback =lseek (fd,0 ,SEEK_CUR ); + +if (seekback == (off_t) -1 ) +die ("cannot find the current offset" ); + +/* Next patch will do something complex to find out where to cut */ + chunk_size = size; +if (TARGET_CHUNK_SIZE < chunk_size) + chunk_size =TARGET_CHUNK_SIZE ; + +if (lseek (fd, seekback,SEEK_SET ) == (off_t) -1 ) +return error ("cannot seek back" ); + +return chunk_size; +}
t/t1050-large.sh +29 -0
@@ -100,4 +100,33 @@ test_expect_success 'packsize limit' ' ) ' +test_expect_success 'split limit' ' + test_create_repo split && + ( + cd split && + git config core.bigfilethreshold 2m && + git config pack.splitsizelimit 1m && + + test-genrandom "a" $(( 4800 * 1024 )) >split && + git add split && + + # This should result in a new chunked object "tail" + # that shares most of the component blobs in its + # early part with "split". + cat split >tail && + echo cruft >>tail && + git add tail && + + # This should result in a new chunked object "head" + # that begins with its own unique component blobs + # but quickly synchronize and start using the same + # component blobs with "split" and "tail", once we + # switch to a better chunking heuristics. + echo cruft >head && + cat split >>head && + git add head + + ) +' + test_done
Signature · 1 line
1.7.8.rc4.177.g4d64
PATCH v3 6/6 chunked-object: fallback checkout codepaths
In reply to Junio C HamanoThis prepares the default codepaths based on the traditional "slurping everything in-core" model around read_sha1_file() API for objects that use chunked encoding. Needless to say, these codepaths are unsuitable for the kind of objects that use chunked encoding and are intended to only serve as the fallback where specialized "large object API" support is still lacking.
--- sha1_file.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ t/t1050-large.sh | 14 +++++++++++++- 2 files changed, 67 insertions(+), 1 deletions(-)
sha1_file.c +54 -0
@@ -1607,6 +1607,11 @@ static int packed_object_info(struct packed_git *p, off_t obj_offset,if (sizep) *sizep = size;break ; +case OBJ_CHUNKED_BLOB : +if (sizep) + *sizep = size; + type =OBJ_DEKNUHC (type); +break ;default :error ("unknown object type %i at offset %" PRIuMAX" in %s" , type, (uintmax_t )obj_offset, p->pack_name);
@@ -1648,6 +1653,51 @@ static void *unpack_compressed_entry(struct packed_git *p,return buffer; } +static void *unpack_chunked_entry (struct packed_git *p, +struct pack_window **w_curs, +off_t curpos, +unsigned long size) +{ +/* +* *NOTE* *NOTE* *NOTE* +* +* In the longer term, we should aim to exercise this codepath +* less and less often, as it defeats the whole purpose of +* chuncked object encoding! +*/ +unsigned char *buffer; +const unsigned char *in, *ptr; +unsigned long avail, ofs; +int chunk_cnt; + + buffer =xmallocz (size); + in =use_pack (p, w_curs, curpos, &avail); + ptr = in; + chunk_cnt =decode_in_pack_varint (&ptr); + curpos += ptr - in; + ofs =0 ; +while (chunk_cnt--) { +unsigned long csize; +unsigned char *data; +enum object_type type; + + in =use_pack (p, w_curs, curpos, &avail); + data =read_sha1_file (in, &type, &csize); +if (!data) +die ("malformed chunked object contents ('%s' does not exist)" , +sha1_to_hex (in)); +if (type !=OBJ_BLOB ) +die ("malformed chunked object contents (not a blob)" ); +if (size < ofs + csize) +die ("malformed chunked object contents (sizes do not add up)" ); +memcpy (buffer + ofs, data, csize); + ofs += csize; + curpos +=20 ; +free (data); + } +return buffer; +} +#define MAX_DELTA_CACHE (256)static size_t delta_base_cached;
@@ -1883,6 +1933,10 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,case OBJ_TAG : data =unpack_compressed_entry (p, &w_curs, curpos, *sizep);break ; +case OBJ_CHUNKED_BLOB : + data =unpack_chunked_entry (p, &w_curs, curpos, *sizep); + *type =OBJ_DEKNUHC (*type); +break ;default : data =NULL ; error("unknown object type %i at offset %"PRIuMAX" in %s",
t/t1050-large.sh +13 -1
@@ -124,8 +124,20 @@ test_expect_success 'split limit' ' # switch to a better chunking heuristics. echo cruft >head && cat split >>head && - git add head + git add head && + echo blob >expect && + git cat-file -t :split >actual && + test_cmp expect actual && + + git cat-file -p :split >actual && + # You probably do not want to use test_cmp here... + cmp split actual && + + mv split expect && + git checkout split && + # You probably do not want to use test_cmp here... + cmp expect split ) '
Signature · 1 line
1.7.8.rc4.177.g4d64
Re: [PATCH v2 5/5] bulk-checkin: replace fast-import based implementation
In reply to Junio C HamanoQuoted 13 lines · Junio C Hamano
builtin/add.c +4
-0@@ -458,11 +459,15 @@ int cmd_add(int argc, const char **argv, const char *prefix) free(seen); } + plug_bulk_checkin(); + exit_status |= add_files_to_cache(prefix, pathspec, flags); if (add_new_files) exit_status |= add_files(&dir, flags); + unplug_bulk_checkin(); +
Quoted 3 lines
finish:
if (active_cache_changed) {
if (write_cache(newfd, active_cache, active_nr)||
Also do the same for git-commit, except as-is commit case, for updating large files?
update-index should also learn about this, although at plumbing level, maybe we could have an option to let users choose what to stream (i.e. skip size check for streaming).
Signature · 1 line
Duy
Re: [PATCH v2 5/5] bulk-checkin: replace fast-import based implementation
Quoted 21 lines · Nguyen Thai Ngoc Duy
Quoted 13 lines · Junio C Hamano
builtin/add.c +4
-0@@ -458,11 +459,15 @@ int cmd_add(int argc, const char **argv, const char *prefix) free(seen); } + plug_bulk_checkin(); + exit_status |= add_files_to_cache(prefix, pathspec, flags); if (add_new_files) exit_status |= add_files(&dir, flags); + unplug_bulk_checkin(); +Quoted 3 lines
finish:
if (active_cache_changed) {
if (write_cache(newfd, active_cache, active_nr)||Also do the same for git-commit, except as-is commit case, for updating large files?
Quoted 1 line
update-index should also learn about this,...
I didn't do any of the above in this series and that was on purpose.
Getting plug/unplug (and all the machinery that they are related to) to do the right thing when they are called is far more important at this stage than figuring out when it is appropriate to plug and unplug in various random programs, it is sufficient to have one canonical and simplest callsite pair as an example in the primary interface to add new objects (i.e. "git add") for that purpose, and it is not too cumbersome for early adopters to remember using "git add" when adding oddball large blobs instead of using "commit -a".
In short, I wanted to keep the patch to the minimum to avoid distracting capable reviewers (which is in short supply these days).
I wouldn't stop you or anybody from preparing a patch series that adds plug/unplug pairs before the machinery is perfected, so that such an effort can expose a corner case where the machinery and the API presented in this series is inadequate and can use improvements. Once the machinery gets perfected, submit such a patch series to add users that are well tested.
Thanks.