[Buildbot-devel] SVN.parseGotRevision() patch

Aaron Maxwell amax at snaplogic.org
Tue Oct 30 20:27:58 UTC 2007


Hello,

I have a patch for SVN.parseGotRevision() in buildbot/slave/commands.py, in 
0.7.6.  It solved a specific problem we had; I'd like feedback as to whether 
it is generally useful, and if so, submit it.

What it does is change how the svn reversion number is calculated.  Here's the 
exact example that we first noticed.  One of our SVN repositories consists of 
a trunk and branches, including individual developer's working branches.  The 
other day, the most recent commit was made to one developer's branch, with a 
revision number of 602.  At the same time, the most recent trunk commit was 
numbered 598.  If you do a command like:

  svn co -r 602 svn+ssh://path/to/trunk/

what you'll get is a checkout of trunk at rev. 598.  If you run "svnversion ." 
there the response will be '602'; if you run "svnversion -c ." the response 
is '1:598'.

For our purposes, the number we need is 598, since it's the revision of the 
actual trunk commit.  This is what the patch does: basically 
runs "svnversion -c ." rather than "svnversion .", parsing the response 
appropriately.  Is this the right solution for others as well?

Perhaps some people will need the "svnversion ." behavior, and 
some "svnversion -c .".  If so, I could alter this so that it's configurable.

Thanks in advance.  Here's the patch as a separate file: 
http://redsymbol.net/buildbot/commands.py.patch

And here it is pasted:
{{{
--- buildbot/slave/commands.py.orig     2007-10-29 20:55:59.000000000 -0700
+++ buildbot/slave/commands.py  2007-10-29 21:03:40.000000000 -0700
@@ -1501,7 +1501,7 @@
         svnversion_command = getCommand("svnversion")
         # older versions of 'svnversion' (1.1.4) require the WC_PATH
         # argument, newer ones (1.3.1) do not.
-        command = [svnversion_command, "."]
+        command = [svnversion_command, "-c", "."]
         c = ShellCommand(self.builder, command,
                          os.path.join(self.builder.basedir, self.srcdir),
                          environ=self.env,
@@ -1510,16 +1510,17 @@
         c.usePTY = False
         d = c.start()
         def _parse(res):
-            r = c.stdout.strip()
-            # Support for removing svnversion indicator for 'modified'
-            if r[-1] == 'M':
-                r = r[:-1]
+            r_raw = c.stdout.strip()
+            # Extract revision from the version "number" string
+            r = r_raw.rstrip('MS')
+            if r.find(':') >= 0:
+                r = r.split(':')[-1]
             got_version = None
             try:
                 got_version = int(r)
             except ValueError:
                 msg =("SVN.parseGotRevision unable to parse output "
-                      "of svnversion: '%s'" % r)
+                      "of svnversion: '%s'" % r_raw)
                 log.msg(msg)
                 self.sendStatus({'header': msg + "\n"})
             return got_version
}}}

-- 
Aaron Maxwell .:. amax at snaplogic.org .:. http://snaplogic.org
SnapLogic, Inc. - Data Integration for the Last Mile




More information about the devel mailing list