如何将Go添加到gitg的可查看源列表中?

huangapple go评论111阅读模式
英文:

How do I add the Go to gitg's list of viewable sources?

问题

我刚开始第一次使用“git”,并从Ubuntu 10.4 / AMD64发行版安装了git和gitg(即可能不是“最新”版本,但也不是古老的版本)。

我试图通过gitg查看我已经提交的go代码,在“树标签”中显示:

无法显示文件内容为文本。

然而,“详细标签”可以正常显示相同文件的差异。
我知道gitg的“树标签”是工作正常的,因为我可以正常使用树视图查看*.c / *.html / *.txt等文件。

<问题>是否有办法调整gitg以理解“*.go”只是文本?</问题>

更多背景信息:

  • 安装的gitg版本是0.0.5 - 即比最新版本0.0.6落后一个版本 - 我正在查看其源代码。

我确实有一个可用的/usr/share/gtksourceview-2.0/language-specs/go.lang
它在gedit中作为语法高亮器工作正常。
看起来gitg可能要求可显示的文件具有“text/plain”的MIME类型,所以我将其添加到go.lang中。

但是没有成功。gitg仍然无法处理*.go文件。
我相对确定修复方法很简单,只是不知道在哪里查找。

英文:

I am just beginning to "git" for the first time and have git and gitg installed from Ubuntu 10.4 / AMD64 distribution (i.e. maybe not 'latest' version but not ancient).

I am trying to look at the go code I've committed via gitg and in the "tree tab" it says:

Cannot display file content as text.

However, the "details tab" shows the diffs of the same file just fine.
I know gitg's "tree tab" is working because I can use the tree view on *.c / *.html / *.txt, etc just fine.

&lt;question&gt; Is there a way to tweak gitg into understanding that "*.go" is just text? &lt;/question&gt;

A little more context:

  • Installed gitg version is 0.0.5 - ie a version behind latest - 0.0.6 - source of which I am looking thru now.

I do have a working /usr/share/gtksourceview-2.0/language-specs/go.lang.
It works just fine as highlighter in gedit.
It appears that gitg may require displayable files to have a mime type of "text/plain", so I added that to go.lang

No joy. gitg still fails on *.go.
I'm relatively sure the fix is simple, just don't know where to look.

答案1

得分: 1

当谈到**gitg** 如何将Go添加到gitg的可查看源列表中?(针对gtk+/GNOME的git仓库查看器)时,可能会对查看其代码也在这里)感兴趣:

特别是gitg-commit-view.c显示该消息,是因为它的函数gitg_utils_can_display_content_type()对于文本显示目的返回了一个未知类型。

gboolean
gitg_utils_can_display_content_type(gchar const *content_type)
{
        return g_content_type_is_a(content_type, &quot;text/plain&quot;) || 
                   g_content_type_equals(content_type, &quot;application/octet-stream&quot;);
}

所以你确实需要将go文件类型声明为text/plain(在gitg中,而不是"to go.lang"),然后它应该可以工作。


实际上,声明不在gitg中:g_content_type_is_aglib\gio\gcontenttype.cglib项目)的一个函数,它调用get_registry_classes_key(),该函数读取注册表(对于Windows来说是HKEY_CLASSES_ROOT,对于Unix是**注册的mime类型**)。

所以,如果你注册了go文件,它应该可以工作:

xdg-icon-resource install --context mimetypes --size 48 go-type.png plain/text

用于注册的xml文件(由OP Hotei发现,做得很好!)

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mime-info xmlns=&quot;http://www.freedesktop.org/standards/shared-mime-info&quot;&gt;
  &lt;mime-type type=&quot;application/x-extension-go&quot;&gt;
    &lt;sub-class-of type=&quot;text/plain&quot;/&gt;
    &lt;comment&gt;go for files&lt;/comment&gt;
    &lt;glob pattern=&quot;*.go&quot;/&gt;
  &lt;/mime-type&gt;
&lt;/mime-info&gt;

xdg-mime install go-mime.xml
update-desktop-database
英文:

When it comes to gitg 如何将Go添加到gitg的可查看源列表中? (the git repository viewer targeting gtk+/GNOME), it may be interesting to look at its code (also here):

In particular, gitg-commit-view.c displays that message because its function gitg_utils_can_display_content_type() return an unknown type for text display purposes.

gboolean
gitg_utils_can_display_content_type(gchar const *content_type)
{
        return g_content_type_is_a(content_type, &quot;text/plain&quot;) || 
                   g_content_type_equals(content_type, &quot;application/octet-stream&quot;);
}

So you do need to declare go file type as text/plain (in gitg, not "to go.lang") and it should work.


Actually, the declaration is not in gitg: g_content_type_is_a is a function of glib\gio\gcontenttype.c (project glib), and it calls get_registry_classes_key(), which read the registry (HKEY_CLASSES_ROOT for Windows, mime type registered for Unix).

So if you register the go files, it should work:

xdg-icon-resource install --context mimetypes --size 48 go-type.png plain/text

The xml file to register (found by the OP Hotei, great work!)

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mime-info xmlns=&quot;http://www.freedesktop.org/standards/shared-mime-info&quot;&gt;
  &lt;mime-type type=&quot;application/x-extension-go&quot;&gt;
    &lt;sub-class-of type=&quot;text/plain&quot;/&gt;
    &lt;comment&gt;go for files&lt;/comment&gt;
    &lt;glob pattern=&quot;*.go&quot;/&gt;
  &lt;/mime-type&gt;
&lt;/mime-info&gt;

xdg-mime install go-mime.xml
update-desktop-database

huangapple
  • 本文由 发表于 2010年5月1日 00:52:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/2746237.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定