[Kde-scm-interest] Source of "pattern must end in /" rule?

Nicolás Alvarez nicolas.alvarez at gmail.com
Tue Feb 12 00:04:48 UTC 2013


Dave Abrahams wrote:
> Boost's SVN repository contains a bunch of files in the same directory
> that need to be sorted into separate repositories.  As a result, we need
> svn2git to be able to match names that don't end in a forward slash.
> I've been looking through the svn2git code for code that malfunctions
> when that rule is violated, not finding anything obvious.  Could someone
> explain where that rule comes from?
> 
> That information would be a big help in closing
> https://github.com/ryppl/boost-svn2git/issues/6

A rule *that matches a directory* should end in a slash.

Say a SVN change arrives containing changes to /boost/bind/bind.hpp.
If you have a rule matching /boost/bind, svn2git will tell git-fast-import 
to create a file called "/bind.hpp" (the trailing part of the SVN path that 
wasn't matched by the regex). git-fast-import will then crash and burn 
because paths in the fast-import stream must not have leading or trailing 
slashes.

In addition, this would match (say) /boost/bind.hpp and put it into a file 
called ".hpp" which you probably don't want. Or anything else that happens 
to start with 'bind'.

If your rule has a trailing slash, then "/boost/bind/bind.hpp" with the rule 
regex "/boost/bind/" leaves "bind.hpp" to use as the path in the git 
repository, and everything goes well.


Now, on exporting individual files. Let's say you want to put 
/boost/bind.hpp into the repository as well. If you just make a rule
for "/boost/bind.hpp$" (the $ is usually a good idea when matching files!), 
it would match the entire SVN path, and the unmatched trailing part to use 
as git path would be empty. To avoid this, you have to use the 'prefix' 
statement inside the rule to give it a filename (svn2git will append the 
path it got, but as I said, it's empty):

match /boost/bind.hpp$
   repository bind
   branch master
   prefix bind.hpp
end match

Usually you would use captured subpatterns to your advantage here, by 
matching /boost/(bind.hpp) and using \1 as the prefix.

-- 
Nicolas




More information about the Kde-scm-interest mailing list