生成svn changelog脚本

出于简化生成Release Note的需要。
在网上找来一个svn2cl.xsl 略为修改一下。改名为autobild_svn2cl.xsl, 上传到/usr/local/apache/htdocs/abdev/下。
虽然格式还是不尽人意,勉强用着先。

做了一个输出svn log的脚本。脚本位于249 的/usr/local/apache/htdocs/abdev/下。
svnlog2changelog.sh
然后chomd 777 svnlog2changelog.sh
使用方法
./svnlog2changelog.sh {2008-12-01}:{2008-12-04}

{2008-12-01}:{2008-12-04} 为起始日期


svnlog2changelog.sh 内容:


 

  1. #!/bin/bash
  2. cd /usr/local/apache/htdocs/abdev/
  3. export LC_ALL=zh_CN.GBK
  4. export LANG=zh_CN.GBK
  5. svn log -v --xml -r $1 > changelog.xml
  6. xsltproc -o changeLog.txt autobild_svn2cl.xsl changelog.xml
  7. export LC_ALL=en_US
  8. export LANG=en_US

autobild_svn2cl.xsl 内容:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3.    svn2cl.xsl - xslt stylesheet for converting svn log to a normal
  4.                 changelog
  5.    version 0.10
  6.    Usage (replace ++ with two minus signs which aren't allowed
  7.    inside xml comments):
  8.      svn ++verbose ++xml log | /
  9.        xsltproc ++stringparam strip-prefix `basename $(pwd)` /
  10.                 ++stringparam linelen 75 /
  11.                 ++stringparam groupbyday yes /
  12.                 ++stringparam separate-daylogs yes /
  13.                 ++stringparam include-rev yes /
  14.                 ++stringparam include-actions yes /
  15.                 ++stringparam breakbeforemsg yes/2 /
  16.                 ++stringparam reparagraph yes /
  17.                 ++stringparam authorsfile FILE /
  18.                 ++stringparam ignore-message-starting /
  19.                 svn2cl.xsl - > ChangeLog
  20.    This file is based on several implementations of this conversion
  21.    that I was not completely happy with and some other common
  22.    xslt constructs found on the web.
  23.    Copyright (C) 2004, 2005, 2006, 2007 Arthur de Jong.
  24.    Redistribution and use in source and binary forms, with or without
  25.    modification, are permitted provided that the following conditions
  26.    are met:
  27.    1. Redistributions of source code must retain the above copyright
  28.       notice, this list of conditions and the following disclaimer.
  29.    2. Redistributions in binary form must reproduce the above copyright
  30.       notice, this list of conditions and the following disclaimer in
  31.       the documentation and/or other materials provided with the
  32.       distribution.
  33.    3. The name of the author may not be used to endorse or promote
  34.       products derived from this software without specific prior
  35.       written permission.
  36.    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  37.    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  38.    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  39.    ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  40.    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  41.    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  42.    GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  43.    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  44.    IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  45.    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  46.    IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47. -->
  48. <!DOCTYPE xsl:stylesheet [
  49.  <!ENTITY tab " ">
  50.  <!ENTITY newl "&#xA;">
  51.  <!ENTITY space " ">
  52. ]>
  53. <xsl:stylesheet
  54.   version="1.0"
  55.   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  56.  <xsl:output
  57.    method="text"
  58.    encoding="utf-8"
  59.    media-type="text/plain"
  60.    omit-xml-declaration="yes"
  61.    standalone="yes"
  62.    indent="no" />
  63.  <xsl:strip-space elements="*" />
  64.  <!-- the prefix of pathnames to strip -->
  65.  <xsl:param name="strip-prefix" select="''" />
  66.  <!-- the length of a line to wrap messages at -->
  67.  <xsl:param name="linelen" select="90" />
  68.  <!-- whether entries should be grouped by day -->
  69.  <xsl:param name="groupbyday" select="'no'" />
  70.  <!-- whether to seperate log messages by empty lines -->
  71.  <xsl:param name="separate-daylogs" select="'no'" />
  72.  <!-- whether a revision number should be included -->
  73.  <xsl:param name="include-rev" select="'no'" />
  74.  <!-- whether aaction labels should be added to files -->
  75.  <xsl:param name="include-actions" select="'no'" />
  76.  <!-- whether the log message should start on a new line -->
  77.  <xsl:param name="breakbeforemsg" select="'yes'" />
  78.  <!-- whether the message should be rewrapped within one paragraph -->
  79.  <xsl:param name="reparagraph" select="'no'" />
  80.  <!-- whether certain messages should be ignored -->
  81.  <xsl:param name="ignore-message-starting" select="''" />
  82.  <!-- location of authors file if any -->
  83.  <xsl:param name="authorsfile" select="''" />
  84.  <xsl:key name="author-lookup" match="author" use="@uid" />
  85.  <xsl:variable name="authors-top" select="document($authorsfile)/authors" />
  86.  <!-- match the topmost log entry -->
  87.  <xsl:template match="log">
  88.   <xsl:for-each select="logentry">
  89.   <xsl:sort select="author" />
  90.     <!-- add newline -->
  91.     <xsl:if test="not(position()=1)">
  92.      <xsl:text>&newl;</xsl:text>
  93.     </xsl:if>
  94.     <!-- author's name -->
  95.     <xsl:apply-templates select="author" />
  96.     <!-- two spaces -->
  97.     <xsl:text>&space;&space;</xsl:text>
  98.     <!-- date -->
  99.     <xsl:apply-templates select="date" />
  100.     <!-- two newlines -->
  101.     <xsl:text>&newl;</xsl:text>
  102.    
  103.     <!-- get paths string -->
  104.   <xsl:variable name="paths">
  105.    <xsl:apply-templates select="paths" />
  106.   </xsl:variable>
  107.   <!-- get revision number -->
  108.   <xsl:variable name="rev">
  109.    <xsl:if test="$include-rev='yes'">
  110.     <xsl:text>[r</xsl:text>
  111.     <xsl:value-of select="@revision" />
  112.     <xsl:text>]&space;</xsl:text>
  113.    </xsl:if>
  114.   </xsl:variable>
  115.   <!-- trim trailing newlines -->
  116.   <xsl:variable name="msg">
  117.    <!-- add a line break before the log message -->
  118.    <xsl:choose>
  119.     <xsl:when test="$breakbeforemsg='yes'">
  120.      <xsl:text>&newl;</xsl:text>
  121.     </xsl:when>
  122.     <xsl:when test="number($breakbeforemsg)>0">
  123.      <xsl:call-template name="newlines">
  124.       <xsl:with-param name="count" select="number($breakbeforemsg)" />
  125.      </xsl:call-template>
  126.     </xsl:when>
  127.    </xsl:choose>
  128.    <xsl:call-template name="trim-newln">
  129.     <xsl:with-param name="txt" select="msg" />
  130.    </xsl:call-template>
  131.   </xsl:variable>
  132.   <!-- add newline here if separate-daylogs is in effect -->
  133.   <xsl:if test="$groupbyday='yes' and $separate-daylogs='yes'"><xsl:text>&newl;</xsl:text></xsl:if>
  134.   <!-- set up the text to wrap -->
  135.   <xsl:variable name="txt">
  136.    <xsl:value-of select="$rev" />
  137.    <xsl:value-of select="$msg" />
  138.    <xsl:text>&newl;</xsl:text>
  139.    <xsl:if test="$paths!=''">
  140.     <xsl:value-of select="concat($paths,'&space;')" />
  141.    </xsl:if>
  142.   </xsl:variable>
  143.   <!-- print the paths and message nicely wrapped -->
  144.   <xsl:call-template name="wrap">
  145.    <xsl:with-param name="txt" select="$txt" />
  146.   </xsl:call-template>
  147.    <!-- add newlines at the end of the changelog -->
  148.    <xsl:text>&newl;</xsl:text>
  149.    
  150.   </xsl:for-each>
  151.   <!-- add newlines at the end of the changelog -->
  152.   <xsl:text>&newl;</xsl:text>
  153.  </xsl:template>
  154.   <!-- format date -->
  155.  <xsl:template match="date">
  156.   <xsl:variable name="date" select="normalize-space(.)" />
  157.   <!-- output date part -->
  158.   <xsl:value-of select="substring($date,1,10)" />
  159.   <!-- output time part -->
  160.   <xsl:if test="$groupbyday!='yes'">
  161.    <xsl:text>&space;</xsl:text>
  162.    <xsl:value-of select="substring($date,12,5)" />
  163.   </xsl:if>
  164.  </xsl:template>
  165.  <!-- format author -->
  166.  <xsl:template match="author">
  167.   <xsl:variable name="uid" select="normalize-space(.)" />
  168.   <!-- try to lookup author in authorsfile -->
  169.   <xsl:choose>
  170.    <xsl:when test="$authorsfile!=''">
  171.     <xsl:for-each select="$authors-top">
  172.      <xsl:variable name="author" select="key('author-lookup',$uid)" />
  173.      <!-- present result -->
  174.      <xsl:choose>
  175.       <xsl:when test="string($author/.)">
  176.        <xsl:apply-templates select="$author/node()" mode="copy" />
  177.       </xsl:when>
  178.       <xsl:otherwise>
  179.        <xsl:value-of select="$uid" />
  180.       </xsl:otherwise>
  181.      </xsl:choose>
  182.     </xsl:for-each>
  183.    </xsl:when>
  184.    <xsl:otherwise>
  185.     <xsl:value-of select="$uid" />
  186.    </xsl:otherwise>
  187.   </xsl:choose>
  188.  </xsl:template>
  189.  <!-- copy but normalize text -->
  190.  <xsl:template match="text()" mode="copy">
  191.   <xsl:value-of select="normalize-space(.)" />
  192.  </xsl:template>
  193.  <!-- simple copy template -->
  194.  <xsl:template match="@*|node()" mode="copy">
  195.   <xsl:copy>
  196.    <xsl:apply-templates select="@*|node()" mode="copy" />
  197.   </xsl:copy>
  198.  </xsl:template>
  199.  <!-- present a list of paths names -->
  200.  <xsl:template match="paths">
  201.   <xsl:choose>
  202.    <!-- only handle paths that begin with the path and strip the path -->
  203.    <xsl:when test="$strip-prefix != ''">
  204.     <!-- if strip-prefix does not start with a slash, prepend it -->
  205.     <xsl:variable name="tmpstrip1">
  206.      <xsl:choose>
  207.       <xsl:when test="starts-with($strip-prefix,'/')">
  208.        <xsl:value-of select="$strip-prefix" />
  209.       </xsl:when>
  210.       <xsl:otherwise>
  211.        <xsl:value-of select="concat('/',$strip-prefix)" />
  212.       </xsl:otherwise>
  213.      </xsl:choose>
  214.     </xsl:variable>
  215.     <!-- strip trailing slash from strip-prefix -->
  216.     <xsl:variable name="tmpstrip2">
  217.      <xsl:choose>
  218.       <xsl:when test="substring($tmpstrip1,string-length($tmpstrip1),1)='/'">
  219.        <xsl:value-of select="substring($tmpstrip1,1,string-length($tmpstrip1)-1)" />
  220.       </xsl:when>
  221.       <xsl:otherwise>
  222.        <xsl:value-of select="$tmpstrip1" />
  223.       </xsl:otherwise>
  224.      </xsl:choose>
  225.     </xsl:variable>
  226.     <!-- filter on all entries within directory -->
  227.     <xsl:for-each select="path[starts-with(concat(normalize-space(.),'/'),concat($tmpstrip2,'/'))]">
  228.      <xsl:sort select="normalize-space(.)" data-type="text" />
  229.      <!-- unless we are the first entry, add a comma -->
  230.      <xsl:if test="not(position()=1)">
  231.       <xsl:text>,&space;</xsl:text>
  232.      </xsl:if>
  233.      <!-- print the path name -->
  234.      <xsl:call-template name="printpath">
  235.       <xsl:with-param name="path" select="substring(normalize-space(.),string-length($strip-prefix)+3)" />
  236.      </xsl:call-template>
  237.      <!-- add the action flag -->
  238.      <xsl:if test="$include-actions='yes'">
  239.       <xsl:apply-templates select="." mode="action"/>
  240.      </xsl:if>
  241.     </xsl:for-each>
  242.    </xsl:when>
  243.    <!-- print a simple list of all paths -->
  244.    <xsl:otherwise>
  245.     <xsl:for-each select="path">
  246.      <xsl:sort select="normalize-space(.)" data-type="text" />
  247.      <!-- unless we are the first entry, add a comma -->
  248.      <xsl:if test="not(position()=1)">
  249.       <xsl:text>&space;</xsl:text>
  250.      </xsl:if>
  251.      <!-- print the path name -->
  252.      <xsl:value-of select="normalize-space(.)" />
  253.      <!-- add the action flag -->
  254.      <xsl:if test="$include-actions='yes'">
  255.       <xsl:apply-templates select="." mode="action"/>
  256.      </xsl:if>
  257.     </xsl:for-each>
  258.    </xsl:otherwise>
  259.   </xsl:choose>
  260.  </xsl:template>
  261.  <xsl:template match="path" mode="action">
  262.   <xsl:choose>
  263.    <xsl:when test="@action='D'">
  264.     <xsl:text>[DEL]</xsl:text>
  265.    </xsl:when>
  266.    <xsl:when test="@copyfrom-path">
  267.     <xsl:text>[CPY]</xsl:text>
  268.    </xsl:when>
  269.    <xsl:when test="@action='D'">
  270.     <xsl:text>[ADD]</xsl:text>
  271.    </xsl:when>
  272.   </xsl:choose>
  273.  </xsl:template>
  274.  <!-- transform path to something printable -->
  275.  <xsl:template name="printpath">
  276.   <!-- fetch the pathname -->
  277.   <xsl:param name="path" />
  278.   <!-- strip leading slash -->
  279.   <xsl:variable name="tmp1">
  280.    <xsl:choose>
  281.     <xsl:when test="starts-with($path,'/')">
  282.      <xsl:value-of select="substring($path,2)" />
  283.     </xsl:when>
  284.     <xsl:otherwise>
  285.      <xsl:value-of select="$path" />
  286.     </xsl:otherwise>
  287.    </xsl:choose>
  288.   </xsl:variable>
  289.   <!-- translate empty string to dot -->
  290.   <xsl:choose>
  291.    <xsl:when test="$tmp1 = ''">
  292.     <xsl:text>.</xsl:text>
  293.    </xsl:when>
  294.    <xsl:otherwise>
  295.     <xsl:value-of select="$tmp1" />
  296.    </xsl:otherwise>
  297.   </xsl:choose>
  298.  </xsl:template>
  299.  <!-- string-wrapping template -->
  300.  <xsl:template name="wrap">
  301.   <xsl:param name="txt" />
  302.   <xsl:variable name="normtxt" select="normalize-space($txt)" />
  303.   <xsl:choose>
  304.    <xsl:when test="contains($txt,'&newl;')">
  305.      <!-- text contains newlines, do the first line -->
  306.      <xsl:call-template name="wrap">
  307.       <xsl:with-param name="txt" select="substring-before($txt,'&newl;')" />
  308.      </xsl:call-template>
  309.      <!-- print tab -->
  310.      <xsl:text>&tab;&space;&space;</xsl:text>
  311.      <!-- wrap the rest of the text -->
  312.      <xsl:call-template name="wrap">
  313.       <xsl:with-param name="txt" select="substring-after($txt,'&newl;')" />
  314.      </xsl:call-template>
  315.    </xsl:when>
  316.    <xsl:when test="(string-length($normtxt) < (($linelen)-9)) or not(contains($normtxt,' '))">
  317.     <!-- this is easy, nothing to do -->
  318.     <xsl:value-of select="$normtxt" />
  319.     <!-- add newline -->
  320.     <xsl:text>&newl;</xsl:text>
  321.    </xsl:when>
  322.    <xsl:otherwise>
  323.     <!-- find the first line -->
  324.     <xsl:variable name="tmp" select="substring($normtxt,1,(($linelen)-9))" />
  325.     <xsl:variable name="line">
  326.      <xsl:choose>
  327.       <!-- if our attempt contains spaces wrap on that -->
  328.       <xsl:when test="contains($tmp,' ')">
  329.        <xsl:call-template name="find-line">
  330.         <xsl:with-param name="txt" select="$tmp" />
  331.        </xsl:call-template>
  332.       </xsl:when>
  333.       <!-- otherwise use the first non-space characters from the text -->
  334.       <xsl:otherwise>
  335.        <xsl:value-of select="substring-before($normtxt,' ')" />
  336.       </xsl:otherwise>
  337.      </xsl:choose>
  338.     </xsl:variable>
  339.     <!-- print line -->
  340.     <xsl:value-of select="$line" />
  341.     <!-- print newline and tab -->
  342.     <xsl:text>&newl;&tab;&space;&space;</xsl:text>
  343.     <!-- wrap the rest of the text -->
  344.     <xsl:call-template name="wrap">
  345.      <xsl:with-param name="txt" select="normalize-space(substring($normtxt,string-length($line)+1))" />
  346.     </xsl:call-template>
  347.    </xsl:otherwise>
  348.   </xsl:choose>
  349.  </xsl:template>
  350.  <!-- template to trim line to contain space as last char -->
  351.  <xsl:template name="find-line">
  352.   <xsl:param name="txt" />
  353.   <xsl:choose>
  354.    <xsl:when test="substring($txt,string-length($txt),1)=' '">
  355.     <xsl:value-of select="substring($txt,1,string-length($txt)-1)" />
  356.    </xsl:when>
  357.    <xsl:otherwise>
  358.     <xsl:call-template name="find-line">
  359.      <xsl:with-param name="txt" select="substring($txt,1,string-length($txt)-1)" />
  360.     </xsl:call-template>
  361.    </xsl:otherwise>
  362.   </xsl:choose>
  363.  </xsl:template>
  364.  <!-- template to trim trailing and starting newlines -->
  365.  <xsl:template name="trim-newln">
  366.   <xsl:param name="txt" />
  367.   <xsl:choose>
  368.    <!-- find starting newlines -->
  369.    <xsl:when test="substring($txt,1,1) = '&newl;'">
  370.     <xsl:call-template name="trim-newln">
  371.      <xsl:with-param name="txt" select="substring($txt,2)" />
  372.     </xsl:call-template>
  373.    </xsl:when>
  374.    <!-- find trailing newlines -->
  375.    <xsl:when test="substring($txt,string-length($txt),1) = '&newl;'">
  376.     <xsl:call-template name="trim-newln">
  377.      <xsl:with-param name="txt" select="substring($txt,1,string-length($txt)-1)" />
  378.     </xsl:call-template>
  379.    </xsl:when>
  380.    <!-- if the message has paragrapgs, find the first one -->
  381.    <xsl:when test="$reparagraph='yes' and contains($txt,'&newl;&newl;')">
  382.      <!-- remove newlines from first paragraph -->
  383.      <xsl:value-of select="normalize-space(substring-before($txt,'&newl;&newl;'))" />
  384.      <!-- paragraph separator -->
  385.      <xsl:text>&newl;&newl;</xsl:text>
  386.      <!-- do the rest of the text -->
  387.      <xsl:call-template name="trim-newln">
  388.       <xsl:with-param name="txt" select="substring-after($txt,'&newl;&newl;')" />
  389.      </xsl:call-template>
  390.    </xsl:when>
  391.    <!-- remove more single newlines -->
  392.    <xsl:when test="$reparagraph='yes'">
  393.     <xsl:value-of select="normalize-space($txt)" />
  394.    </xsl:when>
  395.    <!-- no newlines found, we're done -->
  396.    <xsl:otherwise>
  397.     <xsl:value-of select="$txt" />
  398.    </xsl:otherwise>
  399.   </xsl:choose>
  400.  </xsl:template>
  401.  <!-- insert a number of newlines -->
  402.  <xsl:template name="newlines">
  403.   <xsl:param name="count" />
  404.   <xsl:text>&newl;</xsl:text>
  405.   <xsl:if test="$count>1">
  406.    <xsl:call-template name="newlines">
  407.     <xsl:with-param name="count" select="($count)-1" />
  408.    </xsl:call-template>
  409.   </xsl:if>
  410.  </xsl:template>
  411. </xsl:stylesheet>


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值