The code for the Akka Hacking session is maintained in a git repository. The idea is to push the exercises from a private to a public repository used by the attendees.
While writing the code (and README file), mistakes are made, necessitating corrections to the different commits in the repo. Doing this 'manually' is a tedious and error-prone process. This is where git filter-branch
comes into play...
See below the way in which the different source files were corrected. It started with a rename of three variables, which turned out to introduce a name clash. This in turn was corrected with further edits.
Of course, don't do this on your working copy of the repo. Instead:
- Clone the repo and remove the *remote(s)*
- Apply the changes using ```filter-branch```
- Test, test, test...
- Add *remote(s)* back
- Force push the repo
- Inform other users :-)
Details
The following mapping of variable names was applied:
pingerCount => pingyCount
pingRetryCount => pingCount
pingRetryInterval => pingInterval
by running the following command
git filter-branch --tree-filter '/scb/AkkaHackingSessionBeScalaTmp/patchFile src/main/scala/org/bescala/akkapingpong/PingMaster.scala' -f
with /scb/AkkaHackingSessionBeScalaTmp/patchFile:
#!/bin/ksh
FILE=$1
if [ -e ${FILE} ]
then
sed -i.bak -f /scb/AkkaHackingSessionBeScalaTmp/cmdPatchCode ${FILE} && rm ${FILE}.bak
else
exit 0
fi
and /scb/AkkaHackingSessionBeScalaTmp/cmdPatchCode:
1,$s/pingerCount/pingyCount/g
1,$s/pingRetryCount/pingCount/g
1,$s/pingRetryInterval/pingInterval/g
1,$s/var pingCount = pingCount/var curPingCount = pingCount/g
1,$s/for (seq <- 1 to pingCount)/for (seq <- 1 to curPingCount)/g
1,$s/case Pongy.Pong(seq, ref) if pingCount == 1 =>/case Pongy.Pong(seq, ref) if curPingCount == 1 =>/g
1,$s/pingCount -= 1/curPingCount -= 1/g