Refs belong to particular repositories, so the replacements defined by them should belong to a particular repository as well. Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx> Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx> --- object-store.h | 9 ++++++++- replace-object.c | 42 ++++++++++++++++++------------------------ replace-object.h | 20 ++++++++++++++++++++ 3 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 replace-object.h diff --git a/object-store.h b/object-store.h index 57b8d89738..298e34e978 100644 --- a/object-store.h +++ b/object-store.h @@ -3,6 +3,7 @@ #include "cache.h" #include "mru.h" +#include "replace-object.h" struct object_store { struct packed_git *packed_git; @@ -16,6 +17,12 @@ struct object_store { struct alternate_object_database *alt_odb_list; struct alternate_object_database **alt_odb_tail; + /* + * Objects that should be substituted by other objects + * (see git-replace(1)). + */ + struct replace_objects replacements; + /* * A fast, rough count of the number of objects in the repository. * These two fields are not meant for direct access. Use @@ -30,7 +37,7 @@ struct object_store { */ unsigned packed_git_initialized : 1; }; -#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL, 0, 0, 0 } +#define OBJECT_STORE_INIT { NULL, MRU_INIT, NULL, NULL, REPLACE_OBJECTS_INIT, 0, 0, 0 } struct packed_git { struct packed_git *next; diff --git a/replace-object.c b/replace-object.c index f0b39f06d5..d26e180639 100644 --- a/replace-object.c +++ b/replace-object.c @@ -1,19 +1,10 @@ #include "cache.h" +#include "replace-object.h" #include "sha1-lookup.h" #include "refs.h" +#include "repository.h" #include "commit.h" -/* - * An array of replacements. The array is kept sorted by the original - * sha1. - */ -static struct replace_object { - unsigned char original[20]; - unsigned char replacement[20]; -} **replace_object; - -static int replace_object_alloc, replace_object_nr; - static const unsigned char *replace_sha1_access(size_t index, void *table) { struct replace_object **replace = table; @@ -22,7 +13,8 @@ static const unsigned char *replace_sha1_access(size_t index, void *table) static int replace_object_pos(const unsigned char *sha1) { - return sha1_pos(sha1, replace_object, replace_object_nr, + return sha1_pos(sha1, the_repository->objects.replacements.items, + the_repository->objects.replacements.nr, replace_sha1_access); } @@ -35,20 +27,22 @@ static int register_replace_object(struct replace_object *replace, if (ignore_dups) free(replace); else { - free(replace_object[pos]); - replace_object[pos] = replace; + free(the_repository->objects.replacements.items[pos]); + the_repository->objects.replacements.items[pos] = replace; } return 1; } pos = -pos - 1; - ALLOC_GROW(replace_object, replace_object_nr + 1, replace_object_alloc); - replace_object_nr++; - if (pos < replace_object_nr) - memmove(replace_object + pos + 1, - replace_object + pos, - (replace_object_nr - pos - 1) * - sizeof(*replace_object)); - replace_object[pos] = replace; + ALLOC_GROW(the_repository->objects.replacements.items, + the_repository->objects.replacements.nr + 1, + the_repository->objects.replacements.alloc); + the_repository->objects.replacements.nr++; + if (pos < the_repository->objects.replacements.nr) + memmove(the_repository->objects.replacements.items + pos + 1, + the_repository->objects.replacements.items + pos, + (the_repository->objects.replacements.nr - pos - 1) * + sizeof(*the_repository->objects.replacements.items)); + the_repository->objects.replacements.items[pos] = replace; return 0; } @@ -86,7 +80,7 @@ static void prepare_replace_object(void) for_each_replace_ref(register_replace_ref, NULL); replace_object_prepared = 1; - if (!replace_object_nr) + if (!the_repository->objects.replacements.nr) check_replace_refs = 0; } @@ -115,7 +109,7 @@ const unsigned char *do_lookup_replace_object(const unsigned char *sha1) pos = replace_object_pos(cur); if (0 <= pos) - cur = replace_object[pos]->replacement; + cur = the_repository->objects.replacements.items[pos]->replacement; } while (0 <= pos); return cur; diff --git a/replace-object.h b/replace-object.h new file mode 100644 index 0000000000..483335ffcc --- /dev/null +++ b/replace-object.h @@ -0,0 +1,20 @@ +#ifndef REPLACE_OBJECT_H +#define REPLACE_OBJECT_H + +struct replace_objects { + /* + * An array of replacements. The array is kept sorted by the original + * sha1. + */ + struct replace_object **items; + + int alloc, nr; +}; +#define REPLACE_OBJECTS_INIT { NULL, 0, 0 } + +struct replace_object { + unsigned char original[20]; + unsigned char replacement[20]; +}; + +#endif /* REPLACE_OBJECT_H */ -- 2.15.1.433.g936d1b9894.dirty