[PATCH] convert: Separate trunk detection from branch layout detection

Patrick Mézard pmezard at gmail.com
Wed Jan 2 15:25:14 CST 2008


Edouard Gomez a écrit :
> # HG changeset patch
> # User Edouard Gomez <ed.gomez at free.fr>
> # Date 1199210123 -3600
> # Node ID 96a2c66f4bb1a68d85715fd331ec5d53feed4b51
> # Parent  51776e50bc8c05de42a04208ccd91e7326ede6c8
> convert: Separate trunk detection from branch layout detection
> 
> In some subversion repositories, trunk is present but no branches
> are used. The current code is assuming that both trunk and branches
> must exist before adding trunk's head to the heads list.
>
> It's just better to separate the branch layout stuff from the trunk one.
> 
> diff -r 51776e50bc8c -r 96a2c66f4bb1 hgext/convert/subversion.py
> --- a/hgext/convert/subversion.py	Mon Dec 31 18:20:34 2007 -0600
> +++ b/hgext/convert/subversion.py	Tue Jan 01 18:55:23 2008 +0100
> @@ -187,14 +187,19 @@ class svn_source(converter_source):
>          trunk = (cfgtrunk or 'trunk').strip('/')
>          branches = (cfgbranches or 'branches').strip('/')
>          tags = (cfgtags or 'tags').strip('/')
> -        if self.exists(trunk, rev) and self.exists(branches, rev) and self.exists(tags, rev):
> -            self.ui.note('found trunk at %r, branches at %r and tags at %r\n' %
> -                         (trunk, branches, tags))
> +        oldmodule = None
> +        if self.exists(trunk, rev):
> +            self.ui.note('found trunk at %r\n' % trunk)
>              oldmodule = self.module
>              self.module += '/' + trunk
>              lt = self.latest(self.module, self.last_changed)
>              self.head = self.revid(lt)
>              self.heads = [self.head]
> +        elif cfgtrunk:
> +            raise util.Abort('expected trunk to be at %r, but not found' % trunk)

Maybe we can wrap the path selection and checking logic in a local function ? Like:

def findpath(name, rev):
    cfgpath = self.ui.config('convert', 'svn.' + name)
    path = (cfgpath or name).strip('/')
    if not self.exists(path, rev):
        if cfgpath:
            raise util.Abort(_('expected %s to be at %r, but not found') % (name, path))
        return None
    else:
        self.ui.note(_('found %s at %r\n') % (name, trunk))
    return path

> +
> +        if self.exists(branches, rev):
> +            self.ui.note('found branches at %r\n' % branches)
>              branchnames = svn.client.ls(rpath + '/' + branches, rev, False,
>                                          self.ctx)
>              for branch in branchnames.keys():
> @@ -206,15 +211,19 @@ class svn_source(converter_source):
>                  brev = self.revid(brevnum, module)
>                  self.ui.note('found branch %s at %d\n' % (branch, brevnum))
>                  self.heads.append(brev)

self.heads is not initialized if there is no trunk.

> +        elif cfgbranches:
> +            raise util.Abort('expected branches to be at %r, but not found' % branches)
>  
> +        if self.exists(tags, rev):
> +            self.ui.note('found tags at %r\n' % tags)
>              if oldmodule:
>                  self.tags = '%s/%s' % (oldmodule, tags)
>              else:
>                  self.tags = '/%s' % tags
> +        elif cfgtags:
> +            raise util.Abort('expected tags to be at %r, but not found' % tags)
>  
> -        elif cfgtrunk or cfgbranches or cfgtags:
> -            raise util.Abort('trunk/branch/tags layout expected, but not found')
> -        else:
> +        if not self.heads:
>              self.ui.note('working with one branch\n')
>              self.heads = [self.head]
>              self.tags  = tags

Shouldn't we use the tags we may have found just before ?

Can you hack test-convert-svn-source a little to add a test exhibiting a trunk without branches for instance ?

--
Patrick Mézard


More information about the Mercurial mailing list