views:

80

answers:

1

Is there any way to have something like svn externals for files stored in source control (Subversion preferably but I'd be interested if it's possible or easier for other SCM systems).

Here's what I mean. Say I've got a whole bunch of SQL scripts and these have to be merged into one big script for packaging each release. It would be good if I could create a file for the entire scripts and then just link to the other files some how and the file would automatically get updated (after an SVN update) when any of the referenced files change in subversion. The concatenated file would have to be readonly I guess.

Thinking about this a bit more having too files would probably be easier. One for the template definition and another for the file itself.

It might look something like this.

Template file (maybe .sql.svntemplate extension or something):

<external file="relative/repository/url/Script1.sql"/>
<external file="relative/repository/url/Script2.sql"/>
<external file="relative/repository/url/Script3.sql"/>
<external file="relative/repository/url/Script4.sql"/>

Of course it doesn't have to be XML.

Then when you add and commit the .sql.svntemplate file Subversion will automatically generate a readonly file with the same name except without the .svntemplate extension.

E.g.

DBScripts.sql.svntemplate

would generate a readonly file called:

DBScripts.sql

which would contain the contents from all the scripts.

+3  A: 

What you are describing is commonly known as Derived Object and many source control systems have different ways of handling them. In the most common case derived objects are created during the integration of a new label in the build phase. Common other derived objects are compiled object files, archive files and database files. An example of source control system handling derived objects is IBM Rational ClearCase.

SVN does not have good handling of derived objects implemented. I would suggest to create a make file for pre-commit actions. So before svn checkin you run 'make -f Makefile.commit', which creates/updates all the relevant derived objects. You can put a specific Makefile into each directory and make them include makefiles from subdirectories so anytime you commit a subtree, just run a makefile in its directory and it will update dervied objects in the entire subtree that you modified. You can add rules to the makefile to set derived objects as read-only after they are generated.

On Makefile stategies see the gnu user manual. Make is a tool specifically designed to handle creation of derived objects based on source file modification and dependencies.

Jiri Klouda
Ah, I remember make from Uni. I'm doing .NET now so I guess NAnt is the tool I should (and am at the moment) using. I was looking for a short cut though to avoid file manipulation goo in my build file.
Jonathan Parker
There are no shortcuts. Source control systems never generate the derived objects, they just manage them, in better cases. You will need to generate them in Make or Ant or other build tool.
Jiri Klouda