Search code examples
cvs

Is it possible to repair badly indented C/C++ code in RCS/CVS safely without adding new commits?


I have some old code in CVS format (RCS format). I would like to avoid checking in a new revision only to fix the indentation, and not syntax. Often the original developer no longer has an account (they have left the company). If I were to fix that indentation, then that change is marked with my user account in cvs annotate output, which is undesirable. Since only indentation is changed, functionality is not changed. The net result is that, when the file is checked out again, its indentation is corrected, and a cvs annotate shows that line of the last "real" change and its associated author.

So, is this even possible with directly editing of the ,v RCS file (on a copy of the file on a locked down CVSROOT, for instance), or are there checksums that check for such editing (RCS format alludes to a "integrity" field but it is not clear if it is the thing that would invalidate this type of change)? Notice this is CVS-specific; other source code control systems such as Git have built-in mechanisms. (Migrating to those other systems is being considered but that is off-topic here).

https://stackoverflow.com/a/46713192/257924 seems to indicate there are tools readily available for parsing the underlying RCS format (,v files), so might be used for the basis of this in case it is actually true that there is some type of checksum in the file. But if I could just do the edits directly, that would be better.


Solution

  • I would avoid rewriting the raw ,v file if you possibly can. Lots of things can go wrong in there, and the pool of people who can help dwindles each passing day.

    I would suggest "lying" to RCS instead. Something like this:

    $ co -l file.ext
    $ prettyformat file.ext
    $ lastauthor=$(rlog file.ext | awk '$1=="date:"{print $5;exit}')
    $ ci -u -w"${lastauthor%;}" -m'formatting updates' file.ext
    

    I don't know what your prettyformat command might be, but you can swap it in.

    The basic idea here is that we WILL do an update to each file, but we'll "fake" the author name with -w. This is fine, it's just a text string in the ,v file, there's no magic associated with it.

    If you're also concerned about dates, you could also fake them with the -d option:

    $ lastmod=$(rlog file.ext | awk '$1=="date:"{print $2,$3;exit}')
    $ co -l file.ext
    $ prettyformat file.ext
    $ lastauthor=$(rlog file.ext | awk '$1=="date:"{print $5;exit}')
    $ ci -u -w"${lastauthor%;}" -d"${lastmod%;}" -m'formatting updates' file.ext
    

    This way, if you choose to migrate things to something other than CVS in the future, the age of each file will be recorded correctly irrespective of the formatting changes.