[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: Daniel Shahaf <d.s_at_daniel.shahaf.name>
Date: Sun, 29 Mar 2009 05:50:01 +0300 (Jerusalem Daylight Time)

> > +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'
>
> We can save a line and a variable here by doing:
>
> if (len(str(format_nbr))) < 2:
> format_string = '%02d'
> else:
> format_string = '%01d'
>
> and getting rid of this line:
>
> > + format_string = frmt_val + 'd'
>
> > + # Overwrite all bytes of the format number.

You don't need the "overwrite all bytes" stuff here. It's necessary for
the entries file (when downgrading from format >=10 to format <=9),
since that one is edited in-place (mode 'r+'); but for the format file,
you open the file in 'w' ("truncate") mode anyway, so

    format_string = '%d\n'

is good enough.

Daniel

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

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1465021
Received on 2009-03-29 04:50:25 CEST

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.