670
return &index[pos]->oid;
671
}
672
673
-static void write_selected_commits_v1(struct hashfile *f,
674
- uint32_t *commit_positions,
675
- off_t *offsets)
673
+static void write_selected_commits_v1(struct hashfile *f, off_t *offsets)
674
{
675
int i;
676
680
if (offsets)
681
offsets[i] = hashfile_total(f);
682
685
- hashwrite_be32(f, commit_positions[i]);
683
+ hashwrite_be32(f, stored->commit_pos);
684
hashwrite_u8(f, stored->xor_offset);
685
hashwrite_u8(f, stored->flags);
686
688
}
689
}
690
693
-static int table_cmp(const void *_va, const void *_vb, void *_data)
691
+static int table_cmp(const void *_va, const void *_vb)
692
{
695
- uint32_t *commit_positions = _data;
696
- uint32_t a = commit_positions[*(uint32_t *)_va];
697
- uint32_t b = commit_positions[*(uint32_t *)_vb];
693
+ struct bitmapped_commit *a = &writer.selected[*(uint32_t *)_va];
694
+ struct bitmapped_commit *b = &writer.selected[*(uint32_t *)_vb];
695
699
- if (a > b)
700
- return 1;
701
- else if (a < b)
696
+ if (a->commit_pos < b->commit_pos)
697
return -1;
698
+ else if (a->commit_pos > b->commit_pos)
699
+ return 1;
700
701
return 0;
702
}
703
707
-static void write_lookup_table(struct hashfile *f,
708
- uint32_t *commit_positions,
709
- off_t *offsets)
704
+static void write_lookup_table(struct hashfile *f, off_t *offsets)
705
{
706
uint32_t i;
707
uint32_t *table, *table_inv;
717
* bitmap corresponds to j'th bitmapped commit (among the selected
718
* commits) in lex order of OIDs.
719
*/
725
- QSORT_S(table, writer.selected_nr, table_cmp, commit_positions);
720
+ QSORT(table, writer.selected_nr, table_cmp);
721
722
/* table_inv helps us discover that relationship (i'th bitmap
723
* to j'th commit by j = table_inv[i])
748
xor_row = 0xffffffff;
749
}
750
756
- hashwrite_be32(f, commit_positions[table[i]]);
751
+ hashwrite_be32(f, writer.selected[table[i]].commit_pos);
752
hashwrite_be64(f, (uint64_t)offsets[table[i]]);
753
hashwrite_be32(f, xor_row);
754
}
784
static uint16_t flags = BITMAP_OPT_FULL_DAG;
785
struct strbuf tmp_file = STRBUF_INIT;
786
struct hashfile *f;
792
- uint32_t *commit_positions = NULL;
787
off_t *offsets = NULL;
788
uint32_t i;
789
808
if (options & BITMAP_OPT_LOOKUP_TABLE)
809
CALLOC_ARRAY(offsets, index_nr);
810
817
- ALLOC_ARRAY(commit_positions, writer.selected_nr);
818
-
811
for (i = 0; i < writer.selected_nr; i++) {
812
struct bitmapped_commit *stored = &writer.selected[i];
821
- int commit_pos = oid_pos(&stored->commit->object.oid, index, index_nr, oid_access);
813
+ int commit_pos = oid_pos(&stored->commit->object.oid, index,
814
+ index_nr, oid_access);
815
816
if (commit_pos < 0)
817
BUG(_("trying to write commit not in index"));
825
-
826
- commit_positions[i] = commit_pos;
818
+ stored->commit_pos = commit_pos;
819
}
820
829
- write_selected_commits_v1(f, commit_positions, offsets);
821
+ write_selected_commits_v1(f, offsets);
822
823
if (options & BITMAP_OPT_LOOKUP_TABLE)
832
- write_lookup_table(f, commit_positions, offsets);
824
+ write_lookup_table(f, offsets);
825
826
if (options & BITMAP_OPT_HASH_CACHE)
827
write_hash_cache(f, index, index_nr);
836
die_errno("unable to rename temporary bitmap file to '%s'", filename);
837
838
strbuf_release(&tmp_file);
847
- free(commit_positions);
839
free(offsets);
840
}