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 checkpoint ::= 'checkpoint' lf
46 # note: the first idnum in a stream should be 1 and subsequent
47 # idnums should not have gaps between values as this will cause
48 # the stream parser to reserve space for the gapped values. An
49 # idnum can be updated in the future to a new object by issuing
50 # a new mark directive with the old idnum.
52 mark ::= 'mark' sp idnum lf;
54 # note: declen indicates the length of binary_data in bytes.
55 # declen does not include the lf preceeding or trailing the
58 data ::= 'data' sp declen lf
62 # note: quoted strings are C-style quoting supporting \c for
63 # common escapes of 'c' (e..g \n, \t, \\, \") or \nnn where nnn
64 # is the signed byte value in octal. Note that the only
65 # characters which must actually be escaped to protect the
66 # stream formatting is: \, " and LF. Otherwise these values
69 ref_str ::= ref | '"' quoted(ref) '"' ;
70 sha1exp_str ::= sha1exp | '"' quoted(sha1exp) '"' ;
71 tag_str ::= tag | '"' quoted(tag) '"' ;
72 path_str ::= path | '"' quoted(path) '"' ;
74 declen ::= # unsigned 32 bit value, ascii base10 notation;
75 binary_data ::= # file content, not interpreted;
77 sp ::= # ASCII space character;
78 lf ::= # ASCII newline (LF) character;
80 # note: a colon (':') must precede the numerical value assigned to
81 # an idnum. This is to distinguish it from a ref or tag name as
82 # GIT does not permit ':' in ref or tag strings.
85 path ::= # GIT style file path, e.g. "a/b/c";
86 ref ::= # GIT ref name, e.g. "refs/heads/MOZ_GECKO_EXPERIMENT";
87 tag ::= # GIT tag name, e.g. "FIREFOX_1_5";
88 sha1exp ::= # Any valid GIT SHA1 expression;
89 hexsha1 ::= # SHA1 in hexadecimal format;
91 # note: name and email are UTF8 strings, however name must not
92 # contain '<' or lf and email must not contain any of the
93 # following: '<', '>', lf.
95 name ::= # valid GIT author/committer name;
96 email ::= # valid GIT author/committer email;
97 ts ::= # time since the epoch in seconds, ascii base10 notation;
98 tz ::= # GIT style timezone;
109 #include "csum-file.h"
115 struct object_entry
*next
;
116 unsigned long offset
;
117 unsigned type
: TYPE_BITS
;
118 unsigned pack_id
: 16;
119 unsigned char sha1
[20];
122 struct object_entry_pool
124 struct object_entry_pool
*next_pool
;
125 struct object_entry
*next_free
;
126 struct object_entry
*end
;
127 struct object_entry entries
[FLEX_ARRAY
]; /* more */
134 struct object_entry
*marked
[1024];
135 struct mark_set
*sets
[1024];
143 unsigned long offset
;
150 struct mem_pool
*next_pool
;
153 char space
[FLEX_ARRAY
]; /* more */
158 struct atom_str
*next_atom
;
160 char str_dat
[FLEX_ARRAY
]; /* more */
166 struct tree_content
*tree
;
167 struct atom_str
* name
;
171 unsigned char sha1
[20];
177 unsigned int entry_capacity
; /* must match avail_tree_content */
178 unsigned int entry_count
;
179 unsigned int delta_depth
;
180 struct tree_entry
*entries
[FLEX_ARRAY
]; /* more */
183 struct avail_tree_content
185 unsigned int entry_capacity
; /* must match tree_content */
186 struct avail_tree_content
*next_avail
;
191 struct branch
*table_next_branch
;
192 struct branch
*active_next_branch
;
194 unsigned long last_commit
;
195 struct tree_entry branch_tree
;
196 unsigned char sha1
[20];
201 struct tag
*next_tag
;
203 unsigned char sha1
[20];
214 struct hash_list
*next
;
215 unsigned char sha1
[20];
218 /* Stats and misc. counters */
219 static unsigned long max_depth
= 10;
220 static unsigned long alloc_count
;
221 static unsigned long branch_count
;
222 static unsigned long branch_load_count
;
223 static unsigned long object_count
;
224 static unsigned long marks_set_count
;
225 static unsigned long object_count_by_type
[1 << TYPE_BITS
];
226 static unsigned long duplicate_count_by_type
[1 << TYPE_BITS
];
227 static unsigned long delta_count_by_type
[1 << TYPE_BITS
];
230 static size_t mem_pool_alloc
= 2*1024*1024 - sizeof(struct mem_pool
);
231 static size_t total_allocd
;
232 static struct mem_pool
*mem_pool
;
234 /* Atom management */
235 static unsigned int atom_table_sz
= 4451;
236 static unsigned int atom_cnt
;
237 static struct atom_str
**atom_table
;
239 /* The .pack file being generated */
240 static const char *base_name
;
241 static unsigned int pack_id
;
242 static char *idx_name
;
243 static struct packed_git
*pack_data
;
244 static struct packed_git
**all_packs
;
246 static unsigned long pack_size
;
247 static unsigned char pack_sha1
[20];
249 /* Table of objects we've written. */
250 static unsigned int object_entry_alloc
= 5000;
251 static struct object_entry_pool
*blocks
;
252 static struct object_entry
*object_table
[1 << 16];
253 static struct mark_set
*marks
;
254 static const char* mark_file
;
257 static struct last_object last_blob
;
259 /* Tree management */
260 static unsigned int tree_entry_alloc
= 1000;
261 static void *avail_tree_entry
;
262 static unsigned int avail_tree_table_sz
= 100;
263 static struct avail_tree_content
**avail_tree_table
;
264 static struct dbuf old_tree
;
265 static struct dbuf new_tree
;
268 static unsigned long max_active_branches
= 5;
269 static unsigned long cur_active_branches
;
270 static unsigned long branch_table_sz
= 1039;
271 static struct branch
**branch_table
;
272 static struct branch
*active_branches
;
275 static struct tag
*first_tag
;
276 static struct tag
*last_tag
;
278 /* Input stream parsing */
279 static struct strbuf command_buf
;
280 static unsigned long next_mark
;
281 static struct dbuf new_data
;
282 static FILE* branch_log
;
285 static void alloc_objects(unsigned int cnt
)
287 struct object_entry_pool
*b
;
289 b
= xmalloc(sizeof(struct object_entry_pool
)
290 + cnt
* sizeof(struct object_entry
));
291 b
->next_pool
= blocks
;
292 b
->next_free
= b
->entries
;
293 b
->end
= b
->entries
+ cnt
;
298 static struct object_entry
* new_object(unsigned char *sha1
)
300 struct object_entry
*e
;
302 if (blocks
->next_free
== blocks
->end
)
303 alloc_objects(object_entry_alloc
);
305 e
= blocks
->next_free
++;
306 e
->pack_id
= pack_id
;
307 hashcpy(e
->sha1
, sha1
);
311 static struct object_entry
* find_object(unsigned char *sha1
)
313 unsigned int h
= sha1
[0] << 8 | sha1
[1];
314 struct object_entry
*e
;
315 for (e
= object_table
[h
]; e
; e
= e
->next
)
316 if (!hashcmp(sha1
, e
->sha1
))
321 static struct object_entry
* insert_object(unsigned char *sha1
)
323 unsigned int h
= sha1
[0] << 8 | sha1
[1];
324 struct object_entry
*e
= object_table
[h
];
325 struct object_entry
*p
= NULL
;
328 if (!hashcmp(sha1
, e
->sha1
))
334 e
= new_object(sha1
);
344 static unsigned int hc_str(const char *s
, size_t len
)
352 static void* pool_alloc(size_t len
)
357 for (p
= mem_pool
; p
; p
= p
->next_pool
)
358 if ((p
->end
- p
->next_free
>= len
))
362 if (len
>= (mem_pool_alloc
/2)) {
366 total_allocd
+= sizeof(struct mem_pool
) + mem_pool_alloc
;
367 p
= xmalloc(sizeof(struct mem_pool
) + mem_pool_alloc
);
368 p
->next_pool
= mem_pool
;
369 p
->next_free
= p
->space
;
370 p
->end
= p
->next_free
+ mem_pool_alloc
;
375 /* round out to a pointer alignment */
376 if (len
& (sizeof(void*) - 1))
377 len
+= sizeof(void*) - (len
& (sizeof(void*) - 1));
382 static void* pool_calloc(size_t count
, size_t size
)
384 size_t len
= count
* size
;
385 void *r
= pool_alloc(len
);
390 static char* pool_strdup(const char *s
)
392 char *r
= pool_alloc(strlen(s
) + 1);
397 static void size_dbuf(struct dbuf
*b
, size_t maxlen
)
400 if (b
->capacity
>= maxlen
)
404 b
->capacity
= ((maxlen
/ 1024) + 1) * 1024;
405 b
->buffer
= xmalloc(b
->capacity
);
408 static void insert_mark(unsigned long idnum
, struct object_entry
*oe
)
410 struct mark_set
*s
= marks
;
411 while ((idnum
>> s
->shift
) >= 1024) {
412 s
= pool_calloc(1, sizeof(struct mark_set
));
413 s
->shift
= marks
->shift
+ 10;
414 s
->data
.sets
[0] = marks
;
418 unsigned long i
= idnum
>> s
->shift
;
419 idnum
-= i
<< s
->shift
;
420 if (!s
->data
.sets
[i
]) {
421 s
->data
.sets
[i
] = pool_calloc(1, sizeof(struct mark_set
));
422 s
->data
.sets
[i
]->shift
= s
->shift
- 10;
426 if (!s
->data
.marked
[idnum
])
428 s
->data
.marked
[idnum
] = oe
;
431 static struct object_entry
* find_mark(unsigned long idnum
)
433 unsigned long orig_idnum
= idnum
;
434 struct mark_set
*s
= marks
;
435 struct object_entry
*oe
= NULL
;
436 if ((idnum
>> s
->shift
) < 1024) {
437 while (s
&& s
->shift
) {
438 unsigned long i
= idnum
>> s
->shift
;
439 idnum
-= i
<< s
->shift
;
443 oe
= s
->data
.marked
[idnum
];
446 die("mark :%lu not declared", orig_idnum
);
450 static struct atom_str
* to_atom(const char *s
, size_t len
)
452 unsigned int hc
= hc_str(s
, len
) % atom_table_sz
;
455 for (c
= atom_table
[hc
]; c
; c
= c
->next_atom
)
456 if (c
->str_len
== len
&& !strncmp(s
, c
->str_dat
, len
))
459 c
= pool_alloc(sizeof(struct atom_str
) + len
+ 1);
461 strncpy(c
->str_dat
, s
, len
);
463 c
->next_atom
= atom_table
[hc
];
469 static struct branch
* lookup_branch(const char *name
)
471 unsigned int hc
= hc_str(name
, strlen(name
)) % branch_table_sz
;
474 for (b
= branch_table
[hc
]; b
; b
= b
->table_next_branch
)
475 if (!strcmp(name
, b
->name
))
480 static struct branch
* new_branch(const char *name
)
482 unsigned int hc
= hc_str(name
, strlen(name
)) % branch_table_sz
;
483 struct branch
* b
= lookup_branch(name
);
486 die("Invalid attempt to create duplicate branch: %s", name
);
487 if (check_ref_format(name
))
488 die("Branch name doesn't conform to GIT standards: %s", name
);
490 b
= pool_calloc(1, sizeof(struct branch
));
491 b
->name
= pool_strdup(name
);
492 b
->table_next_branch
= branch_table
[hc
];
493 b
->branch_tree
.versions
[0].mode
= S_IFDIR
;
494 b
->branch_tree
.versions
[1].mode
= S_IFDIR
;
495 branch_table
[hc
] = b
;
500 static unsigned int hc_entries(unsigned int cnt
)
502 cnt
= cnt
& 7 ? (cnt
/ 8) + 1 : cnt
/ 8;
503 return cnt
< avail_tree_table_sz
? cnt
: avail_tree_table_sz
- 1;
506 static struct tree_content
* new_tree_content(unsigned int cnt
)
508 struct avail_tree_content
*f
, *l
= NULL
;
509 struct tree_content
*t
;
510 unsigned int hc
= hc_entries(cnt
);
512 for (f
= avail_tree_table
[hc
]; f
; l
= f
, f
= f
->next_avail
)
513 if (f
->entry_capacity
>= cnt
)
518 l
->next_avail
= f
->next_avail
;
520 avail_tree_table
[hc
] = f
->next_avail
;
522 cnt
= cnt
& 7 ? ((cnt
/ 8) + 1) * 8 : cnt
;
523 f
= pool_alloc(sizeof(*t
) + sizeof(t
->entries
[0]) * cnt
);
524 f
->entry_capacity
= cnt
;
527 t
= (struct tree_content
*)f
;
533 static void release_tree_entry(struct tree_entry
*e
);
534 static void release_tree_content(struct tree_content
*t
)
536 struct avail_tree_content
*f
= (struct avail_tree_content
*)t
;
537 unsigned int hc
= hc_entries(f
->entry_capacity
);
538 f
->next_avail
= avail_tree_table
[hc
];
539 avail_tree_table
[hc
] = f
;
542 static void release_tree_content_recursive(struct tree_content
*t
)
545 for (i
= 0; i
< t
->entry_count
; i
++)
546 release_tree_entry(t
->entries
[i
]);
547 release_tree_content(t
);
550 static struct tree_content
* grow_tree_content(
551 struct tree_content
*t
,
554 struct tree_content
*r
= new_tree_content(t
->entry_count
+ amt
);
555 r
->entry_count
= t
->entry_count
;
556 r
->delta_depth
= t
->delta_depth
;
557 memcpy(r
->entries
,t
->entries
,t
->entry_count
*sizeof(t
->entries
[0]));
558 release_tree_content(t
);
562 static struct tree_entry
* new_tree_entry()
564 struct tree_entry
*e
;
566 if (!avail_tree_entry
) {
567 unsigned int n
= tree_entry_alloc
;
568 total_allocd
+= n
* sizeof(struct tree_entry
);
569 avail_tree_entry
= e
= xmalloc(n
* sizeof(struct tree_entry
));
571 *((void**)e
) = e
+ 1;
577 e
= avail_tree_entry
;
578 avail_tree_entry
= *((void**)e
);
582 static void release_tree_entry(struct tree_entry
*e
)
585 release_tree_content_recursive(e
->tree
);
586 *((void**)e
) = avail_tree_entry
;
587 avail_tree_entry
= e
;
590 static void yread(int fd
, void *buffer
, size_t length
)
593 while (ret
< length
) {
594 ssize_t size
= xread(fd
, (char *) buffer
+ ret
, length
- ret
);
596 die("Read from descriptor %i: end of stream", fd
);
598 die("Read from descriptor %i: %s", fd
, strerror(errno
));
603 static void start_packfile()
605 struct packed_git
*p
;
606 struct pack_header hdr
;
608 idx_name
= xmalloc(strlen(base_name
) + 11);
609 p
= xcalloc(1, sizeof(*p
) + strlen(base_name
) + 13);
610 sprintf(p
->pack_name
, "%s%5.5i.pack", base_name
, pack_id
+ 1);
611 sprintf(idx_name
, "%s%5.5i.idx", base_name
, pack_id
+ 1);
613 pack_fd
= open(p
->pack_name
, O_RDWR
|O_CREAT
|O_EXCL
, 0666);
615 die("Can't create %s: %s", p
->pack_name
, strerror(errno
));
616 p
->pack_fd
= pack_fd
;
618 hdr
.hdr_signature
= htonl(PACK_SIGNATURE
);
619 hdr
.hdr_version
= htonl(2);
621 write_or_die(pack_fd
, &hdr
, sizeof(hdr
));
624 pack_size
= sizeof(hdr
);
627 all_packs
= xrealloc(all_packs
, sizeof(*all_packs
) * (pack_id
+ 1));
628 all_packs
[pack_id
] = p
;
631 static void fixup_header_footer()
638 if (lseek(pack_fd
, 0, SEEK_SET
) != 0)
639 die("Failed seeking to start: %s", strerror(errno
));
642 yread(pack_fd
, hdr
, 8);
643 SHA1_Update(&c
, hdr
, 8);
645 cnt
= htonl(object_count
);
646 SHA1_Update(&c
, &cnt
, 4);
647 write_or_die(pack_fd
, &cnt
, 4);
649 buf
= xmalloc(128 * 1024);
651 size_t n
= xread(pack_fd
, buf
, 128 * 1024);
654 SHA1_Update(&c
, buf
, n
);
658 SHA1_Final(pack_sha1
, &c
);
659 write_or_die(pack_fd
, pack_sha1
, sizeof(pack_sha1
));
662 static int oecmp (const void *a_
, const void *b_
)
664 struct object_entry
*a
= *((struct object_entry
**)a_
);
665 struct object_entry
*b
= *((struct object_entry
**)b_
);
666 return hashcmp(a
->sha1
, b
->sha1
);
669 static void write_index(const char *idx_name
)
672 struct object_entry
**idx
, **c
, **last
, *e
;
673 struct object_entry_pool
*o
;
674 unsigned int array
[256];
677 /* Build the sorted table of object IDs. */
678 idx
= xmalloc(object_count
* sizeof(struct object_entry
*));
680 for (o
= blocks
; o
; o
= o
->next_pool
)
681 for (e
= o
->next_free
; e
-- != o
->entries
;) {
682 if (pack_id
!= e
->pack_id
)
687 last
= idx
+ object_count
;
689 die("internal consistency error creating the index");
690 qsort(idx
, object_count
, sizeof(struct object_entry
*), oecmp
);
692 /* Generate the fan-out array. */
694 for (i
= 0; i
< 256; i
++) {
695 struct object_entry
**next
= c
;;
696 while (next
< last
) {
697 if ((*next
)->sha1
[0] != i
)
701 array
[i
] = htonl(next
- idx
);
705 f
= sha1create("%s", idx_name
);
706 sha1write(f
, array
, 256 * sizeof(int));
707 for (c
= idx
; c
!= last
; c
++) {
708 unsigned int offset
= htonl((*c
)->offset
);
709 sha1write(f
, &offset
, 4);
710 sha1write(f
, (*c
)->sha1
, sizeof((*c
)->sha1
));
712 sha1write(f
, pack_sha1
, sizeof(pack_sha1
));
713 sha1close(f
, NULL
, 1);
717 static void end_packfile()
719 struct packed_git
*old_p
= pack_data
, *new_p
;
722 fixup_header_footer();
723 write_index(idx_name
);
725 /* Register the packfile with core git's machinary. */
726 new_p
= add_packed_git(idx_name
, strlen(idx_name
), 1);
728 die("core git rejected index %s", idx_name
);
729 new_p
->windows
= old_p
->windows
;
730 new_p
->pack_fd
= old_p
->pack_fd
;
731 all_packs
[pack_id
++] = new_p
;
732 install_packed_git(new_p
);
736 unlink(old_p
->pack_name
);
741 /* We can't carry a delta across packfiles. */
742 free(last_blob
.data
);
743 last_blob
.data
= NULL
;
745 last_blob
.offset
= 0;
749 static size_t encode_header(
750 enum object_type type
,
757 if (type
< OBJ_COMMIT
|| type
> OBJ_REF_DELTA
)
758 die("bad type %d", type
);
760 c
= (type
<< 4) | (size
& 15);
772 static int store_object(
773 enum object_type type
,
776 struct last_object
*last
,
777 unsigned char *sha1out
,
781 struct object_entry
*e
;
782 unsigned char hdr
[96];
783 unsigned char sha1
[20];
784 unsigned long hdrlen
, deltalen
;
788 hdrlen
= sprintf((char*)hdr
,"%s %lu",type_names
[type
],datlen
) + 1;
790 SHA1_Update(&c
, hdr
, hdrlen
);
791 SHA1_Update(&c
, dat
, datlen
);
792 SHA1_Final(sha1
, &c
);
794 hashcpy(sha1out
, sha1
);
796 e
= insert_object(sha1
);
798 insert_mark(mark
, e
);
800 duplicate_count_by_type
[type
]++;
804 e
->offset
= pack_size
;
806 object_count_by_type
[type
]++;
808 if (last
&& last
->data
&& last
->depth
< max_depth
)
809 delta
= diff_delta(last
->data
, last
->len
,
815 memset(&s
, 0, sizeof(s
));
816 deflateInit(&s
, zlib_compression_level
);
819 unsigned long ofs
= e
->offset
- last
->offset
;
820 unsigned pos
= sizeof(hdr
) - 1;
822 delta_count_by_type
[type
]++;
825 s
.avail_in
= deltalen
;
827 hdrlen
= encode_header(OBJ_OFS_DELTA
, deltalen
, hdr
);
828 write_or_die(pack_fd
, hdr
, hdrlen
);
831 hdr
[pos
] = ofs
& 127;
833 hdr
[--pos
] = 128 | (--ofs
& 127);
834 write_or_die(pack_fd
, hdr
+ pos
, sizeof(hdr
) - pos
);
835 pack_size
+= sizeof(hdr
) - pos
;
841 hdrlen
= encode_header(type
, datlen
, hdr
);
842 write_or_die(pack_fd
, hdr
, hdrlen
);
846 s
.avail_out
= deflateBound(&s
, s
.avail_in
);
847 s
.next_out
= out
= xmalloc(s
.avail_out
);
848 while (deflate(&s
, Z_FINISH
) == Z_OK
)
852 write_or_die(pack_fd
, out
, s
.total_out
);
853 pack_size
+= s
.total_out
;
859 if (last
->data
&& !last
->no_free
)
862 last
->offset
= e
->offset
;
868 static void *gfi_unpack_entry(
869 struct object_entry
*oe
,
870 unsigned long *sizep
)
872 static char type
[20];
873 struct packed_git
*p
= all_packs
[oe
->pack_id
];
875 p
->pack_size
= pack_size
+ 20;
876 return unpack_entry(p
, oe
->offset
, type
, sizep
);
879 static const char *get_mode(const char *str
, unsigned int *modep
)
882 unsigned int mode
= 0;
884 while ((c
= *str
++) != ' ') {
885 if (c
< '0' || c
> '7')
887 mode
= (mode
<< 3) + (c
- '0');
893 static void load_tree(struct tree_entry
*root
)
895 unsigned char* sha1
= root
->versions
[1].sha1
;
896 struct object_entry
*myoe
;
897 struct tree_content
*t
;
902 root
->tree
= t
= new_tree_content(8);
903 if (is_null_sha1(sha1
))
906 myoe
= find_object(sha1
);
908 if (myoe
->type
!= OBJ_TREE
)
909 die("Not a tree: %s", sha1_to_hex(sha1
));
911 buf
= gfi_unpack_entry(myoe
, &size
);
914 buf
= read_sha1_file(sha1
, type
, &size
);
915 if (!buf
|| strcmp(type
, tree_type
))
916 die("Can't load tree %s", sha1_to_hex(sha1
));
920 while (c
!= (buf
+ size
)) {
921 struct tree_entry
*e
= new_tree_entry();
923 if (t
->entry_count
== t
->entry_capacity
)
924 root
->tree
= t
= grow_tree_content(t
, 8);
925 t
->entries
[t
->entry_count
++] = e
;
928 c
= get_mode(c
, &e
->versions
[1].mode
);
930 die("Corrupt mode in %s", sha1_to_hex(sha1
));
931 e
->versions
[0].mode
= e
->versions
[1].mode
;
932 e
->name
= to_atom(c
, strlen(c
));
933 c
+= e
->name
->str_len
+ 1;
934 hashcpy(e
->versions
[0].sha1
, (unsigned char*)c
);
935 hashcpy(e
->versions
[1].sha1
, (unsigned char*)c
);
941 static int tecmp0 (const void *_a
, const void *_b
)
943 struct tree_entry
*a
= *((struct tree_entry
**)_a
);
944 struct tree_entry
*b
= *((struct tree_entry
**)_b
);
945 return base_name_compare(
946 a
->name
->str_dat
, a
->name
->str_len
, a
->versions
[0].mode
,
947 b
->name
->str_dat
, b
->name
->str_len
, b
->versions
[0].mode
);
950 static int tecmp1 (const void *_a
, const void *_b
)
952 struct tree_entry
*a
= *((struct tree_entry
**)_a
);
953 struct tree_entry
*b
= *((struct tree_entry
**)_b
);
954 return base_name_compare(
955 a
->name
->str_dat
, a
->name
->str_len
, a
->versions
[1].mode
,
956 b
->name
->str_dat
, b
->name
->str_len
, b
->versions
[1].mode
);
959 static void mktree(struct tree_content
*t
,
969 qsort(t
->entries
,t
->entry_count
,sizeof(t
->entries
[0]),tecmp0
);
971 qsort(t
->entries
,t
->entry_count
,sizeof(t
->entries
[0]),tecmp1
);
973 for (i
= 0; i
< t
->entry_count
; i
++) {
974 if (t
->entries
[i
]->versions
[v
].mode
)
975 maxlen
+= t
->entries
[i
]->name
->str_len
+ 34;
978 size_dbuf(b
, maxlen
);
980 for (i
= 0; i
< t
->entry_count
; i
++) {
981 struct tree_entry
*e
= t
->entries
[i
];
982 if (!e
->versions
[v
].mode
)
984 c
+= sprintf(c
, "%o", e
->versions
[v
].mode
);
986 strcpy(c
, e
->name
->str_dat
);
987 c
+= e
->name
->str_len
+ 1;
988 hashcpy((unsigned char*)c
, e
->versions
[v
].sha1
);
991 *szp
= c
- (char*)b
->buffer
;
994 static void store_tree(struct tree_entry
*root
)
996 struct tree_content
*t
= root
->tree
;
997 unsigned int i
, j
, del
;
998 unsigned long new_len
;
999 struct last_object lo
;
1000 struct object_entry
*le
;
1002 if (!is_null_sha1(root
->versions
[1].sha1
))
1005 for (i
= 0; i
< t
->entry_count
; i
++) {
1006 if (t
->entries
[i
]->tree
)
1007 store_tree(t
->entries
[i
]);
1010 le
= find_object(root
->versions
[0].sha1
);
1011 if (!S_ISDIR(root
->versions
[0].mode
)
1013 || le
->pack_id
!= pack_id
) {
1017 mktree(t
, 0, &lo
.len
, &old_tree
);
1018 lo
.data
= old_tree
.buffer
;
1019 lo
.offset
= le
->offset
;
1020 lo
.depth
= t
->delta_depth
;
1024 mktree(t
, 1, &new_len
, &new_tree
);
1025 store_object(OBJ_TREE
, new_tree
.buffer
, new_len
,
1026 &lo
, root
->versions
[1].sha1
, 0);
1028 t
->delta_depth
= lo
.depth
;
1029 for (i
= 0, j
= 0, del
= 0; i
< t
->entry_count
; i
++) {
1030 struct tree_entry
*e
= t
->entries
[i
];
1031 if (e
->versions
[1].mode
) {
1032 e
->versions
[0].mode
= e
->versions
[1].mode
;
1033 hashcpy(e
->versions
[0].sha1
, e
->versions
[1].sha1
);
1034 t
->entries
[j
++] = e
;
1036 release_tree_entry(e
);
1040 t
->entry_count
-= del
;
1043 static int tree_content_set(
1044 struct tree_entry
*root
,
1046 const unsigned char *sha1
,
1047 const unsigned int mode
)
1049 struct tree_content
*t
= root
->tree
;
1052 struct tree_entry
*e
;
1054 slash1
= strchr(p
, '/');
1060 for (i
= 0; i
< t
->entry_count
; i
++) {
1062 if (e
->name
->str_len
== n
&& !strncmp(p
, e
->name
->str_dat
, n
)) {
1064 if (e
->versions
[1].mode
== mode
1065 && !hashcmp(e
->versions
[1].sha1
, sha1
))
1067 e
->versions
[1].mode
= mode
;
1068 hashcpy(e
->versions
[1].sha1
, sha1
);
1070 release_tree_content_recursive(e
->tree
);
1073 hashclr(root
->versions
[1].sha1
);
1076 if (!S_ISDIR(e
->versions
[1].mode
)) {
1077 e
->tree
= new_tree_content(8);
1078 e
->versions
[1].mode
= S_IFDIR
;
1082 if (tree_content_set(e
, slash1
+ 1, sha1
, mode
)) {
1083 hashclr(root
->versions
[1].sha1
);
1090 if (t
->entry_count
== t
->entry_capacity
)
1091 root
->tree
= t
= grow_tree_content(t
, 8);
1092 e
= new_tree_entry();
1093 e
->name
= to_atom(p
, n
);
1094 e
->versions
[0].mode
= 0;
1095 hashclr(e
->versions
[0].sha1
);
1096 t
->entries
[t
->entry_count
++] = e
;
1098 e
->tree
= new_tree_content(8);
1099 e
->versions
[1].mode
= S_IFDIR
;
1100 tree_content_set(e
, slash1
+ 1, sha1
, mode
);
1103 e
->versions
[1].mode
= mode
;
1104 hashcpy(e
->versions
[1].sha1
, sha1
);
1106 hashclr(root
->versions
[1].sha1
);
1110 static int tree_content_remove(struct tree_entry
*root
, const char *p
)
1112 struct tree_content
*t
= root
->tree
;
1115 struct tree_entry
*e
;
1117 slash1
= strchr(p
, '/');
1123 for (i
= 0; i
< t
->entry_count
; i
++) {
1125 if (e
->name
->str_len
== n
&& !strncmp(p
, e
->name
->str_dat
, n
)) {
1126 if (!slash1
|| !S_ISDIR(e
->versions
[1].mode
))
1130 if (tree_content_remove(e
, slash1
+ 1)) {
1131 for (n
= 0; n
< e
->tree
->entry_count
; n
++) {
1132 if (e
->tree
->entries
[n
]->versions
[1].mode
) {
1133 hashclr(root
->versions
[1].sha1
);
1146 release_tree_content_recursive(e
->tree
);
1149 e
->versions
[1].mode
= 0;
1150 hashclr(e
->versions
[1].sha1
);
1151 hashclr(root
->versions
[1].sha1
);
1155 static void dump_branches()
1157 static const char *msg
= "fast-import";
1160 struct ref_lock
*lock
;
1162 for (i
= 0; i
< branch_table_sz
; i
++) {
1163 for (b
= branch_table
[i
]; b
; b
= b
->table_next_branch
) {
1164 lock
= lock_any_ref_for_update(b
->name
, NULL
);
1165 if (!lock
|| write_ref_sha1(lock
, b
->sha1
, msg
) < 0)
1166 die("Can't write %s", b
->name
);
1171 static void dump_tags()
1173 static const char *msg
= "fast-import";
1175 struct ref_lock
*lock
;
1176 char path
[PATH_MAX
];
1178 for (t
= first_tag
; t
; t
= t
->next_tag
) {
1179 sprintf(path
, "refs/tags/%s", t
->name
);
1180 lock
= lock_any_ref_for_update(path
, NULL
);
1181 if (!lock
|| write_ref_sha1(lock
, t
->sha1
, msg
) < 0)
1182 die("Can't write %s", path
);
1186 static void dump_marks_helper(FILE *f
,
1192 for (k
= 0; k
< 1024; k
++) {
1193 if (m
->data
.sets
[k
])
1194 dump_marks_helper(f
, (base
+ k
) << m
->shift
,
1198 for (k
= 0; k
< 1024; k
++) {
1199 if (m
->data
.marked
[k
])
1200 fprintf(f
, ":%lu %s\n", base
+ k
,
1201 sha1_to_hex(m
->data
.marked
[k
]->sha1
));
1206 static void dump_marks()
1210 FILE *f
= fopen(mark_file
, "w");
1211 dump_marks_helper(f
, 0, marks
);
1216 static void read_next_command()
1218 read_line(&command_buf
, stdin
, '\n');
1221 static void cmd_mark()
1223 if (!strncmp("mark :", command_buf
.buf
, 6)) {
1224 next_mark
= strtoul(command_buf
.buf
+ 6, NULL
, 10);
1225 read_next_command();
1231 static void* cmd_data (size_t *size
)
1237 if (strncmp("data ", command_buf
.buf
, 5))
1238 die("Expected 'data n' command, found: %s", command_buf
.buf
);
1240 length
= strtoul(command_buf
.buf
+ 5, NULL
, 10);
1241 buffer
= xmalloc(length
);
1243 while (n
< length
) {
1244 size_t s
= fread((char*)buffer
+ n
, 1, length
- n
, stdin
);
1245 if (!s
&& feof(stdin
))
1246 die("EOF in data (%lu bytes remaining)", length
- n
);
1250 if (fgetc(stdin
) != '\n')
1251 die("An lf did not trail the binary data as expected.");
1257 static void cmd_new_blob()
1262 read_next_command();
1266 if (store_object(OBJ_BLOB
, d
, l
, &last_blob
, NULL
, next_mark
))
1270 static void unload_one_branch()
1272 while (cur_active_branches
1273 && cur_active_branches
>= max_active_branches
) {
1274 unsigned long min_commit
= ULONG_MAX
;
1275 struct branch
*e
, *l
= NULL
, *p
= NULL
;
1277 for (e
= active_branches
; e
; e
= e
->active_next_branch
) {
1278 if (e
->last_commit
< min_commit
) {
1280 min_commit
= e
->last_commit
;
1286 e
= p
->active_next_branch
;
1287 p
->active_next_branch
= e
->active_next_branch
;
1289 e
= active_branches
;
1290 active_branches
= e
->active_next_branch
;
1292 e
->active_next_branch
= NULL
;
1293 if (e
->branch_tree
.tree
) {
1294 release_tree_content_recursive(e
->branch_tree
.tree
);
1295 e
->branch_tree
.tree
= NULL
;
1297 cur_active_branches
--;
1301 static void load_branch(struct branch
*b
)
1303 load_tree(&b
->branch_tree
);
1304 b
->active_next_branch
= active_branches
;
1305 active_branches
= b
;
1306 cur_active_branches
++;
1307 branch_load_count
++;
1310 static void file_change_m(struct branch
*b
)
1312 const char *p
= command_buf
.buf
+ 2;
1315 struct object_entry
*oe
;
1316 unsigned char sha1
[20];
1320 p
= get_mode(p
, &mode
);
1322 die("Corrupt mode: %s", command_buf
.buf
);
1324 case S_IFREG
| 0644:
1325 case S_IFREG
| 0755:
1332 die("Corrupt mode: %s", command_buf
.buf
);
1337 oe
= find_mark(strtoul(p
+ 1, &x
, 10));
1338 hashcpy(sha1
, oe
->sha1
);
1341 if (get_sha1_hex(p
, sha1
))
1342 die("Invalid SHA1: %s", command_buf
.buf
);
1343 oe
= find_object(sha1
);
1347 die("Missing space after SHA1: %s", command_buf
.buf
);
1349 p_uq
= unquote_c_style(p
, &endp
);
1352 die("Garbage after path in: %s", command_buf
.buf
);
1357 if (oe
->type
!= OBJ_BLOB
)
1358 die("Not a blob (actually a %s): %s",
1359 command_buf
.buf
, type_names
[oe
->type
]);
1361 if (sha1_object_info(sha1
, type
, NULL
))
1362 die("Blob not found: %s", command_buf
.buf
);
1363 if (strcmp(blob_type
, type
))
1364 die("Not a blob (actually a %s): %s",
1365 command_buf
.buf
, type
);
1368 tree_content_set(&b
->branch_tree
, p
, sha1
, S_IFREG
| mode
);
1374 static void file_change_d(struct branch
*b
)
1376 const char *p
= command_buf
.buf
+ 2;
1380 p_uq
= unquote_c_style(p
, &endp
);
1383 die("Garbage after path in: %s", command_buf
.buf
);
1386 tree_content_remove(&b
->branch_tree
, p
);
1391 static void cmd_from(struct branch
*b
)
1393 const char *from
, *endp
;
1397 if (strncmp("from ", command_buf
.buf
, 5))
1401 die("Can't reinitailize branch %s", b
->name
);
1403 from
= strchr(command_buf
.buf
, ' ') + 1;
1404 str_uq
= unquote_c_style(from
, &endp
);
1407 die("Garbage after string in: %s", command_buf
.buf
);
1411 s
= lookup_branch(from
);
1413 die("Can't create a branch from itself: %s", b
->name
);
1415 unsigned char *t
= s
->branch_tree
.versions
[1].sha1
;
1416 hashcpy(b
->sha1
, s
->sha1
);
1417 hashcpy(b
->branch_tree
.versions
[0].sha1
, t
);
1418 hashcpy(b
->branch_tree
.versions
[1].sha1
, t
);
1419 } else if (*from
== ':') {
1420 unsigned long idnum
= strtoul(from
+ 1, NULL
, 10);
1421 struct object_entry
*oe
= find_mark(idnum
);
1424 if (oe
->type
!= OBJ_COMMIT
)
1425 die("Mark :%lu not a commit", idnum
);
1426 hashcpy(b
->sha1
, oe
->sha1
);
1427 buf
= gfi_unpack_entry(oe
, &size
);
1428 if (!buf
|| size
< 46)
1429 die("Not a valid commit: %s", from
);
1430 if (memcmp("tree ", buf
, 5)
1431 || get_sha1_hex(buf
+ 5, b
->branch_tree
.versions
[1].sha1
))
1432 die("The commit %s is corrupt", sha1_to_hex(b
->sha1
));
1434 hashcpy(b
->branch_tree
.versions
[0].sha1
,
1435 b
->branch_tree
.versions
[1].sha1
);
1436 } else if (!get_sha1(from
, b
->sha1
)) {
1437 if (is_null_sha1(b
->sha1
)) {
1438 hashclr(b
->branch_tree
.versions
[0].sha1
);
1439 hashclr(b
->branch_tree
.versions
[1].sha1
);
1444 buf
= read_object_with_reference(b
->sha1
,
1445 type_names
[OBJ_COMMIT
], &size
, b
->sha1
);
1446 if (!buf
|| size
< 46)
1447 die("Not a valid commit: %s", from
);
1448 if (memcmp("tree ", buf
, 5)
1449 || get_sha1_hex(buf
+ 5, b
->branch_tree
.versions
[1].sha1
))
1450 die("The commit %s is corrupt", sha1_to_hex(b
->sha1
));
1452 hashcpy(b
->branch_tree
.versions
[0].sha1
,
1453 b
->branch_tree
.versions
[1].sha1
);
1456 die("Invalid ref name or SHA1 expression: %s", from
);
1458 read_next_command();
1461 static struct hash_list
* cmd_merge(unsigned int *count
)
1463 struct hash_list
*list
= NULL
, *n
, *e
;
1464 const char *from
, *endp
;
1469 while (!strncmp("merge ", command_buf
.buf
, 6)) {
1470 from
= strchr(command_buf
.buf
, ' ') + 1;
1471 str_uq
= unquote_c_style(from
, &endp
);
1474 die("Garbage after string in: %s", command_buf
.buf
);
1478 n
= xmalloc(sizeof(*n
));
1479 s
= lookup_branch(from
);
1481 hashcpy(n
->sha1
, s
->sha1
);
1482 else if (*from
== ':') {
1483 unsigned long idnum
= strtoul(from
+ 1, NULL
, 10);
1484 struct object_entry
*oe
= find_mark(idnum
);
1485 if (oe
->type
!= OBJ_COMMIT
)
1486 die("Mark :%lu not a commit", idnum
);
1487 hashcpy(n
->sha1
, oe
->sha1
);
1488 } else if (get_sha1(from
, n
->sha1
))
1489 die("Invalid ref name or SHA1 expression: %s", from
);
1498 read_next_command();
1503 static void cmd_new_commit()
1511 char *author
= NULL
;
1512 char *committer
= NULL
;
1513 struct hash_list
*merge_list
= NULL
;
1514 unsigned int merge_count
;
1516 /* Obtain the branch name from the rest of our command */
1517 sp
= strchr(command_buf
.buf
, ' ') + 1;
1518 str_uq
= unquote_c_style(sp
, &endp
);
1521 die("Garbage after ref in: %s", command_buf
.buf
);
1524 b
= lookup_branch(sp
);
1530 read_next_command();
1532 if (!strncmp("author ", command_buf
.buf
, 7)) {
1533 author
= strdup(command_buf
.buf
);
1534 read_next_command();
1536 if (!strncmp("committer ", command_buf
.buf
, 10)) {
1537 committer
= strdup(command_buf
.buf
);
1538 read_next_command();
1541 die("Expected committer but didn't get one");
1542 msg
= cmd_data(&msglen
);
1543 read_next_command();
1545 merge_list
= cmd_merge(&merge_count
);
1547 /* ensure the branch is active/loaded */
1548 if (!b
->branch_tree
.tree
|| !max_active_branches
) {
1549 unload_one_branch();
1555 if (1 == command_buf
.len
)
1557 else if (!strncmp("M ", command_buf
.buf
, 2))
1559 else if (!strncmp("D ", command_buf
.buf
, 2))
1562 die("Unsupported file_change: %s", command_buf
.buf
);
1563 read_next_command();
1566 /* build the tree and the commit */
1567 store_tree(&b
->branch_tree
);
1568 hashcpy(b
->branch_tree
.versions
[0].sha1
,
1569 b
->branch_tree
.versions
[1].sha1
);
1570 size_dbuf(&new_data
, 97 + msglen
1573 ? strlen(author
) + strlen(committer
)
1574 : 2 * strlen(committer
)));
1575 sp
= new_data
.buffer
;
1576 sp
+= sprintf(sp
, "tree %s\n",
1577 sha1_to_hex(b
->branch_tree
.versions
[1].sha1
));
1578 if (!is_null_sha1(b
->sha1
))
1579 sp
+= sprintf(sp
, "parent %s\n", sha1_to_hex(b
->sha1
));
1580 while (merge_list
) {
1581 struct hash_list
*next
= merge_list
->next
;
1582 sp
+= sprintf(sp
, "parent %s\n", sha1_to_hex(merge_list
->sha1
));
1587 sp
+= sprintf(sp
, "%s\n", author
);
1589 sp
+= sprintf(sp
, "author %s\n", committer
+ 10);
1590 sp
+= sprintf(sp
, "%s\n\n", committer
);
1591 memcpy(sp
, msg
, msglen
);
1598 store_object(OBJ_COMMIT
,
1599 new_data
.buffer
, sp
- (char*)new_data
.buffer
,
1600 NULL
, b
->sha1
, next_mark
);
1601 b
->last_commit
= object_count_by_type
[OBJ_COMMIT
];
1604 int need_dq
= quote_c_style(b
->name
, NULL
, NULL
, 0);
1605 fprintf(branch_log
, "commit ");
1607 fputc('"', branch_log
);
1608 quote_c_style(b
->name
, NULL
, branch_log
, 0);
1609 fputc('"', branch_log
);
1611 fprintf(branch_log
, "%s", b
->name
);
1612 fprintf(branch_log
," :%lu %s\n",next_mark
,sha1_to_hex(b
->sha1
));
1616 static void cmd_new_tag()
1627 unsigned long from_mark
= 0;
1628 unsigned char sha1
[20];
1630 /* Obtain the new tag name from the rest of our command */
1631 sp
= strchr(command_buf
.buf
, ' ') + 1;
1632 str_uq
= unquote_c_style(sp
, &endp
);
1635 die("Garbage after tag name in: %s", command_buf
.buf
);
1638 t
= pool_alloc(sizeof(struct tag
));
1640 t
->name
= pool_strdup(sp
);
1642 last_tag
->next_tag
= t
;
1648 read_next_command();
1651 if (strncmp("from ", command_buf
.buf
, 5))
1652 die("Expected from command, got %s", command_buf
.buf
);
1654 from
= strchr(command_buf
.buf
, ' ') + 1;
1655 str_uq
= unquote_c_style(from
, &endp
);
1658 die("Garbage after string in: %s", command_buf
.buf
);
1662 s
= lookup_branch(from
);
1664 hashcpy(sha1
, s
->sha1
);
1665 } else if (*from
== ':') {
1666 from_mark
= strtoul(from
+ 1, NULL
, 10);
1667 struct object_entry
*oe
= find_mark(from_mark
);
1668 if (oe
->type
!= OBJ_COMMIT
)
1669 die("Mark :%lu not a commit", from_mark
);
1670 hashcpy(sha1
, oe
->sha1
);
1671 } else if (!get_sha1(from
, sha1
)) {
1675 buf
= read_object_with_reference(sha1
,
1676 type_names
[OBJ_COMMIT
], &size
, sha1
);
1677 if (!buf
|| size
< 46)
1678 die("Not a valid commit: %s", from
);
1681 die("Invalid ref name or SHA1 expression: %s", from
);
1685 read_next_command();
1688 if (strncmp("tagger ", command_buf
.buf
, 7))
1689 die("Expected tagger command, got %s", command_buf
.buf
);
1690 tagger
= strdup(command_buf
.buf
);
1692 /* tag payload/message */
1693 read_next_command();
1694 msg
= cmd_data(&msglen
);
1696 /* build the tag object */
1697 size_dbuf(&new_data
, 67+strlen(t
->name
)+strlen(tagger
)+msglen
);
1698 sp
= new_data
.buffer
;
1699 sp
+= sprintf(sp
, "object %s\n", sha1_to_hex(sha1
));
1700 sp
+= sprintf(sp
, "type %s\n", type_names
[OBJ_COMMIT
]);
1701 sp
+= sprintf(sp
, "tag %s\n", t
->name
);
1702 sp
+= sprintf(sp
, "%s\n\n", tagger
);
1703 memcpy(sp
, msg
, msglen
);
1708 store_object(OBJ_TAG
, new_data
.buffer
, sp
- (char*)new_data
.buffer
,
1712 int need_dq
= quote_c_style(t
->name
, NULL
, NULL
, 0);
1713 fprintf(branch_log
, "tag ");
1715 fputc('"', branch_log
);
1716 quote_c_style(t
->name
, NULL
, branch_log
, 0);
1717 fputc('"', branch_log
);
1719 fprintf(branch_log
, "%s", t
->name
);
1720 fprintf(branch_log
," :%lu %s\n",from_mark
,sha1_to_hex(t
->sha1
));
1724 static void cmd_reset_branch()
1731 /* Obtain the branch name from the rest of our command */
1732 sp
= strchr(command_buf
.buf
, ' ') + 1;
1733 str_uq
= unquote_c_style(sp
, &endp
);
1736 die("Garbage after ref in: %s", command_buf
.buf
);
1739 b
= lookup_branch(sp
);
1742 if (b
->branch_tree
.tree
) {
1743 release_tree_content_recursive(b
->branch_tree
.tree
);
1744 b
->branch_tree
.tree
= NULL
;
1751 read_next_command();
1755 static void cmd_checkpoint()
1761 read_next_command();
1764 static const char fast_import_usage
[] =
1765 "git-fast-import [--objects=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file] [--branch-log=log] temp.pack";
1767 int main(int argc
, const char **argv
)
1770 unsigned long est_obj_cnt
= object_entry_alloc
;
1771 unsigned long duplicate_count
;
1774 git_config(git_default_config
);
1776 for (i
= 1; i
< argc
; i
++) {
1777 const char *a
= argv
[i
];
1779 if (*a
!= '-' || !strcmp(a
, "--"))
1781 else if (!strncmp(a
, "--objects=", 10))
1782 est_obj_cnt
= strtoul(a
+ 10, NULL
, 0);
1783 else if (!strncmp(a
, "--depth=", 8))
1784 max_depth
= strtoul(a
+ 8, NULL
, 0);
1785 else if (!strncmp(a
, "--active-branches=", 18))
1786 max_active_branches
= strtoul(a
+ 18, NULL
, 0);
1787 else if (!strncmp(a
, "--export-marks=", 15))
1789 else if (!strncmp(a
, "--branch-log=", 13)) {
1790 branch_log
= fopen(a
+ 13, "w");
1792 die("Can't create %s: %s", a
+ 13, strerror(errno
));
1795 die("unknown option %s", a
);
1798 usage(fast_import_usage
);
1799 base_name
= argv
[i
];
1801 alloc_objects(est_obj_cnt
);
1802 strbuf_init(&command_buf
);
1804 atom_table
= xcalloc(atom_table_sz
, sizeof(struct atom_str
*));
1805 branch_table
= xcalloc(branch_table_sz
, sizeof(struct branch
*));
1806 avail_tree_table
= xcalloc(avail_tree_table_sz
, sizeof(struct avail_tree_content
*));
1807 marks
= pool_calloc(1, sizeof(struct mark_set
));
1811 read_next_command();
1812 if (command_buf
.eof
)
1814 else if (!strcmp("blob", command_buf
.buf
))
1816 else if (!strncmp("commit ", command_buf
.buf
, 7))
1818 else if (!strncmp("tag ", command_buf
.buf
, 4))
1820 else if (!strncmp("reset ", command_buf
.buf
, 6))
1822 else if (!strcmp("checkpoint", command_buf
.buf
))
1825 die("Unsupported command: %s", command_buf
.buf
);
1835 for (i
= 0; i
< ARRAY_SIZE(duplicate_count_by_type
); i
++)
1836 duplicate_count
+= duplicate_count_by_type
[i
];
1838 fprintf(stderr
, "%s statistics:\n", argv
[0]);
1839 fprintf(stderr
, "---------------------------------------------------------------------\n");
1840 fprintf(stderr
, "Alloc'd objects: %10lu (%10lu overflow )\n", alloc_count
, alloc_count
- est_obj_cnt
);
1841 fprintf(stderr
, "Total objects: %10lu (%10lu duplicates )\n", object_count
, duplicate_count
);
1842 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
]);
1843 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
]);
1844 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
]);
1845 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
]);
1846 fprintf(stderr
, "Total branches: %10lu (%10lu loads )\n", branch_count
, branch_load_count
);
1847 fprintf(stderr
, " marks: %10u (%10lu unique )\n", (1 << marks
->shift
) * 1024, marks_set_count
);
1848 fprintf(stderr
, " atoms: %10u\n", atom_cnt
);
1849 fprintf(stderr
, "Memory total: %10lu KiB\n", (total_allocd
+ alloc_count
*sizeof(struct object_entry
))/1024);
1850 fprintf(stderr
, " pools: %10lu KiB\n", total_allocd
/1024);
1851 fprintf(stderr
, " objects: %10lu KiB\n", (alloc_count
*sizeof(struct object_entry
))/1024);
1852 fprintf(stderr
, "---------------------------------------------------------------------\n");
1854 fprintf(stderr
, "---------------------------------------------------------------------\n");
1855 fprintf(stderr
, "\n");