Is there a way to "mix up" two files in Subversion?

I have the following problem that other people should have encountered. I am working on a code base that runs on two different platforms. Most of the code is distributed between platforms, but some parts of the code are optimized for a specific platform. Thus, there may be a general implementation of the function foo() in the file foo.cpp and an implementation optimized for platform A in the file foo_A.cpp .

Of course, sometimes it happens that a developer modifies foo.cpp and forgets to make a corresponding change to foo_A.cpp to synchronize them. This leads to very unpleasant errors that are difficult to track.

Finally, here is my question: is there a way to โ€œconfuseโ€ two or more files in Subversion? Is it possible, when someone makes a change to foo.cpp , so that svn foo.cpp warning, a reminder to update foo_A.cpp ?

+7
svn
source share
5 answers

You can write a pre-commit hook that checks that both foo.cpp and foo_A.cpp are present when one of them is committed.

He can either simply present a warning message and continue, or actually fail, returning an error, your choice.

+7
source share

Subversion has hooks you can use. Basically, you are writing a script in the correct folder and with the correct name. It can check if a specific named file is checked, and then do a bunch of stuff in response. (In other words, you can automate updating one file every time another file is checked.)

This is usually a bad idea. Restructuring your projects, so you all use the same file, is usually the best solution.

+3
source share

You can use pre-commit hook to reject the commit if foo.c is changed as part of commit, but foo_A.c is not. Depending on how many files are in your project, it can be difficult to get around by specifying the files explicitly in the hook script.

If you have consistent file naming conventions, you can put some smart pattern matching logic in the script. (for example, if you know that optimized file names always end with "_A", you can automate checking a little easier.)

Alternatively, you can try to solve the problem in your build process. The script line can execute "svn info" in two files, and then throw a warning / error if the SVNs of the two files do not match. It would be difficult to determine if the RPMs are different for legitimate reasons (for example, you only edited one of the files intentionally).

However, as commentators note, I honestly think that you are trying to solve the problem incorrectly. I would try to structure the code to prevent this class of errors in the first place. If both functions must change at the same time, this is a sign of unnecessary duplication in the code base. Look at combining common elements of two files in one place.

+2
source share

Since you are using a compiled language, have you just #ifdef entry (checking the flags defining the platform) in functions for optimization, instead of just writing a whole new function?

+1
source share

You may also want to run unit tests with this file, working on both platforms through continuous integration - then changes can be detected that break only one platform. At the very least, this will verify that both implementations display the same interface at compile time.

0
source share

All Articles