19
static struct repository the_repo;
20
struct repository *the_repository = &the_repo;
21
22
+/*
23
+ * An escape hatch: if we hit a bug in the production code that fails
24
+ * to set an appropriate hash algorithm (most likely to happen when
25
+ * running outside a repository), we can tell the user who reported
26
+ * the crash to set the environment variable to "sha1" (all lowercase)
27
+ * to revert to the historical behaviour of defaulting to SHA-1.
28
+ */
29
+static void set_default_hash_algo(struct repository *repo)
30
+{
31
+ const char *hash_name;
32
+ int algo;
33
+
34
+ hash_name = getenv("GIT_TEST_DEFAULT_HASH_ALGO");
35
+ if (!hash_name)
36
+ return;
37
+ algo = hash_algo_by_name(hash_name);
38
+ if (algo == GIT_HASH_UNKNOWN)
39
+ return;
40
+
41
+ repo_set_hash_algo(repo, algo);
42
+}
43
+
44
void initialize_repository(struct repository *repo)
45
{
46
repo->objects = raw_object_store_new();
48
repo->parsed_objects = parsed_object_pool_new();
49
ALLOC_ARRAY(repo->index, 1);
50
index_state_init(repo->index, repo);
51
+
52
+ /*
53
+ * When a command runs inside a repository, it learns what
54
+ * hash algorithm is in use from the repository, but some
55
+ * commands are designed to work outside a repository, yet
56
+ * they want to access the_hash_algo, if only for the length
57
+ * of the hashed value to see if their input looks like a
58
+ * plausible hash value.
59
+ *
60
+ * We are in the process of identifying such code paths and
61
+ * giving them an appropriate default individually; any
62
+ * unconverted code paths that try to access the_hash_algo
63
+ * will thus fail. The end-users however have an escape hatch
64
+ * to set GIT_TEST_DEFAULT_HASH_ALGO environment variable to
65
+ * "sha1" to get back the old behaviour of defaulting to SHA-1.
66
+ *
67
+ * This escape hatch is deliberately kept unadvertised, so
68
+ * that they see crashes and we can get a report before
69
+ * telling them about it.
70
+ */
71
+ if (repo == the_repository)
72
+ set_default_hash_algo(repo);
73
}
74
75
static void expand_base_dir(char **out, const char *in,