Skip to content

Commit b1bf38c

Browse files
committed
Merge branch 'ps/rerere-remove-global-state'
The 'rerere' subsystem has been libified to remove its dependency on the global 'the_repository' state and global tracking variables, allowing it to operate correctly in multi-repository contexts. * ps/rerere-remove-global-state: rerere: get rid of global rerere cache state rerere: bundle global state into a struct rerere: stop using `the_repository` rerere: cache result of `is_rerere_enabled()` rerere: remove redundant calls to `repo_config()` rerere: stop using `the_repository` in internal helpers rerere: stop using `the_repository` in `rerere_path()`
2 parents aa139fd + b948c10 commit b1bf38c

7 files changed

Lines changed: 216 additions & 151 deletions

File tree

‎builtin/rerere.c‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,15 @@ int cmd_rerere(int argc,
106106
rerere_gc(the_repository, &merge_rr,
107107
skip_locked ? RERERE_NOWAIT : 0);
108108
else if (!strcmp(argv[0], "status")) {
109-
if (setup_rerere(the_repository, &merge_rr,
110-
flags | RERERE_READONLY) < 0)
109+
struct rerere_cache cache;
110+
111+
if (rerere_cache_setup(&cache, the_repository, &merge_rr,
112+
flags | RERERE_READONLY) < 0)
111113
return 0;
112114
for (size_t i = 0; i < merge_rr.nr; i++)
113115
printf("%s\n", merge_rr.items[i].string);
116+
117+
rerere_cache_release(&cache);
114118
} else if (!strcmp(argv[0], "remaining")) {
115119
rerere_remaining(the_repository, &merge_rr);
116120
for (size_t i = 0; i < merge_rr.nr; i++) {
@@ -123,16 +127,21 @@ int cmd_rerere(int argc,
123127
}
124128
} else if (!strcmp(argv[0], "diff")) {
125129
struct strbuf buf = STRBUF_INIT;
126-
if (setup_rerere(the_repository, &merge_rr,
127-
flags | RERERE_READONLY) < 0)
130+
struct rerere_cache cache;
131+
132+
if (rerere_cache_setup(&cache, the_repository, &merge_rr,
133+
flags | RERERE_READONLY) < 0)
128134
return 0;
129135
for (size_t i = 0; i < merge_rr.nr; i++) {
130136
const char *path = merge_rr.items[i].string;
131137
const struct rerere_id *id = merge_rr.items[i].util;
132-
if (diff_two(rerere_path(&buf, id, "preimage"), path, path, path))
133-
die(_("unable to generate diff for '%s'"), rerere_path(&buf, id, NULL));
138+
if (diff_two(rerere_path(the_repository, &buf, id, "preimage"),
139+
path, path, path))
140+
die(_("unable to generate diff for '%s'"),
141+
rerere_path(the_repository, &buf, id, NULL));
134142
}
135143

144+
rerere_cache_release(&cache);
136145
strbuf_release(&buf);
137146
} else
138147
usage_with_options(rerere_usage, options);

‎hex.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include "hex.h"
66
#include "strbuf.h"
77

8-
static int get_hash_hex_algop(const char *hex, unsigned char *hash,
9-
const struct git_hash_algo *algop)
8+
int get_hash_hex_algop(const char *hex, unsigned char *hash,
9+
const struct git_hash_algo *algop)
1010
{
1111
for (size_t i = 0; i < algop->rawsz; i++) {
1212
int val = hex2chr(hex);

‎hex.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ int parse_oid_hex_algop_impl(const char *hex, struct object_id *oid, const char
5959
int get_oid_hex_any(const char *hex, struct object_id *oid);
6060
int parse_oid_hex_any(const char *hex, struct object_id *oid, const char **end);
6161

62+
int get_hash_hex_algop(const char *hex, unsigned char *hash,
63+
const struct git_hash_algo *algop);
64+
6265
#ifdef USE_THE_REPOSITORY_VARIABLE
6366

6467
/* Like get_oid_hex_algop, but for `the_hash_algo`. */

‎repository.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void initialize_repository(struct repository *repo)
7676
repo->bare_cfg = -1;
7777
repo->fetch_if_missing = 1;
7878
repo_config_values_init(&repo->config_values_private_);
79+
repo->rerere_cache_enabled = -1;
7980

8081
/*
8182
* When a command runs inside a repository, it learns what

‎repository.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ struct repository {
185185
/* True if commit-graph has been disabled within this process. */
186186
int commit_graph_disabled;
187187

188+
/*
189+
* Indicates whether the rerere-cache has been enabled. -1 (the default
190+
* value) causes us to perform auto-detection via ".git/rr-cache".
191+
*/
192+
int rerere_cache_enabled;
193+
188194
/*
189195
* Controls whether the repository should lazily fetch missing
190196
* objects from promisor remotes. Defaults to 1.

0 commit comments

Comments
 (0)