views:

169

answers:

5

I have some projects that run on custom hardware. Now the hardware has changed, which required some software changes. Therefore, there is source A for "old hardware" and source B for "new hardware", which are 95% the same.

If a new feature is added in the future, it has to be done for both versions. In other words, A und B will exist side by side and from now on will always require the same changes.

I have just started to use Subversion, therefore I am not very familiar with all the possibilities.

As I understand, a new branch for B would separate both from that point on, which is not what I need.

What is the best way to maintain A and B so that future changes will apply to both versions without having to manually apply them twice?

A: 

In SVN you can make branches for "old" and "new" hardware.

Luixv
But woulnd't I have to check out "old" and "new" separately and apply a change to both of them manually?
Holgerwa
Yes you would have to do it this way: change old and than apply changes manualy to new.
Michal Sznajder
+3  A: 

If possible, I'd maintain a single source tree and use #ifdefs to customize the code for the particular processor (assuming you're using C or C++). This works especially well if you can isolate the parts that are hardware-dependent into a small number of files. If you can do this, no extra subversion magic is needed.

Mr Fooz
That is the same way I did these things before, without thinking of Subversion.Could have been that there was a better solution using Subversion, that was my reason for the question.
Holgerwa
Having ifdefs inside the code to maintain a "common" code base location is not so easy as it might look and I strongly not recommend it. In the end, it will be another significant source of change control nightmare, because it is easy that, in the same source code, to introduce side effects "cross" versions. The more "branches" you'll have, the more problems in following the changes for one specific version and to keep the side effects out for the rest of the versions.
Cătălin Pitiș
@Catalin Pitis: For each unique hardware environment there will need to be at least some branching of the code. IMHO, one should try to isolate what's unique as much as possible, and preferably gather it in one place. Sometimes #ifdefs work nicely, other times it makes sense to create some hardware-specific driver classes or functions. What do you recommend as an alternative?
Mr Fooz
The problem with #ifdef: In good cases it is simple like 'console.WriteLine' instead of 'logFile.WriteLine'. In that case, the A version and B version are LOGICALLY and Input/Output indentical. That is to say, the function requires the same parameters, and would have the same outputs, the differences are a few lines internal to the function.Once the parameter requirements, output, state variables, Environmental factors start effecting more than just one or two lines, and you are using strings of #ifdefs across multiple files, it becomes a nightmare.
+9  A: 

I see no need for any sophisticated versioning. Just organize your sources into structure like this:

Project
|-CommonSource95%
|-HardwareA
|-HardwareB

Use makefiles or #ifdefs to customize the code for the particular hardware.

Michal Sznajder
+1  A: 

Isolate the code which is specific to a certain hardware version somehow: Put it into different functions or use a macro to exchange the different parts. This is what high level OSs call "device driver".

In either the build file or at runtime, determine which version you need and activate it. Function pointers are your friend.

Factor common code out and use it from both versions. This way, you reduce code duplication, you can see both versions at the same time. If you separate this using SVN revisions, this wouldn't be possible.

Aaron Digulla
A: 

I would not solve this by branching in your version control system. The branches may diverge to a point where it becomes difficult to port changes between them.

This question reminded me of the Apache Portable Runtime project. You can use the same idea for your code: hide the implementation differences for different hardware behind a Hardware Abstraction Layer. The different implementations of this layer can live next to each other in the same trunk. Most of the code should not care about the hardware and access it through the HAL.

Wim Coenen