tags:

views:

85

answers:

1

Hoping a 'git' guru will help out here.

I am just beginning to "git" for the first time and have (among other things :-) ) git and gitg installed from Ubuntu 10.4 / AMD64 distribution (ie. 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  A: 

When it comes to gitg alt text (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"&gt;
  <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
VonC
VonC, Saw that line. I'm assuming that gitg is "table driven" when it comes to deciding which files are displayable and that it will ask gtk for the answer to that. Gtk will then look in the sourceview-2.0 directory and inspect *.lang for a match. I've not used GTK before so this is a guess, but I'm relatively certain it's correct. I looked for the function referred to here ...return g_content_type_is_a(content_type, "text/plain")but a grep in the gitg/gitg directory returns nil. That leads me to believe the function is part of the gtk package, not gitg. Still searching...
Hotei
@Hotei: same grep, same result here!
VonC
@Hotei: right: part of glib (http://www.gtk.org/download.html), in gio/gcontenttype.c. Looking it up right now.
VonC
VonC, Ran xdg-mime install go-mime.xml with no errors. Test gitg again ... No there yet. I get the feeling I'm supposed to update the mime database with "update-mime-database /usr/share/mime" but after doing that I get some error messages and still no joy. There's no x-go.xml in the /usr/share/mime/text directory and that tells me the install/update was 'incomplete'. So for the moment I'm still stuck.
Hotei
@Hotei: Darn, I thought I had nailed it ;) Did you try a `update-desktop-database` after the `xdg-mime install` command? and try simple quotes around your commands: see http://gitorious.com/listaller/listaller/commit/b4dd43c80bdc81b717a6de02aa53bc9fd3eba037?diffmode=sidebyside for some examples.
VonC
@Hotei: see also http://pj.freefaculty.org/blog/?p=40: "When `RPMS` install, they often have a post script call to execute“`update-desktop-database`” which scans the desktop files under`/usr/share/applications` and it builds`/usr/share/applications/mimeinfo.cache`.To my surprise/astonishment, the `update-desktop-database` function is completely undocumented, not even a man page or a mention in the`README` file from the `xdg` group that provides it. To my even greater surprise, there is apparently no way to predict which programs will be at the front of the list for each mime type."
VonC
Hotei
VonC - still no joy. By the way, update-mime-database and xdg-mime have man pages on Ubuntu 10.4. Below is my latest go-mime.xmlBTW-Didn't work with mime type of x-go either. I do see files updating in the /usr/share/mime dirs after xdg-mime install.<?xml version="1.0" encoding="utf-8"?> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> <mime-type type="text/x-extension-go"> <sub-class-of type="text/plain"/> <comment>gofor giles</comment> <glob pattern="*.go"/> </mime-type> </mime-info>Who knew it would be this easy?
Hotei
EUREKA! This version worked.<?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>gofor giles</comment> <glob pattern="*.go"/> </mime-type> </mime-info>VonC - couldn't have done it without your help! I've accepted your answer. Many Thanks!!!:-)Hotei
Hotei
@Hotei: glad you made it work in the end. I have updated my answer to reflect your xml file. Hopefully, this will help others as well.
VonC