make tog store refs and object id map in global variables instead of per view ok naddy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
diff --git a/tog/tog.c b/tog/tog.c
index a28a005..44a8a5c 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -125,6 +125,32 @@ struct tog_color {
};
SIMPLEQ_HEAD(tog_colors, tog_color);
+static struct got_reflist_head tog_refs = SIMPLEQ_HEAD_INITIALIZER(tog_refs);
+static struct got_reflist_object_id_map *tog_refs_idmap;
+
+static const struct got_error *
+tog_load_refs(struct got_repository *repo)
+{
+ const struct got_error *err;
+
+ err = got_ref_list(&tog_refs, repo, NULL, got_ref_cmp_by_name, NULL);
+ if (err)
+ return err;
+
+ return got_reflist_object_id_map_create(&tog_refs_idmap, &tog_refs,
+ repo);
+}
+
+static void
+tog_free_refs(void)
+{
+ if (tog_refs_idmap) {
+ got_reflist_object_map_free(tog_refs_idmap);
+ tog_refs_idmap = NULL;
+ }
+ got_ref_list_free(&tog_refs);
+}
+
static const struct got_error *
add_color(struct tog_colors *colors, const char *pattern,
int idx, short color)
@@ -262,8 +288,6 @@ struct tog_diff_view_state {
int ignore_whitespace;
int force_text_diff;
struct got_repository *repo;
- struct got_reflist_head refs;
- struct got_reflist_object_id_map *idmap;
struct tog_colors colors;
size_t nlines;
off_t *line_offsets;
@@ -304,8 +328,6 @@ struct tog_log_view_state {
char *head_ref_name;
int log_branches;
struct got_repository *repo;
- struct got_reflist_head refs;
- struct got_reflist_object_id_map *idmap;
struct got_object_id *start_id;
sig_atomic_t quit;
pthread_t thread;
@@ -1578,7 +1600,7 @@ draw_commits(struct tog_view *view)
err = got_object_id_str(&id_str, s->selected_entry->id);
if (err)
return err;
- refs = got_reflist_object_id_map_lookup(s->idmap,
+ refs = got_reflist_object_id_map_lookup(tog_refs_idmap,
s->selected_entry->id);
if (refs) {
err = build_refs_str(&refs_str, refs,
@@ -2125,11 +2147,6 @@ close_log_view(struct tog_view *view)
s->start_id = NULL;
free(s->head_ref_name);
s->head_ref_name = NULL;
- if (s->idmap) {
- got_reflist_object_map_free(s->idmap);
- s->idmap = NULL;
- }
- got_ref_list_free(&s->refs);
return err;
}
@@ -2258,8 +2275,6 @@ open_log_view(struct tog_view *view, struct got_object_id *start_id,
struct got_commit_graph *thread_graph = NULL;
int errcode;
- SIMPLEQ_INIT(&s->refs);
-
if (in_repo_path != s->in_repo_path) {
free(s->in_repo_path);
s->in_repo_path = strdup(in_repo_path);
@@ -2271,13 +2286,6 @@ open_log_view(struct tog_view *view, struct got_object_id *start_id,
TAILQ_INIT(&s->commits.head);
s->commits.ncommits = 0;
- err = got_ref_list(&s->refs, repo, NULL, got_ref_cmp_by_name, NULL);
- if (err)
- goto done;
- err = got_reflist_object_id_map_create(&s->idmap, &s->refs, repo);
- if (err)
- goto done;
-
s->repo = repo;
if (head_ref_name) {
s->head_ref_name = strdup(head_ref_name);
@@ -2543,17 +2551,8 @@ input_log_view(struct tog_view **new_view, struct tog_view *view, int ch)
got_repo_get_path(s->repo), NULL);
if (err)
return err;
- if (s->idmap) {
- got_reflist_object_map_free(s->idmap);
- s->idmap = NULL;
- }
- got_ref_list_free(&s->refs);
- err = got_ref_list(&s->refs, s->repo, NULL,
- got_ref_cmp_by_name, NULL);
- if (err)
- return err;
- err = got_reflist_object_id_map_create(&s->idmap, &s->refs,
- s->repo);
+ tog_free_refs();
+ err = tog_load_refs(s->repo);
if (err)
return err;
err = got_commit_graph_open(&s->thread_args.graph,
@@ -2758,6 +2757,10 @@ cmd_log(int argc, char *argv[])
if (error)
goto done;
+ error = tog_load_refs(repo);
+ if (error)
+ goto done;
+
if (start_commit == NULL) {
error = got_repo_match_object_id(&start_id, &label,
worktree ? got_worktree_get_head_ref_name(worktree) :
@@ -2804,6 +2807,7 @@ done:
got_repo_close(repo);
if (worktree)
got_worktree_close(worktree);
+ tog_free_refs();
return error;
}
@@ -3281,7 +3285,7 @@ create_diff(struct tog_diff_view_state *s)
err = got_object_open_as_commit(&commit2, s->repo, s->id2);
if (err)
goto done;
- refs = got_reflist_object_id_map_lookup(s->idmap, s->id2);
+ refs = got_reflist_object_id_map_lookup(tog_refs_idmap, s->id2);
/* Show commit info if we're diffing to a parent/root commit. */
if (s->id1 == NULL) {
err = write_commit_info(&s->line_offsets, &s->nlines,
@@ -3414,8 +3418,6 @@ open_diff_view(struct tog_view *view, struct got_object_id *id1,
const struct got_error *err;
struct tog_diff_view_state *s = &view->state.diff;
- SIMPLEQ_INIT(&s->refs);
-
if (id1 != NULL && id2 != NULL) {
int type1, type2;
err = got_object_get_type(&type1, repo, id1);
@@ -3507,26 +3509,6 @@ open_diff_view(struct tog_view *view, struct got_object_id *id1,
}
}
- err = got_ref_list(&s->refs, repo, NULL, got_ref_cmp_by_name, NULL);
- if (err) {
- free(s->id1);
- s->id1 = NULL;
- free(s->id2);
- s->id2 = NULL;
- free_colors(&s->colors);
- return err;
- }
- err = got_reflist_object_id_map_create(&s->idmap, &s->refs, repo);
- if (err) {
- free(s->id1);
- s->id1 = NULL;
- free(s->id2);
- s->id2 = NULL;
- free_colors(&s->colors);
- got_ref_list_free(&s->refs);
- return err;
- }
-
if (log_view && view_is_splitscreen(view))
show_log_view(log_view); /* draw vborder */
diff_view_indicate_progress(view);
@@ -3540,9 +3522,6 @@ open_diff_view(struct tog_view *view, struct got_object_id *id1,
free(s->id2);
s->id2 = NULL;
free_colors(&s->colors);
- got_ref_list_free(&s->refs);
- got_reflist_object_map_free(s->idmap);
- s->idmap = NULL;
return err;
}
@@ -3571,11 +3550,6 @@ close_diff_view(struct tog_view *view)
free(s->line_offsets);
s->line_offsets = NULL;
s->nlines = 0;
- if (s->idmap) {
- got_reflist_object_map_free(s->idmap);
- s->idmap = NULL;
- }
- got_ref_list_free(&s->refs);
return err;
}
@@ -3855,6 +3829,10 @@ cmd_diff(int argc, char *argv[])
if (error)
goto done;
+ error = tog_load_refs(repo);
+ if (error)
+ goto done;
+
error = got_repo_match_object_id(&id1, &label1, id_str1,
GOT_OBJ_TYPE_ANY, 1, repo);
if (error)
@@ -3884,6 +3862,7 @@ done:
got_repo_close(repo);
if (worktree)
got_worktree_close(worktree);
+ tog_free_refs();
return error;
}
@@ -4748,6 +4727,10 @@ cmd_blame(int argc, char *argv[])
if (error)
goto done;
+ error = tog_load_refs(repo);
+ if (error)
+ goto done;
+
if (commit_id_str == NULL) {
struct got_reference *head_ref;
error = got_ref_open(&head_ref, repo, worktree ?
@@ -4794,6 +4777,7 @@ done:
got_worktree_close(worktree);
if (repo)
got_repo_close(repo);
+ tog_free_refs();
return error;
}
@@ -5558,6 +5542,10 @@ cmd_tree(int argc, char *argv[])
if (error)
goto done;
+ error = tog_load_refs(repo);
+ if (error)
+ goto done;
+
if (commit_id_arg == NULL) {
error = got_repo_match_object_id(&commit_id, &label,
worktree ? got_worktree_get_head_ref_name(worktree) :
@@ -5620,6 +5608,7 @@ done:
got_object_tree_close(tree);
if (repo)
got_repo_close(repo);
+ tog_free_refs();
return error;
}
@@ -6272,6 +6261,10 @@ cmd_ref(int argc, char *argv[])
if (error)
goto done;
+ error = tog_load_refs(repo);
+ if (error)
+ goto done;
+
view = view_open(0, 0, 0, 0, TOG_VIEW_REF);
if (view == NULL) {
error = got_error_from_errno("view_open");
@@ -6293,6 +6286,7 @@ done:
free(cwd);
if (repo)
got_repo_close(repo);
+ tog_free_refs();
return error;
}