Tutorial :How to maintain slightly different software?


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?


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.


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.


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.


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


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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »