Potential bug with "--path-style through" and GTAGSLIBPATH

Aymeric Agon-Rambosson <[email protected]> Thu, 01 May 2025 12:10:09 +0200
Newsgroups gmane.comp.gnu.global.bugs
Message-ID <877c30fxq6.fsf@X570GP>
--=-=-=
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable


Hello,

First of all, thank you very much for this very useful software.

There is a potential issue I wanted to bring to your attention.

The documentation relative to the --path-style option of global=20
states the following :

=C2=B4through=C2=B4 means the relative path from the project root directory=
=20
(internal format of GPATH)

Global will indeed print the path to the source file containing=20
some definition relatively to the project root directory, but only=20
if the symbol was found in the GTAGS file of the current project.=20
However, if the definition happens to be found in the GTAGS file=20
of some other out-of-tree directory pointed to by the GTAGSLIBPATH=20
environment variable, then the path printed by global is relative=20
to that out-of-tree directory, and NOT relative to the project=20
root directory the user finds itself in when it calls global.

Is this intended behaviour ?

If it is intended behaviour, I think it would be desirable to=20
stress this a little bit more in the documentation.

I agree that the phrase "(internal format of GPATH)" should make=20
the reader understand that global is going to print the path=20
exactly how it is written in the GPATH file *of the directory=20
pointed by GTAGSLIBPATH*, and draw the conclusions. Nonetheless,=20
making this consequence a little more obvious in the documentation=20
would not be amiss. I propose something along the lines of :

=C2=B4through=C2=B4 means the internal format of GPATH, that is the relativ=
e=20
path from the
GTAGS file in which the symbol was found. In particular, if the=20
symbol was found
in the GTAGS file of some directory pointed to by GTAGSLIBPATH,=20
then the path
will have to be interpreted as coming from that last directory,=20
and not the root
directory of the project you called global from.

It would also make sense that it is not intended behaviour :=20
invoking global with --path-style=3Dthrough while having=20
GTAGSLIBPATH set to some out-of-tree directory makes it impossible=20
for the caller to know what directory the output path is relative=20
to.

In this case, would it not be better to have some behaviour like=20
the one from abslib, something like "throughabslib" : relative to=20
the project root directory for the definitions found in the=20
project, and absolute for the definitions found in library=20
directories pointed to by GTAGSLIBPATH. If I am not mistaken, this=20
could be done trivially by doing the following :


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline; filename=patch.diff

--- global.c	2024-12-11 07:44:34.000000000 +0100
+++ globalnew.c	2025-05-01 12:07:48.990171720 +0200
@@ -949,9 +949,10 @@
 			type = PATH_RELATIVE;
 		else if (!strcmp(path_style, "absolute"))
 			type = PATH_ABSOLUTE;
-		else if (!strcmp(path_style, "through"))
+		else if (!strcmp(path_style, "through")) {
 			type = PATH_THROUGH;
-		else if (!strcmp(path_style, "shorter"))
+			abslib++;
+		} else if (!strcmp(path_style, "shorter"))
 			type = PATH_SHORTER;
 		else if (!strcmp(path_style, "abslib")) {
 			type = PATH_RELATIVE;

--=-=-=
Content-Type: text/plain; format=flowed


Let me know what you think.

Best,

Aymeric Agon-Rambosson


--=-=-=--