解决Google Code SVN HTML文件在Firefox中显示为源码的问题
近期测试发现,托管于Google Code SVN仓库中的HTML文件,在Firefox浏览器中无法正常渲染,而是直接以源代码形式呈现。
经过搜索排查,找到了导致该现象的原因及解决方案:
要使HTML文件在浏览器中正常显示,必须在提交至SVN时将文件的svn:mime-type属性设置为text/html(参考http://blog.pluskid.org/?p=70)。
主流的SVN客户端均支持自动配置此类属性,具体操作指南可参见(http://www.worldhello.net/wiki/SVN)。
--------------------------------------
6.2 新增文件的属性设置?
Whodo SVN的Hooks脚本会校验新增文件的属性,若缺失svn:mime-type或svn:eol-style属性,将禁止提交操作。
然而,每次添加文件后手动执行如“svn ps svn:eol-style ...”的命令过于繁琐。幸运的是,SVN客户端(无论是命令行还是TortoiseSVN)支持自动属性功能,即为新增文件自动附加相应属性。
6.2.1 config 配置文件
启用并配置自动属性需在config配置文件中完成。该配置文件在不同平台的位置如下:
Unix 平台
全局配置文件位于:/etc/subversion/config;每个用户主目录下也存在配置文件,用于覆盖全局设置:~/.subversion/config;
Windows 平台
注册表中可能包含相关设置:HKLM\Software\Tigris.org\Subversion\Config 以及 HKCU\Software\Tigris.org\Subversion\Config。但文件配置的优先级更高。全局配置文件路径:%ALLUSERSPROFILE%\Application Data\Subversion\config,用户个人配置文件路径:%APPDATA%\Subversion\config
6.2.2 启用 auto-props
修改config配置以启用auto-props功能:
[miscellany]global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store .cvsignore Thumbs.db CVSuse-commit-times = yesenable-auto-props = yes
6.2.3 基于文件名的 auto-props 设置
自动属性的匹配依据是文件名。需在config文件中添加新的配置段,示例如下:
### Section for configuring automatic properties.[auto-props]### The format of the entries is:### file-name-pattern = propname[=value][;propname[=value]...]### The file-name-pattern can contain wildcards (such as '*' and### '?'). All entries which match will be applied to the file.### Note that auto-props functionality must be enabled, which### is typically done by setting the 'enable-auto-props' option.##################################################### Binary files##################################################*.bmp = svn:mime-type=image/bmp*.gif = svn:mime-type=image/gif*.gz = svn:mime-type=application/x-gzip*.ico = svn:mime-type=image/x-icon*.jar = svn:mime-type=application/zip*.jpg = svn:mime-type=image/jpeg*.pdf = svn:mime-type=application/pdf*.png = svn:mime-type=image/png*.ps = svn:mime-type=application/postscript*.tif = svn:mime-type=image/tiff*.vsd = svn:mime-type=application/octet-stream*.zip = svn:mime-type=application/zip##################################################### Text files, OS dependent eol-style##################################################*.dsp = svn:eol-style=CRLF*.dsw = svn:eol-style=CRLF*.mm = svn:eol-style=LF;svn:mime-type=text/xml*.sh = svn:eol-style=LF;svn:executableMakefile = svn:eol-style=LF##################################################### Text files, eol-style is native##################################################*.c = svn:eol-style=native;svn:mime-type=text/plain*.cpp = svn:eol-style=native;svn:mime-type=text/plain*.css = svn:eol-style=native;svn:mime-type=text/css*.diff = svn:eol-style=native;svn:mime-type=text/plain*.dsl = svn:eol-style=native;svn:mime-type=text/sgml*.dtd = svn:eol-style=native;svn:mime-type=text/plain*.ent = svn:eol-style=native;svn:mime-type=text/plain*.gml = svn:eol-style=native;svn:mime-type=text/sgml*.h = svn:eol-style=native;svn:mime-type=text/plain*.htm = svn:eol-style=native;svn:mime-type=text/html*.html = svn:eol-style=native;svn:mime-type=text/html*.java = svn:eol-style=native;svn:mime-type=text/plain*.js = svn:eol-style=native;svn:mime-type=text/plain*.mod = svn:eol-style=native;svn:mime-type=text/plain*.patch = svn:eol-style=native;svn:mime-type=text/plain*.php = svn:eol-style=native*.pl = svn:eol-style=native*.py = svn:eol-style=native*.sgm = svn:eol-style=native;svn:mime-type=text/sgml*.sgml = svn:eol-style=native;svn:mime-type=text/sgml*.svg = svn:eol-style=native;svn:mime-type=text/xml*.txt = svn:mime-type=text/plain*.xml = svn:eol-style=native;svn:mime-type=text/xml*.xsl = svn:eol-style=native;svn:mime-type=text/xml*.xslt = svn:eol-style=native;svn:mime-type=text/xmlREADME = svn:eol-style=native文件添加后,在提交之前,可以通过如下命令查看新增文件的属性:
$ svn proplist -v *