Code clean-up to remove hardcoded SHA-1 hash from many places.

* jk/oidhash:
  hashmap: convert sha1hash() to oidhash()
  hash.h: move object_id definition from cache.h
  khash: rename oid helper functions
  khash: drop sha1-specific map types
  pack-bitmap: convert khash_sha1 maps into kh_oid_map
  delta-islands: convert island_marks khash to use oids
  khash: rename kh_oid_t to kh_oid_set
  khash: drop broken oid_map typedef
  object: convert create_object() to use object_id
  object: convert internal hash_obj() to object_id
  object: convert lookup_object() to use object_id
  object: convert lookup_unknown_object() to use object_id
  pack-objects: convert locate_object_entry_hash() to object_id
  pack-objects: convert packlist_find() to use object_id
  pack-bitmap-write: convert some helpers to use object_id
  upload-pack: rename a "sha1" variable to "oid"
  describe: fix accidental oid/hash type-punning
This commit is contained in:
Junio C Hamano 2019-07-09 15:25:43 -07:00
Родитель a4c8352e1e d40abc8e95
Коммит a7db4c193d
37 изменённых файлов: 156 добавлений и 168 удалений

5
blob.c
Просмотреть файл

@ -7,10 +7,9 @@ const char *blob_type = "blob";
struct blob *lookup_blob(struct repository *r, const struct object_id *oid)
{
struct object *obj = lookup_object(r, oid->hash);
struct object *obj = lookup_object(r, oid);
if (!obj)
return create_object(r, oid->hash,
alloc_blob_node(r));
return create_object(r, oid, alloc_blob_node(r));
return object_as_type(r, obj, OBJ_BLOB, 0);
}

Просмотреть файл

