[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: auto-props and svn:keywords

From: Ian Schneider <Ian.Schneider_at_ars.usda.gov>
Date: 2004-05-19 18:43:42 CEST

On Wednesday 19 May 2004 09:34 am, John Peacock wrote:
> Robert M.Zigweid wrote:
> > Are there any plans to change this? It really would be nice to be able
> > to enforce a global policy. Is this something that could be done with
> > one of the pre-commit type hooks? Sometimes the big stick doesn't work
> > on people.
>
> Yes. Of course. Possibly. (in that order ;)

I'd refute the 'possibly'. You can place the big stick in your pre-commit
script:

Heres one I just hacked up:

pre-commit
#!/bin/sh
/usr/local/svn/test/hooks/checkprops $1 $2 >> /tmp/svnlog || exit 1

checkprops
#!/usr/bin/python

from ConfigParser import ConfigParser
from fnmatch import fnmatch
import sys,os

repos = sys.argv[1]
trans = sys.argv[2]

SVNLOOK = "/usr/bin/svnlook"
CONFIG = "%s/conf/config" % repos
MESSAGE = "set the auto-props in your subversion config file like the ones
here : http://blah/blah/config"

config = ConfigParser()
config.read(CONFIG)
autoprops = dict(config.items("auto-props"))
changes = os.popen("%s changed -t %s %s" % (SVNLOOK,trans,repos)).readlines()

def checkPath(path,autoprops):
  okay = 1
  for pattern in autoprops.keys():
    if fnmatch(path,pattern):
      items = map( lambda rule: rule.split("="),autoprops[pattern].split(";"))
      for item in items:
        propname = item[0]
        expected = item[1]
        propget = os.popen("%s propget -t %s %s %s %s" %
(SVNLOOK,trans,repos,propname,path))
        propval = propget.read()
        status = propget.close()
        if propval.find(expected) < 0:
          okay = 0
          if not status:
            sys.stderr.write("hook: Property value '%s:%s' not found on path
'%s'\n" % (propname,expected,path))
  return okay

failures = 0
for change in changes:
  if change[0] == 'A':
    path = change[4:].strip()
    if not checkPath(path,autoprops):
      sys.stderr.write("props not set correctly for %s\n" % path)
      failures = 1

if failures:
  hr = "\n" + "-" * 80 + "\n"
  sys.stderr.write(hr + MESSAGE + hr)
sys.exit(failures)

Go ahead and bash my python, but it _is_ possible to enforce these rules.

Regards,
Ian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Wed May 19 18:44:40 2004

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.