Skip to content

Commit 48b3036

Browse files
committed
Merge branch 'jc/stream-to-pack'
* jc/stream-to-pack: bulk-checkin: replace fast-import based implementation csum-file: introduce sha1file_checkpoint finish_tmp_packfile(): a helper function create_tmp_packfile(): a helper function write_pack_header(): a helper function Conflicts: pack.h
2 parents e45c9b0 + 568508e commit 48b3036

16 files changed

+516
-134
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ LIB_H += argv-array.h
511511
LIB_H += attr.h
512512
LIB_H += blob.h
513513
LIB_H += builtin.h
514+
LIB_H += bulk-checkin.h
514515
LIB_H += cache.h
515516
LIB_H += cache-tree.h
516517
LIB_H += color.h
@@ -600,6 +601,7 @@ LIB_OBJS += base85.o
600601
LIB_OBJS += bisect.o
601602
LIB_OBJS += blob.o
602603
LIB_OBJS += branch.o
604+
LIB_OBJS += bulk-checkin.o
603605
LIB_OBJS += bundle.o
604606
LIB_OBJS += cache-tree.o
605607
LIB_OBJS += color.o

builtin/add.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "diff.h"
1414
#include "diffcore.h"
1515
#include "revision.h"
16+
#include "bulk-checkin.h"
1617

1718
static const char * const builtin_add_usage[] = {
1819
"git add [options] [--] <filepattern>...",
@@ -458,11 +459,15 @@ int cmd_add(int argc, const char **argv, const char *prefix)
458459
free(seen);
459460
}
460461

462+
plug_bulk_checkin();
463+
461464
exit_status |= add_files_to_cache(prefix, pathspec, flags);
462465

463466
if (add_new_files)
464467
exit_status |= add_files(&dir, flags);
465468

469+
unplug_bulk_checkin();
470+
466471
finish:
467472
if (active_cache_changed) {
468473
if (write_cache(newfd, active_cache, active_nr) ||

builtin/pack-objects.c

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static struct pack_idx_option pack_idx_opts;
7676
static const char *base_name;
7777
static int progress = 1;
7878
static int window = 10;
79-
static unsigned long pack_size_limit, pack_size_limit_cfg;
79+
static unsigned long pack_size_limit;
8080
static int depth = 50;
8181
static int delta_search_threads;
8282
static int pack_to_stdout;
@@ -638,7 +638,6 @@ static void write_pack_file(void)
638638
uint32_t i = 0, j;
639639
struct sha1file *f;
640640
off_t offset;
641-
struct pack_header hdr;
642641
uint32_t nr_remaining = nr_result;
643642
time_t last_mtime = 0;
644643
struct object_entry **write_order;
@@ -652,22 +651,14 @@ static void write_pack_file(void)
652651
unsigned char sha1[20];
653652
char *pack_tmp_name = NULL;
654653

655-
if (pack_to_stdout) {
654+
if (pack_to_stdout)
656655
f = sha1fd_throughput(1, "<stdout>", progress_state);
657-
} else {
658-
char tmpname[PATH_MAX];
659-
int fd;
660-
fd = odb_mkstemp(tmpname, sizeof(tmpname),
661-
"pack/tmp_pack_XXXXXX");
662-
pack_tmp_name = xstrdup(tmpname);
663-
f = sha1fd(fd, pack_tmp_name);
664-
}
665-
666-
hdr.hdr_signature = htonl(PACK_SIGNATURE);
667-
hdr.hdr_version = htonl(PACK_VERSION);
668-
hdr.hdr_entries = htonl(nr_remaining);
669-
sha1write(f, &hdr, sizeof(hdr));
670-
offset = sizeof(hdr);
656+
else
657+
f = create_tmp_packfile(&pack_tmp_name);
658+
659+
offset = write_pack_header(f, nr_remaining);
660+
if (!offset)
661+
die_errno("unable to write pack header");
671662
nr_written = 0;
672663
for (; i < nr_objects; i++) {
673664
struct object_entry *e = write_order[i];
@@ -693,49 +684,36 @@ static void write_pack_file(void)
693684

694685
if (!pack_to_stdout) {
695686
struct stat st;
696-
const char *idx_tmp_name;
697687
char tmpname[PATH_MAX];
698688

699-
idx_tmp_name = write_idx_file(NULL, written_list, nr_written,
700-
&pack_idx_opts, sha1);
701-
702-
snprintf(tmpname, sizeof(tmpname), "%s-%s.pack",
703-
base_name, sha1_to_hex(sha1));
704-
free_pack_by_name(tmpname);
705-
if (adjust_shared_perm(pack_tmp_name))
706-
die_errno("unable to make temporary pack file readable");
707-
if (rename(pack_tmp_name, tmpname))
708-
die_errno("unable to rename temporary pack file");
709-
710689
/*
711690
* Packs are runtime accessed in their mtime
712691
* order since newer packs are more likely to contain
713692
* younger objects. So if we are creating multiple
714693
* packs then we should modify the mtime of later ones
715694
* to preserve this property.
716695
*/
717-
if (stat(tmpname, &st) < 0) {
696+
if (stat(pack_tmp_name, &st) < 0) {
718697
warning("failed to stat %s: %s",
719-
tmpname, strerror(errno));
698+
pack_tmp_name, strerror(errno));
720699
} else if (!last_mtime) {
721700
last_mtime = st.st_mtime;
722701
} else {
723702
struct utimbuf utb;
724703
utb.actime = st.st_atime;
725704
utb.modtime = --last_mtime;
726-
if (utime(tmpname, &utb) < 0)
705+
if (utime(pack_tmp_name, &utb) < 0)
727706
warning("failed utime() on %s: %s",
728707
tmpname, strerror(errno));
729708
}
730709

731-
snprintf(tmpname, sizeof(tmpname), "%s-%s.idx",
732-
base_name, sha1_to_hex(sha1));
733-
if (adjust_shared_perm(idx_tmp_name))
734-
die_errno("unable to make temporary index file readable");
735-
if (rename(idx_tmp_name, tmpname))
736-
die_errno("unable to rename temporary index file");
737-
738-
free((void *) idx_tmp_name);
710+
/* Enough space for "-<sha-1>.pack"? */
711+
if (sizeof(tmpname) <= strlen(base_name) + 50)
712+
die("pack base name '%s' too long", base_name);
713+
snprintf(tmpname, sizeof(tmpname), "%s-", base_name);
714+
finish_tmp_packfile(tmpname, pack_tmp_name,
715+
written_list, nr_written,
716+
&pack_idx_opts, sha1);
739717
free(pack_tmp_name);
740718
puts(sha1_to_hex(sha1));
741719
}
@@ -2098,10 +2076,6 @@ static int git_pack_config(const char *k, const char *v, void *cb)
20982076
pack_idx_opts.version);
20992077
return 0;
21002078
}
2101-
if (!strcmp(k, "pack.packsizelimit")) {
2102-
pack_size_limit_cfg = git_config_ulong(k, v);
2103-
return 0;
2104-
}
21052079
return git_default_config(k, v, cb);
21062080
}
21072081

0 commit comments

Comments
 (0)