switch tog ref view to the global reference list as well 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
diff --git a/tog/tog.c b/tog/tog.c
index 44a8a5c..ee2324c 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -434,7 +434,6 @@ struct tog_reflist_entry {
TAILQ_HEAD(tog_reflist_head, tog_reflist_entry);
struct tog_ref_view_state {
- struct got_reflist_head simplerefs; /* SIMPLEQ */
struct tog_reflist_head refs; /* TAILQ */
struct tog_reflist_entry *first_displayed_entry;
struct tog_reflist_entry *last_displayed_entry;
@@ -5615,17 +5614,11 @@ done:
static const struct got_error *
ref_view_load_refs(struct tog_ref_view_state *s)
{
- const struct got_error *err;
struct got_reflist_entry *sre;
struct tog_reflist_entry *re;
- err = got_ref_list(&s->simplerefs, s->repo, NULL,
- got_ref_cmp_by_name, NULL);
- if (err)
- return err;
-
s->nrefs = 0;
- SIMPLEQ_FOREACH(sre, &s->simplerefs, entry) {
+ SIMPLEQ_FOREACH(sre, &tog_refs, entry) {
if (strncmp(got_ref_get_name(sre->ref), "refs/got/", 9) == 0)
continue;
@@ -5633,11 +5626,14 @@ ref_view_load_refs(struct tog_ref_view_state *s)
if (re == NULL)
return got_error_from_errno("malloc");
- re->ref = sre->ref;
+ re->ref = got_ref_dup(sre->ref);
+ if (re->ref == NULL)
+ return got_error_from_errno("got_ref_dup");
re->idx = s->nrefs++;
TAILQ_INSERT_TAIL(&s->refs, re, entry);
}
+ s->first_displayed_entry = TAILQ_FIRST(&s->refs);
return NULL;
}
@@ -5649,9 +5645,9 @@ ref_view_free_refs(struct tog_ref_view_state *s)
while (!TAILQ_EMPTY(&s->refs)) {
re = TAILQ_FIRST(&s->refs);
TAILQ_REMOVE(&s->refs, re, entry);
+ got_ref_close(re->ref);
free(re);
}
- got_ref_list_free(&s->simplerefs);
}
static const struct got_error *
@@ -5663,7 +5659,6 @@ open_ref_view(struct tog_view *view, struct got_repository *repo)
s->selected_entry = 0;
s->repo = repo;
- SIMPLEQ_INIT(&s->simplerefs);
TAILQ_INIT(&s->refs);
SIMPLEQ_INIT(&s->colors);
@@ -5671,8 +5666,6 @@ open_ref_view(struct tog_view *view, struct got_repository *repo)
if (err)
return err;
- s->first_displayed_entry = TAILQ_FIRST(&s->refs);
-
if (has_colors() && getenv("TOG_COLORS") != NULL) {
err = add_color(&s->colors, "^refs/heads/",
TOG_COLOR_REFS_HEADS,
@@ -6180,6 +6173,10 @@ input_ref_view(struct tog_view **new_view, struct tog_view *view, int ch)
ref_scroll_down(s, view->nlines - 1);
break;
case CTRL('l'):
+ tog_free_refs();
+ err = tog_load_refs(s->repo);
+ if (err)
+ break;
ref_view_free_refs(s);
err = ref_view_load_refs(s);
break;