<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SukmoonLee Blog &#187; post-commit</title>
	<atom:link href="http://blog.sukmoonlee.com/wordpress/archives/tag/post-commit/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.sukmoonlee.com/wordpress</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Thu, 20 Sep 2012 00:01:14 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>SVN Hook (HTML &amp; Syntax Highlight)</title>
		<link>http://blog.sukmoonlee.com/wordpress/archives/7</link>
		<comments>http://blog.sukmoonlee.com/wordpress/archives/7#comments</comments>
		<pubDate>Tue, 03 Apr 2012 11:59:09 +0000</pubDate>
		<dc:creator>Sukmoon Lee</dc:creator>
				<category><![CDATA[Program]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[post-commit]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://blog.sukmoonlee.com/wordpress/?p=7</guid>
		<description><![CDATA[SVN을 사용하면 hook script를 이용해서 다양한 기능을 할수 있다. 특히 commit을 하고 나면 해당 내용을 같은 팀원들이 공유를 하고, 서로 코드를 리뷰를 해주면 더욱 좋다. SVN에 기본적으로 포함되어 있는 post-commit 스크립트와 mailer.py를 사용하면 보내면 text/plain 형태로 전달이 되기 때문에 가독성이 떨어진다. 이것을 text/html로 보내면서 문법까지 쉽게 확인하면 좋을것 같다는 생각을 가지고 소스를 약간 수정했다. 일단 <a href='http://blog.sukmoonlee.com/wordpress/archives/7' class='excerpt-more'>[...]</a>]]></description>
				<content:encoded><![CDATA[<p>SVN을 사용하면 hook script를 이용해서 다양한 기능을 할수 있다.<br />
특히 commit을 하고 나면 해당 내용을 같은 팀원들이 공유를 하고, 서로 코드를 리뷰를 해주면 더욱 좋다.</p>
<p>SVN에 기본적으로 포함되어 있는 post-commit 스크립트와 mailer.py를 사용하면 보내면 text/plain 형태로 전달이 되기 때문에 가독성이 떨어진다. 이것을 text/html로 보내면서 문법까지 쉽게 확인하면 좋을것 같다는 생각을 가지고 소스를 약간 수정했다.</p>
<p>일단 아래와 같이 post-commit.tmpl 파일을 복사해서 아래와 같이 만든다.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="diff" style="font-family:monospace;">$ diff post-commit.tmpl post-commit
<span style="color: #440088;">50c50</span>
&amp;lt; mailer.py commit &quot;$REPOS&quot; &quot;$REV&quot; /path/to/mailer.conf
<span style="color: #888822;">---
&amp;gt; /home/svn/mailer.py commit &quot;$REPOS&quot; $REV /home/svn/mailer.conf</span></pre></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>smlee<span style="color: #000000; font-weight: bold;">@</span>nams2 mailer<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ rpm <span style="color: #660033;">-ql</span> subversion <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> mailer
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>subversion-1.6.11<span style="color: #000000; font-weight: bold;">/</span>tools<span style="color: #000000; font-weight: bold;">/</span>hook-scripts<span style="color: #000000; font-weight: bold;">/</span>mailer
<span style="color: #000000; font-weight: bold;">&lt;</span>strong<span style="color: #000000; font-weight: bold;">&gt;/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>subversion-1.6.11<span style="color: #000000; font-weight: bold;">/</span>tools<span style="color: #000000; font-weight: bold;">/</span>hook-scripts<span style="color: #000000; font-weight: bold;">/</span>mailer<span style="color: #000000; font-weight: bold;">/</span>mailer.conf.example <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>subversion-1.6.11<span style="color: #000000; font-weight: bold;">/</span>tools<span style="color: #000000; font-weight: bold;">/</span>hook-scripts<span style="color: #000000; font-weight: bold;">/</span>mailer<span style="color: #000000; font-weight: bold;">/</span>mailer.py<span style="color: #000000; font-weight: bold;">&lt;/</span>strong<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>subversion-1.6.11<span style="color: #000000; font-weight: bold;">/</span>tools<span style="color: #000000; font-weight: bold;">/</span>hook-scripts<span style="color: #000000; font-weight: bold;">/</span>mailer<span style="color: #000000; font-weight: bold;">/</span>tests
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>subversion-1.6.11<span style="color: #000000; font-weight: bold;">/</span>tools<span style="color: #000000; font-weight: bold;">/</span>hook-scripts<span style="color: #000000; font-weight: bold;">/</span>mailer<span style="color: #000000; font-weight: bold;">/</span>tests<span style="color: #000000; font-weight: bold;">/</span>mailer-init.sh
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>subversion-1.6.11<span style="color: #000000; font-weight: bold;">/</span>tools<span style="color: #000000; font-weight: bold;">/</span>hook-scripts<span style="color: #000000; font-weight: bold;">/</span>mailer<span style="color: #000000; font-weight: bold;">/</span>tests<span style="color: #000000; font-weight: bold;">/</span>mailer-t1.output
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>subversion-1.6.11<span style="color: #000000; font-weight: bold;">/</span>tools<span style="color: #000000; font-weight: bold;">/</span>hook-scripts<span style="color: #000000; font-weight: bold;">/</span>mailer<span style="color: #000000; font-weight: bold;">/</span>tests<span style="color: #000000; font-weight: bold;">/</span>mailer-t1.sh
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>subversion-1.6.11<span style="color: #000000; font-weight: bold;">/</span>tools<span style="color: #000000; font-weight: bold;">/</span>hook-scripts<span style="color: #000000; font-weight: bold;">/</span>mailer<span style="color: #000000; font-weight: bold;">/</span>tests<span style="color: #000000; font-weight: bold;">/</span>mailer-tweak.py
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>subversion-1.6.11<span style="color: #000000; font-weight: bold;">/</span>tools<span style="color: #000000; font-weight: bold;">/</span>hook-scripts<span style="color: #000000; font-weight: bold;">/</span>mailer<span style="color: #000000; font-weight: bold;">/</span>tests<span style="color: #000000; font-weight: bold;">/</span>mailer.conf</pre></td></tr></table></div>

<p>해당 파일은 적당한 디렉토리(/home/svn) 에 복사해서 만들면 된다.<br />
대부분 mailer.conf를 자신이 사용하는 메일서버(구글서버로 설정하면 편리합니다.)와 수신자와 발신자를 설정하면 된다.(대부분 commit을 한 author를 중심으로 설정하면 된다.)</p>
<p>여기서 제가 추가적으로 수정한 부분은 다음과 같습니다. 기존에 OS에서 가지고 있는 diff를 사용을 하면 text형태로만 제공이 됩니다.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="diff" style="font-family:monospace;"><span style="color: #440088;">144c144,145</span>
&amp;lt; diff = /usr/bin/diff -u -L %<span style="">&#40;</span>label_from<span style="">&#41;</span>s -L %<span style="">&#40;</span>label_to<span style="">&#41;</span>s %<span style="">&#40;</span>from<span style="">&#41;</span>s %<span style="">&#40;</span>to<span style="">&#41;</span>s --- &amp;gt; #diff = /usr/bin/diff -u -L %<span style="">&#40;</span>label_from<span style="">&#41;</span>s -L %<span style="">&#40;</span>label_to<span style="">&#41;</span>s %<span style="">&#40;</span>from<span style="">&#41;</span>s %<span style="">&#40;</span>to<span style="">&#41;</span>s
&amp;gt; diff = /home/svn/diff.sh %<span style="">&#40;</span>label_from<span style="">&#41;</span>s %<span style="">&#40;</span>label_to<span style="">&#41;</span>s %<span style="">&#40;</span>from<span style="">&#41;</span>s %<span style="">&#40;</span>to<span style="">&#41;</span>s</pre></td></tr></table></div>

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

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cat diff.sh</span>
<span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #007800;">TMP</span>=<span style="color: #ff0000;">&quot;$4.diff&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">diff</span> <span style="color: #660033;">-u</span> <span style="color: #660033;">-L</span> <span style="color: #ff0000;">'$1'</span> <span style="color: #660033;">-L</span> <span style="color: #ff0000;">'$2'</span> <span style="color: #007800;">$3</span> <span style="color: #007800;">$4</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$TMP</span>
php <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>svn_geshi.php <span style="color: #007800;">$TMP</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #ff0000;">&quot;$2&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$TMP</span></pre></td></tr></table></div>

<p>보는 것과 같이 기존의 diff 결과를 파일로 저장하고, 저장된 파일을 geshi에 들어있는 샘플 파일을 이용해서 출력을 하면 된다.<br />
이렇게 하면 mailer.py 에서 해당 결과를 읽어서 메일로 전달하게 되는 구조이다.</p>
<p>다만 기존의 mailer.py는 text/plain 형태의 메일을 보내는 것을 text/html로 변경하고, 출력되는 문구에 HTML이 가능하도록 수정하면 된다. 나는 geshi에 있는 샘플 파일의 HTML 형식을 사용했다.</p>
<p>소스는 지금도 수정중이고, mailer.conf 파일의 활용법을 계속 연습중이라서 나중에 공개하도록 하겠다.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sukmoonlee.com/wordpress/archives/7/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
