English 中文(简体)
How to avoid line delimiter conversion (resulting in wrong line numbers) in Subversion pre-commit hook?
原标题:

we have the following environment: a Windows 2008 Server with Apache 2.2.14 and SVN 1.6.6 through WebDAV. Multiple developers commit Java code from different Windows platforms.

Now we want to implement a pre-commit hook to our repository that runs Checkstyle on the committed code. We use SVNChecker (http://svnchecker.tigris.org/) for this, which works pretty well. Unfortunately, when Checkstyle reports errors, the line numbers in the reports are the double values of the actual line numbers.

When you commit something in SVN, it creates a temporary directory with the new files. Then, the pre-commit hook is run and if it succeeds, the new files are actually committed to the repository. I analysed these temporary files in a Hex Editor and found out that all newlines ( ) were replaced by a carriage return and a newline ( ). As we use Windows line-breaks ( ) in our files, this resulted in , which is considered as two newlines by Checkstyle and several text editors. The strage thing is that the line-breaks are correct when checking out from our repository, so they are somehow converted back somewhere.

I could solve this problem by setting the property svn:eol-style (see http://svnbook.red-bean.com/en/1.1/ch07s02.html#svn-ch-7-sect-2.3.5) to native. Everything worked as it should then. Unfortunately, for us this would mean that we would have to add this property to every file in our repository. As far as I know, there is a setting in the SVN client that does this automatically whenever you add a new file, but unfortunately we cannot tell all our developers to add this setting to their SVN client.

The description of the eol-style property says "by default, Subversion doesn t pay any attention to the type of end-of-line (EOL) markers used in your files". To me, it looks like a bug in SVN that the newlines are converted nevertheless.

Does anyone have an idea how to fix this behaviour without using ugly workarounds such as manually converting the newlines back in the pre-commit hook?

Thanks for your help, memminger

最佳回答

My assumption that SVN created a temporary directory for pre-commit hooks was wrong. Instead, a pre-commit hook can access the source files using svnlook and a transaction number. SVNChecker is the one who saves these files in a temporary directory.

What causes the wrong line delimiters is a Python feature that automatically converts line-breaks so that all Python applications can use Unix line delimiters internally. However, only some functions convert line-breaks from external sources to Python-internal line-breaks by default. SVNChecker does not take care of this, which has already been reported as a bug on http://svnchecker.tigris.org/issues/show_bug.cgi?id=33.

问题回答

暂无回答




相关问题
Best practices for Subversion and Visual Studio projects

I ve recently started working on various C# projects in Visual Studio as part of a plan for a large scale system that will be used to replace our current system that s built from a cobbling-together ...

Changing username in SVN+SSH URI on the fly in working copy

I am using SVN+SSH to check out a working copy of repository from an SVN server on which all developers are members of a developer group and have full read/write permissions on the repository ...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

How to search for file in subversion server?

Is there a way to search for a file in a subversion repository? Something similar to Unix find command, with which I can find the location of a file in a repository. I know there is svn list, but ...

热门标签