static struct rerere_dir *find_rerere_dir(const char *hex) { unsigned char sha1[20]; struct rerere_dir *rr_dir; int pos; if (get_sha1_hex(hex, sha1)) return NULL; /* BUG */ pos = sha1_pos(sha1, rerere_dir, rerere_dir_nr, rerere_dir_sha1); if (pos < 0) { rr_dir = xmalloc(sizeof(*rr_dir)); hashcpy(rr_dir->sha1, sha1); rr_dir->status = NULL; rr_dir->status_nr = 0; rr_dir->status_alloc = 0; pos = -1 - pos; /* Make sure the array is big enough ... */ ALLOC_GROW(rerere_dir, rerere_dir_nr + 1, rerere_dir_alloc); /* ... and add it in. */ rerere_dir_nr++; MOVE_ARRAY(rerere_dir + pos + 1, rerere_dir + pos, rerere_dir_nr - pos - 1); rerere_dir[pos] = rr_dir; scan_rerere_dir(rr_dir); } return rerere_dir[pos]; }
static int lookup_sha1_array(struct sha1_array *array, const unsigned char *sha1) { if (!array->sorted) sort_sha1_array(array); return sha1_pos(sha1, array->sha1, array->sha1_nr, sha1_access); }
static const char *get_exact_ref_match(const struct object *o) { int found; if (!tip_table.table || !tip_table.nr) return NULL; if (!tip_table.sorted) { qsort(tip_table.table, tip_table.nr, sizeof(*tip_table.table), tipcmp); tip_table.sorted = 1; } found = sha1_pos(o->oid.hash, tip_table.table, tip_table.nr, nth_tip_table_ent); if (0 <= found) return tip_table.table[found].refname; return NULL; }
static void write_selected_commits_v1(struct hashfile *f, struct pack_idx_entry **index, uint32_t index_nr) { int i; for (i = 0; i < writer.selected_nr; ++i) { struct bitmapped_commit *stored = &writer.selected[i]; int commit_pos = sha1_pos(stored->commit->object.oid.hash, index, index_nr, sha1_access); if (commit_pos < 0) BUG("trying to write commit not in index"); hashwrite_be32(f, commit_pos); hashwrite_u8(f, stored->xor_offset); hashwrite_u8(f, stored->flags); dump_bitmap(f, stored->write_as); } }
static void write_selected_commits_v1(struct sha1file *f, struct pack_idx_entry **index, uint32_t index_nr) { int i; for (i = 0; i < writer.selected_nr; ++i) { struct bitmapped_commit *stored = &writer.selected[i]; struct bitmap_disk_entry on_disk; int commit_pos = sha1_pos(stored->commit->object.sha1, index, index_nr, sha1_access); if (commit_pos < 0) die("BUG: trying to write commit not in index"); on_disk.object_pos = htonl(commit_pos); on_disk.xor_offset = stored->xor_offset; on_disk.flags = stored->flags; sha1write(f, &on_disk, sizeof(on_disk)); dump_bitmap(f, stored->write_as); } }
int sha1_array_lookup(struct sha1_array *array, const unsigned char *sha1) { if (!array->sorted) sha1_array_sort(array); return sha1_pos(sha1, array->sha1, array->nr, sha1_access); }
int oid_array_lookup(struct oid_array *array, const struct object_id *oid) { if (!array->sorted) oid_array_sort(array); return sha1_pos(oid->hash, array->oid, array->nr, sha1_access); }
static int replace_object_pos(const unsigned char *sha1) { return sha1_pos(sha1, replace_object, replace_object_nr, replace_sha1_access); }