Stoppt die Vorratsdatenspeicherung! Jetzt klicken &handeln! Willst du auch an der Aktion teilnehmen? Hier findest du alle relevanten Infos und Materialien:

Mittwoch, März 07, 2007

How to get an atom feed from svn logs

Now a small but cool thing. How to get an Atom feed out of a svn commit log? That's pretty easy because svn may output logfiles as XML and because Atom is valid XML too we may use a simple XSLT script to do the job

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<xsl:stylesheet version="1.0" xmlns:xsl="">

<xsl:output method="xml" encoding="utf-8" indent="yes" />
<xsl:template match="text()|@*" />

<xsl:template match="log">
<feed xmlns="">

<title>KDEmod SVN Commit log</title>
<link href=""/>
<link rel="self" href=""/>
<updated><xsl:value-of select="logentry/date" /></updated>
<name>KDEmod Team</name>

<xsl:apply-templates />

<xsl:template match="logentry">
<entry xmlns="">
<id>Revision: <xsl:value-of select="@revision" /></id>
<title type="text">
SVN Commit from <xsl:value-of select="author" />
(<xsl:value-of select="count(paths/path)" /> files affected)
<published><xsl:value-of select="date" /></published>
<name><xsl:value-of select="author" /></name>
<content type="xhtml">
<div xmlns="">
<h1>SVN Commit from <xsl:value-of select="author" /></h1>
<xsl:apply-templates />
<link rel="alternate" href="" />

<xsl:template match="paths">
<p xmlns=""><h2>Files:</h2>
<xsl:apply-templates />

<xsl:template match="path">
<li xmlns="">
<xsl:if test="@action = 'M'">(modified) </xsl:if>
<xsl:if test="@action = 'A'">(added) </xsl:if>
<xsl:if test="@action = 'D'">(deleted) </xsl:if>
<xsl:attribute name="href"><xsl:value-of select="." /></xsl:attribute>
<xsl:value-of select="." />

<xsl:template match="msg">
<p xmlns=""><h2>Message:</h2>
<xsl:value-of select="." />


It's output not very pretty but it does it's work (you may change it as you want, just be sure to write valid XML). Call it as cron job like that:

svn log -v --xml | sabcmd svn2atom.xsl >svn.xml

I am using the sablotron xslt processor here but every other one should do as well. (for example on my server I use xsltproc)

Eingestellt von dunkelstern

Labels: , , , ,
Neuerer Post Älterer Post Startseite