โš ๏ธ Warning: This post is over a year old, the information may be out of date.

๐Ÿ“ Patching cvs files using patch manually and how to revert it

๐Ÿ“… | โฐ 2 minutes

Assalamualaikum and hello everyone!

Today, I gonna put my note how to patch file using “patch” (linux utility tool). Have you using it? Well, please read linux.die.net/man/1/patch if you are looking for standard manual from man pages.

I know it already 2020 and yes, someone like me are still using CVS.

CVS (Concurrent Version Control) is very old source code control but it still use nowadays for certain project, even BSD ports still using CVS. To be honest, I donโ€™t like CVS but because it they only SCM (source control management) tool for certain project.

Problem

So my project is microservices not monolith. Thus compiled services running inside server and we also store source code (checkout from cvs) inside the same server.

I have option todo coding on my Eclipse IDE locally and commit changes on cvs server and update (pull) changes on production/testing server, but sometimes I don’t want to commit yet. I don’t like half-baked code committed into branches. It will be dangerous and immature (not finalize code yet).

Solution

As solution, i will use patch to solve this issue. First, grab the changes as patch using command cvs diff -N -u -l "file_name_here" or via from eclipse ide (setting as diff output as Unified and patch root as project)

You may get something like this as result

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
cvs diff -N -u -l "/dev-ops-tools/src/com/ssp/support/commons/connection/ConnectionController.java"
    Index: src/com/ssp/support/commons/connection/ConnectionController.java
    ===================================================================
    RCS file: /cvs/dev-ops-tools/src/com/ssp/support/commons/connection/ConnectionController.java,v
    retrieving revision 1.5
    diff -u -r1.5 ConnectionController.java
    --- src/com/ssp/support/commons/connection/ConnectionController.java	8 Mar 2016 16:08:05 -0000	1.5
    +++ src/com/ssp/support/commons/connection/ConnectionController.java	22 Sep 2020 03:32:09 -0000
    @@ -61,6 +61,7 @@
             }
           }
         } else {
    +      LOG.info("ROB WAS HEREZ");
           LOG.info("connections.xml file found");
         }
         return pathname;

README

From my example above, look at line num 7-8 (lets just called it as target file). Please change it manually if file are location inside server are different with your development enviroment.

Copy the diff output (if from my example, copy from line 2-16 only) as put on file (as example I will call it as patch.diff) inside you server. Make use location of target file are correct and match from where patch.diff file are stored.

Now we can simulate / test it first (no file changes) using patch -b --dry-run -p0 < patch.diff and if everything ok, then do the real patch with patch -b -p0 < patch.diff.

$ patch -b -p0 < patch.diff
patching file src/com/ssp/support/commons/connection/ConnectionController.java

The parameter -b is additional but it better to always use it because it will create backup of file with extension *.orig and you can rollback / revert to origin state if after patched file and thing are not working as expected. so yes, wiht -b parameter, it will create backup for you. (you can search it with find . -name *.orig command)

Undo, revert, rollback? yes.. just simple run patch -R -p0 < patch.diff from terminal ๐Ÿ˜„

Posted by: Hugo

Edit

Have some thoughts, discussion or feedback on this post?

๐Ÿ’ฌย Send me an email

What is webmention? How to send interactions!

Below you can find all of webmention with this page. Which means, you also can mentioned this URL on any website that support WebMention. Have you written a response to this post? Let me know the URL:

Do you use a website that don't have WebMention capabilities? You can just use Comment Parade!