Commit c959ee63 authored by Naba Kumar's avatar Naba Kumar

symbol-db: Enabled files population. Use relative files correctly.

Symbol population now correctly uses relative path without the leading '/' which
was wrong since that signified absolute path. Also, relative paths are created
without allocating new strings. This saves plenty of string dups and possibly
some time during both population and queries.
parent 6696b8aa
......@@ -941,7 +941,9 @@ on_project_element_removed (IAnjutaProjectManager *pm, GFile *gfile,
{
DEBUG_PRINT ("%s", "on_project_element_removed");
symbol_db_engine_remove_file (sdb_plugin->sdbe_project,
sdb_plugin->project_root_dir, filename);
sdb_plugin->project_root_dir,
symbol_db_util_get_file_db_path (sdb_plugin->sdbe_project,
filename));
g_free (filename);
}
......@@ -1329,7 +1331,6 @@ do_update_project_symbols (SymbolDBPlugin *sdb_plugin, const gchar *root_dir)
return FALSE;
}
#if 0
/**
* @return TRUE is a scan process is started, FALSE elsewhere.
*/
......@@ -1388,35 +1389,25 @@ do_check_offline_files_changed (SymbolDBPlugin *sdb_plugin)
/* some files may have added/removed editing Makefile.am while
* Anjuta was offline. Check this case too.
* FIXME: Get rid of data model here.
*/
SymbolDBEngineIterator *it =
symbol_db_engine_get_files_for_project (sdb_plugin->sdbe_project,
NULL,
SYMINFO_FILE_PATH);
if (it != NULL && symbol_db_engine_iterator_get_n_items (it) > 0)
GdaDataModel *model =
symbol_db_engine_get_files_for_project (sdb_plugin->sdbe_project);
GdaDataModelIter *it =
gda_data_model_create_iter (model);
if (it && gda_data_model_iter_move_to_row (it, 0))
{
GPtrArray *remove_array;
remove_array = g_ptr_array_new ();
do {
SymbolDBEngineIteratorNode *dbin;
dbin = (SymbolDBEngineIteratorNode *) it;
const gchar * file =
symbol_db_engine_iterator_node_get_symbol_extra_string (dbin,
SYMINFO_FILE_PATH);
const GValue *val = gda_data_model_iter_get_value_at (it, 0);
const gchar * file = g_value_get_string (val);
if (file && g_hash_table_remove (prj_elements_hash, file) == FALSE)
{
/* hey, we dind't find an element to remove the the project list.
* So, probably, this is a new file added in offline mode via Makefile.am
* editing.
* Keep a reference to it.
*/
/*DEBUG_PRINT ("ARRAY REMOVE %s", file);*/
g_ptr_array_add (remove_array, (gpointer)file);
}
} while (symbol_db_engine_iterator_move_next (it));
g_ptr_array_add (remove_array, (gpointer) file);
} while (gda_data_model_iter_move_next (it));
symbol_db_engine_remove_files (sdb_plugin->sdbe_project,
sdb_plugin->project_opened,
......@@ -1471,12 +1462,12 @@ do_check_offline_files_changed (SymbolDBPlugin *sdb_plugin)
}
g_object_unref (it);
g_object_unref (model);
g_ptr_array_free (to_add_files, TRUE);
g_hash_table_destroy (prj_elements_hash);
return real_added > 0 ? TRUE : FALSE;
}
#endif
static void
on_session_save (AnjutaShell *shell, AnjutaSessionPhase phase,
......@@ -1717,22 +1708,12 @@ on_project_root_added (AnjutaPlugin *plugin, const gchar *name,
g_ptr_array_foreach (sources_array, (GFunc)g_free, NULL);
g_ptr_array_free (sources_array, TRUE);
}
#if 0
/* check for offline changes */
flag_offline = do_check_offline_files_changed (sdb_plugin);
#endif
/* update any files of the project which isn't up-to-date */
flag_update = do_update_project_symbols (sdb_plugin, root_dir);
/* if they're both false then there won't be a place where
* the do_check_languages_count () is called. Check the returns
* and to it here
*/
if (flag_offline == FALSE && flag_update == FALSE)
{
/* check for the number of languages used in the opened project. */
//do_check_languages_count (sdb_plugin);
}
}
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (sdb_plugin->progress_bar_project),
_("Populating symbol database…"));
......@@ -1838,8 +1819,6 @@ on_scan_end_manager (SymbolDBEngine *dbe, gint process_id,
gboolean parallel_scan = anjuta_preferences_get_bool (sdb_plugin->prefs,
PARALLEL_SCAN);
//do_check_languages_count (sdb_plugin);
/* check the system population has a parallel fashion or not. */
if (parallel_scan == FALSE)
do_import_system_sources (sdb_plugin);
......@@ -1854,7 +1833,6 @@ on_scan_end_manager (SymbolDBEngine *dbe, gint process_id,
case TASK_ELEMENT_ADDED:
DEBUG_PRINT ("received TASK_ELEMENT_ADDED");
sdb_plugin->is_adding_element = FALSE;
//do_check_languages_count (sdb_plugin);
break;
case TASK_OFFLINE_CHANGES:
......@@ -1865,8 +1843,6 @@ on_scan_end_manager (SymbolDBEngine *dbe, gint process_id,
sdb_plugin);
sdb_plugin->is_offline_scanning = FALSE;
//do_check_languages_count (sdb_plugin);
break;
case TASK_PROJECT_UPDATE:
......
......@@ -1511,7 +1511,7 @@ sdb_engine_get_file_defined_id (SymbolDBEngine* dbe,
/* we expect here an absolute path */
g_value_set_static_string (value,
tag_entry->file + strlen (base_prj_path) );
tag_entry->file + strlen (base_prj_path) + 1);
}
else
{
......@@ -3288,7 +3288,7 @@ gboolean
symbol_db_engine_file_exists (SymbolDBEngine * dbe, const gchar * abs_file_path)
{
SymbolDBEnginePriv *priv;
gchar *relative;
const gchar *relative;
gint file_defined_id;
GValue *value;
......@@ -3313,12 +3313,10 @@ symbol_db_engine_file_exists (SymbolDBEngine * dbe, const gchar * abs_file_path)
"filepath",
value)) < 0)
{
g_free (relative);
SDB_UNLOCK(priv);
return FALSE;
}
g_free (relative);
SDB_UNLOCK(priv);
return TRUE;
}
......@@ -3887,7 +3885,7 @@ CREATE TABLE file (file_id integer PRIMARY KEY AUTOINCREMENT,
* e.g.: we have a file on disk: "/tmp/foo/src/file.c" and a db_directory located on
* "/tmp/foo/". The entry on db will be "src/file.c"
*/
gchar *relative_path = symbol_db_util_get_file_db_path (dbe, local_filepath);
const gchar *relative_path = symbol_db_util_get_file_db_path (dbe, local_filepath);
if (relative_path == NULL)
{
DEBUG_PRINT ("%s", "relative_path == NULL");
......@@ -3917,7 +3915,6 @@ CREATE TABLE file (file_id integer PRIMARY KEY AUTOINCREMENT,
== NULL)
{
g_warning ("query is null");
g_free (relative_path);
SDB_UNLOCK(priv);
return FALSE;
}
......@@ -3928,7 +3925,6 @@ CREATE TABLE file (file_id integer PRIMARY KEY AUTOINCREMENT,
if ((param = gda_set_get_holder ((GdaSet*)plist, "filepath")) == NULL)
{
g_warning ("param langname is NULL from pquery!");
g_free (relative_path);
SDB_UNLOCK(priv);
return FALSE;
}
......@@ -3939,7 +3935,6 @@ CREATE TABLE file (file_id integer PRIMARY KEY AUTOINCREMENT,
if ((param = gda_set_get_holder ((GdaSet*)plist, "prjid")) == NULL)
{
g_warning ("param prjid is NULL from pquery!");
g_free (relative_path);
SDB_UNLOCK(priv);
return FALSE;
}
......@@ -3950,7 +3945,6 @@ CREATE TABLE file (file_id integer PRIMARY KEY AUTOINCREMENT,
if ((param = gda_set_get_holder ((GdaSet*)plist, "langid")) == NULL)
{
g_warning ("param langid is NULL from pquery!");
g_free (relative_path);
SDB_UNLOCK(priv);
return FALSE;
}
......@@ -3969,8 +3963,6 @@ CREATE TABLE file (file_id integer PRIMARY KEY AUTOINCREMENT,
NULL) == -1)
{
MP_RESET_PLIST(plist);
g_free (relative_path);
SDB_UNLOCK(priv);
return FALSE;
}
......@@ -3978,8 +3970,6 @@ CREATE TABLE file (file_id integer PRIMARY KEY AUTOINCREMENT,
MP_RESET_PLIST(plist);
}
g_free (relative_path);
SDB_UNLOCK(priv);
return TRUE;
}
......@@ -6798,8 +6788,8 @@ symbol_db_engine_update_project_symbols (SymbolDBEngine *dbe,
file_name = g_value_get_string (value);
if (priv->project_directory != NULL)
{
file_abs_path = g_strdup_printf ("%s%s", priv->project_directory,
file_name);
file_abs_path = g_build_filename (priv->project_directory,
file_name, NULL);
}
gfile = g_file_new_for_path (file_abs_path);
......@@ -6888,8 +6878,8 @@ symbol_db_engine_update_project_symbols (SymbolDBEngine *dbe,
/* ~~~ Thread note: this function locks the mutex ~~~ */
gboolean
symbol_db_engine_remove_file (SymbolDBEngine * dbe, const gchar * project,
const gchar * abs_file)
symbol_db_engine_remove_file (SymbolDBEngine * dbe, const gchar *project,
const gchar *rel_file)
{
SymbolDBEnginePriv *priv;
const GdaSet *plist;
......@@ -6901,19 +6891,19 @@ symbol_db_engine_remove_file (SymbolDBEngine * dbe, const gchar * project,
g_return_val_if_fail (dbe != NULL, FALSE);
g_return_val_if_fail (project != NULL, FALSE);
g_return_val_if_fail (abs_file != NULL, FALSE);
g_return_val_if_fail (rel_file != NULL, FALSE);
priv = dbe->priv;
SDB_LOCK(priv);
if (strlen (abs_file) < strlen (priv->project_directory))
if (strlen (rel_file))
{
g_warning ("wrong file to delete.");
SDB_UNLOCK(priv);
return FALSE;
}
DEBUG_PRINT ("deleting from db %s", abs_file);
DEBUG_PRINT ("deleting from db %s", rel_file);
if ((stmt = sdb_engine_get_statement_by_query_id (dbe,
PREP_QUERY_REMOVE_FILE_BY_PROJECT_NAME)) == NULL)
......@@ -6941,8 +6931,7 @@ symbol_db_engine_remove_file (SymbolDBEngine * dbe, const gchar * project,
return FALSE;
}
gchar * file_on_db = symbol_db_util_get_file_db_path (dbe, abs_file);
MP_SET_HOLDER_BATCH_STR(priv, param, file_on_db, ret_bool, ret_value);
MP_SET_HOLDER_BATCH_STR(priv, param, rel_file, ret_bool, ret_value);
/* Triggers will take care of updating/deleting connected symbols
* tuples, like sym_kind, sym_type etc */
......@@ -6954,7 +6943,6 @@ symbol_db_engine_remove_file (SymbolDBEngine * dbe, const gchar * project,
/* emits removed symbols signals */
sdb_engine_detects_removed_ids (dbe);
g_free (file_on_db);
SDB_UNLOCK(priv);
return TRUE;
......@@ -6962,7 +6950,7 @@ symbol_db_engine_remove_file (SymbolDBEngine * dbe, const gchar * project,
void
symbol_db_engine_remove_files (SymbolDBEngine * dbe, const gchar * project,
const GPtrArray * files)
const GPtrArray * files)
{
SymbolDBEnginePriv *priv;
gint i;
......@@ -6994,17 +6982,15 @@ on_scan_update_buffer_end (SymbolDBEngine * dbe, gint process_id, gpointer data)
for (i = 0; i < files_to_scan->len; i++)
{
gchar *node = (gchar *) g_ptr_array_index (files_to_scan, i);
gchar *relative_path = symbol_db_util_get_file_db_path (dbe, node);
const gchar *relative_path = symbol_db_util_get_file_db_path (dbe, node);
if (relative_path != NULL)
{
/* will be emitted removed signals */
if (sdb_engine_update_file (dbe, relative_path) == FALSE)
{
g_warning ("Error processing file %s", node);
g_free (relative_path);
return;
}
g_free (relative_path);
}
g_free (node);
}
......@@ -7046,7 +7032,7 @@ symbol_db_engine_update_buffer_symbols (SymbolDBEngine * dbe, const gchar *proje
/* obtain a GPtrArray with real_files on database */
for (i=0; i < real_files_list->len; i++)
{
gchar *relative_path;
const gchar *relative_path;
const gchar *curr_abs_file;
FILE *buffer_mem_file;
const gchar *temp_buffer;
......@@ -7073,7 +7059,7 @@ symbol_db_engine_update_buffer_symbols (SymbolDBEngine * dbe, const gchar *proje
"relative_path is NULL");
continue;
}
g_ptr_array_add (real_files_on_db, relative_path);
g_ptr_array_add (real_files_on_db, (gpointer) relative_path);
/* it's ok to have just the base filename to create the
* target buffer one */
......@@ -7146,14 +7132,16 @@ symbol_db_engine_update_buffer_symbols (SymbolDBEngine * dbe, const gchar *proje
g_ptr_array_free (temp_files, TRUE);
/* and the real_files_on_db too */
for (i=0; i < real_files_on_db->len; i++)
g_free (g_ptr_array_index (real_files_on_db, i));
g_ptr_array_free (real_files_on_db, TRUE);
return ret_id;
}
GdaDataModel*
symbol_db_engine_get_files_for_project (SymbolDBEngine *dbe)
{
return sdb_engine_execute_select_sql (dbe, "SELECT file.file_path FROME file");
}
/* ~~~ Thread note: this function locks the mutex ~~~ */
void
symbol_db_engine_set_db_case_sensitive (SymbolDBEngine *dbe, gboolean case_sensitive)
......
......@@ -240,12 +240,12 @@ symbol_db_engine_update_project_symbols (SymbolDBEngine *dbe,
/** Remove a file, together with its symbols, from a project. */
gboolean
symbol_db_engine_remove_file (SymbolDBEngine *dbe, const gchar* project,
const gchar* abs_file);
symbol_db_engine_remove_file (SymbolDBEngine *dbe, const gchar *project,
const gchar* rel_file);
void
symbol_db_engine_remove_files (SymbolDBEngine * dbe, const gchar * project,
const GPtrArray * files);
symbol_db_engine_remove_files (SymbolDBEngine * dbe, const gchar *project,
const GPtrArray *rel_files);
/**
* Update symbols of saved files.
......@@ -272,6 +272,13 @@ symbol_db_engine_update_buffer_symbols (SymbolDBEngine * dbe, const gchar * proj
const GPtrArray * text_buffers,
const GPtrArray * buffer_sizes);
/**
* Retrieves the list of files in project. The data model contains only 1
* column, which is the file name.
*/
GdaDataModel*
symbol_db_engine_get_files_for_project (SymbolDBEngine *dbe);
/**
* Set the opened db case sensitive. The searches on this db will then be performed
* taking into consideration this SQLite's PRAGMA case_sensitive_like.
......
......@@ -29,7 +29,6 @@
#include <glib.h>
#include "symbol-db-engine.h"
#include "symbol-db-engine-iterator.h"
......
......@@ -68,38 +68,26 @@ gchar*
symbol_db_util_get_full_local_path (SymbolDBEngine *dbe, const gchar* file)
{
SymbolDBEnginePriv *priv;
gchar *full_path;
g_return_val_if_fail (dbe != NULL, NULL);
priv = dbe->priv;
full_path = g_strdup_printf ("%s%s", priv->project_directory, file);
return full_path;
return g_build_filename (priv->project_directory, file, NULL);
}
gchar*
const gchar*
symbol_db_util_get_file_db_path (SymbolDBEngine *dbe, const gchar* full_local_file_path)
{
SymbolDBEnginePriv *priv;
gchar *relative_path;
const gchar *tmp;
g_return_val_if_fail (dbe != NULL, NULL);
g_return_val_if_fail (full_local_file_path != NULL, NULL);
priv = dbe->priv;
if (priv->db_directory == NULL)
if (priv->db_directory == NULL ||
strlen (priv->project_directory) >= strlen (full_local_file_path))
return NULL;
if (strlen (priv->project_directory) >= strlen (full_local_file_path))
{
return NULL;
}
tmp = full_local_file_path + strlen (priv->project_directory);
relative_path = strdup (tmp);
return relative_path;
return full_local_file_path + strlen (priv->project_directory) + 1;
}
GPtrArray *
......
......@@ -57,7 +57,7 @@ symbol_db_util_get_full_local_path (SymbolDBEngine *dbe, const gchar* db_file);
* /home/user/foo_project/src/foo.c returned file should be /src/foo.c.
* Return NULL on error.
*/
gchar *
const gchar *
symbol_db_util_get_file_db_path (SymbolDBEngine *dbe, const gchar* full_local_file_path);
/**
......
......@@ -174,7 +174,7 @@ sdb_model_file_get_children (SymbolDBModel *model, gint tree_level,
gda_holder_set_value (priv->param_limit, &ival, NULL);
g_value_set_int (&ival, offset);
gda_holder_set_value (priv->param_offset, &ival, NULL);
g_value_take_string (&sval, relative_path);
g_value_set_static_string (&sval, relative_path);
gda_holder_set_value (priv->param_file_path, &sval, NULL);
g_value_reset (&sval);
......
......@@ -1178,7 +1178,8 @@ static IAnjutaIterable*
sdb_query_search_file (IAnjutaSymbolQuery *query, const gchar *search_string,
const GFile *file, GError **error)
{
gchar *rel_file_path, *abs_file_path;
const gchar *rel_file_path;
gchar *abs_file_path;
SDB_QUERY_SEARCH_HEADER;
g_return_val_if_fail (priv->name == IANJUTA_SYMBOL_QUERY_SEARCH_FILE, NULL);
......@@ -1186,8 +1187,7 @@ sdb_query_search_file (IAnjutaSymbolQuery *query, const gchar *search_string,
rel_file_path = symbol_db_util_get_file_db_path (priv->dbe_selected, abs_file_path);
SDB_PARAM_SET_STATIC_STRING (priv->param_pattern, search_string);
SDB_PARAM_TAKE_STRING (priv->param_file_path, rel_file_path);
SDB_PARAM_SET_STATIC_STRING (priv->param_file_path, rel_file_path);
g_free (abs_file_path);
return sdb_query_execute (SYMBOL_DB_QUERY (query));
}
......@@ -1241,7 +1241,7 @@ static IAnjutaIterable*
sdb_query_search_scope (IAnjutaSymbolQuery *query, const gchar *file_path,
gint file_line, GError **error)
{
gchar *db_relative_path;
const gchar *db_relative_path;
SDB_QUERY_SEARCH_HEADER;
g_return_val_if_fail (priv->name == IANJUTA_SYMBOL_QUERY_SEARCH_SCOPE, NULL);
......@@ -1250,7 +1250,7 @@ sdb_query_search_scope (IAnjutaSymbolQuery *query, const gchar *file_path,
return NULL;
SDB_PARAM_SET_INT (priv->param_file_line, file_line);
SDB_PARAM_TAKE_STRING (priv->param_file_path, db_relative_path);
SDB_PARAM_SET_STATIC_STRING (priv->param_file_path, db_relative_path);
return sdb_query_execute (SYMBOL_DB_QUERY (query));
}
......@@ -1269,7 +1269,7 @@ static IAnjutaIterable*
sdb_query_search_parent_scope_file (IAnjutaSymbolQuery *query, IAnjutaSymbol *symbol,
const gchar *file_path, GError **error)
{
gchar *db_relative_path;
const gchar *db_relative_path;
SDB_QUERY_SEARCH_HEADER;
g_return_val_if_fail (priv->name == IANJUTA_SYMBOL_QUERY_SEARCH_PARENT_SCOPE_FILE, NULL);
......@@ -1278,7 +1278,7 @@ sdb_query_search_parent_scope_file (IAnjutaSymbolQuery *query, IAnjutaSymbol *sy
return NULL;
SDB_PARAM_SET_INT (priv->param_id, ianjuta_symbol_get_int (symbol, IANJUTA_SYMBOL_FIELD_ID, NULL));
SDB_PARAM_TAKE_STRING (priv->param_file_path, db_relative_path);
SDB_PARAM_SET_STATIC_STRING (priv->param_file_path, db_relative_path);
return sdb_query_execute (SYMBOL_DB_QUERY (query));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment