Apr 042012
 

UNIX 개발환경에서 파일 비교를 위해서 많이 사용하는 것 중에 diff 라는 명령어가 있습니다.

특히 해당 프로그램은 patch 명령어와 연동해서 사용하게 되면 버전 관리도 가능합니다.

소스 형상관리 소프트웨어(CVS, SVN)을 사용하지 않는 경우에는 diff가 상당히 유용할것입니다.

아래와 같은 명령어를 이용하면 사람이 가독하기 쉬운 형태의 diff 결과를 확인할 수 있다.

diff -Nur A B

최근 들어서는 형상관리 소프트웨어를 많이 사용하기 때문에 특정 디렉토리(.svn, CVS)를 제거하고 diff를 하는 경우가 있습니다.
이런 경우에는 아래와 같이 하면 편리합니다.

diff -Nur –exclude=”.svn” –exclude=”.gitignore” A B


참고로 위의 exclude 기능 관련해서 man 페이지에는 찾아보면 아래와 같다.

–exclude=pattern
디렉토리를 비교할 때, 파일과 하위 디렉토리의 basename이 pattern 과 일치하면무시한다.

–exclude-from=file
디 렉토리를 비교할 때, 파일과 하위 디렉토리의 basename이 file 에 있는 어떤 패턴과 일치하
면 무시한다.

Apr 032012
 

SVN을 사용하면 hook script를 이용해서 다양한 기능을 할수 있다.
특히 commit을 하고 나면 해당 내용을 같은 팀원들이 공유를 하고, 서로 코드를 리뷰를 해주면 더욱 좋다.

SVN에 기본적으로 포함되어 있는 post-commit 스크립트와 mailer.py를 사용하면 보내면 text/plain 형태로 전달이 되기 때문에 가독성이 떨어진다. 이것을 text/html로 보내면서 문법까지 쉽게 확인하면 좋을것 같다는 생각을 가지고 소스를 약간 수정했다.

일단 아래와 같이 post-commit.tmpl 파일을 복사해서 아래와 같이 만든다.

$ diff post-commit.tmpl post-commit
50c50
< mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf
---
> /home/svn/mailer.py commit "$REPOS" $REV /home/svn/mailer.conf

그리고 svn을 설치된 경로에 가보면 아래와 같이 mailer.py와 mailer.conf 파일이 있다.
(리눅스 CentOS 6의 경우에는 아래의 경로에 있다.)

[smlee@nams2 mailer]$ rpm -ql subversion |grep mailer
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer
<strong>/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/mailer.conf.example /usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/mailer.py</strong>
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer-init.sh
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer-t1.output
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer-t1.sh
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer-tweak.py
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer.conf

해당 파일은 적당한 디렉토리(/home/svn) 에 복사해서 만들면 된다.
대부분 mailer.conf를 자신이 사용하는 메일서버(구글서버로 설정하면 편리합니다.)와 수신자와 발신자를 설정하면 된다.(대부분 commit을 한 author를 중심으로 설정하면 된다.)

여기서 제가 추가적으로 수정한 부분은 다음과 같습니다. 기존에 OS에서 가지고 있는 diff를 사용을 하면 text형태로만 제공이 됩니다.

144c144,145
&lt; diff = /usr/bin/diff -u -L %(label_from)s -L %(label_to)s %(from)s %(to)s --- &gt; #diff = /usr/bin/diff -u -L %(label_from)s -L %(label_to)s %(from)s %(to)s
&gt; diff = /home/svn/diff.sh %(label_from)s %(label_to)s %(from)s %(to)s

syntax highlight를 사용하기 위해서 GeSHi 프로그램을 사용하기 위해서 간단한 shell을 하나 만들어서 php 프로그램을 실행하도록 했습니다.

# cat diff.sh
#!/bin/sh
 
TMP="$4.diff"
 
/usr/bin/diff -u -L '$1' -L '$2' $3 $4 &gt; $TMP
php /home/bin/svn_geshi.php $TMP "$1" "$2"
rm -f $TMP

보는 것과 같이 기존의 diff 결과를 파일로 저장하고, 저장된 파일을 geshi에 들어있는 샘플 파일을 이용해서 출력을 하면 된다.
이렇게 하면 mailer.py 에서 해당 결과를 읽어서 메일로 전달하게 되는 구조이다.

다만 기존의 mailer.py는 text/plain 형태의 메일을 보내는 것을 text/html로 변경하고, 출력되는 문구에 HTML이 가능하도록 수정하면 된다. 나는 geshi에 있는 샘플 파일의 HTML 형식을 사용했다.

소스는 지금도 수정중이고, mailer.conf 파일의 활용법을 계속 연습중이라서 나중에 공개하도록 하겠다.

 

 

Apr 032012
 

SVN서버를 사용할때 오래된 OS(redhat 7.3)에는 설치하기가 힘듭니다. OS가 maintaince 기간이 만료되었기 때문에 rpm 구하기가 힘듭니다.

yum 도 사용하기 힘들기 때문에 소스를 컴파일해서 설치해서 사용해야 합니다.

설치를 하다 보면 APR(Apache Portable Runtime) 패키지가 없어서 아래와 같이 컴파일 에러가 납니다.

[root@guide1 subversion-1.7.4]# ./configure
configure: Configuring Subversion 1.7.4
configure: creating config.nice
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C preprocessor... gcc -E
checking for a sed that does not truncate output... /bin/sed
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking whether ln -s works... yes
checking for a BSD-compatible install... /usr/bin/install -c
configure: Apache Portable Runtime (APR) library configuration
checking for APR... no
configure: WARNING: APR not found
The Apache Portable Runtime (APR) library cannot be found.
Please install APR on this system and supply the appropriate
--with-apr option to 'configure'

or

get it with SVN and put it in a subdirectory of this source:

svn co \
http://svn.apache.org/repos/asf/apr/apr/branches/1.3.x \
apr

Run that right here in the top level of the Subversion tree.
Afterwards, run apr/buildconf in that subdirectory and
then run configure again here.

Whichever of the above you do, you probably need to do
something similar for apr-util, either providing both
--with-apr and --with-apr-util to 'configure', or
getting both from SVN with:

svn co \
http://svn.apache.org/repos/asf/apr/apr-util/branches/1.3.x \
apr-util

configure: error: no suitable apr found
[root@guide1 subversion-1.7.4]#

이런 문제를 해결하기 위해서는 최신 버전이 아닌 1.3.x 버전을 사용하면 해결이 가능합니다.

아래의 경로에서 다운로드 가능합니다.

http://archive.apache.org/dist/subversion/subversion-1.3.2.tar.gz

[root@guide1 root]# cat /etc/redhat-release
Red Hat Linux release 7.3 (Valhalla)
[root@guide1 root]# svn --version
svn, version 1.3.2 (r19776)
compiled Apr 3 2012, 15:09:18

Copyright (C) 2000-2006 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following repository access (RA) modules are available:

* ra_dav : Module for accessing a repository via WebDAV (DeltaV) protocol.
- handles 'http' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
- handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
- handles 'file' scheme

참고사이트 : http://svn.haxx.se/users/archive-2006-06/0713.shtml

Plugin from the creators of Brindes :: More at Plulz Wordpress Plugins