prepare local variable in open_diff_view and close_diff_view for diff view searching ok stsp
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
diff --git a/tog/tog.c b/tog/tog.c
index 57bbc95..e22ea5a 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -2939,6 +2939,7 @@ open_diff_view(struct tog_view *view, struct got_object_id *id1,
struct got_reflist_head *refs, struct got_repository *repo)
{
const struct got_error *err;
+ struct tog_diff_view_state *s = &view->state.diff;
if (id1 != NULL && id2 != NULL) {
int type1, type2;
@@ -2954,69 +2955,69 @@ open_diff_view(struct tog_view *view, struct got_object_id *id1,
}
if (id1) {
- view->state.diff.id1 = got_object_id_dup(id1);
- if (view->state.diff.id1 == NULL)
+ s->id1 = got_object_id_dup(id1);
+ if (s->id1 == NULL)
return got_error_from_errno("got_object_id_dup");
} else
- view->state.diff.id1 = NULL;
+ s->id1 = NULL;
- view->state.diff.id2 = got_object_id_dup(id2);
- if (view->state.diff.id2 == NULL) {
- free(view->state.diff.id1);
- view->state.diff.id1 = NULL;
+ s->id2 = got_object_id_dup(id2);
+ if (s->id2 == NULL) {
+ free(s->id1);
+ s->id1 = NULL;
return got_error_from_errno("got_object_id_dup");
}
- view->state.diff.f = NULL;
- view->state.diff.first_displayed_line = 1;
- view->state.diff.last_displayed_line = view->nlines;
- view->state.diff.diff_context = 3;
- view->state.diff.log_view = log_view;
- view->state.diff.repo = repo;
- view->state.diff.refs = refs;
- SIMPLEQ_INIT(&view->state.diff.colors);
+ s->f = NULL;
+ s->first_displayed_line = 1;
+ s->last_displayed_line = view->nlines;
+ s->diff_context = 3;
+ s->log_view = log_view;
+ s->repo = repo;
+ s->refs = refs;
+ SIMPLEQ_INIT(&s->colors);
if (has_colors() && getenv("TOG_COLORS") != NULL) {
- err = add_color(&view->state.diff.colors,
+ err = add_color(&s->colors,
"^-", TOG_COLOR_DIFF_MINUS,
get_color_value("TOG_COLOR_DIFF_MINUS"));
if (err)
return err;
- err = add_color(&view->state.diff.colors, "^\\+",
+ err = add_color(&s->colors, "^\\+",
TOG_COLOR_DIFF_PLUS,
get_color_value("TOG_COLOR_DIFF_PLUS"));
if (err) {
- free_colors(&view->state.diff.colors);
+ free_colors(&s->colors);
return err;
}
- err = add_color(&view->state.diff.colors,
+ err = add_color(&s->colors,
"^@@", TOG_COLOR_DIFF_CHUNK_HEADER,
get_color_value("TOG_COLOR_DIFF_CHUNK_HEADER"));
if (err) {
- free_colors(&view->state.diff.colors);
+ free_colors(&s->colors);
return err;
}
- err = add_color(&view->state.diff.colors,
+ err = add_color(&s->colors,
"^(commit|(blob|file) [-+] )", TOG_COLOR_DIFF_META,
get_color_value("TOG_COLOR_DIFF_META"));
if (err) {
- free_colors(&view->state.diff.colors);
+ free_colors(&s->colors);
return err;
}
- err = add_color(&view->state.diff.colors,
+ err = add_color(&s->colors,
"^(from|via): ", TOG_COLOR_AUTHOR,
get_color_value("TOG_COLOR_AUTHOR"));
if (err) {
- free_colors(&view->state.diff.colors);
+ free_colors(&s->colors);
return err;
}
- err = add_color(&view->state.diff.colors,
+ err = add_color(&s->colors,
"^date: ", TOG_COLOR_DATE,
get_color_value("TOG_COLOR_DATE"));
if (err) {
- free_colors(&view->state.diff.colors);
+ free_colors(&s->colors);
return err;
}
}
@@ -3025,12 +3026,12 @@ open_diff_view(struct tog_view *view, struct got_object_id *id1,
show_log_view(log_view); /* draw vborder */
diff_view_indicate_progress(view);
- err = create_diff(&view->state.diff);
+ err = create_diff(s);
if (err) {
- free(view->state.diff.id1);
- view->state.diff.id1 = NULL;
- free(view->state.diff.id2);
- view->state.diff.id2 = NULL;
+ free(s->id1);
+ s->id1 = NULL;
+ free(s->id2);
+ s->id2 = NULL;
return err;
}
@@ -3045,14 +3046,15 @@ static const struct got_error *
close_diff_view(struct tog_view *view)
{
const struct got_error *err = NULL;
+ struct tog_diff_view_state *s = &view->state.diff;
- free(view->state.diff.id1);
- view->state.diff.id1 = NULL;
- free(view->state.diff.id2);
- view->state.diff.id2 = NULL;
- if (view->state.diff.f && fclose(view->state.diff.f) == EOF)
+ free(s->id1);
+ s->id1 = NULL;
+ free(s->id2);
+ s->id2 = NULL;
+ if (s->f && fclose(s->f) == EOF)
err = got_error_from_errno("fclose");
- free_colors(&view->state.diff.colors);
+ free_colors(&s->colors);
return err;
}