changeset 282:f58f9adb7dc3

Add functions to get SVN logs and extract tag revisions from it. Add some tests for the log parsing.
author Bernhard Herzog <bh@intevation.de>
date Tue, 04 Aug 2009 10:09:12 +0000
parents 2b9d94f0ccad
children cd10b835d9b8
files test/test_subversion.py treepkg/subversion.py
diffstat 2 files changed, 225 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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 <bh@intevation.de>
+#
+# 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 = """\
+<?xml version="1.0"?>
+<log>
+<logentry
+   revision="1001832">
+<author>tmcguire</author>
+<date>2009-07-24T11:01:19.722901Z</date>
+<paths>
+<path
+   action="M">/branches/kdepim/enterprise/kdepim/kontact/src/main.cpp</path>
+<path
+   action="M">/branches/kdepim/enterprise/kdepim/kmail/kmversion.h</path>
+<path
+   action="M">/branches/kdepim/enterprise/kdepim/korganizer/version.h</path>
+</paths>
+<msg>SVN_SILENT Update version numbers for today's release.</msg>
+</logentry>
+<logentry
+   revision="1001837">
+<author>tmcguire</author>
+<date>2009-07-24T11:02:47.403605Z</date>
+<paths>
+<path
+   copyfrom-path="/branches/kdepim/enterprise/kdepim"
+   copyfrom-rev="1001836"
+   action="A">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim</path>
+</paths>
+<msg>SVN_SILENT Tag kdepim.</msg>
+</logentry>
+<logentry
+   revision="1004164">
+<author>winterz</author>
+<date>2009-07-29T13:23:42.262028Z</date>
+<paths>
+<path
+   action="M">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/libkcal/scheduler.cpp</path>
+</paths>
+<msg>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
+
+</msg>
+</logentry>
+<logentry
+   revision="1004558">
+<author>winterz</author>
+<date>2009-07-30T13:34:18.385413Z</date>
+<paths>
+<path
+   action="M">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/kmail/newfolderdialog.cpp</path>
+</paths>
+<msg>merge SVN commit 1004535 by tmcguire:
+
+Fix silly crash when creating a folder.
+
+kolab/issue3777
+</msg>
+</logentry>
+<logentry
+   revision="1004604">
+<author>winterz</author>
+<date>2009-07-30T15:25:19.331744Z</date>
+<paths>
+<path
+   action="M">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/libkcal/incidenceformatter.cpp</path>
+</paths>
+<msg>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.
+
+</msg>
+</logentry>
+</log>
+"""
+        #
+
+        self.assertEquals(extract_tag_revisions(xml),
+                          ["1001837", "1004164", "1004558", "1004604"])
+
+
+    def test_tag_changes_count_two_copy_commands(self):
+        xml = """\
+<?xml version="1.0"?>
+<log>
+<logentry
+   revision="901832">
+<author>tmcguire</author>
+<date>2009-07-24T11:01:19.722901Z</date>
+<paths>
+<path
+   action="M">/branches/kdepim/enterprise/kdepim/kontact/src/main.cpp</path>
+<path
+   action="M">/branches/kdepim/enterprise/kdepim/kmail/kmversion.h</path>
+<path
+   action="M">/branches/kdepim/enterprise/kdepim/korganizer/version.h</path>
+</paths>
+<msg>SVN_SILENT Update version numbers for today's release.</msg>
+</logentry>
+<logentry
+   revision="901837">
+<author>tmcguire</author>
+<date>2009-07-24T11:02:47.403605Z</date>
+<paths>
+<path
+   copyfrom-path="/branches/kdepim/enterprise/kdepim"
+   copyfrom-rev="1001836"
+   action="A">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim</path>
+</paths>
+<msg>SVN_SILENT Tag kdepim.</msg>
+</logentry>
+<logentry
+   revision="1004164">
+<author>winterz</author>
+<date>2009-07-29T13:23:42.262028Z</date>
+<paths>
+<path
+   action="M">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/libkcal/scheduler.cpp</path>
+</paths>
+<msg>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
+
+</msg>
+</logentry>
+<logentry
+   revision="1004558">
+<author>winterz</author>
+<date>2009-07-30T13:34:18.385413Z</date>
+<paths>
+<path
+   action="M">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/kmail/newfolderdialog.cpp</path>
+</paths>
+<msg>merge SVN commit 1004535 by tmcguire:
+
+Fix silly crash when creating a folder.
+
+kolab/issue3777
+</msg>
+</logentry>
+<logentry
+   revision="1004604">
+<author>winterz</author>
+<date>2009-07-30T15:25:19.331744Z</date>
+<paths>
+<path
+   action="M">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim/libkcal/incidenceformatter.cpp</path>
+</paths>
+<msg>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.
+
+</msg>
+</logentry>
+<logentry
+   revision="1005000">
+<author>somebody</author>
+<date>2009-07-24T12:02:47.403605Z</date>
+<paths>
+<path
+   copyfrom-path="/branches/kdepim/enterprise/kdepim"
+   copyfrom-rev="1001836"
+   action="A">/tags/kdepim/enterprise35.0.20090724.1001831/kdepim</path>
+</paths>
+<msg>ficticious commit that looks like the earlier copy that created the tag.
+</msg>
+</logentry>
+</log>
+"""
+        #
+
+        self.assertEquals(extract_tag_revisions(xml),
+                          ["901837", "1004164", "1004558", "1004604",
+                           "1005000"])
--- 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):
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)