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

Script to downgrade WCs from 1.4 to 1.3

From: Max Bowsher <maxb1_at_ukf.net>
Date: 2006-04-09 16:37:27 CEST

WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!

  This is completely without warrantee or even any significant
  testing. It may trash your working copies !!!

WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!

That said, here's a script I wrote when I found I had accidentally
upgraded lots of working copies which I didn't want to.

Max.

#!/usr/bin/python

import os, shutil, sys

class LE(RuntimeError):
  "Local Error exception class"
  pass

def downgrade_dir(dn):
  def fn(fn, dn=dn): return os.path.join(dn, '.svn', fn)
  # I'm aware that O_EXCL is broken on NFS, but Subversion uses it too,
  # so there is little point doing better than that.
  lockfd = os.open(fn('lock'), os.O_WRONLY | os.O_CREAT | os.O_EXCL)
  fl = open(fn('format'), 'r')
  fmt = fl.readline()
  fl.close()
  fmt = fmt.rstrip('\n')
  if fmt != '6':
    os.close(lockfd)
    os.unlink(fn('lock'))
    if fmt != '4':
      return "UNEXPECTED FORMAT: %s" % repr(fmt)
    else:
      return "is already format 4"
  # Because it is read-only
  os.unlink(fn('format'))
  fl = open(fn('format'), 'w')
  fl.write('downgrade-from-6-to-4-in-progress\n')
  fl.close()
  textbases = os.listdir(fn('text-base'))
  for textbase in textbases:
    if not textbase.endswith('.svn-base'):
      raise LE("Unexpected file %s in %s"
          % (repr(textbase), repr(fn('text-base'))))
    bn = textbase[:-9]
    propbase = fn(os.path.join('prop-base', bn+'.svn-base'))
    if not os.path.exists(propbase):
      fl = open(propbase, 'w')
      fl.close()
    propwork = fn(os.path.join('props', bn+'.svn-work'))
    if not os.path.exists(propwork):
      shutil.copyfile(propbase, propwork)
  propbase = fn('dir-prop-base')
  if not os.path.exists(propbase):
    fl = open(propbase, 'w')
    fl.close()
  propwork = fn('dir-props')
  if not os.path.exists(propwork):
    shutil.copyfile(propbase, propwork)
  fl = open(fn('format'), 'w')
  fl.write('4\n')
  fl.close()
  os.close(lockfd)
  os.unlink(fn('lock'))
  return "done"

def recurse_downgrade(dn):
  for dirpath, dirnames, filenames in os.walk(dn):
    if '.svn' in dirnames:
      sys.stderr.write("%s... " % repr(dirpath))
      sys.stderr.write(downgrade_dir(dirpath))
      sys.stderr.write('\n')
      dirnames.remove('.svn')

def main(args):
  for i in args:
    recurse_downgrade(i)

if __name__ == '__main__':
  main(sys.argv[1:])

Received on Sun Apr 9 16:38:00 2006

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

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