]>
git.ipfire.org Git - thirdparty/git.git/blob - fast-import.c
2 Format of STDIN stream:
12 new_blob ::= 'blob' lf
15 file_content ::= data;
17 new_commit ::= 'commit' sp ref_str lf
19 ('author' sp name '<' email '>' ts tz lf)?
20 'committer' sp name '<' email '>' ts tz lf
22 ('from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)?
23 ('merge' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)*
28 file_change ::= 'M' sp mode sp (hexsha1 | idnum) sp path_str lf
31 mode ::= '644' | '755';
33 new_tag ::= 'tag' sp tag_str lf
34 'from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf
35 'tagger' sp name '<' email '>' ts tz lf
39 reset_branch ::= 'reset' sp ref_str lf
40 ('from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)?
43 # note: the first idnum in a stream should be 1 and subsequent
44 # idnums should not have gaps between values as this will cause
45 # the stream parser to reserve space for the gapped values. An
46 # idnum can be updated in the future to a new object by issuing
47 # a new mark directive with the old idnum.
49 mark ::= 'mark' sp idnum lf;
51 # note: declen indicates the length of binary_data in bytes.
52 # declen does not include the lf preceeding or trailing the
55 data ::= 'data' sp declen lf
59 # note: quoted strings are C-style quoting supporting \c for
60 # common escapes of 'c' (e..g \n, \t, \\, \") or \nnn where nnn
61 # is the signed byte value in octal. Note that the only
62 # characters which must actually be escaped to protect the
63 # stream formatting is: \, " and LF. Otherwise these values
66 ref_str ::= ref | '"' quoted(ref) '"' ;
67 sha1exp_str ::= sha1exp | '"' quoted(sha1exp) '"' ;
68 tag_str ::= tag | '"' quoted(tag) '"' ;
69 path_str ::= path | '"' quoted(path) '"' ;
71 declen ::= # unsigned 32 bit value, ascii base10 notation;
72 binary_data ::= # file content, not interpreted;
74 sp ::= # ASCII space character;
75 lf ::= # ASCII newline (LF) character;
77 # note: a colon (':') must precede the numerical value assigned to
78 # an idnum. This is to distinguish it from a ref or tag name as
79 # GIT does not permit ':' in ref or tag strings.
82 path ::= # GIT style file path, e.g. "a/b/c";
83 ref ::= # GIT ref name, e.g. "refs/heads/MOZ_GECKO_EXPERIMENT";
84 tag ::= # GIT tag name, e.g. "FIREFOX_1_5";
85 sha1exp ::= # Any valid GIT SHA1 expression;
86 hexsha1 ::= # SHA1 in hexadecimal format;
88 # note: name and email are UTF8 strings, however name must not
89 # contain '<' or lf and email must not contain any of the
90 # following: '<', '>', lf.
92 name ::= # valid GIT author/committer name;
93 email ::= # valid GIT author/committer email;
94 ts ::= # time since the epoch in seconds, ascii base10 notation;
95 tz ::= # GIT style timezone;
106 #include "csum-file.h"
112 struct object_entry
*next
;
113 enum object_type type
;
114 unsigned long offset
;
115 unsigned char sha1
[20];
118 struct object_entry_pool
120 struct object_entry_pool
*next_pool
;
121 struct object_entry
*next_free
;
122 struct object_entry
*end
;
123 struct object_entry entries
[FLEX_ARRAY
]; /* more */
130 struct object_entry
*marked
[1024];
131 struct mark_set
*sets
[1024];
139 unsigned long offset
;
146 struct mem_pool
*next_pool
;
149 char space
[FLEX_ARRAY
]; /* more */
154 struct atom_str
*next_atom
;
156 char str_dat
[FLEX_ARRAY
]; /* more */
162 struct tree_content
*tree
;
163 struct atom_str
* name
;
167 unsigned char sha1
[20];
173 unsigned int entry_capacity
; /* must match avail_tree_content */
174 unsigned int entry_count
;
175 unsigned int delta_depth
;
176 struct tree_entry
*entries
[FLEX_ARRAY
]; /* more */
179 struct avail_tree_content
181 unsigned int entry_capacity
; /* must match tree_content */
182 struct avail_tree_content
*next_avail
;
187 struct branch
*table_next_branch
;
188 struct branch
*active_next_branch
;
190 unsigned long last_commit
;
191 struct tree_entry branch_tree
;
192 unsigned char sha1
[20];
197 struct tag
*next_tag
;
199 unsigned char sha1
[20];
210 struct hash_list
*next
;
211 unsigned char sha1
[20];
214 /* Stats and misc. counters */
215 static unsigned long max_depth
= 10;
216 static unsigned long alloc_count
;
217 static unsigned long branch_count
;
218 static unsigned long branch_load_count
;
219 static unsigned long remap_count
;
220 static unsigned long object_count
;
221 static unsigned long duplicate_count
;
222 static unsigned long marks_set_count
;
223 static unsigned long object_count_by_type
[9];
224 static unsigned long duplicate_count_by_type
[9];
225 static unsigned long delta_count_by_type
[9];
228 static size_t mem_pool_alloc
= 2*1024*1024 - sizeof(struct mem_pool
);
229 static size_t total_allocd
;
230 static struct mem_pool
*mem_pool
;
232 /* Atom management */
233 static unsigned int atom_table_sz
= 4451;
234 static unsigned int atom_cnt
;
235 static struct atom_str
**atom_table
;
237 /* The .pack file being generated */
238 static struct packed_git
*pack_data
;
240 static unsigned long pack_size
;
241 static unsigned char pack_sha1
[20];
243 /* Table of objects we've written. */
244 static unsigned int object_entry_alloc
= 5000;
245 static struct object_entry_pool
*blocks
;
246 static struct object_entry
*object_table
[1 << 16];
247 static struct mark_set
*marks
;
248 static const char* mark_file
;
251 static struct last_object last_blob
;
253 /* Tree management */
254 static unsigned int tree_entry_alloc
= 1000;
255 static void *avail_tree_entry
;
256 static unsigned int avail_tree_table_sz
= 100;
257 static struct avail_tree_content
**avail_tree_table
;
258 static struct dbuf old_tree
;
259 static struct dbuf new_tree
;
262 static unsigned long max_active_branches
= 5;
263 static unsigned long cur_active_branches
;
264 static unsigned long branch_table_sz
= 1039;
265 static struct branch
**branch_table
;
266 static struct branch
*active_branches
;
269 static struct tag
*first_tag
;
270 static struct tag
*last_tag
;
272 /* Input stream parsing */
273 static struct strbuf command_buf
;
274 static unsigned long next_mark
;
275 static struct dbuf new_data
;
276 static FILE* branch_log
;
279 static void alloc_objects(int cnt
)
281 struct object_entry_pool
*b
;
283 b
= xmalloc(sizeof(struct object_entry_pool
)
284 + cnt
* sizeof(struct object_entry
));
285 b
->next_pool
= blocks
;
286 b
->next_free
= b
->entries
;
287 b
->end
= b
->entries
+ cnt
;
292 static struct object_entry
* new_object(unsigned char *sha1
)
294 struct object_entry
*e
;
296 if (blocks
->next_free
== blocks
->end
)
297 alloc_objects(object_entry_alloc
);
299 e
= blocks
->next_free
++;
300 hashcpy(e
->sha1
, sha1
);
304 static struct object_entry
* find_object(unsigned char *sha1
)
306 unsigned int h
= sha1
[0] << 8 | sha1
[1];
307 struct object_entry
*e
;
308 for (e
= object_table
[h
]; e
; e
= e
->next
)
309 if (!hashcmp(sha1
, e
->sha1
))
314 static struct object_entry
* insert_object(unsigned char *sha1
)
316 unsigned int h
= sha1
[0] << 8 | sha1
[1];
317 struct object_entry
*e
= object_table
[h
];
318 struct object_entry
*p
= NULL
;
321 if (!hashcmp(sha1
, e
->sha1
))
327 e
= new_object(sha1
);
337 static unsigned int hc_str(const char *s
, size_t len
)
345 static void* pool_alloc(size_t len
)
350 for (p
= mem_pool
; p
; p
= p
->next_pool
)
351 if ((p
->end
- p
->next_free
>= len
))
355 if (len
>= (mem_pool_alloc
/2)) {
359 total_allocd
+= sizeof(struct mem_pool
) + mem_pool_alloc
;
360 p
= xmalloc(sizeof(struct mem_pool
) + mem_pool_alloc
);
361 p
->next_pool
= mem_pool
;
362 p
->next_free
= p
->space
;
363 p
->end
= p
->next_free
+ mem_pool_alloc
;
368 /* round out to a pointer alignment */
369 if (len
& (sizeof(void*) - 1))
370 len
+= sizeof(void*) - (len
& (sizeof(void*) - 1));
375 static void* pool_calloc(size_t count
, size_t size
)
377 size_t len
= count
* size
;
378 void *r
= pool_alloc(len
);
383 static char* pool_strdup(const char *s
)
385 char *r
= pool_alloc(strlen(s
) + 1);
390 static void size_dbuf(struct dbuf
*b
, size_t maxlen
)
393 if (b
->capacity
>= maxlen
)
397 b
->capacity
= ((maxlen
/ 1024) + 1) * 1024;
398 b
->buffer
= xmalloc(b
->capacity
);
401 static void insert_mark(unsigned long idnum
, struct object_entry
*oe
)
403 struct mark_set
*s
= marks
;
404 while ((idnum
>> s
->shift
) >= 1024) {
405 s
= pool_calloc(1, sizeof(struct mark_set
));
406 s
->shift
= marks
->shift
+ 10;
407 s
->data
.sets
[0] = marks
;
411 unsigned long i
= idnum
>> s
->shift
;
412 idnum
-= i
<< s
->shift
;
413 if (!s
->data
.sets
[i
]) {
414 s
->data
.sets
[i
] = pool_calloc(1, sizeof(struct mark_set
));
415 s
->data
.sets
[i
]->shift
= s
->shift
- 10;
419 if (!s
->data
.marked
[idnum
])
421 s
->data
.marked
[idnum
] = oe
;
424 static struct object_entry
* find_mark(unsigned long idnum
)
426 unsigned long orig_idnum
= idnum
;
427 struct mark_set
*s
= marks
;
428 struct object_entry
*oe
= NULL
;
429 if ((idnum
>> s
->shift
) < 1024) {
430 while (s
&& s
->shift
) {
431 unsigned long i
= idnum
>> s
->shift
;
432 idnum
-= i
<< s
->shift
;
436 oe
= s
->data
.marked
[idnum
];
439 die("mark :%lu not declared", orig_idnum
);
443 static struct atom_str
* to_atom(const char *s
, size_t len
)
445 unsigned int hc
= hc_str(s
, len
) % atom_table_sz
;
448 for (c
= atom_table
[hc
]; c
; c
= c
->next_atom
)
449 if (c
->str_len
== len
&& !strncmp(s
, c
->str_dat
, len
))
452 c
= pool_alloc(sizeof(struct atom_str
) + len
+ 1);
454 strncpy(c
->str_dat
, s
, len
);
456 c
->next_atom
= atom_table
[hc
];
462 static struct branch
* lookup_branch(const char *name
)
464 unsigned int hc
= hc_str(name
, strlen(name
)) % branch_table_sz
;
467 for (b
= branch_table
[hc
]; b
; b
= b
->table_next_branch
)
468 if (!strcmp(name
, b
->name
))
473 static struct branch
* new_branch(const char *name
)
475 unsigned int hc
= hc_str(name
, strlen(name
)) % branch_table_sz
;
476 struct branch
* b
= lookup_branch(name
);
479 die("Invalid attempt to create duplicate branch: %s", name
);
480 if (check_ref_format(name
))
481 die("Branch name doesn't conform to GIT standards: %s", name
);
483 b
= pool_calloc(1, sizeof(struct branch
));
484 b
->name
= pool_strdup(name
);
485 b
->table_next_branch
= branch_table
[hc
];
486 b
->branch_tree
.versions
[0].mode
= S_IFDIR
;
487 b
->branch_tree
.versions
[1].mode
= S_IFDIR
;
488 branch_table
[hc
] = b
;
493 static unsigned int hc_entries(unsigned int cnt
)
495 cnt
= cnt
& 7 ? (cnt
/ 8) + 1 : cnt
/ 8;
496 return cnt
< avail_tree_table_sz
? cnt
: avail_tree_table_sz
- 1;
499 static struct tree_content
* new_tree_content(unsigned int cnt
)
501 struct avail_tree_content
*f
, *l
= NULL
;
502 struct tree_content
*t
;
503 unsigned int hc
= hc_entries(cnt
);
505 for (f
= avail_tree_table
[hc
]; f
; l
= f
, f
= f
->next_avail
)
506 if (f
->entry_capacity
>= cnt
)
511 l
->next_avail
= f
->next_avail
;
513 avail_tree_table
[hc
] = f
->next_avail
;
515 cnt
= cnt
& 7 ? ((cnt
/ 8) + 1) * 8 : cnt
;
516 f
= pool_alloc(sizeof(*t
) + sizeof(t
->entries
[0]) * cnt
);
517 f
->entry_capacity
= cnt
;
520 t
= (struct tree_content
*)f
;
526 static void release_tree_entry(struct tree_entry
*e
);
527 static void release_tree_content(struct tree_content
*t
)
529 struct avail_tree_content
*f
= (struct avail_tree_content
*)t
;
530 unsigned int hc
= hc_entries(f
->entry_capacity
);
531 f
->next_avail
= avail_tree_table
[hc
];
532 avail_tree_table
[hc
] = f
;
535 static void release_tree_content_recursive(struct tree_content
*t
)
538 for (i
= 0; i
< t
->entry_count
; i
++)
539 release_tree_entry(t
->entries
[i
]);
540 release_tree_content(t
);
543 static struct tree_content
* grow_tree_content(
544 struct tree_content
*t
,
547 struct tree_content
*r
= new_tree_content(t
->entry_count
+ amt
);
548 r
->entry_count
= t
->entry_count
;
549 r
->delta_depth
= t
->delta_depth
;
550 memcpy(r
->entries
,t
->entries
,t
->entry_count
*sizeof(t
->entries
[0]));
551 release_tree_content(t
);
555 static struct tree_entry
* new_tree_entry()
557 struct tree_entry
*e
;
559 if (!avail_tree_entry
) {
560 unsigned int n
= tree_entry_alloc
;
561 total_allocd
+= n
* sizeof(struct tree_entry
);
562 avail_tree_entry
= e
= xmalloc(n
* sizeof(struct tree_entry
));
564 *((void**)e
) = e
+ 1;
570 e
= avail_tree_entry
;
571 avail_tree_entry
= *((void**)e
);
575 static void release_tree_entry(struct tree_entry
*e
)
578 release_tree_content_recursive(e
->tree
);
579 *((void**)e
) = avail_tree_entry
;
580 avail_tree_entry
= e
;
583 static void yread(int fd
, void *buffer
, size_t length
)
586 while (ret
< length
) {
587 ssize_t size
= xread(fd
, (char *) buffer
+ ret
, length
- ret
);
589 die("Read from descriptor %i: end of stream", fd
);
591 die("Read from descriptor %i: %s", fd
, strerror(errno
));
596 static size_t encode_header(
597 enum object_type type
,
604 if (type
< OBJ_COMMIT
|| type
> OBJ_REF_DELTA
)
605 die("bad type %d", type
);
607 c
= (type
<< 4) | (size
& 15);
619 static int store_object(
620 enum object_type type
,
623 struct last_object
*last
,
624 unsigned char *sha1out
,
628 struct object_entry
*e
;
629 unsigned char hdr
[96];
630 unsigned char sha1
[20];
631 unsigned long hdrlen
, deltalen
;
635 hdrlen
= sprintf((char*)hdr
,"%s %lu",type_names
[type
],datlen
) + 1;
637 SHA1_Update(&c
, hdr
, hdrlen
);
638 SHA1_Update(&c
, dat
, datlen
);
639 SHA1_Final(sha1
, &c
);
641 hashcpy(sha1out
, sha1
);
643 e
= insert_object(sha1
);
645 insert_mark(mark
, e
);
648 duplicate_count_by_type
[type
]++;
652 e
->offset
= pack_size
;
654 object_count_by_type
[type
]++;
656 if (last
&& last
->data
&& last
->depth
< max_depth
)
657 delta
= diff_delta(last
->data
, last
->len
,
663 memset(&s
, 0, sizeof(s
));
664 deflateInit(&s
, zlib_compression_level
);
667 unsigned long ofs
= e
->offset
- last
->offset
;
668 unsigned pos
= sizeof(hdr
) - 1;
670 delta_count_by_type
[type
]++;
673 s
.avail_in
= deltalen
;
675 hdrlen
= encode_header(OBJ_OFS_DELTA
, deltalen
, hdr
);
676 write_or_die(pack_fd
, hdr
, hdrlen
);
679 hdr
[pos
] = ofs
& 127;
681 hdr
[--pos
] = 128 | (--ofs
& 127);
682 write_or_die(pack_fd
, hdr
+ pos
, sizeof(hdr
) - pos
);
683 pack_size
+= sizeof(hdr
) - pos
;
689 hdrlen
= encode_header(type
, datlen
, hdr
);
690 write_or_die(pack_fd
, hdr
, hdrlen
);
694 s
.avail_out
= deflateBound(&s
, s
.avail_in
);
695 s
.next_out
= out
= xmalloc(s
.avail_out
);
696 while (deflate(&s
, Z_FINISH
) == Z_OK
)
700 write_or_die(pack_fd
, out
, s
.total_out
);
701 pack_size
+= s
.total_out
;
707 if (last
->data
&& !last
->no_free
)
710 last
->offset
= e
->offset
;
716 static void *gfi_unpack_entry(unsigned long ofs
, unsigned long *sizep
)
719 pack_data
->pack_size
= pack_size
+ 20;
720 return unpack_entry(pack_data
, ofs
, type
, sizep
);
723 static const char *get_mode(const char *str
, unsigned int *modep
)
726 unsigned int mode
= 0;
728 while ((c
= *str
++) != ' ') {
729 if (c
< '0' || c
> '7')
731 mode
= (mode
<< 3) + (c
- '0');
737 static void load_tree(struct tree_entry
*root
)
739 unsigned char* sha1
= root
->versions
[1].sha1
;
740 struct object_entry
*myoe
;
741 struct tree_content
*t
;
746 root
->tree
= t
= new_tree_content(8);
747 if (is_null_sha1(sha1
))
750 myoe
= find_object(sha1
);
752 if (myoe
->type
!= OBJ_TREE
)
753 die("Not a tree: %s", sha1_to_hex(sha1
));
755 buf
= gfi_unpack_entry(myoe
->offset
, &size
);
758 buf
= read_sha1_file(sha1
, type
, &size
);
759 if (!buf
|| strcmp(type
, tree_type
))
760 die("Can't load tree %s", sha1_to_hex(sha1
));
764 while (c
!= (buf
+ size
)) {
765 struct tree_entry
*e
= new_tree_entry();
767 if (t
->entry_count
== t
->entry_capacity
)
768 root
->tree
= t
= grow_tree_content(t
, 8);
769 t
->entries
[t
->entry_count
++] = e
;
772 c
= get_mode(c
, &e
->versions
[1].mode
);
774 die("Corrupt mode in %s", sha1_to_hex(sha1
));
775 e
->versions
[0].mode
= e
->versions
[1].mode
;
776 e
->name
= to_atom(c
, strlen(c
));
777 c
+= e
->name
->str_len
+ 1;
778 hashcpy(e
->versions
[0].sha1
, (unsigned char*)c
);
779 hashcpy(e
->versions
[1].sha1
, (unsigned char*)c
);
785 static int tecmp0 (const void *_a
, const void *_b
)
787 struct tree_entry
*a
= *((struct tree_entry
**)_a
);
788 struct tree_entry
*b
= *((struct tree_entry
**)_b
);
789 return base_name_compare(
790 a
->name
->str_dat
, a
->name
->str_len
, a
->versions
[0].mode
,
791 b
->name
->str_dat
, b
->name
->str_len
, b
->versions
[0].mode
);
794 static int tecmp1 (const void *_a
, const void *_b
)
796 struct tree_entry
*a
= *((struct tree_entry
**)_a
);
797 struct tree_entry
*b
= *((struct tree_entry
**)_b
);
798 return base_name_compare(
799 a
->name
->str_dat
, a
->name
->str_len
, a
->versions
[1].mode
,
800 b
->name
->str_dat
, b
->name
->str_len
, b
->versions
[1].mode
);
803 static void mktree(struct tree_content
*t
,
813 qsort(t
->entries
,t
->entry_count
,sizeof(t
->entries
[0]),tecmp0
);
815 qsort(t
->entries
,t
->entry_count
,sizeof(t
->entries
[0]),tecmp1
);
817 for (i
= 0; i
< t
->entry_count
; i
++) {
818 if (t
->entries
[i
]->versions
[v
].mode
)
819 maxlen
+= t
->entries
[i
]->name
->str_len
+ 34;
822 size_dbuf(b
, maxlen
);
824 for (i
= 0; i
< t
->entry_count
; i
++) {
825 struct tree_entry
*e
= t
->entries
[i
];
826 if (!e
->versions
[v
].mode
)
828 c
+= sprintf(c
, "%o", e
->versions
[v
].mode
);
830 strcpy(c
, e
->name
->str_dat
);
831 c
+= e
->name
->str_len
+ 1;
832 hashcpy((unsigned char*)c
, e
->versions
[v
].sha1
);
835 *szp
= c
- (char*)b
->buffer
;
838 static void store_tree(struct tree_entry
*root
)
840 struct tree_content
*t
= root
->tree
;
841 unsigned int i
, j
, del
;
842 unsigned long new_len
;
843 struct last_object lo
;
844 struct object_entry
*le
;
846 if (!is_null_sha1(root
->versions
[1].sha1
))
849 for (i
= 0; i
< t
->entry_count
; i
++) {
850 if (t
->entries
[i
]->tree
)
851 store_tree(t
->entries
[i
]);
854 le
= find_object(root
->versions
[0].sha1
);
855 if (!S_ISDIR(root
->versions
[0].mode
) || !le
) {
859 mktree(t
, 0, &lo
.len
, &old_tree
);
860 lo
.data
= old_tree
.buffer
;
861 lo
.offset
= le
->offset
;
862 lo
.depth
= t
->delta_depth
;
866 mktree(t
, 1, &new_len
, &new_tree
);
867 store_object(OBJ_TREE
, new_tree
.buffer
, new_len
,
868 &lo
, root
->versions
[1].sha1
, 0);
870 t
->delta_depth
= lo
.depth
;
871 for (i
= 0, j
= 0, del
= 0; i
< t
->entry_count
; i
++) {
872 struct tree_entry
*e
= t
->entries
[i
];
873 if (e
->versions
[1].mode
) {
874 e
->versions
[0].mode
= e
->versions
[1].mode
;
875 hashcpy(e
->versions
[0].sha1
, e
->versions
[1].sha1
);
878 release_tree_entry(e
);
882 t
->entry_count
-= del
;
885 static int tree_content_set(
886 struct tree_entry
*root
,
888 const unsigned char *sha1
,
889 const unsigned int mode
)
891 struct tree_content
*t
= root
->tree
;
894 struct tree_entry
*e
;
896 slash1
= strchr(p
, '/');
902 for (i
= 0; i
< t
->entry_count
; i
++) {
904 if (e
->name
->str_len
== n
&& !strncmp(p
, e
->name
->str_dat
, n
)) {
906 if (e
->versions
[1].mode
== mode
907 && !hashcmp(e
->versions
[1].sha1
, sha1
))
909 e
->versions
[1].mode
= mode
;
910 hashcpy(e
->versions
[1].sha1
, sha1
);
912 release_tree_content_recursive(e
->tree
);
915 hashclr(root
->versions
[1].sha1
);
918 if (!S_ISDIR(e
->versions
[1].mode
)) {
919 e
->tree
= new_tree_content(8);
920 e
->versions
[1].mode
= S_IFDIR
;
924 if (tree_content_set(e
, slash1
+ 1, sha1
, mode
)) {
925 hashclr(root
->versions
[1].sha1
);
932 if (t
->entry_count
== t
->entry_capacity
)
933 root
->tree
= t
= grow_tree_content(t
, 8);
934 e
= new_tree_entry();
935 e
->name
= to_atom(p
, n
);
936 e
->versions
[0].mode
= 0;
937 hashclr(e
->versions
[0].sha1
);
938 t
->entries
[t
->entry_count
++] = e
;
940 e
->tree
= new_tree_content(8);
941 e
->versions
[1].mode
= S_IFDIR
;
942 tree_content_set(e
, slash1
+ 1, sha1
, mode
);
945 e
->versions
[1].mode
= mode
;
946 hashcpy(e
->versions
[1].sha1
, sha1
);
948 hashclr(root
->versions
[1].sha1
);
952 static int tree_content_remove(struct tree_entry
*root
, const char *p
)
954 struct tree_content
*t
= root
->tree
;
957 struct tree_entry
*e
;
959 slash1
= strchr(p
, '/');
965 for (i
= 0; i
< t
->entry_count
; i
++) {
967 if (e
->name
->str_len
== n
&& !strncmp(p
, e
->name
->str_dat
, n
)) {
968 if (!slash1
|| !S_ISDIR(e
->versions
[1].mode
))
972 if (tree_content_remove(e
, slash1
+ 1)) {
973 for (n
= 0; n
< e
->tree
->entry_count
; n
++) {
974 if (e
->tree
->entries
[n
]->versions
[1].mode
) {
975 hashclr(root
->versions
[1].sha1
);
988 release_tree_content_recursive(e
->tree
);
991 e
->versions
[1].mode
= 0;
992 hashclr(e
->versions
[1].sha1
);
993 hashclr(root
->versions
[1].sha1
);
997 static void init_pack_header()
999 struct pack_header hdr
;
1001 hdr
.hdr_signature
= htonl(PACK_SIGNATURE
);
1002 hdr
.hdr_version
= htonl(2);
1003 hdr
.hdr_entries
= 0;
1005 write_or_die(pack_fd
, &hdr
, sizeof(hdr
));
1006 pack_size
= sizeof(hdr
);
1009 static void fixup_header_footer()
1017 if (lseek(pack_fd
, 0, SEEK_SET
) != 0)
1018 die("Failed seeking to start: %s", strerror(errno
));
1021 yread(pack_fd
, hdr
, 8);
1022 SHA1_Update(&c
, hdr
, 8);
1024 cnt
= htonl(object_count
);
1025 SHA1_Update(&c
, &cnt
, 4);
1026 write_or_die(pack_fd
, &cnt
, 4);
1028 buf
= xmalloc(128 * 1024);
1030 n
= xread(pack_fd
, buf
, 128 * 1024);
1033 SHA1_Update(&c
, buf
, n
);
1037 SHA1_Final(pack_sha1
, &c
);
1038 write_or_die(pack_fd
, pack_sha1
, sizeof(pack_sha1
));
1041 static int oecmp (const void *_a
, const void *_b
)
1043 struct object_entry
*a
= *((struct object_entry
**)_a
);
1044 struct object_entry
*b
= *((struct object_entry
**)_b
);
1045 return hashcmp(a
->sha1
, b
->sha1
);
1048 static void write_index(const char *idx_name
)
1051 struct object_entry
**idx
, **c
, **last
;
1052 struct object_entry
*e
;
1053 struct object_entry_pool
*o
;
1054 unsigned int array
[256];
1057 /* Build the sorted table of object IDs. */
1058 idx
= xmalloc(object_count
* sizeof(struct object_entry
*));
1060 for (o
= blocks
; o
; o
= o
->next_pool
)
1061 for (e
= o
->entries
; e
!= o
->next_free
; e
++)
1063 last
= idx
+ object_count
;
1064 qsort(idx
, object_count
, sizeof(struct object_entry
*), oecmp
);
1066 /* Generate the fan-out array. */
1068 for (i
= 0; i
< 256; i
++) {
1069 struct object_entry
**next
= c
;;
1070 while (next
< last
) {
1071 if ((*next
)->sha1
[0] != i
)
1075 array
[i
] = htonl(next
- idx
);
1079 f
= sha1create("%s", idx_name
);
1080 sha1write(f
, array
, 256 * sizeof(int));
1081 for (c
= idx
; c
!= last
; c
++) {
1082 unsigned int offset
= htonl((*c
)->offset
);
1083 sha1write(f
, &offset
, 4);
1084 sha1write(f
, (*c
)->sha1
, sizeof((*c
)->sha1
));
1086 sha1write(f
, pack_sha1
, sizeof(pack_sha1
));
1087 sha1close(f
, NULL
, 1);
1091 static void dump_branches()
1093 static const char *msg
= "fast-import";
1096 struct ref_lock
*lock
;
1098 for (i
= 0; i
< branch_table_sz
; i
++) {
1099 for (b
= branch_table
[i
]; b
; b
= b
->table_next_branch
) {
1100 lock
= lock_any_ref_for_update(b
->name
, NULL
);
1101 if (!lock
|| write_ref_sha1(lock
, b
->sha1
, msg
) < 0)
1102 die("Can't write %s", b
->name
);
1107 static void dump_tags()
1109 static const char *msg
= "fast-import";
1111 struct ref_lock
*lock
;
1112 char path
[PATH_MAX
];
1114 for (t
= first_tag
; t
; t
= t
->next_tag
) {
1115 sprintf(path
, "refs/tags/%s", t
->name
);
1116 lock
= lock_any_ref_for_update(path
, NULL
);
1117 if (!lock
|| write_ref_sha1(lock
, t
->sha1
, msg
) < 0)
1118 die("Can't write %s", path
);
1122 static void dump_marks_helper(FILE *f
,
1128 for (k
= 0; k
< 1024; k
++) {
1129 if (m
->data
.sets
[k
])
1130 dump_marks_helper(f
, (base
+ k
) << m
->shift
,
1134 for (k
= 0; k
< 1024; k
++) {
1135 if (m
->data
.marked
[k
])
1136 fprintf(f
, ":%lu %s\n", base
+ k
,
1137 sha1_to_hex(m
->data
.marked
[k
]->sha1
));
1142 static void dump_marks()
1146 FILE *f
= fopen(mark_file
, "w");
1147 dump_marks_helper(f
, 0, marks
);
1152 static void read_next_command()
1154 read_line(&command_buf
, stdin
, '\n');
1157 static void cmd_mark()
1159 if (!strncmp("mark :", command_buf
.buf
, 6)) {
1160 next_mark
= strtoul(command_buf
.buf
+ 6, NULL
, 10);
1161 read_next_command();
1167 static void* cmd_data (size_t *size
)
1173 if (strncmp("data ", command_buf
.buf
, 5))
1174 die("Expected 'data n' command, found: %s", command_buf
.buf
);
1176 length
= strtoul(command_buf
.buf
+ 5, NULL
, 10);
1177 buffer
= xmalloc(length
);
1179 while (n
< length
) {
1180 size_t s
= fread((char*)buffer
+ n
, 1, length
- n
, stdin
);
1181 if (!s
&& feof(stdin
))
1182 die("EOF in data (%lu bytes remaining)", length
- n
);
1186 if (fgetc(stdin
) != '\n')
1187 die("An lf did not trail the binary data as expected.");
1193 static void cmd_new_blob()
1198 read_next_command();
1202 if (store_object(OBJ_BLOB
, d
, l
, &last_blob
, NULL
, next_mark
))
1206 static void unload_one_branch()
1208 while (cur_active_branches
1209 && cur_active_branches
>= max_active_branches
) {
1210 unsigned long min_commit
= ULONG_MAX
;
1211 struct branch
*e
, *l
= NULL
, *p
= NULL
;
1213 for (e
= active_branches
; e
; e
= e
->active_next_branch
) {
1214 if (e
->last_commit
< min_commit
) {
1216 min_commit
= e
->last_commit
;
1222 e
= p
->active_next_branch
;
1223 p
->active_next_branch
= e
->active_next_branch
;
1225 e
= active_branches
;
1226 active_branches
= e
->active_next_branch
;
1228 e
->active_next_branch
= NULL
;
1229 if (e
->branch_tree
.tree
) {
1230 release_tree_content_recursive(e
->branch_tree
.tree
);
1231 e
->branch_tree
.tree
= NULL
;
1233 cur_active_branches
--;
1237 static void load_branch(struct branch
*b
)
1239 load_tree(&b
->branch_tree
);
1240 b
->active_next_branch
= active_branches
;
1241 active_branches
= b
;
1242 cur_active_branches
++;
1243 branch_load_count
++;
1246 static void file_change_m(struct branch
*b
)
1248 const char *p
= command_buf
.buf
+ 2;
1251 struct object_entry
*oe
;
1252 unsigned char sha1
[20];
1256 p
= get_mode(p
, &mode
);
1258 die("Corrupt mode: %s", command_buf
.buf
);
1260 case S_IFREG
| 0644:
1261 case S_IFREG
| 0755:
1268 die("Corrupt mode: %s", command_buf
.buf
);
1273 oe
= find_mark(strtoul(p
+ 1, &x
, 10));
1274 hashcpy(sha1
, oe
->sha1
);
1277 if (get_sha1_hex(p
, sha1
))
1278 die("Invalid SHA1: %s", command_buf
.buf
);
1279 oe
= find_object(sha1
);
1283 die("Missing space after SHA1: %s", command_buf
.buf
);
1285 p_uq
= unquote_c_style(p
, &endp
);
1288 die("Garbage after path in: %s", command_buf
.buf
);
1293 if (oe
->type
!= OBJ_BLOB
)
1294 die("Not a blob (actually a %s): %s",
1295 command_buf
.buf
, type_names
[oe
->type
]);
1297 if (sha1_object_info(sha1
, type
, NULL
))
1298 die("Blob not found: %s", command_buf
.buf
);
1299 if (strcmp(blob_type
, type
))
1300 die("Not a blob (actually a %s): %s",
1301 command_buf
.buf
, type
);
1304 tree_content_set(&b
->branch_tree
, p
, sha1
, S_IFREG
| mode
);
1310 static void file_change_d(struct branch
*b
)
1312 const char *p
= command_buf
.buf
+ 2;
1316 p_uq
= unquote_c_style(p
, &endp
);
1319 die("Garbage after path in: %s", command_buf
.buf
);
1322 tree_content_remove(&b
->branch_tree
, p
);
1327 static void cmd_from(struct branch
*b
)
1329 const char *from
, *endp
;
1333 if (strncmp("from ", command_buf
.buf
, 5))
1337 die("Can't reinitailize branch %s", b
->name
);
1339 from
= strchr(command_buf
.buf
, ' ') + 1;
1340 str_uq
= unquote_c_style(from
, &endp
);
1343 die("Garbage after string in: %s", command_buf
.buf
);
1347 s
= lookup_branch(from
);
1349 die("Can't create a branch from itself: %s", b
->name
);
1351 unsigned char *t
= s
->branch_tree
.versions
[1].sha1
;
1352 hashcpy(b
->sha1
, s
->sha1
);
1353 hashcpy(b
->branch_tree
.versions
[0].sha1
, t
);
1354 hashcpy(b
->branch_tree
.versions
[1].sha1
, t
);
1355 } else if (*from
== ':') {
1356 unsigned long idnum
= strtoul(from
+ 1, NULL
, 10);
1357 struct object_entry
*oe
= find_mark(idnum
);
1360 if (oe
->type
!= OBJ_COMMIT
)
1361 die("Mark :%lu not a commit", idnum
);
1362 hashcpy(b
->sha1
, oe
->sha1
);
1363 buf
= gfi_unpack_entry(oe
->offset
, &size
);
1364 if (!buf
|| size
< 46)
1365 die("Not a valid commit: %s", from
);
1366 if (memcmp("tree ", buf
, 5)
1367 || get_sha1_hex(buf
+ 5, b
->branch_tree
.versions
[1].sha1
))
1368 die("The commit %s is corrupt", sha1_to_hex(b
->sha1
));
1370 hashcpy(b
->branch_tree
.versions
[0].sha1
,
1371 b
->branch_tree
.versions
[1].sha1
);
1372 } else if (!get_sha1(from
, b
->sha1
)) {
1373 if (is_null_sha1(b
->sha1
)) {
1374 hashclr(b
->branch_tree
.versions
[0].sha1
);
1375 hashclr(b
->branch_tree
.versions
[1].sha1
);
1380 buf
= read_object_with_reference(b
->sha1
,
1381 type_names
[OBJ_COMMIT
], &size
, b
->sha1
);
1382 if (!buf
|| size
< 46)
1383 die("Not a valid commit: %s", from
);
1384 if (memcmp("tree ", buf
, 5)
1385 || get_sha1_hex(buf
+ 5, b
->branch_tree
.versions
[1].sha1
))
1386 die("The commit %s is corrupt", sha1_to_hex(b
->sha1
));
1388 hashcpy(b
->branch_tree
.versions
[0].sha1
,
1389 b
->branch_tree
.versions
[1].sha1
);
1392 die("Invalid ref name or SHA1 expression: %s", from
);
1394 read_next_command();
1397 static struct hash_list
* cmd_merge(unsigned int *count
)
1399 struct hash_list
*list
= NULL
, *n
, *e
;
1400 const char *from
, *endp
;
1405 while (!strncmp("merge ", command_buf
.buf
, 6)) {
1406 from
= strchr(command_buf
.buf
, ' ') + 1;
1407 str_uq
= unquote_c_style(from
, &endp
);
1410 die("Garbage after string in: %s", command_buf
.buf
);
1414 n
= xmalloc(sizeof(*n
));
1415 s
= lookup_branch(from
);
1417 hashcpy(n
->sha1
, s
->sha1
);
1418 else if (*from
== ':') {
1419 unsigned long idnum
= strtoul(from
+ 1, NULL
, 10);
1420 struct object_entry
*oe
= find_mark(idnum
);
1421 if (oe
->type
!= OBJ_COMMIT
)
1422 die("Mark :%lu not a commit", idnum
);
1423 hashcpy(n
->sha1
, oe
->sha1
);
1424 } else if (get_sha1(from
, n
->sha1
))
1425 die("Invalid ref name or SHA1 expression: %s", from
);
1434 read_next_command();
1439 static void cmd_new_commit()
1447 char *author
= NULL
;
1448 char *committer
= NULL
;
1449 struct hash_list
*merge_list
= NULL
;
1450 unsigned int merge_count
;
1452 /* Obtain the branch name from the rest of our command */
1453 sp
= strchr(command_buf
.buf
, ' ') + 1;
1454 str_uq
= unquote_c_style(sp
, &endp
);
1457 die("Garbage after ref in: %s", command_buf
.buf
);
1460 b
= lookup_branch(sp
);
1466 read_next_command();
1468 if (!strncmp("author ", command_buf
.buf
, 7)) {
1469 author
= strdup(command_buf
.buf
);
1470 read_next_command();
1472 if (!strncmp("committer ", command_buf
.buf
, 10)) {
1473 committer
= strdup(command_buf
.buf
);
1474 read_next_command();
1477 die("Expected committer but didn't get one");
1478 msg
= cmd_data(&msglen
);
1479 read_next_command();
1481 merge_list
= cmd_merge(&merge_count
);
1483 /* ensure the branch is active/loaded */
1484 if (!b
->branch_tree
.tree
|| !max_active_branches
) {
1485 unload_one_branch();
1491 if (1 == command_buf
.len
)
1493 else if (!strncmp("M ", command_buf
.buf
, 2))
1495 else if (!strncmp("D ", command_buf
.buf
, 2))
1498 die("Unsupported file_change: %s", command_buf
.buf
);
1499 read_next_command();
1502 /* build the tree and the commit */
1503 store_tree(&b
->branch_tree
);
1504 hashcpy(b
->branch_tree
.versions
[0].sha1
,
1505 b
->branch_tree
.versions
[1].sha1
);
1506 size_dbuf(&new_data
, 97 + msglen
1509 ? strlen(author
) + strlen(committer
)
1510 : 2 * strlen(committer
)));
1511 sp
= new_data
.buffer
;
1512 sp
+= sprintf(sp
, "tree %s\n",
1513 sha1_to_hex(b
->branch_tree
.versions
[1].sha1
));
1514 if (!is_null_sha1(b
->sha1
))
1515 sp
+= sprintf(sp
, "parent %s\n", sha1_to_hex(b
->sha1
));
1516 while (merge_list
) {
1517 struct hash_list
*next
= merge_list
->next
;
1518 sp
+= sprintf(sp
, "parent %s\n", sha1_to_hex(merge_list
->sha1
));
1523 sp
+= sprintf(sp
, "%s\n", author
);
1525 sp
+= sprintf(sp
, "author %s\n", committer
+ 10);
1526 sp
+= sprintf(sp
, "%s\n\n", committer
);
1527 memcpy(sp
, msg
, msglen
);
1534 store_object(OBJ_COMMIT
,
1535 new_data
.buffer
, sp
- (char*)new_data
.buffer
,
1536 NULL
, b
->sha1
, next_mark
);
1537 b
->last_commit
= object_count_by_type
[OBJ_COMMIT
];
1540 int need_dq
= quote_c_style(b
->name
, NULL
, NULL
, 0);
1541 fprintf(branch_log
, "commit ");
1543 fputc('"', branch_log
);
1544 quote_c_style(b
->name
, NULL
, branch_log
, 0);
1545 fputc('"', branch_log
);
1547 fprintf(branch_log
, "%s", b
->name
);
1548 fprintf(branch_log
," :%lu %s\n",next_mark
,sha1_to_hex(b
->sha1
));
1552 static void cmd_new_tag()
1563 unsigned long from_mark
= 0;
1564 unsigned char sha1
[20];
1566 /* Obtain the new tag name from the rest of our command */
1567 sp
= strchr(command_buf
.buf
, ' ') + 1;
1568 str_uq
= unquote_c_style(sp
, &endp
);
1571 die("Garbage after tag name in: %s", command_buf
.buf
);
1574 t
= pool_alloc(sizeof(struct tag
));
1576 t
->name
= pool_strdup(sp
);
1578 last_tag
->next_tag
= t
;
1584 read_next_command();
1587 if (strncmp("from ", command_buf
.buf
, 5))
1588 die("Expected from command, got %s", command_buf
.buf
);
1590 from
= strchr(command_buf
.buf
, ' ') + 1;
1591 str_uq
= unquote_c_style(from
, &endp
);
1594 die("Garbage after string in: %s", command_buf
.buf
);
1598 s
= lookup_branch(from
);
1600 hashcpy(sha1
, s
->sha1
);
1601 } else if (*from
== ':') {
1602 from_mark
= strtoul(from
+ 1, NULL
, 10);
1603 struct object_entry
*oe
= find_mark(from_mark
);
1604 if (oe
->type
!= OBJ_COMMIT
)
1605 die("Mark :%lu not a commit", from_mark
);
1606 hashcpy(sha1
, oe
->sha1
);
1607 } else if (!get_sha1(from
, sha1
)) {
1611 buf
= read_object_with_reference(sha1
,
1612 type_names
[OBJ_COMMIT
], &size
, sha1
);
1613 if (!buf
|| size
< 46)
1614 die("Not a valid commit: %s", from
);
1617 die("Invalid ref name or SHA1 expression: %s", from
);
1621 read_next_command();
1624 if (strncmp("tagger ", command_buf
.buf
, 7))
1625 die("Expected tagger command, got %s", command_buf
.buf
);
1626 tagger
= strdup(command_buf
.buf
);
1628 /* tag payload/message */
1629 read_next_command();
1630 msg
= cmd_data(&msglen
);
1632 /* build the tag object */
1633 size_dbuf(&new_data
, 67+strlen(t
->name
)+strlen(tagger
)+msglen
);
1634 sp
= new_data
.buffer
;
1635 sp
+= sprintf(sp
, "object %s\n", sha1_to_hex(sha1
));
1636 sp
+= sprintf(sp
, "type %s\n", type_names
[OBJ_COMMIT
]);
1637 sp
+= sprintf(sp
, "tag %s\n", t
->name
);
1638 sp
+= sprintf(sp
, "%s\n\n", tagger
);
1639 memcpy(sp
, msg
, msglen
);
1644 store_object(OBJ_TAG
, new_data
.buffer
, sp
- (char*)new_data
.buffer
,
1648 int need_dq
= quote_c_style(t
->name
, NULL
, NULL
, 0);
1649 fprintf(branch_log
, "tag ");
1651 fputc('"', branch_log
);
1652 quote_c_style(t
->name
, NULL
, branch_log
, 0);
1653 fputc('"', branch_log
);
1655 fprintf(branch_log
, "%s", t
->name
);
1656 fprintf(branch_log
," :%lu %s\n",from_mark
,sha1_to_hex(t
->sha1
));
1660 static void cmd_reset_branch()
1667 /* Obtain the branch name from the rest of our command */
1668 sp
= strchr(command_buf
.buf
, ' ') + 1;
1669 str_uq
= unquote_c_style(sp
, &endp
);
1672 die("Garbage after ref in: %s", command_buf
.buf
);
1675 b
= lookup_branch(sp
);
1678 if (b
->branch_tree
.tree
) {
1679 release_tree_content_recursive(b
->branch_tree
.tree
);
1680 b
->branch_tree
.tree
= NULL
;
1687 read_next_command();
1691 static const char fast_import_usage
[] =
1692 "git-fast-import [--objects=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file] [--branch-log=log] temp.pack";
1694 int main(int argc
, const char **argv
)
1696 const char *base_name
;
1698 unsigned long est_obj_cnt
= object_entry_alloc
;
1704 git_config(git_default_config
);
1706 for (i
= 1; i
< argc
; i
++) {
1707 const char *a
= argv
[i
];
1709 if (*a
!= '-' || !strcmp(a
, "--"))
1711 else if (!strncmp(a
, "--objects=", 10))
1712 est_obj_cnt
= strtoul(a
+ 10, NULL
, 0);
1713 else if (!strncmp(a
, "--depth=", 8))
1714 max_depth
= strtoul(a
+ 8, NULL
, 0);
1715 else if (!strncmp(a
, "--active-branches=", 18))
1716 max_active_branches
= strtoul(a
+ 18, NULL
, 0);
1717 else if (!strncmp(a
, "--export-marks=", 15))
1719 else if (!strncmp(a
, "--branch-log=", 13)) {
1720 branch_log
= fopen(a
+ 13, "w");
1722 die("Can't create %s: %s", a
+ 13, strerror(errno
));
1725 die("unknown option %s", a
);
1728 usage(fast_import_usage
);
1729 base_name
= argv
[i
];
1731 pack_name
= xmalloc(strlen(base_name
) + 6);
1732 sprintf(pack_name
, "%s.pack", base_name
);
1733 idx_name
= xmalloc(strlen(base_name
) + 5);
1734 sprintf(idx_name
, "%s.idx", base_name
);
1736 pack_fd
= open(pack_name
, O_RDWR
|O_CREAT
|O_EXCL
, 0666);
1738 die("Can't create %s: %s", pack_name
, strerror(errno
));
1740 pack_data
= xcalloc(1, sizeof(*pack_data
) + strlen(pack_name
) + 2);
1741 strcpy(pack_data
->pack_name
, pack_name
);
1742 pack_data
->pack_fd
= pack_fd
;
1745 alloc_objects(est_obj_cnt
);
1746 strbuf_init(&command_buf
);
1748 atom_table
= xcalloc(atom_table_sz
, sizeof(struct atom_str
*));
1749 branch_table
= xcalloc(branch_table_sz
, sizeof(struct branch
*));
1750 avail_tree_table
= xcalloc(avail_tree_table_sz
, sizeof(struct avail_tree_content
*));
1751 marks
= pool_calloc(1, sizeof(struct mark_set
));
1754 read_next_command();
1755 if (command_buf
.eof
)
1757 else if (!strcmp("blob", command_buf
.buf
))
1759 else if (!strncmp("commit ", command_buf
.buf
, 7))
1761 else if (!strncmp("tag ", command_buf
.buf
, 4))
1763 else if (!strncmp("reset ", command_buf
.buf
, 6))
1766 die("Unsupported command: %s", command_buf
.buf
);
1769 fixup_header_footer();
1771 write_index(idx_name
);
1778 fprintf(stderr
, "%s statistics:\n", argv
[0]);
1779 fprintf(stderr
, "---------------------------------------------------------------------\n");
1780 fprintf(stderr
, "Alloc'd objects: %10lu (%10lu overflow )\n", alloc_count
, alloc_count
- est_obj_cnt
);
1781 fprintf(stderr
, "Total objects: %10lu (%10lu duplicates )\n", object_count
, duplicate_count
);
1782 fprintf(stderr
, " blobs : %10lu (%10lu duplicates %10lu deltas)\n", object_count_by_type
[OBJ_BLOB
], duplicate_count_by_type
[OBJ_BLOB
], delta_count_by_type
[OBJ_BLOB
]);
1783 fprintf(stderr
, " trees : %10lu (%10lu duplicates %10lu deltas)\n", object_count_by_type
[OBJ_TREE
], duplicate_count_by_type
[OBJ_TREE
], delta_count_by_type
[OBJ_TREE
]);
1784 fprintf(stderr
, " commits: %10lu (%10lu duplicates %10lu deltas)\n", object_count_by_type
[OBJ_COMMIT
], duplicate_count_by_type
[OBJ_COMMIT
], delta_count_by_type
[OBJ_COMMIT
]);
1785 fprintf(stderr
, " tags : %10lu (%10lu duplicates %10lu deltas)\n", object_count_by_type
[OBJ_TAG
], duplicate_count_by_type
[OBJ_TAG
], delta_count_by_type
[OBJ_TAG
]);
1786 fprintf(stderr
, "Total branches: %10lu (%10lu loads )\n", branch_count
, branch_load_count
);
1787 fprintf(stderr
, " marks: %10u (%10lu unique )\n", (1 << marks
->shift
) * 1024, marks_set_count
);
1788 fprintf(stderr
, " atoms: %10u\n", atom_cnt
);
1789 fprintf(stderr
, "Memory total: %10lu KiB\n", (total_allocd
+ alloc_count
*sizeof(struct object_entry
))/1024);
1790 fprintf(stderr
, " pools: %10lu KiB\n", total_allocd
/1024);
1791 fprintf(stderr
, " objects: %10lu KiB\n", (alloc_count
*sizeof(struct object_entry
))/1024);
1792 fprintf(stderr
, "Pack remaps: %10lu\n", remap_count
);
1793 stat(pack_name
, &sb
);
1794 fprintf(stderr
, "Pack size: %10lu KiB\n", (unsigned long)(sb
.st_size
/1024));
1795 stat(idx_name
, &sb
);
1796 fprintf(stderr
, "Index size: %10lu KiB\n", (unsigned long)(sb
.st_size
/1024));
1797 fprintf(stderr
, "---------------------------------------------------------------------\n");
1799 fprintf(stderr
, "\n");