Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tm: Cleanup include lookup #1991

Merged
merged 3 commits into from Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 5 additions & 32 deletions src/tagmanager/tm_workspace.c
Expand Up @@ -370,34 +370,6 @@ gboolean tm_workspace_load_global_tags(const char *tags_file, TMParserType mode)
}


static guint tm_file_inode_hash(gconstpointer key)
{
GStatBuf file_stat;
const char *filename = (const char*)key;

if (g_stat(filename, &file_stat) == 0)
{
#ifdef TM_DEBUG
g_message ("Hash for '%s' is '%d'\n", filename, file_stat.st_ino);
#endif
return g_direct_hash ((gpointer)(intptr_t)file_stat.st_ino);
}

return 0;
}


static void tm_move_entries_to_g_list(gpointer key, gpointer value, gpointer user_data)
{
GList **pp_list = (GList**)user_data;

if (user_data == NULL)
return;

*pp_list = g_list_prepend(*pp_list, g_strdup(value));
}


static gboolean write_includes_file(const gchar *outf, GList *includes_files)
{
FILE *fp = g_fopen(outf, "w");
Expand Down Expand Up @@ -470,14 +442,14 @@ static gchar *create_temp_file(const gchar *tpl)
static GList *lookup_includes(const gchar **includes, gint includes_count)
{
GList *includes_files = NULL;
GHashTable *table;
GHashTable *table; /* used for deduping */
gint i;
#ifdef HAVE_GLOB_H
glob_t globbuf;
size_t idx_glob;
#endif

table = g_hash_table_new_full(tm_file_inode_hash, g_direct_equal, NULL, g_free);
table = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);

#ifdef HAVE_GLOB_H
globbuf.gl_offs = 0;
Expand Down Expand Up @@ -515,6 +487,7 @@ static GList *lookup_includes(const gchar **includes, gint includes_count)
{
gchar *file_name_copy = g_strdup(globbuf.gl_pathv[idx_glob]);

includes_files = g_list_prepend(includes_files, file_name_copy);
g_hash_table_insert(table, file_name_copy, file_name_copy);
#ifdef TM_DEBUG
g_message ("Added ...\n");
Expand All @@ -535,15 +508,15 @@ static GList *lookup_includes(const gchar **includes, gint includes_count)
{
gchar* file_name_copy = g_strdup(includes[i]);

includes_files = g_list_prepend(includes_files, file_name_copy);
g_hash_table_insert(table, file_name_copy, file_name_copy);
}
}
}

g_hash_table_foreach(table, tm_move_entries_to_g_list, &includes_files);
g_hash_table_destroy(table);

return includes_files;
return g_list_reverse(includes_files);
}

static gchar *pre_process_file(const gchar *cmd, const gchar *inf)
Expand Down
10 changes: 10 additions & 0 deletions tests/ctags/Makefile.am
Expand Up @@ -319,3 +319,13 @@ TAGS_LOG_COMPILER = $(srcdir)/runner.sh

TESTS = $(test_results)
EXTRA_DIST = $(test_sources) $(test_results)

# check processing order of files on the command line
check_processing_order_sources = \
process_order.c.tags process_order_1.h process_order_2.h
EXTRA_DIST += $(check_processing_order_sources)
.PHONY: check-processing-order
check-processing-order: $(check_processing_order_sources)
srcdir="$(srcdir)" top_builddir="$(top_builddir)" \
$(srcdir)/runner.sh --result $(check_processing_order_sources:%=$(srcdir)/%)
check-local: check-processing-order
7 changes: 7 additions & 0 deletions tests/ctags/process_order.c.tags
@@ -0,0 +1,7 @@
# format=tagmanager
I1_E1�4�anon_enum_0�0
I1_E2�4�anon_enum_0�0
I2_E1�4�anon_enum_1�0
I2_E2�4�anon_enum_1�0
anon_enum_0�2�0
anon_enum_1�2�0
4 changes: 4 additions & 0 deletions tests/ctags/process_order_1.h
@@ -0,0 +1,4 @@
enum {
I1_E1,
I1_E2,
};
4 changes: 4 additions & 0 deletions tests/ctags/process_order_2.h
@@ -0,0 +1,4 @@
enum {
I2_E1,
I2_E2,
};
18 changes: 15 additions & 3 deletions tests/ctags/runner.sh
Expand Up @@ -17,9 +17,21 @@ mkdir -p "$CONFDIR/filedefs/" || exit 99
cp "${srcdir:-.}"/../../data/filetype_extensions.conf "$CONFDIR" || exit 99
cp "${srcdir:-.}"/../../data/filedefs/filetypes.* "$CONFDIR/filedefs/" || exit 99

result="$1"
source="${result%.*}"
if [ "$1" = "--result" ]; then
# --result $result $source...
[ $# -gt 2 ] || exit 99
shift
result="$1"
shift
source="$1"
else
# result is $1 and source is inferred from result
result="$1"
source="${result%.*}"
fi
shift

tagfile="$TMPDIR/test.${source##*.}.tags"

"$GEANY" -c "$CONFDIR" -P -g "$tagfile" "$source" || exit 1
"$GEANY" -c "$CONFDIR" -P -g "$tagfile" "$source" "$@" || exit 1
diff -u "$result" "$tagfile" || exit 2