# HG changeset patch # User Bernhard Herzog # Date 1249380552 0 # Node ID f58f9adb7dc314bf7c5f8aeccd9922c828c70330 # Parent 2b9d94f0ccad04fedb88c47fb4a1b2efc5f0572f Add functions to get SVN logs and extract tag revisions from it. Add some tests for the log parsing. diff -r 2b9d94f0ccad -r f58f9adb7dc3 test/test_subversion.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test_subversion.py Tue Aug 04 10:09:12 2009 +0000 @@ -0,0 +1,199 @@ +# Copyright (C) 2008, 2009 by Intevation GmbH +# Authors: +# Bernhard Herzog +# +# This program is free software under the GPL (>=v2) +# Read the file COPYING coming with the software for details. + +"""Tests for the treepkg.subversion module""" + + +import unittest + +from treepkg.subversion import extract_tag_revisions + + +class TestTagDetector(unittest.TestCase): + + def test_tag_changes_count_one_copy_command(self): + xml = """\ + + + +tmcguire +2009-07-24T11:01:19.722901Z + +/branches/kdepim/enterprise/kdepim/kontact/src/main.cpp +/branches/kdepim/enterprise/kdepim/kmail/kmversion.h +/branches/kdepim/enterprise/kdepim/korganizer/version.h + +SVN_SILENT Update version numbers for today's release. + + +tmcguire +2009-07-24T11:02:47.403605Z + +/tags/kdepim/enterprise35.0.20090724.1001831/kdepim + +SVN_SILENT Tag kdepim. + + +winterz +2009-07-29T13:23:42.262028Z + +/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/libkcal/scheduler.cpp + +merge SVN commit 1004159 by winterz: + +Allow an attendee to decline an new invitation without getting the error +message that the event couldn't be found in their calendar. +kolab/issue3780 + + + + +winterz +2009-07-30T13:34:18.385413Z + +/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/kmail/newfolderdialog.cpp + +merge SVN commit 1004535 by tmcguire: + +Fix silly crash when creating a folder. + +kolab/issue3777 + + + +winterz +2009-07-30T15:25:19.331744Z + +/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/libkcal/incidenceformatter.cpp + +merge SVN commit 1004601 by winterz: + +possible fix for kolab/issue3724 and kolab/issue3780, whereby multiple +persons having write access to a folder can confuse things for other +users accessing that folder. + + + + +""" + # + + self.assertEquals(extract_tag_revisions(xml), + ["1001837", "1004164", "1004558", "1004604"]) + + + def test_tag_changes_count_two_copy_commands(self): + xml = """\ + + + +tmcguire +2009-07-24T11:01:19.722901Z + +/branches/kdepim/enterprise/kdepim/kontact/src/main.cpp +/branches/kdepim/enterprise/kdepim/kmail/kmversion.h +/branches/kdepim/enterprise/kdepim/korganizer/version.h + +SVN_SILENT Update version numbers for today's release. + + +tmcguire +2009-07-24T11:02:47.403605Z + +/tags/kdepim/enterprise35.0.20090724.1001831/kdepim + +SVN_SILENT Tag kdepim. + + +winterz +2009-07-29T13:23:42.262028Z + +/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/libkcal/scheduler.cpp + +merge SVN commit 1004159 by winterz: + +Allow an attendee to decline an new invitation without getting the error +message that the event couldn't be found in their calendar. +kolab/issue3780 + + + + +winterz +2009-07-30T13:34:18.385413Z + +/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/kmail/newfolderdialog.cpp + +merge SVN commit 1004535 by tmcguire: + +Fix silly crash when creating a folder. + +kolab/issue3777 + + + +winterz +2009-07-30T15:25:19.331744Z + +/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/libkcal/incidenceformatter.cpp + +merge SVN commit 1004601 by winterz: + +possible fix for kolab/issue3724 and kolab/issue3780, whereby multiple +persons having write access to a folder can confuse things for other +users accessing that folder. + + + + +somebody +2009-07-24T12:02:47.403605Z + +/tags/kdepim/enterprise35.0.20090724.1001831/kdepim + +ficticious commit that looks like the earlier copy that created the tag. + + + +""" + # + + self.assertEquals(extract_tag_revisions(xml), + ["901837", "1004164", "1004558", "1004604", + "1005000"]) diff -r 2b9d94f0ccad -r f58f9adb7dc3 treepkg/subversion.py --- a/treepkg/subversion.py Tue Aug 04 10:01:56 2009 +0000 +++ b/treepkg/subversion.py Tue Aug 04 10:09:12 2009 +0000 @@ -10,6 +10,9 @@ import os import shutil import re +import StringIO + +from lxml import etree import run from cmdexpand import cmdexpand @@ -70,6 +73,29 @@ % svn_working_copy) return int(str_rev) +def log_xml(url, base_revision): + """Return the log in XML of the repository at url from base_revision to HEAD + """ + args = ["--revision", str(base_revision) + ":HEAD", + "--verbose", + "--xml"] + return run.capture_output(cmdexpand("svn log @args $url", **locals())) + + +def extract_tag_revisions(xml_log): + """Extracts the revisions which changed an SVN tag since its creation + This includes the revision which created the tag and all subsequent + changes. The xml_log parameter should contain the xml-Version of + the SVN log of the tag that includes at least the revision that + created the tag and all the newer revisions. + """ + tree = etree.parse(StringIO.StringIO(xml_log)) + tag_revisions = tree.xpath("logentry/@revision" + "[.>=../../logentry/@revision" + "[../paths/path[@copyfrom-path]]]") + return tag_revisions + + class SvnRepository(object):