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

Re: A CVS Entries file parser

From: Sam TH <sam_at_uchicago.edu>
Date: 2001-04-19 17:15:50 CEST

On Thu, Apr 19, 2001 at 10:01:09AM -0500, Ben Collins-Sussman wrote:
> From: Ben Collins-Sussman <sussman@newt.ch.collab.net>
> Date: 19 Apr 2001 10:01:04 -0500
> In-Reply-To: Sam TH's message of "Thu, 19 Apr 2001 08:55:45 -0500"
> Message-ID: <86bspt9bnz.fsf@newt.ch.collab.net>
> Lines: 18
> X-Mailer: Gnus v5.7/Emacs 20.7
>
>
> Sam, please post your patches! This sounds great.

Translation: Didn't you mean to attach something? :-)

Also, plenty of people on this list have a more detailed knowledge of
the internals of CVS than I do (understatement). So if I missed
something significant in the format of Entries files, please let me
know.

Index: svn_entry.py
===================================================================
RCS file: /cvs/subversion/subversion/tests/clients/cmdline/svn_entry.py,v
retrieving revision 1.4
diff -u -r1.4 svn_entry.py
--- svn_entry.py 2001/04/12 18:11:02 1.4
+++ svn_entry.py 2001/04/19 13:34:47
@@ -26,12 +26,13 @@
 # kind, revision, ancestor. Other optional keys *might* be
 # present, such as prop-time, text-time, add, delete, conflict.
 
-import xml.parsers.expat # you may need to install this package
+import xml.parsers.expat # you may need to install this package
+import copy # for deepcopy
 
 class svn_entry:
   "An object that represents an entry from an 'entries' file."
 
- def __init__(self, attributes): # constructor
+ def __init__(self, attributes={}): # constructor
     self.atts = attributes
 
   def prettyprint(self):
@@ -71,14 +72,85 @@
                   
       self.entry_dict[attrs['name']] = entry # store the new entry
 
+ def prettyprint(self):
+ "Pretty-print the entire set of entries"
+ for i in self.entry_dict.values():
+ i.prettyprint()
+
+class svn_cvs_entryparser:
+ "A class to parse a CVS 'Entries' file."
+
+ def __init__(self):
+ self.entry_dict = {}
+
+ def parse_file(self, file):
+ "Parse the CVS 'Entries' file FILE into a dictionary."
+
+ # Create a parent entry to represent the current directory
+ # This directory isn't in the Entries file, and isn't really under
+ # CVS's control, but SVN has an entry for it, and we want to be
+ # compatible
+ parent = svn_entry({})
+ parent.atts['name'] = "" # for consistency with subversion
+ # this is arbitary, since it isn't versioned by CVS
+ parent.atts['revision'] = "1"
+ # FIXME This is wrong. How can we get this info? Do we want to
+ # fix this here, or when we create the tree? Doing it here
+ # requires info not in the Entries file
+ parent.atts['ancestor'] = "anni"
+ parent.atts['kind'] = "dir"
+ self.entry_dict[parent.atts['name']] = parent
+
+ lines = file.readlines()
+ for l in lines:
+ entry = svn_entry()
+ if l[0] == 'D': # Directories begin with D
+ if len(l) == 1:
+ # If a directory contains no subdirectories, the last line
+ # of the entries file is a single 'D'
+ continue
+ else:
+ entry.atts['kind'] = 'dir'
+ l = l[1:]
+ else:
+ entry.atts['kind'] = 'file'
+ props = l.split("/")
+ if l[0] == '\n': # skip empty entries
+ continue
+ entry.atts['name'] = props[1]
+ entry.atts['revision'] = props[2]
+ entry.atts['text-time'] = props[3]
+ entry.atts['ancestor'] = parent.atts['ancestor'] + '/' \
+ + entry.atts['name']
+
+ self.entry_dict[entry.atts['name']] = copy.deepcopy(entry) # store the new entry
+
+ def prettyprint(self):
+ "Pretty-print the entire set of entries"
+
+ for i in self.entry_dict.values():
+ i.prettyprint()
+
 
 # The main exported routine
 def get_entries(path):
- "Parse the entries file at PATH and return a list of svn_entry objects."
+ """Parse the entries file at PATH and return a dictionary of entry
+ objects. This can be passed either a CVS or an SVN entries file,
+ and it will do the right thing."""
 
- entryparser = svn_entryparser() # make a parser instance
   fp = open(path, 'r')
- entryparser.parser.ParseFile(fp)
+ first_line = fp.readline().strip()
+ fp.seek(0) # go back, so we don't miss the first line
+
+ # we assume the the XML declaration is on the first line. Since we
+ # are writing the files, this should be a safe assumption.
+ if first_line.find("xml") != -1:
+ entryparser = svn_entryparser()
+ entryparser.parser.ParseFile(fp)
+ # We assume that the first line is not blank - should be a safe assumption
+ elif (first_line[0] == '/') or (first_line[0] == 'D'):
+ entryparser = svn_cvs_entryparser()
+ entryparser.parse_file(fp)
   fp.close()
   return entryparser.entry_dict
 
sam th --- sam_at_uchicago.edu --- http://www.abisource.com/~sam/
OpenPGP Key: CABD33FC --- http://samth.dyndns.org/key
DeCSS: http://samth.dyndns.org/decss

  • application/pgp-signature attachment: stored
Received on Sat Oct 21 14:36:29 2006

This is an archived mail posted to the Subversion Dev mailing list.