blob: ba478eb30c47a639c679ba0cfd3d42a3932b0a1c [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/*
Derrick Stoleef1178382023-06-06 13:24:36 +000023 * Some commands disable replace-refs unconditionally, and otherwise each
24 * repository could alter the core.useReplaceRefs config value.
25 *
26 * Return 1 if and only if all of the following are true:
27 *
28 * a. disable_replace_refs() has not been called.
29 * b. GIT_NO_REPLACE_OBJECTS is unset or zero.
30 * c. the given repository does not have core.useReplaceRefs=false.
31 */
32int replace_refs_enabled(struct repository *r);
33
34/*
Stefan Beller47f351e2018-04-11 17:21:06 -070035 * If object sha1 should be replaced, return the replacement object's
36 * name (replaced recursively, if necessary). The return value is
37 * either sha1 or a pointer to a permanently-allocated value. When
38 * object replacement is suppressed, always return sha1.
Matheus Tavaresb1fc9da2020-01-15 23:39:52 -030039 *
40 * Note: some thread debuggers might point a data race on the
41 * replace_map_initialized reading in this function. However, we know there's no
42 * problem in the value being updated by one thread right after another one read
43 * it here (and it should be written to only once, anyway).
Stefan Beller47f351e2018-04-11 17:21:06 -070044 */
Stefan Beller90e777f2018-04-11 17:21:18 -070045static inline const struct object_id *lookup_replace_object(struct repository *r,
46 const struct object_id *oid)
Stefan Beller47f351e2018-04-11 17:21:06 -070047{
Derrick Stoleef1178382023-06-06 13:24:36 +000048 if (!replace_refs_enabled(r) ||
Matheus Tavaresb1fc9da2020-01-15 23:39:52 -030049 (r->objects->replace_map_initialized &&
Stefan Beller90e777f2018-04-11 17:21:18 -070050 r->objects->replace_map->map.tablesize == 0))
Stefan Beller47f351e2018-04-11 17:21:06 -070051 return oid;
Stefan Beller90e777f2018-04-11 17:21:18 -070052 return do_lookup_replace_object(r, oid);
Stefan Beller47f351e2018-04-11 17:21:06 -070053}
54
Derrick Stoleed24eda42023-06-06 13:24:35 +000055/*
56 * Some commands override config and environment settings for using
57 * replace references. Use this method to disable the setting and ensure
58 * those other settings will not override this choice. This applies
59 * globally to all in-process repositories.
60 */
61void disable_replace_refs(void);
62
Stefan Bellerd88f9fd2018-04-11 17:21:05 -070063#endif /* REPLACE_OBJECT_H */