[gnome-builder] plugins/todo: handle insertion/removal without a todo item
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/todo: handle insertion/removal without a todo item
- Date: Tue, 6 Sep 2022 22:08:48 +0000 (UTC)
commit 1eb08dbf85839d54cf1196f771c2961b1a47d5df
Author: Christian Hergert <chergert redhat com>
Date: Tue Sep 6 15:08:29 2022 -0700
plugins/todo: handle insertion/removal without a todo item
This uses relative paths instead to do the search/insertion so that we can
handle situations where we don't have an item on either side of sequences.
Fixes #1777
src/plugins/todo/gbp-todo-model.c | 36 ++++++++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 8 deletions(-)
---
diff --git a/src/plugins/todo/gbp-todo-model.c b/src/plugins/todo/gbp-todo-model.c
index d4a5bb09d..01a1d432f 100644
--- a/src/plugins/todo/gbp-todo-model.c
+++ b/src/plugins/todo/gbp-todo-model.c
@@ -60,6 +60,7 @@ typedef struct
GbpTodoModel *self;
GSequence *items;
GFile *file;
+ GFile *workdir;
guint single_file : 1;
} ResultInfo;
@@ -154,6 +155,7 @@ result_info_free (gpointer data)
g_clear_object (&info->self);
g_clear_object (&info->file);
+ g_clear_object (&info->workdir);
g_clear_pointer (&info->items, g_sequence_free);
g_slice_free (ResultInfo, info);
}
@@ -257,12 +259,25 @@ gbp_todo_model_new (IdeVcs *vcs)
}
static int
-gbp_todo_model_compare_func (const GbpTodoItem *a,
- const GbpTodoItem *b)
+gbp_todo_model_compare_func (GbpTodoItem *a,
+ GbpTodoItem *b)
{
+ g_assert (GBP_IS_TODO_ITEM (a));
+ g_assert (GBP_IS_TODO_ITEM (b));
+
return g_strcmp0 (a->path, b->path);
}
+static int
+gbp_todo_model_compare_file (GbpTodoItem *a,
+ const char *path)
+{
+ g_assert (GBP_IS_TODO_ITEM (a));
+ g_assert (path != NULL);
+
+ return g_strcmp0 (a->path, path);
+}
+
static gboolean
result_info_merge (gpointer user_data)
{
@@ -294,7 +309,7 @@ result_info_merge (gpointer user_data)
}
else
{
- GbpTodoItem *first = g_sequence_get (g_sequence_get_begin_iter (r->items));
+ g_autofree char *path = NULL;
GSequenceIter *iter;
GSequenceIter *prev;
GSequenceIter *next;
@@ -308,9 +323,10 @@ result_info_merge (gpointer user_data)
* iter is removed, we can start inserting our sorted result set.
*/
+ path = g_file_get_relative_path (r->workdir, r->file);
iter = g_sequence_search (r->self->items,
- first,
- (GCompareDataFunc)gbp_todo_model_compare_func,
+ path,
+ (GCompareDataFunc)gbp_todo_model_compare_file,
NULL);
g_assert (iter != NULL);
@@ -321,24 +337,27 @@ result_info_merge (gpointer user_data)
*/
while ((prev = g_sequence_iter_prev (iter)) &&
(prev != iter) &&
- gbp_todo_model_compare_func (g_sequence_get (prev), first) == 0)
+ gbp_todo_model_compare_file (g_sequence_get (prev), path) == 0)
iter = prev;
position = g_sequence_iter_get_position (iter);
while ((next = g_sequence_iter_next (iter)) &&
(next != iter) &&
- gbp_todo_model_compare_func (g_sequence_get (iter), first) == 0)
+ gbp_todo_model_compare_file (g_sequence_get (iter), path) == 0)
{
g_sequence_remove (iter);
iter = next;
removed++;
}
+ if (removed > 0)
+ iter = g_sequence_iter_prev (iter);
+
if (added > 0)
g_sequence_move_range (iter,
g_sequence_get_begin_iter (r->items),
- g_sequence_iter_prev (g_sequence_get_end_iter (r->items)));
+ g_sequence_get_end_iter (r->items));
g_list_model_items_changed (G_LIST_MODEL (r->self), position, removed, added);
@@ -648,6 +667,7 @@ gbp_todo_model_mine_worker (IdeTask *task,
info->items = g_steal_pointer (&items);
info->file = g_object_ref (m->file);
info->single_file = single_file;
+ info->workdir = g_object_ref (m->workdir);
/* Sort our result set to help reduce how much sorting
* needs to be done on the main thread later.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]