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

[PATCH] change-svn-wc-format.py

From: Edmund Wong <edmund_at_belfordhk.com>
Date: Fri, 27 Mar 2009 12:52:04 +0800

Here's the patch to create the format file in the WC .svn folder.

--- D:/test_svn/change-svn-wc-format.py-rev4.svn000.tmp.py Fri Mar 27
12:41:37 2009
+++ D:/test_svn/test/change-svn-wc-format.py Fri Mar 27 12:14:59 2009
@@ -84,7 +84,7 @@
      if self.verbosity:
        print("Processing directory '%s'" % dirname)
      entries = Entries(os.path.join(dirname, get_adm_dir(), "entries"))
-
+
      if self.verbosity:
        print("Parsing file '%s'" % entries.path)
      try:
@@ -95,7 +95,18 @@
        sys.stderr.write("%s, skipping\n" % e)
        sys.stderr.flush()

+ format = Format(os.path.join(dirname,get_adm_dir(),"format"))
      if self.verbosity:
+ print("Updating file '%s'" % format.path)
+ try:
+ format.write_format(format_nbr,self.verbosity)
+ except UnrecognizedWCFormatException, e:
+ if self.error_on_unrecognized:
+ raise
+ sys.stderr.write("%s, skipping\n" % e)
+ sys.stderr.flush()
+
+ if self.verbosity:
        print("Checking whether WC format can be converted")
      try:
        entries.assert_valid_format(format_nbr, self.verbosity)
@@ -110,6 +121,8 @@
      if self.verbosity:
        print("Writing WC format")
      entries.write_format(format_nbr)
+
+

    def change_wc_format(self, format_nbr):
      """Walk all paths in a WC tree, and change their format to
@@ -298,7 +311,45 @@
        rep += "[%s] %s\n" % (Entries.entry_fields[i], self.fields[i])
      return rep

-
+class Format:
+ """Represents a .svn/format file."""
+
+ def __init__(self,path):
+ self.path = path
+
+ def write_format(self,format_nbr,verbosity=0):
+ if (len(str(format_nbr))) < 2:
+ frmt_val = '%02'
+ else:
+ frmt_val = '%01'
+ format_string = frmt_val+'d'
+ # Overwrite all bytes of the format number.
+ if os.path.exists(self.path):
+ format = open(self.path,"r")
+ os.chmod(self.path, 0600)
+ format_line = format.readline()
+ format_line.rstrip()
+ format_nbr_old = int(format_line)
+ if format_nbr_old < format_nbr:
+ # Upgrading version is not supported? (Please review.)
+ raise UnrecognizedWCFormatException(format_nbr_old,self.path)
+ else:
+ format.close()
+ format = open(self.path,"w")
+ format.write(format_string % format_nbr)
+ if verbosity >= 2:
+ print("Downgraded WC format.")
+ else:
+ if verbosity >= 1:
+ print("Format file does not exist. Creating it now.")
+ format = open(self.path,"w")
+ os.chmod(self.path,0600)
+ format.write(format_string % format_nbr)
+ if verbosity >= 1:
+ print("Format file has been created.")
+ format.close()
+ os.chmod(self.path, 0400)
+
  class LocalException(Exception):
    """Root of local exception class hierarchy."""
    pass

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1439775
Received on 2009-03-27 12:57:27 CET

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.