Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: GitHub noreply@github.com Date: Wed, 15 Nov 2023 20:19:38 UTC Commit: 6227d2bebb980b908261f4c9bc470d2de011351c https://github.com/geany/geany-plugins/commit/6227d2bebb980b908261f4c9bc470d...
Log Message: ----------- Merge pull request #1290 from dolik-rce/prjorg-do-not-parse-open-files
avoid parsing opened files when loading project #1289
Modified Paths: -------------- projectorganizer/src/prjorg-project.c
Modified: projectorganizer/src/prjorg-project.c 58 lines changed, 53 insertions(+), 5 deletions(-) =================================================================== @@ -282,7 +282,9 @@ static void regenerate_tags(PrjOrgRoot *root, gpointer user_data) gpointer key, value; GPtrArray *source_files; GHashTable *file_table; + const gchar **session_files;
+ session_files = (const gchar **) user_data; source_files = g_ptr_array_new(); file_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GFreeFunc)tm_source_file_free); g_hash_table_iter_init(&iter, root->file_table); @@ -292,10 +294,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 will_open = session_files && g_strv_contains(session_files, utf8_path);
if (g_strcmp0(PROJORG_DIR_ENTRY, basename) != 0) sf = tm_source_file_new(locale_path, filetypes_detect(utf8_path)->name); - if (sf && !document_find_by_filename(utf8_path) ) + if (sf && !will_open && !document_find_by_filename(utf8_path)) g_ptr_array_add(source_files, sf);
g_hash_table_insert(file_table, g_strdup(utf8_path), sf); @@ -310,7 +313,7 @@ static void regenerate_tags(PrjOrgRoot *root, gpointer user_data) }
-void prjorg_project_rescan(void) +void rescan_project(gchar **session_files) { GSList *elem; gint filenum = 0; @@ -325,10 +328,14 @@ void prjorg_project_rescan(void) filenum += prjorg_project_rescan_root(elem->data);
if (prj_org->generate_tag_prefs == PrjOrgTagYes || (prj_org->generate_tag_prefs == PrjOrgTagAuto && filenum < 1000)) - g_slist_foreach(prj_org->roots, (GFunc)regenerate_tags, NULL); + g_slist_foreach(prj_org->roots, (GFunc)regenerate_tags, session_files); }
+void prjorg_project_rescan() { + rescan_project(NULL); +} + static PrjOrgRoot *create_root(const gchar *utf8_base_dir) { PrjOrgRoot *root = (PrjOrgRoot *) g_new0(PrjOrgRoot, 1); @@ -343,6 +350,7 @@ static void update_project( gchar **header_patterns, gchar **ignored_dirs_patterns, gchar **ignored_file_patterns, + gchar **session_files, PrjOrgTagPrefs generate_tag_prefs, gboolean show_empty_dirs) { @@ -374,7 +382,7 @@ static void update_project( prj_org->roots = g_slist_prepend(prj_org->roots, create_root(utf8_base_path)); g_free(utf8_base_path);
- prjorg_project_rescan(); + rescan_project(session_files); }
@@ -497,13 +505,49 @@ gchar **prjorg_project_load_expanded_paths(GKeyFile * key_file) }
+static gchar **get_session_files(GKeyFile *config) +{ + guint i; + gboolean have_session_files; + gchar entry[16]; + gchar **tmp_array; + GError *error = NULL; + GPtrArray *files; + gchar *unescaped_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); + g_ptr_array_add(files, g_strdup(unescaped_filename)); + g_free(unescaped_filename); + } + i++; + } + g_ptr_array_add(files, NULL); + + return (gchar **) g_ptr_array_free(files, FALSE); +} + + 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; + gchar **session_files;
if (prj_org != NULL) prjorg_project_close(); @@ -532,6 +576,8 @@ 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);
+ /* we need to know which files will be opened and parsed by Geany, to avoid parsing them twice */ + session_files = get_session_files(key_file); external_dirs = g_key_file_get_string_list(key_file, "prjorg", "external_dirs", NULL, NULL); foreach_strv (dir_ptr, external_dirs) ext_list = g_slist_prepend(ext_list, *dir_ptr); @@ -555,6 +601,7 @@ void prjorg_project_open(GKeyFile * key_file) header_patterns, ignored_dirs_patterns, ignored_file_patterns, + session_files, generate_tag_prefs, show_empty_dirs);
@@ -563,6 +610,7 @@ void prjorg_project_open(GKeyFile * key_file) g_strfreev(ignored_dirs_patterns); g_strfreev(ignored_file_patterns); g_strfreev(external_dirs); + g_strfreev(session_files); }
@@ -594,7 +642,7 @@ void prjorg_project_read_properties_tab(void) ignored_file_patterns = split_patterns(gtk_entry_get_text(GTK_ENTRY(e->ignored_file_patterns)));
update_project( - source_patterns, header_patterns, ignored_dirs_patterns, ignored_file_patterns, + source_patterns, header_patterns, ignored_dirs_patterns, ignored_file_patterns, NULL, gtk_combo_box_get_active(GTK_COMBO_BOX(e->generate_tag_prefs)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(e->show_empty_dirs)));
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).