Version Control with EWB

by Erick Engelke
August 21, 2024

As your projects get more complex, you will occasionally run into problems where you may want to revert to an earlier version of a particular file or recover from unexpected erasure of important parts of your project.

Don’t assume if you are careful things won’t go wrong. OS problems, EWB crashes, mistakes erasing old files, etc. They can all lead to loss of source. Also, sometimes you will make an incorrect change, we are all fallable.

Solutions include:

  • GIT and variations of it, which is a powerful solution to various problems, such as sharing source among several people, backups, restores, versioning.

  • Storage Back Directories like DropBox, NextCloud - which automatically copy files to the server and implement auto-versioning.

  • ZIP for the less adventurous

Storage Backed Solutions

The concept is simple, when you save files to certain subdirectories (such as your source tree), the files are automatically copied to a cloud (DropBox) or company (NextCloud) servers in the background. And you can restore an earlier version judging by the file time when it saved.

This has advantages over other solutions:

  • it is automatic, you can forget aabout it until you need the data.

  • it saves every copy, so you lose only minutes worth of work if you revert

  • it copies the data to secondary location, much better than keeping everything on one solitary device.

Note
I’m not a fan of certain large cloud providers whom I won’t name, ones who also sell AI programming tools which were created by learning from other people’s code without their knowledge or permission. If you aren’t paying or paying enough to cover costs, you aren’t a customer, you’re the product!

Develop a Habbit of Backing Up

Whatever you do, the most important part is to make a habbit of doing day saves.

My strategy is to keep things really simple, because the more complex your configuration, the more likely you are to make mistakes.

I like to keep my source code separate from my compiler, OS and other applications. So I have a virtual D: drive on each of my systems (home, work, laptop), where I just store development related files.

You can set up a partition of your hard drive, or just use virtual tools, like SUBST if you want. But it helps to separate your code from everything else.

  1. I use NextCloud to copy source to our enterprise server. It’s free open source, though you can pay for support and upgraded features. We have more then a Petabyte of storage this way, but i use very little myself.

  2. Also, nightly, I Zip up my entire D: drive and copy it to a separate server (in a different building and room - so fire, theft, flooding, etc. are unlikely to hurt both systems).
    That way, if something goes wrong, I’ve lost only a few hours worth of work at most. My entire workspace is only about 7 GB, including EXEs from Delphi. So terabyte drives can hold many months worth.

Note: Use a simple naming scheme so you can quickly find the old version. I use ISO dates: YYYY-MM-DD.zip so alphanumeric sorting puts them in order.

But this only helps if you are disciplined and keep up your backups or use server backed storge like DropBox or NextCloud.

Restoring Files

Don’t restore over your existing files, restore to a new directory, and then search for what you need. More on that in a second.

Searching for Something in Files

EWB uses WideText for files, so many searching tools that assume 8 bit ASCII dont’t work on its sources.

I wrote NiceGrep which implements many features of Unix grep but is compatible with EWB’s files.

To find, for example, a file and line with 'TButton in it,

nicegrep 'TButton *.wbs

if you want a case insensitive search, us

nicegrep -i 'tbutton *.wbs

and if you just want filenames, add a lower case L to it:

nicegrep -i -l 'tbutton *.wbs

It supports most REGEX search strings, so you can search with wild cards and various patterns. Googling REGEX should help you out.

Comparison of Files

So you have backups, good first start, but what if a problem started between a certain date (say 3 days ago) and today - how can you figure out the differences.

Restore the project’s files to a new subdirectory and use a DIFF-like tool to highlight the differences.'

A poor person with no Internet will use Windows’s FC.EXE. It’s one step above doing a comparision by hand, barely.

I like Difftastic. It’s free and available for most OSs. It understands Pascal, HTML, CSS, etc. though the default Unicode search is good enough for me.

It only shows you which lines are different and the preceding and successor lines. Old file contents are shown in red, new file in green.

Here I added line 15 with door : integer, pushing the rest of the file down one line (new line 16 was previous line 15).

sample

If you force Pascal file type interpretation, the program will display with Pascal colouring which is helpful.

sample

Summary

It’s not hard to develop a good backup strategy, but it’s a really good idea, and today’s tools make it almost effortless.