Crude but working solution to #1289.
Disclaimer: I'm not really a C person, so any suggestion on how to improve the code quality are most welcome. You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany-plugins/pull/1290
-- Commit Summary --
* avoid parsing opened files when loading project #1289
-- File Changes --
M projectorganizer/src/prjorg-project.c (67) M projectorganizer/src/prjorg-project.h (2) M projectorganizer/src/prjorg-sidebar.c (10)
-- Patch Links --
https://github.com/geany/geany-plugins/pull/1290.patch https://github.com/geany/geany-plugins/pull/1290.diff
@dolik-rce commented on this pull request.
I just hope I didn't introduce any stupid memory leak. It's been years since I had to manage memory manually.
@@ -276,13 +276,24 @@ static GeanyFiletype *filetypes_detect(const gchar *utf8_filename)
}
+static gboolean string_exists_in_array(gchar **array, gchar *str) {
I'm pretty sure this function already exists in glib or somewhere... I just couldn't find it :roll_eyes:
@@ -497,13 +509,51 @@ gchar **prjorg_project_load_expanded_paths(GKeyFile * key_file)
}
+static GPtrArray *get_session_files(GKeyFile *config)
This is mostly ~~stolen from~~ inspired by `configuration_load_session_files` in Geany. The only difference is that this one only reads the filename.
+ files = g_ptr_array_new(); + have_session_files = TRUE; + i = 0; + while (have_session_files) + { + g_snprintf(entry, sizeof(entry), "FILE_NAME_%d", i); + tmp_array = g_key_file_get_string_list(config, "files", entry, NULL, &error); + if (! tmp_array || error) + { + g_error_free(error); + error = NULL; + have_session_files = FALSE; + } else { + unescaped_filename = g_uri_unescape_string(tmp_array[7], NULL); + locale_filename = utils_get_locale_from_utf8(unescaped_filename);
Hm, thinking about it now: This should probably not be here. I think conversion to locale should only be used for display purposes, but all internal filenames should be handled in UTF-8, right?
@rdipardo commented on this pull request.
@@ -276,13 +276,24 @@ static GeanyFiletype *filetypes_detect(const gchar *utf8_filename)
}
+static gboolean string_exists_in_array(gchar **array, gchar *str) {
I'm pretty sure this function already exists in glib or somewhere...
Perhaps you mean [g_strv_contains](https://developer-old.gnome.org/glib/stable/glib-String-Utility-Functions.ht...
@dolik-rce pushed 1 commit.
f8771f6df63e32d7d98d78fbc7893ff1d81a5950 avoid parsing opened files when loading project #1289
@dolik-rce pushed 1 commit.
6cb68a7ae16f5b4496fefdd7f59e119bfe2d8ccd avoid parsing opened files when loading project #1289
@techee requested changes on this pull request.
@dolik-rce Thanks! I was hesitating whether this patch doesn't complicate things but it's not too bad so let's do that!
There are some minor comments in the review, nothing major, mostly some renames and minor cleanups.
@@ -532,6 +571,7 @@ void prjorg_project_open(GKeyFile * key_file)
generate_tag_prefs = utils_get_setting_integer(key_file, "prjorg", "generate_tag_prefs", PrjOrgTagAuto); show_empty_dirs = utils_get_setting_boolean(key_file, "prjorg", "show_empty_dirs", TRUE);
+ open_files = get_session_files(key_file);
Big fat comment here what we are actually doing and why.
@@ -343,6 +345,7 @@ static void update_project(
gchar **header_patterns, gchar **ignored_dirs_patterns, gchar **ignored_file_patterns, + gchar **open_files,
`session_files`
static void regenerate_tags(PrjOrgRoot *root, gpointer user_data)
{ GHashTableIter iter; gpointer key, value; GPtrArray *source_files; GHashTable *file_table; + gchar **open_files;
I'd suggest renaming it to `session_files` because these aren't open yet and may be confusing.
@@ -292,10 +293,11 @@ static void regenerate_tags(PrjOrgRoot *root, gpointer user_data)
gchar *utf8_path = key; gchar *locale_path = utils_get_locale_from_utf8(utf8_path); gchar *basename = g_path_get_basename(locale_path); + gboolean is_open = open_files && g_strv_contains(open_files, utf8_path);
Maybe call it `will_open`.
@@ -310,7 +312,7 @@ static void regenerate_tags(PrjOrgRoot *root, gpointer user_data)
}
-void prjorg_project_rescan(void) +void prjorg_project_rescan(gchar **open_files)
Rename to `session_files`
void prjorg_project_open(GKeyFile * key_file)
{ gchar **source_patterns, **header_patterns, **ignored_dirs_patterns, **ignored_file_patterns, **external_dirs, **dir_ptr, *last_name; gint generate_tag_prefs; gboolean show_empty_dirs; GSList *elem = NULL, *ext_list = NULL; gchar *utf8_base_path; + GPtrArray *open_files;
`session_files`
@@ -275,14 +275,15 @@ static GeanyFiletype *filetypes_detect(const gchar *utf8_filename)
return ft; }
-
keep two empty lines before functions
tmp_array = g_key_file_get_string_list(config, "files", entry, NULL, &error);
+ if (! tmp_array || error) + { + g_error_free(error); + error = NULL; + have_session_files = FALSE; + } else { + unescaped_filename = g_uri_unescape_string(tmp_array[7], NULL); + g_ptr_array_add(files, g_strdup(unescaped_filename)); + g_free(unescaped_filename); + } + i++; + } + g_ptr_array_add(files, NULL); + + return files;
change to `return g_ptr_array_free(files, FALSE);` and return `gchar **` from the function.
@@ -563,6 +604,7 @@ void prjorg_project_open(GKeyFile * key_file)
g_strfreev(ignored_dirs_patterns); g_strfreev(ignored_file_patterns); g_strfreev(external_dirs); + g_ptr_array_free(open_files, TRUE);
Use `g_strfreev` with the other changes above.
@@ -292,10 +293,11 @@ static void regenerate_tags(PrjOrgRoot *root, gpointer user_data)
gchar *utf8_path = key; gchar *locale_path = utils_get_locale_from_utf8(utf8_path); gchar *basename = g_path_get_basename(locale_path); + gboolean is_open = open_files && g_strv_contains(open_files, utf8_path);
Cast `open_files` to `(const gchar **)` to avoid warnings.
@@ -310,7 +312,7 @@ static void regenerate_tags(PrjOrgRoot *root, gpointer user_data)
}
-void prjorg_project_rescan(void) +void prjorg_project_rescan(gchar **open_files)
In addition, I'd suggest converting it to a static function called `rescan_project` and having a separate `prjorg_project_rescan()` without any arguments and just calling `rescan_project(NULL);` inside it. This way you avoid the diffs adding the `NULL` parameter across the project.
void prjorg_project_open(GKeyFile * key_file)
{ gchar **source_patterns, **header_patterns, **ignored_dirs_patterns, **ignored_file_patterns, **external_dirs, **dir_ptr, *last_name; gint generate_tag_prefs; gboolean show_empty_dirs; GSList *elem = NULL, *ext_list = NULL; gchar *utf8_base_path; + GPtrArray *open_files;
In addition, with the suggested change in `get_session_files`, change to `gchar **`.
@dolik-rce pushed 1 commit.
a8c8ca2a83672291136117fbab53ed0ceae23776 avoid parsing opened files when loading project #1289
I was hesitating whether this patch doesn't complicate things but it's not too bad so let's do that!
It is even less complicated now, after I applied your suggestions :-)
@techee approved this pull request.
Merged #1290 into master.
Thanks! Merged now.
github-comments@lists.geany.org