[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: Sun, 29 Mar 2009 01:30:32 +0800

My second attempt at the patch. It's now a proper svn diff
file.

Notes: Writes the format_nbr, regardless of what the
        previous value was (and if the format file doesn't
        exist, it creates it with the right value, which
        was the initial reason for this patch -- to create
        the format file)

Since format_nbr is fed into this format:write_format(),
it's a 'valid' value otherwise it would've choked prior to
the execution of the format part, no?

I'm still going over it, but I'd like some comments. Should
I add more code to check the format_nbr, or is it redundant?

Edmund

Index: change-svn-wc-format.py
===================================================================
--- change-svn-wc-format.py (revision 36814)
+++ change-svn-wc-format.py (working copy)
@@ -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)
@@ -298,7 +309,41 @@
       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)
+ format.close()
+ format = open(self.path, "w")
+ format.write(format_string % format_nbr)
+ if verbosity >= 2:
+ print("format file has been updated.")
+ 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

--
"Pax tecum"
------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1458714
Received on 2009-03-28 21:53:40 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.