2525#include "alloc.h"
2626#include "refs.h"
2727#include "strmap.h"
28+ #include "midx.h"
29+ #include "pack-revindex.h"
2830
2931struct bitmapped_commit {
3032 struct commit * commit ;
@@ -42,14 +44,16 @@ static inline int bitmap_writer_nr_selected_commits(struct bitmap_writer *writer
4244}
4345
4446void bitmap_writer_init (struct bitmap_writer * writer , struct repository * r ,
45- struct packing_data * pdata )
47+ struct packing_data * pdata ,
48+ struct multi_pack_index * midx )
4649{
4750 memset (writer , 0 , sizeof (struct bitmap_writer ));
4851 if (writer -> bitmaps )
4952 BUG ("bitmap writer already initialized" );
5053 writer -> bitmaps = kh_init_oid_map ();
5154 writer -> pseudo_merge_commits = kh_init_oid_map ();
5255 writer -> to_pack = pdata ;
56+ writer -> midx = midx ;
5357
5458 string_list_init_dup (& writer -> pseudo_merge_groups );
5559
@@ -104,6 +108,11 @@ void bitmap_writer_build_type_index(struct bitmap_writer *writer,
104108 struct pack_idx_entry * * index )
105109{
106110 uint32_t i ;
111+ uint32_t base_objects = 0 ;
112+
113+ if (writer -> midx )
114+ base_objects = writer -> midx -> num_objects +
115+ writer -> midx -> num_objects_in_base ;
107116
108117 writer -> commits = ewah_new ();
109118 writer -> trees = ewah_new ();
@@ -133,19 +142,19 @@ void bitmap_writer_build_type_index(struct bitmap_writer *writer,
133142
134143 switch (real_type ) {
135144 case OBJ_COMMIT :
136- ewah_set (writer -> commits , i );
145+ ewah_set (writer -> commits , i + base_objects );
137146 break ;
138147
139148 case OBJ_TREE :
140- ewah_set (writer -> trees , i );
149+ ewah_set (writer -> trees , i + base_objects );
141150 break ;
142151
143152 case OBJ_BLOB :
144- ewah_set (writer -> blobs , i );
153+ ewah_set (writer -> blobs , i + base_objects );
145154 break ;
146155
147156 case OBJ_TAG :
148- ewah_set (writer -> tags , i );
157+ ewah_set (writer -> tags , i + base_objects );
149158 break ;
150159
151160 default :
@@ -198,19 +207,37 @@ void bitmap_writer_push_commit(struct bitmap_writer *writer,
198207static uint32_t find_object_pos (struct bitmap_writer * writer ,
199208 const struct object_id * oid , int * found )
200209{
201- struct object_entry * entry = packlist_find (writer -> to_pack , oid );
210+ struct object_entry * entry ;
211+
212+ entry = packlist_find (writer -> to_pack , oid );
213+ if (entry ) {
214+ uint32_t base_objects = 0 ;
215+ if (writer -> midx )
216+ base_objects = writer -> midx -> num_objects +
217+ writer -> midx -> num_objects_in_base ;
202218
203- if (!entry ) {
204219 if (found )
205- * found = 0 ;
206- warning ("Failed to write bitmap index. Packfile doesn't have full closure "
207- "(object %s is missing)" , oid_to_hex (oid ));
208- return 0 ;
220+ * found = 1 ;
221+ return oe_in_pack_pos (writer -> to_pack , entry ) + base_objects ;
222+ } else if (writer -> midx ) {
223+ uint32_t at , pos ;
224+
225+ if (!bsearch_midx (oid , writer -> midx , & at ))
226+ goto missing ;
227+ if (midx_to_pack_pos (writer -> midx , at , & pos ) < 0 )
228+ goto missing ;
229+
230+ if (found )
231+ * found = 1 ;
232+ return pos ;
209233 }
210234
235+ missing :
211236 if (found )
212- * found = 1 ;
213- return oe_in_pack_pos (writer -> to_pack , entry );
237+ * found = 0 ;
238+ warning ("Failed to write bitmap index. Packfile doesn't have full closure "
239+ "(object %s is missing)" , oid_to_hex (oid ));
240+ return 0 ;
214241}
215242
216243static void compute_xor_offsets (struct bitmap_writer * writer )
@@ -577,7 +604,7 @@ int bitmap_writer_build(struct bitmap_writer *writer)
577604 struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
578605 struct prio_queue tree_queue = { NULL };
579606 struct bitmap_index * old_bitmap ;
580- uint32_t * mapping ;
607+ uint32_t * mapping = NULL ;
581608 int closed = 1 ; /* until proven otherwise */
582609
583610 if (writer -> show_progress )
@@ -1009,7 +1036,7 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
10091036 struct strbuf tmp_file = STRBUF_INIT ;
10101037 struct hashfile * f ;
10111038 off_t * offsets = NULL ;
1012- uint32_t i ;
1039+ uint32_t i , base_objects ;
10131040
10141041 struct bitmap_disk_header header ;
10151042
@@ -1035,6 +1062,12 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
10351062 if (options & BITMAP_OPT_LOOKUP_TABLE )
10361063 CALLOC_ARRAY (offsets , writer -> to_pack -> nr_objects );
10371064
1065+ if (writer -> midx )
1066+ base_objects = writer -> midx -> num_objects +
1067+ writer -> midx -> num_objects_in_base ;
1068+ else
1069+ base_objects = 0 ;
1070+
10381071 for (i = 0 ; i < bitmap_writer_nr_selected_commits (writer ); i ++ ) {
10391072 struct bitmapped_commit * stored = & writer -> selected [i ];
10401073 int commit_pos = oid_pos (& stored -> commit -> object .oid , index ,
@@ -1043,7 +1076,7 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
10431076
10441077 if (commit_pos < 0 )
10451078 BUG (_ ("trying to write commit not in index" ));
1046- stored -> commit_pos = commit_pos ;
1079+ stored -> commit_pos = commit_pos + base_objects ;
10471080 }
10481081
10491082 write_selected_commits_v1 (writer , f , offsets );
0 commit comments