You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Edmund Wong <ed...@belfordhk.com> on 2009/03/27 04:52:04 UTC

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

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

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

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.
Stefan Sperling wrote on Sat, 28 Mar 2009 at 13:24 -0000:
> On Sat, Mar 28, 2009 at 04:18:55PM +0300, Daniel Shahaf wrote:
> > Stefan Sperling wrote on Sat, 28 Mar 2009 at 12:52 -0000:
> > > For all x and y in [0...6] inclusive:
> > > Downgrade from svn 1.x to svn 1.y -> decrease format number appropriately.
> > > Upgrade from svn 1.x to svn 1.y -> increase format number appropriately.
> > > 
> > The script doesn't support downgrading to (or upgrading from) svn 1.3
> > and earlier formats.
> 
> So I should have said:
> 
>  For all x and y in [4...6] inclusive:
> 
> In which case creating an empty file is enough I'd say, because
> all these versions of Subversion just ignore the file (except 1.6.0).
> 

Still, it's nice to be consistent when the consistency doesn't cost
much.  (The script already knows the magic numbers.)  However, the only
API-conformant argument I have is "svn <=1.3 will give a better error
message", so perhaps it doesn't matter.

> Stefan
>

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1456696

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

Posted by Stefan Sperling <st...@elego.de>.
On Sat, Mar 28, 2009 at 04:18:55PM +0300, Daniel Shahaf wrote:
> Stefan Sperling wrote on Sat, 28 Mar 2009 at 12:52 -0000:
> > For all x and y in [0...6] inclusive:
> > Downgrade from svn 1.x to svn 1.y -> decrease format number appropriately.
> > Upgrade from svn 1.x to svn 1.y -> increase format number appropriately.
> > 
> The script doesn't support downgrading to (or upgrading from) svn 1.3
> and earlier formats.

So I should have said:

 For all x and y in [4...6] inclusive:

In which case creating an empty file is enough I'd say, because
all these versions of Subversion just ignore the file (except 1.6.0).

Stefan

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

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.
Stefan Sperling wrote on Sat, 28 Mar 2009 at 12:52 -0000:
> On Sat, Mar 28, 2009 at 11:46:32AM +0800, Edmund Wong wrote:
> > On Fri, 27 Mar 2009 14:36:52 +0000, Stefan Sperling wrote
> > > Changing working copy format should work either way, up to 1.6.
> > > This script will never be able to support 1.7.
> > > 
> > I understand.  So basically I take out the last three lines above?
> 
> You need to create the file with the correct format version
> number no matter which direction you are going.
> 

+1

> For all x and y in [0...6] inclusive:
> Downgrade from svn 1.x to svn 1.y -> decrease format number appropriately.
> Upgrade from svn 1.x to svn 1.y -> increase format number appropriately.
> 

> > From Greg Stein's post, it's likely that it's only up to 1.4. 
> > Or did I misunderstand?
> 
> Greg is usually right ;)
> 
> You can decide whether to treat Subversion 1.4 and above as
> a special case and leave the file empty, or if you don't want
> special cases and just always create an appropriate format file.
> 

The script doesn't support downgrading to (or upgrading from) svn 1.3
and earlier formats.

Nonetheless, +1 to always creating a valid (non-empty) format file.

> Either approach will fix the bug with 1.6.0.

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1455946

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

Posted by Stefan Sperling <st...@elego.de>.
On Sat, Mar 28, 2009 at 11:46:32AM +0800, Edmund Wong wrote:
> On Fri, 27 Mar 2009 14:36:52 +0000, Stefan Sperling wrote
> > 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.
> > 
> My mistake.  I used TortoiseSVN's diff feature.  Anyway, I'll post
> a new diff with the changes.

Yes, please post a new diff.

> > The above change is probably due to mismatching end-of-line markers? 
> > Does that also happen with 'svn diff'?
> >
> Nope.  As mentioned above, my bad. 
>  
> > Please use spaces after commas for consistency:
> > > +
> > > +
> > 
> > Adding the two empty lines above might not be necessary.
> > The rest of the code also uses spaces around operators like +.
> > 
> 
> I've fixed the space issues.
> 
> > > +    # 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?
> >
> 
> Nope.  It doesn't work, or rather, it has no affect, 
> as far as I know. (Ran this script on a Vista machine.)
> 
> Should I test for OS?

If os.chmod() is a no-op on OSs the don't support chmod,
we don't need extra code to check for OS.
Let python handle it if it can.

> > > +      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.
> > 
> I understand.  So basically I take out the last three lines above?

You need to create the file with the correct format version
number no matter which direction you are going.

For all x and y in [0...6] inclusive:
Downgrade from svn 1.x to svn 1.y -> decrease format number appropriately.
Upgrade from svn 1.x to svn 1.y -> increase format number appropriately.

> > 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.
> 
> From Greg Stein's post, it's likely that it's only up to 1.4. 
> Or did I misunderstand?

Greg is usually right ;)

You can decide whether to treat Subversion 1.4 and above as
a special case and leave the file empty, or if you don't want
special cases and just always create an appropriate format file.

Either approach will fix the bug with 1.6.0.

> > > +        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?
> 
> I fixed it to "format file has been updated."  Is this a better
> message?

Yes.

Thanks,
Stefan

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

Posted by Edmund Wong <ed...@belfordhk.com>.
On Fri, 27 Mar 2009 14:36:52 +0000, Stefan Sperling wrote
> 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.
> 
My mistake.  I used TortoiseSVN's diff feature.  Anyway, I'll post
a new diff with the changes.

> The above change is probably due to mismatching end-of-line markers? 
> Does that also happen with 'svn diff'?
>
Nope.  As mentioned above, my bad. 
 
> Please use spaces after commas for consistency:
> > +
> > +
> 
> Adding the two empty lines above might not be necessary.
> The rest of the code also uses spaces around operators like +.
> 

I've fixed the space issues.

> > +    # 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?
>

Nope.  It doesn't work, or rather, it has no affect, 
as far as I know. (Ran this script on a Vista machine.)

Should I test for OS?

> > +      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.
> 
I understand.  So basically I take out the last three lines above?

> 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.

From Greg Stein's post, it's likely that it's only up to 1.4. 
Or did I misunderstand?

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

I fixed it to "format file has been updated."  Is this a better
message?

Thanks for the comments.

Edmund

--
"Pax tecum"

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1451773

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

Posted by Edmund Wong <ed...@belfordhk.com>.
Hi Greg,

> I believe we stopped reading the format file in 1.4, but forgot to 
> delete it :-P
> 
> I don't know what number is supposed to go in there for each release...

So clients with version < 1.4 will have problems with the missing
format file, right?   (Rhetorical question really, since it's 
pretty much answered. :))

Edmund
--
"Pax tecum"

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1451884

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

Posted by Greg Stein <gs...@gmail.com>.
I believe we stopped reading the format file in 1.4, but forgot to delete it :-P

I don't know what number is supposed to go in there for each release...


On Fri, Mar 27, 2009 at 15:36, Stefan Sperling <st...@elego.de> wrote:
> 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
>
>

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1445171


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

Posted by Stefan Sperling <st...@elego.de>.
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