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