@ -76,7 +76,7 @@ static int commit_name_neq(const void *unused_cmp_data,
static inline struct commit_name *find_commit_name(const struct object_id *peeled)
{
return hashmap_get_from_hash(&names, sha1hash(peeled->hash), peeled->hash);
return hashmap_get_from_hash(&names, oidhash(peeled), peeled);
}
static int replace_name(struct commit_name *e,
@ -123,7 +123,7 @@ static void add_to_known_names(const char *path,
if (!e) {
e = xmalloc(sizeof(struct commit_name));
oidcpy(&e->peeled, peeled);
hashmap_entry_init(e, sha1hash(peeled->hash));
hashmap_entry_init(e, oidhash(peeled));
hashmap_add(&names, e);
e->path = NULL;
}

Просмотреть файл

@ -275,7 +275,7 @@ static void export_blob(const struct object_id *oid)
if (is_null_oid(oid))
return;
object = lookup_object(the_repository, oid->hash);
object = lookup_object(the_repository, oid);
if (object && object->flags & SHOWN)
return;
@ -453,7 +453,7 @@ static void show_filemodify(struct diff_queue_struct *q,
&spec->oid));
else {
struct object *object = lookup_object(the_repository,
spec->oid.hash);
&spec->oid);
printf("M %06o :%d ", spec->mode,
get_object_mark(object));
}

Просмотреть файл

@ -238,7 +238,7 @@ static int mark_used(struct object *obj, int type, void *data, struct fsck_optio
static void mark_unreachable_referents(const struct object_id *oid)
{
struct fsck_options options = FSCK_OPTIONS_DEFAULT;
struct object *obj = lookup_object(the_repository, oid->hash);
struct object *obj = lookup_object(the_repository, oid);
if (!obj || !(obj->flags & HAS_OBJ))
return; /* not part of our original set */
@ -497,7 +497,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
struct object *obj;
if (!is_null_oid(oid)) {
obj = lookup_object(the_repository, oid->hash);
obj = lookup_object(the_repository, oid);
if (obj && (obj->flags & HAS_OBJ)) {
if (timestamp && name_objects)
add_decoration(fsck_walk_options.object_names,
@ -756,7 +756,7 @@ static int fsck_cache_tree(struct cache_tree *it)
static void mark_object_for_connectivity(const struct object_id *oid)
{
struct object *obj = lookup_unknown_object(oid->hash);
struct object *obj = lookup_unknown_object(oid);
obj->flags |= HAS_OBJ;
}
@ -879,7 +879,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
struct object_id oid;
if (!get_oid(arg, &oid)) {
struct object *obj = lookup_object(the_repository,
oid.hash);
&oid);
if (!obj || !(obj->flags & HAS_OBJ)) {
if (is_promisor_object(&oid))

Просмотреть файл

@ -378,8 +378,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
*(p+1) = 0;
if (!get_oid(p - (hexsz - 1), &oid)) {
struct object *o =
lookup_object(the_repository,
oid.hash);
lookup_object(the_repository, &oid);
if (o)
name = get_rev_name(o, &buf);
}

Просмотреть файл

@ -606,12 +606,12 @@ static int mark_tagged(const char *path, const struct object_id *oid, int flag,
void *cb_data)
{
struct object_id peeled;
struct object_entry *entry = packlist_find(&to_pack, oid->hash, NULL);
struct object_entry *entry = packlist_find(&to_pack, oid, NULL);
if (entry)
entry->tagged = 1;
if (!peel_ref(path, &peeled)) {
entry = packlist_find(&to_pack, peeled.hash, NULL);
entry = packlist_find(&to_pack, &peeled, NULL);
if (entry)
entry->tagged = 1;
}
@ -996,7 +996,7 @@ static int have_duplicate_entry(const struct object_id *oid,
{
struct object_entry *entry;
entry = packlist_find(&to_pack, oid->hash, index_pos);
entry = packlist_find(&to_pack, oid, index_pos);
if (!entry)
return 0;
@ -1494,11 +1494,13 @@ static int can_reuse_delta(const unsigned char *base_sha1,
if (!base_sha1)
return 0;
oidread(&base_oid, base_sha1);
/*
* First see if we're already sending the base (or it's explicitly in
* our "excluded" list).
*/
base = packlist_find(&to_pack, base_sha1, NULL);
base = packlist_find(&to_pack, &base_oid, NULL);
if (base) {
if (!in_same_island(&delta->idx.oid, &base->idx.oid))
return 0;
@ -1511,7 +1513,6 @@ static int can_reuse_delta(const unsigned char *base_sha1,
* even if it was buried too deep in history to make it into the
* packing list.
*/
oidread(&base_oid, base_sha1);
if (thin && bitmap_has_oid_in_uninteresting(bitmap_git, &base_oid)) {
if (use_delta_islands) {
if (!in_same_island(&delta->idx.oid, &base_oid))
@ -2571,7 +2572,7 @@ static void add_tag_chain(const struct object_id *oid)
* it was included via bitmaps, we would not have parsed it
* previously).
*/
if (packlist_find(&to_pack, oid->hash, NULL))
if (packlist_find(&to_pack, oid, NULL))
return;
tag = lookup_tag(the_repository, oid);
@ -2595,7 +2596,7 @@ static int add_ref_tag(const char *path, const struct object_id *oid, int flag,
if (starts_with(path, "refs/tags/") && /* is a tag? */
!peel_ref(path, &peeled) && /* peelable? */
packlist_find(&to_pack, peeled.hash, NULL)) /* object packed? */
packlist_find(&to_pack, &peeled, NULL)) /* object packed? */
add_tag_chain(oid);
return 0;
}
@ -2795,7 +2796,7 @@ static void show_object(struct object *obj, const char *name, void *data)
for (p = strchr(name, '/'); p; p = strchr(p + 1, '/'))
depth++;
ent = packlist_find(&to_pack, obj->oid.hash, NULL);
ent = packlist_find(&to_pack, &obj->oid, NULL);
if (ent && depth > oe_tree_depth(&to_pack, ent))
oe_set_tree_depth(&to_pack, ent, depth);
}
@ -2922,7 +2923,7 @@ static void add_objects_in_unpacked_packs(void)
for (i = 0; i < p->num_objects; i++) {
nth_packed_object_oid(&oid, p, i);
o = lookup_unknown_object(oid.hash);
o = lookup_unknown_object(&oid);
if (!(o->flags & OBJECT_ADDED))
mark_in_pack_object(o, p, &in_pack);
o->flags |= OBJECT_ADDED;
@ -3026,7 +3027,7 @@ static void loosen_unused_packed_objects(void)
for (i = 0; i < p->num_objects; i++) {
nth_packed_object_oid(&oid, p, i);
if (!packlist_find(&to_pack, oid.hash, NULL) &&
if (!packlist_find(&to_pack, &oid, NULL) &&
!has_sha1_pack_kept_or_nonlocal(&oid) &&
!loosened_object_can_be_discarded(&oid, p->mtime))
if (force_object_loose(&oid, p->mtime))

Просмотреть файл

@ -53,7 +53,7 @@ static int is_object_reachable(const struct object_id *oid,
perform_reachability_traversal(revs);
obj = lookup_object(the_repository, oid->hash);
obj = lookup_object(the_repository, oid);
return obj && (obj->flags & SEEN);
}

Просмотреть файл

@ -332,7 +332,7 @@ static int resolve_against_held(unsigned nr, const struct object_id *base,
{
struct object *obj;
struct obj_buffer *obj_buffer;
obj = lookup_object(the_repository, base->hash);
obj = lookup_object(the_repository, base);
if (!obj)
return 0;
obj_buffer = lookup_object_buffer(obj);

24
cache.h
Просмотреть файл

@ -43,30 +43,6 @@ int git_deflate_end_gently(git_zstream *);
int git_deflate(git_zstream *, int flush);
unsigned long git_deflate_bound(git_zstream *, unsigned long);
/* The length in bytes and in hex digits of an object name (SHA-1 value). */
#define GIT_SHA1_RAWSZ 20
#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
/* The block size of SHA-1. */
#define GIT_SHA1_BLKSZ 64
/* The length in bytes and in hex digits of an object name (SHA-256 value). */
#define GIT_SHA256_RAWSZ 32
#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ)
/* The block size of SHA-256. */
#define GIT_SHA256_BLKSZ 64
/* The length in byte and in hex digits of the largest possible hash value. */
#define GIT_MAX_RAWSZ GIT_SHA256_RAWSZ
#define GIT_MAX_HEXSZ GIT_SHA256_HEXSZ
/* The largest possible block size for any supported hash. */
#define GIT_MAX_BLKSZ GIT_SHA256_BLKSZ
struct object_id {
unsigned char hash[GIT_MAX_RAWSZ];
};
#define the_hash_algo the_repository->hash_algo
#if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)
#define DTYPE(de) ((de)->d_type)
#else

Просмотреть файл

@ -1279,7 +1279,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
graph_commit = lookup_commit(r, &cur_oid);
odb_commit = (struct commit *)create_object(r, cur_oid.hash, alloc_commit_node(r));
odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));
if (parse_commit_internal(odb_commit, 0, 0)) {
graph_report(_("failed to parse commit %s from object database for commit-graph"),
oid_to_hex(&cur_oid));

Просмотреть файл

@ -57,10 +57,9 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
struct commit *lookup_commit(struct repository *r, const struct object_id *oid)
{
struct object *obj = lookup_object(r, oid->hash);
struct object *obj = lookup_object(r, oid);
if (!obj)
return create_object(r, oid->hash,
alloc_commit_node(r));
return create_object(r, oid, alloc_commit_node(r));
return object_as_type(r, obj, OBJ_COMMIT, 0);
}

Просмотреть файл

@ -8,7 +8,7 @@
static unsigned int hash_obj(const struct object *obj, unsigned int n)
{
return sha1hash(obj->oid.hash) % n;
return oidhash(&obj->oid) % n;
}
static void *insert_decoration(struct decoration *n, const struct object *base, void *decoration)

Просмотреть файл

@ -22,7 +22,7 @@
KHASH_INIT(str, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal)
static khash_sha1 *island_marks;
static kh_oid_map_t *island_marks;
static unsigned island_counter;
static unsigned island_counter_core;
@ -105,7 +105,7 @@ int in_same_island(const struct object_id *trg_oid, const struct object_id *src_
* If we don't have a bitmap for the target, we can delta it
* against anything -- it's not an important object
*/
trg_pos = kh_get_sha1(island_marks, trg_oid->hash);
trg_pos = kh_get_oid_map(island_marks, *trg_oid);
if (trg_pos >= kh_end(island_marks))
return 1;
@ -113,7 +113,7 @@ int in_same_island(const struct object_id *trg_oid, const struct object_id *src_
* if the source (our delta base) doesn't have a bitmap,
* we don't want to base any deltas on it!
*/
src_pos = kh_get_sha1(island_marks, src_oid->hash);
src_pos = kh_get_oid_map(island_marks, *src_oid);
if (src_pos >= kh_end(island_marks))
return 0;
@ -129,11 +129,11 @@ int island_delta_cmp(const struct object_id *a, const struct object_id *b)
if (!island_marks)
return 0;
a_pos = kh_get_sha1(island_marks, a->hash);
a_pos = kh_get_oid_map(island_marks, *a);
if (a_pos < kh_end(island_marks))
a_bitmap = kh_value(island_marks, a_pos);
b_pos = kh_get_sha1(island_marks, b->hash);
b_pos = kh_get_oid_map(island_marks, *b);
if (b_pos < kh_end(island_marks))
b_bitmap = kh_value(island_marks, b_pos);
@ -154,7 +154,7 @@ static struct island_bitmap *create_or_get_island_marks(struct object *obj)
khiter_t pos;
int hash_ret;
pos = kh_put_sha1(island_marks, obj->oid.hash, &hash_ret);
pos = kh_put_oid_map(island_marks, obj->oid, &hash_ret);
if (hash_ret)
kh_value(island_marks, pos) = island_bitmap_new(NULL);
@ -167,7 +167,7 @@ static void set_island_marks(struct object *obj, struct island_bitmap *marks)
khiter_t pos;
int hash_ret;
pos = kh_put_sha1(island_marks, obj->oid.hash, &hash_ret);
pos = kh_put_oid_map(island_marks, obj->oid, &hash_ret);
if (hash_ret) {
/*
* We don't have one yet; make a copy-on-write of the
@ -279,7 +279,7 @@ void resolve_tree_islands(struct repository *r,
struct name_entry entry;
khiter_t pos;
pos = kh_get_sha1(island_marks, ent->idx.oid.hash);
pos = kh_get_oid_map(island_marks, ent->idx.oid);
if (pos >= kh_end(island_marks))
continue;
@ -296,7 +296,7 @@ void resolve_tree_islands(struct repository *r,
if (S_ISGITLINK(entry.mode))
continue;
obj = lookup_object(r, entry.oid.hash);
obj = lookup_object(r, &entry.oid);
if (!obj)
continue;
@ -456,7 +456,7 @@ static void deduplicate_islands(struct repository *r)
void load_delta_islands(struct repository *r, int progress)
{
island_marks = kh_init_sha1();
island_marks = kh_init_oid_map();
remote_islands = kh_init_str();
git_config(island_config_callback, NULL);
@ -469,7 +469,7 @@ void load_delta_islands(struct repository *r, int progress)
void propagate_island_marks(struct commit *commit)
{
khiter_t pos = kh_get_sha1(island_marks, commit->object.oid.hash);
khiter_t pos = kh_get_oid_map(island_marks, commit->object.oid);
if (pos < kh_end(island_marks)) {
struct commit_list *p;
@ -491,7 +491,7 @@ int compute_pack_layers(struct packing_data *to_pack)
for (i = 0; i < to_pack->nr_objects; ++i) {
struct object_entry *entry = &to_pack->objects[i];
khiter_t pos = kh_get_sha1(island_marks, entry->idx.oid.hash);
khiter_t pos = kh_get_oid_map(island_marks, entry->idx.oid);
oe_set_layer(to_pack, entry, 1);

Просмотреть файл

@ -266,7 +266,7 @@ static unsigned int hash_filespec(struct repository *r,
hash_object_file(filespec->data, filespec->size, "blob",
&filespec->oid);
}
return sha1hash(filespec->oid.hash);
return oidhash(&filespec->oid);
}
static int find_identical_files(struct hashmap *srcs,

Просмотреть файл

@ -286,7 +286,7 @@ static int find_common(struct fetch_negotiator *negotiator,
* we cannot trust the object flags).
*/
if (!args->no_dependents &&
((o = lookup_object(the_repository, remote->hash)) != NULL) &&
((o = lookup_object(the_repository, remote)) != NULL) &&
(o->flags & COMPLETE)) {
continue;
}
@ -364,7 +364,7 @@ static int find_common(struct fetch_negotiator *negotiator,
if (skip_prefix(reader.line, "unshallow ", &arg)) {
if (get_oid_hex(arg, &oid))
die(_("invalid unshallow line: %s"), reader.line);
if (!lookup_object(the_repository, oid.hash))
if (!lookup_object(the_repository, &oid))
die(_("object not found: %s"), reader.line);
/* make sure that it is parsed as shallow */
if (!parse_object(the_repository, &oid))
@ -707,7 +707,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
for (ref = *refs; ref; ref = ref->next) {
struct object *o = deref_tag(the_repository,
lookup_object(the_repository,
ref->old_oid.hash),
&ref->old_oid),
NULL, 0);
if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
@ -734,7 +734,7 @@ static int everything_local(struct fetch_pack_args *args,
const struct object_id *remote = &ref->old_oid;
struct object *o;
o = lookup_object(the_repository, remote->hash);
o = lookup_object(the_repository, remote);
if (!o || !(o->flags & COMPLETE)) {
retval = 0;
print_verbose(args, "want %s (%s)", oid_to_hex(remote),
@ -1048,7 +1048,7 @@ static void add_wants(int no_dependents, const struct ref *wants, struct strbuf
* we cannot trust the object flags).
*/
if (!no_dependents &&
((o = lookup_object(the_repository, remote->hash)) != NULL) &&
((o = lookup_object(the_repository, remote)) != NULL) &&
(o->flags & COMPLETE)) {
continue;
}
@ -1275,7 +1275,7 @@ static void receive_shallow_info(struct fetch_pack_args *args,
if (skip_prefix(reader->line, "unshallow ", &arg)) {
if (get_oid_hex(arg, &oid))
die(_("invalid unshallow line: %s"), reader->line);
if (!lookup_object(the_repository, oid.hash))
if (!lookup_object(the_repository, &oid))
die(_("object not found: %s"), reader->line);
/* make sure that it is parsed as shallow */
if (!parse_object(the_repository, &oid))

2
fsck.c
Просмотреть файл

@ -1092,7 +1092,7 @@ int fsck_finish(struct fsck_options *options)
blob = lookup_blob(the_repository, oid);
if (!blob) {
struct object *obj = lookup_unknown_object(oid->hash);
struct object *obj = lookup_unknown_object(oid);
ret |= report(options, obj,
FSCK_MSG_GITMODULES_BLOB,
"non-blob found at .gitmodules");

24
hash.h
Просмотреть файл

@ -139,4 +139,28 @@ static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
return p - hash_algos;
}
/* The length in bytes and in hex digits of an object name (SHA-1 value). */
#define GIT_SHA1_RAWSZ 20
#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
/* The block size of SHA-1. */
#define GIT_SHA1_BLKSZ 64
/* The length in bytes and in hex digits of an object name (SHA-256 value). */
#define GIT_SHA256_RAWSZ 32
#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ)
/* The block size of SHA-256. */
#define GIT_SHA256_BLKSZ 64
/* The length in byte and in hex digits of the largest possible hash value. */
#define GIT_MAX_RAWSZ GIT_SHA256_RAWSZ
#define GIT_MAX_HEXSZ GIT_SHA256_HEXSZ
/* The largest possible block size for any supported hash. */
#define GIT_MAX_BLKSZ GIT_SHA256_BLKSZ
struct object_id {
unsigned char hash[GIT_MAX_RAWSZ];
};
#define the_hash_algo the_repository->hash_algo
#endif

Просмотреть файл

@ -1,6 +1,8 @@
#ifndef HASHMAP_H
#define HASHMAP_H
#include "hash.h"
/*
* Generic implementation of hash-based key-value mappings.
*
@ -118,14 +120,14 @@ unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len);
* the results will be different on big-endian and little-endian
* platforms, so they should not be stored or transferred over the net.
*/
static inline unsigned int sha1hash(const unsigned char *sha1)
static inline unsigned int oidhash(const struct object_id *oid)
{
/*
* Equivalent to 'return *(unsigned int *)sha1;', but safe on
* Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
* platforms that don't support unaligned reads.
*/
unsigned int hash;
memcpy(&hash, sha1, sizeof(hash));
memcpy(&hash, oid->hash, sizeof(hash));
return hash;
}

Просмотреть файл

@ -723,7 +723,7 @@ static void one_remote_object(const struct object_id *oid)
{
struct object *obj;
obj = lookup_object(the_repository, oid->hash);
obj = lookup_object(the_repository, oid);
if (!obj)
obj = parse_object(the_repository, oid);
@ -1432,7 +1432,7 @@ static void one_remote_ref(const char *refname)
* may be required for updating server info later.
*/
if (repo->can_update_info_refs && !has_object_file(&ref->old_oid)) {
obj = lookup_unknown_object(ref->old_oid.hash);
obj = lookup_unknown_object(&ref->old_oid);
fprintf(stderr, " fetch %s for %s\n",
oid_to_hex(&ref->old_oid), refname);
add_fetch_request(obj);

22
khash.h
Просмотреть файл

@ -324,30 +324,20 @@ static const double __ac_HASH_UPPER = 0.77;
code; \
} }
#define __kh_oid_cmp(a, b) (hashcmp(a, b) == 0)
KHASH_INIT(sha1, const unsigned char *, void *, 1, sha1hash, __kh_oid_cmp)
typedef kh_sha1_t khash_sha1;
KHASH_INIT(sha1_pos, const unsigned char *, int, 1, sha1hash, __kh_oid_cmp)
typedef kh_sha1_pos_t khash_sha1_pos;
static inline unsigned int oid_hash(struct object_id oid)
static inline unsigned int oidhash_by_value(struct object_id oid)
{
return sha1hash(oid.hash);
return oidhash(&oid);
}
static inline int oid_equal(struct object_id a, struct object_id b)
static inline int oideq_by_value(struct object_id a, struct object_id b)
{
return oideq(&a, &b);
}
KHASH_INIT(oid, struct object_id, int, 0, oid_hash, oid_equal)
KHASH_INIT(oid_set, struct object_id, int, 0, oidhash_by_value, oideq_by_value)
KHASH_INIT(oid_map, struct object_id, void *, 1, oid_hash, oid_equal)
typedef kh_oid_t khash_oid_map;
KHASH_INIT(oid_map, struct object_id, void *, 1, oidhash_by_value, oideq_by_value)
KHASH_INIT(oid_pos, struct object_id, int, 1, oid_hash, oid_equal)
typedef kh_oid_pos_t khash_oid_pos;
KHASH_INIT(oid_pos, struct object_id, int, 1, oidhash_by_value, oideq_by_value)
#endif /* __AC_KHASH_H */

Просмотреть файл

@ -59,9 +59,9 @@ int type_from_string_gently(const char *str, ssize_t len, int gentle)
* the specified sha1. n must be a power of 2. Please note that the
* return value is *not* consistent across computer architectures.
*/
static unsigned int hash_obj(const unsigned char *sha1, unsigned int n)
static unsigned int hash_obj(const struct object_id *oid, unsigned int n)
{
return sha1hash(sha1) & (n - 1);
return oidhash(oid) & (n - 1);
}
/*
@ -71,7 +71,7 @@ static unsigned int hash_obj(const unsigned char *sha1, unsigned int n)
*/
static void insert_obj_hash(struct object *obj, struct object **hash, unsigned int size)
{
unsigned int j = hash_obj(obj->oid.hash, size);
unsigned int j = hash_obj(&obj->oid, size);
while (hash[j]) {
j++;
@ -85,7 +85,7 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i
* Look up the record for the given sha1 in the hash map stored in
* obj_hash. Return NULL if it was not found.
*/
struct object *lookup_object(struct repository *r, const unsigned char *sha1)
struct object *lookup_object(struct repository *r, const struct object_id *oid)
{
unsigned int i, first;
struct object *obj;
@ -93,9 +93,9 @@ struct object *lookup_object(struct repository *r, const unsigned char *sha1)
if (!r->parsed_objects->obj_hash)
return NULL;
first = i = hash_obj(sha1, r->parsed_objects->obj_hash_size);
first = i = hash_obj(oid, r->parsed_objects->obj_hash_size);
while ((obj = r->parsed_objects->obj_hash[i]) != NULL) {
if (hasheq(sha1, obj->oid.hash))
if (oideq(oid, &obj->oid))
break;
i++;
if (i == r->parsed_objects->obj_hash_size)
@ -141,13 +141,13 @@ static void grow_object_hash(struct repository *r)
r->parsed_objects->obj_hash_size = new_hash_size;
}
void *create_object(struct repository *r, const unsigned char *sha1, void *o)
void *create_object(struct repository *r, const struct object_id *oid, void *o)
{
struct object *obj = o;
obj->parsed = 0;
obj->flags = 0;
hashcpy(obj->oid.hash, sha1);
oidcpy(&obj->oid, oid);
if (r->parsed_objects->obj_hash_size - 1 <= r->parsed_objects->nr_objs * 2)
grow_object_hash(r);
@ -178,11 +178,11 @@ void *object_as_type(struct repository *r, struct object *obj, enum object_type
}
}
struct object *lookup_unknown_object(const unsigned char *sha1)
struct object *lookup_unknown_object(const struct object_id *oid)
{
struct object *obj = lookup_object(the_repository, sha1);
struct object *obj = lookup_object(the_repository, oid);
if (!obj)
obj = create_object(the_repository, sha1,
obj = create_object(the_repository, oid,
alloc_object_node(the_repository));
return obj;
}
@ -256,7 +256,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
void *buffer;
struct object *obj;
obj = lookup_object(r, oid->hash);
obj = lookup_object(r, oid);
if (obj && obj->parsed)
return obj;
@ -268,7 +268,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
return NULL;
}
parse_blob_buffer(lookup_blob(r, oid), NULL, 0);
return lookup_object(r, oid->hash);
return lookup_object(r, oid);
}
buffer = repo_read_object_file(r, oid, &type, &size);

Просмотреть файл

@ -116,9 +116,9 @@ struct object *get_indexed_object(unsigned int);
* half-initialised objects, the caller is expected to initialize them
* by calling parse_object() on them.
*/
struct object *lookup_object(struct repository *r, const unsigned char *sha1);
struct object *lookup_object(struct repository *r, const struct object_id *oid);
void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
void *create_object(struct repository *r, const struct object_id *oid, void *obj);
void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet);
@ -143,7 +143,7 @@ struct object *parse_object_or_die(const struct object_id *oid, const char *name
struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
/** Returns the object, with potentially excess memory allocated. **/
struct object *lookup_unknown_object(const unsigned char *sha1);
struct object *lookup_unknown_object(const struct object_id *oid);
struct object_list *object_list_insert(struct object *item,
struct object_list **list_p);

Просмотреть файл

@ -5,33 +5,33 @@ void oidset_init(struct oidset *set, size_t initial_size)
{
memset(&set->set, 0, sizeof(set->set));
if (initial_size)
kh_resize_oid(&set->set, initial_size);
kh_resize_oid_set(&set->set, initial_size);
}
int oidset_contains(const struct oidset *set, const struct object_id *oid)
{
khiter_t pos = kh_get_oid(&set->set, *oid);
khiter_t pos = kh_get_oid_set(&set->set, *oid);
return pos != kh_end(&set->set);
}
int oidset_insert(struct oidset *set, const struct object_id *oid)
{
int added;
kh_put_oid(&set->set, *oid, &added);
kh_put_oid_set(&set->set, *oid, &added);
return !added;
}
int oidset_remove(struct oidset *set, const struct object_id *oid)
{
khiter_t pos = kh_get_oid(&set->set, *oid);
khiter_t pos = kh_get_oid_set(&set->set, *oid);
if (pos == kh_end(&set->set))
return 0;
kh_del_oid(&set->set, pos);
kh_del_oid_set(&set->set, pos);
return 1;
}
void oidset_clear(struct oidset *set)
{
kh_release_oid(&set->set);
kh_release_oid_set(&set->set);
oidset_init(set, 0);
}

Просмотреть файл

@ -20,7 +20,7 @@
* A single oidset; should be zero-initialized (or use OIDSET_INIT).
*/
struct oidset {
kh_oid_t set;
kh_oid_set_t set;
};
#define OIDSET_INIT { { 0 } }
@ -62,7 +62,7 @@ int oidset_remove(struct oidset *set, const struct object_id *oid);
void oidset_clear(struct oidset *set);
struct oidset_iter {
kh_oid_t *set;
kh_oid_set_t *set;
khiter_t iter;
};

Просмотреть файл

@ -28,8 +28,8 @@ struct bitmap_writer {
struct ewah_bitmap *blobs;
struct ewah_bitmap *tags;
khash_sha1 *bitmaps;
khash_sha1 *reused;
kh_oid_map_t *bitmaps;
kh_oid_map_t *reused;
struct packing_data *to_pack;
struct bitmapped_commit *selected;
@ -142,13 +142,13 @@ static inline void reset_all_seen(void)
seen_objects_nr = 0;
}
static uint32_t find_object_pos(const unsigned char *hash)
static uint32_t find_object_pos(const struct object_id *oid)
{
struct object_entry *entry = packlist_find(writer.to_pack, hash, NULL);
struct object_entry *entry = packlist_find(writer.to_pack, oid, NULL);
if (!entry) {
die("Failed to write bitmap index. Packfile doesn't have full closure "
"(object %s is missing)", hash_to_hex(hash));
"(object %s is missing)", oid_to_hex(oid));
}
return oe_in_pack_pos(writer.to_pack, entry);
@ -157,7 +157,7 @@ static uint32_t find_object_pos(const unsigned char *hash)
static void show_object(struct object *object, const char *name, void *data)
{
struct bitmap *base = data;
bitmap_set(base, find_object_pos(object->oid.hash));
bitmap_set(base, find_object_pos(&object->oid));
mark_as_seen(object);
}
@ -170,12 +170,12 @@ static int
add_to_include_set(struct bitmap *base, struct commit *commit)
{
khiter_t hash_pos;
uint32_t bitmap_pos = find_object_pos(commit->object.oid.hash);
uint32_t bitmap_pos = find_object_pos(&commit->object.oid);
if (bitmap_get(base, bitmap_pos))
return 0;
hash_pos = kh_get_sha1(writer.bitmaps, commit->object.oid.hash);
hash_pos = kh_get_oid_map(writer.bitmaps, commit->object.oid);
if (hash_pos < kh_end(writer.bitmaps)) {
struct bitmapped_commit *bc = kh_value(writer.bitmaps, hash_pos);
bitmap_or_ewah(base, bc->bitmap);
@ -256,7 +256,7 @@ void bitmap_writer_build(struct packing_data *to_pack)
struct bitmap *base = bitmap_new();
struct rev_info revs;
writer.bitmaps = kh_init_sha1();
writer.bitmaps = kh_init_oid_map();
writer.to_pack = to_pack;
if (writer.show_progress)
@ -311,7 +311,7 @@ void bitmap_writer_build(struct packing_data *to_pack)
if (i >= reuse_after)
stored->flags |= BITMAP_FLAG_REUSE;
hash_pos = kh_put_sha1(writer.bitmaps, object->oid.hash, &hash_ret);
hash_pos = kh_put_oid_map(writer.bitmaps, object->oid, &hash_ret);
if (hash_ret == 0)
die("Duplicate entry when writing index: %s",
oid_to_hex(&object->oid));
@ -366,7 +366,7 @@ void bitmap_writer_reuse_bitmaps(struct packing_data *to_pack)
if (!(bitmap_git = prepare_bitmap_git(to_pack->repo)))
return;
writer.reused = kh_init_sha1();
writer.reused = kh_init_oid_map();
rebuild_existing_bitmaps(bitmap_git, to_pack, writer.reused,
writer.show_progress);
/*
@ -375,14 +375,14 @@ void bitmap_writer_reuse_bitmaps(struct packing_data *to_pack)
*/
}
static struct ewah_bitmap *find_reused_bitmap(const unsigned char *sha1)
static struct ewah_bitmap *find_reused_bitmap(const struct object_id *oid)
{
khiter_t hash_pos;
if (!writer.reused)
return NULL;
hash_pos = kh_get_sha1(writer.reused, sha1);
hash_pos = kh_get_oid_map(writer.reused, *oid);
if (hash_pos >= kh_end(writer.reused))
return NULL;
@ -422,14 +422,14 @@ void bitmap_writer_select_commits(struct commit **indexed_commits,
if (next == 0) {
chosen = indexed_commits[i];
reused_bitmap = find_reused_bitmap(chosen->object.oid.hash);
reused_bitmap = find_reused_bitmap(&chosen->object.oid);
} else {
chosen = indexed_commits[i + next];
for (j = 0; j <= next; ++j) {
struct commit *cm = indexed_commits[i + j];
reused_bitmap = find_reused_bitmap(cm->object.oid.hash);
reused_bitmap = find_reused_bitmap(&cm->object.oid);
if (reused_bitmap || (cm->object.flags & NEEDS_BITMAP) != 0) {
chosen = cm;
break;

Просмотреть файл

@ -365,7 +365,7 @@ struct include_data {
static inline int bitmap_position_extended(struct bitmap_index *bitmap_git,
const struct object_id *oid)
{
khash_oid_pos *positions = bitmap_git->ext_index.positions;
kh_oid_pos_t *positions = bitmap_git->ext_index.positions;
khiter_t pos = kh_get_oid_pos(positions, *oid);
if (pos < kh_end(positions)) {
@ -1041,7 +1041,7 @@ static int rebuild_bitmap(uint32_t *reposition,
int rebuild_existing_bitmaps(struct bitmap_index *bitmap_git,
struct packing_data *mapping,
khash_sha1 *reused_bitmaps,
kh_oid_map_t *reused_bitmaps,
int show_progress)
{
uint32_t i, num_objects;
@ -1057,13 +1057,13 @@ int rebuild_existing_bitmaps(struct bitmap_index *bitmap_git,
reposition = xcalloc(num_objects, sizeof(uint32_t));
for (i = 0; i < num_objects; ++i) {
const unsigned char *sha1;
struct object_id oid;
struct revindex_entry *entry;
struct object_entry *oe;
entry = &bitmap_git->pack->revindex[i];
sha1 = nth_packed_object_sha1(bitmap_git->pack, entry->nr);
oe = packlist_find(mapping, sha1, NULL);
nth_packed_object_oid(&oid, bitmap_git->pack, entry->nr);
oe = packlist_find(mapping, &oid, NULL);
if (oe)
reposition[i] = oe_in_pack_pos(mapping, oe) + 1;
@ -1080,8 +1080,8 @@ int rebuild_existing_bitmaps(struct bitmap_index *bitmap_git,
if (!rebuild_bitmap(reposition,
lookup_stored_bitmap(stored),
rebuild)) {
hash_pos = kh_put_sha1(reused_bitmaps,
stored->oid.hash,
hash_pos = kh_put_oid_map(reused_bitmaps,
stored->oid,
&hash_ret);
kh_value(reused_bitmaps, hash_pos) =
bitmap_to_ewah(rebuild);

Просмотреть файл

@ -51,7 +51,7 @@ int reuse_partial_packfile_from_bitmap(struct bitmap_index *,
struct packed_git **packfile,
uint32_t *entries, off_t *up_to);
int rebuild_existing_bitmaps(struct bitmap_index *, struct packing_data *mapping,
khash_sha1 *reused_bitmaps, int show_progress);
kh_oid_map_t *reused_bitmaps, int show_progress);
void free_bitmap_index(struct bitmap_index *);
/*

Просмотреть файл

@ -6,17 +6,17 @@
#include "config.h"
static uint32_t locate_object_entry_hash(struct packing_data *pdata,
const unsigned char *sha1,
const struct object_id *oid,
int *found)
{
uint32_t i, mask = (pdata->index_size - 1);
i = sha1hash(sha1) & mask;
i = oidhash(oid) & mask;
while (pdata->index[i] > 0) {
uint32_t pos = pdata->index[i] - 1;
if (hasheq(sha1, pdata->objects[pos].idx.oid.hash)) {
if (oideq(oid, &pdata->objects[pos].idx.oid)) {
*found = 1;
return i;
}
@ -56,7 +56,7 @@ static void rehash_objects(struct packing_data *pdata)
for (i = 0; i < pdata->nr_objects; i++) {
int found;
uint32_t ix = locate_object_entry_hash(pdata,
entry->idx.oid.hash,
&entry->idx.oid,
&found);
if (found)
@ -68,7 +68,7 @@ static void rehash_objects(struct packing_data *pdata)
}
struct object_entry *packlist_find(struct packing_data *pdata,
const unsigned char *sha1,
const struct object_id *oid,
uint32_t *index_pos)
{
uint32_t i;
@ -77,7 +77,7 @@ struct object_entry *packlist_find(struct packing_data *pdata,
if (!pdata->index_size)
return NULL;
i = locate_object_entry_hash(pdata, sha1, &found);
i = locate_object_entry_hash(pdata, oid, &found);
if (index_pos)
*index_pos = i;

Просмотреть файл

@ -187,7 +187,7 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,
uint32_t index_pos);
struct object_entry *packlist_find(struct packing_data *pdata,
const unsigned char *sha1,
const struct object_id *oid,
uint32_t *index_pos);
static inline uint32_t pack_name_hash(const char *name)

Просмотреть файл

@ -83,7 +83,7 @@ static int init_patch_id_entry(struct patch_id *patch,
if (commit_patch_id(commit, &ids->diffopts, &header_only_patch_id, 1, 0))
return -1;
hashmap_entry_init(patch, sha1hash(header_only_patch_id.hash));
hashmap_entry_init(patch, oidhash(&header_only_patch_id));
return 0;
}

Просмотреть файл

@ -109,7 +109,7 @@ static int add_recent_loose(const struct object_id *oid,
const char *path, void *data)
{
struct stat st;
struct object *obj = lookup_object(the_repository, oid->hash);
struct object *obj = lookup_object(the_repository, oid);
if (obj && obj->flags & SEEN)
return 0;
@ -134,7 +134,7 @@ static int add_recent_packed(const struct object_id *oid,
struct packed_git *p, uint32_t pos,
void *data)
{
struct object *obj = lookup_object(the_repository, oid->hash);
struct object *obj = lookup_object(the_repository, oid);
if (obj && obj->flags & SEEN)
return 0;

2
refs.c
Просмотреть файл

@ -379,7 +379,7 @@ static int filter_refs(const char *refname, const struct object_id *oid,
enum peel_status peel_object(const struct object_id *name, struct object_id *oid)
{
struct object *o = lookup_unknown_object(name->hash);
struct object *o = lookup_unknown_object(name);
if (o->type == OBJ_NONE) {
int type = oid_object_info(the_repository, name, NULL);

Просмотреть файл

@ -26,8 +26,8 @@ int cmd__example_decorate(int argc, const char **argv)
* Add 2 objects, one with a non-NULL decoration and one with a NULL
* decoration.
*/
one = lookup_unknown_object(one_oid.hash);
two = lookup_unknown_object(two_oid.hash);
one = lookup_unknown_object(&one_oid);
two = lookup_unknown_object(&two_oid);
ret = add_decoration(&n, one, &decoration_a);
if (ret)
BUG("when adding a brand-new object, NULL should be returned");
@ -56,7 +56,7 @@ int cmd__example_decorate(int argc, const char **argv)
ret = lookup_decoration(&n, two);
if (ret != &decoration_b)
BUG("lookup should return added declaration");
three = lookup_unknown_object(three_oid.hash);
three = lookup_unknown_object(&three_oid);
ret = lookup_decoration(&n, three);
if (ret)
BUG("lookup for unknown object should return NULL");

5
tag.c
Просмотреть файл

@ -100,10 +100,9 @@ struct object *deref_tag_noverify(struct object *o)
struct tag *lookup_tag(struct repository *r, const struct object_id *oid)
{
struct object *obj = lookup_object(r, oid->hash);
struct object *obj = lookup_object(r, oid);
if (!obj)
return create_object(r, oid->hash,
alloc_tag_node(r));
return create_object(r, oid, alloc_tag_node(r));
return object_as_type(r, obj, OBJ_TAG, 0);
}

5
tree.c
Просмотреть файл

@ -197,10 +197,9 @@ int read_tree(struct repository *r, struct tree *tree, int stage,
struct tree *lookup_tree(struct repository *r, const struct object_id *oid)
{
struct object *obj = lookup_object(r, oid->hash);
struct object *obj = lookup_object(r, oid);
if (!obj)
return create_object(r, oid->hash,
alloc_tree_node(r));
return create_object(r, oid, alloc_tree_node(r));
return object_as_type(r, obj, OBJ_TREE, 0);
}

Просмотреть файл

@ -528,13 +528,13 @@ static int get_reachable_list(struct object_array *src,
return -1;
while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) {
struct object_id sha1;
struct object_id oid;
const char *p;
if (parse_oid_hex(namebuf, &sha1, &p) || *p != '\n')
if (parse_oid_hex(namebuf, &oid, &p) || *p != '\n')
break;
o = lookup_object(the_repository, sha1.hash);
o = lookup_object(the_repository, &oid);
if (o && o->type == OBJ_COMMIT) {
o->flags &= ~TMP_MARK;
}
@ -960,7 +960,7 @@ static void receive_needs(struct packet_reader *reader, struct object_array *wan
static int mark_our_ref(const char *refname, const char *refname_full,
const struct object_id *oid)
{
struct object *o = lookup_unknown_object(oid->hash);
struct object *o = lookup_unknown_object(oid);
if (ref_is_hidden(refname, refname_full)) {
o->flags |= HIDDEN_REF;

Просмотреть файл

@ -285,7 +285,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,
error("Could not interpret response from server '%s' as something to pull", target[i]);
goto done;
}
if (process(walker, lookup_unknown_object(oids[i].hash)))
if (process(walker, lookup_unknown_object(&oids[i])))
goto done;
}