英文:
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.
<question>
Is there a way to tweak gitg into understanding that "*.go" is just text? </question>
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** (针对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, "text/plain") ||
g_content_type_equals(content_type, "application/octet-stream");
}
所以你确实需要将go文件类型声明为text/plain
(在gitg中,而不是"to go.lang"),然后它应该可以工作。
实际上,声明不在gitg中:g_content_type_is_a
是glib\gio\gcontenttype.c
(glib项目)的一个函数,它调用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发现,做得很好!)
<?xml version="1.0" encoding="utf-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-extension-go">
<sub-class-of type="text/plain"/>
<comment>go for files</comment>
<glob pattern="*.go"/>
</mime-type>
</mime-info>
xdg-mime install go-mime.xml
update-desktop-database
英文:
When it comes to 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, "text/plain") ||
g_content_type_equals(content_type, "application/octet-stream");
}
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!)
<?xml version="1.0" encoding="utf-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-extension-go">
<sub-class-of type="text/plain"/>
<comment>go for files</comment>
<glob pattern="*.go"/>
</mime-type>
</mime-info>
xdg-mime install go-mime.xml
update-desktop-database
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论