douxie2023 2010-04-30 16:52
浏览 41
已采纳

如何添加转到gitg的可见源列表?

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条回答 默认 最新

  • dtwxmn8741 2010-04-30 17:43
    关注

    When it comes to gitg alt text http://trac.novowork.com/gitg/chrome/site/logo.png (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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了