blob: 3fbc32eb7b7ef7bf9119f83aa7e3a4b6c20104b3 [file] [log] [blame]
Stefan Bellerd88f9fd2018-04-11 17:21:05 -07001#ifndef REPLACE_OBJECT_H
2#define REPLACE_OBJECT_H
3
Stefan Beller47f351e2018-04-11 17:21:06 -07004#include "oidmap.h"
5#include "repository.h"
Stefan Bellerc3c36d72018-04-11 17:21:08 -07006#include "object-store.h"
Stefan Beller47f351e2018-04-11 17:21:06 -07007
Stefan Bellerd88f9fd2018-04-11 17:21:05 -07008struct replace_object {
9 struct oidmap_entry original;
10 struct object_id replacement;
11};
12
Derrick Stoleed6538242018-08-20 18:24:27 +000013void prepare_replace_object(struct repository *r);
14
Stefan Beller47f351e2018-04-11 17:21:06 -070015/*
16 * This internal function is only declared here for the benefit of
17 * lookup_replace_object(). Please do not call it directly.
18 */
Denton Liu55454422019-04-29 04:28:14 -040019const struct object_id *do_lookup_replace_object(struct repository *r,
Denton Liuad6dad02019-04-29 04:28:23 -040020 const struct object_id *oid);
Stefan Beller47f351e2018-04-11 17:21:06 -070021
22/*
23 * If object sha1 should be replaced, return the replacement object's
24 * name (replaced recursively, if necessary). The return value is
25 * either sha1 or a pointer to a permanently-allocated value. When
26 * object replacement is suppressed, always return sha1.
Matheus Tavaresb1fc9da2020-01-15 23:39:52 -030027 *
28 * Note: some thread debuggers might point a data race on the
29 * replace_map_initialized reading in this function. However, we know there's no
30 * problem in the value being updated by one thread right after another one read
31 * it here (and it should be written to only once, anyway).
Stefan Beller47f351e2018-04-11 17:21:06 -070032 */
Stefan Beller90e777f2018-04-11 17:21:18 -070033static inline const struct object_id *lookup_replace_object(struct repository *r,
34 const struct object_id *oid)
Stefan Beller47f351e2018-04-11 17:21:06 -070035{
Jeff King6ebd1ca2018-07-18 16:45:20 -040036 if (!read_replace_refs ||
Matheus Tavaresb1fc9da2020-01-15 23:39:52 -030037 (r->objects->replace_map_initialized &&
Stefan Beller90e777f2018-04-11 17:21:18 -070038 r->objects->replace_map->map.tablesize == 0))
Stefan Beller47f351e2018-04-11 17:21:06 -070039 return oid;
Stefan Beller90e777f2018-04-11 17:21:18 -070040 return do_lookup_replace_object(r, oid);
Stefan Beller47f351e2018-04-11 17:21:06 -070041}
42
Stefan Bellerd88f9fd2018-04-11 17:21:05 -070043#endif /* REPLACE_OBJECT_H */