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

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

From: Stefan Sperling <stsp_at_elego.de>
Date: Fri, 27 Mar 2009 14:36:52 +0000

On Fri, Mar 27, 2009 at 12:52:04PM +0800, Edmund Wong wrote:
> Here's the patch to create the format file in the WC .svn folder.

It does not look like you used 'svn diff' to produce this patch.

In general, it is good practice to generate patches with an up-to-date
trunk working copy from svn.collab.net to make sure you are working
against the latest and greatest.

Also, 'svn diff' will make sure the diff is generated correctly on all
platforms.

> --- 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"))
> -
> +

The above change is probably due to mismatching end-of-line markers?
Does that also happen with 'svn diff'?

> 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"))

Please use spaces after commas for consistency:

   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)

Again, space after comma.

> + 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)
> +
> +

Adding the two empty lines above might not be necessary.

> 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):

Space after comma...

> + self.path = path
> +
> + def write_format(self,format_nbr,verbosity=0):

Dum dudum...

> + if (len(str(format_nbr))) < 2:
> + frmt_val = '%02'
> + else:
> + frmt_val = '%01'
> + format_string = frmt_val+'d'

The rest of the code also uses spaces around operators like +.

> + # Overwrite all bytes of the format number.
> + if os.path.exists(self.path):
> + format = open(self.path,"r")
> + os.chmod(self.path, 0600)

Will the chmod work on Windows?

> + 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)

Changing working copy format should work either way, up to 1.6.
This script will never be able to support 1.7.

Note that not all versions of Subversion actually read and interpret
the format file. I'm not sure when we stopped reading it, but the
revision log of subversion/libsvn_wc/log.c might tell you.

Creating an empty file is enough to work around the bug in 1.6.0,
but older Subversion versions might complain about the file being
empty.

> + else:
> + format.close()
> + format = open(self.path,"w")
> + format.write(format_string % format_nbr)
> + if verbosity >= 2:
> + print("Downgraded WC format.")

This message sounds like the whole operation of downgrading
the working copy was complete. Is this appropriate here?

> + else:
> + if verbosity >= 1:
> + print("Format file does not exist. Creating it now.")
> + format = open(self.path,"w")
> + os.chmod(self.path,0600)

Again, will this work in Windows?

> + format.write(format_string % format_nbr)
> + if verbosity >= 1:
> + print("Format file has been created.")
> + format.close()
> + os.chmod(self.path, 0400)

Same.

> +
> class LocalException(Exception):
> """Root of local exception class hierarchy."""
> pass

Looks very good otherwise!

Thanks,
Stefan
Received on 2009-03-27 15:37:36 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.