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

Re: svn commit: rev 5750 - branches/cvs2svn-kfogel/tools/cvs2svn

From: Jeffrey C. Ollie <jeff_at_ollie.clive.ia.us>
Date: 2003-04-29 05:31:27 CEST

On Mon, 2003-04-28 at 17:51, Karl Fogel wrote:
> Greg Stein <gstein@lyra.org> writes:
> > > + path_so_far = None
> > > + components = string.split(path, '/')
> >
> > One of the things that I like to do is:
> >
> > components = filter(None, string.split(path, '/'))
> >
> > That filter() usage will filter out all empty strings, which means it
> > ignores leading and trailing slashes, and double-slashes. Kinda nifty :-)
>
> Ooooh, I like it.

One thing that I noticed about the construction of ensure_directories is
that it's probably not very portable to Windows, to say nothing about
MacOS <= 9 (although that's probably not a big market segment for
cvs2svn!). I also noticed that a lot of other functions are hardcoded to
use Unix-style paths instead of using the os.path.* functions. Also,
I think that I fixed a buglet. You had the following:

if path_so_far:
  path_so_far = path + '/' + component
else:
  path_so_far = component

Using "path_so_far" rather than "path" in the second line would seem to
be the proper way to go. Anyway here's a proposed replacement that uses
os.path.* functions:

def ensure_directories(path, root, dumpfile):
  """Output to DUMPFILE any intermediate directories in PATH that are
  not already present under node ROOT, adding them to ROOT's tree as
  we go. Return the last parent directory, that is, the parent
  of PATH's basename. Leading slash(es) on PATH are optional."""

  # split the drive letter off on Windows (Mac & Unix path_so_far will be '')
  # after normalizing the path to get rid of double slashes, etc.
  path_so_far, head = os.path.splitdrive(os.path.normpath(path))

  # build a list of the path's components, in reverse order, which will
  # be used as a stack later
  components = []
  while head not in ['', os.sep, os.altsep]:
    head, tail = os.path.split(head)
    components.append(tail)

  # get rid of the very last component, which is at the bottom of
  # the stack
  del components[0]

  this_node = root

  while len(components) > 0:
    # pop a component off the stack
    component = components[-1]
    del components[-1]

    # string the paths together
    path_so_far = os.path.join(path_so_far, component)

    if component not in this_node.children:
      this_node.children[component] = Node()
      dumpfile.write("Node-path: %s\n" % path_so_far)
      dumpfile.write("Node-kind: dir\n")
      dumpfile.write("Node-action: add\n")
      dumpfile.write("Prop-content-length: 10\n")
      dumpfile.write("Content-length: 10\n")
      dumpfile.write("\n")
      dumpfile.write("PROPS-END\n")
      dumpfile.write("\n")
      dumpfile.write("\n")
    this_node = this_node.children[component]

  return this_node

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Apr 29 05:32:24 2003

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