IT한 것

다양한 환경에서 subversion을 이용한 개발 환경시 CRLF, LF, EOL 문제.

lovian 2011. 4. 15. 10:08
이미 많은 사람들이 알고 있는것 같지만, 난 이제 알았으니까 기록해본다. :)

내 환경이
subversion 서버는 linux
프로젝트 서버는 linux
프로젝트 클라이언트는 windows/linux

이어서. 클라이언트 작업중에 혼선이 많다.
사실 vim 같은 녀석으로 작업을하면 알아서 잘 변환하여 보여주므로 상관이 없다.

그런데 워낙에 unix 환경에서 놀다보니 AIX 같은 특이 시스템에서는 CRLF(dos)도 되어 있는,
파일을 올바르게 분석하지 못하는 경우가 많다.

그런 이유로 모든 소스 코드는 unix 타입으로 저장하기로 하였는데,
윈도우 개발에 큰 문제가 발생하였다.

빌드나 테스트에는 아무 지장이 없지만, 디버깅모드에 들어가면 LF(unix)로 되어 있는 소스는
현재 실행중인 소스코드의 라인을 올바르게 보여주지 못한다.

결국 CRLF 형식이 아니면, 윈도우에서는 죽을 만큼 괴로운 개발을 해야된다는 소리.

이 모든 불만을 해소하기 위해서 찾아낸 결과가

svn property이다.

현재 올라가 있는 파일에 대해서 속성을 거는 것으로,
svn:eol-style라는 녀석이 존재한다.
이 설정 값에 따라서 해당파일의 End Of Line 저장 형식을 선택할 수 있게된다.

native

This causes the file to contain the EOL markers that are native to the operating system on which Subversion was run. In other words, if a user on a Windows machine checks out a working copy that contains a file with an svn:eol-style property set to native, that file will contain CRLF EOL markers. A Unix user checking out a working copy which contains the same file will see LF EOL markers in his copy of the file.


Note that Subversion will actually store the file in the repository using normalized LF EOL markers regardless of the operating system. This is basically transparent to the user, though.


CRLF

This causes the file to contain CRLF sequences for EOL markers, regardless of the operating system in use.


LF

This causes the file to contain LF characters for EOL markers, regardless of the operating system in use.


CR

This causes the file to contain CR characters for EOL markers, regardless of the operating system in use. This line ending style is not very common. It was used on older Macintosh platforms (on which Subversion doesn't even run).



요 native가 핵심인 듯하다, subversion 클라이언트가 작동하는 시스템에 맞는 개행문자로 변환하여 가져온다는 소리로 들린다.

svn propset [FILE] 의 명령으로 각각의 파일 마다 적용해야 한다.
윈도우의 경우 (tortoise를 이용하다고 가정)탐색기를 이용하여 원하는 디렉터리 이하의 모든 h, c, cpp 파일을 검색하여 선택후,
등록정보 혹은 속성 메뉴로 들어가 subversion 탭에서 property 설정을 해주면 된다.

자, 이제 마무리,
이렇게 속성 설정하여 사용하는 중에 새로은 소스가 추가되면 또 이짓을 해야 할까?
그렇지 않다.

subversion 클라이언트의 설정에, 패턴을 적용하여 그에 맞는 파일이 추가되면 자동으로 속성을 정해주는 기능이 있다. 

linux

${HOME}/.subversion/config


windows
windows 7

notepad "%APPDATA%\Subversion\config"


이 파일에서 아래와 같이 설정 할 수 있다.

[miscellany]

### Set global-ignores to a set of whitespace-delimited globs

### which Subversion will ignore in its 'status' output, and

### while importing or adding files and directories.

# global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store

### Set log-encoding to the default encoding for log messages

# log-encoding = latin1

### Set use-commit-times to make checkout/update/switch/revert

### put last-committed timestamps on every file touched.

# use-commit-times = yes

### Set no-unlock to prevent 'svn commit' from automatically

### releasing locks on files.

# no-unlock = yes

### Set enable-auto-props to 'yes' to enable automatic properties

### for 'svn add' and 'svn import', it defaults to 'no'.

### Automatic properties are defined in the section 'auto-props'.

enable-auto-props = yes


### 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.

*.c = svn:eol-style=native

*.cpp = svn:eol-style=native

*.h = svn:eol-style=native

 

이렇게 수정하면,
해당 subversion 클라이언트에서는 파일을 신규로 추가할때마다, 해당 패턴에 일치하는 경우, 여기서 설정해준 property가 자동으로 같이 등록된다.